1 /* Emit RTL for the GNU C-Compiler expander.
2 Copyright (C) 1987, 88, 92, 93, 94, 1995 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. */
77 enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
79 /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
80 After rtl generation, it is 1 plus the largest register number used. */
82 int reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
84 /* This is *not* reset after each function. It gives each CODE_LABEL
85 in the entire compilation a unique label number. */
87 static int label_num = 1;
89 /* Lowest label number in current function. */
91 static int first_label_num;
93 /* Highest label number in current function.
94 Zero means use the value of label_num instead.
95 This is nonzero only when belatedly compiling an inline function. */
97 static int last_label_num;
99 /* Value label_num had when set_new_first_and_last_label_number was called.
100 If label_num has not changed since then, last_label_num is valid. */
102 static int base_label_num;
104 /* Nonzero means do not generate NOTEs for source line numbers. */
106 static int no_line_numbers;
108 /* Commonly used rtx's, so that we only need space for one copy.
109 These are initialized once for the entire compilation.
110 All of these except perhaps the floating-point CONST_DOUBLEs
111 are unique; no other rtx-object will be equal to any of these. */
113 rtx pc_rtx; /* (PC) */
114 rtx cc0_rtx; /* (CC0) */
115 rtx cc1_rtx; /* (CC1) (not actually used nowadays) */
116 rtx const0_rtx; /* (CONST_INT 0) */
117 rtx const1_rtx; /* (CONST_INT 1) */
118 rtx const2_rtx; /* (CONST_INT 2) */
119 rtx constm1_rtx; /* (CONST_INT -1) */
120 rtx const_true_rtx; /* (CONST_INT STORE_FLAG_VALUE) */
122 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
123 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
124 record a copy of const[012]_rtx. */
126 rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
128 REAL_VALUE_TYPE dconst0;
129 REAL_VALUE_TYPE dconst1;
130 REAL_VALUE_TYPE dconst2;
131 REAL_VALUE_TYPE dconstm1;
133 /* All references to the following fixed hard registers go through
134 these unique rtl objects. On machines where the frame-pointer and
135 arg-pointer are the same register, they use the same unique object.
137 After register allocation, other rtl objects which used to be pseudo-regs
138 may be clobbered to refer to the frame-pointer register.
139 But references that were originally to the frame-pointer can be
140 distinguished from the others because they contain frame_pointer_rtx.
142 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
143 tricky: until register elimination has taken place hard_frame_pointer_rtx
144 should be used if it is being set, and frame_pointer_rtx otherwise. After
145 register elimination hard_frame_pointer_rtx should always be used.
146 On machines where the two registers are same (most) then these are the
149 In an inline procedure, the stack and frame pointer rtxs may not be
150 used for anything else. */
151 rtx stack_pointer_rtx; /* (REG:Pmode STACK_POINTER_REGNUM) */
152 rtx frame_pointer_rtx; /* (REG:Pmode FRAME_POINTER_REGNUM) */
153 rtx hard_frame_pointer_rtx; /* (REG:Pmode HARD_FRAME_POINTER_REGNUM) */
154 rtx arg_pointer_rtx; /* (REG:Pmode ARG_POINTER_REGNUM) */
155 rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
156 rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
157 rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
158 rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
159 rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
161 rtx virtual_incoming_args_rtx; /* (REG:Pmode VIRTUAL_INCOMING_ARGS_REGNUM) */
162 rtx virtual_stack_vars_rtx; /* (REG:Pmode VIRTUAL_STACK_VARS_REGNUM) */
163 rtx virtual_stack_dynamic_rtx; /* (REG:Pmode VIRTUAL_STACK_DYNAMIC_REGNUM) */
164 rtx virtual_outgoing_args_rtx; /* (REG:Pmode VIRTUAL_OUTGOING_ARGS_REGNUM) */
166 /* We make one copy of (const_int C) where C is in
167 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
168 to save space during the compilation and simplify comparisons of
171 #define MAX_SAVED_CONST_INT 64
173 static rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
175 /* The ends of the doubly-linked chain of rtl for the current function.
176 Both are reset to null at the start of rtl generation for the function.
178 start_sequence saves both of these on `sequence_stack' along with
179 `sequence_rtl_expr' and then starts a new, nested sequence of insns. */
181 static rtx first_insn = NULL;
182 static rtx last_insn = NULL;
184 /* RTL_EXPR within which the current sequence will be placed. Use to
185 prevent reuse of any temporaries within the sequence until after the
186 RTL_EXPR is emitted. */
188 tree sequence_rtl_expr = NULL;
190 /* INSN_UID for next insn emitted.
191 Reset to 1 for each function compiled. */
193 static int cur_insn_uid = 1;
195 /* Line number and source file of the last line-number NOTE emitted.
196 This is used to avoid generating duplicates. */
198 static int last_linenum = 0;
199 static char *last_filename = 0;
201 /* A vector indexed by pseudo reg number. The allocated length
202 of this vector is regno_pointer_flag_length. Since this
203 vector is needed during the expansion phase when the total
204 number of registers in the function is not yet known,
205 it is copied and made bigger when necessary. */
207 char *regno_pointer_flag;
208 int regno_pointer_flag_length;
210 /* Indexed by pseudo register number, gives the rtx for that pseudo.
211 Allocated in parallel with regno_pointer_flag. */
215 /* Stack of pending (incomplete) sequences saved by `start_sequence'.
216 Each element describes one pending sequence.
217 The main insn-chain is saved in the last element of the chain,
218 unless the chain is empty. */
220 struct sequence_stack *sequence_stack;
222 /* start_sequence and gen_sequence can make a lot of rtx expressions which are
223 shortly thrown away. We use two mechanisms to prevent this waste:
225 First, we keep a list of the expressions used to represent the sequence
226 stack in sequence_element_free_list.
228 Second, for sizes up to 5 elements, we keep a SEQUENCE and its associated
229 rtvec for use by gen_sequence. One entry for each size is sufficient
230 because most cases are calls to gen_sequence followed by immediately
231 emitting the SEQUENCE. Reuse is safe since emitting a sequence is
232 destructive on the insn in it anyway and hence can't be redone.
234 We do not bother to save this cached data over nested function calls.
235 Instead, we just reinitialize them. */
237 #define SEQUENCE_RESULT_SIZE 5
239 static struct sequence_stack *sequence_element_free_list;
240 static rtx sequence_result[SEQUENCE_RESULT_SIZE];
242 extern int rtx_equal_function_value_matters;
244 /* Filename and line number of last line-number note,
245 whether we actually emitted it or not. */
246 extern char *emit_filename;
247 extern int emit_lineno;
249 rtx change_address ();
252 extern struct obstack *rtl_obstack;
254 extern int stack_depth;
255 extern int max_stack_depth;
257 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
259 ** This routine generates an RTX of the size specified by
260 ** <code>, which is an RTX code. The RTX structure is initialized
261 ** from the arguments <element1> through <elementn>, which are
262 ** interpreted according to the specific RTX type's format. The
263 ** special machine mode associated with the rtx (if any) is specified
266 ** gen_rtx can be invoked in a way which resembles the lisp-like
267 ** rtx it will generate. For example, the following rtx structure:
269 ** (plus:QI (mem:QI (reg:SI 1))
270 ** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
272 ** ...would be generated by the following C code:
274 ** gen_rtx (PLUS, QImode,
275 ** gen_rtx (MEM, QImode,
276 ** gen_rtx (REG, SImode, 1)),
277 ** gen_rtx (MEM, QImode,
278 ** gen_rtx (PLUS, SImode,
279 ** gen_rtx (REG, SImode, 2),
280 ** gen_rtx (REG, SImode, 3)))),
285 gen_rtx VPROTO((enum rtx_code code, enum machine_mode mode, ...))
289 enum machine_mode mode;
292 register int i; /* Array indices... */
293 register char *fmt; /* Current rtx's format... */
294 register rtx rt_val; /* RTX to return to caller... */
299 code = va_arg (p, enum rtx_code);
300 mode = va_arg (p, enum machine_mode);
303 if (code == CONST_INT)
305 HOST_WIDE_INT arg = va_arg (p, HOST_WIDE_INT);
307 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
308 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
310 if (const_true_rtx && arg == STORE_FLAG_VALUE)
311 return const_true_rtx;
313 rt_val = rtx_alloc (code);
314 INTVAL (rt_val) = arg;
316 else if (code == REG)
318 int regno = va_arg (p, int);
320 /* In case the MD file explicitly references the frame pointer, have
321 all such references point to the same frame pointer. This is used
322 during frame pointer elimination to distinguish the explicit
323 references to these registers from pseudos that happened to be
326 If we have eliminated the frame pointer or arg pointer, we will
327 be using it as a normal register, for example as a spill register.
328 In such cases, we might be accessing it in a mode that is not
329 Pmode and therefore cannot use the pre-allocated rtx.
331 Also don't do this when we are making new REGs in reload,
332 since we don't want to get confused with the real pointers. */
334 if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM && mode == Pmode
335 && ! reload_in_progress)
336 return frame_pointer_rtx;
337 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
338 if (hard_frame_pointer_rtx && regno == HARD_FRAME_POINTER_REGNUM
339 && mode == Pmode && ! reload_in_progress)
340 return hard_frame_pointer_rtx;
342 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
343 if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM && mode == Pmode
344 && ! reload_in_progress)
345 return arg_pointer_rtx;
347 if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM && mode == Pmode
348 && ! reload_in_progress)
349 return stack_pointer_rtx;
352 rt_val = rtx_alloc (code);
354 REGNO (rt_val) = regno;
360 rt_val = rtx_alloc (code); /* Allocate the storage space. */
361 rt_val->mode = mode; /* Store the machine mode... */
363 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
364 for (i = 0; i < GET_RTX_LENGTH (code); i++)
368 case '0': /* Unused field. */
371 case 'i': /* An integer? */
372 XINT (rt_val, i) = va_arg (p, int);
375 case 'w': /* A wide integer? */
376 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
379 case 's': /* A string? */
380 XSTR (rt_val, i) = va_arg (p, char *);
383 case 'e': /* An expression? */
384 case 'u': /* An insn? Same except when printing. */
385 XEXP (rt_val, i) = va_arg (p, rtx);
388 case 'E': /* An RTX vector? */
389 XVEC (rt_val, i) = va_arg (p, rtvec);
398 return rt_val; /* Return the new RTX... */
401 /* gen_rtvec (n, [rt1, ..., rtn])
403 ** This routine creates an rtvec and stores within it the
404 ** pointers to rtx's which are its arguments.
409 gen_rtvec VPROTO((int n, ...))
425 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
427 vector = (rtx *) alloca (n * sizeof (rtx));
429 for (i = 0; i < n; i++)
430 vector[i] = va_arg (p, rtx);
433 return gen_rtvec_v (n, vector);
437 gen_rtvec_v (n, argp)
442 register rtvec rt_val;
445 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
447 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
449 for (i = 0; i < n; i++)
450 rt_val->elem[i].rtx = *argp++;
455 /* Generate a REG rtx for a new pseudo register of mode MODE.
456 This pseudo is assigned the next sequential register number. */
460 enum machine_mode mode;
464 /* Don't let anything called by or after reload create new registers
465 (actually, registers can't be created after flow, but this is a good
468 if (reload_in_progress || reload_completed)
471 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
472 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
474 /* For complex modes, don't make a single pseudo.
475 Instead, make a CONCAT of two pseudos.
476 This allows noncontiguous allocation of the real and imaginary parts,
477 which makes much better code. Besides, allocating DCmode
478 pseudos overstrains reload on some machines like the 386. */
479 rtx realpart, imagpart;
480 int size = GET_MODE_UNIT_SIZE (mode);
481 enum machine_mode partmode
482 = mode_for_size (size * BITS_PER_UNIT,
483 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
484 ? MODE_FLOAT : MODE_INT),
487 realpart = gen_reg_rtx (partmode);
488 imagpart = gen_reg_rtx (partmode);
489 return gen_rtx (CONCAT, mode, realpart, imagpart);
492 /* Make sure regno_pointer_flag and regno_reg_rtx are large
493 enough to have an element for this pseudo reg number. */
495 if (reg_rtx_no == regno_pointer_flag_length)
499 (char *) oballoc (regno_pointer_flag_length * 2);
500 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
501 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
502 regno_pointer_flag = new;
504 new1 = (rtx *) oballoc (regno_pointer_flag_length * 2 * sizeof (rtx));
505 bcopy ((char *) regno_reg_rtx, (char *) new1,
506 regno_pointer_flag_length * sizeof (rtx));
507 bzero ((char *) &new1[regno_pointer_flag_length],
508 regno_pointer_flag_length * sizeof (rtx));
509 regno_reg_rtx = new1;
511 regno_pointer_flag_length *= 2;
514 val = gen_rtx (REG, mode, reg_rtx_no);
515 regno_reg_rtx[reg_rtx_no++] = val;
519 /* Identify REG as a probable pointer register. */
522 mark_reg_pointer (reg)
525 REGNO_POINTER_FLAG (REGNO (reg)) = 1;
528 /* Return 1 plus largest pseudo reg number used in the current function. */
536 /* Return 1 + the largest label number used so far in the current function. */
541 if (last_label_num && label_num == base_label_num)
542 return last_label_num;
546 /* Return first label number used in this function (if any were used). */
549 get_first_label_num ()
551 return first_label_num;
554 /* Return a value representing some low-order bits of X, where the number
555 of low-order bits is given by MODE. Note that no conversion is done
556 between floating-point and fixed-point values, rather, the bit
557 representation is returned.
559 This function handles the cases in common between gen_lowpart, below,
560 and two variants in cse.c and combine.c. These are the cases that can
561 be safely handled at all points in the compilation.
563 If this is not a case we can handle, return 0. */
566 gen_lowpart_common (mode, x)
567 enum machine_mode mode;
572 if (GET_MODE (x) == mode)
575 /* MODE must occupy no more words than the mode of X. */
576 if (GET_MODE (x) != VOIDmode
577 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
578 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
582 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
583 word = ((GET_MODE_SIZE (GET_MODE (x))
584 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
587 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
588 && (GET_MODE_CLASS (mode) == MODE_INT
589 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
591 /* If we are getting the low-order part of something that has been
592 sign- or zero-extended, we can either just use the object being
593 extended or make a narrower extension. If we want an even smaller
594 piece than the size of the object being extended, call ourselves
597 This case is used mostly by combine and cse. */
599 if (GET_MODE (XEXP (x, 0)) == mode)
601 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
602 return gen_lowpart_common (mode, XEXP (x, 0));
603 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
604 return gen_rtx (GET_CODE (x), mode, XEXP (x, 0));
606 else if (GET_CODE (x) == SUBREG
607 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
608 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
609 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
611 : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x)));
612 else if (GET_CODE (x) == REG)
614 /* If the register is not valid for MODE, return 0. If we don't
615 do this, there is no way to fix up the resulting REG later.
616 But we do do this if the current REG is not valid for its
617 mode. This latter is a kludge, but is required due to the
618 way that parameters are passed on some machines, most
620 if (REGNO (x) < FIRST_PSEUDO_REGISTER
621 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
622 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
624 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
625 /* integrate.c can't handle parts of a return value register. */
626 && (! REG_FUNCTION_VALUE_P (x)
627 || ! rtx_equal_function_value_matters)
628 /* We want to keep the stack, frame, and arg pointers
630 && x != frame_pointer_rtx
631 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
632 && x != arg_pointer_rtx
634 && x != stack_pointer_rtx)
635 return gen_rtx (REG, mode, REGNO (x) + word);
637 return gen_rtx (SUBREG, mode, x, word);
639 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
640 from the low-order part of the constant. */
641 else if ((GET_MODE_CLASS (mode) == MODE_INT
642 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
643 && GET_MODE (x) == VOIDmode
644 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
646 /* If MODE is twice the host word size, X is already the desired
647 representation. Otherwise, if MODE is wider than a word, we can't
648 do this. If MODE is exactly a word, return just one CONST_INT.
649 If MODE is smaller than a word, clear the bits that don't belong
650 in our mode, unless they and our sign bit are all one. So we get
651 either a reasonable negative value or a reasonable unsigned value
654 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
656 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
658 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
659 return (GET_CODE (x) == CONST_INT ? x
660 : GEN_INT (CONST_DOUBLE_LOW (x)));
663 /* MODE must be narrower than HOST_BITS_PER_INT. */
664 int width = GET_MODE_BITSIZE (mode);
665 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
666 : CONST_DOUBLE_LOW (x));
668 if (((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
669 != ((HOST_WIDE_INT) (-1) << (width - 1))))
670 val &= ((HOST_WIDE_INT) 1 << width) - 1;
672 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
677 /* If X is an integral constant but we want it in floating-point, it
678 must be the case that we have a union of an integer and a floating-point
679 value. If the machine-parameters allow it, simulate that union here
680 and return the result. The two-word and single-word cases are
683 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
684 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
685 || flag_pretend_float)
686 && GET_MODE_CLASS (mode) == MODE_FLOAT
687 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
688 && GET_CODE (x) == CONST_INT
689 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
690 #ifdef REAL_ARITHMETIC
696 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
697 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
701 union {HOST_WIDE_INT i; float d; } u;
704 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
707 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
708 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
709 || flag_pretend_float)
710 && GET_MODE_CLASS (mode) == MODE_FLOAT
711 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
712 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
713 && GET_MODE (x) == VOIDmode
714 && (sizeof (double) * HOST_BITS_PER_CHAR
715 == 2 * HOST_BITS_PER_WIDE_INT))
716 #ifdef REAL_ARITHMETIC
720 HOST_WIDE_INT low, high;
722 if (GET_CODE (x) == CONST_INT)
723 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
725 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
727 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
729 if (WORDS_BIG_ENDIAN)
730 i[0] = high, i[1] = low;
732 i[0] = low, i[1] = high;
734 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
735 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
739 union {HOST_WIDE_INT i[2]; double d; } u;
740 HOST_WIDE_INT low, high;
742 if (GET_CODE (x) == CONST_INT)
743 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
745 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
747 #ifdef HOST_WORDS_BIG_ENDIAN
748 u.i[0] = high, u.i[1] = low;
750 u.i[0] = low, u.i[1] = high;
753 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
756 /* Similarly, if this is converting a floating-point value into a
757 single-word integer. Only do this is the host and target parameters are
760 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
761 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
762 || flag_pretend_float)
763 && (GET_MODE_CLASS (mode) == MODE_INT
764 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
765 && GET_CODE (x) == CONST_DOUBLE
766 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
767 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
768 return operand_subword (x, 0, 0, GET_MODE (x));
770 /* Similarly, if this is converting a floating-point value into a
771 two-word integer, we can do this one word at a time and make an
772 integer. Only do this is the host and target parameters are
775 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
776 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
777 || flag_pretend_float)
778 && (GET_MODE_CLASS (mode) == MODE_INT
779 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
780 && GET_CODE (x) == CONST_DOUBLE
781 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
782 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
784 rtx lowpart = operand_subword (x, WORDS_BIG_ENDIAN, 0, GET_MODE (x));
785 rtx highpart = operand_subword (x, ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
787 if (lowpart && GET_CODE (lowpart) == CONST_INT
788 && highpart && GET_CODE (highpart) == CONST_INT)
789 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
792 /* Otherwise, we can't do this. */
796 /* Return the real part (which has mode MODE) of a complex value X.
797 This always comes at the low address in memory. */
800 gen_realpart (mode, x)
801 enum machine_mode mode;
804 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
806 else if (WORDS_BIG_ENDIAN)
807 return gen_highpart (mode, x);
809 return gen_lowpart (mode, x);
812 /* Return the imaginary part (which has mode MODE) of a complex value X.
813 This always comes at the high address in memory. */
816 gen_imagpart (mode, x)
817 enum machine_mode mode;
820 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
822 else if (WORDS_BIG_ENDIAN)
823 return gen_lowpart (mode, x);
825 return gen_highpart (mode, x);
828 /* Return 1 iff X, assumed to be a SUBREG,
829 refers to the real part of the complex value in its containing reg.
830 Complex values are always stored with the real part in the first word,
831 regardless of WORDS_BIG_ENDIAN. */
834 subreg_realpart_p (x)
837 if (GET_CODE (x) != SUBREG)
840 return SUBREG_WORD (x) == 0;
843 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
844 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
845 least-significant part of X.
846 MODE specifies how big a part of X to return;
847 it usually should not be larger than a word.
848 If X is a MEM whose address is a QUEUED, the value may be so also. */
851 gen_lowpart (mode, x)
852 enum machine_mode mode;
855 rtx result = gen_lowpart_common (mode, x);
859 else if (GET_CODE (x) == MEM)
861 /* The only additional case we can do is MEM. */
862 register int offset = 0;
863 if (WORDS_BIG_ENDIAN)
864 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
865 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
867 if (BYTES_BIG_ENDIAN)
868 /* Adjust the address so that the address-after-the-data
870 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
871 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
873 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
879 /* Like `gen_lowpart', but refer to the most significant part.
880 This is used to access the imaginary part of a complex number. */
883 gen_highpart (mode, x)
884 enum machine_mode mode;
887 /* This case loses if X is a subreg. To catch bugs early,
888 complain if an invalid MODE is used even in other cases. */
889 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
890 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
892 if (GET_CODE (x) == CONST_DOUBLE
893 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
894 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
897 return gen_rtx (CONST_INT, VOIDmode,
898 CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
899 else if (GET_CODE (x) == CONST_INT)
901 else if (GET_CODE (x) == MEM)
903 register int offset = 0;
904 if (! WORDS_BIG_ENDIAN)
905 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
906 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
908 if (! BYTES_BIG_ENDIAN
909 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
910 offset -= (GET_MODE_SIZE (mode)
911 - MIN (UNITS_PER_WORD,
912 GET_MODE_SIZE (GET_MODE (x))));
914 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
916 else if (GET_CODE (x) == SUBREG)
918 /* The only time this should occur is when we are looking at a
919 multi-word item with a SUBREG whose mode is the same as that of the
920 item. It isn't clear what we would do if it wasn't. */
921 if (SUBREG_WORD (x) != 0)
923 return gen_highpart (mode, SUBREG_REG (x));
925 else if (GET_CODE (x) == REG)
929 if (! WORDS_BIG_ENDIAN
930 && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
931 word = ((GET_MODE_SIZE (GET_MODE (x))
932 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
935 if (REGNO (x) < FIRST_PSEUDO_REGISTER
936 /* integrate.c can't handle parts of a return value register. */
937 && (! REG_FUNCTION_VALUE_P (x)
938 || ! rtx_equal_function_value_matters)
939 /* We want to keep the stack, frame, and arg pointers special. */
940 && x != frame_pointer_rtx
941 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
942 && x != arg_pointer_rtx
944 && x != stack_pointer_rtx)
945 return gen_rtx (REG, mode, REGNO (x) + word);
947 return gen_rtx (SUBREG, mode, x, word);
953 /* Return 1 iff X, assumed to be a SUBREG,
954 refers to the least significant part of its containing reg.
955 If X is not a SUBREG, always return 1 (it is its own low part!). */
961 if (GET_CODE (x) != SUBREG)
965 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
966 return (SUBREG_WORD (x)
967 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
968 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
971 return SUBREG_WORD (x) == 0;
974 /* Return subword I of operand OP.
975 The word number, I, is interpreted as the word number starting at the
976 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
977 otherwise it is the high-order word.
979 If we cannot extract the required word, we return zero. Otherwise, an
980 rtx corresponding to the requested word will be returned.
982 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
983 reload has completed, a valid address will always be returned. After
984 reload, if a valid address cannot be returned, we return zero.
986 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
987 it is the responsibility of the caller.
989 MODE is the mode of OP in case it is a CONST_INT. */
992 operand_subword (op, i, validate_address, mode)
995 int validate_address;
996 enum machine_mode mode;
999 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1001 if (mode == VOIDmode)
1002 mode = GET_MODE (op);
1004 if (mode == VOIDmode)
1007 /* If OP is narrower than a word or if we want a word outside OP, fail. */
1009 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
1010 || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
1013 /* If OP is already an integer word, return it. */
1014 if (GET_MODE_CLASS (mode) == MODE_INT
1015 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1018 /* If OP is a REG or SUBREG, we can handle it very simply. */
1019 if (GET_CODE (op) == REG)
1021 /* If the register is not valid for MODE, return 0. If we don't
1022 do this, there is no way to fix up the resulting REG later. */
1023 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1024 && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode))
1026 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1027 || (REG_FUNCTION_VALUE_P (op)
1028 && rtx_equal_function_value_matters)
1029 /* We want to keep the stack, frame, and arg pointers
1031 || op == frame_pointer_rtx
1032 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1033 || op == arg_pointer_rtx
1035 || op == stack_pointer_rtx)
1036 return gen_rtx (SUBREG, word_mode, op, i);
1038 return gen_rtx (REG, word_mode, REGNO (op) + i);
1040 else if (GET_CODE (op) == SUBREG)
1041 return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1042 else if (GET_CODE (op) == CONCAT)
1044 int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1046 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1047 return operand_subword (XEXP (op, 1), i - partwords,
1048 validate_address, mode);
1051 /* Form a new MEM at the requested address. */
1052 if (GET_CODE (op) == MEM)
1054 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1057 if (validate_address)
1059 if (reload_completed)
1061 if (! strict_memory_address_p (word_mode, addr))
1065 addr = memory_address (word_mode, addr);
1068 new = gen_rtx (MEM, word_mode, addr);
1070 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
1071 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
1072 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1077 /* The only remaining cases are when OP is a constant. If the host and
1078 target floating formats are the same, handling two-word floating
1079 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1080 are defined as returning one or two 32 bit values, respectively,
1081 and not values of BITS_PER_WORD bits. */
1082 #ifdef REAL_ARITHMETIC
1083 /* The output is some bits, the width of the target machine's word.
1084 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1086 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1087 && GET_MODE_CLASS (mode) == MODE_FLOAT
1088 && GET_MODE_BITSIZE (mode) == 64
1089 && GET_CODE (op) == CONST_DOUBLE)
1094 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1095 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1097 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1098 which the words are written depends on the word endianness.
1100 ??? This is a potential portability problem and should
1101 be fixed at some point. */
1102 if (BITS_PER_WORD == 32)
1103 return GEN_INT ((HOST_WIDE_INT) k[i]);
1104 #if HOST_BITS_PER_WIDE_INT > 32
1105 else if (BITS_PER_WORD >= 64 && i == 0)
1106 return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
1107 | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
1109 else if (BITS_PER_WORD == 16)
1116 return GEN_INT ((HOST_WIDE_INT) value);
1121 #else /* no REAL_ARITHMETIC */
1122 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1123 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1124 || flag_pretend_float)
1125 && GET_MODE_CLASS (mode) == MODE_FLOAT
1126 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1127 && GET_CODE (op) == CONST_DOUBLE)
1129 /* The constant is stored in the host's word-ordering,
1130 but we want to access it in the target's word-ordering. Some
1131 compilers don't like a conditional inside macro args, so we have two
1132 copies of the return. */
1133 #ifdef HOST_WORDS_BIG_ENDIAN
1134 return GEN_INT (i == WORDS_BIG_ENDIAN
1135 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1137 return GEN_INT (i != WORDS_BIG_ENDIAN
1138 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1141 #endif /* no REAL_ARITHMETIC */
1143 /* Single word float is a little harder, since single- and double-word
1144 values often do not have the same high-order bits. We have already
1145 verified that we want the only defined word of the single-word value. */
1146 #ifdef REAL_ARITHMETIC
1147 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1148 && GET_MODE_BITSIZE (mode) == 32
1149 && GET_CODE (op) == CONST_DOUBLE)
1154 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1155 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1156 return GEN_INT ((HOST_WIDE_INT) l);
1159 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1160 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1161 || flag_pretend_float)
1162 && GET_MODE_CLASS (mode) == MODE_FLOAT
1163 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1164 && GET_CODE (op) == CONST_DOUBLE)
1167 union {float f; HOST_WIDE_INT i; } u;
1169 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1172 return GEN_INT (u.i);
1174 #endif /* no REAL_ARITHMETIC */
1176 /* The only remaining cases that we can handle are integers.
1177 Convert to proper endianness now since these cases need it.
1178 At this point, i == 0 means the low-order word.
1180 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1181 in general. However, if OP is (const_int 0), we can just return
1184 if (op == const0_rtx)
1187 if (GET_MODE_CLASS (mode) != MODE_INT
1188 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1189 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1192 if (WORDS_BIG_ENDIAN)
1193 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1195 /* Find out which word on the host machine this value is in and get
1196 it from the constant. */
1197 val = (i / size_ratio == 0
1198 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1199 : (GET_CODE (op) == CONST_INT
1200 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1202 /* If BITS_PER_WORD is smaller than an int, get the appropriate bits. */
1203 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1204 val = ((val >> ((i % size_ratio) * BITS_PER_WORD))
1205 & (((HOST_WIDE_INT) 1
1206 << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1));
1208 return GEN_INT (val);
1211 /* Similar to `operand_subword', but never return 0. If we can't extract
1212 the required subword, put OP into a register and try again. If that fails,
1213 abort. We always validate the address in this case. It is not valid
1214 to call this function after reload; it is mostly meant for RTL
1217 MODE is the mode of OP, in case it is CONST_INT. */
1220 operand_subword_force (op, i, mode)
1223 enum machine_mode mode;
1225 rtx result = operand_subword (op, i, 1, mode);
1230 if (mode != BLKmode && mode != VOIDmode)
1231 op = force_reg (mode, op);
1233 result = operand_subword (op, i, 1, mode);
1240 /* Given a compare instruction, swap the operands.
1241 A test instruction is changed into a compare of 0 against the operand. */
1244 reverse_comparison (insn)
1247 rtx body = PATTERN (insn);
1250 if (GET_CODE (body) == SET)
1251 comp = SET_SRC (body);
1253 comp = SET_SRC (XVECEXP (body, 0, 0));
1255 if (GET_CODE (comp) == COMPARE)
1257 rtx op0 = XEXP (comp, 0);
1258 rtx op1 = XEXP (comp, 1);
1259 XEXP (comp, 0) = op1;
1260 XEXP (comp, 1) = op0;
1264 rtx new = gen_rtx (COMPARE, VOIDmode,
1265 CONST0_RTX (GET_MODE (comp)), comp);
1266 if (GET_CODE (body) == SET)
1267 SET_SRC (body) = new;
1269 SET_SRC (XVECEXP (body, 0, 0)) = new;
1273 /* Return a memory reference like MEMREF, but with its mode changed
1274 to MODE and its address changed to ADDR.
1275 (VOIDmode means don't change the mode.
1276 NULL for ADDR means don't change the address.) */
1279 change_address (memref, mode, addr)
1281 enum machine_mode mode;
1286 if (GET_CODE (memref) != MEM)
1288 if (mode == VOIDmode)
1289 mode = GET_MODE (memref);
1291 addr = XEXP (memref, 0);
1293 /* If reload is in progress or has completed, ADDR must be valid.
1294 Otherwise, we can call memory_address to make it valid. */
1295 if (reload_completed || reload_in_progress)
1297 if (! memory_address_p (mode, addr))
1301 addr = memory_address (mode, addr);
1303 new = gen_rtx (MEM, mode, addr);
1304 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
1305 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
1306 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
1310 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1317 label = (output_bytecode
1318 ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ())
1319 : gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++, NULL_PTR));
1321 LABEL_NUSES (label) = 0;
1325 /* For procedure integration. */
1327 /* Return a newly created INLINE_HEADER rtx. Should allocate this
1328 from a permanent obstack when the opportunity arises. */
1331 gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
1332 last_labelno, max_parm_regnum, max_regnum, args_size,
1333 pops_args, stack_slots, forced_labels, function_flags,
1334 outgoing_args_size, original_arg_vector,
1335 original_decl_initial)
1336 rtx first_insn, first_parm_insn;
1337 int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
1342 int outgoing_args_size;
1343 rtvec original_arg_vector;
1344 rtx original_decl_initial;
1346 rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
1347 cur_insn_uid++, NULL_RTX,
1348 first_insn, first_parm_insn,
1349 first_labelno, last_labelno,
1350 max_parm_regnum, max_regnum, args_size, pops_args,
1351 stack_slots, forced_labels, function_flags,
1353 original_arg_vector, original_decl_initial);
1357 /* Install new pointers to the first and last insns in the chain.
1358 Used for an inline-procedure after copying the insn chain. */
1361 set_new_first_and_last_insn (first, last)
1368 /* Set the range of label numbers found in the current function.
1369 This is used when belatedly compiling an inline function. */
1372 set_new_first_and_last_label_num (first, last)
1375 base_label_num = label_num;
1376 first_label_num = first;
1377 last_label_num = last;
1380 /* Save all variables describing the current status into the structure *P.
1381 This is used before starting a nested function. */
1384 save_emit_status (p)
1387 p->reg_rtx_no = reg_rtx_no;
1388 p->first_label_num = first_label_num;
1389 p->first_insn = first_insn;
1390 p->last_insn = last_insn;
1391 p->sequence_rtl_expr = sequence_rtl_expr;
1392 p->sequence_stack = sequence_stack;
1393 p->cur_insn_uid = cur_insn_uid;
1394 p->last_linenum = last_linenum;
1395 p->last_filename = last_filename;
1396 p->regno_pointer_flag = regno_pointer_flag;
1397 p->regno_pointer_flag_length = regno_pointer_flag_length;
1398 p->regno_reg_rtx = regno_reg_rtx;
1401 /* Restore all variables describing the current status from the structure *P.
1402 This is used after a nested function. */
1405 restore_emit_status (p)
1410 reg_rtx_no = p->reg_rtx_no;
1411 first_label_num = p->first_label_num;
1413 first_insn = p->first_insn;
1414 last_insn = p->last_insn;
1415 sequence_rtl_expr = p->sequence_rtl_expr;
1416 sequence_stack = p->sequence_stack;
1417 cur_insn_uid = p->cur_insn_uid;
1418 last_linenum = p->last_linenum;
1419 last_filename = p->last_filename;
1420 regno_pointer_flag = p->regno_pointer_flag;
1421 regno_pointer_flag_length = p->regno_pointer_flag_length;
1422 regno_reg_rtx = p->regno_reg_rtx;
1424 /* Clear our cache of rtx expressions for start_sequence and gen_sequence. */
1425 sequence_element_free_list = 0;
1426 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
1427 sequence_result[i] = 0;
1430 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1431 It does not work to do this twice, because the mark bits set here
1432 are not cleared afterwards. */
1435 unshare_all_rtl (insn)
1438 for (; insn; insn = NEXT_INSN (insn))
1439 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
1440 || GET_CODE (insn) == CALL_INSN)
1442 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1443 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1444 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1447 /* Make sure the addresses of stack slots found outside the insn chain
1448 (such as, in DECL_RTL of a variable) are not shared
1449 with the insn chain.
1451 This special care is necessary when the stack slot MEM does not
1452 actually appear in the insn chain. If it does appear, its address
1453 is unshared from all else at that point. */
1455 copy_rtx_if_shared (stack_slot_list);
1458 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1459 Recursively does the same for subexpressions. */
1462 copy_rtx_if_shared (orig)
1465 register rtx x = orig;
1467 register enum rtx_code code;
1468 register char *format_ptr;
1474 code = GET_CODE (x);
1476 /* These types may be freely shared. */
1489 /* SCRATCH must be shared because they represent distinct values. */
1493 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1494 a LABEL_REF, it isn't sharable. */
1495 if (GET_CODE (XEXP (x, 0)) == PLUS
1496 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1497 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1506 /* The chain of insns is not being copied. */
1510 /* A MEM is allowed to be shared if its address is constant
1511 or is a constant plus one of the special registers. */
1512 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1513 || XEXP (x, 0) == virtual_stack_vars_rtx
1514 || XEXP (x, 0) == virtual_incoming_args_rtx)
1517 if (GET_CODE (XEXP (x, 0)) == PLUS
1518 && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
1519 || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
1520 && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
1522 /* This MEM can appear in more than one place,
1523 but its address better not be shared with anything else. */
1525 XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
1531 /* This rtx may not be shared. If it has already been seen,
1532 replace it with a copy of itself. */
1538 copy = rtx_alloc (code);
1539 bcopy ((char *) x, (char *) copy,
1540 (sizeof (*copy) - sizeof (copy->fld)
1541 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1547 /* Now scan the subexpressions recursively.
1548 We can store any replaced subexpressions directly into X
1549 since we know X is not shared! Any vectors in X
1550 must be copied if X was copied. */
1552 format_ptr = GET_RTX_FORMAT (code);
1554 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1556 switch (*format_ptr++)
1559 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1563 if (XVEC (x, i) != NULL)
1566 int len = XVECLEN (x, i);
1568 if (copied && len > 0)
1569 XVEC (x, i) = gen_rtvec_v (len, &XVECEXP (x, i, 0));
1570 for (j = 0; j < len; j++)
1571 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1579 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1580 to look for shared sub-parts. */
1583 reset_used_flags (x)
1587 register enum rtx_code code;
1588 register char *format_ptr;
1593 code = GET_CODE (x);
1595 /* These types may be freely shared so we needn't do any reseting
1616 /* The chain of insns is not being copied. */
1622 format_ptr = GET_RTX_FORMAT (code);
1623 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1625 switch (*format_ptr++)
1628 reset_used_flags (XEXP (x, i));
1632 for (j = 0; j < XVECLEN (x, i); j++)
1633 reset_used_flags (XVECEXP (x, i, j));
1639 /* Copy X if necessary so that it won't be altered by changes in OTHER.
1640 Return X or the rtx for the pseudo reg the value of X was copied into.
1641 OTHER must be valid as a SET_DEST. */
1644 make_safe_from (x, other)
1648 switch (GET_CODE (other))
1651 other = SUBREG_REG (other);
1653 case STRICT_LOW_PART:
1656 other = XEXP (other, 0);
1662 if ((GET_CODE (other) == MEM
1664 && GET_CODE (x) != REG
1665 && GET_CODE (x) != SUBREG)
1666 || (GET_CODE (other) == REG
1667 && (REGNO (other) < FIRST_PSEUDO_REGISTER
1668 || reg_mentioned_p (other, x))))
1670 rtx temp = gen_reg_rtx (GET_MODE (x));
1671 emit_move_insn (temp, x);
1677 /* Emission of insns (adding them to the doubly-linked list). */
1679 /* Return the first insn of the current sequence or current function. */
1687 /* Return the last insn emitted in current sequence or current function. */
1695 /* Specify a new insn as the last in the chain. */
1698 set_last_insn (insn)
1701 if (NEXT_INSN (insn) != 0)
1706 /* Return the last insn emitted, even if it is in a sequence now pushed. */
1709 get_last_insn_anywhere ()
1711 struct sequence_stack *stack;
1714 for (stack = sequence_stack; stack; stack = stack->next)
1715 if (stack->last != 0)
1720 /* Return a number larger than any instruction's uid in this function. */
1725 return cur_insn_uid;
1728 /* Return the next insn. If it is a SEQUENCE, return the first insn
1737 insn = NEXT_INSN (insn);
1738 if (insn && GET_CODE (insn) == INSN
1739 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1740 insn = XVECEXP (PATTERN (insn), 0, 0);
1746 /* Return the previous insn. If it is a SEQUENCE, return the last insn
1750 previous_insn (insn)
1755 insn = PREV_INSN (insn);
1756 if (insn && GET_CODE (insn) == INSN
1757 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1758 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
1764 /* Return the next insn after INSN that is not a NOTE. This routine does not
1765 look inside SEQUENCEs. */
1768 next_nonnote_insn (insn)
1773 insn = NEXT_INSN (insn);
1774 if (insn == 0 || GET_CODE (insn) != NOTE)
1781 /* Return the previous insn before INSN that is not a NOTE. This routine does
1782 not look inside SEQUENCEs. */
1785 prev_nonnote_insn (insn)
1790 insn = PREV_INSN (insn);
1791 if (insn == 0 || GET_CODE (insn) != NOTE)
1798 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
1799 or 0, if there is none. This routine does not look inside
1803 next_real_insn (insn)
1808 insn = NEXT_INSN (insn);
1809 if (insn == 0 || GET_CODE (insn) == INSN
1810 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
1817 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
1818 or 0, if there is none. This routine does not look inside
1822 prev_real_insn (insn)
1827 insn = PREV_INSN (insn);
1828 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1829 || GET_CODE (insn) == JUMP_INSN)
1836 /* Find the next insn after INSN that really does something. This routine
1837 does not look inside SEQUENCEs. Until reload has completed, this is the
1838 same as next_real_insn. */
1841 next_active_insn (insn)
1846 insn = NEXT_INSN (insn);
1848 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1849 || (GET_CODE (insn) == INSN
1850 && (! reload_completed
1851 || (GET_CODE (PATTERN (insn)) != USE
1852 && GET_CODE (PATTERN (insn)) != CLOBBER))))
1859 /* Find the last insn before INSN that really does something. This routine
1860 does not look inside SEQUENCEs. Until reload has completed, this is the
1861 same as prev_real_insn. */
1864 prev_active_insn (insn)
1869 insn = PREV_INSN (insn);
1871 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1872 || (GET_CODE (insn) == INSN
1873 && (! reload_completed
1874 || (GET_CODE (PATTERN (insn)) != USE
1875 && GET_CODE (PATTERN (insn)) != CLOBBER))))
1882 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
1890 insn = NEXT_INSN (insn);
1891 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
1898 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
1906 insn = PREV_INSN (insn);
1907 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
1915 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
1916 and REG_CC_USER notes so we can find it. */
1919 link_cc0_insns (insn)
1922 rtx user = next_nonnote_insn (insn);
1924 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
1925 user = XVECEXP (PATTERN (user), 0, 0);
1927 REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn,
1929 REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn));
1932 /* Return the next insn that uses CC0 after INSN, which is assumed to
1933 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
1934 applied to the result of this function should yield INSN).
1936 Normally, this is simply the next insn. However, if a REG_CC_USER note
1937 is present, it contains the insn that uses CC0.
1939 Return 0 if we can't find the insn. */
1942 next_cc0_user (insn)
1945 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
1948 return XEXP (note, 0);
1950 insn = next_nonnote_insn (insn);
1951 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1952 insn = XVECEXP (PATTERN (insn), 0, 0);
1954 if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1955 && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
1961 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
1962 note, it is the previous insn. */
1965 prev_cc0_setter (insn)
1968 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1972 return XEXP (note, 0);
1974 insn = prev_nonnote_insn (insn);
1975 if (! sets_cc0_p (PATTERN (insn)))
1982 /* Try splitting insns that can be split for better scheduling.
1983 PAT is the pattern which might split.
1984 TRIAL is the insn providing PAT.
1985 LAST is non-zero if we should return the last insn of the sequence produced.
1987 If this routine succeeds in splitting, it returns the first or last
1988 replacement insn depending on the value of LAST. Otherwise, it
1989 returns TRIAL. If the insn to be returned can be split, it will be. */
1992 try_split (pat, trial, last)
1996 rtx before = PREV_INSN (trial);
1997 rtx after = NEXT_INSN (trial);
1998 rtx seq = split_insns (pat, trial);
1999 int has_barrier = 0;
2002 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2003 We may need to handle this specially. */
2004 if (after && GET_CODE (after) == BARRIER)
2007 after = NEXT_INSN (after);
2012 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2013 The latter case will normally arise only when being done so that
2014 it, in turn, will be split (SFmode on the 29k is an example). */
2015 if (GET_CODE (seq) == SEQUENCE)
2017 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2018 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2019 increment the usage count so we don't delete the label. */
2022 if (GET_CODE (trial) == JUMP_INSN)
2023 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2024 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2026 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2028 if (JUMP_LABEL (trial))
2029 LABEL_NUSES (JUMP_LABEL (trial))++;
2032 tem = emit_insn_after (seq, before);
2034 delete_insn (trial);
2036 emit_barrier_after (tem);
2038 /* Recursively call try_split for each new insn created; by the
2039 time control returns here that insn will be fully split, so
2040 set LAST and continue from the insn after the one returned.
2041 We can't use next_active_insn here since AFTER may be a note.
2042 Ignore deleted insns, which can be occur if not optimizing. */
2043 for (tem = NEXT_INSN (before); tem != after;
2044 tem = NEXT_INSN (tem))
2045 if (! INSN_DELETED_P (tem))
2046 tem = try_split (PATTERN (tem), tem, 1);
2048 /* Avoid infinite loop if the result matches the original pattern. */
2049 else if (rtx_equal_p (seq, pat))
2053 PATTERN (trial) = seq;
2054 INSN_CODE (trial) = -1;
2055 try_split (seq, trial, last);
2058 /* Return either the first or the last insn, depending on which was
2060 return last ? prev_active_insn (after) : next_active_insn (before);
2066 /* Make and return an INSN rtx, initializing all its slots.
2067 Store PATTERN in the pattern slots. */
2070 make_insn_raw (pattern)
2075 insn = rtx_alloc (INSN);
2076 INSN_UID (insn) = cur_insn_uid++;
2078 PATTERN (insn) = pattern;
2079 INSN_CODE (insn) = -1;
2080 LOG_LINKS (insn) = NULL;
2081 REG_NOTES (insn) = NULL;
2086 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2089 make_jump_insn_raw (pattern)
2094 insn = rtx_alloc (JUMP_INSN);
2095 INSN_UID (insn) = cur_insn_uid++;
2097 PATTERN (insn) = pattern;
2098 INSN_CODE (insn) = -1;
2099 LOG_LINKS (insn) = NULL;
2100 REG_NOTES (insn) = NULL;
2101 JUMP_LABEL (insn) = NULL;
2106 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2109 make_call_insn_raw (pattern)
2114 insn = rtx_alloc (CALL_INSN);
2115 INSN_UID (insn) = cur_insn_uid++;
2117 PATTERN (insn) = pattern;
2118 INSN_CODE (insn) = -1;
2119 LOG_LINKS (insn) = NULL;
2120 REG_NOTES (insn) = NULL;
2121 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2126 /* Add INSN to the end of the doubly-linked list.
2127 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2133 PREV_INSN (insn) = last_insn;
2134 NEXT_INSN (insn) = 0;
2136 if (NULL != last_insn)
2137 NEXT_INSN (last_insn) = insn;
2139 if (NULL == first_insn)
2145 /* Add INSN into the doubly-linked list after insn AFTER. This and
2146 the next should be the only functions called to insert an insn once
2147 delay slots have been filled since only they know how to update a
2151 add_insn_after (insn, after)
2154 rtx next = NEXT_INSN (after);
2156 if (optimize && INSN_DELETED_P (after))
2159 NEXT_INSN (insn) = next;
2160 PREV_INSN (insn) = after;
2164 PREV_INSN (next) = insn;
2165 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2166 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2168 else if (last_insn == after)
2172 struct sequence_stack *stack = sequence_stack;
2173 /* Scan all pending sequences too. */
2174 for (; stack; stack = stack->next)
2175 if (after == stack->last)
2185 NEXT_INSN (after) = insn;
2186 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2188 rtx sequence = PATTERN (after);
2189 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2193 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2194 the previous should be the only functions called to insert an insn once
2195 delay slots have been filled since only they know how to update a
2199 add_insn_before (insn, before)
2202 rtx prev = PREV_INSN (before);
2204 if (optimize && INSN_DELETED_P (before))
2207 PREV_INSN (insn) = prev;
2208 NEXT_INSN (insn) = before;
2212 NEXT_INSN (prev) = insn;
2213 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2215 rtx sequence = PATTERN (prev);
2216 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2219 else if (first_insn == before)
2223 struct sequence_stack *stack = sequence_stack;
2224 /* Scan all pending sequences too. */
2225 for (; stack; stack = stack->next)
2226 if (before == stack->first)
2228 stack->first = insn;
2236 PREV_INSN (before) = insn;
2237 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2238 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2241 /* Delete all insns made since FROM.
2242 FROM becomes the new last instruction. */
2245 delete_insns_since (from)
2251 NEXT_INSN (from) = 0;
2255 /* This function is deprecated, please use sequences instead.
2257 Move a consecutive bunch of insns to a different place in the chain.
2258 The insns to be moved are those between FROM and TO.
2259 They are moved to a new position after the insn AFTER.
2260 AFTER must not be FROM or TO or any insn in between.
2262 This function does not know about SEQUENCEs and hence should not be
2263 called after delay-slot filling has been done. */
2266 reorder_insns (from, to, after)
2267 rtx from, to, after;
2269 /* Splice this bunch out of where it is now. */
2270 if (PREV_INSN (from))
2271 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2273 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2274 if (last_insn == to)
2275 last_insn = PREV_INSN (from);
2276 if (first_insn == from)
2277 first_insn = NEXT_INSN (to);
2279 /* Make the new neighbors point to it and it to them. */
2280 if (NEXT_INSN (after))
2281 PREV_INSN (NEXT_INSN (after)) = to;
2283 NEXT_INSN (to) = NEXT_INSN (after);
2284 PREV_INSN (from) = after;
2285 NEXT_INSN (after) = from;
2286 if (after == last_insn)
2290 /* Return the line note insn preceding INSN. */
2293 find_line_note (insn)
2296 if (no_line_numbers)
2299 for (; insn; insn = PREV_INSN (insn))
2300 if (GET_CODE (insn) == NOTE
2301 && NOTE_LINE_NUMBER (insn) >= 0)
2307 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2308 of the moved insns when debugging. This may insert a note between AFTER
2309 and FROM, and another one after TO. */
2312 reorder_insns_with_line_notes (from, to, after)
2313 rtx from, to, after;
2315 rtx from_line = find_line_note (from);
2316 rtx after_line = find_line_note (after);
2318 reorder_insns (from, to, after);
2320 if (from_line == after_line)
2324 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2325 NOTE_LINE_NUMBER (from_line),
2328 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2329 NOTE_LINE_NUMBER (after_line),
2333 /* Emit an insn of given code and pattern
2334 at a specified place within the doubly-linked list. */
2336 /* Make an instruction with body PATTERN
2337 and output it before the instruction BEFORE. */
2340 emit_insn_before (pattern, before)
2341 register rtx pattern, before;
2343 register rtx insn = before;
2345 if (GET_CODE (pattern) == SEQUENCE)
2349 for (i = 0; i < XVECLEN (pattern, 0); i++)
2351 insn = XVECEXP (pattern, 0, i);
2352 add_insn_before (insn, before);
2354 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2355 sequence_result[XVECLEN (pattern, 0)] = pattern;
2359 insn = make_insn_raw (pattern);
2360 add_insn_before (insn, before);
2366 /* Make an instruction with body PATTERN and code JUMP_INSN
2367 and output it before the instruction BEFORE. */
2370 emit_jump_insn_before (pattern, before)
2371 register rtx pattern, before;
2375 if (GET_CODE (pattern) == SEQUENCE)
2376 insn = emit_insn_before (pattern, before);
2379 insn = make_jump_insn_raw (pattern);
2380 add_insn_before (insn, before);
2386 /* Make an instruction with body PATTERN and code CALL_INSN
2387 and output it before the instruction BEFORE. */
2390 emit_call_insn_before (pattern, before)
2391 register rtx pattern, before;
2395 if (GET_CODE (pattern) == SEQUENCE)
2396 insn = emit_insn_before (pattern, before);
2399 insn = make_call_insn_raw (pattern);
2400 add_insn_before (insn, before);
2401 PUT_CODE (insn, CALL_INSN);
2407 /* Make an insn of code BARRIER
2408 and output it before the insn AFTER. */
2411 emit_barrier_before (before)
2412 register rtx before;
2414 register rtx insn = rtx_alloc (BARRIER);
2416 INSN_UID (insn) = cur_insn_uid++;
2418 add_insn_before (insn, before);
2422 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
2425 emit_note_before (subtype, before)
2429 register rtx note = rtx_alloc (NOTE);
2430 INSN_UID (note) = cur_insn_uid++;
2431 NOTE_SOURCE_FILE (note) = 0;
2432 NOTE_LINE_NUMBER (note) = subtype;
2434 add_insn_before (note, before);
2438 /* Make an insn of code INSN with body PATTERN
2439 and output it after the insn AFTER. */
2442 emit_insn_after (pattern, after)
2443 register rtx pattern, after;
2445 register rtx insn = after;
2447 if (GET_CODE (pattern) == SEQUENCE)
2451 for (i = 0; i < XVECLEN (pattern, 0); i++)
2453 insn = XVECEXP (pattern, 0, i);
2454 add_insn_after (insn, after);
2457 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2458 sequence_result[XVECLEN (pattern, 0)] = pattern;
2462 insn = make_insn_raw (pattern);
2463 add_insn_after (insn, after);
2469 /* Similar to emit_insn_after, except that line notes are to be inserted so
2470 as to act as if this insn were at FROM. */
2473 emit_insn_after_with_line_notes (pattern, after, from)
2474 rtx pattern, after, from;
2476 rtx from_line = find_line_note (from);
2477 rtx after_line = find_line_note (after);
2478 rtx insn = emit_insn_after (pattern, after);
2481 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2482 NOTE_LINE_NUMBER (from_line),
2486 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2487 NOTE_LINE_NUMBER (after_line),
2491 /* Make an insn of code JUMP_INSN with body PATTERN
2492 and output it after the insn AFTER. */
2495 emit_jump_insn_after (pattern, after)
2496 register rtx pattern, after;
2500 if (GET_CODE (pattern) == SEQUENCE)
2501 insn = emit_insn_after (pattern, after);
2504 insn = make_jump_insn_raw (pattern);
2505 add_insn_after (insn, after);
2511 /* Make an insn of code BARRIER
2512 and output it after the insn AFTER. */
2515 emit_barrier_after (after)
2518 register rtx insn = rtx_alloc (BARRIER);
2520 INSN_UID (insn) = cur_insn_uid++;
2522 add_insn_after (insn, after);
2526 /* Emit the label LABEL after the insn AFTER. */
2529 emit_label_after (label, after)
2532 /* This can be called twice for the same label
2533 as a result of the confusion that follows a syntax error!
2534 So make it harmless. */
2535 if (INSN_UID (label) == 0)
2537 INSN_UID (label) = cur_insn_uid++;
2538 add_insn_after (label, after);
2544 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
2547 emit_note_after (subtype, after)
2551 register rtx note = rtx_alloc (NOTE);
2552 INSN_UID (note) = cur_insn_uid++;
2553 NOTE_SOURCE_FILE (note) = 0;
2554 NOTE_LINE_NUMBER (note) = subtype;
2555 add_insn_after (note, after);
2559 /* Emit a line note for FILE and LINE after the insn AFTER. */
2562 emit_line_note_after (file, line, after)
2569 if (no_line_numbers && line > 0)
2575 note = rtx_alloc (NOTE);
2576 INSN_UID (note) = cur_insn_uid++;
2577 NOTE_SOURCE_FILE (note) = file;
2578 NOTE_LINE_NUMBER (note) = line;
2579 add_insn_after (note, after);
2583 /* Make an insn of code INSN with pattern PATTERN
2584 and add it to the end of the doubly-linked list.
2585 If PATTERN is a SEQUENCE, take the elements of it
2586 and emit an insn for each element.
2588 Returns the last insn emitted. */
2594 rtx insn = last_insn;
2596 if (GET_CODE (pattern) == SEQUENCE)
2600 for (i = 0; i < XVECLEN (pattern, 0); i++)
2602 insn = XVECEXP (pattern, 0, i);
2605 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2606 sequence_result[XVECLEN (pattern, 0)] = pattern;
2610 insn = make_insn_raw (pattern);
2617 /* Emit the insns in a chain starting with INSN.
2618 Return the last insn emitted. */
2628 rtx next = NEXT_INSN (insn);
2637 /* Emit the insns in a chain starting with INSN and place them in front of
2638 the insn BEFORE. Return the last insn emitted. */
2641 emit_insns_before (insn, before)
2649 rtx next = NEXT_INSN (insn);
2650 add_insn_before (insn, before);
2658 /* Emit the insns in a chain starting with FIRST and place them in back of
2659 the insn AFTER. Return the last insn emitted. */
2662 emit_insns_after (first, after)
2667 register rtx after_after;
2675 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
2678 after_after = NEXT_INSN (after);
2680 NEXT_INSN (after) = first;
2681 PREV_INSN (first) = after;
2682 NEXT_INSN (last) = after_after;
2684 PREV_INSN (after_after) = last;
2686 if (after == last_insn)
2691 /* Make an insn of code JUMP_INSN with pattern PATTERN
2692 and add it to the end of the doubly-linked list. */
2695 emit_jump_insn (pattern)
2698 if (GET_CODE (pattern) == SEQUENCE)
2699 return emit_insn (pattern);
2702 register rtx insn = make_jump_insn_raw (pattern);
2708 /* Make an insn of code CALL_INSN with pattern PATTERN
2709 and add it to the end of the doubly-linked list. */
2712 emit_call_insn (pattern)
2715 if (GET_CODE (pattern) == SEQUENCE)
2716 return emit_insn (pattern);
2719 register rtx insn = make_call_insn_raw (pattern);
2721 PUT_CODE (insn, CALL_INSN);
2726 /* Add the label LABEL to the end of the doubly-linked list. */
2732 /* This can be called twice for the same label
2733 as a result of the confusion that follows a syntax error!
2734 So make it harmless. */
2735 if (INSN_UID (label) == 0)
2737 INSN_UID (label) = cur_insn_uid++;
2743 /* Make an insn of code BARRIER
2744 and add it to the end of the doubly-linked list. */
2749 register rtx barrier = rtx_alloc (BARRIER);
2750 INSN_UID (barrier) = cur_insn_uid++;
2755 /* Make an insn of code NOTE
2756 with data-fields specified by FILE and LINE
2757 and add it to the end of the doubly-linked list,
2758 but only if line-numbers are desired for debugging info. */
2761 emit_line_note (file, line)
2765 if (output_bytecode)
2767 /* FIXME: for now we do nothing, but eventually we will have to deal with
2768 debugging information. */
2772 emit_filename = file;
2776 if (no_line_numbers)
2780 return emit_note (file, line);
2783 /* Make an insn of code NOTE
2784 with data-fields specified by FILE and LINE
2785 and add it to the end of the doubly-linked list.
2786 If it is a line-number NOTE, omit it if it matches the previous one. */
2789 emit_note (file, line)
2797 if (file && last_filename && !strcmp (file, last_filename)
2798 && line == last_linenum)
2800 last_filename = file;
2801 last_linenum = line;
2804 if (no_line_numbers && line > 0)
2810 note = rtx_alloc (NOTE);
2811 INSN_UID (note) = cur_insn_uid++;
2812 NOTE_SOURCE_FILE (note) = file;
2813 NOTE_LINE_NUMBER (note) = line;
2818 /* Emit a NOTE, and don't omit it even if LINE it the previous note. */
2821 emit_line_note_force (file, line)
2826 return emit_line_note (file, line);
2829 /* Cause next statement to emit a line note even if the line number
2830 has not changed. This is used at the beginning of a function. */
2833 force_next_line_note ()
2838 /* Return an indication of which type of insn should have X as a body.
2839 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
2845 if (GET_CODE (x) == CODE_LABEL)
2847 if (GET_CODE (x) == CALL)
2849 if (GET_CODE (x) == RETURN)
2851 if (GET_CODE (x) == SET)
2853 if (SET_DEST (x) == pc_rtx)
2855 else if (GET_CODE (SET_SRC (x)) == CALL)
2860 if (GET_CODE (x) == PARALLEL)
2863 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
2864 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
2866 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2867 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
2869 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2870 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
2876 /* Emit the rtl pattern X as an appropriate kind of insn.
2877 If X is a label, it is simply added into the insn chain. */
2883 enum rtx_code code = classify_insn (x);
2885 if (code == CODE_LABEL)
2886 return emit_label (x);
2887 else if (code == INSN)
2888 return emit_insn (x);
2889 else if (code == JUMP_INSN)
2891 register rtx insn = emit_jump_insn (x);
2892 if (simplejump_p (insn) || GET_CODE (x) == RETURN)
2893 return emit_barrier ();
2896 else if (code == CALL_INSN)
2897 return emit_call_insn (x);
2902 /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR. */
2907 struct sequence_stack *tem;
2909 if (sequence_element_free_list)
2911 /* Reuse a previously-saved struct sequence_stack. */
2912 tem = sequence_element_free_list;
2913 sequence_element_free_list = tem->next;
2916 tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
2918 tem->next = sequence_stack;
2919 tem->first = first_insn;
2920 tem->last = last_insn;
2921 tem->sequence_rtl_expr = sequence_rtl_expr;
2923 sequence_stack = tem;
2929 /* Similarly, but indicate that this sequence will be placed in
2933 start_sequence_for_rtl_expr (t)
2938 sequence_rtl_expr = t;
2941 /* Set up the insn chain starting with FIRST
2942 as the current sequence, saving the previously current one. */
2945 push_to_sequence (first)
2952 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
2958 /* Set up the outer-level insn chain
2959 as the current sequence, saving the previously current one. */
2962 push_topmost_sequence ()
2964 struct sequence_stack *stack, *top;
2968 for (stack = sequence_stack; stack; stack = stack->next)
2971 first_insn = top->first;
2972 last_insn = top->last;
2973 sequence_rtl_expr = top->sequence_rtl_expr;
2976 /* After emitting to the outer-level insn chain, update the outer-level
2977 insn chain, and restore the previous saved state. */
2980 pop_topmost_sequence ()
2982 struct sequence_stack *stack, *top;
2984 for (stack = sequence_stack; stack; stack = stack->next)
2987 top->first = first_insn;
2988 top->last = last_insn;
2989 /* ??? Why don't we save sequence_rtl_expr here? */
2994 /* After emitting to a sequence, restore previous saved state.
2996 To get the contents of the sequence just made,
2997 you must call `gen_sequence' *before* calling here. */
3002 struct sequence_stack *tem = sequence_stack;
3004 first_insn = tem->first;
3005 last_insn = tem->last;
3006 sequence_rtl_expr = tem->sequence_rtl_expr;
3007 sequence_stack = tem->next;
3009 tem->next = sequence_element_free_list;
3010 sequence_element_free_list = tem;
3013 /* Return 1 if currently emitting into a sequence. */
3018 return sequence_stack != 0;
3021 /* Generate a SEQUENCE rtx containing the insns already emitted
3022 to the current sequence.
3024 This is how the gen_... function from a DEFINE_EXPAND
3025 constructs the SEQUENCE that it returns. */
3035 /* Count the insns in the chain. */
3037 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3040 /* If only one insn, return its pattern rather than a SEQUENCE.
3041 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3042 the case of an empty list.) */
3044 && (GET_CODE (first_insn) == INSN
3045 || GET_CODE (first_insn) == JUMP_INSN
3046 || GET_CODE (first_insn) == CALL_INSN))
3047 return PATTERN (first_insn);
3049 /* Put them in a vector. See if we already have a SEQUENCE of the
3050 appropriate length around. */
3051 if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
3052 sequence_result[len] = 0;
3055 /* Ensure that this rtl goes in saveable_obstack, since we may be
3057 push_obstacks_nochange ();
3058 rtl_in_saveable_obstack ();
3059 result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
3063 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3064 XVECEXP (result, 0, i) = tem;
3069 /* Set up regno_reg_rtx, reg_rtx_no and regno_pointer_flag
3070 according to the chain of insns starting with FIRST.
3072 Also set cur_insn_uid to exceed the largest uid in that chain.
3074 This is used when an inline function's rtl is saved
3075 and passed to rest_of_compilation later. */
3077 static void restore_reg_data_1 ();
3080 restore_reg_data (first)
3085 register int max_uid = 0;
3087 for (insn = first; insn; insn = NEXT_INSN (insn))
3089 if (INSN_UID (insn) >= max_uid)
3090 max_uid = INSN_UID (insn);
3092 switch (GET_CODE (insn))
3102 restore_reg_data_1 (PATTERN (insn));
3107 /* Don't duplicate the uids already in use. */
3108 cur_insn_uid = max_uid + 1;
3110 /* If any regs are missing, make them up.
3112 ??? word_mode is not necessarily the right mode. Most likely these REGs
3113 are never used. At some point this should be checked. */
3115 for (i = FIRST_PSEUDO_REGISTER; i < reg_rtx_no; i++)
3116 if (regno_reg_rtx[i] == 0)
3117 regno_reg_rtx[i] = gen_rtx (REG, word_mode, i);
3121 restore_reg_data_1 (orig)
3124 register rtx x = orig;
3126 register enum rtx_code code;
3127 register char *format_ptr;
3129 code = GET_CODE (x);
3144 if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
3146 /* Make sure regno_pointer_flag and regno_reg_rtx are large
3147 enough to have an element for this pseudo reg number. */
3148 if (REGNO (x) >= reg_rtx_no)
3150 reg_rtx_no = REGNO (x);
3152 if (reg_rtx_no >= regno_pointer_flag_length)
3154 int newlen = MAX (regno_pointer_flag_length * 2,
3157 char *new = (char *) oballoc (newlen);
3158 bzero (new, newlen);
3159 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
3161 new1 = (rtx *) oballoc (newlen * sizeof (rtx));
3162 bzero ((char *) new1, newlen * sizeof (rtx));
3163 bcopy ((char *) regno_reg_rtx, (char *) new1,
3164 regno_pointer_flag_length * sizeof (rtx));
3166 regno_pointer_flag = new;
3167 regno_reg_rtx = new1;
3168 regno_pointer_flag_length = newlen;
3172 regno_reg_rtx[REGNO (x)] = x;
3177 if (GET_CODE (XEXP (x, 0)) == REG)
3178 mark_reg_pointer (XEXP (x, 0));
3179 restore_reg_data_1 (XEXP (x, 0));
3183 /* Now scan the subexpressions recursively. */
3185 format_ptr = GET_RTX_FORMAT (code);
3187 for (i = 0; i < GET_RTX_LENGTH (code); i++)
3189 switch (*format_ptr++)
3192 restore_reg_data_1 (XEXP (x, i));
3196 if (XVEC (x, i) != NULL)
3200 for (j = 0; j < XVECLEN (x, i); j++)
3201 restore_reg_data_1 (XVECEXP (x, i, j));
3208 /* Initialize data structures and variables in this file
3209 before generating rtl for each function. */
3218 sequence_rtl_expr = NULL;
3220 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3223 first_label_num = label_num;
3225 sequence_stack = NULL;
3227 /* Clear the start_sequence/gen_sequence cache. */
3228 sequence_element_free_list = 0;
3229 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3230 sequence_result[i] = 0;
3232 /* Init the tables that describe all the pseudo regs. */
3234 regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
3237 = (char *) oballoc (regno_pointer_flag_length);
3238 bzero (regno_pointer_flag, regno_pointer_flag_length);
3241 = (rtx *) oballoc (regno_pointer_flag_length * sizeof (rtx));
3242 bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
3244 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3245 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3246 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3247 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3248 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3250 /* Indicate that the virtual registers and stack locations are
3252 REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3253 REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
3254 REGNO_POINTER_FLAG (HARD_FRAME_POINTER_REGNUM) = 1;
3255 REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3257 REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3258 REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3259 REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3260 REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
3262 #ifdef INIT_EXPANDERS
3267 /* Create some permanent unique rtl objects shared between all functions.
3268 LINE_NUMBERS is nonzero if line numbers are to be generated. */
3271 init_emit_once (line_numbers)
3275 enum machine_mode mode;
3277 no_line_numbers = ! line_numbers;
3279 sequence_stack = NULL;
3281 /* Compute the word and byte modes. */
3283 byte_mode = VOIDmode;
3284 word_mode = VOIDmode;
3286 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3287 mode = GET_MODE_WIDER_MODE (mode))
3289 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3290 && byte_mode == VOIDmode)
3293 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3294 && word_mode == VOIDmode)
3298 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
3300 /* Create the unique rtx's for certain rtx codes and operand values. */
3302 pc_rtx = gen_rtx (PC, VOIDmode);
3303 cc0_rtx = gen_rtx (CC0, VOIDmode);
3305 /* Don't use gen_rtx here since gen_rtx in this case
3306 tries to use these variables. */
3307 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
3309 const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
3310 PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
3311 INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
3314 /* These four calls obtain some of the rtx expressions made above. */
3315 const0_rtx = GEN_INT (0);
3316 const1_rtx = GEN_INT (1);
3317 const2_rtx = GEN_INT (2);
3318 constm1_rtx = GEN_INT (-1);
3320 /* This will usually be one of the above constants, but may be a new rtx. */
3321 const_true_rtx = GEN_INT (STORE_FLAG_VALUE);
3323 dconst0 = REAL_VALUE_ATOF ("0", DFmode);
3324 dconst1 = REAL_VALUE_ATOF ("1", DFmode);
3325 dconst2 = REAL_VALUE_ATOF ("2", DFmode);
3326 dconstm1 = REAL_VALUE_ATOF ("-1", DFmode);
3328 for (i = 0; i <= 2; i++)
3330 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3331 mode = GET_MODE_WIDER_MODE (mode))
3333 rtx tem = rtx_alloc (CONST_DOUBLE);
3334 union real_extract u;
3336 bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */
3337 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3339 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
3340 CONST_DOUBLE_MEM (tem) = cc0_rtx;
3341 PUT_MODE (tem, mode);
3343 const_tiny_rtx[i][(int) mode] = tem;
3346 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
3348 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3349 mode = GET_MODE_WIDER_MODE (mode))
3350 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3352 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3354 mode = GET_MODE_WIDER_MODE (mode))
3355 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3358 for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode;
3359 mode = GET_MODE_WIDER_MODE (mode))
3360 const_tiny_rtx[0][(int) mode] = const0_rtx;
3362 stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
3363 frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
3365 if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM)
3366 hard_frame_pointer_rtx = frame_pointer_rtx;
3368 hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM);
3370 if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3371 arg_pointer_rtx = frame_pointer_rtx;
3372 else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3373 arg_pointer_rtx = hard_frame_pointer_rtx;
3374 else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
3375 arg_pointer_rtx = stack_pointer_rtx;
3377 arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
3379 /* Create the virtual registers. Do so here since the following objects
3380 might reference them. */
3382 virtual_incoming_args_rtx = gen_rtx (REG, Pmode,
3383 VIRTUAL_INCOMING_ARGS_REGNUM);
3384 virtual_stack_vars_rtx = gen_rtx (REG, Pmode,
3385 VIRTUAL_STACK_VARS_REGNUM);
3386 virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode,
3387 VIRTUAL_STACK_DYNAMIC_REGNUM);
3388 virtual_outgoing_args_rtx = gen_rtx (REG, Pmode,
3389 VIRTUAL_OUTGOING_ARGS_REGNUM);
3392 struct_value_rtx = STRUCT_VALUE;
3394 struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
3397 #ifdef STRUCT_VALUE_INCOMING
3398 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3400 #ifdef STRUCT_VALUE_INCOMING_REGNUM
3401 struct_value_incoming_rtx
3402 = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3404 struct_value_incoming_rtx = struct_value_rtx;
3408 #ifdef STATIC_CHAIN_REGNUM
3409 static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
3411 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3412 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3413 static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3416 static_chain_incoming_rtx = static_chain_rtx;
3420 static_chain_rtx = STATIC_CHAIN;
3422 #ifdef STATIC_CHAIN_INCOMING
3423 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3425 static_chain_incoming_rtx = static_chain_rtx;
3429 #ifdef PIC_OFFSET_TABLE_REGNUM
3430 pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);