1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
32 #include "hard-reg-set.h"
35 #include "insn-config.h"
36 #include "insn-attr.h"
37 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
44 #include "typeclass.h"
47 #include "langhooks.h"
50 #include "tree-iterator.h"
51 #include "tree-pass.h"
52 #include "tree-flow.h"
56 /* Decide whether a function's arguments should be processed
57 from first to last or from last to first.
59 They should if the stack and args grow in opposite directions, but
60 only if we have push insns. */
64 #ifndef PUSH_ARGS_REVERSED
65 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
66 #define PUSH_ARGS_REVERSED /* If it's last to first. */
72 #ifndef STACK_PUSH_CODE
73 #ifdef STACK_GROWS_DOWNWARD
74 #define STACK_PUSH_CODE PRE_DEC
76 #define STACK_PUSH_CODE PRE_INC
81 /* If this is nonzero, we do not bother generating VOLATILE
82 around volatile memory references, and we are willing to
83 output indirect addresses. If cse is to follow, we reject
84 indirect addresses so a useful potential cse is generated;
85 if it is used only once, instruction combination will produce
86 the same indirect address eventually. */
89 /* This structure is used by move_by_pieces to describe the move to
100 int explicit_inc_from;
101 unsigned HOST_WIDE_INT len;
102 HOST_WIDE_INT offset;
106 /* This structure is used by store_by_pieces to describe the clear to
109 struct store_by_pieces
115 unsigned HOST_WIDE_INT len;
116 HOST_WIDE_INT offset;
117 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
122 static unsigned HOST_WIDE_INT move_by_pieces_ninsns (unsigned HOST_WIDE_INT,
124 static void move_by_pieces_1 (rtx (*) (rtx, ...), enum machine_mode,
125 struct move_by_pieces *);
126 static bool block_move_libcall_safe_for_call_parm (void);
127 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned);
128 static rtx emit_block_move_via_libcall (rtx, rtx, rtx);
129 static tree emit_block_move_libcall_fn (int);
130 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
131 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
132 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
133 static void store_by_pieces_1 (struct store_by_pieces *, unsigned int);
134 static void store_by_pieces_2 (rtx (*) (rtx, ...), enum machine_mode,
135 struct store_by_pieces *);
136 static bool clear_storage_via_clrmem (rtx, rtx, unsigned);
137 static rtx clear_storage_via_libcall (rtx, rtx);
138 static tree clear_storage_libcall_fn (int);
139 static rtx compress_float_constant (rtx, rtx);
140 static rtx get_subtarget (rtx);
141 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
142 HOST_WIDE_INT, enum machine_mode,
143 tree, tree, int, int);
144 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
145 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT, enum machine_mode,
146 tree, enum machine_mode, int, tree, int);
147 static rtx var_rtx (tree);
149 static unsigned HOST_WIDE_INT highest_pow2_factor (tree);
150 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (tree, tree);
152 static int is_aligning_offset (tree, tree);
153 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
154 enum expand_modifier);
155 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
156 static rtx do_store_flag (tree, rtx, enum machine_mode, int);
158 static void emit_single_push_insn (enum machine_mode, rtx, tree);
160 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx);
161 static rtx const_vector_from_tree (tree);
163 /* Record for each mode whether we can move a register directly to or
164 from an object of that mode in memory. If we can't, we won't try
165 to use that mode directly when accessing a field of that mode. */
167 static char direct_load[NUM_MACHINE_MODES];
168 static char direct_store[NUM_MACHINE_MODES];
170 /* Record for each mode whether we can float-extend from memory. */
172 static bool float_extend_from_mem[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
174 /* This macro is used to determine whether move_by_pieces should be called
175 to perform a structure copy. */
176 #ifndef MOVE_BY_PIECES_P
177 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
178 (move_by_pieces_ninsns (SIZE, ALIGN) < (unsigned int) MOVE_RATIO)
181 /* This macro is used to determine whether clear_by_pieces should be
182 called to clear storage. */
183 #ifndef CLEAR_BY_PIECES_P
184 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
185 (move_by_pieces_ninsns (SIZE, ALIGN) < (unsigned int) CLEAR_RATIO)
188 /* This macro is used to determine whether store_by_pieces should be
189 called to "memset" storage with byte values other than zero, or
190 to "memcpy" storage when the source is a constant string. */
191 #ifndef STORE_BY_PIECES_P
192 #define STORE_BY_PIECES_P(SIZE, ALIGN) MOVE_BY_PIECES_P (SIZE, ALIGN)
195 /* This array records the insn_code of insns to perform block moves. */
196 enum insn_code movmem_optab[NUM_MACHINE_MODES];
198 /* This array records the insn_code of insns to perform block clears. */
199 enum insn_code clrmem_optab[NUM_MACHINE_MODES];
201 /* These arrays record the insn_code of two different kinds of insns
202 to perform block compares. */
203 enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
204 enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
206 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
208 #ifndef SLOW_UNALIGNED_ACCESS
209 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
212 /* This is run once per compilation to set up which modes can be used
213 directly in memory and to initialize the block move optab. */
216 init_expr_once (void)
219 enum machine_mode mode;
224 /* Try indexing by frame ptr and try by stack ptr.
225 It is known that on the Convex the stack ptr isn't a valid index.
226 With luck, one or the other is valid on any machine. */
227 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
228 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
230 /* A scratch register we can modify in-place below to avoid
231 useless RTL allocations. */
232 reg = gen_rtx_REG (VOIDmode, -1);
234 insn = rtx_alloc (INSN);
235 pat = gen_rtx_SET (0, NULL_RTX, NULL_RTX);
236 PATTERN (insn) = pat;
238 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
239 mode = (enum machine_mode) ((int) mode + 1))
243 direct_load[(int) mode] = direct_store[(int) mode] = 0;
244 PUT_MODE (mem, mode);
245 PUT_MODE (mem1, mode);
246 PUT_MODE (reg, mode);
248 /* See if there is some register that can be used in this mode and
249 directly loaded or stored from memory. */
251 if (mode != VOIDmode && mode != BLKmode)
252 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
253 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
256 if (! HARD_REGNO_MODE_OK (regno, mode))
262 SET_DEST (pat) = reg;
263 if (recog (pat, insn, &num_clobbers) >= 0)
264 direct_load[(int) mode] = 1;
266 SET_SRC (pat) = mem1;
267 SET_DEST (pat) = reg;
268 if (recog (pat, insn, &num_clobbers) >= 0)
269 direct_load[(int) mode] = 1;
272 SET_DEST (pat) = mem;
273 if (recog (pat, insn, &num_clobbers) >= 0)
274 direct_store[(int) mode] = 1;
277 SET_DEST (pat) = mem1;
278 if (recog (pat, insn, &num_clobbers) >= 0)
279 direct_store[(int) mode] = 1;
283 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
285 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
286 mode = GET_MODE_WIDER_MODE (mode))
288 enum machine_mode srcmode;
289 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
290 srcmode = GET_MODE_WIDER_MODE (srcmode))
294 ic = can_extend_p (mode, srcmode, 0);
295 if (ic == CODE_FOR_nothing)
298 PUT_MODE (mem, srcmode);
300 if ((*insn_data[ic].operand[1].predicate) (mem, srcmode))
301 float_extend_from_mem[mode][srcmode] = true;
306 /* This is run at the start of compiling a function. */
311 cfun->expr = ggc_alloc_cleared (sizeof (struct expr_status));
314 /* Copy data from FROM to TO, where the machine modes are not the same.
315 Both modes may be integer, or both may be floating.
316 UNSIGNEDP should be nonzero if FROM is an unsigned type.
317 This causes zero-extension instead of sign-extension. */
320 convert_move (rtx to, rtx from, int unsignedp)
322 enum machine_mode to_mode = GET_MODE (to);
323 enum machine_mode from_mode = GET_MODE (from);
324 int to_real = GET_MODE_CLASS (to_mode) == MODE_FLOAT;
325 int from_real = GET_MODE_CLASS (from_mode) == MODE_FLOAT;
329 /* rtx code for making an equivalent value. */
330 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
331 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
334 if (to_real != from_real)
337 /* If the source and destination are already the same, then there's
342 /* If FROM is a SUBREG that indicates that we have already done at least
343 the required extension, strip it. We don't handle such SUBREGs as
346 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
347 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
348 >= GET_MODE_SIZE (to_mode))
349 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
350 from = gen_lowpart (to_mode, from), from_mode = to_mode;
352 if (GET_CODE (to) == SUBREG && SUBREG_PROMOTED_VAR_P (to))
355 if (to_mode == from_mode
356 || (from_mode == VOIDmode && CONSTANT_P (from)))
358 emit_move_insn (to, from);
362 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
364 if (GET_MODE_BITSIZE (from_mode) != GET_MODE_BITSIZE (to_mode))
367 if (VECTOR_MODE_P (to_mode))
368 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
370 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
372 emit_move_insn (to, from);
376 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
378 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
379 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
388 if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
390 else if (GET_MODE_PRECISION (from_mode) > GET_MODE_PRECISION (to_mode))
395 /* Try converting directly if the insn is supported. */
397 code = tab->handlers[to_mode][from_mode].insn_code;
398 if (code != CODE_FOR_nothing)
400 emit_unop_insn (code, to, from,
401 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
405 /* Otherwise use a libcall. */
406 libcall = tab->handlers[to_mode][from_mode].libfunc;
409 /* This conversion is not implemented yet. */
413 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
415 insns = get_insns ();
417 emit_libcall_block (insns, to, value,
418 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
420 : gen_rtx_FLOAT_EXTEND (to_mode, from));
424 /* Handle pointer conversion. */ /* SPEE 900220. */
425 /* Targets are expected to provide conversion insns between PxImode and
426 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
427 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
429 enum machine_mode full_mode
430 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
432 if (trunc_optab->handlers[to_mode][full_mode].insn_code
436 if (full_mode != from_mode)
437 from = convert_to_mode (full_mode, from, unsignedp);
438 emit_unop_insn (trunc_optab->handlers[to_mode][full_mode].insn_code,
442 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
444 enum machine_mode full_mode
445 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
447 if (sext_optab->handlers[full_mode][from_mode].insn_code
451 emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
453 if (to_mode == full_mode)
456 /* else proceed to integer conversions below. */
457 from_mode = full_mode;
460 /* Now both modes are integers. */
462 /* Handle expanding beyond a word. */
463 if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
464 && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
471 enum machine_mode lowpart_mode;
472 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
474 /* Try converting directly if the insn is supported. */
475 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
478 /* If FROM is a SUBREG, put it into a register. Do this
479 so that we always generate the same set of insns for
480 better cse'ing; if an intermediate assignment occurred,
481 we won't be doing the operation directly on the SUBREG. */
482 if (optimize > 0 && GET_CODE (from) == SUBREG)
483 from = force_reg (from_mode, from);
484 emit_unop_insn (code, to, from, equiv_code);
487 /* Next, try converting via full word. */
488 else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
489 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
490 != CODE_FOR_nothing))
494 if (reg_overlap_mentioned_p (to, from))
495 from = force_reg (from_mode, from);
496 emit_insn (gen_rtx_CLOBBER (VOIDmode, to));
498 convert_move (gen_lowpart (word_mode, to), from, unsignedp);
499 emit_unop_insn (code, to,
500 gen_lowpart (word_mode, to), equiv_code);
504 /* No special multiword conversion insn; do it by hand. */
507 /* Since we will turn this into a no conflict block, we must ensure
508 that the source does not overlap the target. */
510 if (reg_overlap_mentioned_p (to, from))
511 from = force_reg (from_mode, from);
513 /* Get a copy of FROM widened to a word, if necessary. */
514 if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
515 lowpart_mode = word_mode;
517 lowpart_mode = from_mode;
519 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
521 lowpart = gen_lowpart (lowpart_mode, to);
522 emit_move_insn (lowpart, lowfrom);
524 /* Compute the value to put in each remaining word. */
526 fill_value = const0_rtx;
531 && insn_data[(int) CODE_FOR_slt].operand[0].mode == word_mode
532 && STORE_FLAG_VALUE == -1)
534 emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
536 fill_value = gen_reg_rtx (word_mode);
537 emit_insn (gen_slt (fill_value));
543 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
544 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
546 fill_value = convert_to_mode (word_mode, fill_value, 1);
550 /* Fill the remaining words. */
551 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
553 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
554 rtx subword = operand_subword (to, index, 1, to_mode);
559 if (fill_value != subword)
560 emit_move_insn (subword, fill_value);
563 insns = get_insns ();
566 emit_no_conflict_block (insns, to, from, NULL_RTX,
567 gen_rtx_fmt_e (equiv_code, to_mode, copy_rtx (from)));
571 /* Truncating multi-word to a word or less. */
572 if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
573 && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
576 && ! MEM_VOLATILE_P (from)
577 && direct_load[(int) to_mode]
578 && ! mode_dependent_address_p (XEXP (from, 0)))
580 || GET_CODE (from) == SUBREG))
581 from = force_reg (from_mode, from);
582 convert_move (to, gen_lowpart (word_mode, from), 0);
586 /* Now follow all the conversions between integers
587 no more than a word long. */
589 /* For truncation, usually we can just refer to FROM in a narrower mode. */
590 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
591 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
592 GET_MODE_BITSIZE (from_mode)))
595 && ! MEM_VOLATILE_P (from)
596 && direct_load[(int) to_mode]
597 && ! mode_dependent_address_p (XEXP (from, 0)))
599 || GET_CODE (from) == SUBREG))
600 from = force_reg (from_mode, from);
601 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
602 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
603 from = copy_to_reg (from);
604 emit_move_insn (to, gen_lowpart (to_mode, from));
608 /* Handle extension. */
609 if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
611 /* Convert directly if that works. */
612 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
616 from = force_not_mem (from);
618 emit_unop_insn (code, to, from, equiv_code);
623 enum machine_mode intermediate;
627 /* Search for a mode to convert via. */
628 for (intermediate = from_mode; intermediate != VOIDmode;
629 intermediate = GET_MODE_WIDER_MODE (intermediate))
630 if (((can_extend_p (to_mode, intermediate, unsignedp)
632 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
633 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
634 GET_MODE_BITSIZE (intermediate))))
635 && (can_extend_p (intermediate, from_mode, unsignedp)
636 != CODE_FOR_nothing))
638 convert_move (to, convert_to_mode (intermediate, from,
639 unsignedp), unsignedp);
643 /* No suitable intermediate mode.
644 Generate what we need with shifts. */
645 shift_amount = build_int_2 (GET_MODE_BITSIZE (to_mode)
646 - GET_MODE_BITSIZE (from_mode), 0);
647 from = gen_lowpart (to_mode, force_reg (from_mode, from));
648 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
650 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
653 emit_move_insn (to, tmp);
658 /* Support special truncate insns for certain modes. */
659 if (trunc_optab->handlers[to_mode][from_mode].insn_code != CODE_FOR_nothing)
661 emit_unop_insn (trunc_optab->handlers[to_mode][from_mode].insn_code,
666 /* Handle truncation of volatile memrefs, and so on;
667 the things that couldn't be truncated directly,
668 and for which there was no special instruction.
670 ??? Code above formerly short-circuited this, for most integer
671 mode pairs, with a force_reg in from_mode followed by a recursive
672 call to this routine. Appears always to have been wrong. */
673 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
675 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
676 emit_move_insn (to, temp);
680 /* Mode combination is not recognized. */
684 /* Return an rtx for a value that would result
685 from converting X to mode MODE.
686 Both X and MODE may be floating, or both integer.
687 UNSIGNEDP is nonzero if X is an unsigned value.
688 This can be done by referring to a part of X in place
689 or by copying to a new temporary with conversion. */
692 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
694 return convert_modes (mode, VOIDmode, x, unsignedp);
697 /* Return an rtx for a value that would result
698 from converting X from mode OLDMODE to mode MODE.
699 Both modes may be floating, or both integer.
700 UNSIGNEDP is nonzero if X is an unsigned value.
702 This can be done by referring to a part of X in place
703 or by copying to a new temporary with conversion.
705 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
708 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
712 /* If FROM is a SUBREG that indicates that we have already done at least
713 the required extension, strip it. */
715 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
716 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
717 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
718 x = gen_lowpart (mode, x);
720 if (GET_MODE (x) != VOIDmode)
721 oldmode = GET_MODE (x);
726 /* There is one case that we must handle specially: If we are converting
727 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
728 we are to interpret the constant as unsigned, gen_lowpart will do
729 the wrong if the constant appears negative. What we want to do is
730 make the high-order word of the constant zero, not all ones. */
732 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
733 && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
734 && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
736 HOST_WIDE_INT val = INTVAL (x);
738 if (oldmode != VOIDmode
739 && HOST_BITS_PER_WIDE_INT > GET_MODE_BITSIZE (oldmode))
741 int width = GET_MODE_BITSIZE (oldmode);
743 /* We need to zero extend VAL. */
744 val &= ((HOST_WIDE_INT) 1 << width) - 1;
747 return immed_double_const (val, (HOST_WIDE_INT) 0, mode);
750 /* We can do this with a gen_lowpart if both desired and current modes
751 are integer, and this is either a constant integer, a register, or a
752 non-volatile MEM. Except for the constant case where MODE is no
753 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
755 if ((GET_CODE (x) == CONST_INT
756 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
757 || (GET_MODE_CLASS (mode) == MODE_INT
758 && GET_MODE_CLASS (oldmode) == MODE_INT
759 && (GET_CODE (x) == CONST_DOUBLE
760 || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
761 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
762 && direct_load[(int) mode])
764 && (! HARD_REGISTER_P (x)
765 || HARD_REGNO_MODE_OK (REGNO (x), mode))
766 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
767 GET_MODE_BITSIZE (GET_MODE (x)))))))))
769 /* ?? If we don't know OLDMODE, we have to assume here that
770 X does not need sign- or zero-extension. This may not be
771 the case, but it's the best we can do. */
772 if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
773 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
775 HOST_WIDE_INT val = INTVAL (x);
776 int width = GET_MODE_BITSIZE (oldmode);
778 /* We must sign or zero-extend in this case. Start by
779 zero-extending, then sign extend if we need to. */
780 val &= ((HOST_WIDE_INT) 1 << width) - 1;
782 && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
783 val |= (HOST_WIDE_INT) (-1) << width;
785 return gen_int_mode (val, mode);
788 return gen_lowpart (mode, x);
791 /* Converting from integer constant into mode is always equivalent to an
793 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
795 if (GET_MODE_BITSIZE (mode) != GET_MODE_BITSIZE (oldmode))
797 return simplify_gen_subreg (mode, x, oldmode, 0);
800 temp = gen_reg_rtx (mode);
801 convert_move (temp, x, unsignedp);
805 /* STORE_MAX_PIECES is the number of bytes at a time that we can
806 store efficiently. Due to internal GCC limitations, this is
807 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
808 for an immediate constant. */
810 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
812 /* Determine whether the LEN bytes can be moved by using several move
813 instructions. Return nonzero if a call to move_by_pieces should
817 can_move_by_pieces (unsigned HOST_WIDE_INT len,
818 unsigned int align ATTRIBUTE_UNUSED)
820 return MOVE_BY_PIECES_P (len, align);
823 /* Generate several move instructions to copy LEN bytes from block FROM to
824 block TO. (These are MEM rtx's with BLKmode).
826 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
827 used to push FROM to the stack.
829 ALIGN is maximum stack alignment we can assume.
831 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
832 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
836 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
837 unsigned int align, int endp)
839 struct move_by_pieces data;
840 rtx to_addr, from_addr = XEXP (from, 0);
841 unsigned int max_size = MOVE_MAX_PIECES + 1;
842 enum machine_mode mode = VOIDmode, tmode;
843 enum insn_code icode;
845 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
848 data.from_addr = from_addr;
851 to_addr = XEXP (to, 0);
854 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
855 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
857 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
864 #ifdef STACK_GROWS_DOWNWARD
870 data.to_addr = to_addr;
873 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
874 || GET_CODE (from_addr) == POST_INC
875 || GET_CODE (from_addr) == POST_DEC);
877 data.explicit_inc_from = 0;
878 data.explicit_inc_to = 0;
879 if (data.reverse) data.offset = len;
882 /* If copying requires more than two move insns,
883 copy addresses to registers (to make displacements shorter)
884 and use post-increment if available. */
885 if (!(data.autinc_from && data.autinc_to)
886 && move_by_pieces_ninsns (len, align) > 2)
888 /* Find the mode of the largest move... */
889 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
890 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
891 if (GET_MODE_SIZE (tmode) < max_size)
894 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
896 data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
897 data.autinc_from = 1;
898 data.explicit_inc_from = -1;
900 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
902 data.from_addr = copy_addr_to_reg (from_addr);
903 data.autinc_from = 1;
904 data.explicit_inc_from = 1;
906 if (!data.autinc_from && CONSTANT_P (from_addr))
907 data.from_addr = copy_addr_to_reg (from_addr);
908 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
910 data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
912 data.explicit_inc_to = -1;
914 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
916 data.to_addr = copy_addr_to_reg (to_addr);
918 data.explicit_inc_to = 1;
920 if (!data.autinc_to && CONSTANT_P (to_addr))
921 data.to_addr = copy_addr_to_reg (to_addr);
924 if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
925 || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
926 align = MOVE_MAX * BITS_PER_UNIT;
928 /* First move what we can in the largest integer mode, then go to
929 successively smaller modes. */
933 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
934 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
935 if (GET_MODE_SIZE (tmode) < max_size)
938 if (mode == VOIDmode)
941 icode = mov_optab->handlers[(int) mode].insn_code;
942 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
943 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
945 max_size = GET_MODE_SIZE (mode);
948 /* The code above should have handled everything. */
962 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
963 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
965 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
968 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
975 to1 = adjust_address (data.to, QImode, data.offset);
983 /* Return number of insns required to move L bytes by pieces.
984 ALIGN (in bits) is maximum alignment we can assume. */
986 static unsigned HOST_WIDE_INT
987 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align)
989 unsigned HOST_WIDE_INT n_insns = 0;
990 unsigned HOST_WIDE_INT max_size = MOVE_MAX + 1;
992 if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
993 || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
994 align = MOVE_MAX * BITS_PER_UNIT;
998 enum machine_mode mode = VOIDmode, tmode;
999 enum insn_code icode;
1001 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1002 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1003 if (GET_MODE_SIZE (tmode) < max_size)
1006 if (mode == VOIDmode)
1009 icode = mov_optab->handlers[(int) mode].insn_code;
1010 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1011 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1013 max_size = GET_MODE_SIZE (mode);
1021 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1022 with move instructions for mode MODE. GENFUN is the gen_... function
1023 to make a move insn for that mode. DATA has all the other info. */
1026 move_by_pieces_1 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
1027 struct move_by_pieces *data)
1029 unsigned int size = GET_MODE_SIZE (mode);
1030 rtx to1 = NULL_RTX, from1;
1032 while (data->len >= size)
1035 data->offset -= size;
1039 if (data->autinc_to)
1040 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1043 to1 = adjust_address (data->to, mode, data->offset);
1046 if (data->autinc_from)
1047 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1050 from1 = adjust_address (data->from, mode, data->offset);
1052 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1053 emit_insn (gen_add2_insn (data->to_addr,
1054 GEN_INT (-(HOST_WIDE_INT)size)));
1055 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1056 emit_insn (gen_add2_insn (data->from_addr,
1057 GEN_INT (-(HOST_WIDE_INT)size)));
1060 emit_insn ((*genfun) (to1, from1));
1063 #ifdef PUSH_ROUNDING
1064 emit_single_push_insn (mode, from1, NULL);
1070 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1071 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1072 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1073 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1075 if (! data->reverse)
1076 data->offset += size;
1082 /* Emit code to move a block Y to a block X. This may be done with
1083 string-move instructions, with multiple scalar move instructions,
1084 or with a library call.
1086 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1087 SIZE is an rtx that says how long they are.
1088 ALIGN is the maximum alignment we can assume they have.
1089 METHOD describes what kind of copy this is, and what mechanisms may be used.
1091 Return the address of the new block, if memcpy is called and returns it,
1095 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1103 case BLOCK_OP_NORMAL:
1104 may_use_call = true;
1107 case BLOCK_OP_CALL_PARM:
1108 may_use_call = block_move_libcall_safe_for_call_parm ();
1110 /* Make inhibit_defer_pop nonzero around the library call
1111 to force it to pop the arguments right away. */
1115 case BLOCK_OP_NO_LIBCALL:
1116 may_use_call = false;
1123 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1132 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1133 block copy is more efficient for other large modes, e.g. DCmode. */
1134 x = adjust_address (x, BLKmode, 0);
1135 y = adjust_address (y, BLKmode, 0);
1137 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1138 can be incorrect is coming from __builtin_memcpy. */
1139 if (GET_CODE (size) == CONST_INT)
1141 if (INTVAL (size) == 0)
1144 x = shallow_copy_rtx (x);
1145 y = shallow_copy_rtx (y);
1146 set_mem_size (x, size);
1147 set_mem_size (y, size);
1150 if (GET_CODE (size) == CONST_INT && MOVE_BY_PIECES_P (INTVAL (size), align))
1151 move_by_pieces (x, y, INTVAL (size), align, 0);
1152 else if (emit_block_move_via_movmem (x, y, size, align))
1154 else if (may_use_call)
1155 retval = emit_block_move_via_libcall (x, y, size);
1157 emit_block_move_via_loop (x, y, size, align);
1159 if (method == BLOCK_OP_CALL_PARM)
1165 /* A subroutine of emit_block_move. Returns true if calling the
1166 block move libcall will not clobber any parameters which may have
1167 already been placed on the stack. */
1170 block_move_libcall_safe_for_call_parm (void)
1172 /* If arguments are pushed on the stack, then they're safe. */
1176 /* If registers go on the stack anyway, any argument is sure to clobber
1177 an outgoing argument. */
1178 #if defined (REG_PARM_STACK_SPACE) && defined (OUTGOING_REG_PARM_STACK_SPACE)
1180 tree fn = emit_block_move_libcall_fn (false);
1182 if (REG_PARM_STACK_SPACE (fn) != 0)
1187 /* If any argument goes in memory, then it might clobber an outgoing
1190 CUMULATIVE_ARGS args_so_far;
1193 fn = emit_block_move_libcall_fn (false);
1194 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fn), NULL_RTX, 0, 3);
1196 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1197 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1199 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1200 rtx tmp = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
1201 if (!tmp || !REG_P (tmp))
1203 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode,
1206 FUNCTION_ARG_ADVANCE (args_so_far, mode, NULL_TREE, 1);
1212 /* A subroutine of emit_block_move. Expand a movmem pattern;
1213 return true if successful. */
1216 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align)
1218 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
1219 int save_volatile_ok = volatile_ok;
1220 enum machine_mode mode;
1222 /* Since this is a move insn, we don't care about volatility. */
1225 /* Try the most limited insn first, because there's no point
1226 including more than one in the machine description unless
1227 the more limited one has some advantage. */
1229 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1230 mode = GET_MODE_WIDER_MODE (mode))
1232 enum insn_code code = movmem_optab[(int) mode];
1233 insn_operand_predicate_fn pred;
1235 if (code != CODE_FOR_nothing
1236 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1237 here because if SIZE is less than the mode mask, as it is
1238 returned by the macro, it will definitely be less than the
1239 actual mode mask. */
1240 && ((GET_CODE (size) == CONST_INT
1241 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1242 <= (GET_MODE_MASK (mode) >> 1)))
1243 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1244 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
1245 || (*pred) (x, BLKmode))
1246 && ((pred = insn_data[(int) code].operand[1].predicate) == 0
1247 || (*pred) (y, BLKmode))
1248 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
1249 || (*pred) (opalign, VOIDmode)))
1252 rtx last = get_last_insn ();
1255 op2 = convert_to_mode (mode, size, 1);
1256 pred = insn_data[(int) code].operand[2].predicate;
1257 if (pred != 0 && ! (*pred) (op2, mode))
1258 op2 = copy_to_mode_reg (mode, op2);
1260 /* ??? When called via emit_block_move_for_call, it'd be
1261 nice if there were some way to inform the backend, so
1262 that it doesn't fail the expansion because it thinks
1263 emitting the libcall would be more efficient. */
1265 pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1269 volatile_ok = save_volatile_ok;
1273 delete_insns_since (last);
1277 volatile_ok = save_volatile_ok;
1281 /* A subroutine of emit_block_move. Expand a call to memcpy.
1282 Return the return value from memcpy, 0 otherwise. */
1285 emit_block_move_via_libcall (rtx dst, rtx src, rtx size)
1287 rtx dst_addr, src_addr;
1288 tree call_expr, arg_list, fn, src_tree, dst_tree, size_tree;
1289 enum machine_mode size_mode;
1292 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1293 pseudos. We can then place those new pseudos into a VAR_DECL and
1296 dst_addr = copy_to_mode_reg (Pmode, XEXP (dst, 0));
1297 src_addr = copy_to_mode_reg (Pmode, XEXP (src, 0));
1299 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1300 src_addr = convert_memory_address (ptr_mode, src_addr);
1302 dst_tree = make_tree (ptr_type_node, dst_addr);
1303 src_tree = make_tree (ptr_type_node, src_addr);
1305 size_mode = TYPE_MODE (sizetype);
1307 size = convert_to_mode (size_mode, size, 1);
1308 size = copy_to_mode_reg (size_mode, size);
1310 /* It is incorrect to use the libcall calling conventions to call
1311 memcpy in this context. This could be a user call to memcpy and
1312 the user may wish to examine the return value from memcpy. For
1313 targets where libcalls and normal calls have different conventions
1314 for returning pointers, we could end up generating incorrect code. */
1316 size_tree = make_tree (sizetype, size);
1318 fn = emit_block_move_libcall_fn (true);
1319 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
1320 arg_list = tree_cons (NULL_TREE, src_tree, arg_list);
1321 arg_list = tree_cons (NULL_TREE, dst_tree, arg_list);
1323 /* Now we have to build up the CALL_EXPR itself. */
1324 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
1325 call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
1326 call_expr, arg_list, NULL_TREE);
1328 retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
1330 /* If we are initializing a readonly value, show the above call clobbered
1331 it. Otherwise, a load from it may erroneously be hoisted from a loop, or
1332 the delay slot scheduler might overlook conflicts and take nasty
1334 if (RTX_UNCHANGING_P (dst))
1335 add_function_usage_to
1336 (last_call_insn (), gen_rtx_EXPR_LIST (VOIDmode,
1337 gen_rtx_CLOBBER (VOIDmode, dst),
1343 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1344 for the function we use for block copies. The first time FOR_CALL
1345 is true, we call assemble_external. */
1347 static GTY(()) tree block_move_fn;
1350 init_block_move_fn (const char *asmspec)
1356 fn = get_identifier ("memcpy");
1357 args = build_function_type_list (ptr_type_node, ptr_type_node,
1358 const_ptr_type_node, sizetype,
1361 fn = build_decl (FUNCTION_DECL, fn, args);
1362 DECL_EXTERNAL (fn) = 1;
1363 TREE_PUBLIC (fn) = 1;
1364 DECL_ARTIFICIAL (fn) = 1;
1365 TREE_NOTHROW (fn) = 1;
1372 SET_DECL_RTL (block_move_fn, NULL_RTX);
1373 SET_DECL_ASSEMBLER_NAME (block_move_fn, get_identifier (asmspec));
1378 emit_block_move_libcall_fn (int for_call)
1380 static bool emitted_extern;
1383 init_block_move_fn (NULL);
1385 if (for_call && !emitted_extern)
1387 emitted_extern = true;
1388 make_decl_rtl (block_move_fn, NULL);
1389 assemble_external (block_move_fn);
1392 return block_move_fn;
1395 /* A subroutine of emit_block_move. Copy the data via an explicit
1396 loop. This is used only when libcalls are forbidden. */
1397 /* ??? It'd be nice to copy in hunks larger than QImode. */
1400 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1401 unsigned int align ATTRIBUTE_UNUSED)
1403 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1404 enum machine_mode iter_mode;
1406 iter_mode = GET_MODE (size);
1407 if (iter_mode == VOIDmode)
1408 iter_mode = word_mode;
1410 top_label = gen_label_rtx ();
1411 cmp_label = gen_label_rtx ();
1412 iter = gen_reg_rtx (iter_mode);
1414 emit_move_insn (iter, const0_rtx);
1416 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1417 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1418 do_pending_stack_adjust ();
1420 emit_jump (cmp_label);
1421 emit_label (top_label);
1423 tmp = convert_modes (Pmode, iter_mode, iter, true);
1424 x_addr = gen_rtx_PLUS (Pmode, x_addr, tmp);
1425 y_addr = gen_rtx_PLUS (Pmode, y_addr, tmp);
1426 x = change_address (x, QImode, x_addr);
1427 y = change_address (y, QImode, y_addr);
1429 emit_move_insn (x, y);
1431 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1432 true, OPTAB_LIB_WIDEN);
1434 emit_move_insn (iter, tmp);
1436 emit_label (cmp_label);
1438 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1442 /* Copy all or part of a value X into registers starting at REGNO.
1443 The number of registers to be filled is NREGS. */
1446 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1449 #ifdef HAVE_load_multiple
1457 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
1458 x = validize_mem (force_const_mem (mode, x));
1460 /* See if the machine can do this with a load multiple insn. */
1461 #ifdef HAVE_load_multiple
1462 if (HAVE_load_multiple)
1464 last = get_last_insn ();
1465 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1473 delete_insns_since (last);
1477 for (i = 0; i < nregs; i++)
1478 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1479 operand_subword_force (x, i, mode));
1482 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1483 The number of registers to be filled is NREGS. */
1486 move_block_from_reg (int regno, rtx x, int nregs)
1493 /* See if the machine can do this with a store multiple insn. */
1494 #ifdef HAVE_store_multiple
1495 if (HAVE_store_multiple)
1497 rtx last = get_last_insn ();
1498 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1506 delete_insns_since (last);
1510 for (i = 0; i < nregs; i++)
1512 rtx tem = operand_subword (x, i, 1, BLKmode);
1517 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1521 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1522 ORIG, where ORIG is a non-consecutive group of registers represented by
1523 a PARALLEL. The clone is identical to the original except in that the
1524 original set of registers is replaced by a new set of pseudo registers.
1525 The new set has the same modes as the original set. */
1528 gen_group_rtx (rtx orig)
1533 if (GET_CODE (orig) != PARALLEL)
1536 length = XVECLEN (orig, 0);
1537 tmps = alloca (sizeof (rtx) * length);
1539 /* Skip a NULL entry in first slot. */
1540 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1545 for (; i < length; i++)
1547 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1548 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1550 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1553 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1556 /* Emit code to move a block ORIG_SRC of type TYPE to a block DST,
1557 where DST is non-consecutive registers represented by a PARALLEL.
1558 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1562 emit_group_load (rtx dst, rtx orig_src, tree type ATTRIBUTE_UNUSED, int ssize)
1567 if (GET_CODE (dst) != PARALLEL)
1570 /* Check for a NULL entry, used to indicate that the parameter goes
1571 both on the stack and in registers. */
1572 if (XEXP (XVECEXP (dst, 0, 0), 0))
1577 tmps = alloca (sizeof (rtx) * XVECLEN (dst, 0));
1579 /* Process the pieces. */
1580 for (i = start; i < XVECLEN (dst, 0); i++)
1582 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1583 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1584 unsigned int bytelen = GET_MODE_SIZE (mode);
1587 /* Handle trailing fragments that run over the size of the struct. */
1588 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1590 /* Arrange to shift the fragment to where it belongs.
1591 extract_bit_field loads to the lsb of the reg. */
1593 #ifdef BLOCK_REG_PADDING
1594 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1595 == (BYTES_BIG_ENDIAN ? upward : downward)
1600 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1601 bytelen = ssize - bytepos;
1606 /* If we won't be loading directly from memory, protect the real source
1607 from strange tricks we might play; but make sure that the source can
1608 be loaded directly into the destination. */
1610 if (!MEM_P (orig_src)
1611 && (!CONSTANT_P (orig_src)
1612 || (GET_MODE (orig_src) != mode
1613 && GET_MODE (orig_src) != VOIDmode)))
1615 if (GET_MODE (orig_src) == VOIDmode)
1616 src = gen_reg_rtx (mode);
1618 src = gen_reg_rtx (GET_MODE (orig_src));
1620 emit_move_insn (src, orig_src);
1623 /* Optimize the access just a bit. */
1625 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1626 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1627 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1628 && bytelen == GET_MODE_SIZE (mode))
1630 tmps[i] = gen_reg_rtx (mode);
1631 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1633 else if (GET_CODE (src) == CONCAT)
1635 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1636 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1638 if ((bytepos == 0 && bytelen == slen0)
1639 || (bytepos != 0 && bytepos + bytelen <= slen))
1641 /* The following assumes that the concatenated objects all
1642 have the same size. In this case, a simple calculation
1643 can be used to determine the object and the bit field
1645 tmps[i] = XEXP (src, bytepos / slen0);
1646 if (! CONSTANT_P (tmps[i])
1647 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1648 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1649 (bytepos % slen0) * BITS_PER_UNIT,
1650 1, NULL_RTX, mode, mode);
1652 else if (bytepos == 0)
1654 rtx mem = assign_stack_temp (GET_MODE (src), slen, 0);
1655 emit_move_insn (mem, src);
1656 tmps[i] = adjust_address (mem, mode, 0);
1661 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1662 SIMD register, which is currently broken. While we get GCC
1663 to emit proper RTL for these cases, let's dump to memory. */
1664 else if (VECTOR_MODE_P (GET_MODE (dst))
1667 int slen = GET_MODE_SIZE (GET_MODE (src));
1670 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1671 emit_move_insn (mem, src);
1672 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1674 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1675 && XVECLEN (dst, 0) > 1)
1676 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE(dst), bytepos);
1677 else if (CONSTANT_P (src)
1678 || (REG_P (src) && GET_MODE (src) == mode))
1681 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1682 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1686 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1687 build_int_2 (shift, 0), tmps[i], 0);
1690 /* Copy the extracted pieces into the proper (probable) hard regs. */
1691 for (i = start; i < XVECLEN (dst, 0); i++)
1692 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0), tmps[i]);
1695 /* Emit code to move a block SRC to block DST, where SRC and DST are
1696 non-consecutive groups of registers, each represented by a PARALLEL. */
1699 emit_group_move (rtx dst, rtx src)
1703 if (GET_CODE (src) != PARALLEL
1704 || GET_CODE (dst) != PARALLEL
1705 || XVECLEN (src, 0) != XVECLEN (dst, 0))
1708 /* Skip first entry if NULL. */
1709 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1710 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1711 XEXP (XVECEXP (src, 0, i), 0));
1714 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1715 where SRC is non-consecutive registers represented by a PARALLEL.
1716 SSIZE represents the total size of block ORIG_DST, or -1 if not
1720 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1725 if (GET_CODE (src) != PARALLEL)
1728 /* Check for a NULL entry, used to indicate that the parameter goes
1729 both on the stack and in registers. */
1730 if (XEXP (XVECEXP (src, 0, 0), 0))
1735 tmps = alloca (sizeof (rtx) * XVECLEN (src, 0));
1737 /* Copy the (probable) hard regs into pseudos. */
1738 for (i = start; i < XVECLEN (src, 0); i++)
1740 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1741 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1742 emit_move_insn (tmps[i], reg);
1745 /* If we won't be storing directly into memory, protect the real destination
1746 from strange tricks we might play. */
1748 if (GET_CODE (dst) == PARALLEL)
1752 /* We can get a PARALLEL dst if there is a conditional expression in
1753 a return statement. In that case, the dst and src are the same,
1754 so no action is necessary. */
1755 if (rtx_equal_p (dst, src))
1758 /* It is unclear if we can ever reach here, but we may as well handle
1759 it. Allocate a temporary, and split this into a store/load to/from
1762 temp = assign_stack_temp (GET_MODE (dst), ssize, 0);
1763 emit_group_store (temp, src, type, ssize);
1764 emit_group_load (dst, temp, type, ssize);
1767 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1769 dst = gen_reg_rtx (GET_MODE (orig_dst));
1770 /* Make life a bit easier for combine. */
1771 emit_move_insn (dst, CONST0_RTX (GET_MODE (orig_dst)));
1774 /* Process the pieces. */
1775 for (i = start; i < XVECLEN (src, 0); i++)
1777 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
1778 enum machine_mode mode = GET_MODE (tmps[i]);
1779 unsigned int bytelen = GET_MODE_SIZE (mode);
1782 /* Handle trailing fragments that run over the size of the struct. */
1783 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1785 /* store_bit_field always takes its value from the lsb.
1786 Move the fragment to the lsb if it's not already there. */
1788 #ifdef BLOCK_REG_PADDING
1789 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
1790 == (BYTES_BIG_ENDIAN ? upward : downward)
1796 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1797 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
1798 build_int_2 (shift, 0), tmps[i], 0);
1800 bytelen = ssize - bytepos;
1803 if (GET_CODE (dst) == CONCAT)
1805 if (bytepos + bytelen <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
1806 dest = XEXP (dst, 0);
1807 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
1809 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
1810 dest = XEXP (dst, 1);
1812 else if (bytepos == 0 && XVECLEN (src, 0))
1814 dest = assign_stack_temp (GET_MODE (dest),
1815 GET_MODE_SIZE (GET_MODE (dest)), 0);
1816 emit_move_insn (adjust_address (dest, GET_MODE (tmps[i]), bytepos),
1825 /* Optimize the access just a bit. */
1827 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
1828 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
1829 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1830 && bytelen == GET_MODE_SIZE (mode))
1831 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
1833 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
1837 /* Copy from the pseudo into the (probable) hard reg. */
1838 if (orig_dst != dst)
1839 emit_move_insn (orig_dst, dst);
1842 /* Generate code to copy a BLKmode object of TYPE out of a
1843 set of registers starting with SRCREG into TGTBLK. If TGTBLK
1844 is null, a stack temporary is created. TGTBLK is returned.
1846 The purpose of this routine is to handle functions that return
1847 BLKmode structures in registers. Some machines (the PA for example)
1848 want to return all small structures in registers regardless of the
1849 structure's alignment. */
1852 copy_blkmode_from_reg (rtx tgtblk, rtx srcreg, tree type)
1854 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
1855 rtx src = NULL, dst = NULL;
1856 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
1857 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
1861 tgtblk = assign_temp (build_qualified_type (type,
1863 | TYPE_QUAL_CONST)),
1865 preserve_temp_slots (tgtblk);
1868 /* This code assumes srcreg is at least a full word. If it isn't, copy it
1869 into a new pseudo which is a full word. */
1871 if (GET_MODE (srcreg) != BLKmode
1872 && GET_MODE_SIZE (GET_MODE (srcreg)) < UNITS_PER_WORD)
1873 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
1875 /* If the structure doesn't take up a whole number of words, see whether
1876 SRCREG is padded on the left or on the right. If it's on the left,
1877 set PADDING_CORRECTION to the number of bits to skip.
1879 In most ABIs, the structure will be returned at the least end of
1880 the register, which translates to right padding on little-endian
1881 targets and left padding on big-endian targets. The opposite
1882 holds if the structure is returned at the most significant
1883 end of the register. */
1884 if (bytes % UNITS_PER_WORD != 0
1885 && (targetm.calls.return_in_msb (type)
1887 : BYTES_BIG_ENDIAN))
1889 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
1891 /* Copy the structure BITSIZE bites at a time.
1893 We could probably emit more efficient code for machines which do not use
1894 strict alignment, but it doesn't seem worth the effort at the current
1896 for (bitpos = 0, xbitpos = padding_correction;
1897 bitpos < bytes * BITS_PER_UNIT;
1898 bitpos += bitsize, xbitpos += bitsize)
1900 /* We need a new source operand each time xbitpos is on a
1901 word boundary and when xbitpos == padding_correction
1902 (the first time through). */
1903 if (xbitpos % BITS_PER_WORD == 0
1904 || xbitpos == padding_correction)
1905 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD,
1908 /* We need a new destination operand each time bitpos is on
1910 if (bitpos % BITS_PER_WORD == 0)
1911 dst = operand_subword (tgtblk, bitpos / BITS_PER_WORD, 1, BLKmode);
1913 /* Use xbitpos for the source extraction (right justified) and
1914 xbitpos for the destination store (left justified). */
1915 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
1916 extract_bit_field (src, bitsize,
1917 xbitpos % BITS_PER_WORD, 1,
1918 NULL_RTX, word_mode, word_mode));
1924 /* Add a USE expression for REG to the (possibly empty) list pointed
1925 to by CALL_FUSAGE. REG must denote a hard register. */
1928 use_reg (rtx *call_fusage, rtx reg)
1931 || REGNO (reg) >= FIRST_PSEUDO_REGISTER)
1935 = gen_rtx_EXPR_LIST (VOIDmode,
1936 gen_rtx_USE (VOIDmode, reg), *call_fusage);
1939 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
1940 starting at REGNO. All of these registers must be hard registers. */
1943 use_regs (rtx *call_fusage, int regno, int nregs)
1947 if (regno + nregs > FIRST_PSEUDO_REGISTER)
1950 for (i = 0; i < nregs; i++)
1951 use_reg (call_fusage, regno_reg_rtx[regno + i]);
1954 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
1955 PARALLEL REGS. This is for calls that pass values in multiple
1956 non-contiguous locations. The Irix 6 ABI has examples of this. */
1959 use_group_regs (rtx *call_fusage, rtx regs)
1963 for (i = 0; i < XVECLEN (regs, 0); i++)
1965 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
1967 /* A NULL entry means the parameter goes both on the stack and in
1968 registers. This can also be a MEM for targets that pass values
1969 partially on the stack and partially in registers. */
1970 if (reg != 0 && REG_P (reg))
1971 use_reg (call_fusage, reg);
1976 /* Determine whether the LEN bytes generated by CONSTFUN can be
1977 stored to memory using several move instructions. CONSTFUNDATA is
1978 a pointer which will be passed as argument in every CONSTFUN call.
1979 ALIGN is maximum alignment we can assume. Return nonzero if a
1980 call to store_by_pieces should succeed. */
1983 can_store_by_pieces (unsigned HOST_WIDE_INT len,
1984 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
1985 void *constfundata, unsigned int align)
1987 unsigned HOST_WIDE_INT max_size, l;
1988 HOST_WIDE_INT offset = 0;
1989 enum machine_mode mode, tmode;
1990 enum insn_code icode;
1997 if (! STORE_BY_PIECES_P (len, align))
2000 if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
2001 || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
2002 align = MOVE_MAX * BITS_PER_UNIT;
2004 /* We would first store what we can in the largest integer mode, then go to
2005 successively smaller modes. */
2008 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2013 max_size = STORE_MAX_PIECES + 1;
2014 while (max_size > 1)
2016 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2017 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2018 if (GET_MODE_SIZE (tmode) < max_size)
2021 if (mode == VOIDmode)
2024 icode = mov_optab->handlers[(int) mode].insn_code;
2025 if (icode != CODE_FOR_nothing
2026 && align >= GET_MODE_ALIGNMENT (mode))
2028 unsigned int size = GET_MODE_SIZE (mode);
2035 cst = (*constfun) (constfundata, offset, mode);
2036 if (!LEGITIMATE_CONSTANT_P (cst))
2046 max_size = GET_MODE_SIZE (mode);
2049 /* The code above should have handled everything. */
2057 /* Generate several move instructions to store LEN bytes generated by
2058 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2059 pointer which will be passed as argument in every CONSTFUN call.
2060 ALIGN is maximum alignment we can assume.
2061 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2062 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2066 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2067 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2068 void *constfundata, unsigned int align, int endp)
2070 struct store_by_pieces data;
2079 if (! STORE_BY_PIECES_P (len, align))
2081 data.constfun = constfun;
2082 data.constfundata = constfundata;
2085 store_by_pieces_1 (&data, align);
2096 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2097 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2099 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
2102 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2109 to1 = adjust_address (data.to, QImode, data.offset);
2117 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2118 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2121 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2123 struct store_by_pieces data;
2128 data.constfun = clear_by_pieces_1;
2129 data.constfundata = NULL;
2132 store_by_pieces_1 (&data, align);
2135 /* Callback routine for clear_by_pieces.
2136 Return const0_rtx unconditionally. */
2139 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2140 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2141 enum machine_mode mode ATTRIBUTE_UNUSED)
2146 /* Subroutine of clear_by_pieces and store_by_pieces.
2147 Generate several move instructions to store LEN bytes of block TO. (A MEM
2148 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2151 store_by_pieces_1 (struct store_by_pieces *data ATTRIBUTE_UNUSED,
2152 unsigned int align ATTRIBUTE_UNUSED)
2154 rtx to_addr = XEXP (data->to, 0);
2155 unsigned HOST_WIDE_INT max_size = STORE_MAX_PIECES + 1;
2156 enum machine_mode mode = VOIDmode, tmode;
2157 enum insn_code icode;
2160 data->to_addr = to_addr;
2162 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2163 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2165 data->explicit_inc_to = 0;
2167 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2169 data->offset = data->len;
2171 /* If storing requires more than two move insns,
2172 copy addresses to registers (to make displacements shorter)
2173 and use post-increment if available. */
2174 if (!data->autinc_to
2175 && move_by_pieces_ninsns (data->len, align) > 2)
2177 /* Determine the main mode we'll be using. */
2178 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2179 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2180 if (GET_MODE_SIZE (tmode) < max_size)
2183 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2185 data->to_addr = copy_addr_to_reg (plus_constant (to_addr, data->len));
2186 data->autinc_to = 1;
2187 data->explicit_inc_to = -1;
2190 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2191 && ! data->autinc_to)
2193 data->to_addr = copy_addr_to_reg (to_addr);
2194 data->autinc_to = 1;
2195 data->explicit_inc_to = 1;
2198 if ( !data->autinc_to && CONSTANT_P (to_addr))
2199 data->to_addr = copy_addr_to_reg (to_addr);
2202 if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
2203 || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
2204 align = MOVE_MAX * BITS_PER_UNIT;
2206 /* First store what we can in the largest integer mode, then go to
2207 successively smaller modes. */
2209 while (max_size > 1)
2211 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2212 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2213 if (GET_MODE_SIZE (tmode) < max_size)
2216 if (mode == VOIDmode)
2219 icode = mov_optab->handlers[(int) mode].insn_code;
2220 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2221 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2223 max_size = GET_MODE_SIZE (mode);
2226 /* The code above should have handled everything. */
2231 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2232 with move instructions for mode MODE. GENFUN is the gen_... function
2233 to make a move insn for that mode. DATA has all the other info. */
2236 store_by_pieces_2 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
2237 struct store_by_pieces *data)
2239 unsigned int size = GET_MODE_SIZE (mode);
2242 while (data->len >= size)
2245 data->offset -= size;
2247 if (data->autinc_to)
2248 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2251 to1 = adjust_address (data->to, mode, data->offset);
2253 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2254 emit_insn (gen_add2_insn (data->to_addr,
2255 GEN_INT (-(HOST_WIDE_INT) size)));
2257 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2258 emit_insn ((*genfun) (to1, cst));
2260 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2261 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2263 if (! data->reverse)
2264 data->offset += size;
2270 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2271 its length in bytes. */
2274 clear_storage (rtx object, rtx size)
2277 unsigned int align = (MEM_P (object) ? MEM_ALIGN (object)
2278 : GET_MODE_ALIGNMENT (GET_MODE (object)));
2280 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2281 just move a zero. Otherwise, do this a piece at a time. */
2282 if (GET_MODE (object) != BLKmode
2283 && GET_CODE (size) == CONST_INT
2284 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (object)))
2285 emit_move_insn (object, CONST0_RTX (GET_MODE (object)));
2288 if (size == const0_rtx)
2290 else if (GET_CODE (size) == CONST_INT
2291 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2292 clear_by_pieces (object, INTVAL (size), align);
2293 else if (clear_storage_via_clrmem (object, size, align))
2296 retval = clear_storage_via_libcall (object, size);
2302 /* A subroutine of clear_storage. Expand a clrmem pattern;
2303 return true if successful. */
2306 clear_storage_via_clrmem (rtx object, rtx size, unsigned int align)
2308 /* Try the most limited insn first, because there's no point
2309 including more than one in the machine description unless
2310 the more limited one has some advantage. */
2312 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
2313 enum machine_mode mode;
2315 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2316 mode = GET_MODE_WIDER_MODE (mode))
2318 enum insn_code code = clrmem_optab[(int) mode];
2319 insn_operand_predicate_fn pred;
2321 if (code != CODE_FOR_nothing
2322 /* We don't need MODE to be narrower than
2323 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2324 the mode mask, as it is returned by the macro, it will
2325 definitely be less than the actual mode mask. */
2326 && ((GET_CODE (size) == CONST_INT
2327 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2328 <= (GET_MODE_MASK (mode) >> 1)))
2329 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2330 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
2331 || (*pred) (object, BLKmode))
2332 && ((pred = insn_data[(int) code].operand[2].predicate) == 0
2333 || (*pred) (opalign, VOIDmode)))
2336 rtx last = get_last_insn ();
2339 op1 = convert_to_mode (mode, size, 1);
2340 pred = insn_data[(int) code].operand[1].predicate;
2341 if (pred != 0 && ! (*pred) (op1, mode))
2342 op1 = copy_to_mode_reg (mode, op1);
2344 pat = GEN_FCN ((int) code) (object, op1, opalign);
2351 delete_insns_since (last);
2358 /* A subroutine of clear_storage. Expand a call to memset.
2359 Return the return value of memset, 0 otherwise. */
2362 clear_storage_via_libcall (rtx object, rtx size)
2364 tree call_expr, arg_list, fn, object_tree, size_tree;
2365 enum machine_mode size_mode;
2368 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2369 place those into new pseudos into a VAR_DECL and use them later. */
2371 object = copy_to_mode_reg (Pmode, XEXP (object, 0));
2373 size_mode = TYPE_MODE (sizetype);
2374 size = convert_to_mode (size_mode, size, 1);
2375 size = copy_to_mode_reg (size_mode, size);
2377 /* It is incorrect to use the libcall calling conventions to call
2378 memset in this context. This could be a user call to memset and
2379 the user may wish to examine the return value from memset. For
2380 targets where libcalls and normal calls have different conventions
2381 for returning pointers, we could end up generating incorrect code. */
2383 object_tree = make_tree (ptr_type_node, object);
2384 size_tree = make_tree (sizetype, size);
2386 fn = clear_storage_libcall_fn (true);
2387 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
2388 arg_list = tree_cons (NULL_TREE, integer_zero_node, arg_list);
2389 arg_list = tree_cons (NULL_TREE, object_tree, arg_list);
2391 /* Now we have to build up the CALL_EXPR itself. */
2392 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
2393 call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
2394 call_expr, arg_list, NULL_TREE);
2396 retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
2398 /* If we are initializing a readonly value, show the above call
2399 clobbered it. Otherwise, a load from it may erroneously be
2400 hoisted from a loop. */
2401 if (RTX_UNCHANGING_P (object))
2402 emit_insn (gen_rtx_CLOBBER (VOIDmode, object));
2407 /* A subroutine of clear_storage_via_libcall. Create the tree node
2408 for the function we use for block clears. The first time FOR_CALL
2409 is true, we call assemble_external. */
2411 static GTY(()) tree block_clear_fn;
2414 init_block_clear_fn (const char *asmspec)
2416 if (!block_clear_fn)
2420 fn = get_identifier ("memset");
2421 args = build_function_type_list (ptr_type_node, ptr_type_node,
2422 integer_type_node, sizetype,
2425 fn = build_decl (FUNCTION_DECL, fn, args);
2426 DECL_EXTERNAL (fn) = 1;
2427 TREE_PUBLIC (fn) = 1;
2428 DECL_ARTIFICIAL (fn) = 1;
2429 TREE_NOTHROW (fn) = 1;
2431 block_clear_fn = fn;
2436 SET_DECL_RTL (block_clear_fn, NULL_RTX);
2437 SET_DECL_ASSEMBLER_NAME (block_clear_fn, get_identifier (asmspec));
2442 clear_storage_libcall_fn (int for_call)
2444 static bool emitted_extern;
2446 if (!block_clear_fn)
2447 init_block_clear_fn (NULL);
2449 if (for_call && !emitted_extern)
2451 emitted_extern = true;
2452 make_decl_rtl (block_clear_fn, NULL);
2453 assemble_external (block_clear_fn);
2456 return block_clear_fn;
2459 /* Generate code to copy Y into X.
2460 Both Y and X must have the same mode, except that
2461 Y can be a constant with VOIDmode.
2462 This mode cannot be BLKmode; use emit_block_move for that.
2464 Return the last instruction emitted. */
2467 emit_move_insn (rtx x, rtx y)
2469 enum machine_mode mode = GET_MODE (x);
2470 rtx y_cst = NULL_RTX;
2473 if (mode == BLKmode || (GET_MODE (y) != mode && GET_MODE (y) != VOIDmode))
2479 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
2480 && (last_insn = compress_float_constant (x, y)))
2485 if (!LEGITIMATE_CONSTANT_P (y))
2487 y = force_const_mem (mode, y);
2489 /* If the target's cannot_force_const_mem prevented the spill,
2490 assume that the target's move expanders will also take care
2491 of the non-legitimate constant. */
2497 /* If X or Y are memory references, verify that their addresses are valid
2500 && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
2501 && ! push_operand (x, GET_MODE (x)))
2503 && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
2504 x = validize_mem (x);
2507 && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
2509 && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
2510 y = validize_mem (y);
2512 if (mode == BLKmode)
2515 last_insn = emit_move_insn_1 (x, y);
2517 if (y_cst && REG_P (x)
2518 && (set = single_set (last_insn)) != NULL_RTX
2519 && SET_DEST (set) == x
2520 && ! rtx_equal_p (y_cst, SET_SRC (set)))
2521 set_unique_reg_note (last_insn, REG_EQUAL, y_cst);
2526 /* Low level part of emit_move_insn.
2527 Called just like emit_move_insn, but assumes X and Y
2528 are basically valid. */
2531 emit_move_insn_1 (rtx x, rtx y)
2533 enum machine_mode mode = GET_MODE (x);
2534 enum machine_mode submode;
2535 enum mode_class class = GET_MODE_CLASS (mode);
2537 if ((unsigned int) mode >= (unsigned int) MAX_MACHINE_MODE)
2540 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2542 emit_insn (GEN_FCN (mov_optab->handlers[(int) mode].insn_code) (x, y));
2544 /* Expand complex moves by moving real part and imag part, if possible. */
2545 else if ((class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
2546 && BLKmode != (submode = GET_MODE_INNER (mode))
2547 && (mov_optab->handlers[(int) submode].insn_code
2548 != CODE_FOR_nothing))
2550 /* Don't split destination if it is a stack push. */
2551 int stack = push_operand (x, GET_MODE (x));
2553 #ifdef PUSH_ROUNDING
2554 /* In case we output to the stack, but the size is smaller than the
2555 machine can push exactly, we need to use move instructions. */
2557 && (PUSH_ROUNDING (GET_MODE_SIZE (submode))
2558 != GET_MODE_SIZE (submode)))
2561 HOST_WIDE_INT offset1, offset2;
2563 /* Do not use anti_adjust_stack, since we don't want to update
2564 stack_pointer_delta. */
2565 temp = expand_binop (Pmode,
2566 #ifdef STACK_GROWS_DOWNWARD
2574 (GET_MODE_SIZE (GET_MODE (x)))),
2575 stack_pointer_rtx, 0, OPTAB_LIB_WIDEN);
2577 if (temp != stack_pointer_rtx)
2578 emit_move_insn (stack_pointer_rtx, temp);
2580 #ifdef STACK_GROWS_DOWNWARD
2582 offset2 = GET_MODE_SIZE (submode);
2584 offset1 = -PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (x)));
2585 offset2 = (-PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (x)))
2586 + GET_MODE_SIZE (submode));
2589 emit_move_insn (change_address (x, submode,
2590 gen_rtx_PLUS (Pmode,
2592 GEN_INT (offset1))),
2593 gen_realpart (submode, y));
2594 emit_move_insn (change_address (x, submode,
2595 gen_rtx_PLUS (Pmode,
2597 GEN_INT (offset2))),
2598 gen_imagpart (submode, y));
2602 /* If this is a stack, push the highpart first, so it
2603 will be in the argument order.
2605 In that case, change_address is used only to convert
2606 the mode, not to change the address. */
2609 /* Note that the real part always precedes the imag part in memory
2610 regardless of machine's endianness. */
2611 #ifdef STACK_GROWS_DOWNWARD
2612 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2613 gen_imagpart (submode, y));
2614 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2615 gen_realpart (submode, y));
2617 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2618 gen_realpart (submode, y));
2619 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2620 gen_imagpart (submode, y));
2625 rtx realpart_x, realpart_y;
2626 rtx imagpart_x, imagpart_y;
2628 /* If this is a complex value with each part being smaller than a
2629 word, the usual calling sequence will likely pack the pieces into
2630 a single register. Unfortunately, SUBREG of hard registers only
2631 deals in terms of words, so we have a problem converting input
2632 arguments to the CONCAT of two registers that is used elsewhere
2633 for complex values. If this is before reload, we can copy it into
2634 memory and reload. FIXME, we should see about using extract and
2635 insert on integer registers, but complex short and complex char
2636 variables should be rarely used. */
2637 if (GET_MODE_BITSIZE (mode) < 2 * BITS_PER_WORD
2638 && (reload_in_progress | reload_completed) == 0)
2641 = (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER);
2643 = (REG_P (y) && REGNO (y) < FIRST_PSEUDO_REGISTER);
2645 if (packed_dest_p || packed_src_p)
2647 enum mode_class reg_class = ((class == MODE_COMPLEX_FLOAT)
2648 ? MODE_FLOAT : MODE_INT);
2650 enum machine_mode reg_mode
2651 = mode_for_size (GET_MODE_BITSIZE (mode), reg_class, 1);
2653 if (reg_mode != BLKmode)
2655 rtx mem = assign_stack_temp (reg_mode,
2656 GET_MODE_SIZE (mode), 0);
2657 rtx cmem = adjust_address (mem, mode, 0);
2661 rtx sreg = gen_rtx_SUBREG (reg_mode, x, 0);
2663 emit_move_insn_1 (cmem, y);
2664 return emit_move_insn_1 (sreg, mem);
2668 rtx sreg = gen_rtx_SUBREG (reg_mode, y, 0);
2670 emit_move_insn_1 (mem, sreg);
2671 return emit_move_insn_1 (x, cmem);
2677 realpart_x = gen_realpart (submode, x);
2678 realpart_y = gen_realpart (submode, y);
2679 imagpart_x = gen_imagpart (submode, x);
2680 imagpart_y = gen_imagpart (submode, y);
2682 /* Show the output dies here. This is necessary for SUBREGs
2683 of pseudos since we cannot track their lifetimes correctly;
2684 hard regs shouldn't appear here except as return values.
2685 We never want to emit such a clobber after reload. */
2687 && ! (reload_in_progress || reload_completed)
2688 && (GET_CODE (realpart_x) == SUBREG
2689 || GET_CODE (imagpart_x) == SUBREG))
2690 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
2692 emit_move_insn (realpart_x, realpart_y);
2693 emit_move_insn (imagpart_x, imagpart_y);
2696 return get_last_insn ();
2699 /* Handle MODE_CC modes: If we don't have a special move insn for this mode,
2700 find a mode to do it in. If we have a movcc, use it. Otherwise,
2701 find the MODE_INT mode of the same width. */
2702 else if (GET_MODE_CLASS (mode) == MODE_CC
2703 && mov_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
2705 enum insn_code insn_code;
2706 enum machine_mode tmode = VOIDmode;
2710 && mov_optab->handlers[(int) CCmode].insn_code != CODE_FOR_nothing)
2713 for (tmode = QImode; tmode != VOIDmode;
2714 tmode = GET_MODE_WIDER_MODE (tmode))
2715 if (GET_MODE_SIZE (tmode) == GET_MODE_SIZE (mode))
2718 if (tmode == VOIDmode)
2721 /* Get X and Y in TMODE. We can't use gen_lowpart here because it
2722 may call change_address which is not appropriate if we were
2723 called when a reload was in progress. We don't have to worry
2724 about changing the address since the size in bytes is supposed to
2725 be the same. Copy the MEM to change the mode and move any
2726 substitutions from the old MEM to the new one. */
2728 if (reload_in_progress)
2730 x = gen_lowpart_common (tmode, x1);
2731 if (x == 0 && MEM_P (x1))
2733 x = adjust_address_nv (x1, tmode, 0);
2734 copy_replacements (x1, x);
2737 y = gen_lowpart_common (tmode, y1);
2738 if (y == 0 && MEM_P (y1))
2740 y = adjust_address_nv (y1, tmode, 0);
2741 copy_replacements (y1, y);
2746 x = gen_lowpart (tmode, x);
2747 y = gen_lowpart (tmode, y);
2750 insn_code = mov_optab->handlers[(int) tmode].insn_code;
2751 return emit_insn (GEN_FCN (insn_code) (x, y));
2754 /* Try using a move pattern for the corresponding integer mode. This is
2755 only safe when simplify_subreg can convert MODE constants into integer
2756 constants. At present, it can only do this reliably if the value
2757 fits within a HOST_WIDE_INT. */
2758 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2759 && (submode = int_mode_for_mode (mode)) != BLKmode
2760 && mov_optab->handlers[submode].insn_code != CODE_FOR_nothing)
2761 return emit_insn (GEN_FCN (mov_optab->handlers[submode].insn_code)
2762 (simplify_gen_subreg (submode, x, mode, 0),
2763 simplify_gen_subreg (submode, y, mode, 0)));
2765 /* This will handle any multi-word or full-word mode that lacks a move_insn
2766 pattern. However, you will get better code if you define such patterns,
2767 even if they must turn into multiple assembler instructions. */
2768 else if (GET_MODE_SIZE (mode) >= UNITS_PER_WORD)
2775 #ifdef PUSH_ROUNDING
2777 /* If X is a push on the stack, do the push now and replace
2778 X with a reference to the stack pointer. */
2779 if (push_operand (x, GET_MODE (x)))
2784 /* Do not use anti_adjust_stack, since we don't want to update
2785 stack_pointer_delta. */
2786 temp = expand_binop (Pmode,
2787 #ifdef STACK_GROWS_DOWNWARD
2795 (GET_MODE_SIZE (GET_MODE (x)))),
2796 stack_pointer_rtx, 0, OPTAB_LIB_WIDEN);
2798 if (temp != stack_pointer_rtx)
2799 emit_move_insn (stack_pointer_rtx, temp);
2801 code = GET_CODE (XEXP (x, 0));
2803 /* Just hope that small offsets off SP are OK. */
2804 if (code == POST_INC)
2805 temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
2806 GEN_INT (-((HOST_WIDE_INT)
2807 GET_MODE_SIZE (GET_MODE (x)))));
2808 else if (code == POST_DEC)
2809 temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
2810 GEN_INT (GET_MODE_SIZE (GET_MODE (x))));
2812 temp = stack_pointer_rtx;
2814 x = change_address (x, VOIDmode, temp);
2818 /* If we are in reload, see if either operand is a MEM whose address
2819 is scheduled for replacement. */
2820 if (reload_in_progress && MEM_P (x)
2821 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
2822 x = replace_equiv_address_nv (x, inner);
2823 if (reload_in_progress && MEM_P (y)
2824 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
2825 y = replace_equiv_address_nv (y, inner);
2831 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2834 rtx xpart = operand_subword (x, i, 1, mode);
2835 rtx ypart = operand_subword (y, i, 1, mode);
2837 /* If we can't get a part of Y, put Y into memory if it is a
2838 constant. Otherwise, force it into a register. If we still
2839 can't get a part of Y, abort. */
2840 if (ypart == 0 && CONSTANT_P (y))
2842 y = force_const_mem (mode, y);
2843 ypart = operand_subword (y, i, 1, mode);
2845 else if (ypart == 0)
2846 ypart = operand_subword_force (y, i, mode);
2848 if (xpart == 0 || ypart == 0)
2851 need_clobber |= (GET_CODE (xpart) == SUBREG);
2853 last_insn = emit_move_insn (xpart, ypart);
2859 /* Show the output dies here. This is necessary for SUBREGs
2860 of pseudos since we cannot track their lifetimes correctly;
2861 hard regs shouldn't appear here except as return values.
2862 We never want to emit such a clobber after reload. */
2864 && ! (reload_in_progress || reload_completed)
2865 && need_clobber != 0)
2866 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
2876 /* If Y is representable exactly in a narrower mode, and the target can
2877 perform the extension directly from constant or memory, then emit the
2878 move as an extension. */
2881 compress_float_constant (rtx x, rtx y)
2883 enum machine_mode dstmode = GET_MODE (x);
2884 enum machine_mode orig_srcmode = GET_MODE (y);
2885 enum machine_mode srcmode;
2888 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
2890 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
2891 srcmode != orig_srcmode;
2892 srcmode = GET_MODE_WIDER_MODE (srcmode))
2895 rtx trunc_y, last_insn;
2897 /* Skip if the target can't extend this way. */
2898 ic = can_extend_p (dstmode, srcmode, 0);
2899 if (ic == CODE_FOR_nothing)
2902 /* Skip if the narrowed value isn't exact. */
2903 if (! exact_real_truncate (srcmode, &r))
2906 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
2908 if (LEGITIMATE_CONSTANT_P (trunc_y))
2910 /* Skip if the target needs extra instructions to perform
2912 if (! (*insn_data[ic].operand[1].predicate) (trunc_y, srcmode))
2915 else if (float_extend_from_mem[dstmode][srcmode])
2916 trunc_y = validize_mem (force_const_mem (srcmode, trunc_y));
2920 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
2921 last_insn = get_last_insn ();
2924 set_unique_reg_note (last_insn, REG_EQUAL, y);
2932 /* Pushing data onto the stack. */
2934 /* Push a block of length SIZE (perhaps variable)
2935 and return an rtx to address the beginning of the block.
2936 Note that it is not possible for the value returned to be a QUEUED.
2937 The value may be virtual_outgoing_args_rtx.
2939 EXTRA is the number of bytes of padding to push in addition to SIZE.
2940 BELOW nonzero means this padding comes at low addresses;
2941 otherwise, the padding comes at high addresses. */
2944 push_block (rtx size, int extra, int below)
2948 size = convert_modes (Pmode, ptr_mode, size, 1);
2949 if (CONSTANT_P (size))
2950 anti_adjust_stack (plus_constant (size, extra));
2951 else if (REG_P (size) && extra == 0)
2952 anti_adjust_stack (size);
2955 temp = copy_to_mode_reg (Pmode, size);
2957 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
2958 temp, 0, OPTAB_LIB_WIDEN);
2959 anti_adjust_stack (temp);
2962 #ifndef STACK_GROWS_DOWNWARD
2968 temp = virtual_outgoing_args_rtx;
2969 if (extra != 0 && below)
2970 temp = plus_constant (temp, extra);
2974 if (GET_CODE (size) == CONST_INT)
2975 temp = plus_constant (virtual_outgoing_args_rtx,
2976 -INTVAL (size) - (below ? 0 : extra));
2977 else if (extra != 0 && !below)
2978 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
2979 negate_rtx (Pmode, plus_constant (size, extra)));
2981 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
2982 negate_rtx (Pmode, size));
2985 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
2988 #ifdef PUSH_ROUNDING
2990 /* Emit single push insn. */
2993 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
2996 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
2998 enum insn_code icode;
2999 insn_operand_predicate_fn pred;
3001 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3002 /* If there is push pattern, use it. Otherwise try old way of throwing
3003 MEM representing push operation to move expander. */
3004 icode = push_optab->handlers[(int) mode].insn_code;
3005 if (icode != CODE_FOR_nothing)
3007 if (((pred = insn_data[(int) icode].operand[0].predicate)
3008 && !((*pred) (x, mode))))
3009 x = force_reg (mode, x);
3010 emit_insn (GEN_FCN (icode) (x));
3013 if (GET_MODE_SIZE (mode) == rounded_size)
3014 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3015 /* If we are to pad downward, adjust the stack pointer first and
3016 then store X into the stack location using an offset. This is
3017 because emit_move_insn does not know how to pad; it does not have
3019 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3021 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3022 HOST_WIDE_INT offset;
3024 emit_move_insn (stack_pointer_rtx,
3025 expand_binop (Pmode,
3026 #ifdef STACK_GROWS_DOWNWARD
3032 GEN_INT (rounded_size),
3033 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3035 offset = (HOST_WIDE_INT) padding_size;
3036 #ifdef STACK_GROWS_DOWNWARD
3037 if (STACK_PUSH_CODE == POST_DEC)
3038 /* We have already decremented the stack pointer, so get the
3040 offset += (HOST_WIDE_INT) rounded_size;
3042 if (STACK_PUSH_CODE == POST_INC)
3043 /* We have already incremented the stack pointer, so get the
3045 offset -= (HOST_WIDE_INT) rounded_size;
3047 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3051 #ifdef STACK_GROWS_DOWNWARD
3052 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3053 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3054 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3056 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3057 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3058 GEN_INT (rounded_size));
3060 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3063 dest = gen_rtx_MEM (mode, dest_addr);
3067 set_mem_attributes (dest, type, 1);
3069 if (flag_optimize_sibling_calls)
3070 /* Function incoming arguments may overlap with sibling call
3071 outgoing arguments and we cannot allow reordering of reads
3072 from function arguments with stores to outgoing arguments
3073 of sibling calls. */
3074 set_mem_alias_set (dest, 0);
3076 emit_move_insn (dest, x);
3080 /* Generate code to push X onto the stack, assuming it has mode MODE and
3082 MODE is redundant except when X is a CONST_INT (since they don't
3084 SIZE is an rtx for the size of data to be copied (in bytes),
3085 needed only if X is BLKmode.
3087 ALIGN (in bits) is maximum alignment we can assume.
3089 If PARTIAL and REG are both nonzero, then copy that many of the first
3090 words of X into registers starting with REG, and push the rest of X.
3091 The amount of space pushed is decreased by PARTIAL words,
3092 rounded *down* to a multiple of PARM_BOUNDARY.
3093 REG must be a hard register in this case.
3094 If REG is zero but PARTIAL is not, take any all others actions for an
3095 argument partially in registers, but do not actually load any
3098 EXTRA is the amount in bytes of extra space to leave next to this arg.
3099 This is ignored if an argument block has already been allocated.
3101 On a machine that lacks real push insns, ARGS_ADDR is the address of
3102 the bottom of the argument block for this call. We use indexing off there
3103 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3104 argument block has not been preallocated.
3106 ARGS_SO_FAR is the size of args previously pushed for this call.
3108 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3109 for arguments passed in registers. If nonzero, it will be the number
3110 of bytes required. */
3113 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
3114 unsigned int align, int partial, rtx reg, int extra,
3115 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
3119 enum direction stack_direction
3120 #ifdef STACK_GROWS_DOWNWARD
3126 /* Decide where to pad the argument: `downward' for below,
3127 `upward' for above, or `none' for don't pad it.
3128 Default is below for small data on big-endian machines; else above. */
3129 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
3131 /* Invert direction if stack is post-decrement.
3133 if (STACK_PUSH_CODE == POST_DEC)
3134 if (where_pad != none)
3135 where_pad = (where_pad == downward ? upward : downward);
3139 if (mode == BLKmode)
3141 /* Copy a block into the stack, entirely or partially. */
3144 int used = partial * UNITS_PER_WORD;
3148 if (reg && GET_CODE (reg) == PARALLEL)
3150 /* Use the size of the elt to compute offset. */
3151 rtx elt = XEXP (XVECEXP (reg, 0, 0), 0);
3152 used = partial * GET_MODE_SIZE (GET_MODE (elt));
3153 offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
3156 offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
3163 /* USED is now the # of bytes we need not copy to the stack
3164 because registers will take care of them. */
3167 xinner = adjust_address (xinner, BLKmode, used);
3169 /* If the partial register-part of the arg counts in its stack size,
3170 skip the part of stack space corresponding to the registers.
3171 Otherwise, start copying to the beginning of the stack space,
3172 by setting SKIP to 0. */
3173 skip = (reg_parm_stack_space == 0) ? 0 : used;
3175 #ifdef PUSH_ROUNDING
3176 /* Do it with several push insns if that doesn't take lots of insns
3177 and if there is no difficulty with push insns that skip bytes
3178 on the stack for alignment purposes. */
3181 && GET_CODE (size) == CONST_INT
3183 && MEM_ALIGN (xinner) >= align
3184 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
3185 /* Here we avoid the case of a structure whose weak alignment
3186 forces many pushes of a small amount of data,
3187 and such small pushes do rounding that causes trouble. */
3188 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
3189 || align >= BIGGEST_ALIGNMENT
3190 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
3191 == (align / BITS_PER_UNIT)))
3192 && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
3194 /* Push padding now if padding above and stack grows down,
3195 or if padding below and stack grows up.
3196 But if space already allocated, this has already been done. */
3197 if (extra && args_addr == 0
3198 && where_pad != none && where_pad != stack_direction)
3199 anti_adjust_stack (GEN_INT (extra));
3201 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
3204 #endif /* PUSH_ROUNDING */
3208 /* Otherwise make space on the stack and copy the data
3209 to the address of that space. */
3211 /* Deduct words put into registers from the size we must copy. */
3214 if (GET_CODE (size) == CONST_INT)
3215 size = GEN_INT (INTVAL (size) - used);
3217 size = expand_binop (GET_MODE (size), sub_optab, size,
3218 GEN_INT (used), NULL_RTX, 0,
3222 /* Get the address of the stack space.
3223 In this case, we do not deal with EXTRA separately.
3224 A single stack adjust will do. */
3227 temp = push_block (size, extra, where_pad == downward);
3230 else if (GET_CODE (args_so_far) == CONST_INT)
3231 temp = memory_address (BLKmode,
3232 plus_constant (args_addr,
3233 skip + INTVAL (args_so_far)));
3235 temp = memory_address (BLKmode,
3236 plus_constant (gen_rtx_PLUS (Pmode,
3241 if (!ACCUMULATE_OUTGOING_ARGS)
3243 /* If the source is referenced relative to the stack pointer,
3244 copy it to another register to stabilize it. We do not need
3245 to do this if we know that we won't be changing sp. */
3247 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
3248 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
3249 temp = copy_to_reg (temp);
3252 target = gen_rtx_MEM (BLKmode, temp);
3256 set_mem_attributes (target, type, 1);
3257 /* Function incoming arguments may overlap with sibling call
3258 outgoing arguments and we cannot allow reordering of reads
3259 from function arguments with stores to outgoing arguments
3260 of sibling calls. */
3261 set_mem_alias_set (target, 0);
3264 /* ALIGN may well be better aligned than TYPE, e.g. due to
3265 PARM_BOUNDARY. Assume the caller isn't lying. */
3266 set_mem_align (target, align);
3268 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
3271 else if (partial > 0)
3273 /* Scalar partly in registers. */
3275 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
3278 /* # words of start of argument
3279 that we must make space for but need not store. */
3280 int offset = partial % (PARM_BOUNDARY / BITS_PER_WORD);
3281 int args_offset = INTVAL (args_so_far);
3284 /* Push padding now if padding above and stack grows down,
3285 or if padding below and stack grows up.
3286 But if space already allocated, this has already been done. */
3287 if (extra && args_addr == 0
3288 && where_pad != none && where_pad != stack_direction)
3289 anti_adjust_stack (GEN_INT (extra));
3291 /* If we make space by pushing it, we might as well push
3292 the real data. Otherwise, we can leave OFFSET nonzero
3293 and leave the space uninitialized. */
3297 /* Now NOT_STACK gets the number of words that we don't need to
3298 allocate on the stack. */
3299 not_stack = partial - offset;
3301 /* If the partial register-part of the arg counts in its stack size,
3302 skip the part of stack space corresponding to the registers.
3303 Otherwise, start copying to the beginning of the stack space,
3304 by setting SKIP to 0. */
3305 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
3307 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
3308 x = validize_mem (force_const_mem (mode, x));
3310 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
3311 SUBREGs of such registers are not allowed. */
3312 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
3313 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
3314 x = copy_to_reg (x);
3316 /* Loop over all the words allocated on the stack for this arg. */
3317 /* We can do it by words, because any scalar bigger than a word
3318 has a size a multiple of a word. */
3319 #ifndef PUSH_ARGS_REVERSED
3320 for (i = not_stack; i < size; i++)
3322 for (i = size - 1; i >= not_stack; i--)
3324 if (i >= not_stack + offset)
3325 emit_push_insn (operand_subword_force (x, i, mode),
3326 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
3328 GEN_INT (args_offset + ((i - not_stack + skip)
3330 reg_parm_stack_space, alignment_pad);
3337 /* Push padding now if padding above and stack grows down,
3338 or if padding below and stack grows up.
3339 But if space already allocated, this has already been done. */
3340 if (extra && args_addr == 0
3341 && where_pad != none && where_pad != stack_direction)
3342 anti_adjust_stack (GEN_INT (extra));
3344 #ifdef PUSH_ROUNDING
3345 if (args_addr == 0 && PUSH_ARGS)
3346 emit_single_push_insn (mode, x, type);
3350 if (GET_CODE (args_so_far) == CONST_INT)
3352 = memory_address (mode,
3353 plus_constant (args_addr,
3354 INTVAL (args_so_far)));
3356 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
3358 dest = gen_rtx_MEM (mode, addr);
3361 set_mem_attributes (dest, type, 1);
3362 /* Function incoming arguments may overlap with sibling call
3363 outgoing arguments and we cannot allow reordering of reads
3364 from function arguments with stores to outgoing arguments
3365 of sibling calls. */
3366 set_mem_alias_set (dest, 0);
3369 emit_move_insn (dest, x);
3373 /* If part should go in registers, copy that part
3374 into the appropriate registers. Do this now, at the end,
3375 since mem-to-mem copies above may do function calls. */
3376 if (partial > 0 && reg != 0)
3378 /* Handle calls that pass values in multiple non-contiguous locations.
3379 The Irix 6 ABI has examples of this. */
3380 if (GET_CODE (reg) == PARALLEL)
3381 emit_group_load (reg, x, type, -1);
3383 move_block_to_reg (REGNO (reg), x, partial, mode);
3386 if (extra && args_addr == 0 && where_pad == stack_direction)
3387 anti_adjust_stack (GEN_INT (extra));
3389 if (alignment_pad && args_addr == 0)
3390 anti_adjust_stack (alignment_pad);
3393 /* Return X if X can be used as a subtarget in a sequence of arithmetic
3397 get_subtarget (rtx x)
3400 /* Only registers can be subtargets. */
3402 /* If the register is readonly, it can't be set more than once. */
3403 || RTX_UNCHANGING_P (x)
3404 /* Don't use hard regs to avoid extending their life. */
3405 || REGNO (x) < FIRST_PSEUDO_REGISTER
3406 /* Avoid subtargets inside loops,
3407 since they hide some invariant expressions. */
3408 || preserve_subexpressions_p ())
3412 /* Expand an assignment that stores the value of FROM into TO.
3413 If WANT_VALUE is nonzero, return an rtx for the value of TO.
3414 (This may contain a QUEUED rtx;
3415 if the value is constant, this rtx is a constant.)
3416 Otherwise, the returned value is NULL_RTX. */
3419 expand_assignment (tree to, tree from, int want_value)
3424 /* Don't crash if the lhs of the assignment was erroneous. */
3426 if (TREE_CODE (to) == ERROR_MARK)
3428 result = expand_expr (from, NULL_RTX, VOIDmode, 0);
3429 return want_value ? result : NULL_RTX;
3432 /* Assignment of a structure component needs special treatment
3433 if the structure component's rtx is not simply a MEM.
3434 Assignment of an array element at a constant index, and assignment of
3435 an array element in an unaligned packed structure field, has the same
3438 if (TREE_CODE (to) == COMPONENT_REF || TREE_CODE (to) == BIT_FIELD_REF
3439 || TREE_CODE (to) == ARRAY_REF || TREE_CODE (to) == ARRAY_RANGE_REF
3440 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
3442 enum machine_mode mode1;
3443 HOST_WIDE_INT bitsize, bitpos;
3451 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
3452 &unsignedp, &volatilep);
3454 /* If we are going to use store_bit_field and extract_bit_field,
3455 make sure to_rtx will be safe for multiple use. */
3457 if (mode1 == VOIDmode && want_value)
3458 tem = stabilize_reference (tem);
3460 orig_to_rtx = to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, 0);
3464 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
3466 if (!MEM_P (to_rtx))
3469 #ifdef POINTERS_EXTEND_UNSIGNED
3470 if (GET_MODE (offset_rtx) != Pmode)
3471 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
3473 if (GET_MODE (offset_rtx) != ptr_mode)
3474 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
3477 /* A constant address in TO_RTX can have VOIDmode, we must not try
3478 to call force_reg for that case. Avoid that case. */
3480 && GET_MODE (to_rtx) == BLKmode
3481 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
3483 && (bitpos % bitsize) == 0
3484 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
3485 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
3487 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
3491 to_rtx = offset_address (to_rtx, offset_rtx,
3492 highest_pow2_factor_for_target (to,
3498 /* If the field is at offset zero, we could have been given the
3499 DECL_RTX of the parent struct. Don't munge it. */
3500 to_rtx = shallow_copy_rtx (to_rtx);
3502 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
3505 /* Deal with volatile and readonly fields. The former is only done
3506 for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
3507 if (volatilep && MEM_P (to_rtx))
3509 if (to_rtx == orig_to_rtx)
3510 to_rtx = copy_rtx (to_rtx);
3511 MEM_VOLATILE_P (to_rtx) = 1;
3514 if (TREE_CODE (to) == COMPONENT_REF
3515 && TREE_READONLY (TREE_OPERAND (to, 1))
3516 /* We can't assert that a MEM won't be set more than once
3517 if the component is not addressable because another
3518 non-addressable component may be referenced by the same MEM. */
3519 && ! (MEM_P (to_rtx) && ! can_address_p (to)))
3521 if (to_rtx == orig_to_rtx)
3522 to_rtx = copy_rtx (to_rtx);
3523 RTX_UNCHANGING_P (to_rtx) = 1;