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, 2005, 2006 Free Software Foundation,
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "coretypes.h"
33 #include "hard-reg-set.h"
36 #include "insn-config.h"
37 #include "insn-attr.h"
38 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
45 #include "typeclass.h"
48 #include "langhooks.h"
51 #include "tree-iterator.h"
52 #include "tree-pass.h"
53 #include "tree-flow.h"
57 /* Decide whether a function's arguments should be processed
58 from first to last or from last to first.
60 They should if the stack and args grow in opposite directions, but
61 only if we have push insns. */
65 #ifndef PUSH_ARGS_REVERSED
66 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
67 #define PUSH_ARGS_REVERSED /* If it's last to first. */
73 #ifndef STACK_PUSH_CODE
74 #ifdef STACK_GROWS_DOWNWARD
75 #define STACK_PUSH_CODE PRE_DEC
77 #define STACK_PUSH_CODE PRE_INC
82 /* If this is nonzero, we do not bother generating VOLATILE
83 around volatile memory references, and we are willing to
84 output indirect addresses. If cse is to follow, we reject
85 indirect addresses so a useful potential cse is generated;
86 if it is used only once, instruction combination will produce
87 the same indirect address eventually. */
90 /* This structure is used by move_by_pieces to describe the move to
101 int explicit_inc_from;
102 unsigned HOST_WIDE_INT len;
103 HOST_WIDE_INT offset;
107 /* This structure is used by store_by_pieces to describe the clear to
110 struct store_by_pieces
116 unsigned HOST_WIDE_INT len;
117 HOST_WIDE_INT offset;
118 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
123 static unsigned HOST_WIDE_INT move_by_pieces_ninsns (unsigned HOST_WIDE_INT,
126 static void move_by_pieces_1 (rtx (*) (rtx, ...), enum machine_mode,
127 struct move_by_pieces *);
128 static bool block_move_libcall_safe_for_call_parm (void);
129 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned);
130 static rtx emit_block_move_via_libcall (rtx, rtx, rtx, bool);
131 static tree emit_block_move_libcall_fn (int);
132 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
133 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
134 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
135 static void store_by_pieces_1 (struct store_by_pieces *, unsigned int);
136 static void store_by_pieces_2 (rtx (*) (rtx, ...), enum machine_mode,
137 struct store_by_pieces *);
138 static rtx clear_storage_via_libcall (rtx, rtx, bool);
139 static tree clear_storage_libcall_fn (int);
140 static rtx compress_float_constant (rtx, rtx);
141 static rtx get_subtarget (rtx);
142 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
143 HOST_WIDE_INT, enum machine_mode,
144 tree, tree, int, int);
145 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
146 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT, enum machine_mode,
149 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (tree, tree);
151 static int is_aligning_offset (tree, tree);
152 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
153 enum expand_modifier);
154 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
155 static rtx do_store_flag (tree, rtx, enum machine_mode, int);
157 static void emit_single_push_insn (enum machine_mode, rtx, tree);
159 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx);
160 static rtx const_vector_from_tree (tree);
161 static void write_complex_part (rtx, rtx, bool);
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, MOVE_MAX_PIECES + 1) \
179 < (unsigned int) MOVE_RATIO)
182 /* This macro is used to determine whether clear_by_pieces should be
183 called to clear storage. */
184 #ifndef CLEAR_BY_PIECES_P
185 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
186 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
187 < (unsigned int) CLEAR_RATIO)
190 /* This macro is used to determine whether store_by_pieces should be
191 called to "memset" storage with byte values other than zero, or
192 to "memcpy" storage when the source is a constant string. */
193 #ifndef STORE_BY_PIECES_P
194 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
195 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
196 < (unsigned int) MOVE_RATIO)
199 /* This array records the insn_code of insns to perform block moves. */
200 enum insn_code movmem_optab[NUM_MACHINE_MODES];
202 /* This array records the insn_code of insns to perform block sets. */
203 enum insn_code setmem_optab[NUM_MACHINE_MODES];
205 /* These arrays record the insn_code of three different kinds of insns
206 to perform block compares. */
207 enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
208 enum insn_code cmpstrn_optab[NUM_MACHINE_MODES];
209 enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
211 /* Synchronization primitives. */
212 enum insn_code sync_add_optab[NUM_MACHINE_MODES];
213 enum insn_code sync_sub_optab[NUM_MACHINE_MODES];
214 enum insn_code sync_ior_optab[NUM_MACHINE_MODES];
215 enum insn_code sync_and_optab[NUM_MACHINE_MODES];
216 enum insn_code sync_xor_optab[NUM_MACHINE_MODES];
217 enum insn_code sync_nand_optab[NUM_MACHINE_MODES];
218 enum insn_code sync_old_add_optab[NUM_MACHINE_MODES];
219 enum insn_code sync_old_sub_optab[NUM_MACHINE_MODES];
220 enum insn_code sync_old_ior_optab[NUM_MACHINE_MODES];
221 enum insn_code sync_old_and_optab[NUM_MACHINE_MODES];
222 enum insn_code sync_old_xor_optab[NUM_MACHINE_MODES];
223 enum insn_code sync_old_nand_optab[NUM_MACHINE_MODES];
224 enum insn_code sync_new_add_optab[NUM_MACHINE_MODES];
225 enum insn_code sync_new_sub_optab[NUM_MACHINE_MODES];
226 enum insn_code sync_new_ior_optab[NUM_MACHINE_MODES];
227 enum insn_code sync_new_and_optab[NUM_MACHINE_MODES];
228 enum insn_code sync_new_xor_optab[NUM_MACHINE_MODES];
229 enum insn_code sync_new_nand_optab[NUM_MACHINE_MODES];
230 enum insn_code sync_compare_and_swap[NUM_MACHINE_MODES];
231 enum insn_code sync_compare_and_swap_cc[NUM_MACHINE_MODES];
232 enum insn_code sync_lock_test_and_set[NUM_MACHINE_MODES];
233 enum insn_code sync_lock_release[NUM_MACHINE_MODES];
235 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
237 #ifndef SLOW_UNALIGNED_ACCESS
238 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
241 /* This is run once per compilation to set up which modes can be used
242 directly in memory and to initialize the block move optab. */
245 init_expr_once (void)
248 enum machine_mode mode;
253 /* Try indexing by frame ptr and try by stack ptr.
254 It is known that on the Convex the stack ptr isn't a valid index.
255 With luck, one or the other is valid on any machine. */
256 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
257 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
259 /* A scratch register we can modify in-place below to avoid
260 useless RTL allocations. */
261 reg = gen_rtx_REG (VOIDmode, -1);
263 insn = rtx_alloc (INSN);
264 pat = gen_rtx_SET (0, NULL_RTX, NULL_RTX);
265 PATTERN (insn) = pat;
267 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
268 mode = (enum machine_mode) ((int) mode + 1))
272 direct_load[(int) mode] = direct_store[(int) mode] = 0;
273 PUT_MODE (mem, mode);
274 PUT_MODE (mem1, mode);
275 PUT_MODE (reg, mode);
277 /* See if there is some register that can be used in this mode and
278 directly loaded or stored from memory. */
280 if (mode != VOIDmode && mode != BLKmode)
281 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
282 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
285 if (! HARD_REGNO_MODE_OK (regno, mode))
291 SET_DEST (pat) = reg;
292 if (recog (pat, insn, &num_clobbers) >= 0)
293 direct_load[(int) mode] = 1;
295 SET_SRC (pat) = mem1;
296 SET_DEST (pat) = reg;
297 if (recog (pat, insn, &num_clobbers) >= 0)
298 direct_load[(int) mode] = 1;
301 SET_DEST (pat) = mem;
302 if (recog (pat, insn, &num_clobbers) >= 0)
303 direct_store[(int) mode] = 1;
306 SET_DEST (pat) = mem1;
307 if (recog (pat, insn, &num_clobbers) >= 0)
308 direct_store[(int) mode] = 1;
312 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
314 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
315 mode = GET_MODE_WIDER_MODE (mode))
317 enum machine_mode srcmode;
318 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
319 srcmode = GET_MODE_WIDER_MODE (srcmode))
323 ic = can_extend_p (mode, srcmode, 0);
324 if (ic == CODE_FOR_nothing)
327 PUT_MODE (mem, srcmode);
329 if ((*insn_data[ic].operand[1].predicate) (mem, srcmode))
330 float_extend_from_mem[mode][srcmode] = true;
335 /* This is run at the start of compiling a function. */
340 cfun->expr = ggc_alloc_cleared (sizeof (struct expr_status));
343 /* Copy data from FROM to TO, where the machine modes are not the same.
344 Both modes may be integer, or both may be floating.
345 UNSIGNEDP should be nonzero if FROM is an unsigned type.
346 This causes zero-extension instead of sign-extension. */
349 convert_move (rtx to, rtx from, int unsignedp)
351 enum machine_mode to_mode = GET_MODE (to);
352 enum machine_mode from_mode = GET_MODE (from);
353 int to_real = SCALAR_FLOAT_MODE_P (to_mode);
354 int from_real = SCALAR_FLOAT_MODE_P (from_mode);
358 /* rtx code for making an equivalent value. */
359 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
360 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
363 gcc_assert (to_real == from_real);
365 /* If the source and destination are already the same, then there's
370 /* If FROM is a SUBREG that indicates that we have already done at least
371 the required extension, strip it. We don't handle such SUBREGs as
374 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
375 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
376 >= GET_MODE_SIZE (to_mode))
377 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
378 from = gen_lowpart (to_mode, from), from_mode = to_mode;
380 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
382 if (to_mode == from_mode
383 || (from_mode == VOIDmode && CONSTANT_P (from)))
385 emit_move_insn (to, from);
389 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
391 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
393 if (VECTOR_MODE_P (to_mode))
394 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
396 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
398 emit_move_insn (to, from);
402 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
404 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
405 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
414 gcc_assert ((GET_MODE_PRECISION (from_mode)
415 != GET_MODE_PRECISION (to_mode))
416 || (DECIMAL_FLOAT_MODE_P (from_mode)
417 != DECIMAL_FLOAT_MODE_P (to_mode)));
419 if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
420 /* Conversion between decimal float and binary float, same size. */
421 tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
422 else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
427 /* Try converting directly if the insn is supported. */
429 code = tab->handlers[to_mode][from_mode].insn_code;
430 if (code != CODE_FOR_nothing)
432 emit_unop_insn (code, to, from,
433 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
437 /* Otherwise use a libcall. */
438 libcall = tab->handlers[to_mode][from_mode].libfunc;
440 /* Is this conversion implemented yet? */
441 gcc_assert (libcall);
444 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
446 insns = get_insns ();
448 emit_libcall_block (insns, to, value,
449 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
451 : gen_rtx_FLOAT_EXTEND (to_mode, from));
455 /* Handle pointer conversion. */ /* SPEE 900220. */
456 /* Targets are expected to provide conversion insns between PxImode and
457 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
458 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
460 enum machine_mode full_mode
461 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
463 gcc_assert (trunc_optab->handlers[to_mode][full_mode].insn_code
464 != CODE_FOR_nothing);
466 if (full_mode != from_mode)
467 from = convert_to_mode (full_mode, from, unsignedp);
468 emit_unop_insn (trunc_optab->handlers[to_mode][full_mode].insn_code,
472 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
475 enum machine_mode full_mode
476 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
478 gcc_assert (sext_optab->handlers[full_mode][from_mode].insn_code
479 != CODE_FOR_nothing);
481 if (to_mode == full_mode)
483 emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
488 new_from = gen_reg_rtx (full_mode);
489 emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
490 new_from, from, UNKNOWN);
492 /* else proceed to integer conversions below. */
493 from_mode = full_mode;
497 /* Now both modes are integers. */
499 /* Handle expanding beyond a word. */
500 if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
501 && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
508 enum machine_mode lowpart_mode;
509 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
511 /* Try converting directly if the insn is supported. */
512 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
515 /* If FROM is a SUBREG, put it into a register. Do this
516 so that we always generate the same set of insns for
517 better cse'ing; if an intermediate assignment occurred,
518 we won't be doing the operation directly on the SUBREG. */
519 if (optimize > 0 && GET_CODE (from) == SUBREG)
520 from = force_reg (from_mode, from);
521 emit_unop_insn (code, to, from, equiv_code);
524 /* Next, try converting via full word. */
525 else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
526 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
527 != CODE_FOR_nothing))
531 if (reg_overlap_mentioned_p (to, from))
532 from = force_reg (from_mode, from);
533 emit_insn (gen_rtx_CLOBBER (VOIDmode, to));
535 convert_move (gen_lowpart (word_mode, to), from, unsignedp);
536 emit_unop_insn (code, to,
537 gen_lowpart (word_mode, to), equiv_code);
541 /* No special multiword conversion insn; do it by hand. */
544 /* Since we will turn this into a no conflict block, we must ensure
545 that the source does not overlap the target. */
547 if (reg_overlap_mentioned_p (to, from))
548 from = force_reg (from_mode, from);
550 /* Get a copy of FROM widened to a word, if necessary. */
551 if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
552 lowpart_mode = word_mode;
554 lowpart_mode = from_mode;
556 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
558 lowpart = gen_lowpart (lowpart_mode, to);
559 emit_move_insn (lowpart, lowfrom);
561 /* Compute the value to put in each remaining word. */
563 fill_value = const0_rtx;
568 && insn_data[(int) CODE_FOR_slt].operand[0].mode == word_mode
569 && STORE_FLAG_VALUE == -1)
571 emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
573 fill_value = gen_reg_rtx (word_mode);
574 emit_insn (gen_slt (fill_value));
580 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
581 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
583 fill_value = convert_to_mode (word_mode, fill_value, 1);
587 /* Fill the remaining words. */
588 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
590 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
591 rtx subword = operand_subword (to, index, 1, to_mode);
593 gcc_assert (subword);
595 if (fill_value != subword)
596 emit_move_insn (subword, fill_value);
599 insns = get_insns ();
602 emit_no_conflict_block (insns, to, from, NULL_RTX,
603 gen_rtx_fmt_e (equiv_code, to_mode, copy_rtx (from)));
607 /* Truncating multi-word to a word or less. */
608 if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
609 && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
612 && ! MEM_VOLATILE_P (from)
613 && direct_load[(int) to_mode]
614 && ! mode_dependent_address_p (XEXP (from, 0)))
616 || GET_CODE (from) == SUBREG))
617 from = force_reg (from_mode, from);
618 convert_move (to, gen_lowpart (word_mode, from), 0);
622 /* Now follow all the conversions between integers
623 no more than a word long. */
625 /* For truncation, usually we can just refer to FROM in a narrower mode. */
626 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
627 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
628 GET_MODE_BITSIZE (from_mode)))
631 && ! MEM_VOLATILE_P (from)
632 && direct_load[(int) to_mode]
633 && ! mode_dependent_address_p (XEXP (from, 0)))
635 || GET_CODE (from) == SUBREG))
636 from = force_reg (from_mode, from);
637 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
638 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
639 from = copy_to_reg (from);
640 emit_move_insn (to, gen_lowpart (to_mode, from));
644 /* Handle extension. */
645 if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
647 /* Convert directly if that works. */
648 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
651 emit_unop_insn (code, to, from, equiv_code);
656 enum machine_mode intermediate;
660 /* Search for a mode to convert via. */
661 for (intermediate = from_mode; intermediate != VOIDmode;
662 intermediate = GET_MODE_WIDER_MODE (intermediate))
663 if (((can_extend_p (to_mode, intermediate, unsignedp)
665 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
666 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
667 GET_MODE_BITSIZE (intermediate))))
668 && (can_extend_p (intermediate, from_mode, unsignedp)
669 != CODE_FOR_nothing))
671 convert_move (to, convert_to_mode (intermediate, from,
672 unsignedp), unsignedp);
676 /* No suitable intermediate mode.
677 Generate what we need with shifts. */
678 shift_amount = build_int_cst (NULL_TREE,
679 GET_MODE_BITSIZE (to_mode)
680 - GET_MODE_BITSIZE (from_mode));
681 from = gen_lowpart (to_mode, force_reg (from_mode, from));
682 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
684 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
687 emit_move_insn (to, tmp);
692 /* Support special truncate insns for certain modes. */
693 if (trunc_optab->handlers[to_mode][from_mode].insn_code != CODE_FOR_nothing)
695 emit_unop_insn (trunc_optab->handlers[to_mode][from_mode].insn_code,
700 /* Handle truncation of volatile memrefs, and so on;
701 the things that couldn't be truncated directly,
702 and for which there was no special instruction.
704 ??? Code above formerly short-circuited this, for most integer
705 mode pairs, with a force_reg in from_mode followed by a recursive
706 call to this routine. Appears always to have been wrong. */
707 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
709 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
710 emit_move_insn (to, temp);
714 /* Mode combination is not recognized. */
718 /* Return an rtx for a value that would result
719 from converting X to mode MODE.
720 Both X and MODE may be floating, or both integer.
721 UNSIGNEDP is nonzero if X is an unsigned value.
722 This can be done by referring to a part of X in place
723 or by copying to a new temporary with conversion. */
726 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
728 return convert_modes (mode, VOIDmode, x, unsignedp);
731 /* Return an rtx for a value that would result
732 from converting X from mode OLDMODE to mode MODE.
733 Both modes may be floating, or both integer.
734 UNSIGNEDP is nonzero if X is an unsigned value.
736 This can be done by referring to a part of X in place
737 or by copying to a new temporary with conversion.
739 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
742 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
746 /* If FROM is a SUBREG that indicates that we have already done at least
747 the required extension, strip it. */
749 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
750 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
751 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
752 x = gen_lowpart (mode, x);
754 if (GET_MODE (x) != VOIDmode)
755 oldmode = GET_MODE (x);
760 /* There is one case that we must handle specially: If we are converting
761 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
762 we are to interpret the constant as unsigned, gen_lowpart will do
763 the wrong if the constant appears negative. What we want to do is
764 make the high-order word of the constant zero, not all ones. */
766 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
767 && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
768 && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
770 HOST_WIDE_INT val = INTVAL (x);
772 if (oldmode != VOIDmode
773 && HOST_BITS_PER_WIDE_INT > GET_MODE_BITSIZE (oldmode))
775 int width = GET_MODE_BITSIZE (oldmode);
777 /* We need to zero extend VAL. */
778 val &= ((HOST_WIDE_INT) 1 << width) - 1;
781 return immed_double_const (val, (HOST_WIDE_INT) 0, mode);
784 /* We can do this with a gen_lowpart if both desired and current modes
785 are integer, and this is either a constant integer, a register, or a
786 non-volatile MEM. Except for the constant case where MODE is no
787 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
789 if ((GET_CODE (x) == CONST_INT
790 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
791 || (GET_MODE_CLASS (mode) == MODE_INT
792 && GET_MODE_CLASS (oldmode) == MODE_INT
793 && (GET_CODE (x) == CONST_DOUBLE
794 || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
795 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
796 && direct_load[(int) mode])
798 && (! HARD_REGISTER_P (x)
799 || HARD_REGNO_MODE_OK (REGNO (x), mode))
800 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
801 GET_MODE_BITSIZE (GET_MODE (x)))))))))
803 /* ?? If we don't know OLDMODE, we have to assume here that
804 X does not need sign- or zero-extension. This may not be
805 the case, but it's the best we can do. */
806 if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
807 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
809 HOST_WIDE_INT val = INTVAL (x);
810 int width = GET_MODE_BITSIZE (oldmode);
812 /* We must sign or zero-extend in this case. Start by
813 zero-extending, then sign extend if we need to. */
814 val &= ((HOST_WIDE_INT) 1 << width) - 1;
816 && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
817 val |= (HOST_WIDE_INT) (-1) << width;
819 return gen_int_mode (val, mode);
822 return gen_lowpart (mode, x);
825 /* Converting from integer constant into mode is always equivalent to an
827 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
829 gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
830 return simplify_gen_subreg (mode, x, oldmode, 0);
833 temp = gen_reg_rtx (mode);
834 convert_move (temp, x, unsignedp);
838 /* STORE_MAX_PIECES is the number of bytes at a time that we can
839 store efficiently. Due to internal GCC limitations, this is
840 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
841 for an immediate constant. */
843 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
845 /* Determine whether the LEN bytes can be moved by using several move
846 instructions. Return nonzero if a call to move_by_pieces should
850 can_move_by_pieces (unsigned HOST_WIDE_INT len,
851 unsigned int align ATTRIBUTE_UNUSED)
853 return MOVE_BY_PIECES_P (len, align);
856 /* Generate several move instructions to copy LEN bytes from block FROM to
857 block TO. (These are MEM rtx's with BLKmode).
859 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
860 used to push FROM to the stack.
862 ALIGN is maximum stack alignment we can assume.
864 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
865 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
869 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
870 unsigned int align, int endp)
872 struct move_by_pieces data;
873 rtx to_addr, from_addr = XEXP (from, 0);
874 unsigned int max_size = MOVE_MAX_PIECES + 1;
875 enum machine_mode mode = VOIDmode, tmode;
876 enum insn_code icode;
878 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
881 data.from_addr = from_addr;
884 to_addr = XEXP (to, 0);
887 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
888 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
890 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
897 #ifdef STACK_GROWS_DOWNWARD
903 data.to_addr = to_addr;
906 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
907 || GET_CODE (from_addr) == POST_INC
908 || GET_CODE (from_addr) == POST_DEC);
910 data.explicit_inc_from = 0;
911 data.explicit_inc_to = 0;
912 if (data.reverse) data.offset = len;
915 /* If copying requires more than two move insns,
916 copy addresses to registers (to make displacements shorter)
917 and use post-increment if available. */
918 if (!(data.autinc_from && data.autinc_to)
919 && move_by_pieces_ninsns (len, align, max_size) > 2)
921 /* Find the mode of the largest move... */
922 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
923 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
924 if (GET_MODE_SIZE (tmode) < max_size)
927 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
929 data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
930 data.autinc_from = 1;
931 data.explicit_inc_from = -1;
933 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
935 data.from_addr = copy_addr_to_reg (from_addr);
936 data.autinc_from = 1;
937 data.explicit_inc_from = 1;
939 if (!data.autinc_from && CONSTANT_P (from_addr))
940 data.from_addr = copy_addr_to_reg (from_addr);
941 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
943 data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
945 data.explicit_inc_to = -1;
947 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
949 data.to_addr = copy_addr_to_reg (to_addr);
951 data.explicit_inc_to = 1;
953 if (!data.autinc_to && CONSTANT_P (to_addr))
954 data.to_addr = copy_addr_to_reg (to_addr);
957 tmode = mode_for_size (MOVE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
958 if (align >= GET_MODE_ALIGNMENT (tmode))
959 align = GET_MODE_ALIGNMENT (tmode);
962 enum machine_mode xmode;
964 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
966 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
967 if (GET_MODE_SIZE (tmode) > MOVE_MAX_PIECES
968 || SLOW_UNALIGNED_ACCESS (tmode, align))
971 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
974 /* First move what we can in the largest integer mode, then go to
975 successively smaller modes. */
979 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
980 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
981 if (GET_MODE_SIZE (tmode) < max_size)
984 if (mode == VOIDmode)
987 icode = mov_optab->handlers[(int) mode].insn_code;
988 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
989 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
991 max_size = GET_MODE_SIZE (mode);
994 /* The code above should have handled everything. */
995 gcc_assert (!data.len);
1001 gcc_assert (!data.reverse);
1006 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
1007 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
1009 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
1012 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
1019 to1 = adjust_address (data.to, QImode, data.offset);
1027 /* Return number of insns required to move L bytes by pieces.
1028 ALIGN (in bits) is maximum alignment we can assume. */
1030 static unsigned HOST_WIDE_INT
1031 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1032 unsigned int max_size)
1034 unsigned HOST_WIDE_INT n_insns = 0;
1035 enum machine_mode tmode;
1037 tmode = mode_for_size (MOVE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
1038 if (align >= GET_MODE_ALIGNMENT (tmode))
1039 align = GET_MODE_ALIGNMENT (tmode);
1042 enum machine_mode tmode, xmode;
1044 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
1046 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
1047 if (GET_MODE_SIZE (tmode) > MOVE_MAX_PIECES
1048 || SLOW_UNALIGNED_ACCESS (tmode, align))
1051 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
1054 while (max_size > 1)
1056 enum machine_mode mode = VOIDmode;
1057 enum insn_code icode;
1059 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1060 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1061 if (GET_MODE_SIZE (tmode) < max_size)
1064 if (mode == VOIDmode)
1067 icode = mov_optab->handlers[(int) mode].insn_code;
1068 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1069 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1071 max_size = GET_MODE_SIZE (mode);
1078 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1079 with move instructions for mode MODE. GENFUN is the gen_... function
1080 to make a move insn for that mode. DATA has all the other info. */
1083 move_by_pieces_1 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
1084 struct move_by_pieces *data)
1086 unsigned int size = GET_MODE_SIZE (mode);
1087 rtx to1 = NULL_RTX, from1;
1089 while (data->len >= size)
1092 data->offset -= size;
1096 if (data->autinc_to)
1097 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1100 to1 = adjust_address (data->to, mode, data->offset);
1103 if (data->autinc_from)
1104 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1107 from1 = adjust_address (data->from, mode, data->offset);
1109 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1110 emit_insn (gen_add2_insn (data->to_addr,
1111 GEN_INT (-(HOST_WIDE_INT)size)));
1112 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1113 emit_insn (gen_add2_insn (data->from_addr,
1114 GEN_INT (-(HOST_WIDE_INT)size)));
1117 emit_insn ((*genfun) (to1, from1));
1120 #ifdef PUSH_ROUNDING
1121 emit_single_push_insn (mode, from1, NULL);
1127 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1128 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1129 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1130 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1132 if (! data->reverse)
1133 data->offset += size;
1139 /* Emit code to move a block Y to a block X. This may be done with
1140 string-move instructions, with multiple scalar move instructions,
1141 or with a library call.
1143 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1144 SIZE is an rtx that says how long they are.
1145 ALIGN is the maximum alignment we can assume they have.
1146 METHOD describes what kind of copy this is, and what mechanisms may be used.
1148 Return the address of the new block, if memcpy is called and returns it,
1152 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1160 case BLOCK_OP_NORMAL:
1161 case BLOCK_OP_TAILCALL:
1162 may_use_call = true;
1165 case BLOCK_OP_CALL_PARM:
1166 may_use_call = block_move_libcall_safe_for_call_parm ();
1168 /* Make inhibit_defer_pop nonzero around the library call
1169 to force it to pop the arguments right away. */
1173 case BLOCK_OP_NO_LIBCALL:
1174 may_use_call = false;
1181 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1183 gcc_assert (MEM_P (x));
1184 gcc_assert (MEM_P (y));
1187 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1188 block copy is more efficient for other large modes, e.g. DCmode. */
1189 x = adjust_address (x, BLKmode, 0);
1190 y = adjust_address (y, BLKmode, 0);
1192 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1193 can be incorrect is coming from __builtin_memcpy. */
1194 if (GET_CODE (size) == CONST_INT)
1196 if (INTVAL (size) == 0)
1199 x = shallow_copy_rtx (x);
1200 y = shallow_copy_rtx (y);
1201 set_mem_size (x, size);
1202 set_mem_size (y, size);
1205 if (GET_CODE (size) == CONST_INT && MOVE_BY_PIECES_P (INTVAL (size), align))
1206 move_by_pieces (x, y, INTVAL (size), align, 0);
1207 else if (emit_block_move_via_movmem (x, y, size, align))
1209 else if (may_use_call)
1210 retval = emit_block_move_via_libcall (x, y, size,
1211 method == BLOCK_OP_TAILCALL);
1213 emit_block_move_via_loop (x, y, size, align);
1215 if (method == BLOCK_OP_CALL_PARM)
1221 /* A subroutine of emit_block_move. Returns true if calling the
1222 block move libcall will not clobber any parameters which may have
1223 already been placed on the stack. */
1226 block_move_libcall_safe_for_call_parm (void)
1228 /* If arguments are pushed on the stack, then they're safe. */
1232 /* If registers go on the stack anyway, any argument is sure to clobber
1233 an outgoing argument. */
1234 #if defined (REG_PARM_STACK_SPACE) && defined (OUTGOING_REG_PARM_STACK_SPACE)
1236 tree fn = emit_block_move_libcall_fn (false);
1238 if (REG_PARM_STACK_SPACE (fn) != 0)
1243 /* If any argument goes in memory, then it might clobber an outgoing
1246 CUMULATIVE_ARGS args_so_far;
1249 fn = emit_block_move_libcall_fn (false);
1250 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fn), NULL_RTX, 0, 3);
1252 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1253 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1255 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1256 rtx tmp = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
1257 if (!tmp || !REG_P (tmp))
1259 if (targetm.calls.arg_partial_bytes (&args_so_far, mode, NULL, 1))
1261 FUNCTION_ARG_ADVANCE (args_so_far, mode, NULL_TREE, 1);
1267 /* A subroutine of emit_block_move. Expand a movmem pattern;
1268 return true if successful. */
1271 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align)
1273 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
1274 int save_volatile_ok = volatile_ok;
1275 enum machine_mode mode;
1277 /* Since this is a move insn, we don't care about volatility. */
1280 /* Try the most limited insn first, because there's no point
1281 including more than one in the machine description unless
1282 the more limited one has some advantage. */
1284 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1285 mode = GET_MODE_WIDER_MODE (mode))
1287 enum insn_code code = movmem_optab[(int) mode];
1288 insn_operand_predicate_fn pred;
1290 if (code != CODE_FOR_nothing
1291 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1292 here because if SIZE is less than the mode mask, as it is
1293 returned by the macro, it will definitely be less than the
1294 actual mode mask. */
1295 && ((GET_CODE (size) == CONST_INT
1296 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1297 <= (GET_MODE_MASK (mode) >> 1)))
1298 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1299 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
1300 || (*pred) (x, BLKmode))
1301 && ((pred = insn_data[(int) code].operand[1].predicate) == 0
1302 || (*pred) (y, BLKmode))
1303 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
1304 || (*pred) (opalign, VOIDmode)))
1307 rtx last = get_last_insn ();
1310 op2 = convert_to_mode (mode, size, 1);
1311 pred = insn_data[(int) code].operand[2].predicate;
1312 if (pred != 0 && ! (*pred) (op2, mode))
1313 op2 = copy_to_mode_reg (mode, op2);
1315 /* ??? When called via emit_block_move_for_call, it'd be
1316 nice if there were some way to inform the backend, so
1317 that it doesn't fail the expansion because it thinks
1318 emitting the libcall would be more efficient. */
1320 pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1324 volatile_ok = save_volatile_ok;
1328 delete_insns_since (last);
1332 volatile_ok = save_volatile_ok;
1336 /* A subroutine of emit_block_move. Expand a call to memcpy.
1337 Return the return value from memcpy, 0 otherwise. */
1340 emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
1342 rtx dst_addr, src_addr;
1343 tree call_expr, arg_list, fn, src_tree, dst_tree, size_tree;
1344 enum machine_mode size_mode;
1347 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1348 pseudos. We can then place those new pseudos into a VAR_DECL and
1351 dst_addr = copy_to_mode_reg (Pmode, XEXP (dst, 0));
1352 src_addr = copy_to_mode_reg (Pmode, XEXP (src, 0));
1354 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1355 src_addr = convert_memory_address (ptr_mode, src_addr);
1357 dst_tree = make_tree (ptr_type_node, dst_addr);
1358 src_tree = make_tree (ptr_type_node, src_addr);
1360 size_mode = TYPE_MODE (sizetype);
1362 size = convert_to_mode (size_mode, size, 1);
1363 size = copy_to_mode_reg (size_mode, size);
1365 /* It is incorrect to use the libcall calling conventions to call
1366 memcpy in this context. This could be a user call to memcpy and
1367 the user may wish to examine the return value from memcpy. For
1368 targets where libcalls and normal calls have different conventions
1369 for returning pointers, we could end up generating incorrect code. */
1371 size_tree = make_tree (sizetype, size);
1373 fn = emit_block_move_libcall_fn (true);
1374 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
1375 arg_list = tree_cons (NULL_TREE, src_tree, arg_list);
1376 arg_list = tree_cons (NULL_TREE, dst_tree, arg_list);
1378 /* Now we have to build up the CALL_EXPR itself. */
1379 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
1380 call_expr = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
1381 call_expr, arg_list, NULL_TREE);
1382 CALL_EXPR_TAILCALL (call_expr) = tailcall;
1384 retval = expand_normal (call_expr);
1389 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1390 for the function we use for block copies. The first time FOR_CALL
1391 is true, we call assemble_external. */
1393 static GTY(()) tree block_move_fn;
1396 init_block_move_fn (const char *asmspec)
1402 fn = get_identifier ("memcpy");
1403 args = build_function_type_list (ptr_type_node, ptr_type_node,
1404 const_ptr_type_node, sizetype,
1407 fn = build_decl (FUNCTION_DECL, fn, args);
1408 DECL_EXTERNAL (fn) = 1;
1409 TREE_PUBLIC (fn) = 1;
1410 DECL_ARTIFICIAL (fn) = 1;
1411 TREE_NOTHROW (fn) = 1;
1417 set_user_assembler_name (block_move_fn, asmspec);
1421 emit_block_move_libcall_fn (int for_call)
1423 static bool emitted_extern;
1426 init_block_move_fn (NULL);
1428 if (for_call && !emitted_extern)
1430 emitted_extern = true;
1431 make_decl_rtl (block_move_fn);
1432 assemble_external (block_move_fn);
1435 return block_move_fn;
1438 /* A subroutine of emit_block_move. Copy the data via an explicit
1439 loop. This is used only when libcalls are forbidden. */
1440 /* ??? It'd be nice to copy in hunks larger than QImode. */
1443 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1444 unsigned int align ATTRIBUTE_UNUSED)
1446 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1447 enum machine_mode iter_mode;
1449 iter_mode = GET_MODE (size);
1450 if (iter_mode == VOIDmode)
1451 iter_mode = word_mode;
1453 top_label = gen_label_rtx ();
1454 cmp_label = gen_label_rtx ();
1455 iter = gen_reg_rtx (iter_mode);
1457 emit_move_insn (iter, const0_rtx);
1459 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1460 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1461 do_pending_stack_adjust ();
1463 emit_jump (cmp_label);
1464 emit_label (top_label);
1466 tmp = convert_modes (Pmode, iter_mode, iter, true);
1467 x_addr = gen_rtx_PLUS (Pmode, x_addr, tmp);
1468 y_addr = gen_rtx_PLUS (Pmode, y_addr, tmp);
1469 x = change_address (x, QImode, x_addr);
1470 y = change_address (y, QImode, y_addr);
1472 emit_move_insn (x, y);
1474 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1475 true, OPTAB_LIB_WIDEN);
1477 emit_move_insn (iter, tmp);
1479 emit_label (cmp_label);
1481 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1485 /* Copy all or part of a value X into registers starting at REGNO.
1486 The number of registers to be filled is NREGS. */
1489 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1492 #ifdef HAVE_load_multiple
1500 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
1501 x = validize_mem (force_const_mem (mode, x));
1503 /* See if the machine can do this with a load multiple insn. */
1504 #ifdef HAVE_load_multiple
1505 if (HAVE_load_multiple)
1507 last = get_last_insn ();
1508 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1516 delete_insns_since (last);
1520 for (i = 0; i < nregs; i++)
1521 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1522 operand_subword_force (x, i, mode));
1525 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1526 The number of registers to be filled is NREGS. */
1529 move_block_from_reg (int regno, rtx x, int nregs)
1536 /* See if the machine can do this with a store multiple insn. */
1537 #ifdef HAVE_store_multiple
1538 if (HAVE_store_multiple)
1540 rtx last = get_last_insn ();
1541 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1549 delete_insns_since (last);
1553 for (i = 0; i < nregs; i++)
1555 rtx tem = operand_subword (x, i, 1, BLKmode);
1559 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1563 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1564 ORIG, where ORIG is a non-consecutive group of registers represented by
1565 a PARALLEL. The clone is identical to the original except in that the
1566 original set of registers is replaced by a new set of pseudo registers.
1567 The new set has the same modes as the original set. */
1570 gen_group_rtx (rtx orig)
1575 gcc_assert (GET_CODE (orig) == PARALLEL);
1577 length = XVECLEN (orig, 0);
1578 tmps = alloca (sizeof (rtx) * length);
1580 /* Skip a NULL entry in first slot. */
1581 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1586 for (; i < length; i++)
1588 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1589 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1591 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1594 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1597 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1598 except that values are placed in TMPS[i], and must later be moved
1599 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1602 emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
1606 enum machine_mode m = GET_MODE (orig_src);
1608 gcc_assert (GET_CODE (dst) == PARALLEL);
1611 && !SCALAR_INT_MODE_P (m)
1612 && !MEM_P (orig_src)
1613 && GET_CODE (orig_src) != CONCAT)
1615 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
1616 if (imode == BLKmode)
1617 src = assign_stack_temp (GET_MODE (orig_src), ssize, 0);
1619 src = gen_reg_rtx (imode);
1620 if (imode != BLKmode)
1621 src = gen_lowpart (GET_MODE (orig_src), src);
1622 emit_move_insn (src, orig_src);
1623 /* ...and back again. */
1624 if (imode != BLKmode)
1625 src = gen_lowpart (imode, src);
1626 emit_group_load_1 (tmps, dst, src, type, ssize);
1630 /* Check for a NULL entry, used to indicate that the parameter goes
1631 both on the stack and in registers. */
1632 if (XEXP (XVECEXP (dst, 0, 0), 0))
1637 /* Process the pieces. */
1638 for (i = start; i < XVECLEN (dst, 0); i++)
1640 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1641 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1642 unsigned int bytelen = GET_MODE_SIZE (mode);
1645 /* Handle trailing fragments that run over the size of the struct. */
1646 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1648 /* Arrange to shift the fragment to where it belongs.
1649 extract_bit_field loads to the lsb of the reg. */
1651 #ifdef BLOCK_REG_PADDING
1652 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1653 == (BYTES_BIG_ENDIAN ? upward : downward)
1658 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1659 bytelen = ssize - bytepos;
1660 gcc_assert (bytelen > 0);
1663 /* If we won't be loading directly from memory, protect the real source
1664 from strange tricks we might play; but make sure that the source can
1665 be loaded directly into the destination. */
1667 if (!MEM_P (orig_src)
1668 && (!CONSTANT_P (orig_src)
1669 || (GET_MODE (orig_src) != mode
1670 && GET_MODE (orig_src) != VOIDmode)))
1672 if (GET_MODE (orig_src) == VOIDmode)
1673 src = gen_reg_rtx (mode);
1675 src = gen_reg_rtx (GET_MODE (orig_src));
1677 emit_move_insn (src, orig_src);
1680 /* Optimize the access just a bit. */
1682 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1683 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1684 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1685 && bytelen == GET_MODE_SIZE (mode))
1687 tmps[i] = gen_reg_rtx (mode);
1688 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1690 else if (COMPLEX_MODE_P (mode)
1691 && GET_MODE (src) == mode
1692 && bytelen == GET_MODE_SIZE (mode))
1693 /* Let emit_move_complex do the bulk of the work. */
1695 else if (GET_CODE (src) == CONCAT)
1697 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1698 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1700 if ((bytepos == 0 && bytelen == slen0)
1701 || (bytepos != 0 && bytepos + bytelen <= slen))
1703 /* The following assumes that the concatenated objects all
1704 have the same size. In this case, a simple calculation
1705 can be used to determine the object and the bit field
1707 tmps[i] = XEXP (src, bytepos / slen0);
1708 if (! CONSTANT_P (tmps[i])
1709 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1710 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1711 (bytepos % slen0) * BITS_PER_UNIT,
1712 1, NULL_RTX, mode, mode);
1718 gcc_assert (!bytepos);
1719 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1720 emit_move_insn (mem, src);
1721 tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
1722 0, 1, NULL_RTX, mode, mode);
1725 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1726 SIMD register, which is currently broken. While we get GCC
1727 to emit proper RTL for these cases, let's dump to memory. */
1728 else if (VECTOR_MODE_P (GET_MODE (dst))
1731 int slen = GET_MODE_SIZE (GET_MODE (src));
1734 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1735 emit_move_insn (mem, src);
1736 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1738 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1739 && XVECLEN (dst, 0) > 1)
1740 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE(dst), bytepos);
1741 else if (CONSTANT_P (src)
1742 || (REG_P (src) && GET_MODE (src) == mode))
1745 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1746 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1750 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1751 build_int_cst (NULL_TREE, shift), tmps[i], 0);
1755 /* Emit code to move a block SRC of type TYPE to a block DST,
1756 where DST is non-consecutive registers represented by a PARALLEL.
1757 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1761 emit_group_load (rtx dst, rtx src, tree type, int ssize)
1766 tmps = alloca (sizeof (rtx) * XVECLEN (dst, 0));
1767 emit_group_load_1 (tmps, dst, src, type, ssize);
1769 /* Copy the extracted pieces into the proper (probable) hard regs. */
1770 for (i = 0; i < XVECLEN (dst, 0); i++)
1772 rtx d = XEXP (XVECEXP (dst, 0, i), 0);
1775 emit_move_insn (d, tmps[i]);
1779 /* Similar, but load SRC into new pseudos in a format that looks like
1780 PARALLEL. This can later be fed to emit_group_move to get things
1781 in the right place. */
1784 emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
1789 vec = rtvec_alloc (XVECLEN (parallel, 0));
1790 emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
1792 /* Convert the vector to look just like the original PARALLEL, except
1793 with the computed values. */
1794 for (i = 0; i < XVECLEN (parallel, 0); i++)
1796 rtx e = XVECEXP (parallel, 0, i);
1797 rtx d = XEXP (e, 0);
1801 d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
1802 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
1804 RTVEC_ELT (vec, i) = e;
1807 return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
1810 /* Emit code to move a block SRC to block DST, where SRC and DST are
1811 non-consecutive groups of registers, each represented by a PARALLEL. */
1814 emit_group_move (rtx dst, rtx src)
1818 gcc_assert (GET_CODE (src) == PARALLEL
1819 && GET_CODE (dst) == PARALLEL
1820 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1822 /* Skip first entry if NULL. */
1823 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1824 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1825 XEXP (XVECEXP (src, 0, i), 0));
1828 /* Move a group of registers represented by a PARALLEL into pseudos. */
1831 emit_group_move_into_temps (rtx src)
1833 rtvec vec = rtvec_alloc (XVECLEN (src, 0));
1836 for (i = 0; i < XVECLEN (src, 0); i++)
1838 rtx e = XVECEXP (src, 0, i);
1839 rtx d = XEXP (e, 0);
1842 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
1843 RTVEC_ELT (vec, i) = e;
1846 return gen_rtx_PARALLEL (GET_MODE (src), vec);
1849 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1850 where SRC is non-consecutive registers represented by a PARALLEL.
1851 SSIZE represents the total size of block ORIG_DST, or -1 if not
1855 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1859 enum machine_mode m = GET_MODE (orig_dst);
1861 gcc_assert (GET_CODE (src) == PARALLEL);
1863 if (!SCALAR_INT_MODE_P (m)
1864 && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
1866 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
1867 if (imode == BLKmode)
1868 dst = assign_stack_temp (GET_MODE (orig_dst), ssize, 0);
1870 dst = gen_reg_rtx (imode);
1871 emit_group_store (dst, src, type, ssize);
1872 if (imode != BLKmode)
1873 dst = gen_lowpart (GET_MODE (orig_dst), dst);
1874 emit_move_insn (orig_dst, dst);
1878 /* Check for a NULL entry, used to indicate that the parameter goes
1879 both on the stack and in registers. */
1880 if (XEXP (XVECEXP (src, 0, 0), 0))
1885 tmps = alloca (sizeof (rtx) * XVECLEN (src, 0));
1887 /* Copy the (probable) hard regs into pseudos. */
1888 for (i = start; i < XVECLEN (src, 0); i++)
1890 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1891 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1892 emit_move_insn (tmps[i], reg);
1895 /* If we won't be storing directly into memory, protect the real destination
1896 from strange tricks we might play. */
1898 if (GET_CODE (dst) == PARALLEL)
1902 /* We can get a PARALLEL dst if there is a conditional expression in
1903 a return statement. In that case, the dst and src are the same,
1904 so no action is necessary. */
1905 if (rtx_equal_p (dst, src))
1908 /* It is unclear if we can ever reach here, but we may as well handle
1909 it. Allocate a temporary, and split this into a store/load to/from
1912 temp = assign_stack_temp (GET_MODE (dst), ssize, 0);
1913 emit_group_store (temp, src, type, ssize);
1914 emit_group_load (dst, temp, type, ssize);
1917 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1919 dst = gen_reg_rtx (GET_MODE (orig_dst));
1920 /* Make life a bit easier for combine. */
1921 emit_move_insn (dst, CONST0_RTX (GET_MODE (orig_dst)));
1924 /* Process the pieces. */
1925 for (i = start; i < XVECLEN (src, 0); i++)
1927 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
1928 enum machine_mode mode = GET_MODE (tmps[i]);
1929 unsigned int bytelen = GET_MODE_SIZE (mode);
1932 /* Handle trailing fragments that run over the size of the struct. */
1933 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1935 /* store_bit_field always takes its value from the lsb.
1936 Move the fragment to the lsb if it's not already there. */
1938 #ifdef BLOCK_REG_PADDING
1939 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
1940 == (BYTES_BIG_ENDIAN ? upward : downward)
1946 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1947 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
1948 build_int_cst (NULL_TREE, shift),
1951 bytelen = ssize - bytepos;
1954 if (GET_CODE (dst) == CONCAT)
1956 if (bytepos + bytelen <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
1957 dest = XEXP (dst, 0);
1958 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
1960 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
1961 dest = XEXP (dst, 1);
1965 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
1966 dest = assign_stack_temp (GET_MODE (dest),
1967 GET_MODE_SIZE (GET_MODE (dest)), 0);
1968 emit_move_insn (adjust_address (dest, GET_MODE (tmps[i]), bytepos),
1975 /* Optimize the access just a bit. */
1977 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
1978 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
1979 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1980 && bytelen == GET_MODE_SIZE (mode))
1981 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
1983 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
1987 /* Copy from the pseudo into the (probable) hard reg. */
1988 if (orig_dst != dst)
1989 emit_move_insn (orig_dst, dst);
1992 /* Generate code to copy a BLKmode object of TYPE out of a
1993 set of registers starting with SRCREG into TGTBLK. If TGTBLK
1994 is null, a stack temporary is created. TGTBLK is returned.
1996 The purpose of this routine is to handle functions that return
1997 BLKmode structures in registers. Some machines (the PA for example)
1998 want to return all small structures in registers regardless of the
1999 structure's alignment. */
2002 copy_blkmode_from_reg (rtx tgtblk, rtx srcreg, tree type)
2004 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2005 rtx src = NULL, dst = NULL;
2006 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2007 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2011 tgtblk = assign_temp (build_qualified_type (type,
2013 | TYPE_QUAL_CONST)),
2015 preserve_temp_slots (tgtblk);
2018 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2019 into a new pseudo which is a full word. */
2021 if (GET_MODE (srcreg) != BLKmode
2022 && GET_MODE_SIZE (GET_MODE (srcreg)) < UNITS_PER_WORD)
2023 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
2025 /* If the structure doesn't take up a whole number of words, see whether
2026 SRCREG is padded on the left or on the right. If it's on the left,
2027 set PADDING_CORRECTION to the number of bits to skip.
2029 In most ABIs, the structure will be returned at the least end of
2030 the register, which translates to right padding on little-endian
2031 targets and left padding on big-endian targets. The opposite
2032 holds if the structure is returned at the most significant
2033 end of the register. */
2034 if (bytes % UNITS_PER_WORD != 0
2035 && (targetm.calls.return_in_msb (type)
2037 : BYTES_BIG_ENDIAN))
2039 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2041 /* Copy the structure BITSIZE bites at a time.
2043 We could probably emit more efficient code for machines which do not use
2044 strict alignment, but it doesn't seem worth the effort at the current
2046 for (bitpos = 0, xbitpos = padding_correction;
2047 bitpos < bytes * BITS_PER_UNIT;
2048 bitpos += bitsize, xbitpos += bitsize)
2050 /* We need a new source operand each time xbitpos is on a
2051 word boundary and when xbitpos == padding_correction
2052 (the first time through). */
2053 if (xbitpos % BITS_PER_WORD == 0
2054 || xbitpos == padding_correction)
2055 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD,
2058 /* We need a new destination operand each time bitpos is on
2060 if (bitpos % BITS_PER_WORD == 0)
2061 dst = operand_subword (tgtblk, bitpos / BITS_PER_WORD, 1, BLKmode);
2063 /* Use xbitpos for the source extraction (right justified) and
2064 xbitpos for the destination store (left justified). */
2065 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
2066 extract_bit_field (src, bitsize,
2067 xbitpos % BITS_PER_WORD, 1,
2068 NULL_RTX, word_mode, word_mode));
2074 /* Add a USE expression for REG to the (possibly empty) list pointed
2075 to by CALL_FUSAGE. REG must denote a hard register. */
2078 use_reg (rtx *call_fusage, rtx reg)
2080 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
2083 = gen_rtx_EXPR_LIST (VOIDmode,
2084 gen_rtx_USE (VOIDmode, reg), *call_fusage);
2087 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2088 starting at REGNO. All of these registers must be hard registers. */
2091 use_regs (rtx *call_fusage, int regno, int nregs)
2095 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
2097 for (i = 0; i < nregs; i++)
2098 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2101 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2102 PARALLEL REGS. This is for calls that pass values in multiple
2103 non-contiguous locations. The Irix 6 ABI has examples of this. */
2106 use_group_regs (rtx *call_fusage, rtx regs)
2110 for (i = 0; i < XVECLEN (regs, 0); i++)
2112 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2114 /* A NULL entry means the parameter goes both on the stack and in
2115 registers. This can also be a MEM for targets that pass values
2116 partially on the stack and partially in registers. */
2117 if (reg != 0 && REG_P (reg))
2118 use_reg (call_fusage, reg);
2123 /* Determine whether the LEN bytes generated by CONSTFUN can be
2124 stored to memory using several move instructions. CONSTFUNDATA is
2125 a pointer which will be passed as argument in every CONSTFUN call.
2126 ALIGN is maximum alignment we can assume. Return nonzero if a
2127 call to store_by_pieces should succeed. */
2130 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2131 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2132 void *constfundata, unsigned int align)
2134 unsigned HOST_WIDE_INT l;
2135 unsigned int max_size;
2136 HOST_WIDE_INT offset = 0;
2137 enum machine_mode mode, tmode;
2138 enum insn_code icode;
2145 if (! STORE_BY_PIECES_P (len, align))
2148 tmode = mode_for_size (STORE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
2149 if (align >= GET_MODE_ALIGNMENT (tmode))
2150 align = GET_MODE_ALIGNMENT (tmode);
2153 enum machine_mode xmode;
2155 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
2157 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
2158 if (GET_MODE_SIZE (tmode) > STORE_MAX_PIECES
2159 || SLOW_UNALIGNED_ACCESS (tmode, align))
2162 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
2165 /* We would first store what we can in the largest integer mode, then go to
2166 successively smaller modes. */
2169 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2174 max_size = STORE_MAX_PIECES + 1;
2175 while (max_size > 1)
2177 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2178 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2179 if (GET_MODE_SIZE (tmode) < max_size)
2182 if (mode == VOIDmode)
2185 icode = mov_optab->handlers[(int) mode].insn_code;
2186 if (icode != CODE_FOR_nothing
2187 && align >= GET_MODE_ALIGNMENT (mode))
2189 unsigned int size = GET_MODE_SIZE (mode);
2196 cst = (*constfun) (constfundata, offset, mode);
2197 if (!LEGITIMATE_CONSTANT_P (cst))
2207 max_size = GET_MODE_SIZE (mode);
2210 /* The code above should have handled everything. */
2217 /* Generate several move instructions to store LEN bytes generated by
2218 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2219 pointer which will be passed as argument in every CONSTFUN call.
2220 ALIGN is maximum alignment we can assume.
2221 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2222 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2226 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2227 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2228 void *constfundata, unsigned int align, int endp)
2230 struct store_by_pieces data;
2234 gcc_assert (endp != 2);
2238 gcc_assert (STORE_BY_PIECES_P (len, align));
2239 data.constfun = constfun;
2240 data.constfundata = constfundata;
2243 store_by_pieces_1 (&data, align);
2248 gcc_assert (!data.reverse);
2253 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2254 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2256 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
2259 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2266 to1 = adjust_address (data.to, QImode, data.offset);
2274 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2275 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2278 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2280 struct store_by_pieces data;
2285 data.constfun = clear_by_pieces_1;
2286 data.constfundata = NULL;
2289 store_by_pieces_1 (&data, align);
2292 /* Callback routine for clear_by_pieces.
2293 Return const0_rtx unconditionally. */
2296 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2297 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2298 enum machine_mode mode ATTRIBUTE_UNUSED)
2303 /* Subroutine of clear_by_pieces and store_by_pieces.
2304 Generate several move instructions to store LEN bytes of block TO. (A MEM
2305 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2308 store_by_pieces_1 (struct store_by_pieces *data ATTRIBUTE_UNUSED,
2309 unsigned int align ATTRIBUTE_UNUSED)
2311 rtx to_addr = XEXP (data->to, 0);
2312 unsigned int max_size = STORE_MAX_PIECES + 1;
2313 enum machine_mode mode = VOIDmode, tmode;
2314 enum insn_code icode;
2317 data->to_addr = to_addr;
2319 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2320 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2322 data->explicit_inc_to = 0;
2324 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2326 data->offset = data->len;
2328 /* If storing requires more than two move insns,
2329 copy addresses to registers (to make displacements shorter)
2330 and use post-increment if available. */
2331 if (!data->autinc_to
2332 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2334 /* Determine the main mode we'll be using. */
2335 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2336 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2337 if (GET_MODE_SIZE (tmode) < max_size)
2340 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2342 data->to_addr = copy_addr_to_reg (plus_constant (to_addr, data->len));
2343 data->autinc_to = 1;
2344 data->explicit_inc_to = -1;
2347 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2348 && ! data->autinc_to)
2350 data->to_addr = copy_addr_to_reg (to_addr);
2351 data->autinc_to = 1;
2352 data->explicit_inc_to = 1;
2355 if ( !data->autinc_to && CONSTANT_P (to_addr))
2356 data->to_addr = copy_addr_to_reg (to_addr);
2359 tmode = mode_for_size (STORE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
2360 if (align >= GET_MODE_ALIGNMENT (tmode))
2361 align = GET_MODE_ALIGNMENT (tmode);
2364 enum machine_mode xmode;
2366 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
2368 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
2369 if (GET_MODE_SIZE (tmode) > STORE_MAX_PIECES
2370 || SLOW_UNALIGNED_ACCESS (tmode, align))
2373 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
2376 /* First store what we can in the largest integer mode, then go to
2377 successively smaller modes. */
2379 while (max_size > 1)
2381 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2382 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2383 if (GET_MODE_SIZE (tmode) < max_size)
2386 if (mode == VOIDmode)
2389 icode = mov_optab->handlers[(int) mode].insn_code;
2390 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2391 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2393 max_size = GET_MODE_SIZE (mode);
2396 /* The code above should have handled everything. */
2397 gcc_assert (!data->len);
2400 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2401 with move instructions for mode MODE. GENFUN is the gen_... function
2402 to make a move insn for that mode. DATA has all the other info. */
2405 store_by_pieces_2 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
2406 struct store_by_pieces *data)
2408 unsigned int size = GET_MODE_SIZE (mode);
2411 while (data->len >= size)
2414 data->offset -= size;
2416 if (data->autinc_to)
2417 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2420 to1 = adjust_address (data->to, mode, data->offset);
2422 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2423 emit_insn (gen_add2_insn (data->to_addr,
2424 GEN_INT (-(HOST_WIDE_INT) size)));
2426 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2427 emit_insn ((*genfun) (to1, cst));
2429 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2430 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2432 if (! data->reverse)
2433 data->offset += size;
2439 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2440 its length in bytes. */
2443 clear_storage (rtx object, rtx size, enum block_op_methods method)
2445 enum machine_mode mode = GET_MODE (object);
2448 gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
2450 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2451 just move a zero. Otherwise, do this a piece at a time. */
2453 && GET_CODE (size) == CONST_INT
2454 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
2456 rtx zero = CONST0_RTX (mode);
2459 emit_move_insn (object, zero);
2463 if (COMPLEX_MODE_P (mode))
2465 zero = CONST0_RTX (GET_MODE_INNER (mode));
2468 write_complex_part (object, zero, 0);
2469 write_complex_part (object, zero, 1);
2475 if (size == const0_rtx)
2478 align = MEM_ALIGN (object);
2480 if (GET_CODE (size) == CONST_INT
2481 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2482 clear_by_pieces (object, INTVAL (size), align);
2483 else if (set_storage_via_setmem (object, size, const0_rtx, align))
2486 return clear_storage_via_libcall (object, size,
2487 method == BLOCK_OP_TAILCALL);
2492 /* A subroutine of clear_storage. Expand a call to memset.
2493 Return the return value of memset, 0 otherwise. */
2496 clear_storage_via_libcall (rtx object, rtx size, bool tailcall)
2498 tree call_expr, arg_list, fn, object_tree, size_tree;
2499 enum machine_mode size_mode;
2502 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2503 place those into new pseudos into a VAR_DECL and use them later. */
2505 object = copy_to_mode_reg (Pmode, XEXP (object, 0));
2507 size_mode = TYPE_MODE (sizetype);
2508 size = convert_to_mode (size_mode, size, 1);
2509 size = copy_to_mode_reg (size_mode, size);
2511 /* It is incorrect to use the libcall calling conventions to call
2512 memset in this context. This could be a user call to memset and
2513 the user may wish to examine the return value from memset. For
2514 targets where libcalls and normal calls have different conventions
2515 for returning pointers, we could end up generating incorrect code. */
2517 object_tree = make_tree (ptr_type_node, object);
2518 size_tree = make_tree (sizetype, size);
2520 fn = clear_storage_libcall_fn (true);
2521 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
2522 arg_list = tree_cons (NULL_TREE, integer_zero_node, arg_list);
2523 arg_list = tree_cons (NULL_TREE, object_tree, arg_list);
2525 /* Now we have to build up the CALL_EXPR itself. */
2526 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
2527 call_expr = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
2528 call_expr, arg_list, NULL_TREE);
2529 CALL_EXPR_TAILCALL (call_expr) = tailcall;
2531 retval = expand_normal (call_expr);
2536 /* A subroutine of clear_storage_via_libcall. Create the tree node
2537 for the function we use for block clears. The first time FOR_CALL
2538 is true, we call assemble_external. */
2540 static GTY(()) tree block_clear_fn;
2543 init_block_clear_fn (const char *asmspec)
2545 if (!block_clear_fn)
2549 fn = get_identifier ("memset");
2550 args = build_function_type_list (ptr_type_node, ptr_type_node,
2551 integer_type_node, sizetype,
2554 fn = build_decl (FUNCTION_DECL, fn, args);
2555 DECL_EXTERNAL (fn) = 1;
2556 TREE_PUBLIC (fn) = 1;
2557 DECL_ARTIFICIAL (fn) = 1;
2558 TREE_NOTHROW (fn) = 1;
2560 block_clear_fn = fn;
2564 set_user_assembler_name (block_clear_fn, asmspec);
2568 clear_storage_libcall_fn (int for_call)
2570 static bool emitted_extern;
2572 if (!block_clear_fn)
2573 init_block_clear_fn (NULL);
2575 if (for_call && !emitted_extern)
2577 emitted_extern = true;
2578 make_decl_rtl (block_clear_fn);
2579 assemble_external (block_clear_fn);
2582 return block_clear_fn;
2585 /* Expand a setmem pattern; return true if successful. */
2588 set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align)
2590 /* Try the most limited insn first, because there's no point
2591 including more than one in the machine description unless
2592 the more limited one has some advantage. */
2594 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
2595 enum machine_mode mode;
2597 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2598 mode = GET_MODE_WIDER_MODE (mode))
2600 enum insn_code code = setmem_optab[(int) mode];
2601 insn_operand_predicate_fn pred;
2603 if (code != CODE_FOR_nothing
2604 /* We don't need MODE to be narrower than
2605 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2606 the mode mask, as it is returned by the macro, it will
2607 definitely be less than the actual mode mask. */
2608 && ((GET_CODE (size) == CONST_INT
2609 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2610 <= (GET_MODE_MASK (mode) >> 1)))
2611 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2612 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
2613 || (*pred) (object, BLKmode))
2614 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
2615 || (*pred) (opalign, VOIDmode)))
2618 enum machine_mode char_mode;
2619 rtx last = get_last_insn ();
2622 opsize = convert_to_mode (mode, size, 1);
2623 pred = insn_data[(int) code].operand[1].predicate;
2624 if (pred != 0 && ! (*pred) (opsize, mode))
2625 opsize = copy_to_mode_reg (mode, opsize);
2628 char_mode = insn_data[(int) code].operand[2].mode;
2629 if (char_mode != VOIDmode)
2631 opchar = convert_to_mode (char_mode, opchar, 1);
2632 pred = insn_data[(int) code].operand[2].predicate;
2633 if (pred != 0 && ! (*pred) (opchar, char_mode))
2634 opchar = copy_to_mode_reg (char_mode, opchar);
2637 pat = GEN_FCN ((int) code) (object, opsize, opchar, opalign);
2644 delete_insns_since (last);
2652 /* Write to one of the components of the complex value CPLX. Write VAL to
2653 the real part if IMAG_P is false, and the imaginary part if its true. */
2656 write_complex_part (rtx cplx, rtx val, bool imag_p)
2658 enum machine_mode cmode;
2659 enum machine_mode imode;
2662 if (GET_CODE (cplx) == CONCAT)
2664 emit_move_insn (XEXP (cplx, imag_p), val);
2668 cmode = GET_MODE (cplx);
2669 imode = GET_MODE_INNER (cmode);
2670 ibitsize = GET_MODE_BITSIZE (imode);
2672 /* For MEMs simplify_gen_subreg may generate an invalid new address
2673 because, e.g., the original address is considered mode-dependent
2674 by the target, which restricts simplify_subreg from invoking
2675 adjust_address_nv. Instead of preparing fallback support for an
2676 invalid address, we call adjust_address_nv directly. */
2679 emit_move_insn (adjust_address_nv (cplx, imode,
2680 imag_p ? GET_MODE_SIZE (imode) : 0),
2685 /* If the sub-object is at least word sized, then we know that subregging
2686 will work. This special case is important, since store_bit_field
2687 wants to operate on integer modes, and there's rarely an OImode to
2688 correspond to TCmode. */
2689 if (ibitsize >= BITS_PER_WORD
2690 /* For hard regs we have exact predicates. Assume we can split
2691 the original object if it spans an even number of hard regs.
2692 This special case is important for SCmode on 64-bit platforms
2693 where the natural size of floating-point regs is 32-bit. */
2695 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2696 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2698 rtx part = simplify_gen_subreg (imode, cplx, cmode,
2699 imag_p ? GET_MODE_SIZE (imode) : 0);
2702 emit_move_insn (part, val);
2706 /* simplify_gen_subreg may fail for sub-word MEMs. */
2707 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2710 store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, imode, val);
2713 /* Extract one of the components of the complex value CPLX. Extract the
2714 real part if IMAG_P is false, and the imaginary part if it's true. */
2717 read_complex_part (rtx cplx, bool imag_p)
2719 enum machine_mode cmode, imode;
2722 if (GET_CODE (cplx) == CONCAT)
2723 return XEXP (cplx, imag_p);
2725 cmode = GET_MODE (cplx);
2726 imode = GET_MODE_INNER (cmode);
2727 ibitsize = GET_MODE_BITSIZE (imode);
2729 /* Special case reads from complex constants that got spilled to memory. */
2730 if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
2732 tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
2733 if (decl && TREE_CODE (decl) == COMPLEX_CST)
2735 tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
2736 if (CONSTANT_CLASS_P (part))
2737 return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
2741 /* For MEMs simplify_gen_subreg may generate an invalid new address
2742 because, e.g., the original address is considered mode-dependent
2743 by the target, which restricts simplify_subreg from invoking
2744 adjust_address_nv. Instead of preparing fallback support for an
2745 invalid address, we call adjust_address_nv directly. */
2747 return adjust_address_nv (cplx, imode,
2748 imag_p ? GET_MODE_SIZE (imode) : 0);
2750 /* If the sub-object is at least word sized, then we know that subregging
2751 will work. This special case is important, since extract_bit_field
2752 wants to operate on integer modes, and there's rarely an OImode to
2753 correspond to TCmode. */
2754 if (ibitsize >= BITS_PER_WORD
2755 /* For hard regs we have exact predicates. Assume we can split
2756 the original object if it spans an even number of hard regs.
2757 This special case is important for SCmode on 64-bit platforms
2758 where the natural size of floating-point regs is 32-bit. */
2760 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2761 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2763 rtx ret = simplify_gen_subreg (imode, cplx, cmode,
2764 imag_p ? GET_MODE_SIZE (imode) : 0);
2768 /* simplify_gen_subreg may fail for sub-word MEMs. */
2769 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2772 return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
2773 true, NULL_RTX, imode, imode);
2776 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
2777 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
2778 represented in NEW_MODE. If FORCE is true, this will never happen, as
2779 we'll force-create a SUBREG if needed. */
2782 emit_move_change_mode (enum machine_mode new_mode,
2783 enum machine_mode old_mode, rtx x, bool force)
2789 /* We don't have to worry about changing the address since the
2790 size in bytes is supposed to be the same. */
2791 if (reload_in_progress)
2793 /* Copy the MEM to change the mode and move any
2794 substitutions from the old MEM to the new one. */
2795 ret = adjust_address_nv (x, new_mode, 0);
2796 copy_replacements (x, ret);
2799 ret = adjust_address (x, new_mode, 0);
2803 /* Note that we do want simplify_subreg's behavior of validating
2804 that the new mode is ok for a hard register. If we were to use
2805 simplify_gen_subreg, we would create the subreg, but would
2806 probably run into the target not being able to implement it. */
2807 /* Except, of course, when FORCE is true, when this is exactly what
2808 we want. Which is needed for CCmodes on some targets. */
2810 ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
2812 ret = simplify_subreg (new_mode, x, old_mode, 0);
2818 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
2819 an integer mode of the same size as MODE. Returns the instruction
2820 emitted, or NULL if such a move could not be generated. */
2823 emit_move_via_integer (enum machine_mode mode, rtx x, rtx y, bool force)
2825 enum machine_mode imode;
2826 enum insn_code code;
2828 /* There must exist a mode of the exact size we require. */
2829 imode = int_mode_for_mode (mode);
2830 if (imode == BLKmode)
2833 /* The target must support moves in this mode. */
2834 code = mov_optab->handlers[imode].insn_code;
2835 if (code == CODE_FOR_nothing)
2838 x = emit_move_change_mode (imode, mode, x, force);
2841 y = emit_move_change_mode (imode, mode, y, force);
2844 return emit_insn (GEN_FCN (code) (x, y));
2847 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
2848 Return an equivalent MEM that does not use an auto-increment. */
2851 emit_move_resolve_push (enum machine_mode mode, rtx x)
2853 enum rtx_code code = GET_CODE (XEXP (x, 0));
2854 HOST_WIDE_INT adjust;
2857 adjust = GET_MODE_SIZE (mode);
2858 #ifdef PUSH_ROUNDING
2859 adjust = PUSH_ROUNDING (adjust);
2861 if (code == PRE_DEC || code == POST_DEC)
2863 else if (code == PRE_MODIFY || code == POST_MODIFY)
2865 rtx expr = XEXP (XEXP (x, 0), 1);
2868 gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
2869 gcc_assert (GET_CODE (XEXP (expr, 1)) == CONST_INT);
2870 val = INTVAL (XEXP (expr, 1));
2871 if (GET_CODE (expr) == MINUS)
2873 gcc_assert (adjust == val || adjust == -val);
2877 /* Do not use anti_adjust_stack, since we don't want to update
2878 stack_pointer_delta. */
2879 temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
2880 GEN_INT (adjust), stack_pointer_rtx,
2881 0, OPTAB_LIB_WIDEN);
2882 if (temp != stack_pointer_rtx)
2883 emit_move_insn (stack_pointer_rtx, temp);
2890 temp = stack_pointer_rtx;
2895 temp = plus_constant (stack_pointer_rtx, -adjust);
2901 return replace_equiv_address (x, temp);
2904 /* A subroutine of emit_move_complex. Generate a move from Y into X.
2905 X is known to satisfy push_operand, and MODE is known to be complex.
2906 Returns the last instruction emitted. */
2909 emit_move_complex_push (enum machine_mode mode, rtx x, rtx y)
2911 enum machine_mode submode = GET_MODE_INNER (mode);
2914 #ifdef PUSH_ROUNDING
2915 unsigned int submodesize = GET_MODE_SIZE (submode);
2917 /* In case we output to the stack, but the size is smaller than the
2918 machine can push exactly, we need to use move instructions. */
2919 if (PUSH_ROUNDING (submodesize) != submodesize)
2921 x = emit_move_resolve_push (mode, x);
2922 return emit_move_insn (x, y);
2926 /* Note that the real part always precedes the imag part in memory
2927 regardless of machine's endianness. */
2928 switch (GET_CODE (XEXP (x, 0)))
2942 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2943 read_complex_part (y, imag_first));
2944 return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2945 read_complex_part (y, !imag_first));
2948 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
2949 MODE is known to be complex. Returns the last instruction emitted. */
2952 emit_move_complex (enum machine_mode mode, rtx x, rtx y)
2956 /* Need to take special care for pushes, to maintain proper ordering
2957 of the data, and possibly extra padding. */
2958 if (push_operand (x, mode))
2959 return emit_move_complex_push (mode, x, y);
2961 /* See if we can coerce the target into moving both values at once. */
2963 /* Move floating point as parts. */
2964 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
2965 && mov_optab->handlers[GET_MODE_INNER (mode)].insn_code != CODE_FOR_nothing)
2967 /* Not possible if the values are inherently not adjacent. */
2968 else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
2970 /* Is possible if both are registers (or subregs of registers). */
2971 else if (register_operand (x, mode) && register_operand (y, mode))
2973 /* If one of the operands is a memory, and alignment constraints
2974 are friendly enough, we may be able to do combined memory operations.
2975 We do not attempt this if Y is a constant because that combination is
2976 usually better with the by-parts thing below. */
2977 else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
2978 && (!STRICT_ALIGNMENT
2979 || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
2988 /* For memory to memory moves, optimal behavior can be had with the
2989 existing block move logic. */
2990 if (MEM_P (x) && MEM_P (y))
2992 emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
2993 BLOCK_OP_NO_LIBCALL);
2994 return get_last_insn ();
2997 ret = emit_move_via_integer (mode, x, y, true);
3002 /* Show the output dies here. This is necessary for SUBREGs
3003 of pseudos since we cannot track their lifetimes correctly;
3004 hard regs shouldn't appear here except as return values. */
3005 if (!reload_completed && !reload_in_progress
3006 && REG_P (x) && !reg_overlap_mentioned_p (x, y))
3007 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3009 write_complex_part (x, read_complex_part (y, false), false);
3010 write_complex_part (x, read_complex_part (y, true), true);
3011 return get_last_insn ();
3014 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3015 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3018 emit_move_ccmode (enum machine_mode mode, rtx x, rtx y)
3022 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3025 enum insn_code code = mov_optab->handlers[CCmode].insn_code;
3026 if (code != CODE_FOR_nothing)
3028 x = emit_move_change_mode (CCmode, mode, x, true);
3029 y = emit_move_change_mode (CCmode, mode, y, true);
3030 return emit_insn (GEN_FCN (code) (x, y));
3034 /* Otherwise, find the MODE_INT mode of the same width. */
3035 ret = emit_move_via_integer (mode, x, y, false);
3036 gcc_assert (ret != NULL);
3040 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3041 MODE is any multi-word or full-word mode that lacks a move_insn
3042 pattern. Note that you will get better code if you define such
3043 patterns, even if they must turn into multiple assembler instructions. */
3046 emit_move_multi_word (enum machine_mode mode, rtx x, rtx y)
3053 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
3055 /* If X is a push on the stack, do the push now and replace
3056 X with a reference to the stack pointer. */
3057 if (push_operand (x, mode))
3058 x = emit_move_resolve_push (mode, x);
3060 /* If we are in reload, see if either operand is a MEM whose address
3061 is scheduled for replacement. */
3062 if (reload_in_progress && MEM_P (x)
3063 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3064 x = replace_equiv_address_nv (x, inner);
3065 if (reload_in_progress && MEM_P (y)
3066 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3067 y = replace_equiv_address_nv (y, inner);
3071 need_clobber = false;
3073 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3076 rtx xpart = operand_subword (x, i, 1, mode);
3077 rtx ypart = operand_subword (y, i, 1, mode);
3079 /* If we can't get a part of Y, put Y into memory if it is a
3080 constant. Otherwise, force it into a register. Then we must
3081 be able to get a part of Y. */
3082 if (ypart == 0 && CONSTANT_P (y))
3084 y = use_anchored_address (force_const_mem (mode, y));
3085 ypart = operand_subword (y, i, 1, mode);
3087 else if (ypart == 0)
3088 ypart = operand_subword_force (y, i, mode);
3090 gcc_assert (xpart && ypart);
3092 need_clobber |= (GET_CODE (xpart) == SUBREG);
3094 last_insn = emit_move_insn (xpart, ypart);
3100 /* Show the output dies here. This is necessary for SUBREGs
3101 of pseudos since we cannot track their lifetimes correctly;
3102 hard regs shouldn't appear here except as return values.
3103 We never want to emit such a clobber after reload. */
3105 && ! (reload_in_progress || reload_completed)
3106 && need_clobber != 0)
3107 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3114 /* Low level part of emit_move_insn.
3115 Called just like emit_move_insn, but assumes X and Y
3116 are basically valid. */
3119 emit_move_insn_1 (rtx x, rtx y)
3121 enum machine_mode mode = GET_MODE (x);
3122 enum insn_code code;
3124 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
3126 code = mov_optab->handlers[mode].insn_code;
3127 if (code != CODE_FOR_nothing)
3128 return emit_insn (GEN_FCN (code) (x, y));
3130 /* Expand complex moves by moving real part and imag part. */
3131 if (COMPLEX_MODE_P (mode))
3132 return emit_move_complex (mode, x, y);
3134 if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT)
3136 rtx result = emit_move_via_integer (mode, x, y, true);
3138 /* If we can't find an integer mode, use multi words. */
3142 return emit_move_multi_word (mode, x, y);
3145 if (GET_MODE_CLASS (mode) == MODE_CC)
3146 return emit_move_ccmode (mode, x, y);
3148 /* Try using a move pattern for the corresponding integer mode. This is
3149 only safe when simplify_subreg can convert MODE constants into integer
3150 constants. At present, it can only do this reliably if the value
3151 fits within a HOST_WIDE_INT. */
3152 if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3154 rtx ret = emit_move_via_integer (mode, x, y, false);
3159 return emit_move_multi_word (mode, x, y);
3162 /* Generate code to copy Y into X.
3163 Both Y and X must have the same mode, except that
3164 Y can be a constant with VOIDmode.
3165 This mode cannot be BLKmode; use emit_block_move for that.
3167 Return the last instruction emitted. */
3170 emit_move_insn (rtx x, rtx y)
3172 enum machine_mode mode = GET_MODE (x);
3173 rtx y_cst = NULL_RTX;
3176 gcc_assert (mode != BLKmode
3177 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
3182 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3183 && (last_insn = compress_float_constant (x, y)))
3188 if (!LEGITIMATE_CONSTANT_P (y))
3190 y = force_const_mem (mode, y);
3192 /* If the target's cannot_force_const_mem prevented the spill,
3193 assume that the target's move expanders will also take care
3194 of the non-legitimate constant. */
3198 y = use_anchored_address (y);
3202 /* If X or Y are memory references, verify that their addresses are valid
3205 && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
3206 && ! push_operand (x, GET_MODE (x)))
3208 && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
3209 x = validize_mem (x);
3212 && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
3214 && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
3215 y = validize_mem (y);
3217 gcc_assert (mode != BLKmode);
3219 last_insn = emit_move_insn_1 (x, y);
3221 if (y_cst && REG_P (x)
3222 && (set = single_set (last_insn)) != NULL_RTX
3223 && SET_DEST (set) == x
3224 && ! rtx_equal_p (y_cst, SET_SRC (set)))
3225 set_unique_reg_note (last_insn, REG_EQUAL, y_cst);
3230 /* If Y is representable exactly in a narrower mode, and the target can
3231 perform the extension directly from constant or memory, then emit the
3232 move as an extension. */
3235 compress_float_constant (rtx x, rtx y)
3237 enum machine_mode dstmode = GET_MODE (x);
3238 enum machine_mode orig_srcmode = GET_MODE (y);
3239 enum machine_mode srcmode;
3241 int oldcost, newcost;
3243 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3245 if (LEGITIMATE_CONSTANT_P (y))
3246 oldcost = rtx_cost (y, SET);
3248 oldcost = rtx_cost (force_const_mem (dstmode, y), SET);
3250 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3251 srcmode != orig_srcmode;
3252 srcmode = GET_MODE_WIDER_MODE (srcmode))
3255 rtx trunc_y, last_insn;
3257 /* Skip if the target can't extend this way. */
3258 ic = can_extend_p (dstmode, srcmode, 0);
3259 if (ic == CODE_FOR_nothing)
3262 /* Skip if the narrowed value isn't exact. */
3263 if (! exact_real_truncate (srcmode, &r))
3266 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3268 if (LEGITIMATE_CONSTANT_P (trunc_y))
3270 /* Skip if the target needs extra instructions to perform
3272 if (! (*insn_data[ic].operand[1].predicate) (trunc_y, srcmode))
3274 /* This is valid, but may not be cheaper than the original. */
3275 newcost = rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y), SET);
3276 if (oldcost < newcost)
3279 else if (float_extend_from_mem[dstmode][srcmode])
3281 trunc_y = force_const_mem (srcmode, trunc_y);
3282 /* This is valid, but may not be cheaper than the original. */
3283 newcost = rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y), SET);
3284 if (oldcost < newcost)
3286 trunc_y = validize_mem (trunc_y);
3291 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3292 last_insn = get_last_insn ();
3295 set_unique_reg_note (last_insn, REG_EQUAL, y);
3303 /* Pushing data onto the stack. */
3305 /* Push a block of length SIZE (perhaps variable)
3306 and return an rtx to address the beginning of the block.
3307 The value may be virtual_outgoing_args_rtx.
3309 EXTRA is the number of bytes of padding to push in addition to SIZE.
3310 BELOW nonzero means this padding comes at low addresses;
3311 otherwise, the padding comes at high addresses. */
3314 push_block (rtx size, int extra, int below)
3318 size = convert_modes (Pmode, ptr_mode, size, 1);
3319 if (CONSTANT_P (size))
3320 anti_adjust_stack (plus_constant (size, extra));
3321 else if (REG_P (size) && extra == 0)
3322 anti_adjust_stack (size);
3325 temp = copy_to_mode_reg (Pmode, size);
3327 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
3328 temp, 0, OPTAB_LIB_WIDEN);
3329 anti_adjust_stack (temp);
3332 #ifndef STACK_GROWS_DOWNWARD
3338 temp = virtual_outgoing_args_rtx;
3339 if (extra != 0 && below)
3340 temp = plus_constant (temp, extra);
3344 if (GET_CODE (size) == CONST_INT)
3345 temp = plus_constant (virtual_outgoing_args_rtx,
3346 -INTVAL (size) - (below ? 0 : extra));
3347 else if (extra != 0 && !below)
3348 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3349 negate_rtx (Pmode, plus_constant (size, extra)));
3351 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3352 negate_rtx (Pmode, size));
3355 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3358 #ifdef PUSH_ROUNDING
3360 /* Emit single push insn. */
3363 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
3366 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3368 enum insn_code icode;
3369 insn_operand_predicate_fn pred;
3371 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3372 /* If there is push pattern, use it. Otherwise try old way of throwing
3373 MEM representing push operation to move expander. */
3374 icode = push_optab->handlers[(int) mode].insn_code;
3375 if (icode != CODE_FOR_nothing)
3377 if (((pred = insn_data[(int) icode].operand[0].predicate)
3378 && !((*pred) (x, mode))))
3379 x = force_reg (mode, x);
3380 emit_insn (GEN_FCN (icode) (x));
3383 if (GET_MODE_SIZE (mode) == rounded_size)
3384 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3385 /* If we are to pad downward, adjust the stack pointer first and
3386 then store X into the stack location using an offset. This is
3387 because emit_move_insn does not know how to pad; it does not have
3389 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3391 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3392 HOST_WIDE_INT offset;
3394 emit_move_insn (stack_pointer_rtx,
3395 expand_binop (Pmode,
3396 #ifdef STACK_GROWS_DOWNWARD
3402 GEN_INT (rounded_size),
3403 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3405 offset = (HOST_WIDE_INT) padding_size;
3406 #ifdef STACK_GROWS_DOWNWARD
3407 if (STACK_PUSH_CODE == POST_DEC)
3408 /* We have already decremented the stack pointer, so get the
3410 offset += (HOST_WIDE_INT) rounded_size;
3412 if (STACK_PUSH_CODE == POST_INC)
3413 /* We have already incremented the stack pointer, so get the
3415 offset -= (HOST_WIDE_INT) rounded_size;
3417 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3421 #ifdef STACK_GROWS_DOWNWARD
3422 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3423 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3424 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3426 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3427 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3428 GEN_INT (rounded_size));
3430 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3433 dest = gen_rtx_MEM (mode, dest_addr);
3437 set_mem_attributes (dest, type, 1);
3439 if (flag_optimize_sibling_calls)
3440 /* Function incoming arguments may overlap with sibling call
3441 outgoing arguments and we cannot allow reordering of reads
3442 from function arguments with stores to outgoing arguments
3443 of sibling calls. */
3444 set_mem_alias_set (dest, 0);
3446 emit_move_insn (dest, x);
3450 /* Generate code to push X onto the stack, assuming it has mode MODE and
3452 MODE is redundant except when X is a CONST_INT (since they don't
3454 SIZE is an rtx for the size of data to be copied (in bytes),
3455 needed only if X is BLKmode.
3457 ALIGN (in bits) is maximum alignment we can assume.
3459 If PARTIAL and REG are both nonzero, then copy that many of the first
3460 bytes of X into registers starting with REG, and push the rest of X.
3461 The amount of space pushed is decreased by PARTIAL bytes.
3462 REG must be a hard register in this case.
3463 If REG is zero but PARTIAL is not, take any all others actions for an
3464 argument partially in registers, but do not actually load any
3467 EXTRA is the amount in bytes of extra space to leave next to this arg.
3468 This is ignored if an argument block has already been allocated.
3470 On a machine that lacks real push insns, ARGS_ADDR is the address of
3471 the bottom of the argument block for this call. We use indexing off there
3472 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3473 argument block has not been preallocated.
3475 ARGS_SO_FAR is the size of args previously pushed for this call.
3477 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3478 for arguments passed in registers. If nonzero, it will be the number
3479 of bytes required. */
3482 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
3483 unsigned int align, int partial, rtx reg, int extra,
3484 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
3488 enum direction stack_direction
3489 #ifdef STACK_GROWS_DOWNWARD
3495 /* Decide where to pad the argument: `downward' for below,
3496 `upward' for above, or `none' for don't pad it.
3497 Default is below for small data on big-endian machines; else above. */
3498 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
3500 /* Invert direction if stack is post-decrement.
3502 if (STACK_PUSH_CODE == POST_DEC)
3503 if (where_pad != none)
3504 where_pad = (where_pad == downward ? upward : downward);
3508 if (mode == BLKmode)
3510 /* Copy a block into the stack, entirely or partially. */
3517 offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
3518 used = partial - offset;
3522 /* USED is now the # of bytes we need not copy to the stack
3523 because registers will take care of them. */
3526 xinner = adjust_address (xinner, BLKmode, used);
3528 /* If the partial register-part of the arg counts in its stack size,
3529 skip the part of stack space corresponding to the registers.
3530 Otherwise, start copying to the beginning of the stack space,
3531 by setting SKIP to 0. */
3532 skip = (reg_parm_stack_space == 0) ? 0 : used;
3534 #ifdef PUSH_ROUNDING
3535 /* Do it with several push insns if that doesn't take lots of insns
3536 and if there is no difficulty with push insns that skip bytes
3537 on the stack for alignment purposes. */
3540 && GET_CODE (size) == CONST_INT
3542 && MEM_ALIGN (xinner) >= align
3543 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
3544 /* Here we avoid the case of a structure whose weak alignment
3545 forces many pushes of a small amount of data,
3546 and such small pushes do rounding that causes trouble. */
3547 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
3548 || align >= BIGGEST_ALIGNMENT
3549 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
3550 == (align / BITS_PER_UNIT)))
3551 && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
3553 /* Push padding now if padding above and stack grows down,
3554 or if padding below and stack grows up.
3555 But if space already allocated, this has already been done. */
3556 if (extra && args_addr == 0
3557 && where_pad != none && where_pad != stack_direction)
3558 anti_adjust_stack (GEN_INT (extra));
3560 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
3563 #endif /* PUSH_ROUNDING */
3567 /* Otherwise make space on the stack and copy the data
3568 to the address of that space. */
3570 /* Deduct words put into registers from the size we must copy. */
3573 if (GET_CODE (size) == CONST_INT)
3574 size = GEN_INT (INTVAL (size) - used);
3576 size = expand_binop (GET_MODE (size), sub_optab, size,
3577 GEN_INT (used), NULL_RTX, 0,
3581 /* Get the address of the stack space.
3582 In this case, we do not deal with EXTRA separately.
3583 A single stack adjust will do. */
3586 temp = push_block (size, extra, where_pad == downward);
3589 else if (GET_CODE (args_so_far) == CONST_INT)
3590 temp = memory_address (BLKmode,
3591 plus_constant (args_addr,