1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
32 #include "hard-reg-set.h"
35 #include "insn-config.h"
36 #include "insn-attr.h"
37 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
44 #include "typeclass.h"
47 #include "langhooks.h"
50 #include "tree-iterator.h"
51 #include "tree-pass.h"
52 #include "tree-flow.h"
56 /* Decide whether a function's arguments should be processed
57 from first to last or from last to first.
59 They should if the stack and args grow in opposite directions, but
60 only if we have push insns. */
64 #ifndef PUSH_ARGS_REVERSED
65 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
66 #define PUSH_ARGS_REVERSED /* If it's last to first. */
72 #ifndef STACK_PUSH_CODE
73 #ifdef STACK_GROWS_DOWNWARD
74 #define STACK_PUSH_CODE PRE_DEC
76 #define STACK_PUSH_CODE PRE_INC
81 /* If this is nonzero, we do not bother generating VOLATILE
82 around volatile memory references, and we are willing to
83 output indirect addresses. If cse is to follow, we reject
84 indirect addresses so a useful potential cse is generated;
85 if it is used only once, instruction combination will produce
86 the same indirect address eventually. */
89 /* This structure is used by move_by_pieces to describe the move to
100 int explicit_inc_from;
101 unsigned HOST_WIDE_INT len;
102 HOST_WIDE_INT offset;
106 /* This structure is used by store_by_pieces to describe the clear to
109 struct store_by_pieces
115 unsigned HOST_WIDE_INT len;
116 HOST_WIDE_INT offset;
117 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
122 static unsigned HOST_WIDE_INT move_by_pieces_ninsns (unsigned HOST_WIDE_INT,
125 static void move_by_pieces_1 (rtx (*) (rtx, ...), enum machine_mode,
126 struct move_by_pieces *);
127 static bool block_move_libcall_safe_for_call_parm (void);
128 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned);
129 static rtx emit_block_move_via_libcall (rtx, rtx, rtx);
130 static tree emit_block_move_libcall_fn (int);
131 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
132 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
133 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
134 static void store_by_pieces_1 (struct store_by_pieces *, unsigned int);
135 static void store_by_pieces_2 (rtx (*) (rtx, ...), enum machine_mode,
136 struct store_by_pieces *);
137 static bool clear_storage_via_clrmem (rtx, rtx, unsigned);
138 static rtx clear_storage_via_libcall (rtx, rtx);
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,
147 tree, enum machine_mode, int, tree, int);
149 static unsigned HOST_WIDE_INT highest_pow2_factor (tree);
150 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (tree, tree);
152 static int is_aligning_offset (tree, tree);
153 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
154 enum expand_modifier);
155 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
156 static rtx do_store_flag (tree, rtx, enum machine_mode, int);
158 static void emit_single_push_insn (enum machine_mode, rtx, tree);
160 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx);
161 static rtx const_vector_from_tree (tree);
163 /* Record for each mode whether we can move a register directly to or
164 from an object of that mode in memory. If we can't, we won't try
165 to use that mode directly when accessing a field of that mode. */
167 static char direct_load[NUM_MACHINE_MODES];
168 static char direct_store[NUM_MACHINE_MODES];
170 /* Record for each mode whether we can float-extend from memory. */
172 static bool float_extend_from_mem[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
174 /* This macro is used to determine whether move_by_pieces should be called
175 to perform a structure copy. */
176 #ifndef MOVE_BY_PIECES_P
177 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
178 (move_by_pieces_ninsns (SIZE, ALIGN, 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 clears. */
203 enum insn_code clrmem_optab[NUM_MACHINE_MODES];
205 /* These arrays record the insn_code of two different kinds of insns
206 to perform block compares. */
207 enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
208 enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
210 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
212 #ifndef SLOW_UNALIGNED_ACCESS
213 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
216 /* This is run once per compilation to set up which modes can be used
217 directly in memory and to initialize the block move optab. */
220 init_expr_once (void)
223 enum machine_mode mode;
228 /* Try indexing by frame ptr and try by stack ptr.
229 It is known that on the Convex the stack ptr isn't a valid index.
230 With luck, one or the other is valid on any machine. */
231 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
232 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
234 /* A scratch register we can modify in-place below to avoid
235 useless RTL allocations. */
236 reg = gen_rtx_REG (VOIDmode, -1);
238 insn = rtx_alloc (INSN);
239 pat = gen_rtx_SET (0, NULL_RTX, NULL_RTX);
240 PATTERN (insn) = pat;
242 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
243 mode = (enum machine_mode) ((int) mode + 1))
247 direct_load[(int) mode] = direct_store[(int) mode] = 0;
248 PUT_MODE (mem, mode);
249 PUT_MODE (mem1, mode);
250 PUT_MODE (reg, mode);
252 /* See if there is some register that can be used in this mode and
253 directly loaded or stored from memory. */
255 if (mode != VOIDmode && mode != BLKmode)
256 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
257 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
260 if (! HARD_REGNO_MODE_OK (regno, mode))
266 SET_DEST (pat) = reg;
267 if (recog (pat, insn, &num_clobbers) >= 0)
268 direct_load[(int) mode] = 1;
270 SET_SRC (pat) = mem1;
271 SET_DEST (pat) = reg;
272 if (recog (pat, insn, &num_clobbers) >= 0)
273 direct_load[(int) mode] = 1;
276 SET_DEST (pat) = mem;
277 if (recog (pat, insn, &num_clobbers) >= 0)
278 direct_store[(int) mode] = 1;
281 SET_DEST (pat) = mem1;
282 if (recog (pat, insn, &num_clobbers) >= 0)
283 direct_store[(int) mode] = 1;
287 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
289 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
290 mode = GET_MODE_WIDER_MODE (mode))
292 enum machine_mode srcmode;
293 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
294 srcmode = GET_MODE_WIDER_MODE (srcmode))
298 ic = can_extend_p (mode, srcmode, 0);
299 if (ic == CODE_FOR_nothing)
302 PUT_MODE (mem, srcmode);
304 if ((*insn_data[ic].operand[1].predicate) (mem, srcmode))
305 float_extend_from_mem[mode][srcmode] = true;
310 /* This is run at the start of compiling a function. */
315 cfun->expr = ggc_alloc_cleared (sizeof (struct expr_status));
318 /* Copy data from FROM to TO, where the machine modes are not the same.
319 Both modes may be integer, or both may be floating.
320 UNSIGNEDP should be nonzero if FROM is an unsigned type.
321 This causes zero-extension instead of sign-extension. */
324 convert_move (rtx to, rtx from, int unsignedp)
326 enum machine_mode to_mode = GET_MODE (to);
327 enum machine_mode from_mode = GET_MODE (from);
328 int to_real = GET_MODE_CLASS (to_mode) == MODE_FLOAT;
329 int from_real = GET_MODE_CLASS (from_mode) == MODE_FLOAT;
333 /* rtx code for making an equivalent value. */
334 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
335 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
338 gcc_assert (to_real == from_real);
340 /* If the source and destination are already the same, then there's
345 /* If FROM is a SUBREG that indicates that we have already done at least
346 the required extension, strip it. We don't handle such SUBREGs as
349 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
350 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
351 >= GET_MODE_SIZE (to_mode))
352 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
353 from = gen_lowpart (to_mode, from), from_mode = to_mode;
355 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
357 if (to_mode == from_mode
358 || (from_mode == VOIDmode && CONSTANT_P (from)))
360 emit_move_insn (to, from);
364 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
366 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
368 if (VECTOR_MODE_P (to_mode))
369 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
371 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
373 emit_move_insn (to, from);
377 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
379 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
380 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
389 gcc_assert (GET_MODE_PRECISION (from_mode)
390 != GET_MODE_PRECISION (to_mode));
392 if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
397 /* Try converting directly if the insn is supported. */
399 code = tab->handlers[to_mode][from_mode].insn_code;
400 if (code != CODE_FOR_nothing)
402 emit_unop_insn (code, to, from,
403 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
407 /* Otherwise use a libcall. */
408 libcall = tab->handlers[to_mode][from_mode].libfunc;
410 /* Is this conversion implemented yet? */
411 gcc_assert (libcall);
414 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
416 insns = get_insns ();
418 emit_libcall_block (insns, to, value,
419 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
421 : gen_rtx_FLOAT_EXTEND (to_mode, from));
425 /* Handle pointer conversion. */ /* SPEE 900220. */
426 /* Targets are expected to provide conversion insns between PxImode and
427 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
428 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
430 enum machine_mode full_mode
431 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
433 gcc_assert (trunc_optab->handlers[to_mode][full_mode].insn_code
434 != CODE_FOR_nothing);
436 if (full_mode != from_mode)
437 from = convert_to_mode (full_mode, from, unsignedp);
438 emit_unop_insn (trunc_optab->handlers[to_mode][full_mode].insn_code,
442 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
444 enum machine_mode full_mode
445 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
447 gcc_assert (sext_optab->handlers[full_mode][from_mode].insn_code
448 != CODE_FOR_nothing);
450 emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
452 if (to_mode == full_mode)
455 /* else proceed to integer conversions below. */
456 from_mode = full_mode;
459 /* Now both modes are integers. */
461 /* Handle expanding beyond a word. */
462 if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
463 && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
470 enum machine_mode lowpart_mode;
471 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
473 /* Try converting directly if the insn is supported. */
474 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
477 /* If FROM is a SUBREG, put it into a register. Do this
478 so that we always generate the same set of insns for
479 better cse'ing; if an intermediate assignment occurred,
480 we won't be doing the operation directly on the SUBREG. */
481 if (optimize > 0 && GET_CODE (from) == SUBREG)
482 from = force_reg (from_mode, from);
483 emit_unop_insn (code, to, from, equiv_code);
486 /* Next, try converting via full word. */
487 else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
488 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
489 != CODE_FOR_nothing))
493 if (reg_overlap_mentioned_p (to, from))
494 from = force_reg (from_mode, from);
495 emit_insn (gen_rtx_CLOBBER (VOIDmode, to));
497 convert_move (gen_lowpart (word_mode, to), from, unsignedp);
498 emit_unop_insn (code, to,
499 gen_lowpart (word_mode, to), equiv_code);
503 /* No special multiword conversion insn; do it by hand. */
506 /* Since we will turn this into a no conflict block, we must ensure
507 that the source does not overlap the target. */
509 if (reg_overlap_mentioned_p (to, from))
510 from = force_reg (from_mode, from);
512 /* Get a copy of FROM widened to a word, if necessary. */
513 if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
514 lowpart_mode = word_mode;
516 lowpart_mode = from_mode;
518 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
520 lowpart = gen_lowpart (lowpart_mode, to);
521 emit_move_insn (lowpart, lowfrom);
523 /* Compute the value to put in each remaining word. */
525 fill_value = const0_rtx;
530 && insn_data[(int) CODE_FOR_slt].operand[0].mode == word_mode
531 && STORE_FLAG_VALUE == -1)
533 emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
535 fill_value = gen_reg_rtx (word_mode);
536 emit_insn (gen_slt (fill_value));
542 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
543 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
545 fill_value = convert_to_mode (word_mode, fill_value, 1);
549 /* Fill the remaining words. */
550 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
552 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
553 rtx subword = operand_subword (to, index, 1, to_mode);
555 gcc_assert (subword);
557 if (fill_value != subword)
558 emit_move_insn (subword, fill_value);
561 insns = get_insns ();
564 emit_no_conflict_block (insns, to, from, NULL_RTX,
565 gen_rtx_fmt_e (equiv_code, to_mode, copy_rtx (from)));
569 /* Truncating multi-word to a word or less. */
570 if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
571 && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
574 && ! MEM_VOLATILE_P (from)
575 && direct_load[(int) to_mode]
576 && ! mode_dependent_address_p (XEXP (from, 0)))
578 || GET_CODE (from) == SUBREG))
579 from = force_reg (from_mode, from);
580 convert_move (to, gen_lowpart (word_mode, from), 0);
584 /* Now follow all the conversions between integers
585 no more than a word long. */
587 /* For truncation, usually we can just refer to FROM in a narrower mode. */
588 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
589 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
590 GET_MODE_BITSIZE (from_mode)))
593 && ! MEM_VOLATILE_P (from)
594 && direct_load[(int) to_mode]
595 && ! mode_dependent_address_p (XEXP (from, 0)))
597 || GET_CODE (from) == SUBREG))
598 from = force_reg (from_mode, from);
599 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
600 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
601 from = copy_to_reg (from);
602 emit_move_insn (to, gen_lowpart (to_mode, from));
606 /* Handle extension. */
607 if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
609 /* Convert directly if that works. */
610 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
614 from = force_not_mem (from);
616 emit_unop_insn (code, to, from, equiv_code);
621 enum machine_mode intermediate;
625 /* Search for a mode to convert via. */
626 for (intermediate = from_mode; intermediate != VOIDmode;
627 intermediate = GET_MODE_WIDER_MODE (intermediate))
628 if (((can_extend_p (to_mode, intermediate, unsignedp)
630 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
631 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
632 GET_MODE_BITSIZE (intermediate))))
633 && (can_extend_p (intermediate, from_mode, unsignedp)
634 != CODE_FOR_nothing))
636 convert_move (to, convert_to_mode (intermediate, from,
637 unsignedp), unsignedp);
641 /* No suitable intermediate mode.
642 Generate what we need with shifts. */
643 shift_amount = build_int_cst (NULL_TREE,
644 GET_MODE_BITSIZE (to_mode)
645 - GET_MODE_BITSIZE (from_mode));
646 from = gen_lowpart (to_mode, force_reg (from_mode, from));
647 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
649 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
652 emit_move_insn (to, tmp);
657 /* Support special truncate insns for certain modes. */
658 if (trunc_optab->handlers[to_mode][from_mode].insn_code != CODE_FOR_nothing)
660 emit_unop_insn (trunc_optab->handlers[to_mode][from_mode].insn_code,
665 /* Handle truncation of volatile memrefs, and so on;
666 the things that couldn't be truncated directly,
667 and for which there was no special instruction.
669 ??? Code above formerly short-circuited this, for most integer
670 mode pairs, with a force_reg in from_mode followed by a recursive
671 call to this routine. Appears always to have been wrong. */
672 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
674 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
675 emit_move_insn (to, temp);
679 /* Mode combination is not recognized. */
683 /* Return an rtx for a value that would result
684 from converting X to mode MODE.
685 Both X and MODE may be floating, or both integer.
686 UNSIGNEDP is nonzero if X is an unsigned value.
687 This can be done by referring to a part of X in place
688 or by copying to a new temporary with conversion. */
691 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
693 return convert_modes (mode, VOIDmode, x, unsignedp);
696 /* Return an rtx for a value that would result
697 from converting X from mode OLDMODE to mode MODE.
698 Both modes may be floating, or both integer.
699 UNSIGNEDP is nonzero if X is an unsigned value.
701 This can be done by referring to a part of X in place
702 or by copying to a new temporary with conversion.
704 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
707 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
711 /* If FROM is a SUBREG that indicates that we have already done at least
712 the required extension, strip it. */
714 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
715 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
716 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
717 x = gen_lowpart (mode, x);
719 if (GET_MODE (x) != VOIDmode)
720 oldmode = GET_MODE (x);
725 /* There is one case that we must handle specially: If we are converting
726 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
727 we are to interpret the constant as unsigned, gen_lowpart will do
728 the wrong if the constant appears negative. What we want to do is
729 make the high-order word of the constant zero, not all ones. */
731 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
732 && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
733 && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
735 HOST_WIDE_INT val = INTVAL (x);
737 if (oldmode != VOIDmode
738 && HOST_BITS_PER_WIDE_INT > GET_MODE_BITSIZE (oldmode))
740 int width = GET_MODE_BITSIZE (oldmode);
742 /* We need to zero extend VAL. */
743 val &= ((HOST_WIDE_INT) 1 << width) - 1;
746 return immed_double_const (val, (HOST_WIDE_INT) 0, mode);
749 /* We can do this with a gen_lowpart if both desired and current modes
750 are integer, and this is either a constant integer, a register, or a
751 non-volatile MEM. Except for the constant case where MODE is no
752 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
754 if ((GET_CODE (x) == CONST_INT
755 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
756 || (GET_MODE_CLASS (mode) == MODE_INT
757 && GET_MODE_CLASS (oldmode) == MODE_INT
758 && (GET_CODE (x) == CONST_DOUBLE
759 || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
760 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
761 && direct_load[(int) mode])
763 && (! HARD_REGISTER_P (x)
764 || HARD_REGNO_MODE_OK (REGNO (x), mode))
765 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
766 GET_MODE_BITSIZE (GET_MODE (x)))))))))
768 /* ?? If we don't know OLDMODE, we have to assume here that
769 X does not need sign- or zero-extension. This may not be
770 the case, but it's the best we can do. */
771 if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
772 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
774 HOST_WIDE_INT val = INTVAL (x);
775 int width = GET_MODE_BITSIZE (oldmode);
777 /* We must sign or zero-extend in this case. Start by
778 zero-extending, then sign extend if we need to. */
779 val &= ((HOST_WIDE_INT) 1 << width) - 1;
781 && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
782 val |= (HOST_WIDE_INT) (-1) << width;
784 return gen_int_mode (val, mode);
787 return gen_lowpart (mode, x);
790 /* Converting from integer constant into mode is always equivalent to an
792 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
794 gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
795 return simplify_gen_subreg (mode, x, oldmode, 0);
798 temp = gen_reg_rtx (mode);
799 convert_move (temp, x, unsignedp);
803 /* STORE_MAX_PIECES is the number of bytes at a time that we can
804 store efficiently. Due to internal GCC limitations, this is
805 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
806 for an immediate constant. */
808 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
810 /* Determine whether the LEN bytes can be moved by using several move
811 instructions. Return nonzero if a call to move_by_pieces should
815 can_move_by_pieces (unsigned HOST_WIDE_INT len,
816 unsigned int align ATTRIBUTE_UNUSED)
818 return MOVE_BY_PIECES_P (len, align);
821 /* Generate several move instructions to copy LEN bytes from block FROM to
822 block TO. (These are MEM rtx's with BLKmode).
824 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
825 used to push FROM to the stack.
827 ALIGN is maximum stack alignment we can assume.
829 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
830 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
834 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
835 unsigned int align, int endp)
837 struct move_by_pieces data;
838 rtx to_addr, from_addr = XEXP (from, 0);
839 unsigned int max_size = MOVE_MAX_PIECES + 1;
840 enum machine_mode mode = VOIDmode, tmode;
841 enum insn_code icode;
843 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
846 data.from_addr = from_addr;
849 to_addr = XEXP (to, 0);
852 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
853 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
855 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
862 #ifdef STACK_GROWS_DOWNWARD
868 data.to_addr = to_addr;
871 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
872 || GET_CODE (from_addr) == POST_INC
873 || GET_CODE (from_addr) == POST_DEC);
875 data.explicit_inc_from = 0;
876 data.explicit_inc_to = 0;
877 if (data.reverse) data.offset = len;
880 /* If copying requires more than two move insns,
881 copy addresses to registers (to make displacements shorter)
882 and use post-increment if available. */
883 if (!(data.autinc_from && data.autinc_to)
884 && move_by_pieces_ninsns (len, align, max_size) > 2)
886 /* Find the mode of the largest move... */
887 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
888 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
889 if (GET_MODE_SIZE (tmode) < max_size)
892 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
894 data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
895 data.autinc_from = 1;
896 data.explicit_inc_from = -1;
898 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
900 data.from_addr = copy_addr_to_reg (from_addr);
901 data.autinc_from = 1;
902 data.explicit_inc_from = 1;
904 if (!data.autinc_from && CONSTANT_P (from_addr))
905 data.from_addr = copy_addr_to_reg (from_addr);
906 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
908 data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
910 data.explicit_inc_to = -1;
912 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
914 data.to_addr = copy_addr_to_reg (to_addr);
916 data.explicit_inc_to = 1;
918 if (!data.autinc_to && CONSTANT_P (to_addr))
919 data.to_addr = copy_addr_to_reg (to_addr);
922 tmode = mode_for_size (MOVE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
923 if (align >= GET_MODE_ALIGNMENT (tmode))
924 align = GET_MODE_ALIGNMENT (tmode);
927 enum machine_mode xmode;
929 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
931 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
932 if (GET_MODE_SIZE (tmode) > MOVE_MAX_PIECES
933 || SLOW_UNALIGNED_ACCESS (tmode, align))
936 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
939 /* First move what we can in the largest integer mode, then go to
940 successively smaller modes. */
944 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
945 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
946 if (GET_MODE_SIZE (tmode) < max_size)
949 if (mode == VOIDmode)
952 icode = mov_optab->handlers[(int) mode].insn_code;
953 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
954 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
956 max_size = GET_MODE_SIZE (mode);
959 /* The code above should have handled everything. */
960 gcc_assert (!data.len);
966 gcc_assert (!data.reverse);
971 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
972 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
974 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
977 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
984 to1 = adjust_address (data.to, QImode, data.offset);
992 /* Return number of insns required to move L bytes by pieces.
993 ALIGN (in bits) is maximum alignment we can assume. */
995 static unsigned HOST_WIDE_INT
996 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
997 unsigned int max_size)
999 unsigned HOST_WIDE_INT n_insns = 0;
1000 enum machine_mode tmode;
1002 tmode = mode_for_size (MOVE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
1003 if (align >= GET_MODE_ALIGNMENT (tmode))
1004 align = GET_MODE_ALIGNMENT (tmode);
1007 enum machine_mode tmode, xmode;
1009 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
1011 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
1012 if (GET_MODE_SIZE (tmode) > MOVE_MAX_PIECES
1013 || SLOW_UNALIGNED_ACCESS (tmode, align))
1016 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
1019 while (max_size > 1)
1021 enum machine_mode mode = VOIDmode;
1022 enum insn_code icode;
1024 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1025 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1026 if (GET_MODE_SIZE (tmode) < max_size)
1029 if (mode == VOIDmode)
1032 icode = mov_optab->handlers[(int) mode].insn_code;
1033 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1034 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1036 max_size = GET_MODE_SIZE (mode);
1043 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1044 with move instructions for mode MODE. GENFUN is the gen_... function
1045 to make a move insn for that mode. DATA has all the other info. */
1048 move_by_pieces_1 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
1049 struct move_by_pieces *data)
1051 unsigned int size = GET_MODE_SIZE (mode);
1052 rtx to1 = NULL_RTX, from1;
1054 while (data->len >= size)
1057 data->offset -= size;
1061 if (data->autinc_to)
1062 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1065 to1 = adjust_address (data->to, mode, data->offset);
1068 if (data->autinc_from)
1069 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1072 from1 = adjust_address (data->from, mode, data->offset);
1074 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1075 emit_insn (gen_add2_insn (data->to_addr,
1076 GEN_INT (-(HOST_WIDE_INT)size)));
1077 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1078 emit_insn (gen_add2_insn (data->from_addr,
1079 GEN_INT (-(HOST_WIDE_INT)size)));
1082 emit_insn ((*genfun) (to1, from1));
1085 #ifdef PUSH_ROUNDING
1086 emit_single_push_insn (mode, from1, NULL);
1092 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1093 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1094 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1095 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1097 if (! data->reverse)
1098 data->offset += size;
1104 /* Emit code to move a block Y to a block X. This may be done with
1105 string-move instructions, with multiple scalar move instructions,
1106 or with a library call.
1108 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1109 SIZE is an rtx that says how long they are.
1110 ALIGN is the maximum alignment we can assume they have.
1111 METHOD describes what kind of copy this is, and what mechanisms may be used.
1113 Return the address of the new block, if memcpy is called and returns it,
1117 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1125 case BLOCK_OP_NORMAL:
1126 may_use_call = true;
1129 case BLOCK_OP_CALL_PARM:
1130 may_use_call = block_move_libcall_safe_for_call_parm ();
1132 /* Make inhibit_defer_pop nonzero around the library call
1133 to force it to pop the arguments right away. */
1137 case BLOCK_OP_NO_LIBCALL:
1138 may_use_call = false;
1145 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1147 gcc_assert (MEM_P (x));
1148 gcc_assert (MEM_P (y));
1151 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1152 block copy is more efficient for other large modes, e.g. DCmode. */
1153 x = adjust_address (x, BLKmode, 0);
1154 y = adjust_address (y, BLKmode, 0);
1156 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1157 can be incorrect is coming from __builtin_memcpy. */
1158 if (GET_CODE (size) == CONST_INT)
1160 if (INTVAL (size) == 0)
1163 x = shallow_copy_rtx (x);
1164 y = shallow_copy_rtx (y);
1165 set_mem_size (x, size);
1166 set_mem_size (y, size);
1169 if (GET_CODE (size) == CONST_INT && MOVE_BY_PIECES_P (INTVAL (size), align))
1170 move_by_pieces (x, y, INTVAL (size), align, 0);
1171 else if (emit_block_move_via_movmem (x, y, size, align))
1173 else if (may_use_call)
1174 retval = emit_block_move_via_libcall (x, y, size);
1176 emit_block_move_via_loop (x, y, size, align);
1178 if (method == BLOCK_OP_CALL_PARM)
1184 /* A subroutine of emit_block_move. Returns true if calling the
1185 block move libcall will not clobber any parameters which may have
1186 already been placed on the stack. */
1189 block_move_libcall_safe_for_call_parm (void)
1191 /* If arguments are pushed on the stack, then they're safe. */
1195 /* If registers go on the stack anyway, any argument is sure to clobber
1196 an outgoing argument. */
1197 #if defined (REG_PARM_STACK_SPACE) && defined (OUTGOING_REG_PARM_STACK_SPACE)
1199 tree fn = emit_block_move_libcall_fn (false);
1201 if (REG_PARM_STACK_SPACE (fn) != 0)
1206 /* If any argument goes in memory, then it might clobber an outgoing
1209 CUMULATIVE_ARGS args_so_far;
1212 fn = emit_block_move_libcall_fn (false);
1213 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fn), NULL_RTX, 0, 3);
1215 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1216 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1218 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1219 rtx tmp = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
1220 if (!tmp || !REG_P (tmp))
1222 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode,
1225 FUNCTION_ARG_ADVANCE (args_so_far, mode, NULL_TREE, 1);
1231 /* A subroutine of emit_block_move. Expand a movmem pattern;
1232 return true if successful. */
1235 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align)
1237 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
1238 int save_volatile_ok = volatile_ok;
1239 enum machine_mode mode;
1241 /* Since this is a move insn, we don't care about volatility. */
1244 /* Try the most limited insn first, because there's no point
1245 including more than one in the machine description unless
1246 the more limited one has some advantage. */
1248 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1249 mode = GET_MODE_WIDER_MODE (mode))
1251 enum insn_code code = movmem_optab[(int) mode];
1252 insn_operand_predicate_fn pred;
1254 if (code != CODE_FOR_nothing
1255 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1256 here because if SIZE is less than the mode mask, as it is
1257 returned by the macro, it will definitely be less than the
1258 actual mode mask. */
1259 && ((GET_CODE (size) == CONST_INT
1260 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1261 <= (GET_MODE_MASK (mode) >> 1)))
1262 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1263 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
1264 || (*pred) (x, BLKmode))
1265 && ((pred = insn_data[(int) code].operand[1].predicate) == 0
1266 || (*pred) (y, BLKmode))
1267 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
1268 || (*pred) (opalign, VOIDmode)))
1271 rtx last = get_last_insn ();
1274 op2 = convert_to_mode (mode, size, 1);
1275 pred = insn_data[(int) code].operand[2].predicate;
1276 if (pred != 0 && ! (*pred) (op2, mode))
1277 op2 = copy_to_mode_reg (mode, op2);
1279 /* ??? When called via emit_block_move_for_call, it'd be
1280 nice if there were some way to inform the backend, so
1281 that it doesn't fail the expansion because it thinks
1282 emitting the libcall would be more efficient. */
1284 pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1288 volatile_ok = save_volatile_ok;
1292 delete_insns_since (last);
1296 volatile_ok = save_volatile_ok;
1300 /* A subroutine of emit_block_move. Expand a call to memcpy.
1301 Return the return value from memcpy, 0 otherwise. */
1304 emit_block_move_via_libcall (rtx dst, rtx src, rtx size)
1306 rtx dst_addr, src_addr;
1307 tree call_expr, arg_list, fn, src_tree, dst_tree, size_tree;
1308 enum machine_mode size_mode;
1311 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1312 pseudos. We can then place those new pseudos into a VAR_DECL and
1315 dst_addr = copy_to_mode_reg (Pmode, XEXP (dst, 0));
1316 src_addr = copy_to_mode_reg (Pmode, XEXP (src, 0));
1318 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1319 src_addr = convert_memory_address (ptr_mode, src_addr);
1321 dst_tree = make_tree (ptr_type_node, dst_addr);
1322 src_tree = make_tree (ptr_type_node, src_addr);
1324 size_mode = TYPE_MODE (sizetype);
1326 size = convert_to_mode (size_mode, size, 1);
1327 size = copy_to_mode_reg (size_mode, size);
1329 /* It is incorrect to use the libcall calling conventions to call
1330 memcpy in this context. This could be a user call to memcpy and
1331 the user may wish to examine the return value from memcpy. For
1332 targets where libcalls and normal calls have different conventions
1333 for returning pointers, we could end up generating incorrect code. */
1335 size_tree = make_tree (sizetype, size);
1337 fn = emit_block_move_libcall_fn (true);
1338 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
1339 arg_list = tree_cons (NULL_TREE, src_tree, arg_list);
1340 arg_list = tree_cons (NULL_TREE, dst_tree, arg_list);
1342 /* Now we have to build up the CALL_EXPR itself. */
1343 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
1344 call_expr = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
1345 call_expr, arg_list, NULL_TREE);
1347 retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
1352 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1353 for the function we use for block copies. The first time FOR_CALL
1354 is true, we call assemble_external. */
1356 static GTY(()) tree block_move_fn;
1359 init_block_move_fn (const char *asmspec)
1365 fn = get_identifier ("memcpy");
1366 args = build_function_type_list (ptr_type_node, ptr_type_node,
1367 const_ptr_type_node, sizetype,
1370 fn = build_decl (FUNCTION_DECL, fn, args);
1371 DECL_EXTERNAL (fn) = 1;
1372 TREE_PUBLIC (fn) = 1;
1373 DECL_ARTIFICIAL (fn) = 1;
1374 TREE_NOTHROW (fn) = 1;
1380 set_user_assembler_name (block_move_fn, asmspec);
1384 emit_block_move_libcall_fn (int for_call)
1386 static bool emitted_extern;
1389 init_block_move_fn (NULL);
1391 if (for_call && !emitted_extern)
1393 emitted_extern = true;
1394 make_decl_rtl (block_move_fn);
1395 assemble_external (block_move_fn);
1398 return block_move_fn;
1401 /* A subroutine of emit_block_move. Copy the data via an explicit
1402 loop. This is used only when libcalls are forbidden. */
1403 /* ??? It'd be nice to copy in hunks larger than QImode. */
1406 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1407 unsigned int align ATTRIBUTE_UNUSED)
1409 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1410 enum machine_mode iter_mode;
1412 iter_mode = GET_MODE (size);
1413 if (iter_mode == VOIDmode)
1414 iter_mode = word_mode;
1416 top_label = gen_label_rtx ();
1417 cmp_label = gen_label_rtx ();
1418 iter = gen_reg_rtx (iter_mode);
1420 emit_move_insn (iter, const0_rtx);
1422 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1423 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1424 do_pending_stack_adjust ();
1426 emit_jump (cmp_label);
1427 emit_label (top_label);
1429 tmp = convert_modes (Pmode, iter_mode, iter, true);
1430 x_addr = gen_rtx_PLUS (Pmode, x_addr, tmp);
1431 y_addr = gen_rtx_PLUS (Pmode, y_addr, tmp);
1432 x = change_address (x, QImode, x_addr);
1433 y = change_address (y, QImode, y_addr);
1435 emit_move_insn (x, y);
1437 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1438 true, OPTAB_LIB_WIDEN);
1440 emit_move_insn (iter, tmp);
1442 emit_label (cmp_label);
1444 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1448 /* Copy all or part of a value X into registers starting at REGNO.
1449 The number of registers to be filled is NREGS. */
1452 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1455 #ifdef HAVE_load_multiple
1463 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
1464 x = validize_mem (force_const_mem (mode, x));
1466 /* See if the machine can do this with a load multiple insn. */
1467 #ifdef HAVE_load_multiple
1468 if (HAVE_load_multiple)
1470 last = get_last_insn ();
1471 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1479 delete_insns_since (last);
1483 for (i = 0; i < nregs; i++)
1484 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1485 operand_subword_force (x, i, mode));
1488 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1489 The number of registers to be filled is NREGS. */
1492 move_block_from_reg (int regno, rtx x, int nregs)
1499 /* See if the machine can do this with a store multiple insn. */
1500 #ifdef HAVE_store_multiple
1501 if (HAVE_store_multiple)
1503 rtx last = get_last_insn ();
1504 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1512 delete_insns_since (last);
1516 for (i = 0; i < nregs; i++)
1518 rtx tem = operand_subword (x, i, 1, BLKmode);
1522 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1526 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1527 ORIG, where ORIG is a non-consecutive group of registers represented by
1528 a PARALLEL. The clone is identical to the original except in that the
1529 original set of registers is replaced by a new set of pseudo registers.
1530 The new set has the same modes as the original set. */
1533 gen_group_rtx (rtx orig)
1538 gcc_assert (GET_CODE (orig) == PARALLEL);
1540 length = XVECLEN (orig, 0);
1541 tmps = alloca (sizeof (rtx) * length);
1543 /* Skip a NULL entry in first slot. */
1544 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1549 for (; i < length; i++)
1551 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1552 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1554 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1557 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1560 /* Emit code to move a block ORIG_SRC of type TYPE to a block DST,
1561 where DST is non-consecutive registers represented by a PARALLEL.
1562 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1566 emit_group_load (rtx dst, rtx orig_src, tree type ATTRIBUTE_UNUSED, int ssize)
1571 gcc_assert (GET_CODE (dst) == PARALLEL);
1573 /* Check for a NULL entry, used to indicate that the parameter goes
1574 both on the stack and in registers. */
1575 if (XEXP (XVECEXP (dst, 0, 0), 0))
1580 tmps = alloca (sizeof (rtx) * XVECLEN (dst, 0));
1582 /* Process the pieces. */
1583 for (i = start; i < XVECLEN (dst, 0); i++)
1585 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1586 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1587 unsigned int bytelen = GET_MODE_SIZE (mode);
1590 /* Handle trailing fragments that run over the size of the struct. */
1591 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1593 /* Arrange to shift the fragment to where it belongs.
1594 extract_bit_field loads to the lsb of the reg. */
1596 #ifdef BLOCK_REG_PADDING
1597 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1598 == (BYTES_BIG_ENDIAN ? upward : downward)
1603 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1604 bytelen = ssize - bytepos;
1605 gcc_assert (bytelen > 0);
1608 /* If we won't be loading directly from memory, protect the real source
1609 from strange tricks we might play; but make sure that the source can
1610 be loaded directly into the destination. */
1612 if (!MEM_P (orig_src)
1613 && (!CONSTANT_P (orig_src)
1614 || (GET_MODE (orig_src) != mode
1615 && GET_MODE (orig_src) != VOIDmode)))
1617 if (GET_MODE (orig_src) == VOIDmode)
1618 src = gen_reg_rtx (mode);
1620 src = gen_reg_rtx (GET_MODE (orig_src));
1622 emit_move_insn (src, orig_src);
1625 /* Optimize the access just a bit. */
1627 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1628 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1629 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1630 && bytelen == GET_MODE_SIZE (mode))
1632 tmps[i] = gen_reg_rtx (mode);
1633 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1635 else if (GET_CODE (src) == CONCAT)
1637 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1638 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1640 if ((bytepos == 0 && bytelen == slen0)
1641 || (bytepos != 0 && bytepos + bytelen <= slen))
1643 /* The following assumes that the concatenated objects all
1644 have the same size. In this case, a simple calculation
1645 can be used to determine the object and the bit field
1647 tmps[i] = XEXP (src, bytepos / slen0);
1648 if (! CONSTANT_P (tmps[i])
1649 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1650 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1651 (bytepos % slen0) * BITS_PER_UNIT,
1652 1, NULL_RTX, mode, mode);
1658 gcc_assert (!bytepos);
1659 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1660 emit_move_insn (mem, src);
1661 tmps[i] = adjust_address (mem, mode, 0);
1664 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1665 SIMD register, which is currently broken. While we get GCC
1666 to emit proper RTL for these cases, let's dump to memory. */
1667 else if (VECTOR_MODE_P (GET_MODE (dst))
1670 int slen = GET_MODE_SIZE (GET_MODE (src));
1673 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1674 emit_move_insn (mem, src);
1675 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1677 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1678 && XVECLEN (dst, 0) > 1)
1679 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE(dst), bytepos);
1680 else if (CONSTANT_P (src)
1681 || (REG_P (src) && GET_MODE (src) == mode))
1684 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1685 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1689 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1690 build_int_cst (NULL_TREE, shift), tmps[i], 0);
1693 /* Copy the extracted pieces into the proper (probable) hard regs. */
1694 for (i = start; i < XVECLEN (dst, 0); i++)
1695 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0), tmps[i]);
1698 /* Emit code to move a block SRC to block DST, where SRC and DST are
1699 non-consecutive groups of registers, each represented by a PARALLEL. */
1702 emit_group_move (rtx dst, rtx src)
1706 gcc_assert (GET_CODE (src) == PARALLEL
1707 && GET_CODE (dst) == PARALLEL
1708 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1710 /* Skip first entry if NULL. */
1711 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1712 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1713 XEXP (XVECEXP (src, 0, i), 0));
1716 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1717 where SRC is non-consecutive registers represented by a PARALLEL.
1718 SSIZE represents the total size of block ORIG_DST, or -1 if not
1722 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1727 gcc_assert (GET_CODE (src) == PARALLEL);
1729 /* Check for a NULL entry, used to indicate that the parameter goes
1730 both on the stack and in registers. */
1731 if (XEXP (XVECEXP (src, 0, 0), 0))
1736 tmps = alloca (sizeof (rtx) * XVECLEN (src, 0));
1738 /* Copy the (probable) hard regs into pseudos. */
1739 for (i = start; i < XVECLEN (src, 0); i++)
1741 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1742 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1743 emit_move_insn (tmps[i], reg);
1746 /* If we won't be storing directly into memory, protect the real destination
1747 from strange tricks we might play. */
1749 if (GET_CODE (dst) == PARALLEL)
1753 /* We can get a PARALLEL dst if there is a conditional expression in
1754 a return statement. In that case, the dst and src are the same,
1755 so no action is necessary. */
1756 if (rtx_equal_p (dst, src))
1759 /* It is unclear if we can ever reach here, but we may as well handle
1760 it. Allocate a temporary, and split this into a store/load to/from
1763 temp = assign_stack_temp (GET_MODE (dst), ssize, 0);
1764 emit_group_store (temp, src, type, ssize);
1765 emit_group_load (dst, temp, type, ssize);
1768 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1770 dst = gen_reg_rtx (GET_MODE (orig_dst));
1771 /* Make life a bit easier for combine. */
1772 emit_move_insn (dst, CONST0_RTX (GET_MODE (orig_dst)));
1775 /* Process the pieces. */
1776 for (i = start; i < XVECLEN (src, 0); i++)
1778 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
1779 enum machine_mode mode = GET_MODE (tmps[i]);
1780 unsigned int bytelen = GET_MODE_SIZE (mode);
1783 /* Handle trailing fragments that run over the size of the struct. */
1784 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1786 /* store_bit_field always takes its value from the lsb.
1787 Move the fragment to the lsb if it's not already there. */
1789 #ifdef BLOCK_REG_PADDING
1790 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
1791 == (BYTES_BIG_ENDIAN ? upward : downward)
1797 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1798 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
1799 build_int_cst (NULL_TREE, shift),
1802 bytelen = ssize - bytepos;
1805 if (GET_CODE (dst) == CONCAT)
1807 if (bytepos + bytelen <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
1808 dest = XEXP (dst, 0);
1809 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
1811 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
1812 dest = XEXP (dst, 1);
1816 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
1817 dest = assign_stack_temp (GET_MODE (dest),
1818 GET_MODE_SIZE (GET_MODE (dest)), 0);
1819 emit_move_insn (adjust_address (dest, GET_MODE (tmps[i]), bytepos),
1826 /* Optimize the access just a bit. */
1828 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
1829 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
1830 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1831 && bytelen == GET_MODE_SIZE (mode))
1832 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
1834 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
1838 /* Copy from the pseudo into the (probable) hard reg. */
1839 if (orig_dst != dst)
1840 emit_move_insn (orig_dst, dst);
1843 /* Generate code to copy a BLKmode object of TYPE out of a
1844 set of registers starting with SRCREG into TGTBLK. If TGTBLK
1845 is null, a stack temporary is created. TGTBLK is returned.
1847 The purpose of this routine is to handle functions that return
1848 BLKmode structures in registers. Some machines (the PA for example)
1849 want to return all small structures in registers regardless of the
1850 structure's alignment. */
1853 copy_blkmode_from_reg (rtx tgtblk, rtx srcreg, tree type)
1855 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
1856 rtx src = NULL, dst = NULL;
1857 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
1858 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
1862 tgtblk = assign_temp (build_qualified_type (type,
1864 | TYPE_QUAL_CONST)),
1866 preserve_temp_slots (tgtblk);
1869 /* This code assumes srcreg is at least a full word. If it isn't, copy it
1870 into a new pseudo which is a full word. */
1872 if (GET_MODE (srcreg) != BLKmode
1873 && GET_MODE_SIZE (GET_MODE (srcreg)) < UNITS_PER_WORD)
1874 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
1876 /* If the structure doesn't take up a whole number of words, see whether
1877 SRCREG is padded on the left or on the right. If it's on the left,
1878 set PADDING_CORRECTION to the number of bits to skip.
1880 In most ABIs, the structure will be returned at the least end of
1881 the register, which translates to right padding on little-endian
1882 targets and left padding on big-endian targets. The opposite
1883 holds if the structure is returned at the most significant
1884 end of the register. */
1885 if (bytes % UNITS_PER_WORD != 0
1886 && (targetm.calls.return_in_msb (type)
1888 : BYTES_BIG_ENDIAN))
1890 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
1892 /* Copy the structure BITSIZE bites at a time.
1894 We could probably emit more efficient code for machines which do not use
1895 strict alignment, but it doesn't seem worth the effort at the current
1897 for (bitpos = 0, xbitpos = padding_correction;
1898 bitpos < bytes * BITS_PER_UNIT;
1899 bitpos += bitsize, xbitpos += bitsize)
1901 /* We need a new source operand each time xbitpos is on a
1902 word boundary and when xbitpos == padding_correction
1903 (the first time through). */
1904 if (xbitpos % BITS_PER_WORD == 0
1905 || xbitpos == padding_correction)
1906 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD,
1909 /* We need a new destination operand each time bitpos is on
1911 if (bitpos % BITS_PER_WORD == 0)
1912 dst = operand_subword (tgtblk, bitpos / BITS_PER_WORD, 1, BLKmode);
1914 /* Use xbitpos for the source extraction (right justified) and
1915 xbitpos for the destination store (left justified). */
1916 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
1917 extract_bit_field (src, bitsize,
1918 xbitpos % BITS_PER_WORD, 1,
1919 NULL_RTX, word_mode, word_mode));
1925 /* Add a USE expression for REG to the (possibly empty) list pointed
1926 to by CALL_FUSAGE. REG must denote a hard register. */
1929 use_reg (rtx *call_fusage, rtx reg)
1931 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
1934 = gen_rtx_EXPR_LIST (VOIDmode,
1935 gen_rtx_USE (VOIDmode, reg), *call_fusage);
1938 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
1939 starting at REGNO. All of these registers must be hard registers. */
1942 use_regs (rtx *call_fusage, int regno, int nregs)
1946 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
1948 for (i = 0; i < nregs; i++)
1949 use_reg (call_fusage, regno_reg_rtx[regno + i]);
1952 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
1953 PARALLEL REGS. This is for calls that pass values in multiple
1954 non-contiguous locations. The Irix 6 ABI has examples of this. */
1957 use_group_regs (rtx *call_fusage, rtx regs)
1961 for (i = 0; i < XVECLEN (regs, 0); i++)
1963 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
1965 /* A NULL entry means the parameter goes both on the stack and in
1966 registers. This can also be a MEM for targets that pass values
1967 partially on the stack and partially in registers. */
1968 if (reg != 0 && REG_P (reg))
1969 use_reg (call_fusage, reg);
1974 /* Determine whether the LEN bytes generated by CONSTFUN can be
1975 stored to memory using several move instructions. CONSTFUNDATA is
1976 a pointer which will be passed as argument in every CONSTFUN call.
1977 ALIGN is maximum alignment we can assume. Return nonzero if a
1978 call to store_by_pieces should succeed. */
1981 can_store_by_pieces (unsigned HOST_WIDE_INT len,
1982 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
1983 void *constfundata, unsigned int align)
1985 unsigned HOST_WIDE_INT l;
1986 unsigned int max_size;
1987 HOST_WIDE_INT offset = 0;
1988 enum machine_mode mode, tmode;
1989 enum insn_code icode;
1996 if (! STORE_BY_PIECES_P (len, align))
1999 tmode = mode_for_size (STORE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
2000 if (align >= GET_MODE_ALIGNMENT (tmode))
2001 align = GET_MODE_ALIGNMENT (tmode);
2004 enum machine_mode xmode;
2006 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
2008 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
2009 if (GET_MODE_SIZE (tmode) > STORE_MAX_PIECES
2010 || SLOW_UNALIGNED_ACCESS (tmode, align))
2013 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
2016 /* We would first store what we can in the largest integer mode, then go to
2017 successively smaller modes. */
2020 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2025 max_size = STORE_MAX_PIECES + 1;
2026 while (max_size > 1)
2028 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2029 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2030 if (GET_MODE_SIZE (tmode) < max_size)
2033 if (mode == VOIDmode)
2036 icode = mov_optab->handlers[(int) mode].insn_code;
2037 if (icode != CODE_FOR_nothing
2038 && align >= GET_MODE_ALIGNMENT (mode))
2040 unsigned int size = GET_MODE_SIZE (mode);
2047 cst = (*constfun) (constfundata, offset, mode);
2048 if (!LEGITIMATE_CONSTANT_P (cst))
2058 max_size = GET_MODE_SIZE (mode);
2061 /* The code above should have handled everything. */
2068 /* Generate several move instructions to store LEN bytes generated by
2069 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2070 pointer which will be passed as argument in every CONSTFUN call.
2071 ALIGN is maximum alignment we can assume.
2072 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2073 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2077 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2078 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2079 void *constfundata, unsigned int align, int endp)
2081 struct store_by_pieces data;
2085 gcc_assert (endp != 2);
2089 gcc_assert (STORE_BY_PIECES_P (len, align));
2090 data.constfun = constfun;
2091 data.constfundata = constfundata;
2094 store_by_pieces_1 (&data, align);
2099 gcc_assert (!data.reverse);
2104 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2105 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2107 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
2110 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2117 to1 = adjust_address (data.to, QImode, data.offset);
2125 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2126 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2129 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2131 struct store_by_pieces data;
2136 data.constfun = clear_by_pieces_1;
2137 data.constfundata = NULL;
2140 store_by_pieces_1 (&data, align);
2143 /* Callback routine for clear_by_pieces.
2144 Return const0_rtx unconditionally. */
2147 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2148 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2149 enum machine_mode mode ATTRIBUTE_UNUSED)
2154 /* Subroutine of clear_by_pieces and store_by_pieces.
2155 Generate several move instructions to store LEN bytes of block TO. (A MEM
2156 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2159 store_by_pieces_1 (struct store_by_pieces *data ATTRIBUTE_UNUSED,
2160 unsigned int align ATTRIBUTE_UNUSED)
2162 rtx to_addr = XEXP (data->to, 0);
2163 unsigned int max_size = STORE_MAX_PIECES + 1;
2164 enum machine_mode mode = VOIDmode, tmode;
2165 enum insn_code icode;
2168 data->to_addr = to_addr;
2170 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2171 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2173 data->explicit_inc_to = 0;
2175 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2177 data->offset = data->len;
2179 /* If storing requires more than two move insns,
2180 copy addresses to registers (to make displacements shorter)
2181 and use post-increment if available. */
2182 if (!data->autinc_to
2183 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2185 /* Determine the main mode we'll be using. */
2186 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2187 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2188 if (GET_MODE_SIZE (tmode) < max_size)
2191 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2193 data->to_addr = copy_addr_to_reg (plus_constant (to_addr, data->len));
2194 data->autinc_to = 1;
2195 data->explicit_inc_to = -1;
2198 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2199 && ! data->autinc_to)
2201 data->to_addr = copy_addr_to_reg (to_addr);
2202 data->autinc_to = 1;
2203 data->explicit_inc_to = 1;
2206 if ( !data->autinc_to && CONSTANT_P (to_addr))
2207 data->to_addr = copy_addr_to_reg (to_addr);
2210 tmode = mode_for_size (STORE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
2211 if (align >= GET_MODE_ALIGNMENT (tmode))
2212 align = GET_MODE_ALIGNMENT (tmode);
2215 enum machine_mode xmode;
2217 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
2219 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
2220 if (GET_MODE_SIZE (tmode) > STORE_MAX_PIECES
2221 || SLOW_UNALIGNED_ACCESS (tmode, align))
2224 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
2227 /* First store what we can in the largest integer mode, then go to
2228 successively smaller modes. */
2230 while (max_size > 1)
2232 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2233 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2234 if (GET_MODE_SIZE (tmode) < max_size)
2237 if (mode == VOIDmode)
2240 icode = mov_optab->handlers[(int) mode].insn_code;
2241 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2242 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2244 max_size = GET_MODE_SIZE (mode);
2247 /* The code above should have handled everything. */
2248 gcc_assert (!data->len);
2251 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2252 with move instructions for mode MODE. GENFUN is the gen_... function
2253 to make a move insn for that mode. DATA has all the other info. */
2256 store_by_pieces_2 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
2257 struct store_by_pieces *data)
2259 unsigned int size = GET_MODE_SIZE (mode);
2262 while (data->len >= size)
2265 data->offset -= size;
2267 if (data->autinc_to)
2268 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2271 to1 = adjust_address (data->to, mode, data->offset);
2273 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2274 emit_insn (gen_add2_insn (data->to_addr,
2275 GEN_INT (-(HOST_WIDE_INT) size)));
2277 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2278 emit_insn ((*genfun) (to1, cst));
2280 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2281 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2283 if (! data->reverse)
2284 data->offset += size;
2290 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2291 its length in bytes. */
2294 clear_storage (rtx object, rtx size)
2297 unsigned int align = (MEM_P (object) ? MEM_ALIGN (object)
2298 : GET_MODE_ALIGNMENT (GET_MODE (object)));
2300 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2301 just move a zero. Otherwise, do this a piece at a time. */
2302 if (GET_MODE (object) != BLKmode
2303 && GET_CODE (size) == CONST_INT
2304 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (object)))
2305 emit_move_insn (object, CONST0_RTX (GET_MODE (object)));
2308 if (size == const0_rtx)
2310 else if (GET_CODE (size) == CONST_INT
2311 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2312 clear_by_pieces (object, INTVAL (size), align);
2313 else if (clear_storage_via_clrmem (object, size, align))
2316 retval = clear_storage_via_libcall (object, size);
2322 /* A subroutine of clear_storage. Expand a clrmem pattern;
2323 return true if successful. */
2326 clear_storage_via_clrmem (rtx object, rtx size, unsigned int align)
2328 /* Try the most limited insn first, because there's no point
2329 including more than one in the machine description unless
2330 the more limited one has some advantage. */
2332 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
2333 enum machine_mode mode;
2335 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2336 mode = GET_MODE_WIDER_MODE (mode))
2338 enum insn_code code = clrmem_optab[(int) mode];
2339 insn_operand_predicate_fn pred;
2341 if (code != CODE_FOR_nothing
2342 /* We don't need MODE to be narrower than
2343 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2344 the mode mask, as it is returned by the macro, it will
2345 definitely be less than the actual mode mask. */
2346 && ((GET_CODE (size) == CONST_INT
2347 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2348 <= (GET_MODE_MASK (mode) >> 1)))
2349 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2350 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
2351 || (*pred) (object, BLKmode))
2352 && ((pred = insn_data[(int) code].operand[2].predicate) == 0
2353 || (*pred) (opalign, VOIDmode)))
2356 rtx last = get_last_insn ();
2359 op1 = convert_to_mode (mode, size, 1);
2360 pred = insn_data[(int) code].operand[1].predicate;
2361 if (pred != 0 && ! (*pred) (op1, mode))
2362 op1 = copy_to_mode_reg (mode, op1);
2364 pat = GEN_FCN ((int) code) (object, op1, opalign);
2371 delete_insns_since (last);
2378 /* A subroutine of clear_storage. Expand a call to memset.
2379 Return the return value of memset, 0 otherwise. */
2382 clear_storage_via_libcall (rtx object, rtx size)
2384 tree call_expr, arg_list, fn, object_tree, size_tree;
2385 enum machine_mode size_mode;
2388 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2389 place those into new pseudos into a VAR_DECL and use them later. */
2391 object = copy_to_mode_reg (Pmode, XEXP (object, 0));
2393 size_mode = TYPE_MODE (sizetype);
2394 size = convert_to_mode (size_mode, size, 1);
2395 size = copy_to_mode_reg (size_mode, size);
2397 /* It is incorrect to use the libcall calling conventions to call
2398 memset in this context. This could be a user call to memset and
2399 the user may wish to examine the return value from memset. For
2400 targets where libcalls and normal calls have different conventions
2401 for returning pointers, we could end up generating incorrect code. */
2403 object_tree = make_tree (ptr_type_node, object);
2404 size_tree = make_tree (sizetype, size);
2406 fn = clear_storage_libcall_fn (true);
2407 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
2408 arg_list = tree_cons (NULL_TREE, integer_zero_node, arg_list);
2409 arg_list = tree_cons (NULL_TREE, object_tree, arg_list);
2411 /* Now we have to build up the CALL_EXPR itself. */
2412 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
2413 call_expr = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
2414 call_expr, arg_list, NULL_TREE);
2416 retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
2421 /* A subroutine of clear_storage_via_libcall. Create the tree node
2422 for the function we use for block clears. The first time FOR_CALL
2423 is true, we call assemble_external. */
2425 static GTY(()) tree block_clear_fn;
2428 init_block_clear_fn (const char *asmspec)
2430 if (!block_clear_fn)
2434 fn = get_identifier ("memset");
2435 args = build_function_type_list (ptr_type_node, ptr_type_node,
2436 integer_type_node, sizetype,
2439 fn = build_decl (FUNCTION_DECL, fn, args);
2440 DECL_EXTERNAL (fn) = 1;
2441 TREE_PUBLIC (fn) = 1;
2442 DECL_ARTIFICIAL (fn) = 1;
2443 TREE_NOTHROW (fn) = 1;
2445 block_clear_fn = fn;
2449 set_user_assembler_name (block_clear_fn, asmspec);
2453 clear_storage_libcall_fn (int for_call)
2455 static bool emitted_extern;
2457 if (!block_clear_fn)
2458 init_block_clear_fn (NULL);
2460 if (for_call && !emitted_extern)
2462 emitted_extern = true;
2463 make_decl_rtl (block_clear_fn);
2464 assemble_external (block_clear_fn);
2467 return block_clear_fn;
2470 /* Generate code to copy Y into X.
2471 Both Y and X must have the same mode, except that
2472 Y can be a constant with VOIDmode.
2473 This mode cannot be BLKmode; use emit_block_move for that.
2475 Return the last instruction emitted. */
2478 emit_move_insn (rtx x, rtx y)
2480 enum machine_mode mode = GET_MODE (x);
2481 rtx y_cst = NULL_RTX;
2484 gcc_assert (mode != BLKmode
2485 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
2490 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
2491 && (last_insn = compress_float_constant (x, y)))
2496 if (!LEGITIMATE_CONSTANT_P (y))
2498 y = force_const_mem (mode, y);
2500 /* If the target's cannot_force_const_mem prevented the spill,
2501 assume that the target's move expanders will also take care
2502 of the non-legitimate constant. */
2508 /* If X or Y are memory references, verify that their addresses are valid
2511 && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
2512 && ! push_operand (x, GET_MODE (x)))
2514 && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
2515 x = validize_mem (x);
2518 && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
2520 && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
2521 y = validize_mem (y);
2523 gcc_assert (mode != BLKmode);
2525 last_insn = emit_move_insn_1 (x, y);
2527 if (y_cst && REG_P (x)
2528 && (set = single_set (last_insn)) != NULL_RTX
2529 && SET_DEST (set) == x
2530 && ! rtx_equal_p (y_cst, SET_SRC (set)))
2531 set_unique_reg_note (last_insn, REG_EQUAL, y_cst);
2536 /* Low level part of emit_move_insn.
2537 Called just like emit_move_insn, but assumes X and Y
2538 are basically valid. */
2541 emit_move_insn_1 (rtx x, rtx y)
2543 enum machine_mode mode = GET_MODE (x);
2544 enum machine_mode submode;
2545 enum mode_class class = GET_MODE_CLASS (mode);
2547 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
2549 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2551 emit_insn (GEN_FCN (mov_optab->handlers[(int) mode].insn_code) (x, y));
2553 /* Expand complex moves by moving real part and imag part, if possible. */
2554 else if ((class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
2555 && BLKmode != (submode = GET_MODE_INNER (mode))
2556 && (mov_optab->handlers[(int) submode].insn_code
2557 != CODE_FOR_nothing))
2559 /* Don't split destination if it is a stack push. */
2560 int stack = push_operand (x, GET_MODE (x));
2562 #ifdef PUSH_ROUNDING
2563 /* In case we output to the stack, but the size is smaller than the
2564 machine can push exactly, we need to use move instructions. */
2566 && (PUSH_ROUNDING (GET_MODE_SIZE (submode))
2567 != GET_MODE_SIZE (submode)))
2570 HOST_WIDE_INT offset1, offset2;
2572 /* Do not use anti_adjust_stack, since we don't want to update
2573 stack_pointer_delta. */
2574 temp = expand_binop (Pmode,
2575 #ifdef STACK_GROWS_DOWNWARD
2583 (GET_MODE_SIZE (GET_MODE (x)))),
2584 stack_pointer_rtx, 0, OPTAB_LIB_WIDEN);
2586 if (temp != stack_pointer_rtx)
2587 emit_move_insn (stack_pointer_rtx, temp);
2589 #ifdef STACK_GROWS_DOWNWARD
2591 offset2 = GET_MODE_SIZE (submode);
2593 offset1 = -PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (x)));
2594 offset2 = (-PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (x)))
2595 + GET_MODE_SIZE (submode));
2598 emit_move_insn (change_address (x, submode,
2599 gen_rtx_PLUS (Pmode,
2601 GEN_INT (offset1))),
2602 gen_realpart (submode, y));
2603 emit_move_insn (change_address (x, submode,
2604 gen_rtx_PLUS (Pmode,
2606 GEN_INT (offset2))),
2607 gen_imagpart (submode, y));
2611 /* If this is a stack, push the highpart first, so it
2612 will be in the argument order.
2614 In that case, change_address is used only to convert
2615 the mode, not to change the address. */
2618 /* Note that the real part always precedes the imag part in memory
2619 regardless of machine's endianness. */
2620 #ifdef STACK_GROWS_DOWNWARD
2621 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2622 gen_imagpart (submode, y));
2623 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2624 gen_realpart (submode, y));
2626 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2627 gen_realpart (submode, y));
2628 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2629 gen_imagpart (submode, y));
2634 rtx realpart_x, realpart_y;
2635 rtx imagpart_x, imagpart_y;
2637 /* If this is a complex value with each part being smaller than a
2638 word, the usual calling sequence will likely pack the pieces into
2639 a single register. Unfortunately, SUBREG of hard registers only
2640 deals in terms of words, so we have a problem converting input
2641 arguments to the CONCAT of two registers that is used elsewhere
2642 for complex values. If this is before reload, we can copy it into
2643 memory and reload. FIXME, we should see about using extract and
2644 insert on integer registers, but complex short and complex char
2645 variables should be rarely used. */
2646 if (GET_MODE_BITSIZE (mode) < 2 * BITS_PER_WORD
2647 && (reload_in_progress | reload_completed) == 0)
2650 = (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER);
2652 = (REG_P (y) && REGNO (y) < FIRST_PSEUDO_REGISTER);
2654 if (packed_dest_p || packed_src_p)
2656 enum mode_class reg_class = ((class == MODE_COMPLEX_FLOAT)
2657 ? MODE_FLOAT : MODE_INT);
2659 enum machine_mode reg_mode
2660 = mode_for_size (GET_MODE_BITSIZE (mode), reg_class, 1);
2662 if (reg_mode != BLKmode)
2664 rtx mem = assign_stack_temp (reg_mode,
2665 GET_MODE_SIZE (mode), 0);
2666 rtx cmem = adjust_address (mem, mode, 0);
2670 rtx sreg = gen_rtx_SUBREG (reg_mode, x, 0);
2672 emit_move_insn_1 (cmem, y);
2673 return emit_move_insn_1 (sreg, mem);
2677 rtx sreg = gen_rtx_SUBREG (reg_mode, y, 0);
2679 emit_move_insn_1 (mem, sreg);
2680 return emit_move_insn_1 (x, cmem);
2686 realpart_x = gen_realpart (submode, x);
2687 realpart_y = gen_realpart (submode, y);
2688 imagpart_x = gen_imagpart (submode, x);
2689 imagpart_y = gen_imagpart (submode, y);
2691 /* Show the output dies here. This is necessary for SUBREGs
2692 of pseudos since we cannot track their lifetimes correctly;
2693 hard regs shouldn't appear here except as return values.
2694 We never want to emit such a clobber after reload. */
2696 && ! (reload_in_progress || reload_completed)
2697 && (GET_CODE (realpart_x) == SUBREG
2698 || GET_CODE (imagpart_x) == SUBREG))
2699 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
2701 emit_move_insn (realpart_x, realpart_y);
2702 emit_move_insn (imagpart_x, imagpart_y);
2705 return get_last_insn ();
2708 /* Handle MODE_CC modes: If we don't have a special move insn for this mode,
2709 find a mode to do it in. If we have a movcc, use it. Otherwise,
2710 find the MODE_INT mode of the same width. */
2711 else if (GET_MODE_CLASS (mode) == MODE_CC
2712 && mov_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
2714 enum insn_code insn_code;
2715 enum machine_mode tmode = VOIDmode;
2719 && mov_optab->handlers[(int) CCmode].insn_code != CODE_FOR_nothing)
2722 for (tmode = QImode; tmode != VOIDmode;
2723 tmode = GET_MODE_WIDER_MODE (tmode))
2724 if (GET_MODE_SIZE (tmode) == GET_MODE_SIZE (mode))
2727 gcc_assert (tmode != VOIDmode);
2729 /* Get X and Y in TMODE. We can't use gen_lowpart here because it
2730 may call change_address which is not appropriate if we were
2731 called when a reload was in progress. We don't have to worry
2732 about changing the address since the size in bytes is supposed to
2733 be the same. Copy the MEM to change the mode and move any
2734 substitutions from the old MEM to the new one. */
2736 if (reload_in_progress)
2738 x = gen_lowpart_common (tmode, x1);
2739 if (x == 0 && MEM_P (x1))
2741 x = adjust_address_nv (x1, tmode, 0);
2742 copy_replacements (x1, x);
2745 y = gen_lowpart_common (tmode, y1);
2746 if (y == 0 && MEM_P (y1))
2748 y = adjust_address_nv (y1, tmode, 0);
2749 copy_replacements (y1, y);
2754 x = gen_lowpart (tmode, x);
2755 y = gen_lowpart (tmode, y);
2758 insn_code = mov_optab->handlers[(int) tmode].insn_code;
2759 return emit_insn (GEN_FCN (insn_code) (x, y));
2762 /* Try using a move pattern for the corresponding integer mode. This is
2763 only safe when simplify_subreg can convert MODE constants into integer
2764 constants. At present, it can only do this reliably if the value
2765 fits within a HOST_WIDE_INT. */
2766 else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2767 && (submode = int_mode_for_mode (mode)) != BLKmode
2768 && mov_optab->handlers[submode].insn_code != CODE_FOR_nothing)
2769 return emit_insn (GEN_FCN (mov_optab->handlers[submode].insn_code)
2770 (simplify_gen_subreg (submode, x, mode, 0),
2771 simplify_gen_subreg (submode, y, mode, 0)));
2773 /* This will handle any multi-word or full-word mode that lacks a move_insn
2774 pattern. However, you will get better code if you define such patterns,
2775 even if they must turn into multiple assembler instructions. */
2783 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
2785 #ifdef PUSH_ROUNDING
2787 /* If X is a push on the stack, do the push now and replace
2788 X with a reference to the stack pointer. */
2789 if (push_operand (x, GET_MODE (x)))
2794 /* Do not use anti_adjust_stack, since we don't want to update
2795 stack_pointer_delta. */
2796 temp = expand_binop (Pmode,
2797 #ifdef STACK_GROWS_DOWNWARD
2805 (GET_MODE_SIZE (GET_MODE (x)))),
2806 stack_pointer_rtx, 0, OPTAB_LIB_WIDEN);
2808 if (temp != stack_pointer_rtx)
2809 emit_move_insn (stack_pointer_rtx, temp);
2811 code = GET_CODE (XEXP (x, 0));
2813 /* Just hope that small offsets off SP are OK. */
2814 if (code == POST_INC)
2815 temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
2816 GEN_INT (-((HOST_WIDE_INT)
2817 GET_MODE_SIZE (GET_MODE (x)))));
2818 else if (code == POST_DEC)
2819 temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
2820 GEN_INT (GET_MODE_SIZE (GET_MODE (x))));
2822 temp = stack_pointer_rtx;
2824 x = change_address (x, VOIDmode, temp);
2828 /* If we are in reload, see if either operand is a MEM whose address
2829 is scheduled for replacement. */
2830 if (reload_in_progress && MEM_P (x)
2831 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
2832 x = replace_equiv_address_nv (x, inner);
2833 if (reload_in_progress && MEM_P (y)
2834 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
2835 y = replace_equiv_address_nv (y, inner);
2841 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2844 rtx xpart = operand_subword (x, i, 1, mode);
2845 rtx ypart = operand_subword (y, i, 1, mode);
2847 /* If we can't get a part of Y, put Y into memory if it is a
2848 constant. Otherwise, force it into a register. If we still
2849 can't get a part of Y, abort. */
2850 if (ypart == 0 && CONSTANT_P (y))
2852 y = force_const_mem (mode, y);
2853 ypart = operand_subword (y, i, 1, mode);
2855 else if (ypart == 0)
2856 ypart = operand_subword_force (y, i, mode);
2858 gcc_assert (xpart && ypart);
2860 need_clobber |= (GET_CODE (xpart) == SUBREG);
2862 last_insn = emit_move_insn (xpart, ypart);
2868 /* Show the output dies here. This is necessary for SUBREGs
2869 of pseudos since we cannot track their lifetimes correctly;
2870 hard regs shouldn't appear here except as return values.
2871 We never want to emit such a clobber after reload. */
2873 && ! (reload_in_progress || reload_completed)
2874 && need_clobber != 0)
2875 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
2883 /* If Y is representable exactly in a narrower mode, and the target can
2884 perform the extension directly from constant or memory, then emit the
2885 move as an extension. */
2888 compress_float_constant (rtx x, rtx y)
2890 enum machine_mode dstmode = GET_MODE (x);
2891 enum machine_mode orig_srcmode = GET_MODE (y);
2892 enum machine_mode srcmode;
2895 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
2897 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
2898 srcmode != orig_srcmode;
2899 srcmode = GET_MODE_WIDER_MODE (srcmode))
2902 rtx trunc_y, last_insn;
2904 /* Skip if the target can't extend this way. */
2905 ic = can_extend_p (dstmode, srcmode, 0);
2906 if (ic == CODE_FOR_nothing)
2909 /* Skip if the narrowed value isn't exact. */
2910 if (! exact_real_truncate (srcmode, &r))
2913 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
2915 if (LEGITIMATE_CONSTANT_P (trunc_y))
2917 /* Skip if the target needs extra instructions to perform
2919 if (! (*insn_data[ic].operand[1].predicate) (trunc_y, srcmode))
2922 else if (float_extend_from_mem[dstmode][srcmode])
2923 trunc_y = validize_mem (force_const_mem (srcmode, trunc_y));
2927 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
2928 last_insn = get_last_insn ();
2931 set_unique_reg_note (last_insn, REG_EQUAL, y);
2939 /* Pushing data onto the stack. */
2941 /* Push a block of length SIZE (perhaps variable)
2942 and return an rtx to address the beginning of the block.
2943 The value may be virtual_outgoing_args_rtx.
2945 EXTRA is the number of bytes of padding to push in addition to SIZE.
2946 BELOW nonzero means this padding comes at low addresses;
2947 otherwise, the padding comes at high addresses. */
2950 push_block (rtx size, int extra, int below)
2954 size = convert_modes (Pmode, ptr_mode, size, 1);
2955 if (CONSTANT_P (size))
2956 anti_adjust_stack (plus_constant (size, extra));
2957 else if (REG_P (size) && extra == 0)
2958 anti_adjust_stack (size);
2961 temp = copy_to_mode_reg (Pmode, size);
2963 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
2964 temp, 0, OPTAB_LIB_WIDEN);
2965 anti_adjust_stack (temp);
2968 #ifndef STACK_GROWS_DOWNWARD
2974 temp = virtual_outgoing_args_rtx;
2975 if (extra != 0 && below)
2976 temp = plus_constant (temp, extra);
2980 if (GET_CODE (size) == CONST_INT)
2981 temp = plus_constant (virtual_outgoing_args_rtx,
2982 -INTVAL (size) - (below ? 0 : extra));
2983 else if (extra != 0 && !below)
2984 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
2985 negate_rtx (Pmode, plus_constant (size, extra)));
2987 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
2988 negate_rtx (Pmode, size));
2991 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
2994 #ifdef PUSH_ROUNDING
2996 /* Emit single push insn. */
2999 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
3002 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3004 enum insn_code icode;
3005 insn_operand_predicate_fn pred;
3007 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3008 /* If there is push pattern, use it. Otherwise try old way of throwing
3009 MEM representing push operation to move expander. */
3010 icode = push_optab->handlers[(int) mode].insn_code;
3011 if (icode != CODE_FOR_nothing)
3013 if (((pred = insn_data[(int) icode].operand[0].predicate)
3014 && !((*pred) (x, mode))))
3015 x = force_reg (mode, x);
3016 emit_insn (GEN_FCN (icode) (x));
3019 if (GET_MODE_SIZE (mode) == rounded_size)
3020 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3021 /* If we are to pad downward, adjust the stack pointer first and
3022 then store X into the stack location using an offset. This is
3023 because emit_move_insn does not know how to pad; it does not have
3025 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3027 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3028 HOST_WIDE_INT offset;
3030 emit_move_insn (stack_pointer_rtx,
3031 expand_binop (Pmode,
3032 #ifdef STACK_GROWS_DOWNWARD
3038 GEN_INT (rounded_size),
3039 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3041 offset = (HOST_WIDE_INT) padding_size;
3042 #ifdef STACK_GROWS_DOWNWARD
3043 if (STACK_PUSH_CODE == POST_DEC)
3044 /* We have already decremented the stack pointer, so get the
3046 offset += (HOST_WIDE_INT) rounded_size;
3048 if (STACK_PUSH_CODE == POST_INC)
3049 /* We have already incremented the stack pointer, so get the
3051 offset -= (HOST_WIDE_INT) rounded_size;
3053 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3057 #ifdef STACK_GROWS_DOWNWARD
3058 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3059 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3060 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3062 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3063 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3064 GEN_INT (rounded_size));
3066 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3069 dest = gen_rtx_MEM (mode, dest_addr);
3073 set_mem_attributes (dest, type, 1);
3075 if (flag_optimize_sibling_calls)
3076 /* Function incoming arguments may overlap with sibling call
3077 outgoing arguments and we cannot allow reordering of reads
3078 from function arguments with stores to outgoing arguments
3079 of sibling calls. */
3080 set_mem_alias_set (dest, 0);
3082 emit_move_insn (dest, x);
3086 /* Generate code to push X onto the stack, assuming it has mode MODE and
3088 MODE is redundant except when X is a CONST_INT (since they don't
3090 SIZE is an rtx for the size of data to be copied (in bytes),
3091 needed only if X is BLKmode.
3093 ALIGN (in bits) is maximum alignment we can assume.
3095 If PARTIAL and REG are both nonzero, then copy that many of the first
3096 words of X into registers starting with REG, and push the rest of X.
3097 The amount of space pushed is decreased by PARTIAL words,
3098 rounded *down* to a multiple of PARM_BOUNDARY.
3099 REG must be a hard register in this case.
3100 If REG is zero but PARTIAL is not, take any all others actions for an
3101 argument partially in registers, but do not actually load any
3104 EXTRA is the amount in bytes of extra space to leave next to this arg.
3105 This is ignored if an argument block has already been allocated.
3107 On a machine that lacks real push insns, ARGS_ADDR is the address of
3108 the bottom of the argument block for this call. We use indexing off there
3109 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3110 argument block has not been preallocated.
3112 ARGS_SO_FAR is the size of args previously pushed for this call.
3114 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3115 for arguments passed in registers. If nonzero, it will be the number
3116 of bytes required. */
3119 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
3120 unsigned int align, int partial, rtx reg, int extra,
3121 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
3125 enum direction stack_direction
3126 #ifdef STACK_GROWS_DOWNWARD
3132 /* Decide where to pad the argument: `downward' for below,
3133 `upward' for above, or `none' for don't pad it.
3134 Default is below for small data on big-endian machines; else above. */
3135 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
3137 /* Invert direction if stack is post-decrement.
3139 if (STACK_PUSH_CODE == POST_DEC)
3140 if (where_pad != none)
3141 where_pad = (where_pad == downward ? upward : downward);
3145 if (mode == BLKmode)
3147 /* Copy a block into the stack, entirely or partially. */
3150 int used = partial * UNITS_PER_WORD;
3154 if (reg && GET_CODE (reg) == PARALLEL)
3156 /* Use the size of the elt to compute offset. */
3157 rtx elt = XEXP (XVECEXP (reg, 0, 0), 0);
3158 used = partial * GET_MODE_SIZE (GET_MODE (elt));
3159 offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
3162 offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
3168 /* USED is now the # of bytes we need not copy to the stack
3169 because registers will take care of them. */
3172 xinner = adjust_address (xinner, BLKmode, used);
3174 /* If the partial register-part of the arg counts in its stack size,
3175 skip the part of stack space corresponding to the registers.
3176 Otherwise, start copying to the beginning of the stack space,
3177 by setting SKIP to 0. */
3178 skip = (reg_parm_stack_space == 0) ? 0 : used;
3180 #ifdef PUSH_ROUNDING
3181 /* Do it with several push insns if that doesn't take lots of insns
3182 and if there is no difficulty with push insns that skip bytes
3183 on the stack for alignment purposes. */
3186 && GET_CODE (size) == CONST_INT
3188 && MEM_ALIGN (xinner) >= align
3189 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
3190 /* Here we avoid the case of a structure whose weak alignment
3191 forces many pushes of a small amount of data,
3192 and such small pushes do rounding that causes trouble. */
3193 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
3194 || align >= BIGGEST_ALIGNMENT
3195 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
3196 == (align / BITS_PER_UNIT)))
3197 && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
3199 /* Push padding now if padding above and stack grows down,
3200 or if padding below and stack grows up.
3201 But if space already allocated, this has already been done. */
3202 if (extra && args_addr == 0
3203 && where_pad != none && where_pad != stack_direction)
3204 anti_adjust_stack (GEN_INT (extra));
3206 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
3209 #endif /* PUSH_ROUNDING */
3213 /* Otherwise make space on the stack and copy the data
3214 to the address of that space. */
3216 /* Deduct words put into registers from the size we must copy. */
3219 if (GET_CODE (size) == CONST_INT)
3220 size = GEN_INT (INTVAL (size) - used);
3222 size = expand_binop (GET_MODE (size), sub_optab, size,
3223 GEN_INT (used), NULL_RTX, 0,
3227 /* Get the address of the stack space.
3228 In this case, we do not deal with EXTRA separately.
3229 A single stack adjust will do. */
3232 temp = push_block (size, extra, where_pad == downward);
3235 else if (GET_CODE (args_so_far) == CONST_INT)
3236 temp = memory_address (BLKmode,
3237 plus_constant (args_addr,
3238 skip + INTVAL (args_so_far)));
3240 temp = memory_address (BLKmode,
3241 plus_constant (gen_rtx_PLUS (Pmode,
3246 if (!ACCUMULATE_OUTGOING_ARGS)
3248 /* If the source is referenced relative to the stack pointer,
3249 copy it to another register to stabilize it. We do not need
3250 to do this if we know that we won't be changing sp. */
3252 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
3253 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
3254 temp = copy_to_reg (temp);
3257 target = gen_rtx_MEM (BLKmode, temp);
3259 /* We do *not* set_mem_attributes here, because incoming arguments
3260 may overlap with sibling call outgoing arguments and we cannot
3261 allow reordering of reads from function arguments with stores
3262 to outgoing arguments of sibling calls. We do, however, want
3263 to record the alignment of the stack slot. */
3264 /* ALIGN may well be better aligned than TYPE, e.g. due to
3265 PARM_BOUNDARY. Assume the caller isn't lying. */
3266 set_mem_align (target, align);
3268 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
3271 else if (partial > 0)
3273 /* Scalar partly in registers. */
3275 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
3278 /* # words of start of argument
3279 that we must make space for but need not store. */
3280 int offset = partial % (PARM_BOUNDARY / BITS_PER_WORD);
3281 int args_offset = INTVAL (args_so_far);
3284 /* Push padding now if padding above and stack grows down,
3285 or if padding below and stack grows up.
3286 But if space already allocated, this has already been done. */
3287 if (extra && args_addr == 0
3288 && where_pad != none && where_pad != stack_direction)
3289 anti_adjust_stack (GEN_INT (extra));
3291 /* If we make space by pushing it, we might as well push
3292 the real data. Otherwise, we can leave OFFSET nonzero
3293 and leave the space uninitialized. */
3297 /* Now NOT_STACK gets the number of words that we don't need to
3298 allocate on the stack. */
3299 not_stack = partial - offset;
3301 /* If the partial register-part of the arg counts in its stack size,
3302 skip the part of stack space corresponding to the registers.
3303 Otherwise, start copying to the beginning of the stack space,
3304 by setting SKIP to 0. */
3305 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
3307 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
3308 x = validize_mem (force_const_mem (mode, x));
3310 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
3311 SUBREGs of such registers are not allowed. */
3312 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
3313 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
3314 x = copy_to_reg (x);
3316 /* Loop over all the words allocated on the stack for this arg. */
3317 /* We can do it by words, because any scalar bigger than a word
3318 has a size a multiple of a word. */
3319 #ifndef PUSH_ARGS_REVERSED
3320 for (i = not_stack; i < size; i++)
3322 for (i = size - 1; i >= not_stack; i--)
3324 if (i >= not_stack + offset)
3325 emit_push_insn (operand_subword_force (x, i, mode),
3326 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
3328 GEN_INT (args_offset + ((i - not_stack + skip)
3330 reg_parm_stack_space, alignment_pad);
3337 /* Push padding now if padding above and stack grows down,
3338 or if padding below and stack grows up.
3339 But if space already allocated, this has already been done. */
3340 if (extra && args_addr == 0
3341 && where_pad != none && where_pad != stack_direction)
3342 anti_adjust_stack (GEN_INT (extra));
3344 #ifdef PUSH_ROUNDING
3345 if (args_addr == 0 && PUSH_ARGS)
3346 emit_single_push_insn (mode, x, type);
3350 if (GET_CODE (args_so_far) == CONST_INT)
3352 = memory_address (mode,
3353 plus_constant (args_addr,
3354 INTVAL (args_so_far)));
3356 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
3358 dest = gen_rtx_MEM (mode, addr);
3360 /* We do *not* set_mem_attributes here, because incoming arguments
3361 may overlap with sibling call outgoing arguments and we cannot
3362 allow reordering of reads from function arguments with stores
3363 to outgoing arguments of sibling calls. We do, however, want
3364 to record the alignment of the stack slot. */
3365 /* ALIGN may well be better aligned than TYPE, e.g. due to
3366 PARM_BOUNDARY. Assume the caller isn't lying. */
3367 set_mem_align (dest, align);
3369 emit_move_insn (dest, x);
3373 /* If part should go in registers, copy that part
3374 into the appropriate registers. Do this now, at the end,
3375 since mem-to-mem copies above may do function calls. */
3376 if (partial > 0 && reg != 0)
3378 /* Handle calls that pass values in multiple non-contiguous locations.
3379 The Irix 6 ABI has examples of this. */
3380 if (GET_CODE (reg) == PARALLEL)
3381 emit_group_load (reg, x, type, -1);
3383 move_block_to_reg (REGNO (reg), x, partial, mode);
3386 if (extra && args_addr == 0 && where_pad == stack_direction)
3387 anti_adjust_stack (GEN_INT (extra));
3389 if (alignment_pad && args_addr == 0)
3390 anti_adjust_stack (alignment_pad);
3393 /* Return X if X can be used as a subtarget in a sequence of arithmetic
3397 get_subtarget (rtx x)
3401 /* Only registers can be subtargets. */
3403 /* Don't use hard regs to avoid extending their life. */
3404 || REGNO (x) < FIRST_PSEUDO_REGISTER
3408 /* Expand an assignment that stores the value of FROM into TO.
3409 If WANT_VALUE is nonzero, return an rtx for the value of TO.
3410 (If the value is constant, this rtx is a constant.)
3411 Otherwise, the returned value is NULL_RTX. */
3414 expand_assignment (tree to, tree from, int want_value)
3419 /* Don't crash if the lhs of the assignment was erroneous. */
3421 if (TREE_CODE (to) == ERROR_MARK)
3423 result = expand_expr (from, NULL_RTX, VOIDmode, 0);
3424 return want_value ? result : NULL_RTX;
3427 /* Assignment of a structure component needs special treatment
3428 if the structure component's rtx is not simply a MEM.
3429 Assignment of an array element at a constant index, and assignment of
3430 an array element in an unaligned packed structure field, has the same
3433 if (TREE_CODE (to) == COMPONENT_REF || TREE_CODE (to) == BIT_FIELD_REF
3434 || TREE_CODE (to) == ARRAY_REF || TREE_CODE (to) == ARRAY_RANGE_REF
3435 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
3437 enum machine_mode mode1;
3438 HOST_WIDE_INT bitsize, bitpos;
3446 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
3447 &unsignedp, &volatilep);
3449 /* If we are going to use store_bit_field and extract_bit_field,
3450 make sure to_rtx will be safe for multiple use. */
3452 if (mode1 == VOIDmode && want_value)
3453 tem = stabilize_reference (tem);
3455 orig_to_rtx = to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, 0);
3459 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
3461 gcc_assert (MEM_P (to_rtx));
3463 #ifdef POINTERS_EXTEND_UNSIGNED
3464 if (GET_MODE (offset_rtx) != Pmode)
3465 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
3467 if (GET_MODE (offset_rtx) != ptr_mode)
3468 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
3471 /* A constant address in TO_RTX can have VOIDmode, we must not try
3472 to call force_reg for that case. Avoid that case. */
3474 && GET_MODE (to_rtx) == BLKmode
3475 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
3477 && (bitpos % bitsize) == 0
3478 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
3479 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
3481 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
3485 to_rtx = offset_address (to_rtx, offset_rtx,
3486 highest_pow2_factor_for_target (to,
3492 /* If the field is at offset zero, we could have been given the
3493 DECL_RTX of the parent struct. Don't munge it. */
3494 to_rtx = shallow_copy_rtx (to_rtx);
3496 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
3499 /* Deal with volatile and readonly fields. The former is only done
3500 for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
3501 if (volatilep && MEM_P (to_rtx))
3503 if (to_rtx == orig_to_rtx)
3504 to_rtx = copy_rtx (to_rtx);
3505 MEM_VOLATILE_P (to_rtx) = 1;
3508 if (MEM_P (to_rtx) && ! can_address_p (to))
3510 if (to_rtx == orig_to_rtx)
3511 to_rtx = copy_rtx (to_rtx);
3512 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
3515 /* Optimize bitfld op= val in certain cases. */
3516 while (mode1 == VOIDmode && !want_value
3517 && bitsize > 0 && bitsize < BITS_PER_WORD
3518 && GET_MODE_BITSIZE (GET_MODE (to_rtx)) <= BITS_PER_WORD
3519 && !TREE_SIDE_EFFECTS (to)
3520 && !TREE_THIS_VOLATILE (to))