1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
4 2012 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
31 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "insn-attr.h"
36 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
43 #include "typeclass.h"
45 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "tree-pass.h"
50 #include "tree-flow.h"
52 #include "common/common-target.h"
55 #include "diagnostic.h"
56 #include "ssaexpand.h"
57 #include "target-globals.h"
60 /* Decide whether a function's arguments should be processed
61 from first to last or from last to first.
63 They should if the stack and args grow in opposite directions, but
64 only if we have push insns. */
68 #ifndef PUSH_ARGS_REVERSED
69 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
70 #define PUSH_ARGS_REVERSED /* If it's last to first. */
76 #ifndef STACK_PUSH_CODE
77 #ifdef STACK_GROWS_DOWNWARD
78 #define STACK_PUSH_CODE PRE_DEC
80 #define STACK_PUSH_CODE PRE_INC
85 /* If this is nonzero, we do not bother generating VOLATILE
86 around volatile memory references, and we are willing to
87 output indirect addresses. If cse is to follow, we reject
88 indirect addresses so a useful potential cse is generated;
89 if it is used only once, instruction combination will produce
90 the same indirect address eventually. */
93 /* This structure is used by move_by_pieces to describe the move to
95 struct move_by_pieces_d
104 int explicit_inc_from;
105 unsigned HOST_WIDE_INT len;
106 HOST_WIDE_INT offset;
110 /* This structure is used by store_by_pieces to describe the clear to
113 struct store_by_pieces_d
119 unsigned HOST_WIDE_INT len;
120 HOST_WIDE_INT offset;
121 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
126 static void move_by_pieces_1 (rtx (*) (rtx, ...), enum machine_mode,
127 struct move_by_pieces_d *);
128 static bool block_move_libcall_safe_for_call_parm (void);
129 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned, unsigned, HOST_WIDE_INT);
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_d *, unsigned int);
135 static void store_by_pieces_2 (rtx (*) (rtx, ...), enum machine_mode,
136 struct store_by_pieces_d *);
137 static tree clear_storage_libcall_fn (int);
138 static rtx compress_float_constant (rtx, rtx);
139 static rtx get_subtarget (rtx);
140 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
141 HOST_WIDE_INT, enum machine_mode,
142 tree, tree, int, alias_set_type);
143 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
144 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT,
145 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
147 tree, tree, alias_set_type, bool);
149 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (const_tree, const_tree);
151 static int is_aligning_offset (const_tree, const_tree);
152 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
153 enum expand_modifier);
154 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
155 static rtx do_store_flag (sepops, rtx, enum machine_mode);
157 static void emit_single_push_insn (enum machine_mode, rtx, tree);
159 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx);
160 static rtx const_vector_from_tree (tree);
161 static void write_complex_part (rtx, rtx, bool);
163 /* This macro is used to determine whether move_by_pieces should be called
164 to perform a structure copy. */
165 #ifndef MOVE_BY_PIECES_P
166 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
167 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
168 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
171 /* This macro is used to determine whether clear_by_pieces should be
172 called to clear storage. */
173 #ifndef CLEAR_BY_PIECES_P
174 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
175 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
176 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
179 /* This macro is used to determine whether store_by_pieces should be
180 called to "memset" storage with byte values other than zero. */
181 #ifndef SET_BY_PIECES_P
182 #define SET_BY_PIECES_P(SIZE, ALIGN) \
183 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
184 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
187 /* This macro is used to determine whether store_by_pieces should be
188 called to "memcpy" storage when the source is a constant string. */
189 #ifndef STORE_BY_PIECES_P
190 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
191 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
192 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
195 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
197 #ifndef SLOW_UNALIGNED_ACCESS
198 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
201 /* This is run to set up which modes can be used
202 directly in memory and to initialize the block move optab. It is run
203 at the beginning of compilation and when the target is reinitialized. */
206 init_expr_target (void)
209 enum machine_mode mode;
214 /* Try indexing by frame ptr and try by stack ptr.
215 It is known that on the Convex the stack ptr isn't a valid index.
216 With luck, one or the other is valid on any machine. */
217 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
218 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
220 /* A scratch register we can modify in-place below to avoid
221 useless RTL allocations. */
222 reg = gen_rtx_REG (VOIDmode, -1);
224 insn = rtx_alloc (INSN);
225 pat = gen_rtx_SET (VOIDmode, NULL_RTX, NULL_RTX);
226 PATTERN (insn) = pat;
228 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
229 mode = (enum machine_mode) ((int) mode + 1))
233 direct_load[(int) mode] = direct_store[(int) mode] = 0;
234 PUT_MODE (mem, mode);
235 PUT_MODE (mem1, mode);
236 PUT_MODE (reg, mode);
238 /* See if there is some register that can be used in this mode and
239 directly loaded or stored from memory. */
241 if (mode != VOIDmode && mode != BLKmode)
242 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
243 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
246 if (! HARD_REGNO_MODE_OK (regno, mode))
249 SET_REGNO (reg, regno);
252 SET_DEST (pat) = reg;
253 if (recog (pat, insn, &num_clobbers) >= 0)
254 direct_load[(int) mode] = 1;
256 SET_SRC (pat) = mem1;
257 SET_DEST (pat) = reg;
258 if (recog (pat, insn, &num_clobbers) >= 0)
259 direct_load[(int) mode] = 1;
262 SET_DEST (pat) = mem;
263 if (recog (pat, insn, &num_clobbers) >= 0)
264 direct_store[(int) mode] = 1;
267 SET_DEST (pat) = mem1;
268 if (recog (pat, insn, &num_clobbers) >= 0)
269 direct_store[(int) mode] = 1;
273 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
275 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
276 mode = GET_MODE_WIDER_MODE (mode))
278 enum machine_mode srcmode;
279 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
280 srcmode = GET_MODE_WIDER_MODE (srcmode))
284 ic = can_extend_p (mode, srcmode, 0);
285 if (ic == CODE_FOR_nothing)
288 PUT_MODE (mem, srcmode);
290 if (insn_operand_matches (ic, 1, mem))
291 float_extend_from_mem[mode][srcmode] = true;
296 /* This is run at the start of compiling a function. */
301 memset (&crtl->expr, 0, sizeof (crtl->expr));
304 /* Copy data from FROM to TO, where the machine modes are not the same.
305 Both modes may be integer, or both may be floating, or both may be
307 UNSIGNEDP should be nonzero if FROM is an unsigned type.
308 This causes zero-extension instead of sign-extension. */
311 convert_move (rtx to, rtx from, int unsignedp)
313 enum machine_mode to_mode = GET_MODE (to);
314 enum machine_mode from_mode = GET_MODE (from);
315 int to_real = SCALAR_FLOAT_MODE_P (to_mode);
316 int from_real = SCALAR_FLOAT_MODE_P (from_mode);
320 /* rtx code for making an equivalent value. */
321 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
322 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
325 gcc_assert (to_real == from_real);
326 gcc_assert (to_mode != BLKmode);
327 gcc_assert (from_mode != BLKmode);
329 /* If the source and destination are already the same, then there's
334 /* If FROM is a SUBREG that indicates that we have already done at least
335 the required extension, strip it. We don't handle such SUBREGs as
338 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
339 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from)))
340 >= GET_MODE_PRECISION (to_mode))
341 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
342 from = gen_lowpart (to_mode, from), from_mode = to_mode;
344 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
346 if (to_mode == from_mode
347 || (from_mode == VOIDmode && CONSTANT_P (from)))
349 emit_move_insn (to, from);
353 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
355 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
357 if (VECTOR_MODE_P (to_mode))
358 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
360 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
362 emit_move_insn (to, from);
366 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
368 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
369 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
378 gcc_assert ((GET_MODE_PRECISION (from_mode)
379 != GET_MODE_PRECISION (to_mode))
380 || (DECIMAL_FLOAT_MODE_P (from_mode)
381 != DECIMAL_FLOAT_MODE_P (to_mode)));
383 if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
384 /* Conversion between decimal float and binary float, same size. */
385 tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
386 else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
391 /* Try converting directly if the insn is supported. */
393 code = convert_optab_handler (tab, to_mode, from_mode);
394 if (code != CODE_FOR_nothing)
396 emit_unop_insn (code, to, from,
397 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
401 /* Otherwise use a libcall. */
402 libcall = convert_optab_libfunc (tab, to_mode, from_mode);
404 /* Is this conversion implemented yet? */
405 gcc_assert (libcall);
408 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
410 insns = get_insns ();
412 emit_libcall_block (insns, to, value,
413 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
415 : gen_rtx_FLOAT_EXTEND (to_mode, from));
419 /* Handle pointer conversion. */ /* SPEE 900220. */
420 /* Targets are expected to provide conversion insns between PxImode and
421 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
422 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
424 enum machine_mode full_mode
425 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
427 gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
428 != CODE_FOR_nothing);
430 if (full_mode != from_mode)
431 from = convert_to_mode (full_mode, from, unsignedp);
432 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
436 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
439 enum machine_mode full_mode
440 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
442 gcc_assert (convert_optab_handler (sext_optab, full_mode, from_mode)
443 != CODE_FOR_nothing);
445 if (to_mode == full_mode)
447 emit_unop_insn (convert_optab_handler (sext_optab, full_mode,
453 new_from = gen_reg_rtx (full_mode);
454 emit_unop_insn (convert_optab_handler (sext_optab, full_mode, from_mode),
455 new_from, from, UNKNOWN);
457 /* else proceed to integer conversions below. */
458 from_mode = full_mode;
462 /* Make sure both are fixed-point modes or both are not. */
463 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
464 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
465 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
467 /* If we widen from_mode to to_mode and they are in the same class,
468 we won't saturate the result.
469 Otherwise, always saturate the result to play safe. */
470 if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
471 && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
472 expand_fixed_convert (to, from, 0, 0);
474 expand_fixed_convert (to, from, 0, 1);
478 /* Now both modes are integers. */
480 /* Handle expanding beyond a word. */
481 if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
482 && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
489 enum machine_mode lowpart_mode;
490 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
492 /* Try converting directly if the insn is supported. */
493 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
496 /* If FROM is a SUBREG, put it into a register. Do this
497 so that we always generate the same set of insns for
498 better cse'ing; if an intermediate assignment occurred,
499 we won't be doing the operation directly on the SUBREG. */
500 if (optimize > 0 && GET_CODE (from) == SUBREG)
501 from = force_reg (from_mode, from);
502 emit_unop_insn (code, to, from, equiv_code);
505 /* Next, try converting via full word. */
506 else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
507 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
508 != CODE_FOR_nothing))
510 rtx word_to = gen_reg_rtx (word_mode);
513 if (reg_overlap_mentioned_p (to, from))
514 from = force_reg (from_mode, from);
517 convert_move (word_to, from, unsignedp);
518 emit_unop_insn (code, to, word_to, equiv_code);
522 /* No special multiword conversion insn; do it by hand. */
525 /* Since we will turn this into a no conflict block, we must ensure
526 that the source does not overlap the target. */
528 if (reg_overlap_mentioned_p (to, from))
529 from = force_reg (from_mode, from);
531 /* Get a copy of FROM widened to a word, if necessary. */
532 if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
533 lowpart_mode = word_mode;
535 lowpart_mode = from_mode;
537 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
539 lowpart = gen_lowpart (lowpart_mode, to);
540 emit_move_insn (lowpart, lowfrom);
542 /* Compute the value to put in each remaining word. */
544 fill_value = const0_rtx;
546 fill_value = emit_store_flag (gen_reg_rtx (word_mode),
547 LT, lowfrom, const0_rtx,
550 /* Fill the remaining words. */
551 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
553 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
554 rtx subword = operand_subword (to, index, 1, to_mode);
556 gcc_assert (subword);
558 if (fill_value != subword)
559 emit_move_insn (subword, fill_value);
562 insns = get_insns ();
569 /* Truncating multi-word to a word or less. */
570 if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
571 && GET_MODE_PRECISION (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_MODES_P (to_mode, from_mode))
592 && ! MEM_VOLATILE_P (from)
593 && direct_load[(int) to_mode]
594 && ! mode_dependent_address_p (XEXP (from, 0)))
596 || GET_CODE (from) == SUBREG))
597 from = force_reg (from_mode, from);
598 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
599 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
600 from = copy_to_reg (from);
601 emit_move_insn (to, gen_lowpart (to_mode, from));
605 /* Handle extension. */
606 if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (from_mode))
608 /* Convert directly if that works. */
609 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
612 emit_unop_insn (code, to, from, equiv_code);
617 enum machine_mode intermediate;
621 /* Search for a mode to convert via. */
622 for (intermediate = from_mode; intermediate != VOIDmode;
623 intermediate = GET_MODE_WIDER_MODE (intermediate))
624 if (((can_extend_p (to_mode, intermediate, unsignedp)
626 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
627 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, intermediate)))
628 && (can_extend_p (intermediate, from_mode, unsignedp)
629 != CODE_FOR_nothing))
631 convert_move (to, convert_to_mode (intermediate, from,
632 unsignedp), unsignedp);
636 /* No suitable intermediate mode.
637 Generate what we need with shifts. */
638 shift_amount = (GET_MODE_PRECISION (to_mode)
639 - GET_MODE_PRECISION (from_mode));
640 from = gen_lowpart (to_mode, force_reg (from_mode, from));
641 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
643 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
646 emit_move_insn (to, tmp);
651 /* Support special truncate insns for certain modes. */
652 if (convert_optab_handler (trunc_optab, to_mode,
653 from_mode) != CODE_FOR_nothing)
655 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, from_mode),
660 /* Handle truncation of volatile memrefs, and so on;
661 the things that couldn't be truncated directly,
662 and for which there was no special instruction.
664 ??? Code above formerly short-circuited this, for most integer
665 mode pairs, with a force_reg in from_mode followed by a recursive
666 call to this routine. Appears always to have been wrong. */
667 if (GET_MODE_PRECISION (to_mode) < GET_MODE_PRECISION (from_mode))
669 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
670 emit_move_insn (to, temp);
674 /* Mode combination is not recognized. */
678 /* Return an rtx for a value that would result
679 from converting X to mode MODE.
680 Both X and MODE may be floating, or both integer.
681 UNSIGNEDP is nonzero if X is an unsigned value.
682 This can be done by referring to a part of X in place
683 or by copying to a new temporary with conversion. */
686 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
688 return convert_modes (mode, VOIDmode, x, unsignedp);
691 /* Return an rtx for a value that would result
692 from converting X from mode OLDMODE to mode MODE.
693 Both modes may be floating, or both integer.
694 UNSIGNEDP is nonzero if X is an unsigned value.
696 This can be done by referring to a part of X in place
697 or by copying to a new temporary with conversion.
699 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
702 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
706 /* If FROM is a SUBREG that indicates that we have already done at least
707 the required extension, strip it. */
709 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
710 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
711 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
712 x = gen_lowpart (mode, x);
714 if (GET_MODE (x) != VOIDmode)
715 oldmode = GET_MODE (x);
720 /* There is one case that we must handle specially: If we are converting
721 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
722 we are to interpret the constant as unsigned, gen_lowpart will do
723 the wrong if the constant appears negative. What we want to do is
724 make the high-order word of the constant zero, not all ones. */
726 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
727 && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
728 && CONST_INT_P (x) && INTVAL (x) < 0)
730 double_int val = uhwi_to_double_int (INTVAL (x));
732 /* We need to zero extend VAL. */
733 if (oldmode != VOIDmode)
734 val = double_int_zext (val, GET_MODE_BITSIZE (oldmode));
736 return immed_double_int_const (val, mode);
739 /* We can do this with a gen_lowpart if both desired and current modes
740 are integer, and this is either a constant integer, a register, or a
741 non-volatile MEM. Except for the constant case where MODE is no
742 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
745 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT)
746 || (GET_MODE_CLASS (mode) == MODE_INT
747 && GET_MODE_CLASS (oldmode) == MODE_INT
748 && (GET_CODE (x) == CONST_DOUBLE
749 || (GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (oldmode)
750 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
751 && direct_load[(int) mode])
753 && (! HARD_REGISTER_P (x)
754 || HARD_REGNO_MODE_OK (REGNO (x), mode))
755 && TRULY_NOOP_TRUNCATION_MODES_P (mode,
758 /* ?? If we don't know OLDMODE, we have to assume here that
759 X does not need sign- or zero-extension. This may not be
760 the case, but it's the best we can do. */
761 if (CONST_INT_P (x) && oldmode != VOIDmode
762 && GET_MODE_PRECISION (mode) > GET_MODE_PRECISION (oldmode))
764 HOST_WIDE_INT val = INTVAL (x);
766 /* We must sign or zero-extend in this case. Start by
767 zero-extending, then sign extend if we need to. */
768 val &= GET_MODE_MASK (oldmode);
770 && val_signbit_known_set_p (oldmode, val))
771 val |= ~GET_MODE_MASK (oldmode);
773 return gen_int_mode (val, mode);
776 return gen_lowpart (mode, x);
779 /* Converting from integer constant into mode is always equivalent to an
781 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
783 gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
784 return simplify_gen_subreg (mode, x, oldmode, 0);
787 temp = gen_reg_rtx (mode);
788 convert_move (temp, x, unsignedp);
792 /* Return the largest alignment we can use for doing a move (or store)
793 of MAX_PIECES. ALIGN is the largest alignment we could use. */
796 alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
798 enum machine_mode tmode;
800 tmode = mode_for_size (max_pieces * BITS_PER_UNIT, MODE_INT, 1);
801 if (align >= GET_MODE_ALIGNMENT (tmode))
802 align = GET_MODE_ALIGNMENT (tmode);
805 enum machine_mode tmode, xmode;
807 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
809 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
810 if (GET_MODE_SIZE (tmode) > max_pieces
811 || SLOW_UNALIGNED_ACCESS (tmode, align))
814 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
820 /* Return the widest integer mode no wider than SIZE. If no such mode
821 can be found, return VOIDmode. */
823 static enum machine_mode
824 widest_int_mode_for_size (unsigned int size)
826 enum machine_mode tmode, mode = VOIDmode;
828 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
829 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
830 if (GET_MODE_SIZE (tmode) < size)
836 /* STORE_MAX_PIECES is the number of bytes at a time that we can
837 store efficiently. Due to internal GCC limitations, this is
838 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
839 for an immediate constant. */
841 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
843 /* Determine whether the LEN bytes can be moved by using several move
844 instructions. Return nonzero if a call to move_by_pieces should
848 can_move_by_pieces (unsigned HOST_WIDE_INT len,
849 unsigned int align ATTRIBUTE_UNUSED)
851 return MOVE_BY_PIECES_P (len, align);
854 /* Generate several move instructions to copy LEN bytes from block FROM to
855 block TO. (These are MEM rtx's with BLKmode).
857 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
858 used to push FROM to the stack.
860 ALIGN is maximum stack alignment we can assume.
862 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
863 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
867 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
868 unsigned int align, int endp)
870 struct move_by_pieces_d data;
871 enum machine_mode to_addr_mode, from_addr_mode
872 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (from));
873 rtx to_addr, from_addr = XEXP (from, 0);
874 unsigned int max_size = MOVE_MAX_PIECES + 1;
875 enum insn_code icode;
877 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
880 data.from_addr = from_addr;
883 to_addr_mode = targetm.addr_space.address_mode (MEM_ADDR_SPACE (to));
884 to_addr = XEXP (to, 0);
887 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
888 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
890 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
894 to_addr_mode = VOIDmode;
898 #ifdef STACK_GROWS_DOWNWARD
904 data.to_addr = to_addr;
907 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
908 || GET_CODE (from_addr) == POST_INC
909 || GET_CODE (from_addr) == POST_DEC);
911 data.explicit_inc_from = 0;
912 data.explicit_inc_to = 0;
913 if (data.reverse) data.offset = len;
916 /* If copying requires more than two move insns,
917 copy addresses to registers (to make displacements shorter)
918 and use post-increment if available. */
919 if (!(data.autinc_from && data.autinc_to)
920 && move_by_pieces_ninsns (len, align, max_size) > 2)
922 /* Find the mode of the largest move...
923 MODE might not be used depending on the definitions of the
924 USE_* macros below. */
925 enum machine_mode mode ATTRIBUTE_UNUSED
926 = widest_int_mode_for_size (max_size);
928 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
930 data.from_addr = copy_to_mode_reg (from_addr_mode,
931 plus_constant (from_addr, len));
932 data.autinc_from = 1;
933 data.explicit_inc_from = -1;
935 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
937 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
938 data.autinc_from = 1;
939 data.explicit_inc_from = 1;
941 if (!data.autinc_from && CONSTANT_P (from_addr))
942 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
943 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
945 data.to_addr = copy_to_mode_reg (to_addr_mode,
946 plus_constant (to_addr, len));
948 data.explicit_inc_to = -1;
950 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
952 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
954 data.explicit_inc_to = 1;
956 if (!data.autinc_to && CONSTANT_P (to_addr))
957 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
960 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
962 /* First move what we can in the largest integer mode, then go to
963 successively smaller modes. */
967 enum machine_mode mode = widest_int_mode_for_size (max_size);
969 if (mode == VOIDmode)
972 icode = optab_handler (mov_optab, mode);
973 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
974 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
976 max_size = GET_MODE_SIZE (mode);
979 /* The code above should have handled everything. */
980 gcc_assert (!data.len);
986 gcc_assert (!data.reverse);
991 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
992 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
994 data.to_addr = copy_to_mode_reg (to_addr_mode,
995 plus_constant (data.to_addr,
998 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
1005 to1 = adjust_address (data.to, QImode, data.offset);
1013 /* Return number of insns required to move L bytes by pieces.
1014 ALIGN (in bits) is maximum alignment we can assume. */
1016 unsigned HOST_WIDE_INT
1017 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1018 unsigned int max_size)
1020 unsigned HOST_WIDE_INT n_insns = 0;
1022 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1024 while (max_size > 1)
1026 enum machine_mode mode;
1027 enum insn_code icode;
1029 mode = widest_int_mode_for_size (max_size);
1031 if (mode == VOIDmode)
1034 icode = optab_handler (mov_optab, mode);
1035 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1036 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1038 max_size = GET_MODE_SIZE (mode);
1045 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1046 with move instructions for mode MODE. GENFUN is the gen_... function
1047 to make a move insn for that mode. DATA has all the other info. */
1050 move_by_pieces_1 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
1051 struct move_by_pieces_d *data)
1053 unsigned int size = GET_MODE_SIZE (mode);
1054 rtx to1 = NULL_RTX, from1;
1056 while (data->len >= size)
1059 data->offset -= size;
1063 if (data->autinc_to)
1064 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1067 to1 = adjust_address (data->to, mode, data->offset);
1070 if (data->autinc_from)
1071 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1074 from1 = adjust_address (data->from, mode, data->offset);
1076 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1077 emit_insn (gen_add2_insn (data->to_addr,
1078 GEN_INT (-(HOST_WIDE_INT)size)));
1079 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1080 emit_insn (gen_add2_insn (data->from_addr,
1081 GEN_INT (-(HOST_WIDE_INT)size)));
1084 emit_insn ((*genfun) (to1, from1));
1087 #ifdef PUSH_ROUNDING
1088 emit_single_push_insn (mode, from1, NULL);
1094 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1095 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1096 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1097 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1099 if (! data->reverse)
1100 data->offset += size;
1106 /* Emit code to move a block Y to a block X. This may be done with
1107 string-move instructions, with multiple scalar move instructions,
1108 or with a library call.
1110 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1111 SIZE is an rtx that says how long they are.
1112 ALIGN is the maximum alignment we can assume they have.
1113 METHOD describes what kind of copy this is, and what mechanisms may be used.
1115 Return the address of the new block, if memcpy is called and returns it,
1119 emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
1120 unsigned int expected_align, HOST_WIDE_INT expected_size)
1127 if (CONST_INT_P (size)
1128 && INTVAL (size) == 0)
1133 case BLOCK_OP_NORMAL:
1134 case BLOCK_OP_BUILTIN:
1135 case BLOCK_OP_TAILCALL:
1136 may_use_call = true;
1139 case BLOCK_OP_CALL_PARM:
1140 may_use_call = block_move_libcall_safe_for_call_parm ();
1142 /* Make inhibit_defer_pop nonzero around the library call
1143 to force it to pop the arguments right away. */
1147 case BLOCK_OP_NO_LIBCALL:
1148 may_use_call = false;
1155 #ifdef TARGET_BLOCK_MOVE_MAY_USE_LIBCALL
1156 /* Allow the target a chance to override our decision. */
1157 TARGET_BLOCK_MOVE_MAY_USE_LIBCALL (x, y, size, method, & may_use_call);
1160 gcc_assert (MEM_P (x) && MEM_P (y));
1161 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1162 gcc_assert (align >= BITS_PER_UNIT);
1164 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1165 block copy is more efficient for other large modes, e.g. DCmode. */
1166 x = adjust_address (x, BLKmode, 0);
1167 y = adjust_address (y, BLKmode, 0);
1169 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1170 can be incorrect is coming from __builtin_memcpy. */
1171 if (CONST_INT_P (size))
1173 x = shallow_copy_rtx (x);
1174 y = shallow_copy_rtx (y);
1175 set_mem_size (x, INTVAL (size));
1176 set_mem_size (y, INTVAL (size));
1179 if (CONST_INT_P (size) && MOVE_BY_PIECES_P (INTVAL (size), align))
1180 move_by_pieces (x, y, INTVAL (size), align, 0);
1181 else if (emit_block_move_via_movmem (x, y, size, align,
1182 expected_align, expected_size))
1184 else if (may_use_call
1185 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
1186 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
1188 /* Since x and y are passed to a libcall, mark the corresponding
1189 tree EXPR as addressable. */
1190 tree y_expr = MEM_EXPR (y);
1191 tree x_expr = MEM_EXPR (x);
1193 mark_addressable (y_expr);
1195 mark_addressable (x_expr);
1196 retval = emit_block_move_via_libcall (x, y, size,
1197 method == BLOCK_OP_TAILCALL);
1201 emit_block_move_via_loop (x, y, size, align);
1203 if (method == BLOCK_OP_CALL_PARM)
1210 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1212 return emit_block_move_hints (x, y, size, method, 0, -1);
1215 /* A subroutine of emit_block_move. Returns true if calling the
1216 block move libcall will not clobber any parameters which may have
1217 already been placed on the stack. */
1220 block_move_libcall_safe_for_call_parm (void)
1222 #if defined (REG_PARM_STACK_SPACE)
1226 /* If arguments are pushed on the stack, then they're safe. */
1230 /* If registers go on the stack anyway, any argument is sure to clobber
1231 an outgoing argument. */
1232 #if defined (REG_PARM_STACK_SPACE)
1233 fn = emit_block_move_libcall_fn (false);
1234 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1235 depend on its argument. */
1237 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn ? NULL_TREE : TREE_TYPE (fn)))
1238 && REG_PARM_STACK_SPACE (fn) != 0)
1242 /* If any argument goes in memory, then it might clobber an outgoing
1245 CUMULATIVE_ARGS args_so_far_v;
1246 cumulative_args_t args_so_far;
1249 fn = emit_block_move_libcall_fn (false);
1250 INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
1251 args_so_far = pack_cumulative_args (&args_so_far_v);
1253 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1254 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1256 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1257 rtx tmp = targetm.calls.function_arg (args_so_far, mode,
1259 if (!tmp || !REG_P (tmp))
1261 if (targetm.calls.arg_partial_bytes (args_so_far, mode, NULL, 1))
1263 targetm.calls.function_arg_advance (args_so_far, mode,
1270 /* A subroutine of emit_block_move. Expand a movmem pattern;
1271 return true if successful. */
1274 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
1275 unsigned int expected_align, HOST_WIDE_INT expected_size)
1277 int save_volatile_ok = volatile_ok;
1278 enum machine_mode mode;
1280 if (expected_align < align)
1281 expected_align = align;
1283 /* Since this is a move insn, we don't care about volatility. */
1286 /* Try the most limited insn first, because there's no point
1287 including more than one in the machine description unless
1288 the more limited one has some advantage. */
1290 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1291 mode = GET_MODE_WIDER_MODE (mode))
1293 enum insn_code code = direct_optab_handler (movmem_optab, mode);
1295 if (code != CODE_FOR_nothing
1296 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1297 here because if SIZE is less than the mode mask, as it is
1298 returned by the macro, it will definitely be less than the
1299 actual mode mask. */
1300 && ((CONST_INT_P (size)
1301 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1302 <= (GET_MODE_MASK (mode) >> 1)))
1303 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD))
1305 struct expand_operand ops[6];
1308 /* ??? When called via emit_block_move_for_call, it'd be
1309 nice if there were some way to inform the backend, so
1310 that it doesn't fail the expansion because it thinks
1311 emitting the libcall would be more efficient. */
1312 nops = insn_data[(int) code].n_generator_args;
1313 gcc_assert (nops == 4 || nops == 6);
1315 create_fixed_operand (&ops[0], x);
1316 create_fixed_operand (&ops[1], y);
1317 /* The check above guarantees that this size conversion is valid. */
1318 create_convert_operand_to (&ops[2], size, mode, true);
1319 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
1322 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
1323 create_integer_operand (&ops[5], expected_size);
1325 if (maybe_expand_insn (code, nops, ops))
1327 volatile_ok = save_volatile_ok;
1333 volatile_ok = save_volatile_ok;
1337 /* A subroutine of emit_block_move. Expand a call to memcpy.
1338 Return the return value from memcpy, 0 otherwise. */
1341 emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
1343 rtx dst_addr, src_addr;
1344 tree call_expr, fn, src_tree, dst_tree, size_tree;
1345 enum machine_mode size_mode;
1348 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1349 pseudos. We can then place those new pseudos into a VAR_DECL and
1352 dst_addr = copy_to_mode_reg (Pmode, XEXP (dst, 0));
1353 src_addr = copy_to_mode_reg (Pmode, XEXP (src, 0));
1355 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1356 src_addr = convert_memory_address (ptr_mode, src_addr);
1358 dst_tree = make_tree (ptr_type_node, dst_addr);
1359 src_tree = make_tree (ptr_type_node, src_addr);
1361 size_mode = TYPE_MODE (sizetype);
1363 size = convert_to_mode (size_mode, size, 1);
1364 size = copy_to_mode_reg (size_mode, size);
1366 /* It is incorrect to use the libcall calling conventions to call
1367 memcpy in this context. This could be a user call to memcpy and
1368 the user may wish to examine the return value from memcpy. For
1369 targets where libcalls and normal calls have different conventions
1370 for returning pointers, we could end up generating incorrect code. */
1372 size_tree = make_tree (sizetype, size);
1374 fn = emit_block_move_libcall_fn (true);
1375 call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
1376 CALL_EXPR_TAILCALL (call_expr) = tailcall;
1378 retval = expand_normal (call_expr);
1383 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1384 for the function we use for block copies. The first time FOR_CALL
1385 is true, we call assemble_external. */
1387 static GTY(()) tree block_move_fn;
1390 init_block_move_fn (const char *asmspec)
1396 fn = get_identifier ("memcpy");
1397 args = build_function_type_list (ptr_type_node, ptr_type_node,
1398 const_ptr_type_node, sizetype,
1401 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
1402 DECL_EXTERNAL (fn) = 1;
1403 TREE_PUBLIC (fn) = 1;
1404 DECL_ARTIFICIAL (fn) = 1;
1405 TREE_NOTHROW (fn) = 1;
1406 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
1407 DECL_VISIBILITY_SPECIFIED (fn) = 1;
1413 set_user_assembler_name (block_move_fn, asmspec);
1417 emit_block_move_libcall_fn (int for_call)
1419 static bool emitted_extern;
1422 init_block_move_fn (NULL);
1424 if (for_call && !emitted_extern)
1426 emitted_extern = true;
1427 make_decl_rtl (block_move_fn);
1428 assemble_external (block_move_fn);
1431 return block_move_fn;
1434 /* A subroutine of emit_block_move. Copy the data via an explicit
1435 loop. This is used only when libcalls are forbidden. */
1436 /* ??? It'd be nice to copy in hunks larger than QImode. */
1439 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1440 unsigned int align ATTRIBUTE_UNUSED)
1442 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1443 enum machine_mode x_addr_mode
1444 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (x));
1445 enum machine_mode y_addr_mode
1446 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (y));
1447 enum machine_mode iter_mode;
1449 iter_mode = GET_MODE (size);
1450 if (iter_mode == VOIDmode)
1451 iter_mode = word_mode;
1453 top_label = gen_label_rtx ();
1454 cmp_label = gen_label_rtx ();
1455 iter = gen_reg_rtx (iter_mode);
1457 emit_move_insn (iter, const0_rtx);
1459 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1460 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1461 do_pending_stack_adjust ();
1463 emit_jump (cmp_label);
1464 emit_label (top_label);
1466 tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
1467 x_addr = gen_rtx_PLUS (x_addr_mode, x_addr, tmp);
1469 if (x_addr_mode != y_addr_mode)
1470 tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
1471 y_addr = gen_rtx_PLUS (y_addr_mode, y_addr, tmp);
1473 x = change_address (x, QImode, x_addr);
1474 y = change_address (y, QImode, y_addr);
1476 emit_move_insn (x, y);
1478 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1479 true, OPTAB_LIB_WIDEN);
1481 emit_move_insn (iter, tmp);
1483 emit_label (cmp_label);
1485 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1489 /* Copy all or part of a value X into registers starting at REGNO.
1490 The number of registers to be filled is NREGS. */
1493 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1496 #ifdef HAVE_load_multiple
1504 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
1505 x = validize_mem (force_const_mem (mode, x));
1507 /* See if the machine can do this with a load multiple insn. */
1508 #ifdef HAVE_load_multiple
1509 if (HAVE_load_multiple)
1511 last = get_last_insn ();
1512 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1520 delete_insns_since (last);
1524 for (i = 0; i < nregs; i++)
1525 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1526 operand_subword_force (x, i, mode));
1529 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1530 The number of registers to be filled is NREGS. */
1533 move_block_from_reg (int regno, rtx x, int nregs)
1540 /* See if the machine can do this with a store multiple insn. */
1541 #ifdef HAVE_store_multiple
1542 if (HAVE_store_multiple)
1544 rtx last = get_last_insn ();
1545 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1553 delete_insns_since (last);
1557 for (i = 0; i < nregs; i++)
1559 rtx tem = operand_subword (x, i, 1, BLKmode);
1563 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1567 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1568 ORIG, where ORIG is a non-consecutive group of registers represented by
1569 a PARALLEL. The clone is identical to the original except in that the
1570 original set of registers is replaced by a new set of pseudo registers.
1571 The new set has the same modes as the original set. */
1574 gen_group_rtx (rtx orig)
1579 gcc_assert (GET_CODE (orig) == PARALLEL);
1581 length = XVECLEN (orig, 0);
1582 tmps = XALLOCAVEC (rtx, length);
1584 /* Skip a NULL entry in first slot. */
1585 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1590 for (; i < length; i++)
1592 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1593 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1595 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1598 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1601 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1602 except that values are placed in TMPS[i], and must later be moved
1603 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1606 emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
1610 enum machine_mode m = GET_MODE (orig_src);
1612 gcc_assert (GET_CODE (dst) == PARALLEL);
1615 && !SCALAR_INT_MODE_P (m)
1616 && !MEM_P (orig_src)
1617 && GET_CODE (orig_src) != CONCAT)
1619 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
1620 if (imode == BLKmode)
1621 src = assign_stack_temp (GET_MODE (orig_src), ssize, 0);
1623 src = gen_reg_rtx (imode);
1624 if (imode != BLKmode)
1625 src = gen_lowpart (GET_MODE (orig_src), src);
1626 emit_move_insn (src, orig_src);
1627 /* ...and back again. */
1628 if (imode != BLKmode)
1629 src = gen_lowpart (imode, src);
1630 emit_group_load_1 (tmps, dst, src, type, ssize);
1634 /* Check for a NULL entry, used to indicate that the parameter goes
1635 both on the stack and in registers. */
1636 if (XEXP (XVECEXP (dst, 0, 0), 0))
1641 /* Process the pieces. */
1642 for (i = start; i < XVECLEN (dst, 0); i++)
1644 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1645 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1646 unsigned int bytelen = GET_MODE_SIZE (mode);
1649 /* Handle trailing fragments that run over the size of the struct. */
1650 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1652 /* Arrange to shift the fragment to where it belongs.
1653 extract_bit_field loads to the lsb of the reg. */
1655 #ifdef BLOCK_REG_PADDING
1656 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1657 == (BYTES_BIG_ENDIAN ? upward : downward)
1662 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1663 bytelen = ssize - bytepos;
1664 gcc_assert (bytelen > 0);
1667 /* If we won't be loading directly from memory, protect the real source
1668 from strange tricks we might play; but make sure that the source can
1669 be loaded directly into the destination. */
1671 if (!MEM_P (orig_src)
1672 && (!CONSTANT_P (orig_src)
1673 || (GET_MODE (orig_src) != mode
1674 && GET_MODE (orig_src) != VOIDmode)))
1676 if (GET_MODE (orig_src) == VOIDmode)
1677 src = gen_reg_rtx (mode);
1679 src = gen_reg_rtx (GET_MODE (orig_src));
1681 emit_move_insn (src, orig_src);
1684 /* Optimize the access just a bit. */
1686 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1687 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1688 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1689 && bytelen == GET_MODE_SIZE (mode))
1691 tmps[i] = gen_reg_rtx (mode);
1692 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1694 else if (COMPLEX_MODE_P (mode)
1695 && GET_MODE (src) == mode
1696 && bytelen == GET_MODE_SIZE (mode))
1697 /* Let emit_move_complex do the bulk of the work. */
1699 else if (GET_CODE (src) == CONCAT)
1701 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1702 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1704 if ((bytepos == 0 && bytelen == slen0)
1705 || (bytepos != 0 && bytepos + bytelen <= slen))
1707 /* The following assumes that the concatenated objects all
1708 have the same size. In this case, a simple calculation
1709 can be used to determine the object and the bit field
1711 tmps[i] = XEXP (src, bytepos / slen0);
1712 if (! CONSTANT_P (tmps[i])
1713 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1714 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1715 (bytepos % slen0) * BITS_PER_UNIT,
1716 1, false, NULL_RTX, mode, mode);
1722 gcc_assert (!bytepos);
1723 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1724 emit_move_insn (mem, src);
1725 tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
1726 0, 1, false, NULL_RTX, mode, mode);
1729 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1730 SIMD register, which is currently broken. While we get GCC
1731 to emit proper RTL for these cases, let's dump to memory. */
1732 else if (VECTOR_MODE_P (GET_MODE (dst))
1735 int slen = GET_MODE_SIZE (GET_MODE (src));
1738 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1739 emit_move_insn (mem, src);
1740 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1742 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1743 && XVECLEN (dst, 0) > 1)
1744 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE(dst), bytepos);
1745 else if (CONSTANT_P (src))
1747 HOST_WIDE_INT len = (HOST_WIDE_INT) bytelen;
1755 gcc_assert (2 * len == ssize);
1756 split_double (src, &first, &second);
1763 else if (REG_P (src) && GET_MODE (src) == mode)
1766 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1767 bytepos * BITS_PER_UNIT, 1, false, NULL_RTX,
1771 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1776 /* Emit code to move a block SRC of type TYPE to a block DST,
1777 where DST is non-consecutive registers represented by a PARALLEL.
1778 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1782 emit_group_load (rtx dst, rtx src, tree type, int ssize)
1787 tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
1788 emit_group_load_1 (tmps, dst, src, type, ssize);
1790 /* Copy the extracted pieces into the proper (probable) hard regs. */
1791 for (i = 0; i < XVECLEN (dst, 0); i++)
1793 rtx d = XEXP (XVECEXP (dst, 0, i), 0);
1796 emit_move_insn (d, tmps[i]);
1800 /* Similar, but load SRC into new pseudos in a format that looks like
1801 PARALLEL. This can later be fed to emit_group_move to get things
1802 in the right place. */
1805 emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
1810 vec = rtvec_alloc (XVECLEN (parallel, 0));
1811 emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
1813 /* Convert the vector to look just like the original PARALLEL, except
1814 with the computed values. */
1815 for (i = 0; i < XVECLEN (parallel, 0); i++)
1817 rtx e = XVECEXP (parallel, 0, i);
1818 rtx d = XEXP (e, 0);
1822 d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
1823 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
1825 RTVEC_ELT (vec, i) = e;
1828 return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
1831 /* Emit code to move a block SRC to block DST, where SRC and DST are
1832 non-consecutive groups of registers, each represented by a PARALLEL. */
1835 emit_group_move (rtx dst, rtx src)
1839 gcc_assert (GET_CODE (src) == PARALLEL
1840 && GET_CODE (dst) == PARALLEL
1841 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1843 /* Skip first entry if NULL. */
1844 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1845 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1846 XEXP (XVECEXP (src, 0, i), 0));
1849 /* Move a group of registers represented by a PARALLEL into pseudos. */
1852 emit_group_move_into_temps (rtx src)
1854 rtvec vec = rtvec_alloc (XVECLEN (src, 0));
1857 for (i = 0; i < XVECLEN (src, 0); i++)
1859 rtx e = XVECEXP (src, 0, i);
1860 rtx d = XEXP (e, 0);
1863 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
1864 RTVEC_ELT (vec, i) = e;
1867 return gen_rtx_PARALLEL (GET_MODE (src), vec);
1870 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1871 where SRC is non-consecutive registers represented by a PARALLEL.
1872 SSIZE represents the total size of block ORIG_DST, or -1 if not
1876 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1879 int start, finish, i;
1880 enum machine_mode m = GET_MODE (orig_dst);
1882 gcc_assert (GET_CODE (src) == PARALLEL);
1884 if (!SCALAR_INT_MODE_P (m)
1885 && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
1887 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
1888 if (imode == BLKmode)
1889 dst = assign_stack_temp (GET_MODE (orig_dst), ssize, 0);
1891 dst = gen_reg_rtx (imode);
1892 emit_group_store (dst, src, type, ssize);
1893 if (imode != BLKmode)
1894 dst = gen_lowpart (GET_MODE (orig_dst), dst);
1895 emit_move_insn (orig_dst, dst);
1899 /* Check for a NULL entry, used to indicate that the parameter goes
1900 both on the stack and in registers. */
1901 if (XEXP (XVECEXP (src, 0, 0), 0))
1905 finish = XVECLEN (src, 0);
1907 tmps = XALLOCAVEC (rtx, finish);
1909 /* Copy the (probable) hard regs into pseudos. */
1910 for (i = start; i < finish; i++)
1912 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1913 if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
1915 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1916 emit_move_insn (tmps[i], reg);
1922 /* If we won't be storing directly into memory, protect the real destination
1923 from strange tricks we might play. */
1925 if (GET_CODE (dst) == PARALLEL)
1929 /* We can get a PARALLEL dst if there is a conditional expression in
1930 a return statement. In that case, the dst and src are the same,
1931 so no action is necessary. */
1932 if (rtx_equal_p (dst, src))
1935 /* It is unclear if we can ever reach here, but we may as well handle
1936 it. Allocate a temporary, and split this into a store/load to/from
1939 temp = assign_stack_temp (GET_MODE (dst), ssize, 0);
1940 emit_group_store (temp, src, type, ssize);
1941 emit_group_load (dst, temp, type, ssize);
1944 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1946 enum machine_mode outer = GET_MODE (dst);
1947 enum machine_mode inner;
1948 HOST_WIDE_INT bytepos;
1952 if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
1953 dst = gen_reg_rtx (outer);
1955 /* Make life a bit easier for combine. */
1956 /* If the first element of the vector is the low part
1957 of the destination mode, use a paradoxical subreg to
1958 initialize the destination. */
1961 inner = GET_MODE (tmps[start]);
1962 bytepos = subreg_lowpart_offset (inner, outer);
1963 if (INTVAL (XEXP (XVECEXP (src, 0, start), 1)) == bytepos)
1965 temp = simplify_gen_subreg (outer, tmps[start],
1969 emit_move_insn (dst, temp);
1976 /* If the first element wasn't the low part, try the last. */
1978 && start < finish - 1)
1980 inner = GET_MODE (tmps[finish - 1]);
1981 bytepos = subreg_lowpart_offset (inner, outer);
1982 if (INTVAL (XEXP (XVECEXP (src, 0, finish - 1), 1)) == bytepos)
1984 temp = simplify_gen_subreg (outer, tmps[finish - 1],
1988 emit_move_insn (dst, temp);
1995 /* Otherwise, simply initialize the result to zero. */
1997 emit_move_insn (dst, CONST0_RTX (outer));
2000 /* Process the pieces. */
2001 for (i = start; i < finish; i++)
2003 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
2004 enum machine_mode mode = GET_MODE (tmps[i]);
2005 unsigned int bytelen = GET_MODE_SIZE (mode);
2006 unsigned int adj_bytelen = bytelen;
2009 /* Handle trailing fragments that run over the size of the struct. */
2010 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2011 adj_bytelen = ssize - bytepos;
2013 if (GET_CODE (dst) == CONCAT)
2015 if (bytepos + adj_bytelen
2016 <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2017 dest = XEXP (dst, 0);
2018 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2020 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
2021 dest = XEXP (dst, 1);
2025 enum machine_mode dest_mode = GET_MODE (dest);
2026 enum machine_mode tmp_mode = GET_MODE (tmps[i]);
2028 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
2030 if (GET_MODE_ALIGNMENT (dest_mode)
2031 >= GET_MODE_ALIGNMENT (tmp_mode))
2033 dest = assign_stack_temp (dest_mode,
2034 GET_MODE_SIZE (dest_mode),
2036 emit_move_insn (adjust_address (dest,
2044 dest = assign_stack_temp (tmp_mode,
2045 GET_MODE_SIZE (tmp_mode),
2047 emit_move_insn (dest, tmps[i]);
2048 dst = adjust_address (dest, dest_mode, bytepos);
2054 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2056 /* store_bit_field always takes its value from the lsb.
2057 Move the fragment to the lsb if it's not already there. */
2059 #ifdef BLOCK_REG_PADDING
2060 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
2061 == (BYTES_BIG_ENDIAN ? upward : downward)
2067 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2068 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
2071 bytelen = adj_bytelen;
2074 /* Optimize the access just a bit. */
2076 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
2077 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
2078 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2079 && bytelen == GET_MODE_SIZE (mode))
2080 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2082 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2083 0, 0, mode, tmps[i]);
2086 /* Copy from the pseudo into the (probable) hard reg. */
2087 if (orig_dst != dst)
2088 emit_move_insn (orig_dst, dst);
2091 /* Generate code to copy a BLKmode object of TYPE out of a
2092 set of registers starting with SRCREG into TGTBLK. If TGTBLK
2093 is null, a stack temporary is created. TGTBLK is returned.
2095 The purpose of this routine is to handle functions that return
2096 BLKmode structures in registers. Some machines (the PA for example)
2097 want to return all small structures in registers regardless of the
2098 structure's alignment. */
2101 copy_blkmode_from_reg (rtx tgtblk, rtx srcreg, tree type)
2103 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2104 rtx src = NULL, dst = NULL;
2105 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2106 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2107 enum machine_mode copy_mode;
2111 tgtblk = assign_temp (build_qualified_type (type,
2113 | TYPE_QUAL_CONST)),
2115 preserve_temp_slots (tgtblk);
2118 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2119 into a new pseudo which is a full word. */
2121 if (GET_MODE (srcreg) != BLKmode
2122 && GET_MODE_SIZE (GET_MODE (srcreg)) < UNITS_PER_WORD)
2123 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
2125 /* If the structure doesn't take up a whole number of words, see whether
2126 SRCREG is padded on the left or on the right. If it's on the left,
2127 set PADDING_CORRECTION to the number of bits to skip.
2129 In most ABIs, the structure will be returned at the least end of
2130 the register, which translates to right padding on little-endian
2131 targets and left padding on big-endian targets. The opposite
2132 holds if the structure is returned at the most significant
2133 end of the register. */
2134 if (bytes % UNITS_PER_WORD != 0
2135 && (targetm.calls.return_in_msb (type)
2137 : BYTES_BIG_ENDIAN))
2139 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2141 /* Copy the structure BITSIZE bits at a time. If the target lives in
2142 memory, take care of not reading/writing past its end by selecting
2143 a copy mode suited to BITSIZE. This should always be possible given
2146 We could probably emit more efficient code for machines which do not use
2147 strict alignment, but it doesn't seem worth the effort at the current
2150 copy_mode = word_mode;
2153 enum machine_mode mem_mode = mode_for_size (bitsize, MODE_INT, 1);
2154 if (mem_mode != BLKmode)
2155 copy_mode = mem_mode;
2158 for (bitpos = 0, xbitpos = padding_correction;
2159 bitpos < bytes * BITS_PER_UNIT;
2160 bitpos += bitsize, xbitpos += bitsize)
2162 /* We need a new source operand each time xbitpos is on a
2163 word boundary and when xbitpos == padding_correction
2164 (the first time through). */
2165 if (xbitpos % BITS_PER_WORD == 0
2166 || xbitpos == padding_correction)
2167 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD,
2170 /* We need a new destination operand each time bitpos is on
2172 if (bitpos % BITS_PER_WORD == 0)
2173 dst = operand_subword (tgtblk, bitpos / BITS_PER_WORD, 1, BLKmode);
2175 /* Use xbitpos for the source extraction (right justified) and
2176 bitpos for the destination store (left justified). */
2177 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
2178 extract_bit_field (src, bitsize,
2179 xbitpos % BITS_PER_WORD, 1, false,
2180 NULL_RTX, copy_mode, copy_mode));
2186 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2187 register if it contains any data, otherwise return null.
2189 This is used on targets that return BLKmode values in registers. */
2192 copy_blkmode_to_reg (enum machine_mode mode, tree src)
2195 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
2196 unsigned int bitsize;
2197 rtx *dst_words, dst, x, src_word = NULL_RTX, dst_word = NULL_RTX;
2198 enum machine_mode dst_mode;
2200 gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
2202 x = expand_normal (src);
2204 bytes = int_size_in_bytes (TREE_TYPE (src));
2208 /* If the structure doesn't take up a whole number of words, see
2209 whether the register value should be padded on the left or on
2210 the right. Set PADDING_CORRECTION to the number of padding
2211 bits needed on the left side.
2213 In most ABIs, the structure will be returned at the least end of
2214 the register, which translates to right padding on little-endian
2215 targets and left padding on big-endian targets. The opposite
2216 holds if the structure is returned at the most significant
2217 end of the register. */
2218 if (bytes % UNITS_PER_WORD != 0
2219 && (targetm.calls.return_in_msb (TREE_TYPE (src))
2221 : BYTES_BIG_ENDIAN))
2222 padding_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2225 n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2226 dst_words = XALLOCAVEC (rtx, n_regs);
2227 bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
2229 /* Copy the structure BITSIZE bits at a time. */
2230 for (bitpos = 0, xbitpos = padding_correction;
2231 bitpos < bytes * BITS_PER_UNIT;
2232 bitpos += bitsize, xbitpos += bitsize)
2234 /* We need a new destination pseudo each time xbitpos is
2235 on a word boundary and when xbitpos == padding_correction
2236 (the first time through). */
2237 if (xbitpos % BITS_PER_WORD == 0
2238 || xbitpos == padding_correction)
2240 /* Generate an appropriate register. */
2241 dst_word = gen_reg_rtx (word_mode);
2242 dst_words[xbitpos / BITS_PER_WORD] = dst_word;
2244 /* Clear the destination before we move anything into it. */
2245 emit_move_insn (dst_word, CONST0_RTX (word_mode));
2248 /* We need a new source operand each time bitpos is on a word
2250 if (bitpos % BITS_PER_WORD == 0)
2251 src_word = operand_subword_force (x, bitpos / BITS_PER_WORD, BLKmode);
2253 /* Use bitpos for the source extraction (left justified) and
2254 xbitpos for the destination store (right justified). */
2255 store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
2257 extract_bit_field (src_word, bitsize,
2258 bitpos % BITS_PER_WORD, 1, false,
2259 NULL_RTX, word_mode, word_mode));
2262 if (mode == BLKmode)
2264 /* Find the smallest integer mode large enough to hold the
2265 entire structure. */
2266 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2268 mode = GET_MODE_WIDER_MODE (mode))
2269 /* Have we found a large enough mode? */
2270 if (GET_MODE_SIZE (mode) >= bytes)
2273 /* A suitable mode should have been found. */
2274 gcc_assert (mode != VOIDmode);
2277 if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
2278 dst_mode = word_mode;
2281 dst = gen_reg_rtx (dst_mode);
2283 for (i = 0; i < n_regs; i++)
2284 emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
2286 if (mode != dst_mode)
2287 dst = gen_lowpart (mode, dst);
2292 /* Add a USE expression for REG to the (possibly empty) list pointed
2293 to by CALL_FUSAGE. REG must denote a hard register. */
2296 use_reg_mode (rtx *call_fusage, rtx reg, enum machine_mode mode)
2298 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
2301 = gen_rtx_EXPR_LIST (mode, gen_rtx_USE (VOIDmode, reg), *call_fusage);
2304 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2305 starting at REGNO. All of these registers must be hard registers. */
2308 use_regs (rtx *call_fusage, int regno, int nregs)
2312 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
2314 for (i = 0; i < nregs; i++)
2315 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2318 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2319 PARALLEL REGS. This is for calls that pass values in multiple
2320 non-contiguous locations. The Irix 6 ABI has examples of this. */
2323 use_group_regs (rtx *call_fusage, rtx regs)
2327 for (i = 0; i < XVECLEN (regs, 0); i++)
2329 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2331 /* A NULL entry means the parameter goes both on the stack and in
2332 registers. This can also be a MEM for targets that pass values
2333 partially on the stack and partially in registers. */
2334 if (reg != 0 && REG_P (reg))
2335 use_reg (call_fusage, reg);
2339 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2340 assigment and the code of the expresion on the RHS is CODE. Return
2344 get_def_for_expr (tree name, enum tree_code code)
2348 if (TREE_CODE (name) != SSA_NAME)
2351 def_stmt = get_gimple_for_ssa_name (name);
2353 || gimple_assign_rhs_code (def_stmt) != code)
2360 /* Determine whether the LEN bytes generated by CONSTFUN can be
2361 stored to memory using several move instructions. CONSTFUNDATA is
2362 a pointer which will be passed as argument in every CONSTFUN call.
2363 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2364 a memset operation and false if it's a copy of a constant string.
2365 Return nonzero if a call to store_by_pieces should succeed. */
2368 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2369 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2370 void *constfundata, unsigned int align, bool memsetp)
2372 unsigned HOST_WIDE_INT l;
2373 unsigned int max_size;
2374 HOST_WIDE_INT offset = 0;
2375 enum machine_mode mode;
2376 enum insn_code icode;
2378 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2379 rtx cst ATTRIBUTE_UNUSED;
2385 ? SET_BY_PIECES_P (len, align)
2386 : STORE_BY_PIECES_P (len, align)))
2389 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2391 /* We would first store what we can in the largest integer mode, then go to
2392 successively smaller modes. */
2395 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2399 max_size = STORE_MAX_PIECES + 1;
2400 while (max_size > 1)
2402 mode = widest_int_mode_for_size (max_size);
2404 if (mode == VOIDmode)
2407 icode = optab_handler (mov_optab, mode);
2408 if (icode != CODE_FOR_nothing
2409 && align >= GET_MODE_ALIGNMENT (mode))
2411 unsigned int size = GET_MODE_SIZE (mode);
2418 cst = (*constfun) (constfundata, offset, mode);
2419 if (!targetm.legitimate_constant_p (mode, cst))
2429 max_size = GET_MODE_SIZE (mode);
2432 /* The code above should have handled everything. */
2439 /* Generate several move instructions to store LEN bytes generated by
2440 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2441 pointer which will be passed as argument in every CONSTFUN call.
2442 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2443 a memset operation and false if it's a copy of a constant string.
2444 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2445 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2449 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2450 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2451 void *constfundata, unsigned int align, bool memsetp, int endp)
2453 enum machine_mode to_addr_mode
2454 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (to));
2455 struct store_by_pieces_d data;
2459 gcc_assert (endp != 2);
2464 ? SET_BY_PIECES_P (len, align)
2465 : STORE_BY_PIECES_P (len, align));
2466 data.constfun = constfun;
2467 data.constfundata = constfundata;
2470 store_by_pieces_1 (&data, align);
2475 gcc_assert (!data.reverse);
2480 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2481 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2483 data.to_addr = copy_to_mode_reg (to_addr_mode,
2484 plus_constant (data.to_addr,
2487 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2494 to1 = adjust_address (data.to, QImode, data.offset);
2502 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2503 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2506 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2508 struct store_by_pieces_d data;
2513 data.constfun = clear_by_pieces_1;
2514 data.constfundata = NULL;
2517 store_by_pieces_1 (&data, align);
2520 /* Callback routine for clear_by_pieces.
2521 Return const0_rtx unconditionally. */
2524 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2525 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2526 enum machine_mode mode ATTRIBUTE_UNUSED)
2531 /* Subroutine of clear_by_pieces and store_by_pieces.
2532 Generate several move instructions to store LEN bytes of block TO. (A MEM
2533 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2536 store_by_pieces_1 (struct store_by_pieces_d *data ATTRIBUTE_UNUSED,
2537 unsigned int align ATTRIBUTE_UNUSED)
2539 enum machine_mode to_addr_mode
2540 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (data->to));
2541 rtx to_addr = XEXP (data->to, 0);
2542 unsigned int max_size = STORE_MAX_PIECES + 1;
2543 enum insn_code icode;
2546 data->to_addr = to_addr;
2548 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2549 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2551 data->explicit_inc_to = 0;
2553 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2555 data->offset = data->len;
2557 /* If storing requires more than two move insns,
2558 copy addresses to registers (to make displacements shorter)
2559 and use post-increment if available. */
2560 if (!data->autinc_to
2561 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2563 /* Determine the main mode we'll be using.
2564 MODE might not be used depending on the definitions of the
2565 USE_* macros below. */
2566 enum machine_mode mode ATTRIBUTE_UNUSED
2567 = widest_int_mode_for_size (max_size);
2569 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2571 data->to_addr = copy_to_mode_reg (to_addr_mode,
2572 plus_constant (to_addr, data->len));
2573 data->autinc_to = 1;
2574 data->explicit_inc_to = -1;
2577 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2578 && ! data->autinc_to)
2580 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2581 data->autinc_to = 1;
2582 data->explicit_inc_to = 1;
2585 if ( !data->autinc_to && CONSTANT_P (to_addr))
2586 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2589 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2591 /* First store what we can in the largest integer mode, then go to
2592 successively smaller modes. */
2594 while (max_size > 1)
2596 enum machine_mode mode = widest_int_mode_for_size (max_size);
2598 if (mode == VOIDmode)
2601 icode = optab_handler (mov_optab, mode);
2602 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2603 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2605 max_size = GET_MODE_SIZE (mode);
2608 /* The code above should have handled everything. */
2609 gcc_assert (!data->len);
2612 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2613 with move instructions for mode MODE. GENFUN is the gen_... function
2614 to make a move insn for that mode. DATA has all the other info. */
2617 store_by_pieces_2 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
2618 struct store_by_pieces_d *data)
2620 unsigned int size = GET_MODE_SIZE (mode);
2623 while (data->len >= size)
2626 data->offset -= size;
2628 if (data->autinc_to)
2629 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2632 to1 = adjust_address (data->to, mode, data->offset);
2634 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2635 emit_insn (gen_add2_insn (data->to_addr,
2636 GEN_INT (-(HOST_WIDE_INT) size)));
2638 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2639 emit_insn ((*genfun) (to1, cst));
2641 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2642 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2644 if (! data->reverse)
2645 data->offset += size;
2651 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2652 its length in bytes. */
2655 clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
2656 unsigned int expected_align, HOST_WIDE_INT expected_size)
2658 enum machine_mode mode = GET_MODE (object);
2661 gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
2663 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2664 just move a zero. Otherwise, do this a piece at a time. */
2666 && CONST_INT_P (size)
2667 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
2669 rtx zero = CONST0_RTX (mode);
2672 emit_move_insn (object, zero);
2676 if (COMPLEX_MODE_P (mode))
2678 zero = CONST0_RTX (GET_MODE_INNER (mode));
2681 write_complex_part (object, zero, 0);
2682 write_complex_part (object, zero, 1);
2688 if (size == const0_rtx)
2691 align = MEM_ALIGN (object);
2693 if (CONST_INT_P (size)
2694 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2695 clear_by_pieces (object, INTVAL (size), align);
2696 else if (set_storage_via_setmem (object, size, const0_rtx, align,
2697 expected_align, expected_size))
2699 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
2700 return set_storage_via_libcall (object, size, const0_rtx,
2701 method == BLOCK_OP_TAILCALL);
2709 clear_storage (rtx object, rtx size, enum block_op_methods method)
2711 return clear_storage_hints (object, size, method, 0, -1);
2715 /* A subroutine of clear_storage. Expand a call to memset.
2716 Return the return value of memset, 0 otherwise. */
2719 set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
2721 tree call_expr, fn, object_tree, size_tree, val_tree;
2722 enum machine_mode size_mode;
2725 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2726 place those into new pseudos into a VAR_DECL and use them later. */
2728 object = copy_to_mode_reg (Pmode, XEXP (object, 0));
2730 size_mode = TYPE_MODE (sizetype);
2731 size = convert_to_mode (size_mode, size, 1);
2732 size = copy_to_mode_reg (size_mode, size);
2734 /* It is incorrect to use the libcall calling conventions to call
2735 memset in this context. This could be a user call to memset and
2736 the user may wish to examine the return value from memset. For
2737 targets where libcalls and normal calls have different conventions
2738 for returning pointers, we could end up generating incorrect code. */
2740 object_tree = make_tree (ptr_type_node, object);
2741 if (!CONST_INT_P (val))
2742 val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
2743 size_tree = make_tree (sizetype, size);
2744 val_tree = make_tree (integer_type_node, val);
2746 fn = clear_storage_libcall_fn (true);
2747 call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
2748 CALL_EXPR_TAILCALL (call_expr) = tailcall;
2750 retval = expand_normal (call_expr);
2755 /* A subroutine of set_storage_via_libcall. Create the tree node
2756 for the function we use for block clears. The first time FOR_CALL
2757 is true, we call assemble_external. */
2759 tree block_clear_fn;
2762 init_block_clear_fn (const char *asmspec)
2764 if (!block_clear_fn)
2768 fn = get_identifier ("memset");
2769 args = build_function_type_list (ptr_type_node, ptr_type_node,
2770 integer_type_node, sizetype,
2773 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
2774 DECL_EXTERNAL (fn) = 1;
2775 TREE_PUBLIC (fn) = 1;
2776 DECL_ARTIFICIAL (fn) = 1;
2777 TREE_NOTHROW (fn) = 1;
2778 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
2779 DECL_VISIBILITY_SPECIFIED (fn) = 1;
2781 block_clear_fn = fn;
2785 set_user_assembler_name (block_clear_fn, asmspec);
2789 clear_storage_libcall_fn (int for_call)
2791 static bool emitted_extern;
2793 if (!block_clear_fn)
2794 init_block_clear_fn (NULL);
2796 if (for_call && !emitted_extern)
2798 emitted_extern = true;
2799 make_decl_rtl (block_clear_fn);
2800 assemble_external (block_clear_fn);
2803 return block_clear_fn;
2806 /* Expand a setmem pattern; return true if successful. */
2809 set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
2810 unsigned int expected_align, HOST_WIDE_INT expected_size)
2812 /* Try the most limited insn first, because there's no point
2813 including more than one in the machine description unless
2814 the more limited one has some advantage. */
2816 enum machine_mode mode;
2818 if (expected_align < align)
2819 expected_align = align;
2821 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2822 mode = GET_MODE_WIDER_MODE (mode))
2824 enum insn_code code = direct_optab_handler (setmem_optab, mode);
2826 if (code != CODE_FOR_nothing
2827 /* We don't need MODE to be narrower than
2828 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2829 the mode mask, as it is returned by the macro, it will
2830 definitely be less than the actual mode mask. */
2831 && ((CONST_INT_P (size)
2832 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2833 <= (GET_MODE_MASK (mode) >> 1)))
2834 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD))
2836 struct expand_operand ops[6];
2839 nops = insn_data[(int) code].n_generator_args;
2840 gcc_assert (nops == 4 || nops == 6);
2842 create_fixed_operand (&ops[0], object);
2843 /* The check above guarantees that this size conversion is valid. */
2844 create_convert_operand_to (&ops[1], size, mode, true);
2845 create_convert_operand_from (&ops[2], val, byte_mode, true);
2846 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2849 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2850 create_integer_operand (&ops[5], expected_size);
2852 if (maybe_expand_insn (code, nops, ops))
2861 /* Write to one of the components of the complex value CPLX. Write VAL to
2862 the real part if IMAG_P is false, and the imaginary part if its true. */
2865 write_complex_part (rtx cplx, rtx val, bool imag_p)
2867 enum machine_mode cmode;
2868 enum machine_mode imode;
2871 if (GET_CODE (cplx) == CONCAT)
2873 emit_move_insn (XEXP (cplx, imag_p), val);
2877 cmode = GET_MODE (cplx);
2878 imode = GET_MODE_INNER (cmode);
2879 ibitsize = GET_MODE_BITSIZE (imode);
2881 /* For MEMs simplify_gen_subreg may generate an invalid new address
2882 because, e.g., the original address is considered mode-dependent
2883 by the target, which restricts simplify_subreg from invoking
2884 adjust_address_nv. Instead of preparing fallback support for an
2885 invalid address, we call adjust_address_nv directly. */
2888 emit_move_insn (adjust_address_nv (cplx, imode,
2889 imag_p ? GET_MODE_SIZE (imode) : 0),
2894 /* If the sub-object is at least word sized, then we know that subregging
2895 will work. This special case is important, since store_bit_field
2896 wants to operate on integer modes, and there's rarely an OImode to
2897 correspond to TCmode. */
2898 if (ibitsize >= BITS_PER_WORD
2899 /* For hard regs we have exact predicates. Assume we can split
2900 the original object if it spans an even number of hard regs.
2901 This special case is important for SCmode on 64-bit platforms
2902 where the natural size of floating-point regs is 32-bit. */
2904 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2905 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2907 rtx part = simplify_gen_subreg (imode, cplx, cmode,
2908 imag_p ? GET_MODE_SIZE (imode) : 0);
2911 emit_move_insn (part, val);
2915 /* simplify_gen_subreg may fail for sub-word MEMs. */
2916 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2919 store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, 0, 0, imode, val);
2922 /* Extract one of the components of the complex value CPLX. Extract the
2923 real part if IMAG_P is false, and the imaginary part if it's true. */
2926 read_complex_part (rtx cplx, bool imag_p)
2928 enum machine_mode cmode, imode;
2931 if (GET_CODE (cplx) == CONCAT)
2932 return XEXP (cplx, imag_p);
2934 cmode = GET_MODE (cplx);
2935 imode = GET_MODE_INNER (cmode);
2936 ibitsize = GET_MODE_BITSIZE (imode);
2938 /* Special case reads from complex constants that got spilled to memory. */
2939 if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
2941 tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
2942 if (decl && TREE_CODE (decl) == COMPLEX_CST)
2944 tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
2945 if (CONSTANT_CLASS_P (part))
2946 return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
2950 /* For MEMs simplify_gen_subreg may generate an invalid new address
2951 because, e.g., the original address is considered mode-dependent
2952 by the target, which restricts simplify_subreg from invoking
2953 adjust_address_nv. Instead of preparing fallback support for an
2954 invalid address, we call adjust_address_nv directly. */
2956 return adjust_address_nv (cplx, imode,
2957 imag_p ? GET_MODE_SIZE (imode) : 0);
2959 /* If the sub-object is at least word sized, then we know that subregging
2960 will work. This special case is important, since extract_bit_field
2961 wants to operate on integer modes, and there's rarely an OImode to
2962 correspond to TCmode. */
2963 if (ibitsize >= BITS_PER_WORD
2964 /* For hard regs we have exact predicates. Assume we can split
2965 the original object if it spans an even number of hard regs.
2966 This special case is important for SCmode on 64-bit platforms
2967 where the natural size of floating-point regs is 32-bit. */
2969 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2970 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2972 rtx ret = simplify_gen_subreg (imode, cplx, cmode,
2973 imag_p ? GET_MODE_SIZE (imode) : 0);
2977 /* simplify_gen_subreg may fail for sub-word MEMs. */
2978 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2981 return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
2982 true, false, NULL_RTX, imode, imode);
2985 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
2986 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
2987 represented in NEW_MODE. If FORCE is true, this will never happen, as
2988 we'll force-create a SUBREG if needed. */
2991 emit_move_change_mode (enum machine_mode new_mode,
2992 enum machine_mode old_mode, rtx x, bool force)
2996 if (push_operand (x, GET_MODE (x)))
2998 ret = gen_rtx_MEM (new_mode, XEXP (x, 0));
2999 MEM_COPY_ATTRIBUTES (ret, x);
3003 /* We don't have to worry about changing the address since the
3004 size in bytes is supposed to be the same. */
3005 if (reload_in_progress)
3007 /* Copy the MEM to change the mode and move any
3008 substitutions from the old MEM to the new one. */
3009 ret = adjust_address_nv (x, new_mode, 0);
3010 copy_replacements (x, ret);
3013 ret = adjust_address (x, new_mode, 0);
3017 /* Note that we do want simplify_subreg's behavior of validating
3018 that the new mode is ok for a hard register. If we were to use
3019 simplify_gen_subreg, we would create the subreg, but would
3020 probably run into the target not being able to implement it. */
3021 /* Except, of course, when FORCE is true, when this is exactly what
3022 we want. Which is needed for CCmodes on some targets. */
3024 ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
3026 ret = simplify_subreg (new_mode, x, old_mode, 0);
3032 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3033 an integer mode of the same size as MODE. Returns the instruction
3034 emitted, or NULL if such a move could not be generated. */
3037 emit_move_via_integer (enum machine_mode mode, rtx x, rtx y, bool force)
3039 enum machine_mode imode;
3040 enum insn_code code;
3042 /* There must exist a mode of the exact size we require. */
3043 imode = int_mode_for_mode (mode);
3044 if (imode == BLKmode)
3047 /* The target must support moves in this mode. */
3048 code = optab_handler (mov_optab, imode);
3049 if (code == CODE_FOR_nothing)
3052 x = emit_move_change_mode (imode, mode, x, force);
3055 y = emit_move_change_mode (imode, mode, y, force);
3058 return emit_insn (GEN_FCN (code) (x, y));
3061 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3062 Return an equivalent MEM that does not use an auto-increment. */
3065 emit_move_resolve_push (enum machine_mode mode, rtx x)
3067 enum rtx_code code = GET_CODE (XEXP (x, 0));
3068 HOST_WIDE_INT adjust;
3071 adjust = GET_MODE_SIZE (mode);
3072 #ifdef PUSH_ROUNDING
3073 adjust = PUSH_ROUNDING (adjust);
3075 if (code == PRE_DEC || code == POST_DEC)
3077 else if (code == PRE_MODIFY || code == POST_MODIFY)
3079 rtx expr = XEXP (XEXP (x, 0), 1);
3082 gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
3083 gcc_assert (CONST_INT_P (XEXP (expr, 1)));
3084 val = INTVAL (XEXP (expr, 1));
3085 if (GET_CODE (expr) == MINUS)
3087 gcc_assert (adjust == val || adjust == -val);
3091 /* Do not use anti_adjust_stack, since we don't want to update
3092 stack_pointer_delta. */
3093 temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
3094 GEN_INT (adjust), stack_pointer_rtx,
3095 0, OPTAB_LIB_WIDEN);
3096 if (temp != stack_pointer_rtx)
3097 emit_move_insn (stack_pointer_rtx, temp);
3104 temp = stack_pointer_rtx;
3109 temp = plus_constant (stack_pointer_rtx, -adjust);
3115 return replace_equiv_address (x, temp);
3118 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3119 X is known to satisfy push_operand, and MODE is known to be complex.
3120 Returns the last instruction emitted. */
3123 emit_move_complex_push (enum machine_mode mode, rtx x, rtx y)
3125 enum machine_mode submode = GET_MODE_INNER (mode);
3128 #ifdef PUSH_ROUNDING
3129 unsigned int submodesize = GET_MODE_SIZE (submode);
3131 /* In case we output to the stack, but the size is smaller than the
3132 machine can push exactly, we need to use move instructions. */
3133 if (PUSH_ROUNDING (submodesize) != submodesize)
3135 x = emit_move_resolve_push (mode, x);
3136 return emit_move_insn (x, y);
3140 /* Note that the real part always precedes the imag part in memory
3141 regardless of machine's endianness. */
3142 switch (GET_CODE (XEXP (x, 0)))
3156 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3157 read_complex_part (y, imag_first));
3158 return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3159 read_complex_part (y, !imag_first));
3162 /* A subroutine of emit_move_complex. Perform the move from Y to X
3163 via two moves of the parts. Returns the last instruction emitted. */
3166 emit_move_complex_parts (rtx x, rtx y)
3168 /* Show the output dies here. This is necessary for SUBREGs
3169 of pseudos since we cannot track their lifetimes correctly;
3170 hard regs shouldn't appear here except as return values. */
3171 if (!reload_completed && !reload_in_progress
3172 && REG_P (x) && !reg_overlap_mentioned_p (x, y))
3175 write_complex_part (x, read_complex_part (y, false), false);
3176 write_complex_part (x, read_complex_part (y, true), true);
3178 return get_last_insn ();
3181 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3182 MODE is known to be complex. Returns the last instruction emitted. */
3185 emit_move_complex (enum machine_mode mode, rtx x, rtx y)
3189 /* Need to take special care for pushes, to maintain proper ordering
3190 of the data, and possibly extra padding. */
3191 if (push_operand (x, mode))
3192 return emit_move_complex_push (mode, x, y);
3194 /* See if we can coerce the target into moving both values at once. */
3196 /* Move floating point as parts. */
3197 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3198 && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing)
3200 /* Not possible if the values are inherently not adjacent. */
3201 else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
3203 /* Is possible if both are registers (or subregs of registers). */
3204 else if (register_operand (x, mode) && register_operand (y, mode))
3206 /* If one of the operands is a memory, and alignment constraints
3207 are friendly enough, we may be able to do combined memory operations.
3208 We do not attempt this if Y is a constant because that combination is
3209 usually better with the by-parts thing below. */
3210 else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
3211 && (!STRICT_ALIGNMENT
3212 || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
3221 /* For memory to memory moves, optimal behavior can be had with the
3222 existing block move logic. */
3223 if (MEM_P (x) && MEM_P (y))
3225 emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
3226 BLOCK_OP_NO_LIBCALL);
3227 return get_last_insn ();
3230 ret = emit_move_via_integer (mode, x, y, true);
3235 return emit_move_complex_parts (x, y);
3238 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3239 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3242 emit_move_ccmode (enum machine_mode mode, rtx x, rtx y)
3246 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3249 enum insn_code code = optab_handler (mov_optab, CCmode);
3250 if (code != CODE_FOR_nothing)
3252 x = emit_move_change_mode (CCmode, mode, x, true);
3253 y = emit_move_change_mode (CCmode, mode, y, true);
3254 return emit_insn (GEN_FCN (code) (x, y));
3258 /* Otherwise, find the MODE_INT mode of the same width. */
3259 ret = emit_move_via_integer (mode, x, y, false);
3260 gcc_assert (ret != NULL);
3264 /* Return true if word I of OP lies entirely in the
3265 undefined bits of a paradoxical subreg. */
3268 undefined_operand_subword_p (const_rtx op, int i)
3270 enum machine_mode innermode, innermostmode;
3272 if (GET_CODE (op) != SUBREG)
3274 innermode = GET_MODE (op);
3275 innermostmode = GET_MODE (SUBREG_REG (op));
3276 offset = i * UNITS_PER_WORD + SUBREG_BYTE (op);
3277 /* The SUBREG_BYTE represents offset, as if the value were stored in
3278 memory, except for a paradoxical subreg where we define
3279 SUBREG_BYTE to be 0; undo this exception as in
3281 if (SUBREG_BYTE (op) == 0
3282 && GET_MODE_SIZE (innermostmode) < GET_MODE_SIZE (innermode))
3284 int difference = (GET_MODE_SIZE (innermostmode) - GET_MODE_SIZE (innermode));
3285 if (WORDS_BIG_ENDIAN)
3286 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
3287 if (BYTES_BIG_ENDIAN)
3288 offset += difference % UNITS_PER_WORD;
3290 if (offset >= GET_MODE_SIZE (innermostmode)
3291 || offset <= -GET_MODE_SIZE (word_mode))
3296 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3297 MODE is any multi-word or full-word mode that lacks a move_insn
3298 pattern. Note that you will get better code if you define such
3299 patterns, even if they must turn into multiple assembler instructions. */
3302 emit_move_multi_word (enum machine_mode mode, rtx x, rtx y)
3309 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
3311 /* If X is a push on the stack, do the push now and replace
3312 X with a reference to the stack pointer. */
3313 if (push_operand (x, mode))
3314 x = emit_move_resolve_push (mode, x);
3316 /* If we are in reload, see if either operand is a MEM whose address
3317 is scheduled for replacement. */
3318 if (reload_in_progress && MEM_P (x)
3319 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3320 x = replace_equiv_address_nv (x, inner);
3321 if (reload_in_progress && MEM_P (y)
3322 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3323 y = replace_equiv_address_nv (y, inner);
3327 need_clobber = false;
3329 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3332 rtx xpart = operand_subword (x, i, 1, mode);
3335 /* Do not generate code for a move if it would come entirely
3336 from the undefined bits of a paradoxical subreg. */
3337 if (undefined_operand_subword_p (y, i))
3340 ypart = operand_subword (y, i, 1, mode);
3342 /* If we can't get a part of Y, put Y into memory if it is a
3343 constant. Otherwise, force it into a register. Then we must
3344 be able to get a part of Y. */
3345 if (ypart == 0 && CONSTANT_P (y))
3347 y = use_anchored_address (force_const_mem (mode, y));
3348 ypart = operand_subword (y, i, 1, mode);
3350 else if (ypart == 0)
3351 ypart = operand_subword_force (y, i, mode);
3353 gcc_assert (xpart && ypart);
3355 need_clobber |= (GET_CODE (xpart) == SUBREG);
3357 last_insn = emit_move_insn (xpart, ypart);
3363 /* Show the output dies here. This is necessary for SUBREGs
3364 of pseudos since we cannot track their lifetimes correctly;
3365 hard regs shouldn't appear here except as return values.
3366 We never want to emit such a clobber after reload. */
3368 && ! (reload_in_progress || reload_completed)
3369 && need_clobber != 0)
3377 /* Low level part of emit_move_insn.
3378 Called just like emit_move_insn, but assumes X and Y
3379 are basically valid. */
3382 emit_move_insn_1 (rtx x, rtx y)
3384 enum machine_mode mode = GET_MODE (x);
3385 enum insn_code code;
3387 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
3389 code = optab_handler (mov_optab, mode);
3390 if (code != CODE_FOR_nothing)
3391 return emit_insn (GEN_FCN (code) (x, y));
3393 /* Expand complex moves by moving real part and imag part. */
3394 if (COMPLEX_MODE_P (mode))
3395 return emit_move_complex (mode, x, y);
3397 if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
3398 || ALL_FIXED_POINT_MODE_P (mode))
3400 rtx result = emit_move_via_integer (mode, x, y, true);
3402 /* If we can't find an integer mode, use multi words. */
3406 return emit_move_multi_word (mode, x, y);
3409 if (GET_MODE_CLASS (mode) == MODE_CC)
3410 return emit_move_ccmode (mode, x, y);
3412 /* Try using a move pattern for the corresponding integer mode. This is
3413 only safe when simplify_subreg can convert MODE constants into integer
3414 constants. At present, it can only do this reliably if the value
3415 fits within a HOST_WIDE_INT. */
3416 if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3418 rtx ret = emit_move_via_integer (mode, x, y, false);
3423 return emit_move_multi_word (mode, x, y);
3426 /* Generate code to copy Y into X.
3427 Both Y and X must have the same mode, except that
3428 Y can be a constant with VOIDmode.
3429 This mode cannot be BLKmode; use emit_block_move for that.
3431 Return the last instruction emitted. */
3434 emit_move_insn (rtx x, rtx y)
3436 enum machine_mode mode = GET_MODE (x);
3437 rtx y_cst = NULL_RTX;
3440 gcc_assert (mode != BLKmode
3441 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
3446 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3447 && (last_insn = compress_float_constant (x, y)))
3452 if (!targetm.legitimate_constant_p (mode, y))
3454 y = force_const_mem (mode, y);
3456 /* If the target's cannot_force_const_mem prevented the spill,
3457 assume that the target's move expanders will also take care
3458 of the non-legitimate constant. */
3462 y = use_anchored_address (y);
3466 /* If X or Y are memory references, verify that their addresses are valid
3469 && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
3471 && ! push_operand (x, GET_MODE (x))))
3472 x = validize_mem (x);
3475 && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
3476 MEM_ADDR_SPACE (y)))
3477 y = validize_mem (y);
3479 gcc_assert (mode != BLKmode);
3481 last_insn = emit_move_insn_1 (x, y);
3483 if (y_cst && REG_P (x)
3484 && (set = single_set (last_insn)) != NULL_RTX
3485 && SET_DEST (set) == x
3486 && ! rtx_equal_p (y_cst, SET_SRC (set)))
3487 set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
3492 /* If Y is representable exactly in a narrower mode, and the target can
3493 perform the extension directly from constant or memory, then emit the
3494 move as an extension. */
3497 compress_float_constant (rtx x, rtx y)
3499 enum machine_mode dstmode = GET_MODE (x);
3500 enum machine_mode orig_srcmode = GET_MODE (y);
3501 enum machine_mode srcmode;
3503 int oldcost, newcost;
3504 bool speed = optimize_insn_for_speed_p ();
3506 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3508 if (targetm.legitimate_constant_p (dstmode, y))
3509 oldcost = set_src_cost (y, speed);
3511 oldcost = set_src_cost (force_const_mem (dstmode, y), speed);
3513 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3514 srcmode != orig_srcmode;
3515 srcmode = GET_MODE_WIDER_MODE (srcmode))
3518 rtx trunc_y, last_insn;
3520 /* Skip if the target can't extend this way. */
3521 ic = can_extend_p (dstmode, srcmode, 0);
3522 if (ic == CODE_FOR_nothing)
3525 /* Skip if the narrowed value isn't exact. */
3526 if (! exact_real_truncate (srcmode, &r))
3529 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3531 if (targetm.legitimate_constant_p (srcmode, trunc_y))
3533 /* Skip if the target needs extra instructions to perform
3535 if (!insn_operand_matches (ic, 1, trunc_y))
3537 /* This is valid, but may not be cheaper than the original. */
3538 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3540 if (oldcost < newcost)
3543 else if (float_extend_from_mem[dstmode][srcmode])
3545 trunc_y = force_const_mem (srcmode, trunc_y);
3546 /* This is valid, but may not be cheaper than the original. */
3547 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3549 if (oldcost < newcost)
3551 trunc_y = validize_mem (trunc_y);
3556 /* For CSE's benefit, force the compressed constant pool entry
3557 into a new pseudo. This constant may be used in different modes,
3558 and if not, combine will put things back together for us. */
3559 trunc_y = force_reg (srcmode, trunc_y);
3560 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3561 last_insn = get_last_insn ();
3564 set_unique_reg_note (last_insn, REG_EQUAL, y);
3572 /* Pushing data onto the stack. */
3574 /* Push a block of length SIZE (perhaps variable)
3575 and return an rtx to address the beginning of the block.
3576 The value may be virtual_outgoing_args_rtx.
3578 EXTRA is the number of bytes of padding to push in addition to SIZE.
3579 BELOW nonzero means this padding comes at low addresses;
3580 otherwise, the padding comes at high addresses. */
3583 push_block (rtx size, int extra, int below)
3587 size = convert_modes (Pmode, ptr_mode, size, 1);
3588 if (CONSTANT_P (size))
3589 anti_adjust_stack (plus_constant (size, extra));
3590 else if (REG_P (size) && extra == 0)
3591 anti_adjust_stack (size);
3594 temp = copy_to_mode_reg (Pmode, size);
3596 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
3597 temp, 0, OPTAB_LIB_WIDEN);
3598 anti_adjust_stack (temp);
3601 #ifndef STACK_GROWS_DOWNWARD
3607 temp = virtual_outgoing_args_rtx;
3608 if (extra != 0 && below)
3609 temp = plus_constant (temp, extra);
3613 if (CONST_INT_P (size))
3614 temp = plus_constant (virtual_outgoing_args_rtx,
3615 -INTVAL (size) - (below ? 0 : extra));
3616 else if (extra != 0 && !below)
3617 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3618 negate_rtx (Pmode, plus_constant (size, extra)));
3620 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3621 negate_rtx (Pmode, size));
3624 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3627 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3630 mem_autoinc_base (rtx mem)
3634 rtx addr = XEXP (mem, 0);
3635 if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
3636 return XEXP (addr, 0);
3641 /* A utility routine used here, in reload, and in try_split. The insns
3642 after PREV up to and including LAST are known to adjust the stack,
3643 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3644 placing notes as appropriate. PREV may be NULL, indicating the
3645 entire insn sequence prior to LAST should be scanned.
3647 The set of allowed stack pointer modifications is small:
3648 (1) One or more auto-inc style memory references (aka pushes),
3649 (2) One or more addition/subtraction with the SP as destination,
3650 (3) A single move insn with the SP as destination,
3651 (4) A call_pop insn,
3652 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3654 Insns in the sequence that do not modify the SP are ignored,
3655 except for noreturn calls.
3657 The return value is the amount of adjustment that can be trivially
3658 verified, via immediate operand or auto-inc. If the adjustment
3659 cannot be trivially extracted, the return value is INT_MIN. */
3662 find_args_size_adjust (rtx insn)
3667 pat = PATTERN (insn);
3670 /* Look for a call_pop pattern. */
3673 /* We have to allow non-call_pop patterns for the case
3674 of emit_single_push_insn of a TLS address. */
3675 if (GET_CODE (pat) != PARALLEL)
3678 /* All call_pop have a stack pointer adjust in the parallel.
3679 The call itself is always first, and the stack adjust is
3680 usually last, so search from the end. */
3681 for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
3683 set = XVECEXP (pat, 0, i);
3684 if (GET_CODE (set) != SET)
3686 dest = SET_DEST (set);
3687 if (dest == stack_pointer_rtx)
3690 /* We'd better have found the stack pointer adjust. */
3693 /* Fall through to process the extracted SET and DEST
3694 as if it was a standalone insn. */
3696 else if (GET_CODE (pat) == SET)
3698 else if ((set = single_set (insn)) != NULL)
3700 else if (GET_CODE (pat) == PARALLEL)
3702 /* ??? Some older ports use a parallel with a stack adjust
3703 and a store for a PUSH_ROUNDING pattern, rather than a
3704 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3705 /* ??? See h8300 and m68k, pushqi1. */
3706 for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
3708 set = XVECEXP (pat, 0, i);
3709 if (GET_CODE (set) != SET)
3711 dest = SET_DEST (set);
3712 if (dest == stack_pointer_rtx)
3715 /* We do not expect an auto-inc of the sp in the parallel. */
3716 gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
3717 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3718 != stack_pointer_rtx);
3726 dest = SET_DEST (set);
3728 /* Look for direct modifications of the stack pointer. */
3729 if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
3731 /* Look for a trivial adjustment, otherwise assume nothing. */
3732 /* Note that the SPU restore_stack_block pattern refers to
3733 the stack pointer in V4SImode. Consider that non-trivial. */
3734 if (SCALAR_INT_MODE_P (GET_MODE (dest))
3735 && GET_CODE (SET_SRC (set)) == PLUS
3736 && XEXP (SET_SRC (set), 0) == stack_pointer_rtx
3737 && CONST_INT_P (XEXP (SET_SRC (set), 1)))
3738 return INTVAL (XEXP (SET_SRC (set), 1));
3739 /* ??? Reload can generate no-op moves, which will be cleaned
3740 up later. Recognize it and continue searching. */
3741 else if (rtx_equal_p (dest, SET_SRC (set)))
3744 return HOST_WIDE_INT_MIN;
3750 /* Otherwise only think about autoinc patterns. */
3751 if (mem_autoinc_base (dest) == stack_pointer_rtx)
3754 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3755 != stack_pointer_rtx);
3757 else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
3758 mem = SET_SRC (set);
3762 addr = XEXP (mem, 0);
3763 switch (GET_CODE (addr))
3767 return GET_MODE_SIZE (GET_MODE (mem));
3770 return -GET_MODE_SIZE (GET_MODE (mem));
3773 addr = XEXP (addr, 1);
3774 gcc_assert (GET_CODE (addr) == PLUS);
3775 gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
3776 gcc_assert (CONST_INT_P (XEXP (addr, 1)));
3777 return INTVAL (XEXP (addr, 1));
3785 fixup_args_size_notes (rtx prev, rtx last, int end_args_size)
3787 int args_size = end_args_size;
3788 bool saw_unknown = false;
3791 for (insn = last; insn != prev; insn = PREV_INSN (insn))
3793 HOST_WIDE_INT this_delta;
3795 if (!NONDEBUG_INSN_P (insn))
3798 this_delta = find_args_size_adjust (insn);
3799 if (this_delta == 0)
3802 || ACCUMULATE_OUTGOING_ARGS
3803 || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
3807 gcc_assert (!saw_unknown);
3808 if (this_delta == HOST_WIDE_INT_MIN)
3811 add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (args_size));
3812 #ifdef STACK_GROWS_DOWNWARD
3813 this_delta = -this_delta;
3815 args_size -= this_delta;
3818 return saw_unknown ? INT_MIN : args_size;
3821 #ifdef PUSH_ROUNDING
3822 /* Emit single push insn. */
3825 emit_single_push_insn_1 (enum machine_mode mode, rtx x, tree type)
3828 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3830 enum insn_code icode;
3832 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3833 /* If there is push pattern, use it. Otherwise try old way of throwing
3834 MEM representing push operation to move expander. */
3835 icode = optab_handler (push_optab, mode);
3836 if (icode != CODE_FOR_nothing)
3838 struct expand_operand ops[1];
3840 create_input_operand (&ops[0], x, mode);
3841 if (maybe_expand_insn (icode, 1, ops))
3844 if (GET_MODE_SIZE (mode) == rounded_size)
3845 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3846 /* If we are to pad downward, adjust the stack pointer first and
3847 then store X into the stack location using an offset. This is
3848 because emit_move_insn does not know how to pad; it does not have
3850 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3852 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3853 HOST_WIDE_INT offset;
3855 emit_move_insn (stack_pointer_rtx,
3856 expand_binop (Pmode,
3857 #ifdef STACK_GROWS_DOWNWARD
3863 GEN_INT (rounded_size),
3864 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3866 offset = (HOST_WIDE_INT) padding_size;
3867 #ifdef STACK_GROWS_DOWNWARD
3868 if (STACK_PUSH_CODE == POST_DEC)
3869 /* We have already decremented the stack pointer, so get the
3871 offset += (HOST_WIDE_INT) rounded_size;
3873 if (STACK_PUSH_CODE == POST_INC)
3874 /* We have already incremented the stack pointer, so get the
3876 offset -= (HOST_WIDE_INT) rounded_size;
3878 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3882 #ifdef STACK_GROWS_DOWNWARD
3883 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3884 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3885 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3887 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3888 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3889 GEN_INT (rounded_size));
3891 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3894 dest = gen_rtx_MEM (mode, dest_addr);
3898 set_mem_attributes (dest, type, 1);
3900 if (flag_optimize_sibling_calls)
3901 /* Function incoming arguments may overlap with sibling call
3902 outgoing arguments and we cannot allow reordering of reads
3903 from function arguments with stores to outgoing arguments
3904 of sibling calls. */
3905 set_mem_alias_set (dest, 0);
3907 emit_move_insn (dest, x);
3910 /* Emit and annotate a single push insn. */
3913 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
3915 int delta, old_delta = stack_pointer_delta;
3916 rtx prev = get_last_insn ();
3919 emit_single_push_insn_1 (mode, x, type);
3921 last = get_last_insn ();
3923 /* Notice the common case where we emitted exactly one insn. */
3924 if (PREV_INSN (last) == prev)
3926 add_reg_note (last, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
3930 delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
3931 gcc_assert (delta == INT_MIN || delta == old_delta);
3935 /* Generate code to push X onto the stack, assuming it has mode MODE and
3937 MODE is redundant except when X is a CONST_INT (since they don't
3939 SIZE is an rtx for the size of data to be copied (in bytes),
3940 needed only if X is BLKmode.
3942 ALIGN (in bits) is maximum alignment we can assume.
3944 If PARTIAL and REG are both nonzero, then copy that many of the first
3945 bytes of X into registers starting with REG, and push the rest of X.
3946 The amount of space pushed is decreased by PARTIAL bytes.
3947 REG must be a hard register in this case.
3948 If REG is zero but PARTIAL is not, take any all others actions for an
3949 argument partially in registers, but do not actually load any
3952 EXTRA is the amount in bytes of extra space to leave next to this arg.
3953 This is ignored if an argument block has already been allocated.
3955 On a machine that lacks real push insns, ARGS_ADDR is the address of
3956 the bottom of the argument block for this call. We use indexing off there
3957 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3958 argument block has not been preallocated.
3960 ARGS_SO_FAR is the size of args previously pushed for this call.
3962 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3963 for arguments passed in registers. If nonzero, it will be the number
3964 of bytes required. */
3967 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
3968 unsigned int align, int partial, rtx reg, int extra,
3969 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
3973 enum direction stack_direction
3974 #ifdef STACK_GROWS_DOWNWARD
3980 /* Decide where to pad the argument: `downward' for below,
3981 `upward' for above, or `none' for don't pad it.
3982 Default is below for small data on big-endian machines; else above. */
3983 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
3985 /* Invert direction if stack is post-decrement.
3987 if (STACK_PUSH_CODE == POST_DEC)
3988 if (where_pad != none)
3989 where_pad = (where_pad == downward ? upward : downward);
3994 || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
3996 /* Copy a block into the stack, entirely or partially. */
4003 offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4004 used = partial - offset;
4006 if (mode != BLKmode)
4008 /* A value is to be stored in an insufficiently aligned
4009 stack slot; copy via a suitably aligned slot if
4011 size = GEN_INT (GET_MODE_SIZE (mode));
4012 if (!MEM_P (xinner))
4014 temp = assign_temp (type, 0, 1, 1);
4015 emit_move_insn (temp, xinner);
4022 /* USED is now the # of bytes we need not copy to the stack
4023 because registers will take care of them. */
4026 xinner = adjust_address (xinner, BLKmode, used);
4028 /* If the partial register-part of the arg counts in its stack size,
4029 skip the part of stack space corresponding to the registers.
4030 Otherwise, start copying to the beginning of the stack space,
4031 by setting SKIP to 0. */
4032 skip = (reg_parm_stack_space == 0) ? 0 : used;
4034 #ifdef PUSH_ROUNDING
4035 /* Do it with several push insns if that doesn't take lots of insns
4036 and if there is no difficulty with push insns that skip bytes
4037 on the stack for alignment purposes. */
4040 && CONST_INT_P (size)
4042 && MEM_ALIGN (xinner) >= align
4043 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
4044 /* Here we avoid the case of a structure whose weak alignment
4045 forces many pushes of a small amount of data,
4046 and such small pushes do rounding that causes trouble. */
4047 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
4048 || align >= BIGGEST_ALIGNMENT
4049 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
4050 == (align / BITS_PER_UNIT)))
4051 && (HOST_WIDE_INT) PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
4053 /* Push padding now if padding above and stack grows down,
4054 or if padding below and stack grows up.
4055 But if space already allocated, this has already been done. */
4056 if (extra && args_addr == 0
4057 && where_pad != none && where_pad != stack_direction)
4058 anti_adjust_stack (GEN_INT (extra));
4060 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
4063 #endif /* PUSH_ROUNDING */
4067 /* Otherwise make space on the stack and copy the data
4068 to the address of that space. */
4070 /* Deduct words put into registers from the size we must copy. */
4073 if (CONST_INT_P (size))
4074 size = GEN_INT (INTVAL (size) - used);
4076 size = expand_binop (GET_MODE (size), sub_optab, size,
4077 GEN_INT (used), NULL_RTX, 0,
4081 /* Get the address of the stack space.
4082 In this case, we do not deal with EXTRA separately.
4083 A single stack adjust will do. */
4086 temp = push_block (size, extra, where_pad == downward);
4089 else if (CONST_INT_P (args_so_far))
4090 temp = memory_address (BLKmode,
4091 plus_constant (args_addr,
4092 skip + INTVAL (args_so_far)));
4094 temp = memory_address (BLKmode,
4095 plus_constant (gen_rtx_PLUS (Pmode,
4100 if (!ACCUMULATE_OUTGOING_ARGS)
4102 /* If the source is referenced relative to the stack pointer,
4103 copy it to another register to stabilize it. We do not need
4104 to do this if we know that we won't be changing sp. */
4106 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
4107 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
4108 temp = copy_to_reg (temp);
4111 target = gen_rtx_MEM (BLKmode, temp);
4113 /* We do *not* set_mem_attributes here, because incoming arguments
4114 may overlap with sibling call outgoing arguments and we cannot
4115 allow reordering of reads from function arguments with stores
4116 to outgoing arguments of sibling calls. We do, however, want
4117 to record the alignment of the stack slot. */
4118 /* ALIGN may well be better aligned than TYPE, e.g. due to
4119 PARM_BOUNDARY. Assume the caller isn't lying. */
4120 set_mem_align (target, align);
4122 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
4125 else if (partial > 0)
4127 /* Scalar partly in registers. */
4129 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
4132 /* # bytes of start of argument
4133 that we must make space for but need not store. */
4134 int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4135 int args_offset = INTVAL (args_so_far);
4138 /* Push padding now if padding above and stack grows down,
4139 or if padding below and stack grows up.
4140 But if space already allocated, this has already been done. */
4141 if (extra && args_addr == 0
4142 && where_pad != none && where_pad != stack_direction)
4143 anti_adjust_stack (GEN_INT (extra));
4145 /* If we make space by pushing it, we might as well push
4146 the real data. Otherwise, we can leave OFFSET nonzero
4147 and leave the space uninitialized. */
4151 /* Now NOT_STACK gets the number of words that we don't need to
4152 allocate on the stack. Convert OFFSET to words too. */
4153 not_stack = (partial - offset) / UNITS_PER_WORD;
4154 offset /= UNITS_PER_WORD;
4156 /* If the partial register-part of the arg counts in its stack size,
4157 skip the part of stack space corresponding to the registers.
4158 Otherwise, start copying to the beginning of the stack space,
4159 by setting SKIP to 0. */
4160 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
4162 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
4163 x = validize_mem (force_const_mem (mode, x));
4165 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4166 SUBREGs of such registers are not allowed. */
4167 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
4168 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
4169 x = copy_to_reg (x);
4171 /* Loop over all the words allocated on the stack for this arg. */
4172 /* We can do it by words, because any scalar bigger than a word
4173 has a size a multiple of a word. */
4174 #ifndef PUSH_ARGS_REVERSED
4175 for (i = not_stack; i < size; i++)
4177 for (i = size - 1; i >= not_stack; i--)
4179 if (i >= not_stack + offset)
4180 emit_push_insn (operand_subword_force (x, i, mode),
4181 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
4183 GEN_INT (args_offset + ((i - not_stack + skip)
4185 reg_parm_stack_space, alignment_pad);
4192 /* Push padding now if padding above and stack grows down,
4193 or if padding below and stack grows up.
4194 But if space already allocated, this has already been done. */
4195 if (extra && args_addr == 0
4196 && where_pad != none && where_pad != stack_direction)
4197 anti_adjust_stack (GEN_INT (extra));
4199 #ifdef PUSH_ROUNDING
4200 if (args_addr == 0 && PUSH_ARGS)
4201 emit_single_push_insn (mode, x, type);
4205 if (CONST_INT_P (args_so_far))
4207 = memory_address (mode,
4208 plus_constant (args_addr,
4209 INTVAL (args_so_far)));
4211 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
4213 dest = gen_rtx_MEM (mode, addr);
4215 /* We do *not* set_mem_attributes here, because incoming arguments
4216 may overlap with sibling call outgoing arguments and we cannot
4217 allow reordering of reads from function arguments with stores
4218 to outgoing arguments of sibling calls. We do, however, want
4219 to record the alignment of the stack slot. */
4220 /* ALIGN may well be better aligned than TYPE, e.g. due to
4221 PARM_BOUNDARY. Assume the caller isn't lying. */
4222 set_mem_align (dest, align);
4224 emit_move_insn (dest, x);
4228 /* If part should go in registers, copy that part
4229 into the appropriate registers. Do this now, at the end,
4230 since mem-to-mem copies above may do function calls. */
4231 if (partial > 0 && reg != 0)
4233 /* Handle calls that pass values in multiple non-contiguous locations.
4234 The Irix 6 ABI has examples of this. */
4235 if (GET_CODE (reg) == PARALLEL)
4236 emit_group_load (reg, x, type, -1);
4239 gcc_assert (partial % UNITS_PER_WORD == 0);
4240 move_block_to_reg (REGNO (reg), x, partial / UNITS_PER_WORD, mode);
4244 if (extra && args_addr == 0 && where_pad == stack_direction)
4245 anti_adjust_stack (GEN_INT (extra));
4247 if (alignment_pad && args_addr == 0)
4248 anti_adjust_stack (alignment_pad);
4251 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4255 get_subtarget (rtx x)
4259 /* Only registers can be subtargets. */
4261 /* Don't use hard regs to avoid extending their life. */
4262 || REGNO (x) < FIRST_PSEUDO_REGISTER
4266 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4267 FIELD is a bitfield. Returns true if the optimization was successful,
4268 and there's nothing else to do. */
4271 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize,
4272 unsigned HOST_WIDE_INT bitpos,
4273 unsigned HOST_WIDE_INT bitregion_start,
4274 unsigned HOST_WIDE_INT bitregion_end,
4275 enum machine_mode mode1, rtx str_rtx,
4278 enum machine_mode str_mode = GET_MODE (str_rtx);
4279 unsigned int str_bitsize = GET_MODE_BITSIZE (str_mode);
4284 enum tree_code code;
4286 if (mode1 != VOIDmode
4287 || bitsize >= BITS_PER_WORD
4288 || str_bitsize > BITS_PER_WORD
4289 || TREE_SIDE_EFFECTS (to)
4290 || TREE_THIS_VOLATILE (to))
4294 if (TREE_CODE (src) != SSA_NAME)
4296 if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
4299 srcstmt = get_gimple_for_ssa_name (src);
4301 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
4304 code = gimple_assign_rhs_code (srcstmt);
4306 op0 = gimple_assign_rhs1 (srcstmt);
4308 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4309 to find its initialization. Hopefully the initialization will
4310 be from a bitfield load. */
4311 if (TREE_CODE (op0) == SSA_NAME)
4313 gimple op0stmt = get_gimple_for_ssa_name (op0);
4315 /* We want to eventually have OP0 be the same as TO, which
4316 should be a bitfield. */
4318 || !is_gimple_assign (op0stmt)
4319 || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
4321 op0 = gimple_assign_rhs1 (op0stmt);
4324 op1 = gimple_assign_rhs2 (srcstmt);
4326 if (!operand_equal_p (to, op0, 0))
4329 if (MEM_P (str_rtx))
4331 unsigned HOST_WIDE_INT offset1;
4333 if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
4334 str_mode = word_mode;
4335 str_mode = get_best_mode (bitsize, bitpos,
4336 bitregion_start, bitregion_end,
4337 MEM_ALIGN (str_rtx), str_mode, 0);
4338 if (str_mode == VOIDmode)
4340 str_bitsize = GET_MODE_BITSIZE (str_mode);
4343 bitpos %= str_bitsize;
4344 offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
4345 str_rtx = adjust_address (str_rtx, str_mode, offset1);
4347 else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
4350 /* If the bit field covers the whole REG/MEM, store_field
4351 will likely generate better code. */
4352 if (bitsize >= str_bitsize)
4355 /* We can't handle fields split across multiple entities. */
4356 if (bitpos + bitsize > str_bitsize)
4359 if (BYTES_BIG_ENDIAN)
4360 bitpos = str_bitsize - bitpos - bitsize;
4366 /* For now, just optimize the case of the topmost bitfield
4367 where we don't need to do any masking and also
4368 1 bit bitfields where xor can be used.
4369 We might win by one instruction for the other bitfields
4370 too if insv/extv instructions aren't used, so that
4371 can be added later. */
4372 if (bitpos + bitsize != str_bitsize
4373 && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
4376 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4377 value = convert_modes (str_mode,
4378 TYPE_MODE (TREE_TYPE (op1)), value,
4379 TYPE_UNSIGNED (TREE_TYPE (op1)));
4381 /* We may be accessing data outside the field, which means
4382 we can alias adjacent data. */
4383 if (MEM_P (str_rtx))
4385 str_rtx = shallow_copy_rtx (str_rtx);
4386 set_mem_alias_set (str_rtx, 0);
4387 set_mem_expr (str_rtx, 0);
4390 binop = code == PLUS_EXPR ? add_optab : sub_optab;
4391 if (bitsize == 1 && bitpos + bitsize != str_bitsize)
4393 value = expand_and (str_mode, value, const1_rtx, NULL);
4396 value = expand_shift (LSHIFT_EXPR, str_mode, value,
4397 bitpos, NULL_RTX, 1);
4398 result = expand_binop (str_mode, binop, str_rtx,
4399 value, str_rtx, 1, OPTAB_WIDEN);
4400 if (result != str_rtx)
4401 emit_move_insn (str_rtx, result);
4406 if (TREE_CODE (op1) != INTEGER_CST)
4408 value = expand_expr (op1, NULL_RTX, GET_MODE (str_rtx), EXPAND_NORMAL);
4409 value = convert_modes (GET_MODE (str_rtx),
4410 TYPE_MODE (TREE_TYPE (op1)), value,
4411 TYPE_UNSIGNED (TREE_TYPE (op1)));
4413 /* We may be accessing data outside the field, which means
4414 we can alias adjacent data. */
4415 if (MEM_P (str_rtx))
4417 str_rtx = shallow_copy_rtx (str_rtx);
4418 set_mem_alias_set (str_rtx, 0);
4419 set_mem_expr (str_rtx, 0);
4422 binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
4423 if (bitpos + bitsize != GET_MODE_BITSIZE (GET_MODE (str_rtx)))
4425 rtx mask = GEN_INT (((unsigned HOST_WIDE_INT) 1 << bitsize)
4427 value = expand_and (GET_MODE (str_rtx), value, mask,
4430 value = expand_shift (LSHIFT_EXPR, GET_MODE (str_rtx), value,
4431 bitpos, NULL_RTX, 1);
4432 result = expand_binop (GET_MODE (str_rtx), binop, str_rtx,
4433 value, str_rtx, 1, OPTAB_WIDEN);
4434 if (result != str_rtx)
4435 emit_move_insn (str_rtx, result);
4445 /* In the C++ memory model, consecutive bit fields in a structure are
4446 considered one memory location.
4448 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4449 returns the bit range of consecutive bits in which this COMPONENT_REF
4450 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4451 and *OFFSET may be adjusted in the process.
4453 If the access does not need to be restricted, 0 is returned in both
4454 *BITSTART and *BITEND. */
4457 get_bit_range (unsigned HOST_WIDE_INT *bitstart,
4458 unsigned HOST_WIDE_INT *bitend,
4460 HOST_WIDE_INT *bitpos,
4463 HOST_WIDE_INT bitoffset;
4466 gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
4468 field = TREE_OPERAND (exp, 1);
4469 repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
4470 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4471 need to limit the range we can access. */
4474 *bitstart = *bitend = 0;
4478 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4479 part of a larger bit field, then the representative does not serve any
4480 useful purpose. This can occur in Ada. */
4481 if (handled_component_p (TREE_OPERAND (exp, 0)))
4483 enum machine_mode rmode;
4484 HOST_WIDE_INT rbitsize, rbitpos;
4488 get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
4489 &roffset, &rmode, &unsignedp, &volatilep, false);
4490 if ((rbitpos % BITS_PER_UNIT) != 0)
4492 *bitstart = *bitend = 0;
4497 /* Compute the adjustment to bitpos from the offset of the field
4498 relative to the representative. DECL_FIELD_OFFSET of field and
4499 repr are the same by construction if they are not constants,
4500 see finish_bitfield_layout. */
4501 if (host_integerp (DECL_FIELD_OFFSET (field), 1)
4502 && host_integerp (DECL_FIELD_OFFSET (repr), 1))
4503 bitoffset = (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
4504 - tree_low_cst (DECL_FIELD_OFFSET (repr), 1)) * BITS_PER_UNIT;
4507 bitoffset += (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
4508 - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1));
4510 /* If the adjustment is larger than bitpos, we would have a negative bit
4511 position for the lower bound and this may wreak havoc later. This can
4512 occur only if we have a non-null offset, so adjust offset and bitpos
4513 to make the lower bound non-negative. */
4514 if (bitoffset > *bitpos)
4516 HOST_WIDE_INT adjust = bitoffset - *bitpos;
4518 gcc_assert ((adjust % BITS_PER_UNIT) == 0);
4519 gcc_assert (*offset != NULL_TREE);
4523 = size_binop (MINUS_EXPR, *offset, size_int (adjust / BITS_PER_UNIT));
4527 *bitstart = *bitpos - bitoffset;
4529 *bitend = *bitstart + tree_low_cst (DECL_SIZE (repr), 1) - 1;
4532 /* Returns true if the MEM_REF REF refers to an object that does not
4533 reside in memory and has non-BLKmode. */
4536 mem_ref_refers_to_non_mem_p (tree ref)
4538 tree base = TREE_OPERAND (ref, 0);
4539 if (TREE_CODE (base) != ADDR_EXPR)
4541 base = TREE_OPERAND (base, 0);
4542 return (DECL_P (base)
4543 && !TREE_ADDRESSABLE (base)
4544 && DECL_MODE (base) != BLKmode
4545 && DECL_RTL_SET_P (base)
4546 && !MEM_P (DECL_RTL (base)));
4549 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4550 is true, try generating a nontemporal store. */
4553 expand_assignment (tree to, tree from, bool nontemporal)
4557 enum machine_mode mode;
4559 enum insn_code icode;
4561 /* Don't crash if the lhs of the assignment was erroneous. */
4562 if (TREE_CODE (to) == ERROR_MARK)
4564 expand_normal (from);
4568 /* Optimize away no-op moves without side-effects. */
4569 if (operand_equal_p (to, from, 0))
4572 /* Handle misaligned stores. */
4573 mode = TYPE_MODE (TREE_TYPE (to));
4574 if ((TREE_CODE (to) == MEM_REF
4575 || TREE_CODE (to) == TARGET_MEM_REF)
4577 && !mem_ref_refers_to_non_mem_p (to)
4578 && ((align = get_object_or_type_alignment (to))
4579 < GET_MODE_ALIGNMENT (mode))
4580 && ((icode = optab_handler (movmisalign_optab, mode))
4581 != CODE_FOR_nothing))
4584 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (to, 0))));
4585 struct expand_operand ops[2];
4586 enum machine_mode address_mode;
4589 reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4590 reg = force_not_mem (reg);
4592 if (TREE_CODE (to) == MEM_REF)
4594 tree base = TREE_OPERAND (to, 0);
4595 address_mode = targetm.addr_space.address_mode (as);
4596 op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4597 op0 = convert_memory_address_addr_space (address_mode, op0, as);
4598 if (!integer_zerop (TREE_OPERAND (to, 1)))
4601 = immed_double_int_const (mem_ref_offset (to), address_mode);
4602 op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
4604 op0 = memory_address_addr_space (mode, op0, as);
4605 mem = gen_rtx_MEM (mode, op0);
4606 set_mem_attributes (mem, to, 0);
4607 set_mem_addr_space (mem, as);
4609 else if (TREE_CODE (to) == TARGET_MEM_REF)
4611 struct mem_address addr;
4612 get_address_description (to, &addr);
4613 op0 = addr_for_mem_ref (&addr, as, true);
4614 op0 = memory_address_addr_space (mode, op0, as);
4615 mem = gen_rtx_MEM (mode, op0);
4616 set_mem_attributes (mem, to, 0);
4617 set_mem_addr_space (mem, as);
4621 if (TREE_THIS_VOLATILE (to))
4622 MEM_VOLATILE_P (mem) = 1;
4624 create_fixed_operand (&ops[0], mem);
4625 create_input_operand (&ops[1], reg, mode);
4626 /* The movmisalign<mode> pattern cannot fail, else the assignment would
4627 silently be omitted. */
4628 expand_insn (icode, 2, ops);
4632 /* Assignment of a structure component needs special treatment
4633 if the structure component's rtx is not simply a MEM.
4634 Assignment of an array element at a constant index, and assignment of
4635 an array element in an unaligned packed structure field, has the same
4636 problem. Same for (partially) storing into a non-memory object. */
4637 if (handled_component_p (to)
4638 || (TREE_CODE (to) == MEM_REF
4639 && mem_ref_refers_to_non_mem_p (to))
4640 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
4642 enum machine_mode mode1;
4643 HOST_WIDE_INT bitsize, bitpos;
4644 unsigned HOST_WIDE_INT bitregion_start = 0;
4645 unsigned HOST_WIDE_INT bitregion_end = 0;
4654 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
4655 &unsignedp, &volatilep, true);
4657 if (TREE_CODE (to) == COMPONENT_REF
4658 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
4659 get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
4661 /* If we are going to use store_bit_field and extract_bit_field,
4662 make sure to_rtx will be safe for multiple use. */
4663 mode = TYPE_MODE (TREE_TYPE (tem));
4664 if (TREE_CODE (tem) == MEM_REF
4666 && ((align = get_object_or_type_alignment (tem))
4667 < GET_MODE_ALIGNMENT (mode))
4668 && ((icode = optab_handler (movmisalign_optab, mode))
4669 != CODE_FOR_nothing))
4671 enum machine_mode address_mode;
4673 struct expand_operand ops[2];
4674 addr_space_t as = TYPE_ADDR_SPACE
4675 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (tem, 0))));
4676 tree base = TREE_OPERAND (tem, 0);
4679 to_rtx = gen_reg_rtx (mode);
4681 address_mode = targetm.addr_space.address_mode (as);
4682 op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4683 op0 = convert_memory_address_addr_space (address_mode, op0, as);
4684 if (!integer_zerop (TREE_OPERAND (tem, 1)))
4686 rtx off = immed_double_int_const (mem_ref_offset (tem),
4688 op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
4690 op0 = memory_address_addr_space (mode, op0, as);
4691 mem = gen_rtx_MEM (mode, op0);
4692 set_mem_attributes (mem, tem, 0);
4693 set_mem_addr_space (mem, as);
4694 if (TREE_THIS_VOLATILE (tem))
4695 MEM_VOLATILE_P (mem) = 1;
4697 /* If the misaligned store doesn't overwrite all bits, perform
4698 rmw cycle on MEM. */
4699 if (bitsize != GET_MODE_BITSIZE (mode))
4701 create_input_operand (&ops[0], to_rtx, mode);
4702 create_fixed_operand (&ops[1], mem);
4703 /* The movmisalign<mode> pattern cannot fail, else the assignment
4704 would silently be omitted. */
4705 expand_insn (icode, 2, ops);
4707 mem = copy_rtx (mem);
4713 to_rtx = expand_normal (tem);
4716 /* If the bitfield is volatile, we want to access it in the
4717 field's mode, not the computed mode.
4718 If a MEM has VOIDmode (external with incomplete type),
4719 use BLKmode for it instead. */
4722 if (volatilep && flag_strict_volatile_bitfields > 0)
4723 to_rtx = adjust_address (to_rtx, mode1, 0);
4724 else if (GET_MODE (to_rtx) == VOIDmode)
4725 to_rtx = adjust_address (to_rtx, BLKmode, 0);
4730 enum machine_mode address_mode;
4733 if (!MEM_P (to_rtx))
4735 /* We can get constant negative offsets into arrays with broken
4736 user code. Translate this to a trap instead of ICEing. */
4737 gcc_assert (TREE_CODE (offset) == INTEGER_CST);
4738 expand_builtin_trap ();
4739 to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
4742 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
4744 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (to_rtx));
4745 if (GET_MODE (offset_rtx) != address_mode)
4746 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
4748 /* A constant address in TO_RTX can have VOIDmode, we must not try
4749 to call force_reg for that case. Avoid that case. */
4751 && GET_MODE (to_rtx) == BLKmode
4752 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
4754 && (bitpos % bitsize) == 0
4755 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
4756 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
4758 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
4762 to_rtx = offset_address (to_rtx, offset_rtx,
4763 highest_pow2_factor_for_target (to,
4767 /* No action is needed if the target is not a memory and the field
4768 lies completely outside that target. This can occur if the source
4769 code contains an out-of-bounds access to a small array. */
4771 && GET_MODE (to_rtx) != BLKmode
4772 && (unsigned HOST_WIDE_INT) bitpos
4773 >= GET_MODE_PRECISION (GET_MODE (to_rtx)))
4775 expand_normal (from);
4778 /* Handle expand_expr of a complex value returning a CONCAT. */
4779 else if (GET_CODE (to_rtx) == CONCAT)
4781 unsigned short mode_bitsize = GET_MODE_BITSIZE (GET_MODE (to_rtx));
4782 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from)))
4784 && bitsize == mode_bitsize)
4785 result = store_expr (from, to_rtx, false, nontemporal);
4786 else if (bitsize == mode_bitsize / 2
4787 && (bitpos == 0 || bitpos == mode_bitsize / 2))
4788 result = store_expr (from, XEXP (to_rtx, bitpos != 0), false,
4790 else if (bitpos + bitsize <= mode_bitsize / 2)
4791 result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
4792 bitregion_start, bitregion_end,
4793 mode1, from, TREE_TYPE (tem),
4794 get_alias_set (to), nontemporal);
4795 else if (bitpos >= mode_bitsize / 2)
4796 result = store_field (XEXP (to_rtx, 1), bitsize,
4797 bitpos - mode_bitsize / 2,
4798 bitregion_start, bitregion_end,
4800 TREE_TYPE (tem), get_alias_set (to),
4802 else if (bitpos == 0 && bitsize == mode_bitsize)
4805 result = expand_normal (from);
4806 from_rtx = simplify_gen_subreg (GET_MODE (to_rtx), result,
4807 TYPE_MODE (TREE_TYPE (from)), 0);
4808 emit_move_insn (XEXP (to_rtx, 0),
4809 read_complex_part (from_rtx, false));
4810 emit_move_insn (XEXP (to_rtx, 1),
4811 read_complex_part (from_rtx, true));
4815 rtx temp = assign_stack_temp (GET_MODE (to_rtx),
4816 GET_MODE_SIZE (GET_MODE (to_rtx)),
4818 write_complex_part (temp, XEXP (to_rtx, 0), false);
4819 write_complex_part (temp, XEXP (to_rtx, 1), true);
4820 result = store_field (temp, bitsize, bitpos,
4821 bitregion_start, bitregion_end,
4823 TREE_TYPE (tem), get_alias_set (to),
4825 emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
4826 emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
4833 /* If the field is at offset zero, we could have been given the
4834 DECL_RTX of the parent struct. Don't munge it. */
4835 to_rtx = shallow_copy_rtx (to_rtx);
4837 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
4839 /* Deal with volatile and readonly fields. The former is only
4840 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4842 MEM_VOLATILE_P (to_rtx) = 1;
4843 if (component_uses_parent_alias_set (to))
4844 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
4847 if (optimize_bitfield_assignment_op (bitsize, bitpos,
4848 bitregion_start, bitregion_end,
4853 result = store_field (to_rtx, bitsize, bitpos,
4854 bitregion_start, bitregion_end,
4856 TREE_TYPE (tem), get_alias_set (to),
4862 struct expand_operand ops[2];
4864 create_fixed_operand (&ops[0], mem);
4865 create_input_operand (&ops[1], to_rtx, mode);
4866 /* The movmisalign<mode> pattern cannot fail, else the assignment
4867 would silently be omitted. */
4868 expand_insn (icode, 2, ops);
4872 preserve_temp_slots (result);
4878 /* If the rhs is a function call and its value is not an aggregate,
4879 call the function before we start to compute the lhs.
4880 This is needed for correct code for cases such as
4881 val = setjmp (buf) on machines where reference to val
4882 requires loading up part of an address in a separate insn.
4884 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4885 since it might be a promoted variable where the zero- or sign- extension
4886 needs to be done. Handling this in the normal way is safe because no
4887 computation is done before the call. The same is true for SSA names. */
4888 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
4889 && COMPLETE_TYPE_P (TREE_TYPE (from))
4890 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
4891 && ! (((TREE_CODE (to) == VAR_DECL
4892 || TREE_CODE (to) == PARM_DECL
4893 || TREE_CODE (to) == RESULT_DECL)
4894 && REG_P (DECL_RTL (to)))
4895 || TREE_CODE (to) == SSA_NAME))
4900 value = expand_normal (from);
4902 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4904 /* Handle calls that return values in multiple non-contiguous locations.
4905 The Irix 6 ABI has examples of this. */
4906 if (GET_CODE (to_rtx) == PARALLEL)
4907 emit_group_load (to_rtx, value, TREE_TYPE (from),
4908 int_size_in_bytes (TREE_TYPE (from)));
4909 else if (GET_MODE (to_rtx) == BLKmode)
4910 emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
4913 if (POINTER_TYPE_P (TREE_TYPE (to)))
4914 value = convert_memory_address_addr_space
4915 (GET_MODE (to_rtx), value,
4916 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
4918 emit_move_insn (to_rtx, value);
4920 preserve_temp_slots (to_rtx);
4926 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4927 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4929 /* Don't move directly into a return register. */
4930 if (TREE_CODE (to) == RESULT_DECL
4931 && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
4936 if (REG_P (to_rtx) && TYPE_MODE (TREE_TYPE (from)) == BLKmode)
4937 temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
4939 temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
4941 if (GET_CODE (to_rtx) == PARALLEL)
4942 emit_group_load (to_rtx, temp, TREE_TYPE (from),
4943 int_size_in_bytes (TREE_TYPE (from)));
4945 emit_move_insn (to_rtx, temp);
4947 preserve_temp_slots (to_rtx);
4953 /* In case we are returning the contents of an object which overlaps
4954 the place the value is being stored, use a safe function when copying
4955 a value through a pointer into a structure value return block. */
4956 if (TREE_CODE (to) == RESULT_DECL
4957 && TREE_CODE (from) == INDIRECT_REF
4958 && ADDR_SPACE_GENERIC_P
4959 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
4960 && refs_may_alias_p (to, from)
4961 && cfun->returns_struct
4962 && !cfun->returns_pcc_struct)
4967 size = expr_size (from);
4968 from_rtx = expand_normal (from);
4970 emit_library_call (memmove_libfunc, LCT_NORMAL,
4971 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
4972 XEXP (from_rtx, 0), Pmode,
4973 convert_to_mode (TYPE_MODE (sizetype),
4974 size, TYPE_UNSIGNED (sizetype)),
4975 TYPE_MODE (sizetype));
4977 preserve_temp_slots (to_rtx);
4983 /* Compute FROM and store the value in the rtx we got. */
4986 result = store_expr (from, to_rtx, 0, nontemporal);
4987 preserve_temp_slots (result);
4993 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
4994 succeeded, false otherwise. */
4997 emit_storent_insn (rtx to, rtx from)
4999 struct expand_operand ops[2];
5000 enum machine_mode mode = GET_MODE (to);
5001 enum insn_code code = optab_handler (storent_optab, mode);
5003 if (code == CODE_FOR_nothing)
5006 create_fixed_operand (&ops[0], to);
5007 create_input_operand (&ops[1], from, mode);
5008 return maybe_expand_insn (code, 2, ops);
5011 /* Generate code for computing expression EXP,
5012 and storing the value into TARGET.
5014 If the mode is BLKmode then we may return TARGET itself.
5015 It turns out that in BLKmode it doesn't cause a problem.
5016 because C has no operators that could combine two different
5017 assignments into the same BLKmode object with different values
5018 with no sequence point. Will other languages need this to
5021 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5022 stack, and block moves may need to be treated specially.
5024 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5027 store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
5030 rtx alt_rtl = NULL_RTX;
5031 location_t loc = EXPR_LOCATION (exp);
5033 if (VOID_TYPE_P (TREE_TYPE (exp)))
5035 /* C++ can generate ?: expressions with a throw expression in one
5036 branch and an rvalue in the other. Here, we resolve attempts to
5037 store the throw expression's nonexistent result. */
5038 gcc_assert (!call_param_p);
5039 expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
5042 if (TREE_CODE (exp) == COMPOUND_EXPR)
5044 /* Perform first part of compound expression, then assign from second
5046 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
5047 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5048 return store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
5051 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
5053 /* For conditional expression, get safe form of the target. Then
5054 test the condition, doing the appropriate assignment on either
5055 side. This avoids the creation of unnecessary temporaries.
5056 For non-BLKmode, it is more efficient not to do this. */
5058 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
5060 do_pending_stack_adjust ();
5062 jumpifnot (TREE_OPERAND (exp, 0), lab1, -1);
5063 store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
5065 emit_jump_insn (gen_jump (lab2));
5068 store_expr (TREE_OPERAND (exp, 2), target, call_param_p,
5075 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
5076 /* If this is a scalar in a register that is stored in a wider mode
5077 than the declared mode, compute the result into its declared mode
5078 and then convert to the wider mode. Our value is the computed
5081 rtx inner_target = 0;
5083 /* We can do the conversion inside EXP, which will often result
5084 in some optimizations. Do the conversion in two steps: first
5085 change the signedness, if needed, then the extend. But don't
5086 do this if the type of EXP is a subtype of something else
5087 since then the conversion might involve more than just
5088 converting modes. */
5089 if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
5090 && TREE_TYPE (TREE_TYPE (exp)) == 0
5091 && GET_MODE_PRECISION (GET_MODE (target))
5092 == TYPE_PRECISION (TREE_TYPE (exp)))
5094 if (TYPE_UNSIGNED (TREE_TYPE (exp))
5095 != SUBREG_PROMOTED_UNSIGNED_P (target))
5097 /* Some types, e.g. Fortran's logical*4, won't have a signed
5098 version, so use the mode instead. */
5100 = (signed_or_unsigned_type_for
5101 (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)));
5103 ntype = lang_hooks.types.type_for_mode
5104 (TYPE_MODE (TREE_TYPE (exp)),
5105 SUBREG_PROMOTED_UNSIGNED_P (target));
5107 exp = fold_convert_loc (loc, ntype, exp);
5110 exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
5111 (GET_MODE (SUBREG_REG (target)),
5112 SUBREG_PROMOTED_UNSIGNED_P (target)),
5115 inner_target = SUBREG_REG (target);
5118 temp = expand_expr (exp, inner_target, VOIDmode,
5119 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5121 /* If TEMP is a VOIDmode constant, use convert_modes to make
5122 sure that we properly convert it. */
5123 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
5125 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5126 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
5127 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
5128 GET_MODE (target), temp,
5129 SUBREG_PROMOTED_UNSIGNED_P (target));
5132 convert_move (SUBREG_REG (target), temp,
5133 SUBREG_PROMOTED_UNSIGNED_P (target));
5137 else if ((TREE_CODE (exp) == STRING_CST
5138 || (TREE_CODE (exp) == MEM_REF
5139 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
5140 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
5142 && integer_zerop (TREE_OPERAND (exp, 1))))
5143 && !nontemporal && !call_param_p
5146 /* Optimize initialization of an array with a STRING_CST. */
5147 HOST_WIDE_INT exp_len, str_copy_len;
5149 tree str = TREE_CODE (exp) == STRING_CST
5150 ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5152 exp_len = int_expr_size (exp);
5156 if (TREE_STRING_LENGTH (str) <= 0)
5159 str_copy_len = strlen (TREE_STRING_POINTER (str));
5160 if (str_copy_len < TREE_STRING_LENGTH (str) - 1)
5163 str_copy_len = TREE_STRING_LENGTH (str);
5164 if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0
5165 && TREE_STRING_POINTER (str)[TREE_STRING_LENGTH (str) - 1] == '\0')
5167 str_copy_len += STORE_MAX_PIECES - 1;
5168 str_copy_len &= ~(STORE_MAX_PIECES - 1);
5170 str_copy_len = MIN (str_copy_len, exp_len);
5171 if (!can_store_by_pieces (str_copy_len, builtin_strncpy_read_str,
5172 CONST_CAST (char *, TREE_STRING_POINTER (str)),
5173 MEM_ALIGN (target), false))
5178 dest_mem = store_by_pieces (dest_mem,
5179 str_copy_len, builtin_strncpy_read_str,
5181 TREE_STRING_POINTER (str)),
5182 MEM_ALIGN (target), false,
5183 exp_len > str_copy_len ? 1 : 0);
5184 if (exp_len > str_copy_len)
5185 clear_storage (adjust_address (dest_mem, BLKmode, 0),
5186 GEN_INT (exp_len - str_copy_len),
5195 /* If we want to use a nontemporal store, force the value to
5197 tmp_target = nontemporal ? NULL_RTX : target;
5198 temp = expand_expr_real (exp, tmp_target, GET_MODE (target),
5200 ? EXPAND_STACK_PARM : EXPAND_NORMAL),
5204 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5205 the same as that of TARGET, adjust the constant. This is needed, for
5206 example, in case it is a CONST_DOUBLE and we want only a word-sized
5208 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
5209 && TREE_CODE (exp) != ERROR_MARK
5210 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
5211 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5212 temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5214 /* If value was not generated in the target, store it there.
5215 Convert the value to TARGET's type first if necessary and emit the
5216 pending incrementations that have been queued when expanding EXP.
5217 Note that we cannot emit the whole queue blindly because this will
5218 effectively disable the POST_INC optimization later.
5220 If TEMP and TARGET compare equal according to rtx_equal_p, but
5221 one or both of them are volatile memory refs, we have to distinguish
5223 - expand_expr has used TARGET. In this case, we must not generate
5224 another copy. This can be detected by TARGET being equal according
5226 - expand_expr has not used TARGET - that means that the source just
5227 happens to have the same RTX form. Since temp will have been created
5228 by expand_expr, it will compare unequal according to == .
5229 We must generate a copy in this case, to reach the correct number
5230 of volatile memory references. */
5232 if ((! rtx_equal_p (temp, target)
5233 || (temp != target && (side_effects_p (temp)
5234 || side_effects_p (target))))
5235 && TREE_CODE (exp) != ERROR_MARK
5236 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5237 but TARGET is not valid memory reference, TEMP will differ
5238 from TARGET although it is really the same location. */
5240 && rtx_equal_p (alt_rtl, target)
5241 && !side_effects_p (alt_rtl)
5242 && !side_effects_p (target))
5243 /* If there's nothing to copy, don't bother. Don't call
5244 expr_size unless necessary, because some front-ends (C++)
5245 expr_size-hook must not be given objects that are not
5246 supposed to be bit-copied or bit-initialized. */
5247 && expr_size (exp) != const0_rtx)
5249 if (GET_MODE (temp) != GET_MODE (target)
5250 && GET_MODE (temp) != VOIDmode)
5252 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
5253 if (GET_MODE (target) == BLKmode
5254 && GET_MODE (temp) == BLKmode)
5255 emit_block_move (target, temp, expr_size (exp),
5257 ? BLOCK_OP_CALL_PARM
5258 : BLOCK_OP_NORMAL));
5259 else if (GET_MODE (target) == BLKmode)
5260 store_bit_field (target, INTVAL (expr_size (exp)) * BITS_PER_UNIT,
5261 0, 0, 0, GET_MODE (temp), temp);
5263 convert_move (target, temp, unsignedp);
5266 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
5268 /* Handle copying a string constant into an array. The string
5269 constant may be shorter than the array. So copy just the string's
5270 actual length, and clear the rest. First get the size of the data
5271 type of the string, which is actually the size of the target. */
5272 rtx size = expr_size (exp);
5274 if (CONST_INT_P (size)
5275 && INTVAL (size) < TREE_STRING_LENGTH (exp))
5276 emit_block_move (target, temp, size,
5278 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5281 enum machine_mode pointer_mode
5282 = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
5283 enum machine_mode address_mode
5284 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (target));
5286 /* Compute the size of the data to copy from the string. */
5288 = size_binop_loc (loc, MIN_EXPR,
5289 make_tree (sizetype, size),
5290 size_int (TREE_STRING_LENGTH (exp)));
5292 = expand_expr (copy_size, NULL_RTX, VOIDmode,
5294 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
5297 /* Copy that much. */
5298 copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
5299 TYPE_UNSIGNED (sizetype));
5300 emit_block_move (target, temp, copy_size_rtx,
5302 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5304 /* Figure out how much is left in TARGET that we have to clear.
5305 Do all calculations in pointer_mode. */
5306 if (CONST_INT_P (copy_size_rtx))
5308 size = plus_constant (size, -INTVAL (copy_size_rtx));
5309 target = adjust_address (target, BLKmode,
5310 INTVAL (copy_size_rtx));
5314 size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
5315 copy_size_rtx, NULL_RTX, 0,
5318 if (GET_MODE (copy_size_rtx) != address_mode)
5319 copy_size_rtx = convert_to_mode (address_mode,
5321 TYPE_UNSIGNED (sizetype));
5323 target = offset_address (target, copy_size_rtx,
5324 highest_pow2_factor (copy_size));
5325 label = gen_label_rtx ();
5326 emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
5327 GET_MODE (size), 0, label);
5330 if (size != const0_rtx)
5331 clear_storage (target, size, BLOCK_OP_NORMAL);
5337 /* Handle calls that return values in multiple non-contiguous locations.
5338 The Irix 6 ABI has examples of this. */
5339 else if (GET_CODE (target) == PARALLEL)
5340 emit_group_load (target, temp, TREE_TYPE (exp),
5341 int_size_in_bytes (TREE_TYPE (exp)));
5342 else if (GET_MODE (temp) == BLKmode)
5343 emit_block_move (target, temp, expr_size (exp),
5345 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5346 else if (nontemporal
5347 && emit_storent_insn (target, temp))
5348 /* If we managed to emit a nontemporal store, there is nothing else to
5353 temp = force_operand (temp, target);
5355 emit_move_insn (target, temp);
5362 /* Return true if field F of structure TYPE is a flexible array. */
5365 flexible_array_member_p (const_tree f, const_tree type)
5370 return (DECL_CHAIN (f) == NULL
5371 && TREE_CODE (tf) == ARRAY_TYPE
5373 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
5374 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
5375 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
5376 && int_size_in_bytes (type) >= 0);
5379 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5380 must have in order for it to completely initialize a value of type TYPE.
5381 Return -1 if the number isn't known.
5383 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5385 static HOST_WIDE_INT
5386 count_type_elements (const_tree type, bool for_ctor_p)
5388 switch (TREE_CODE (type))
5394 nelts = array_type_nelts (type);
5395 if (nelts && host_integerp (nelts, 1))
5397 unsigned HOST_WIDE_INT n;
5399 n = tree_low_cst (nelts, 1) + 1;
5400 if (n == 0 || for_ctor_p)
5403 return n * count_type_elements (TREE_TYPE (type), false);
5405 return for_ctor_p ? -1 : 1;
5410 unsigned HOST_WIDE_INT n;
5414 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5415 if (TREE_CODE (f) == FIELD_DECL)
5418 n += count_type_elements (TREE_TYPE (f), false);
5419 else if (!flexible_array_member_p (f, type))
5420 /* Don't count flexible arrays, which are not supposed
5421 to be initialized. */
5429 case QUAL_UNION_TYPE:
5434 gcc_assert (!for_ctor_p);
5435 /* Estimate the number of scalars in each field and pick the
5436 maximum. Other estimates would do instead; the idea is simply
5437 to make sure that the estimate is not sensitive to the ordering
5440 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5441 if (TREE_CODE (f) == FIELD_DECL)
5443 m = count_type_elements (TREE_TYPE (f), false);
5444 /* If the field doesn't span the whole union, add an extra
5445 scalar for the rest. */
5446 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
5447 TYPE_SIZE (type)) != 1)
5459 return TYPE_VECTOR_SUBPARTS (type);
5463 case FIXED_POINT_TYPE:
5468 case REFERENCE_TYPE:
5484 /* Helper for categorize_ctor_elements. Identical interface. */
5487 categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5488 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5490 unsigned HOST_WIDE_INT idx;
5491 HOST_WIDE_INT nz_elts, init_elts, num_fields;
5492 tree value, purpose, elt_type;
5494 /* Whether CTOR is a valid constant initializer, in accordance with what
5495 initializer_constant_valid_p does. If inferred from the constructor
5496 elements, true until proven otherwise. */
5497 bool const_from_elts_p = constructor_static_from_elts_p (ctor);
5498 bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
5503 elt_type = NULL_TREE;
5505 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
5507 HOST_WIDE_INT mult = 1;
5509 if (TREE_CODE (purpose) == RANGE_EXPR)
5511 tree lo_index = TREE_OPERAND (purpose, 0);
5512 tree hi_index = TREE_OPERAND (purpose, 1);
5514 if (host_integerp (lo_index, 1) && host_integerp (hi_index, 1))
5515 mult = (tree_low_cst (hi_index, 1)
5516 - tree_low_cst (lo_index, 1) + 1);
5519 elt_type = TREE_TYPE (value);
5521 switch (TREE_CODE (value))
5525 HOST_WIDE_INT nz = 0, ic = 0;
5527 bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &ic,
5530 nz_elts += mult * nz;
5531 init_elts += mult * ic;
5533 if (const_from_elts_p && const_p)
5534 const_p = const_elt_p;
5541 if (!initializer_zerop (value))
5547 nz_elts += mult * TREE_STRING_LENGTH (value);
5548 init_elts += mult * TREE_STRING_LENGTH (value);
5552 if (!initializer_zerop (TREE_REALPART (value)))
5554 if (!initializer_zerop (TREE_IMAGPART (value)))
5562 for (v = TREE_VECTOR_CST_ELTS (value); v; v = TREE_CHAIN (v))
5564 if (!initializer_zerop (TREE_VALUE (v)))
5573 HOST_WIDE_INT tc = count_type_elements (elt_type, false);
5574 nz_elts += mult * tc;
5575 init_elts += mult * tc;
5577 if (const_from_elts_p && const_p)
5578 const_p = initializer_constant_valid_p (value, elt_type)
5585 if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
5586 num_fields, elt_type))
5587 *p_complete = false;
5589 *p_nz_elts += nz_elts;
5590 *p_init_elts += init_elts;
5595 /* Examine CTOR to discover:
5596 * how many scalar fields are set to nonzero values,
5597 and place it in *P_NZ_ELTS;
5598 * how many scalar fields in total are in CTOR,
5599 and place it in *P_ELT_COUNT.
5600 * whether the constructor is complete -- in the sense that every
5601 meaningful byte is explicitly given a value --
5602 and place it in *P_COMPLETE.
5604 Return whether or not CTOR is a valid static constant initializer, the same
5605 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5608 categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5609 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5615 return categorize_ctor_elements_1 (ctor, p_nz_elts, p_init_elts, p_complete);
5618 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5619 of which had type LAST_TYPE. Each element was itself a complete
5620 initializer, in the sense that every meaningful byte was explicitly
5621 given a value. Return true if the same is true for the constructor
5625 complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
5626 const_tree last_type)
5628 if (TREE_CODE (type) == UNION_TYPE
5629 || TREE_CODE (type) == QUAL_UNION_TYPE)
5634 gcc_assert (num_elts == 1 && last_type);
5636 /* ??? We could look at each element of the union, and find the
5637 largest element. Which would avoid comparing the size of the
5638 initialized element against any tail padding in the union.
5639 Doesn't seem worth the effort... */
5640 return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
5643 return count_type_elements (type, true) == num_elts;
5646 /* Return 1 if EXP contains mostly (3/4) zeros. */
5649 mostly_zeros_p (const_tree exp)
5651 if (TREE_CODE (exp) == CONSTRUCTOR)
5653 HOST_WIDE_INT nz_elts, init_elts;
5656 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5657 return !complete_p || nz_elts < init_elts / 4;
5660 return initializer_zerop (exp);
5663 /* Return 1 if EXP contains all zeros. */
5666 all_zeros_p (const_tree exp)
5668 if (TREE_CODE (exp) == CONSTRUCTOR)
5670 HOST_WIDE_INT nz_elts, init_elts;
5673 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5674 return nz_elts == 0;
5677 return initializer_zerop (exp);
5680 /* Helper function for store_constructor.
5681 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5682 TYPE is the type of the CONSTRUCTOR, not the element type.
5683 CLEARED is as for store_constructor.
5684 ALIAS_SET is the alias set to use for any stores.
5686 This provides a recursive shortcut back to store_constructor when it isn't
5687 necessary to go through store_field. This is so that we can pass through
5688 the cleared field to let store_constructor know that we may not have to
5689 clear a substructure if the outer structure has already been cleared. */
5692 store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
5693 HOST_WIDE_INT bitpos, enum machine_mode mode,
5694 tree exp, tree type, int cleared,
5695 alias_set_type alias_set)
5697 if (TREE_CODE (exp) == CONSTRUCTOR
5698 /* We can only call store_constructor recursively if the size and
5699 bit position are on a byte boundary. */
5700 && bitpos % BITS_PER_UNIT == 0
5701 && (bitsize > 0 && bitsize % BITS_PER_UNIT == 0)
5702 /* If we have a nonzero bitpos for a register target, then we just
5703 let store_field do the bitfield handling. This is unlikely to
5704 generate unnecessary clear instructions anyways. */
5705 && (bitpos == 0 || MEM_P (target)))
5709 = adjust_address (target,
5710 GET_MODE (target) == BLKmode
5712 % GET_MODE_ALIGNMENT (GET_MODE (target)))
5713 ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
5716 /* Update the alias set, if required. */
5717 if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
5718 && MEM_ALIAS_SET (target) != 0)
5720 target = copy_rtx (target);
5721 set_mem_alias_set (target, alias_set);
5724 store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
5727 store_field (target, bitsize, bitpos, 0, 0, mode, exp, type, alias_set,
5731 /* Store the value of constructor EXP into the rtx TARGET.
5732 TARGET is either a REG or a MEM; we know it cannot conflict, since
5733 safe_from_p has been called.
5734 CLEARED is true if TARGET is known to have been zero'd.
5735 SIZE is the number of bytes of TARGET we are allowed to modify: this
5736 may not be the same as the size of EXP if we are assigning to a field
5737 which has been packed to exclude padding bits. */
5740 store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
5742 tree type = TREE_TYPE (exp);
5743 #ifdef WORD_REGISTER_OPERATIONS
5744 HOST_WIDE_INT exp_size = int_size_in_bytes (type);
5747 switch (TREE_CODE (type))
5751 case QUAL_UNION_TYPE:
5753 unsigned HOST_WIDE_INT idx;
5756 /* If size is zero or the target is already cleared, do nothing. */
5757 if (size == 0 || cleared)
5759 /* We either clear the aggregate or indicate the value is dead. */
5760 else if ((TREE_CODE (type) == UNION_TYPE
5761 || TREE_CODE (type) == QUAL_UNION_TYPE)
5762 && ! CONSTRUCTOR_ELTS (exp))
5763 /* If the constructor is empty, clear the union. */
5765 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
5769 /* If we are building a static constructor into a register,
5770 set the initial value as zero so we can fold the value into
5771 a constant. But if more than one register is involved,
5772 this probably loses. */
5773 else if (REG_P (target) && TREE_STATIC (exp)
5774 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
5776 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5780 /* If the constructor has fewer fields than the structure or
5781 if we are initializing the structure to mostly zeros, clear
5782 the whole structure first. Don't do this if TARGET is a
5783 register whose mode size isn't equal to SIZE since
5784 clear_storage can't handle this case. */
5786 && (((int)VEC_length (constructor_elt, CONSTRUCTOR_ELTS (exp))
5787 != fields_length (type))
5788 || mostly_zeros_p (exp))
5790 || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
5793 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5797 if (REG_P (target) && !cleared)
5798 emit_clobber (target);
5800 /* Store each element of the constructor into the
5801 corresponding field of TARGET. */
5802 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
5804 enum machine_mode mode;
5805 HOST_WIDE_INT bitsize;
5806 HOST_WIDE_INT bitpos = 0;
5808 rtx to_rtx = target;
5810 /* Just ignore missing fields. We cleared the whole
5811 structure, above, if any fields are missing. */
5815 if (cleared && initializer_zerop (value))
5818 if (host_integerp (DECL_SIZE (field), 1))
5819 bitsize = tree_low_cst (DECL_SIZE (field), 1);
5823 mode = DECL_MODE (field);
5824 if (DECL_BIT_FIELD (field))
5827 offset = DECL_FIELD_OFFSET (field);
5828 if (host_integerp (offset, 0)
5829 && host_integerp (bit_position (field), 0))
5831 bitpos = int_bit_position (field);
5835 bitpos = tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 0);
5839 enum machine_mode address_mode;
5843 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
5844 make_tree (TREE_TYPE (exp),
5847 offset_rtx = expand_normal (offset);
5848 gcc_assert (MEM_P (to_rtx));
5851 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (to_rtx));
5852 if (GET_MODE (offset_rtx) != address_mode)
5853 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
5855 to_rtx = offset_address (to_rtx, offset_rtx,
5856 highest_pow2_factor (offset));
5859 #ifdef WORD_REGISTER_OPERATIONS
5860 /* If this initializes a field that is smaller than a
5861 word, at the start of a word, try to widen it to a full
5862 word. This special case allows us to output C++ member
5863 function initializations in a form that the optimizers
5866 && bitsize < BITS_PER_WORD
5867 && bitpos % BITS_PER_WORD == 0
5868 && GET_MODE_CLASS (mode) == MODE_INT
5869 && TREE_CODE (value) == INTEGER_CST
5871 && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
5873 tree type = TREE_TYPE (value);
5875 if (TYPE_PRECISION (type) < BITS_PER_WORD)
5877 type = lang_hooks.types.type_for_size
5878 (BITS_PER_WORD, TYPE_UNSIGNED (type));
5879 value = fold_convert (type, value);
5882 if (BYTES_BIG_ENDIAN)
5884 = fold_build2 (LSHIFT_EXPR, type, value,
5885 build_int_cst (type,
5886 BITS_PER_WORD - bitsize));
5887 bitsize = BITS_PER_WORD;
5892 if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
5893 && DECL_NONADDRESSABLE_P (field))
5895 to_rtx = copy_rtx (to_rtx);
5896 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
5899 store_constructor_field (to_rtx, bitsize, bitpos, mode,
5900 value, type, cleared,
5901 get_alias_set (TREE_TYPE (field)));
5908 unsigned HOST_WIDE_INT i;
5911 tree elttype = TREE_TYPE (type);
5913 HOST_WIDE_INT minelt = 0;
5914 HOST_WIDE_INT maxelt = 0;
5916 domain = TYPE_DOMAIN (type);
5917 const_bounds_p = (TYPE_MIN_VALUE (domain)
5918 && TYPE_MAX_VALUE (domain)
5919 && host_integerp (TYPE_MIN_VALUE (domain), 0)
5920 && host_integerp (TYPE_MAX_VALUE (domain), 0));
5922 /* If we have constant bounds for the range of the type, get them. */
5925 minelt = tree_low_cst (TYPE_MIN_VALUE (domain), 0);
5926 maxelt = tree_low_cst (TYPE_MAX_VALUE (domain), 0);
5929 /* If the constructor has fewer elements than the array, clear
5930 the whole array first. Similarly if this is static
5931 constructor of a non-BLKmode object. */
5934 else if (REG_P (target) && TREE_STATIC (exp))
5938 unsigned HOST_WIDE_INT idx;
5940 HOST_WIDE_INT count = 0, zero_count = 0;
5941 need_to_clear = ! const_bounds_p;
5943 /* This loop is a more accurate version of the loop in
5944 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5945 is also needed to check for missing elements. */
5946 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
5948 HOST_WIDE_INT this_node_count;
5953 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5955 tree lo_index = TREE_OPERAND (index, 0);
5956 tree hi_index = TREE_OPERAND (index, 1);
5958 if (! host_integerp (lo_index, 1)
5959 || ! host_integerp (hi_index, 1))
5965 this_node_count = (tree_low_cst (hi_index, 1)
5966 - tree_low_cst (lo_index, 1) + 1);
5969 this_node_count = 1;
5971 count += this_node_count;
5972 if (mostly_zeros_p (value))
5973 zero_count += this_node_count;
5976 /* Clear the entire array first if there are any missing
5977 elements, or if the incidence of zero elements is >=
5980 && (count < maxelt - minelt + 1
5981 || 4 * zero_count >= 3 * count))
5985 if (need_to_clear && size > 0)
5988 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5990 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5994 if (!cleared && REG_P (target))
5995 /* Inform later passes that the old value is dead. */
5996 emit_clobber (target);
5998 /* Store each element of the constructor into the
5999 corresponding element of TARGET, determined by counting the
6001 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
6003 enum machine_mode mode;
6004 HOST_WIDE_INT bitsize;
6005 HOST_WIDE_INT bitpos;
6006 rtx xtarget = target;
6008 if (cleared && initializer_zerop (value))
6011 mode = TYPE_MODE (elttype);
6012 if (mode == BLKmode)
6013 bitsize = (host_integerp (TYPE_SIZE (elttype), 1)
6014 ? tree_low_cst (TYPE_SIZE (elttype), 1)
6017 bitsize = GET_MODE_BITSIZE (mode);
6019 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
6021 tree lo_index = TREE_OPERAND (index, 0);
6022 tree hi_index = TREE_OPERAND (index, 1);
6023 rtx index_r, pos_rtx;
6024 HOST_WIDE_INT lo, hi, count;
6027 /* If the range is constant and "small", unroll the loop. */
6029 && host_integerp (lo_index, 0)
6030 && host_integerp (hi_index, 0)
6031 && (lo = tree_low_cst (lo_index, 0),
6032 hi = tree_low_cst (hi_index, 0),
6033 count = hi - lo + 1,
6036 || (host_integerp (TYPE_SIZE (elttype), 1)
6037 && (tree_low_cst (TYPE_SIZE (elttype), 1) * count
6040 lo -= minelt; hi -= minelt;
6041 for (; lo <= hi; lo++)
6043 bitpos = lo * tree_low_cst (TYPE_SIZE (elttype), 0);
6046 && !MEM_KEEP_ALIAS_SET_P (target)
6047 && TREE_CODE (type) == ARRAY_TYPE
6048 && TYPE_NONALIASED_COMPONENT (type))
6050 target = copy_rtx (target);
6051 MEM_KEEP_ALIAS_SET_P (target) = 1;
6054 store_constructor_field
6055 (target, bitsize, bitpos, mode, value, type, cleared,
6056 get_alias_set (elttype));
6061 rtx loop_start = gen_label_rtx ();
6062 rtx loop_end = gen_label_rtx ();
6065 expand_normal (hi_index);
6067 index = build_decl (EXPR_LOCATION (exp),
6068 VAR_DECL, NULL_TREE, domain);
6069 index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
6070 SET_DECL_RTL (index, index_r);
6071 store_expr (lo_index, index_r, 0, false);
6073 /* Build the head of the loop. */
6074 do_pending_stack_adjust ();
6075 emit_label (loop_start);
6077 /* Assign value to element index. */
6079 fold_convert (ssizetype,
6080 fold_build2 (MINUS_EXPR,
6083 TYPE_MIN_VALUE (domain)));
6086 size_binop (MULT_EXPR, position,
6087 fold_convert (ssizetype,
6088 TYPE_SIZE_UNIT (elttype)));
6090 pos_rtx = expand_normal (position);
6091 xtarget = offset_address (target, pos_rtx,
6092 highest_pow2_factor (position));
6093 xtarget = adjust_address (xtarget, mode, 0);
6094 if (TREE_CODE (value) == CONSTRUCTOR)
6095 store_constructor (value, xtarget, cleared,
6096 bitsize / BITS_PER_UNIT);
6098 store_expr (value, xtarget, 0, false);
6100 /* Generate a conditional jump to exit the loop. */
6101 exit_cond = build2 (LT_EXPR, integer_type_node,
6103 jumpif (exit_cond, loop_end, -1);
6105 /* Update the loop counter, and jump to the head of
6107 expand_assignment (index,
6108 build2 (PLUS_EXPR, TREE_TYPE (index),
6109 index, integer_one_node),
6112 emit_jump (loop_start);
6114 /* Build the end of the loop. */
6115 emit_label (loop_end);
6118 else if ((index != 0 && ! host_integerp (index, 0))
6119 || ! host_integerp (TYPE_SIZE (elttype), 1))
6124 index = ssize_int (1);
6127 index = fold_convert (ssizetype,
6128 fold_build2 (MINUS_EXPR,
6131 TYPE_MIN_VALUE (domain)));
6134 size_binop (MULT_EXPR, index,
6135 fold_convert (ssizetype,
6136 TYPE_SIZE_UNIT (elttype)));
6137 xtarget = offset_address (target,
6138 expand_normal (position),
6139 highest_pow2_factor (position));
6140 xtarget = adjust_address (xtarget, mode, 0);
6141 store_expr (value, xtarget, 0, false);
6146 bitpos = ((tree_low_cst (index, 0) - minelt)
6147 * tree_low_cst (TYPE_SIZE (elttype), 1));
6149 bitpos = (i * tree_low_cst (TYPE_SIZE (elttype), 1));
6151 if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
6152 && TREE_CODE (type) == ARRAY_TYPE
6153 && TYPE_NONALIASED_COMPONENT (type))
6155 target = copy_rtx (target);
6156 MEM_KEEP_ALIAS_SET_P (target) = 1;
6158 store_constructor_field (target, bitsize, bitpos, mode, value,
6159 type, cleared, get_alias_set (elttype));
6167 unsigned HOST_WIDE_INT idx;
6168 constructor_elt *ce;
6172 tree elttype = TREE_TYPE (type);
6173 int elt_size = tree_low_cst (TYPE_SIZE (elttype), 1);
6174 enum machine_mode eltmode = TYPE_MODE (elttype);
6175 HOST_WIDE_INT bitsize;
6176 HOST_WIDE_INT bitpos;
6177 rtvec vector = NULL;
6179 alias_set_type alias;
6181 gcc_assert (eltmode != BLKmode);
6183 n_elts = TYPE_VECTOR_SUBPARTS (type);
6184 if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
6186 enum machine_mode mode = GET_MODE (target);
6188 icode = (int) optab_handler (vec_init_optab, mode);
6189 if (icode != CODE_FOR_nothing)
6193 vector = rtvec_alloc (n_elts);
6194 for (i = 0; i < n_elts; i++)
6195 RTVEC_ELT (vector, i) = CONST0_RTX (GET_MODE_INNER (mode));
6199 /* If the constructor has fewer elements than the vector,
6200 clear the whole array first. Similarly if this is static
6201 constructor of a non-BLKmode object. */
6204 else if (REG_P (target) && TREE_STATIC (exp))
6208 unsigned HOST_WIDE_INT count = 0, zero_count = 0;
6211 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
6213 int n_elts_here = tree_low_cst
6214 (int_const_binop (TRUNC_DIV_EXPR,
6215 TYPE_SIZE (TREE_TYPE (value)),
6216 TYPE_SIZE (elttype)), 1);
6218 count += n_elts_here;
6219 if (mostly_zeros_p (value))
6220 zero_count += n_elts_here;
6223 /* Clear the entire vector first if there are any missing elements,
6224 or if the incidence of zero elements is >= 75%. */
6225 need_to_clear = (count < n_elts || 4 * zero_count >= 3 * count);
6228 if (need_to_clear && size > 0 && !vector)
6231 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6233 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6237 /* Inform later passes that the old value is dead. */
6238 if (!cleared && !vector && REG_P (target))
6239 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6242 alias = MEM_ALIAS_SET (target);
6244 alias = get_alias_set (elttype);
6246 /* Store each element of the constructor into the corresponding
6247 element of TARGET, determined by counting the elements. */
6248 for (idx = 0, i = 0;
6249 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), idx, ce);
6250 idx++, i += bitsize / elt_size)
6252 HOST_WIDE_INT eltpos;
6253 tree value = ce->value;
6255 bitsize = tree_low_cst (TYPE_SIZE (TREE_TYPE (value)), 1);
6256 if (cleared && initializer_zerop (value))
6260 eltpos = tree_low_cst (ce->index, 1);
6266 /* Vector CONSTRUCTORs should only be built from smaller
6267 vectors in the case of BLKmode vectors. */
6268 gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
6269 RTVEC_ELT (vector, eltpos)
6270 = expand_normal (value);
6274 enum machine_mode value_mode =
6275 TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
6276 ? TYPE_MODE (TREE_TYPE (value))
6278 bitpos = eltpos * elt_size;
6279 store_constructor_field (target, bitsize, bitpos,
6280 value_mode, value, type,
6286 emit_insn (GEN_FCN (icode)
6288 gen_rtx_PARALLEL (GET_MODE (target), vector)));
6297 /* Store the value of EXP (an expression tree)
6298 into a subfield of TARGET which has mode MODE and occupies
6299 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6300 If MODE is VOIDmode, it means that we are storing into a bit-field.
6302 BITREGION_START is bitpos of the first bitfield in this region.
6303 BITREGION_END is the bitpos of the ending bitfield in this region.
6304 These two fields are 0, if the C++ memory model does not apply,
6305 or we are not interested in keeping track of bitfield regions.
6307 Always return const0_rtx unless we have something particular to
6310 TYPE is the type of the underlying object,
6312 ALIAS_SET is the alias set for the destination. This value will
6313 (in general) be different from that for TARGET, since TARGET is a
6314 reference to the containing structure.
6316 If NONTEMPORAL is true, try generating a nontemporal store. */
6319 store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
6320 unsigned HOST_WIDE_INT bitregion_start,
6321 unsigned HOST_WIDE_INT bitregion_end,
6322 enum machine_mode mode, tree exp, tree type,
6323 alias_set_type alias_set, bool nontemporal)
6325 if (TREE_CODE (exp) == ERROR_MARK)
6328 /* If we have nothing to store, do nothing unless the expression has
6331 return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
6333 /* If we are storing into an unaligned field of an aligned union that is
6334 in a register, we may have the mode of TARGET being an integer mode but
6335 MODE == BLKmode. In that case, get an aligned object whose size and
6336 alignment are the same as TARGET and store TARGET into it (we can avoid
6337 the store if the field being stored is the entire width of TARGET). Then
6338 call ourselves recursively to store the field into a BLKmode version of
6339 that object. Finally, load from the object into TARGET. This is not
6340 very efficient in general, but should only be slightly more expensive
6341 than the otherwise-required unaligned accesses. Perhaps this can be
6342 cleaned up later. It's tempting to make OBJECT readonly, but it's set
6343 twice, once with emit_move_insn and once via store_field. */
6346 && (REG_P (target) || GET_CODE (target) == SUBREG))
6348 rtx object = assign_temp (type, 0, 1, 1);
6349 rtx blk_object = adjust_address (object, BLKmode, 0);
6351 if (bitsize != (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (target)))
6352 emit_move_insn (object, target);
6354 store_field (blk_object, bitsize, bitpos,
6355 bitregion_start, bitregion_end,
6356 mode, exp, type, MEM_ALIAS_SET (blk_object), nontemporal);
6358 emit_move_insn (target, object);
6360 /* We want to return the BLKmode version of the data. */
6364 if (GET_CODE (target) == CONCAT)
6366 /* We're storing into a struct containing a single __complex. */
6368 gcc_assert (!bitpos);
6369 return store_expr (exp, target, 0, nontemporal);
6372 /* If the structure is in a register or if the component
6373 is a bit field, we cannot use addressing to access it.
6374 Use bit-field techniques or SUBREG to store in it. */
6376 if (mode == VOIDmode
6377 || (mode != BLKmode && ! direct_store[(int) mode]
6378 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
6379 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
6381 || GET_CODE (target) == SUBREG
6382 /* If the field isn't aligned enough to store as an ordinary memref,
6383 store it as a bit field. */
6385 && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
6386 || bitpos % GET_MODE_ALIGNMENT (mode))
6387 && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
6388 || (bitpos % BITS_PER_UNIT != 0)))
6389 || (bitsize >= 0 && mode != BLKmode
6390 && GET_MODE_BITSIZE (mode) > bitsize)
6391 /* If the RHS and field are a constant size and the size of the
6392 RHS isn't the same size as the bitfield, we must use bitfield
6395 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
6396 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0)
6397 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6398 decl we must use bitfield operations. */
6400 && TREE_CODE (exp) == MEM_REF
6401 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6402 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6403 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0),0 ))
6404 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
6409 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6410 implies a mask operation. If the precision is the same size as
6411 the field we're storing into, that mask is redundant. This is
6412 particularly common with bit field assignments generated by the
6414 nop_def = get_def_for_expr (exp, NOP_EXPR);
6417 tree type = TREE_TYPE (exp);
6418 if (INTEGRAL_TYPE_P (type)
6419 && TYPE_PRECISION (type) < GET_MODE_BITSIZE (TYPE_MODE (type))
6420 && bitsize == TYPE_PRECISION (type))
6422 tree op = gimple_assign_rhs1 (nop_def);
6423 type = TREE_TYPE (op);
6424 if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) >= bitsize)
6429 temp = expand_normal (exp);
6431 /* If BITSIZE is narrower than the size of the type of EXP
6432 we will be narrowing TEMP. Normally, what's wanted are the
6433 low-order bits. However, if EXP's type is a record and this is
6434 big-endian machine, we want the upper BITSIZE bits. */
6435 if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
6436 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
6437 && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
6438 temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
6439 GET_MODE_BITSIZE (GET_MODE (temp)) - bitsize,
6442 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to
6444 if (mode != VOIDmode && mode != BLKmode
6445 && mode != TYPE_MODE (TREE_TYPE (exp)))
6446 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
6448 /* If the modes of TEMP and TARGET are both BLKmode, both
6449 must be in memory and BITPOS must be aligned on a byte
6450 boundary. If so, we simply do a block copy. Likewise
6451 for a BLKmode-like TARGET. */
6452 if (GET_MODE (temp) == BLKmode
6453 && (GET_MODE (target) == BLKmode
6455 && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
6456 && (bitpos % BITS_PER_UNIT) == 0
6457 && (bitsize % BITS_PER_UNIT) == 0)))
6459 gcc_assert (MEM_P (target) && MEM_P (temp)
6460 && (bitpos % BITS_PER_UNIT) == 0);
6462 target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
6463 emit_block_move (target, temp,
6464 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
6471 /* Store the value in the bitfield. */
6472 store_bit_field (target, bitsize, bitpos,
6473 bitregion_start, bitregion_end,
6480 /* Now build a reference to just the desired component. */
6481 rtx to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
6483 if (to_rtx == target)
6484 to_rtx = copy_rtx (to_rtx);
6486 if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
6487 set_mem_alias_set (to_rtx, alias_set);
6489 return store_expr (exp, to_rtx, 0, nontemporal);
6493 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6494 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6495 codes and find the ultimate containing object, which we return.
6497 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6498 bit position, and *PUNSIGNEDP to the signedness of the field.
6499 If the position of the field is variable, we store a tree
6500 giving the variable offset (in units) in *POFFSET.
6501 This offset is in addition to the bit position.
6502 If the position is not variable, we store 0 in *POFFSET.
6504 If any of the extraction expressions is volatile,
6505 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6507 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6508 Otherwise, it is a mode that can be used to access the field.
6510 If the field describes a variable-sized object, *PMODE is set to
6511 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6512 this case, but the address of the object can be found.
6514 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6515 look through nodes that serve as markers of a greater alignment than
6516 the one that can be deduced from the expression. These nodes make it
6517 possible for front-ends to prevent temporaries from being created by
6518 the middle-end on alignment considerations. For that purpose, the
6519 normal operating mode at high-level is to always pass FALSE so that
6520 the ultimate containing object is really returned; moreover, the
6521 associated predicate handled_component_p will always return TRUE
6522 on these nodes, thus indicating that they are essentially handled
6523 by get_inner_reference. TRUE should only be passed when the caller
6524 is scanning the expression in order to build another representation
6525 and specifically knows how to handle these nodes; as such, this is
6526 the normal operating mode in the RTL expanders. */
6529 get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
6530 HOST_WIDE_INT *pbitpos, tree *poffset,
6531 enum machine_mode *pmode, int *punsignedp,
6532 int *pvolatilep, bool keep_aligning)
6535 enum machine_mode mode = VOIDmode;
6536 bool blkmode_bitfield = false;
6537 tree offset = size_zero_node;
6538 double_int bit_offset = double_int_zero;
6540 /* First get the mode, signedness, and size. We do this from just the
6541 outermost expression. */
6543 if (TREE_CODE (exp) == COMPONENT_REF)
6545 tree field = TREE_OPERAND (exp, 1);
6546 size_tree = DECL_SIZE (field);
6547 if (!DECL_BIT_FIELD (field))
6548 mode = DECL_MODE (field);
6549 else if (DECL_MODE (field) == BLKmode)
6550 blkmode_bitfield = true;
6551 else if (TREE_THIS_VOLATILE (exp)
6552 && flag_strict_volatile_bitfields > 0)
6553 /* Volatile bitfields should be accessed in the mode of the
6554 field's type, not the mode computed based on the bit
6556 mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
6558 *punsignedp = DECL_UNSIGNED (field);
6560 else if (TREE_CODE (exp) == BIT_FIELD_REF)
6562 size_tree = TREE_OPERAND (exp, 1);
6563 *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
6564 || TYPE_UNSIGNED (TREE_TYPE (exp)));
6566 /* For vector types, with the correct size of access, use the mode of
6568 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
6569 && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
6570 && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
6571 mode = TYPE_MODE (TREE_TYPE (exp));
6575 mode = TYPE_MODE (TREE_TYPE (exp));
6576 *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
6578 if (mode == BLKmode)
6579 size_tree = TYPE_SIZE (TREE_TYPE (exp));
6581 *pbitsize = GET_MODE_BITSIZE (mode);
6586 if (! host_integerp (size_tree, 1))
6587 mode = BLKmode, *pbitsize = -1;
6589 *pbitsize = tree_low_cst (size_tree, 1);
6592 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6593 and find the ultimate containing object. */
6596 switch (TREE_CODE (exp))
6600 = double_int_add (bit_offset,
6601 tree_to_double_int (TREE_OPERAND (exp, 2)));
6606 tree field = TREE_OPERAND (exp, 1);
6607 tree this_offset = component_ref_field_offset (exp);
6609 /* If this field hasn't been filled in yet, don't go past it.
6610 This should only happen when folding expressions made during
6611 type construction. */
6612 if (this_offset == 0)
6615 offset = size_binop (PLUS_EXPR, offset, this_offset);
6616 bit_offset = double_int_add (bit_offset,
6618 (DECL_FIELD_BIT_OFFSET (field)));
6620 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6625 case ARRAY_RANGE_REF:
6627 tree index = TREE_OPERAND (exp, 1);
6628 tree low_bound = array_ref_low_bound (exp);
6629 tree unit_size = array_ref_element_size (exp);
6631 /* We assume all arrays have sizes that are a multiple of a byte.
6632 First subtract the lower bound, if any, in the type of the
6633 index, then convert to sizetype and multiply by the size of
6634 the array element. */
6635 if (! integer_zerop (low_bound))
6636 index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
6639 offset = size_binop (PLUS_EXPR, offset,
6640 size_binop (MULT_EXPR,
6641 fold_convert (sizetype, index),
6650 bit_offset = double_int_add (bit_offset,
6651 uhwi_to_double_int (*pbitsize));
6654 case VIEW_CONVERT_EXPR:
6655 if (keep_aligning && STRICT_ALIGNMENT
6656 && (TYPE_ALIGN (TREE_TYPE (exp))
6657 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
6658 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
6659 < BIGGEST_ALIGNMENT)
6660 && (TYPE_ALIGN_OK (TREE_TYPE (exp))
6661 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp, 0)))))
6666 /* Hand back the decl for MEM[&decl, off]. */
6667 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
6669 tree off = TREE_OPERAND (exp, 1);
6670 if (!integer_zerop (off))
6672 double_int boff, coff = mem_ref_offset (exp);
6673 boff = double_int_lshift (coff,
6675 ? 3 : exact_log2 (BITS_PER_UNIT),
6676 HOST_BITS_PER_DOUBLE_INT, true);
6677 bit_offset = double_int_add (bit_offset, boff);
6679 exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6687 /* If any reference in the chain is volatile, the effect is volatile. */
6688 if (TREE_THIS_VOLATILE (exp))
6691 exp = TREE_OPERAND (exp, 0);
6695 /* If OFFSET is constant, see if we can return the whole thing as a
6696 constant bit position. Make sure to handle overflow during
6698 if (TREE_CODE (offset) == INTEGER_CST)
6700 double_int tem = tree_to_double_int (offset);
6701 tem = double_int_sext (tem, TYPE_PRECISION (sizetype));
6702 tem = double_int_lshift (tem,
6704 ? 3 : exact_log2 (BITS_PER_UNIT),
6705 HOST_BITS_PER_DOUBLE_INT, true);
6706 tem = double_int_add (tem, bit_offset);
6707 if (double_int_fits_in_shwi_p (tem))
6709 *pbitpos = double_int_to_shwi (tem);
6710 *poffset = offset = NULL_TREE;
6714 /* Otherwise, split it up. */
6717 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6718 if (double_int_negative_p (bit_offset))
6721 = double_int_mask (BITS_PER_UNIT == 8
6722 ? 3 : exact_log2 (BITS_PER_UNIT));
6723 double_int tem = double_int_and_not (bit_offset, mask);
6724 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6725 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6726 bit_offset = double_int_sub (bit_offset, tem);
6727 tem = double_int_rshift (tem,
6729 ? 3 : exact_log2 (BITS_PER_UNIT),
6730 HOST_BITS_PER_DOUBLE_INT, true);
6731 offset = size_binop (PLUS_EXPR, offset,
6732 double_int_to_tree (sizetype, tem));
6735 *pbitpos = double_int_to_shwi (bit_offset);
6739 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6740 if (mode == VOIDmode
6742 && (*pbitpos % BITS_PER_UNIT) == 0
6743 && (*pbitsize % BITS_PER_UNIT) == 0)
6751 /* Given an expression EXP that may be a COMPONENT_REF, an ARRAY_REF or an
6752 ARRAY_RANGE_REF, look for whether EXP or any nested component-refs within
6753 EXP is marked as PACKED. */
6756 contains_packed_reference (const_tree exp)
6758 bool packed_p = false;
6762 switch (TREE_CODE (exp))
6766 tree field = TREE_OPERAND (exp, 1);
6767 packed_p = DECL_PACKED (field)
6768 || TYPE_PACKED (TREE_TYPE (field))
6769 || TYPE_PACKED (TREE_TYPE (exp));
6777 case ARRAY_RANGE_REF:
6780 case VIEW_CONVERT_EXPR:
6786 exp = TREE_OPERAND (exp, 0);
6792 /* Return a tree of sizetype representing the size, in bytes, of the element
6793 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6796 array_ref_element_size (tree exp)
6798 tree aligned_size = TREE_OPERAND (exp, 3);
6799 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
6800 location_t loc = EXPR_LOCATION (exp);
6802 /* If a size was specified in the ARRAY_REF, it's the size measured
6803 in alignment units of the element type. So multiply by that value. */
6806 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6807 sizetype from another type of the same width and signedness. */
6808 if (TREE_TYPE (aligned_size) != sizetype)
6809 aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
6810 return size_binop_loc (loc, MULT_EXPR, aligned_size,
6811 size_int (TYPE_ALIGN_UNIT (elmt_type)));
6814 /* Otherwise, take the size from that of the element type. Substitute
6815 any PLACEHOLDER_EXPR that we have. */
6817 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
6820 /* Return a tree representing the lower bound of the array mentioned in
6821 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6824 array_ref_low_bound (tree exp)
6826 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
6828 /* If a lower bound is specified in EXP, use it. */
6829 if (TREE_OPERAND (exp, 2))
6830 return TREE_OPERAND (exp, 2);
6832 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6833 substituting for a PLACEHOLDER_EXPR as needed. */
6834 if (domain_type && TYPE_MIN_VALUE (domain_type))
6835 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
6837 /* Otherwise, return a zero of the appropriate type. */
6838 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp, 1)), 0);
6841 /* Return a tree representing the upper bound of the array mentioned in
6842 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6845 array_ref_up_bound (tree exp)
6847 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
6849 /* If there is a domain type and it has an upper bound, use it, substituting
6850 for a PLACEHOLDER_EXPR as needed. */
6851 if (domain_type && TYPE_MAX_VALUE (domain_type))
6852 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
6854 /* Otherwise fail. */
6858 /* Return a tree representing the offset, in bytes, of the field referenced
6859 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6862 component_ref_field_offset (tree exp)
6864 tree aligned_offset = TREE_OPERAND (exp, 2);
6865 tree field = TREE_OPERAND (exp, 1);
6866 location_t loc = EXPR_LOCATION (exp);
6868 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6869 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6873 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6874 sizetype from another type of the same width and signedness. */
6875 if (TREE_TYPE (aligned_offset) != sizetype)
6876 aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
6877 return size_binop_loc (loc, MULT_EXPR, aligned_offset,
6878 size_int (DECL_OFFSET_ALIGN (field)
6882 /* Otherwise, take the offset from that of the field. Substitute
6883 any PLACEHOLDER_EXPR that we have. */
6885 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
6888 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6890 static unsigned HOST_WIDE_INT
6891 target_align (const_tree target)
6893 /* We might have a chain of nested references with intermediate misaligning
6894 bitfields components, so need to recurse to find out. */
6896 unsigned HOST_WIDE_INT this_align, outer_align;
6898 switch (TREE_CODE (target))
6904 this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
6905 outer_align = target_align (TREE_OPERAND (target, 0));
6906 return MIN (this_align, outer_align);
6909 case ARRAY_RANGE_REF:
6910 this_align = TYPE_ALIGN (TREE_TYPE (target));
6911 outer_align = target_align (TREE_OPERAND (target, 0));
6912 return MIN (this_align, outer_align);
6915 case NON_LVALUE_EXPR:
6916 case VIEW_CONVERT_EXPR:
6917 this_align = TYPE_ALIGN (TREE_TYPE (target));
6918 outer_align = target_align (TREE_OPERAND (target, 0));
6919 return MAX (this_align, outer_align);
6922 return TYPE_ALIGN (TREE_TYPE (target));
6927 /* Given an rtx VALUE that may contain additions and multiplications, return
6928 an equivalent value that just refers to a register, memory, or constant.
6929 This is done by generating instructions to perform the arithmetic and
6930 returning a pseudo-register containing the value.
6932 The returned value may be a REG, SUBREG, MEM or constant. */
6935 force_operand (rtx value, rtx target)
6938 /* Use subtarget as the target for operand 0 of a binary operation. */
6939 rtx subtarget = get_subtarget (target);
6940 enum rtx_code code = GET_CODE (value);
6942 /* Check for subreg applied to an expression produced by loop optimizer. */
6944 && !REG_P (SUBREG_REG (value))
6945 && !MEM_P (SUBREG_REG (value)))
6948 = simplify_gen_subreg (GET_MODE (value),
6949 force_reg (GET_MODE (SUBREG_REG (value)),
6950 force_operand (SUBREG_REG (value),
6952 GET_MODE (SUBREG_REG (value)),
6953 SUBREG_BYTE (value));
6954 code = GET_CODE (value);
6957 /* Check for a PIC address load. */
6958 if ((code == PLUS || code == MINUS)
6959 && XEXP (value, 0) == pic_offset_table_rtx
6960 && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
6961 || GET_CODE (XEXP (value, 1)) == LABEL_REF
6962 || GET_CODE (XEXP (value, 1)) == CONST))
6965 subtarget = gen_reg_rtx (GET_MODE (value));
6966 emit_move_insn (subtarget, value);
6970 if (ARITHMETIC_P (value))
6972 op2 = XEXP (value, 1);
6973 if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
6975 if (code == MINUS && CONST_INT_P (op2))
6978 op2 = negate_rtx (GET_MODE (value), op2);
6981 /* Check for an addition with OP2 a constant integer and our first
6982 operand a PLUS of a virtual register and something else. In that
6983 case, we want to emit the sum of the virtual register and the
6984 constant first and then add the other value. This allows virtual
6985 register instantiation to simply modify the constant rather than
6986 creating another one around this addition. */
6987 if (code == PLUS && CONST_INT_P (op2)
6988 && GET_CODE (XEXP (value, 0)) == PLUS
6989 && REG_P (XEXP (XEXP (value, 0), 0))
6990 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
6991 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
6993 rtx temp = expand_simple_binop (GET_MODE (value), code,
6994 XEXP (XEXP (value, 0), 0), op2,
6995 subtarget, 0, OPTAB_LIB_WIDEN);
6996 return expand_simple_binop (GET_MODE (value), code, temp,
6997 force_operand (XEXP (XEXP (value,
6999 target, 0, OPTAB_LIB_WIDEN);
7002 op1 = force_operand (XEXP (value, 0), subtarget);
7003 op2 = force_operand (op2, NULL_RTX);
7007 return expand_mult (GET_MODE (value), op1, op2, target, 1);
7009 if (!INTEGRAL_MODE_P (GET_MODE (value)))
7010 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7011 target, 1, OPTAB_LIB_WIDEN);
7013 return expand_divmod (0,
7014 FLOAT_MODE_P (GET_MODE (value))
7015 ? RDIV_EXPR : TRUNC_DIV_EXPR,
7016 GET_MODE (value), op1, op2, target, 0);
7018 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7021 return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
7024 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7027 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7028 target, 0, OPTAB_LIB_WIDEN);
7030 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7031 target, 1, OPTAB_LIB_WIDEN);
7034 if (UNARY_P (value))
7037 target = gen_reg_rtx (GET_MODE (value));
7038 op1 = force_operand (XEXP (value, 0), NULL_RTX);
7045 case FLOAT_TRUNCATE:
7046 convert_move (target, op1, code == ZERO_EXTEND);
7051 expand_fix (target, op1, code == UNSIGNED_FIX);
7055 case UNSIGNED_FLOAT:
7056 expand_float (target, op1, code == UNSIGNED_FLOAT);
7060 return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
7064 #ifdef INSN_SCHEDULING
7065 /* On machines that have insn scheduling, we want all memory reference to be
7066 explicit, so we need to deal with such paradoxical SUBREGs. */
7067 if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
7069 = simplify_gen_subreg (GET_MODE (value),
7070 force_reg (GET_MODE (SUBREG_REG (value)),
7071 force_operand (SUBREG_REG (value),
7073 GET_MODE (SUBREG_REG (value)),
7074 SUBREG_BYTE (value));
7080 /* Subroutine of expand_expr: return nonzero iff there is no way that
7081 EXP can reference X, which is being modified. TOP_P is nonzero if this
7082 call is going to be used to determine whether we need a temporary
7083 for EXP, as opposed to a recursive call to this function.
7085 It is always safe for this routine to return zero since it merely
7086 searches for optimization opportunities. */
7089 safe_from_p (const_rtx x, tree exp, int top_p)
7095 /* If EXP has varying size, we MUST use a target since we currently
7096 have no way of allocating temporaries of variable size
7097 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7098 So we assume here that something at a higher level has prevented a
7099 clash. This is somewhat bogus, but the best we can do. Only
7100 do this when X is BLKmode and when we are at the top level. */
7101 || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
7102 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
7103 && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
7104 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
7105 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
7107 && GET_MODE (x) == BLKmode)
7108 /* If X is in the outgoing argument area, it is always safe. */
7110 && (XEXP (x, 0) == virtual_outgoing_args_rtx
7111 || (GET_CODE (XEXP (x, 0)) == PLUS
7112 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
7115 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7116 find the underlying pseudo. */
7117 if (GET_CODE (x) == SUBREG)
7120 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7124 /* Now look at our tree code and possibly recurse. */
7125 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
7127 case tcc_declaration:
7128 exp_rtl = DECL_RTL_IF_SET (exp);
7134 case tcc_exceptional:
7135 if (TREE_CODE (exp) == TREE_LIST)
7139 if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
7141 exp = TREE_CHAIN (exp);
7144 if (TREE_CODE (exp) != TREE_LIST)
7145 return safe_from_p (x, exp, 0);
7148 else if (TREE_CODE (exp) == CONSTRUCTOR)
7150 constructor_elt *ce;
7151 unsigned HOST_WIDE_INT idx;
7153 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (exp), idx, ce)
7154 if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
7155 || !safe_from_p (x, ce->value, 0))
7159 else if (TREE_CODE (exp) == ERROR_MARK)
7160 return 1; /* An already-visited SAVE_EXPR? */
7165 /* The only case we look at here is the DECL_INITIAL inside a
7167 return (TREE_CODE (exp) != DECL_EXPR
7168 || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
7169 || !DECL_INITIAL (DECL_EXPR_DECL (exp))
7170 || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
7173 case tcc_comparison:
7174 if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
7179 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7181 case tcc_expression:
7184 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7185 the expression. If it is set, we conflict iff we are that rtx or
7186 both are in memory. Otherwise, we check all operands of the
7187 expression recursively. */
7189 switch (TREE_CODE (exp))
7192 /* If the operand is static or we are static, we can't conflict.
7193 Likewise if we don't conflict with the operand at all. */
7194 if (staticp (TREE_OPERAND (exp, 0))
7195 || TREE_STATIC (exp)
7196 || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
7199 /* Otherwise, the only way this can conflict is if we are taking
7200 the address of a DECL a that address if part of X, which is
7202 exp = TREE_OPERAND (exp, 0);
7205 if (!DECL_RTL_SET_P (exp)
7206 || !MEM_P (DECL_RTL (exp)))
7209 exp_rtl = XEXP (DECL_RTL (exp), 0);
7215 && alias_sets_conflict_p (MEM_ALIAS_SET (x),
7216 get_alias_set (exp)))
7221 /* Assume that the call will clobber all hard registers and
7223 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7228 case WITH_CLEANUP_EXPR:
7229 case CLEANUP_POINT_EXPR:
7230 /* Lowered by gimplify.c. */
7234 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7240 /* If we have an rtx, we do not need to scan our operands. */
7244 nops = TREE_OPERAND_LENGTH (exp);
7245 for (i = 0; i < nops; i++)
7246 if (TREE_OPERAND (exp, i) != 0
7247 && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
7253 /* Should never get a type here. */
7257 /* If we have an rtl, find any enclosed object. Then see if we conflict
7261 if (GET_CODE (exp_rtl) == SUBREG)
7263 exp_rtl = SUBREG_REG (exp_rtl);
7265 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
7269 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7270 are memory and they conflict. */
7271 return ! (rtx_equal_p (x, exp_rtl)
7272 || (MEM_P (x) && MEM_P (exp_rtl)
7273 && true_dependence (exp_rtl, VOIDmode, x)));
7276 /* If we reach here, it is safe. */
7281 /* Return the highest power of two that EXP is known to be a multiple of.
7282 This is used in updating alignment of MEMs in array references. */
7284 unsigned HOST_WIDE_INT
7285 highest_pow2_factor (const_tree exp)
7287 unsigned HOST_WIDE_INT c0, c1;
7289 switch (TREE_CODE (exp))
7292 /* We can find the lowest bit that's a one. If the low
7293 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
7294 We need to handle this case since we can find it in a COND_EXPR,
7295 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
7296 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
7298 if (TREE_OVERFLOW (exp))
7299 return BIGGEST_ALIGNMENT;
7302 /* Note: tree_low_cst is intentionally not used here,
7303 we don't care about the upper bits. */
7304 c0 = TREE_INT_CST_LOW (exp);
7306 return c0 ? c0 : BIGGEST_ALIGNMENT;
7310 case PLUS_EXPR: case MINUS_EXPR: case MIN_EXPR: case MAX_EXPR:
7311 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7312 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7313 return MIN (c0, c1);
7316 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7317 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7320 case ROUND_DIV_EXPR: case TRUNC_DIV_EXPR: case FLOOR_DIV_EXPR:
7322 if (integer_pow2p (TREE_OPERAND (exp, 1))
7323 && host_integerp (TREE_OPERAND (exp, 1), 1))
7325 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7326 c1 = tree_low_cst (TREE_OPERAND (exp, 1), 1);
7327 return MAX (1, c0 / c1);
7332 /* The highest power of two of a bit-and expression is the maximum of
7333 that of its operands. We typically get here for a complex LHS and
7334 a constant negative power of two on the RHS to force an explicit
7335 alignment, so don't bother looking at the LHS. */
7336 return highest_pow2_factor (TREE_OPERAND (exp, 1));
7340 return highest_pow2_factor (TREE_OPERAND (exp, 0));
7343 return highest_pow2_factor (TREE_OPERAND (exp, 1));
7346 c0 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7347 c1 = highest_pow2_factor (TREE_OPERAND (exp, 2));
7348 return MIN (c0, c1);
7357 /* Similar, except that the alignment requirements of TARGET are
7358 taken into account. Assume it is at least as aligned as its
7359 type, unless it is a COMPONENT_REF in which case the layout of
7360 the structure gives the alignment. */
7362 static unsigned HOST_WIDE_INT
7363 highest_pow2_factor_for_target (const_tree target, const_tree exp)
7365 unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
7366 unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
7368 return MAX (factor, talign);
7371 /* Subroutine of expand_expr. Expand the two operands of a binary
7372 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7373 The value may be stored in TARGET if TARGET is nonzero. The
7374 MODIFIER argument is as documented by expand_expr. */
7377 expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
7378 enum expand_modifier modifier)
7380 if (! safe_from_p (target, exp1, 1))
7382 if (operand_equal_p (exp0, exp1, 0))
7384 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7385 *op1 = copy_rtx (*op0);
7389 /* If we need to preserve evaluation order, copy exp0 into its own
7390 temporary variable so that it can't be clobbered by exp1. */
7391 if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
7392 exp0 = save_expr (exp0);
7393 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7394 *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
7399 /* Return a MEM that contains constant EXP. DEFER is as for
7400 output_constant_def and MODIFIER is as for expand_expr. */
7403 expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
7407 mem = output_constant_def (exp, defer);
7408 if (modifier != EXPAND_INITIALIZER)
7409 mem = use_anchored_address (mem);
7413 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7414 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7417 expand_expr_addr_expr_1 (tree exp, rtx target, enum machine_mode tmode,
7418 enum expand_modifier modifier, addr_space_t as)
7420 rtx result, subtarget;
7422 HOST_WIDE_INT bitsize, bitpos;
7423 int volatilep, unsignedp;
7424 enum machine_mode mode1;
7426 /* If we are taking the address of a constant and are at the top level,
7427 we have to use output_constant_def since we can't call force_const_mem
7429 /* ??? This should be considered a front-end bug. We should not be
7430 generating ADDR_EXPR of something that isn't an LVALUE. The only
7431 exception here is STRING_CST. */
7432 if (CONSTANT_CLASS_P (exp))
7434 result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
7435 if (modifier < EXPAND_SUM)
7436 result = force_operand (result, target);
7440 /* Everything must be something allowed by is_gimple_addressable. */
7441 switch (TREE_CODE (exp))
7444 /* This case will happen via recursion for &a->b. */
7445 return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7449 tree tem = TREE_OPERAND (exp, 0);
7450 if (!integer_zerop (TREE_OPERAND (exp, 1)))
7451 tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
7452 return expand_expr (tem, target, tmode, modifier);
7456 /* Expand the initializer like constants above. */
7457 result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
7459 if (modifier < EXPAND_SUM)
7460 result = force_operand (result, target);
7464 /* The real part of the complex number is always first, therefore
7465 the address is the same as the address of the parent object. */
7468 inner = TREE_OPERAND (exp, 0);
7472 /* The imaginary part of the complex number is always second.
7473 The expression is therefore always offset by the size of the
7476 bitpos = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)));
7477 inner = TREE_OPERAND (exp, 0);
7481 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7482 expand_expr, as that can have various side effects; LABEL_DECLs for
7483 example, may not have their DECL_RTL set yet. Expand the rtl of
7484 CONSTRUCTORs too, which should yield a memory reference for the
7485 constructor's contents. Assume language specific tree nodes can
7486 be expanded in some interesting way. */
7487 gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
7489 || TREE_CODE (exp) == CONSTRUCTOR
7490 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
7492 result = expand_expr (exp, target, tmode,
7493 modifier == EXPAND_INITIALIZER
7494 ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
7496 /* If the DECL isn't in memory, then the DECL wasn't properly
7497 marked TREE_ADDRESSABLE, which will be either a front-end
7498 or a tree optimizer bug. */
7500 if (TREE_ADDRESSABLE (exp)
7502 && ! targetm.calls.allocate_stack_slots_for_args())
7504 error ("local frame unavailable (naked function?)");
7508 gcc_assert (MEM_P (result));
7509 result = XEXP (result, 0);
7511 /* ??? Is this needed anymore? */
7512 if (DECL_P (exp) && !TREE_USED (exp) == 0)
7514 assemble_external (exp);
7515 TREE_USED (exp) = 1;
7518 if (modifier != EXPAND_INITIALIZER
7519 && modifier != EXPAND_CONST_ADDRESS
7520 && modifier != EXPAND_SUM)
7521 result = force_operand (result, target);
7525 /* Pass FALSE as the last argument to get_inner_reference although
7526 we are expanding to RTL. The rationale is that we know how to
7527 handle "aligning nodes" here: we can just bypass them because
7528 they won't change the final object whose address will be returned
7529 (they actually exist only for that purpose). */
7530 inner = get_inner_reference (exp, &bitsize, &bitpos, &offset,
7531 &mode1, &unsignedp, &volatilep, false);
7535 /* We must have made progress. */
7536 gcc_assert (inner != exp);
7538 subtarget = offset || bitpos ? NULL_RTX : target;
7539 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7540 inner alignment, force the inner to be sufficiently aligned. */
7541 if (CONSTANT_CLASS_P (inner)
7542 && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
7544 inner = copy_node (inner);
7545 TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
7546 TYPE_ALIGN (TREE_TYPE (inner)) = TYPE_ALIGN (TREE_TYPE (exp));
7547 TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
7549 result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
7555 if (modifier != EXPAND_NORMAL)
7556 result = force_operand (result, NULL);
7557 tmp = expand_expr (offset, NULL_RTX, tmode,
7558 modifier == EXPAND_INITIALIZER
7559 ? EXPAND_INITIALIZER : EXPAND_NORMAL);
7561 result = convert_memory_address_addr_space (tmode, result, as);
7562 tmp = convert_memory_address_addr_space (tmode, tmp, as);
7564 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7565 result = simplify_gen_binary (PLUS, tmode, result, tmp);
7568 subtarget = bitpos ? NULL_RTX : target;
7569 result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
7570 1, OPTAB_LIB_WIDEN);
7576 /* Someone beforehand should have rejected taking the address
7577 of such an object. */
7578 gcc_assert ((bitpos % BITS_PER_UNIT) == 0);
7580 result = plus_constant (result, bitpos / BITS_PER_UNIT);
7581 if (modifier < EXPAND_SUM)
7582 result = force_operand (result, target);
7588 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7589 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7592 expand_expr_addr_expr (tree exp, rtx target, enum machine_mode tmode,
7593 enum expand_modifier modifier)
7595 addr_space_t as = ADDR_SPACE_GENERIC;
7596 enum machine_mode address_mode = Pmode;
7597 enum machine_mode pointer_mode = ptr_mode;
7598 enum machine_mode rmode;
7601 /* Target mode of VOIDmode says "whatever's natural". */
7602 if (tmode == VOIDmode)
7603 tmode = TYPE_MODE (TREE_TYPE (exp));
7605 if (POINTER_TYPE_P (TREE_TYPE (exp)))
7607 as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
7608 address_mode = targetm.addr_space.address_mode (as);
7609 pointer_mode = targetm.addr_space.pointer_mode (as);
7612 /* We can get called with some Weird Things if the user does silliness
7613 like "(short) &a". In that case, convert_memory_address won't do
7614 the right thing, so ignore the given target mode. */
7615 if (tmode != address_mode && tmode != pointer_mode)
7616 tmode = address_mode;
7618 result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
7619 tmode, modifier, as);
7621 /* Despite expand_expr claims concerning ignoring TMODE when not
7622 strictly convenient, stuff breaks if we don't honor it. Note
7623 that combined with the above, we only do this for pointer modes. */
7624 rmode = GET_MODE (result);
7625 if (rmode == VOIDmode)
7628 result = convert_memory_address_addr_space (tmode, result, as);
7633 /* Generate code for computing CONSTRUCTOR EXP.
7634 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7635 is TRUE, instead of creating a temporary variable in memory
7636 NULL is returned and the caller needs to handle it differently. */
7639 expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
7640 bool avoid_temp_mem)
7642 tree type = TREE_TYPE (exp);
7643 enum machine_mode mode = TYPE_MODE (type);
7645 /* Try to avoid creating a temporary at all. This is possible
7646 if all of the initializer is zero.
7647 FIXME: try to handle all [0..255] initializers we can handle
7649 if (TREE_STATIC (exp)
7650 && !TREE_ADDRESSABLE (exp)
7651 && target != 0 && mode == BLKmode
7652 && all_zeros_p (exp))
7654 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7658 /* All elts simple constants => refer to a constant in memory. But
7659 if this is a non-BLKmode mode, let it store a field at a time
7660 since that should make a CONST_INT or CONST_DOUBLE when we
7661 fold. Likewise, if we have a target we can use, it is best to
7662 store directly into the target unless the type is large enough
7663 that memcpy will be used. If we are making an initializer and
7664 all operands are constant, put it in memory as well.
7666 FIXME: Avoid trying to fill vector constructors piece-meal.
7667 Output them with output_constant_def below unless we're sure
7668 they're zeros. This should go away when vector initializers
7669 are treated like VECTOR_CST instead of arrays. */
7670 if ((TREE_STATIC (exp)
7671 && ((mode == BLKmode
7672 && ! (target != 0 && safe_from_p (target, exp, 1)))
7673 || TREE_ADDRESSABLE (exp)
7674 || (host_integerp (TYPE_SIZE_UNIT (type), 1)
7675 && (! MOVE_BY_PIECES_P
7676 (tree_low_cst (TYPE_SIZE_UNIT (type), 1),
7678 && ! mostly_zeros_p (exp))))
7679 || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
7680 && TREE_CONSTANT (exp)))
7687 constructor = expand_expr_constant (exp, 1, modifier);
7689 if (modifier != EXPAND_CONST_ADDRESS
7690 && modifier != EXPAND_INITIALIZER
7691 && modifier != EXPAND_SUM)
7692 constructor = validize_mem (constructor);
7697 /* Handle calls that pass values in multiple non-contiguous
7698 locations. The Irix 6 ABI has examples of this. */
7699 if (target == 0 || ! safe_from_p (target, exp, 1)
7700 || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM)
7706 = assign_temp (build_qualified_type (type, (TYPE_QUALS (type)
7707 | (TREE_READONLY (exp)
7708 * TYPE_QUAL_CONST))),
7709 0, TREE_ADDRESSABLE (exp), 1);
7712 store_constructor (exp, target, 0, int_expr_size (exp));
7717 /* expand_expr: generate code for computing expression EXP.
7718 An rtx for the computed value is returned. The value is never null.
7719 In the case of a void EXP, const0_rtx is returned.
7721 The value may be stored in TARGET if TARGET is nonzero.
7722 TARGET is just a suggestion; callers must assume that
7723 the rtx returned may not be the same as TARGET.
7725 If TARGET is CONST0_RTX, it means that the value will be ignored.
7727 If TMODE is not VOIDmode, it suggests generating the
7728 result in mode TMODE. But this is done only when convenient.
7729 Otherwise, TMODE is ignored and the value generated in its natural mode.
7730 TMODE is just a suggestion; callers must assume that
7731 the rtx returned may not have mode TMODE.
7733 Note that TARGET may have neither TMODE nor MODE. In that case, it
7734 probably will not be used.
7736 If MODIFIER is EXPAND_SUM then when EXP is an addition
7737 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7738 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7739 products as above, or REG or MEM, or constant.
7740 Ordinarily in such cases we would output mul or add instructions
7741 and then return a pseudo reg containing the sum.
7743 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7744 it also marks a label as absolutely required (it can't be dead).
7745 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7746 This is used for outputting expressions used in initializers.
7748 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7749 with a constant address even if that address is not normally legitimate.
7750 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7752 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7753 a call parameter. Such targets require special care as we haven't yet
7754 marked TARGET so that it's safe from being trashed by libcalls. We
7755 don't want to use TARGET for anything but the final result;
7756 Intermediate values must go elsewhere. Additionally, calls to
7757 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7759 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7760 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7761 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7762 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7766 expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
7767 enum expand_modifier modifier, rtx *alt_rtl)
7771 /* Handle ERROR_MARK before anybody tries to access its type. */
7772 if (TREE_CODE (exp) == ERROR_MARK
7773 || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
7775 ret = CONST0_RTX (tmode);
7776 return ret ? ret : const0_rtx;
7779 /* If this is an expression of some kind and it has an associated line
7780 number, then emit the line number before expanding the expression.
7782 We need to save and restore the file and line information so that
7783 errors discovered during expansion are emitted with the right
7784 information. It would be better of the diagnostic routines
7785 used the file/line information embedded in the tree nodes rather
7787 if (cfun && EXPR_HAS_LOCATION (exp))
7789 location_t saved_location = input_location;
7790 location_t saved_curr_loc = get_curr_insn_source_location ();
7791 tree saved_block = get_curr_insn_block ();
7792 input_location = EXPR_LOCATION (exp);
7793 set_curr_insn_source_location (input_location);
7795 /* Record where the insns produced belong. */
7796 set_curr_insn_block (TREE_BLOCK (exp));
7798 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
7800 input_location = saved_location;
7801 set_curr_insn_block (saved_block);
7802 set_curr_insn_source_location (saved_curr_loc);
7806 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
7813 expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
7814 enum expand_modifier modifier)
7816 rtx op0, op1, op2, temp;
7819 enum machine_mode mode;
7820 enum tree_code code = ops->code;
7822 rtx subtarget, original_target;
7824 bool reduce_bit_field;
7825 location_t loc = ops->location;
7826 tree treeop0, treeop1, treeop2;
7827 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
7828 ? reduce_to_bit_field_precision ((expr), \
7834 mode = TYPE_MODE (type);
7835 unsignedp = TYPE_UNSIGNED (type);
7841 /* We should be called only on simple (binary or unary) expressions,
7842 exactly those that are valid in gimple expressions that aren't
7843 GIMPLE_SINGLE_RHS (or invalid). */
7844 gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
7845 || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
7846 || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
7848 ignore = (target == const0_rtx
7849 || ((CONVERT_EXPR_CODE_P (code)
7850 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
7851 && TREE_CODE (type) == VOID_TYPE));
7853 /* We should be called only if we need the result. */
7854 gcc_assert (!ignore);
7856 /* An operation in what may be a bit-field type needs the
7857 result to be reduced to the precision of the bit-field type,
7858 which is narrower than that of the type's mode. */
7859 reduce_bit_field = (INTEGRAL_TYPE_P (type)
7860 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
7862 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
7865 /* Use subtarget as the target for operand 0 of a binary operation. */
7866 subtarget = get_subtarget (target);
7867 original_target = target;
7871 case NON_LVALUE_EXPR:
7874 if (treeop0 == error_mark_node)
7877 if (TREE_CODE (type) == UNION_TYPE)
7879 tree valtype = TREE_TYPE (treeop0);
7881 /* If both input and output are BLKmode, this conversion isn't doing
7882 anything except possibly changing memory attribute. */
7883 if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
7885 rtx result = expand_expr (treeop0, target, tmode,
7888 result = copy_rtx (result);
7889 set_mem_attributes (result, type, 0);
7895 if (TYPE_MODE (type) != BLKmode)
7896 target = gen_reg_rtx (TYPE_MODE (type));
7898 target = assign_temp (type, 0, 1, 1);
7902 /* Store data into beginning of memory target. */
7903 store_expr (treeop0,
7904 adjust_address (target, TYPE_MODE (valtype), 0),
7905 modifier == EXPAND_STACK_PARM,
7910 gcc_assert (REG_P (target));
7912 /* Store this field into a union of the proper type. */
7913 store_field (target,
7914 MIN ((int_size_in_bytes (TREE_TYPE
7917 (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
7918 0, 0, 0, TYPE_MODE (valtype), treeop0,
7922 /* Return the entire union. */
7926 if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
7928 op0 = expand_expr (treeop0, target, VOIDmode,
7931 /* If the signedness of the conversion differs and OP0 is
7932 a promoted SUBREG, clear that indication since we now
7933 have to do the proper extension. */
7934 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)) != unsignedp
7935 && GET_CODE (op0) == SUBREG)
7936 SUBREG_PROMOTED_VAR_P (op0) = 0;
7938 return REDUCE_BIT_FIELD (op0);
7941 op0 = expand_expr (treeop0, NULL_RTX, mode,
7942 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
7943 if (GET_MODE (op0) == mode)
7946 /* If OP0 is a constant, just convert it into the proper mode. */
7947 else if (CONSTANT_P (op0))
7949 tree inner_type = TREE_TYPE (treeop0);
7950 enum machine_mode inner_mode = GET_MODE (op0);
7952 if (inner_mode == VOIDmode)
7953 inner_mode = TYPE_MODE (inner_type);
7955 if (modifier == EXPAND_INITIALIZER)
7956 op0 = simplify_gen_subreg (mode, op0, inner_mode,
7957 subreg_lowpart_offset (mode,
7960 op0= convert_modes (mode, inner_mode, op0,
7961 TYPE_UNSIGNED (inner_type));
7964 else if (modifier == EXPAND_INITIALIZER)
7965 op0 = gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
7967 else if (target == 0)
7968 op0 = convert_to_mode (mode, op0,
7969 TYPE_UNSIGNED (TREE_TYPE
7973 convert_move (target, op0,
7974 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
7978 return REDUCE_BIT_FIELD (op0);
7980 case ADDR_SPACE_CONVERT_EXPR:
7982 tree treeop0_type = TREE_TYPE (treeop0);
7984 addr_space_t as_from;
7986 gcc_assert (POINTER_TYPE_P (type));
7987 gcc_assert (POINTER_TYPE_P (treeop0_type));
7989 as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
7990 as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
7992 /* Conversions between pointers to the same address space should
7993 have been implemented via CONVERT_EXPR / NOP_EXPR. */
7994 gcc_assert (as_to != as_from);
7996 /* Ask target code to handle conversion between pointers
7997 to overlapping address spaces. */
7998 if (targetm.addr_space.subset_p (as_to, as_from)
7999 || targetm.addr_space.subset_p (as_from, as_to))
8001 op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
8002 op0 = targetm.addr_space.convert (op0, treeop0_type, type);
8007 /* For disjoint address spaces, converting anything but
8008 a null pointer invokes undefined behaviour. We simply
8009 always return a null pointer here. */
8010 return CONST0_RTX (mode);
8013 case POINTER_PLUS_EXPR:
8014 /* Even though the sizetype mode and the pointer's mode can be different
8015 expand is able to handle this correctly and get the correct result out
8016 of the PLUS_EXPR code. */
8017 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8018 if sizetype precision is smaller than pointer precision. */
8019 if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
8020 treeop1 = fold_convert_loc (loc, type,
8021 fold_convert_loc (loc, ssizetype,
8024 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8025 something else, make sure we add the register to the constant and
8026 then to the other thing. This case can occur during strength
8027 reduction and doing it this way will produce better code if the
8028 frame pointer or argument pointer is eliminated.
8030 fold-const.c will ensure that the constant is always in the inner
8031 PLUS_EXPR, so the only case we need to do anything about is if
8032 sp, ap, or fp is our second argument, in which case we must swap
8033 the innermost first argument and our second argument. */
8035 if (TREE_CODE (treeop0) == PLUS_EXPR
8036 && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
8037 && TREE_CODE (treeop1) == VAR_DECL
8038 && (DECL_RTL (treeop1) == frame_pointer_rtx
8039 || DECL_RTL (treeop1) == stack_pointer_rtx
8040 || DECL_RTL (treeop1) == arg_pointer_rtx))
8044 treeop1 = TREE_OPERAND (treeop0, 0);
8045 TREE_OPERAND (treeop0, 0) = t;
8048 /* If the result is to be ptr_mode and we are adding an integer to
8049 something, we might be forming a constant. So try to use
8050 plus_constant. If it produces a sum and we can't accept it,
8051 use force_operand. This allows P = &ARR[const] to generate
8052 efficient code on machines where a SYMBOL_REF is not a valid
8055 If this is an EXPAND_SUM call, always return the sum. */
8056 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
8057 || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
8059 if (modifier == EXPAND_STACK_PARM)
8061 if (TREE_CODE (treeop0) == INTEGER_CST
8062 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8063 && TREE_CONSTANT (treeop1))
8067 op1 = expand_expr (treeop1, subtarget, VOIDmode,
8069 /* Use immed_double_const to ensure that the constant is
8070 truncated according to the mode of OP1, then sign extended
8071 to a HOST_WIDE_INT. Using the constant directly can result
8072 in non-canonical RTL in a 64x32 cross compile. */
8074 = immed_double_const (TREE_INT_CST_LOW (treeop0),
8076 TYPE_MODE (TREE_TYPE (treeop1)));
8077 op1 = plus_constant (op1, INTVAL (constant_part));
8078 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8079 op1 = force_operand (op1, target);
8080 return REDUCE_BIT_FIELD (op1);
8083 else if (TREE_CODE (treeop1) == INTEGER_CST
8084 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8085 && TREE_CONSTANT (treeop0))
8089 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8090 (modifier == EXPAND_INITIALIZER
8091 ? EXPAND_INITIALIZER : EXPAND_SUM));
8092 if (! CONSTANT_P (op0))
8094 op1 = expand_expr (treeop1, NULL_RTX,
8095 VOIDmode, modifier);
8096 /* Return a PLUS if modifier says it's OK. */
8097 if (modifier == EXPAND_SUM
8098 || modifier == EXPAND_INITIALIZER)
8099 return simplify_gen_binary (PLUS, mode, op0, op1);
8102 /* Use immed_double_const to ensure that the constant is
8103 truncated according to the mode of OP1, then sign extended
8104 to a HOST_WIDE_INT. Using the constant directly can result
8105 in non-canonical RTL in a 64x32 cross compile. */
8107 = immed_double_const (TREE_INT_CST_LOW (treeop1),
8109 TYPE_MODE (TREE_TYPE (treeop0)));
8110 op0 = plus_constant (op0, INTVAL (constant_part));
8111 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8112 op0 = force_operand (op0, target);
8113 return REDUCE_BIT_FIELD (op0);
8117 /* Use TER to expand pointer addition of a negated value
8118 as pointer subtraction. */
8119 if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
8120 || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
8121 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
8122 && TREE_CODE (treeop1) == SSA_NAME
8123 && TYPE_MODE (TREE_TYPE (treeop0))
8124 == TYPE_MODE (TREE_TYPE (treeop1)))
8126 gimple def = get_def_for_expr (treeop1, NEGATE_EXPR);
8129 treeop1 = gimple_assign_rhs1 (def);
8135 /* No sense saving up arithmetic to be done
8136 if it's all in the wrong mode to form part of an address.
8137 And force_operand won't know whether to sign-extend or
8139 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8140 || mode != ptr_mode)
8142 expand_operands (treeop0, treeop1,
8143 subtarget, &op0, &op1, EXPAND_NORMAL);
8144 if (op0 == const0_rtx)
8146 if (op1 == const0_rtx)
8151 expand_operands (treeop0, treeop1,
8152 subtarget, &op0, &op1, modifier);
8153 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8157 /* For initializers, we are allowed to return a MINUS of two
8158 symbolic constants. Here we handle all cases when both operands
8160 /* Handle difference of two symbolic constants,
8161 for the sake of an initializer. */
8162 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8163 && really_constant_p (treeop0)
8164 && really_constant_p (treeop1))
8166 expand_operands (treeop0, treeop1,
8167 NULL_RTX, &op0, &op1, modifier);
8169 /* If the last operand is a CONST_INT, use plus_constant of
8170 the negated constant. Else make the MINUS. */
8171 if (CONST_INT_P (op1))
8172 return REDUCE_BIT_FIELD (plus_constant (op0, - INTVAL (op1)));
8174 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode, op0, op1));
8177 /* No sense saving up arithmetic to be done
8178 if it's all in the wrong mode to form part of an address.
8179 And force_operand won't know whether to sign-extend or
8181 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8182 || mode != ptr_mode)
8185 expand_operands (treeop0, treeop1,
8186 subtarget, &op0, &op1, modifier);
8188 /* Convert A - const to A + (-const). */
8189 if (CONST_INT_P (op1))
8191 op1 = negate_rtx (mode, op1);
8192 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8197 case WIDEN_MULT_PLUS_EXPR:
8198 case WIDEN_MULT_MINUS_EXPR:
8199 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8200 op2 = expand_normal (treeop2);
8201 target = expand_widen_pattern_expr (ops, op0, op1, op2,
8205 case WIDEN_MULT_EXPR:
8206 /* If first operand is constant, swap them.
8207 Thus the following special case checks need only
8208 check the second operand. */
8209 if (TREE_CODE (treeop0) == INTEGER_CST)
8216 /* First, check if we have a multiplication of one signed and one
8217 unsigned operand. */
8218 if (TREE_CODE (treeop1) != INTEGER_CST
8219 && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
8220 != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
8222 enum machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
8223 this_optab = usmul_widen_optab;
8224 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8225 != CODE_FOR_nothing)
8227 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8228 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8231 expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
8236 /* Check for a multiplication with matching signedness. */
8237 else if ((TREE_CODE (treeop1) == INTEGER_CST
8238 && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
8239 || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
8240 == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
8242 tree op0type = TREE_TYPE (treeop0);
8243 enum machine_mode innermode = TYPE_MODE (op0type);
8244 bool zextend_p = TYPE_UNSIGNED (op0type);
8245 optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
8246 this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
8248 if (TREE_CODE (treeop0) != INTEGER_CST)
8250 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8251 != CODE_FOR_nothing)
8253 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8255 temp = expand_widening_mult (mode, op0, op1, target,
8256 unsignedp, this_optab);
8257 return REDUCE_BIT_FIELD (temp);
8259 if (find_widening_optab_handler (other_optab, mode, innermode, 0)
8261 && innermode == word_mode)
8264 op0 = expand_normal (treeop0);
8265 if (TREE_CODE (treeop1) == INTEGER_CST)
8266 op1 = convert_modes (innermode, mode,
8267 expand_normal (treeop1), unsignedp);
8269 op1 = expand_normal (treeop1);
8270 temp = expand_binop (mode, other_optab, op0, op1, target,
8271 unsignedp, OPTAB_LIB_WIDEN);
8272 hipart = gen_highpart (innermode, temp);
8273 htem = expand_mult_highpart_adjust (innermode, hipart,
8277 emit_move_insn (hipart, htem);
8278 return REDUCE_BIT_FIELD (temp);
8282 treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
8283 treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
8284 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8285 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8289 optab opt = fma_optab;
8292 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8294 if (optab_handler (fma_optab, mode) == CODE_FOR_nothing)
8296 tree fn = mathfn_built_in (TREE_TYPE (treeop0), BUILT_IN_FMA);
8299 gcc_assert (fn != NULL_TREE);
8300 call_expr = build_call_expr (fn, 3, treeop0, treeop1, treeop2);
8301 return expand_builtin (call_expr, target, subtarget, mode, false);
8304 def0 = get_def_for_expr (treeop0, NEGATE_EXPR);
8305 def2 = get_def_for_expr (treeop2, NEGATE_EXPR);
8310 && optab_handler (fnms_optab, mode) != CODE_FOR_nothing)
8313 op0 = expand_normal (gimple_assign_rhs1 (def0));
8314 op2 = expand_normal (gimple_assign_rhs1 (def2));
8317 && optab_handler (fnma_optab, mode) != CODE_FOR_nothing)
8320 op0 = expand_normal (gimple_assign_rhs1 (def0));
8323 && optab_handler (fms_optab, mode) != CODE_FOR_nothing)
8326 op2 = expand_normal (gimple_assign_rhs1 (def2));
8330 op0 = expand_expr (treeop0, subtarget, VOIDmode, EXPAND_NORMAL);
8332 op2 = expand_normal (treeop2);
8333 op1 = expand_normal (treeop1);
8335 return expand_ternary_op (TYPE_MODE (type), opt,
8336 op0, op1, op2, target, 0);
8340 /* If this is a fixed-point operation, then we cannot use the code
8341 below because "expand_mult" doesn't support sat/no-sat fixed-point
8343 if (ALL_FIXED_POINT_MODE_P (mode))
8346 /* If first operand is constant, swap them.
8347 Thus the following special case checks need only
8348 check the second operand. */
8349 if (TREE_CODE (treeop0) == INTEGER_CST)
8356 /* Attempt to return something suitable for generating an
8357 indexed address, for machines that support that. */
8359 if (modifier == EXPAND_SUM && mode == ptr_mode
8360 && host_integerp (treeop1, 0))
8362 tree exp1 = treeop1;
8364 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8368 op0 = force_operand (op0, NULL_RTX);
8370 op0 = copy_to_mode_reg (mode, op0);
8372 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0,
8373 gen_int_mode (tree_low_cst (exp1, 0),
8374 TYPE_MODE (TREE_TYPE (exp1)))));
8377 if (modifier == EXPAND_STACK_PARM)
8380 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8381 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8383 case TRUNC_DIV_EXPR:
8384 case FLOOR_DIV_EXPR:
8386 case ROUND_DIV_EXPR:
8387 case EXACT_DIV_EXPR:
8388 /* If this is a fixed-point operation, then we cannot use the code
8389 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8391 if (ALL_FIXED_POINT_MODE_P (mode))
8394 if (modifier == EXPAND_STACK_PARM)
8396 /* Possible optimization: compute the dividend with EXPAND_SUM
8397 then if the divisor is constant can optimize the case
8398 where some terms of the dividend have coeffs divisible by it. */
8399 expand_operands (treeop0, treeop1,
8400 subtarget, &op0, &op1, EXPAND_NORMAL);
8401 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
8406 case TRUNC_MOD_EXPR:
8407 case FLOOR_MOD_EXPR:
8409 case ROUND_MOD_EXPR:
8410 if (modifier == EXPAND_STACK_PARM)
8412 expand_operands (treeop0, treeop1,
8413 subtarget, &op0, &op1, EXPAND_NORMAL);
8414 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
8416 case FIXED_CONVERT_EXPR:
8417 op0 = expand_normal (treeop0);
8418 if (target == 0 || modifier == EXPAND_STACK_PARM)
8419 target = gen_reg_rtx (mode);
8421 if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
8422 && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8423 || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
8424 expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
8426 expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
8429 case FIX_TRUNC_EXPR:
8430 op0 = expand_normal (treeop0);
8431 if (target == 0 || modifier == EXPAND_STACK_PARM)
8432 target = gen_reg_rtx (mode);
8433 expand_fix (target, op0, unsignedp);
8437 op0 = expand_normal (treeop0);
8438 if (target == 0 || modifier == EXPAND_STACK_PARM)
8439 target = gen_reg_rtx (mode);
8440 /* expand_float can't figure out what to do if FROM has VOIDmode.
8441 So give it the correct mode. With -O, cse will optimize this. */
8442 if (GET_MODE (op0) == VOIDmode)
8443 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
8445 expand_float (target, op0,
8446 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8450 op0 = expand_expr (treeop0, subtarget,
8451 VOIDmode, EXPAND_NORMAL);
8452 if (modifier == EXPAND_STACK_PARM)
8454 temp = expand_unop (mode,
8455 optab_for_tree_code (NEGATE_EXPR, type,
8459 return REDUCE_BIT_FIELD (temp);
8462 op0 = expand_expr (treeop0, subtarget,
8463 VOIDmode, EXPAND_NORMAL);
8464 if (modifier == EXPAND_STACK_PARM)
8467 /* ABS_EXPR is not valid for complex arguments. */
8468 gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8469 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
8471 /* Unsigned abs is simply the operand. Testing here means we don't
8472 risk generating incorrect code below. */
8473 if (TYPE_UNSIGNED (type))
8476 return expand_abs (mode, op0, target, unsignedp,
8477 safe_from_p (target, treeop0, 1));
8481 target = original_target;
8483 || modifier == EXPAND_STACK_PARM
8484 || (MEM_P (target) && MEM_VOLATILE_P (target))
8485 || GET_MODE (target) != mode
8487 && REGNO (target) < FIRST_PSEUDO_REGISTER))
8488 target = gen_reg_rtx (mode);
8489 expand_operands (treeop0, treeop1,
8490 target, &op0, &op1, EXPAND_NORMAL);
8492 /* First try to do it with a special MIN or MAX instruction.
8493 If that does not win, use a conditional jump to select the proper
8495 this_optab = optab_for_tree_code (code, type, optab_default);
8496 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8501 /* At this point, a MEM target is no longer useful; we will get better
8504 if (! REG_P (target))
8505 target = gen_reg_rtx (mode);
8507 /* If op1 was placed in target, swap op0 and op1. */
8508 if (target != op0 && target == op1)
8515 /* We generate better code and avoid problems with op1 mentioning
8516 target by forcing op1 into a pseudo if it isn't a constant. */
8517 if (! CONSTANT_P (op1))
8518 op1 = force_reg (mode, op1);
8521 enum rtx_code comparison_code;
8524 if (code == MAX_EXPR)
8525 comparison_code = unsignedp ? GEU : GE;
8527 comparison_code = unsignedp ? LEU : LE;
8529 /* Canonicalize to comparisons against 0. */
8530 if (op1 == const1_rtx)
8532 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8533 or (a != 0 ? a : 1) for unsigned.
8534 For MIN we are safe converting (a <= 1 ? a : 1)
8535 into (a <= 0 ? a : 1) */
8536 cmpop1 = const0_rtx;
8537 if (code == MAX_EXPR)
8538 comparison_code = unsignedp ? NE : GT;
8540 if (op1 == constm1_rtx && !unsignedp)
8542 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8543 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8544 cmpop1 = const0_rtx;
8545 if (code == MIN_EXPR)
8546 comparison_code = LT;
8548 #ifdef HAVE_conditional_move
8549 /* Use a conditional move if possible. */
8550 if (can_conditionally_move_p (mode))
8554 /* ??? Same problem as in expmed.c: emit_conditional_move
8555 forces a stack adjustment via compare_from_rtx, and we
8556 lose the stack adjustment if the sequence we are about
8557 to create is discarded. */
8558 do_pending_stack_adjust ();
8562 /* Try to emit the conditional move. */
8563 insn = emit_conditional_move (target, comparison_code,
8568 /* If we could do the conditional move, emit the sequence,
8572 rtx seq = get_insns ();
8578 /* Otherwise discard the sequence and fall back to code with
8584 emit_move_insn (target, op0);
8586 temp = gen_label_rtx ();
8587 do_compare_rtx_and_jump (target, cmpop1, comparison_code,
8588 unsignedp, mode, NULL_RTX, NULL_RTX, temp,
8591 emit_move_insn (target, op1);
8596 op0 = expand_expr (treeop0, subtarget,
8597 VOIDmode, EXPAND_NORMAL);
8598 if (modifier == EXPAND_STACK_PARM)
8600 /* In case we have to reduce the result to bitfield precision
8601 for unsigned bitfield expand this as XOR with a proper constant
8603 if (reduce_bit_field && TYPE_UNSIGNED (type))
8604 temp = expand_binop (mode, xor_optab, op0,
8605 immed_double_int_const
8606 (double_int_mask (TYPE_PRECISION (type)), mode),
8607 target, 1, OPTAB_LIB_WIDEN);
8609 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
8613 /* ??? Can optimize bitwise operations with one arg constant.
8614 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8615 and (a bitwise1 b) bitwise2 b (etc)
8616 but that is probably not worth while. */
8625 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
8626 || (GET_MODE_PRECISION (TYPE_MODE (type))
8627 == TYPE_PRECISION (type)));
8632 /* If this is a fixed-point operation, then we cannot use the code
8633 below because "expand_shift" doesn't support sat/no-sat fixed-point
8635 if (ALL_FIXED_POINT_MODE_P (mode))
8638 if (! safe_from_p (subtarget, treeop1, 1))
8640 if (modifier == EXPAND_STACK_PARM)
8642 op0 = expand_expr (treeop0, subtarget,
8643 VOIDmode, EXPAND_NORMAL);
8644 temp = expand_variable_shift (code, mode, op0, treeop1, target,
8646 if (code == LSHIFT_EXPR)
8647 temp = REDUCE_BIT_FIELD (temp);
8650 /* Could determine the answer when only additive constants differ. Also,
8651 the addition of one can be handled by changing the condition. */
8658 case UNORDERED_EXPR:
8666 temp = do_store_flag (ops,
8667 modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
8668 tmode != VOIDmode ? tmode : mode);
8672 /* Use a compare and a jump for BLKmode comparisons, or for function
8673 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8676 || modifier == EXPAND_STACK_PARM
8677 || ! safe_from_p (target, treeop0, 1)
8678 || ! safe_from_p (target, treeop1, 1)
8679 /* Make sure we don't have a hard reg (such as function's return
8680 value) live across basic blocks, if not optimizing. */
8681 || (!optimize && REG_P (target)
8682 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
8683 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
8685 emit_move_insn (target, const0_rtx);
8687 op1 = gen_label_rtx ();
8688 jumpifnot_1 (code, treeop0, treeop1, op1, -1);
8690 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
8691 emit_move_insn (target, constm1_rtx);
8693 emit_move_insn (target, const1_rtx);
8699 /* Get the rtx code of the operands. */
8700 op0 = expand_normal (treeop0);
8701 op1 = expand_normal (treeop1);
8704 target = gen_reg_rtx (TYPE_MODE (type));
8706 /* Move the real (op0) and imaginary (op1) parts to their location. */
8707 write_complex_part (target, op0, false);
8708 write_complex_part (target, op1, true);
8712 case WIDEN_SUM_EXPR:
8714 tree oprnd0 = treeop0;
8715 tree oprnd1 = treeop1;
8717 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8718 target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
8723 case REDUC_MAX_EXPR:
8724 case REDUC_MIN_EXPR:
8725 case REDUC_PLUS_EXPR:
8727 op0 = expand_normal (treeop0);
8728 this_optab = optab_for_tree_code (code, type, optab_default);
8729 temp = expand_unop (mode, this_optab, op0, target, unsignedp);
8734 case VEC_LSHIFT_EXPR:
8735 case VEC_RSHIFT_EXPR:
8737 target = expand_vec_shift_expr (ops, target);
8741 case VEC_UNPACK_HI_EXPR:
8742 case VEC_UNPACK_LO_EXPR:
8744 op0 = expand_normal (treeop0);
8745 temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
8751 case VEC_UNPACK_FLOAT_HI_EXPR:
8752 case VEC_UNPACK_FLOAT_LO_EXPR:
8754 op0 = expand_normal (treeop0);
8755 /* The signedness is determined from input operand. */
8756 temp = expand_widen_pattern_expr
8757 (ops, op0, NULL_RTX, NULL_RTX,
8758 target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8764 case VEC_WIDEN_MULT_HI_EXPR:
8765 case VEC_WIDEN_MULT_LO_EXPR:
8767 tree oprnd0 = treeop0;
8768 tree oprnd1 = treeop1;
8770 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8771 target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
8773 gcc_assert (target);
8777 case VEC_WIDEN_LSHIFT_HI_EXPR:
8778 case VEC_WIDEN_LSHIFT_LO_EXPR:
8780 tree oprnd0 = treeop0;
8781 tree oprnd1 = treeop1;
8783 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8784 target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
8786 gcc_assert (target);
8790 case VEC_PACK_TRUNC_EXPR:
8791 case VEC_PACK_SAT_EXPR:
8792 case VEC_PACK_FIX_TRUNC_EXPR:
8793 mode = TYPE_MODE (TREE_TYPE (treeop0));
8797 expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
8798 op2 = expand_normal (treeop2);
8800 /* Careful here: if the target doesn't support integral vector modes,
8801 a constant selection vector could wind up smooshed into a normal
8802 integral constant. */
8803 if (CONSTANT_P (op2) && GET_CODE (op2) != CONST_VECTOR)
8805 tree sel_type = TREE_TYPE (treeop2);
8806 enum machine_mode vmode
8807 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type)),
8808 TYPE_VECTOR_SUBPARTS (sel_type));
8809 gcc_assert (GET_MODE_CLASS (vmode) == MODE_VECTOR_INT);
8810 op2 = simplify_subreg (vmode, op2, TYPE_MODE (sel_type), 0);
8811 gcc_assert (op2 && GET_CODE (op2) == CONST_VECTOR);
8814 gcc_assert (GET_MODE_CLASS (GET_MODE (op2)) == MODE_VECTOR_INT);
8816 temp = expand_vec_perm (mode, op0, op1, op2, target);
8822 tree oprnd0 = treeop0;
8823 tree oprnd1 = treeop1;
8824 tree oprnd2 = treeop2;
8827 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8828 op2 = expand_normal (oprnd2);
8829 target = expand_widen_pattern_expr (ops, op0, op1, op2,
8834 case REALIGN_LOAD_EXPR:
8836 tree oprnd0 = treeop0;
8837 tree oprnd1 = treeop1;
8838 tree oprnd2 = treeop2;
8841 this_optab = optab_for_tree_code (code, type, optab_default);
8842 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8843 op2 = expand_normal (oprnd2);
8844 temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
8851 /* A COND_EXPR with its type being VOID_TYPE represents a
8852 conditional jump and is handled in
8853 expand_gimple_cond_expr. */
8854 gcc_assert (!VOID_TYPE_P (type));
8856 /* Note that COND_EXPRs whose type is a structure or union
8857 are required to be constructed to contain assignments of
8858 a temporary variable, so that we can evaluate them here
8859 for side effect only. If type is void, we must do likewise. */
8861 gcc_assert (!TREE_ADDRESSABLE (type)
8863 && TREE_TYPE (treeop1) != void_type_node
8864 && TREE_TYPE (treeop2) != void_type_node);
8866 /* If we are not to produce a result, we have no target. Otherwise,
8867 if a target was specified use it; it will not be used as an
8868 intermediate target unless it is safe. If no target, use a
8871 if (modifier != EXPAND_STACK_PARM
8873 && safe_from_p (original_target, treeop0, 1)
8874 && GET_MODE (original_target) == mode
8875 #ifdef HAVE_conditional_move
8876 && (! can_conditionally_move_p (mode)
8877 || REG_P (original_target))
8879 && !MEM_P (original_target))
8880 temp = original_target;
8882 temp = assign_temp (type, 0, 0, 1);
8884 do_pending_stack_adjust ();
8886 op0 = gen_label_rtx ();
8887 op1 = gen_label_rtx ();
8888 jumpifnot (treeop0, op0, -1);
8889 store_expr (treeop1, temp,
8890 modifier == EXPAND_STACK_PARM,
8893 emit_jump_insn (gen_jump (op1));
8896 store_expr (treeop2, temp,
8897 modifier == EXPAND_STACK_PARM,
8905 target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target);
8912 /* Here to do an ordinary binary operator. */
8914 expand_operands (treeop0, treeop1,
8915 subtarget, &op0, &op1, EXPAND_NORMAL);
8917 this_optab = optab_for_tree_code (code, type, optab_default);
8919 if (modifier == EXPAND_STACK_PARM)
8921 temp = expand_binop (mode, this_optab, op0, op1, target,
8922 unsignedp, OPTAB_LIB_WIDEN);
8924 /* Bitwise operations do not need bitfield reduction as we expect their
8925 operands being properly truncated. */
8926 if (code == BIT_XOR_EXPR
8927 || code == BIT_AND_EXPR
8928 || code == BIT_IOR_EXPR)
8930 return REDUCE_BIT_FIELD (temp);
8932 #undef REDUCE_BIT_FIELD
8935 expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
8936 enum expand_modifier modifier, rtx *alt_rtl)
8938 rtx op0, op1, temp, decl_rtl;
8941 enum machine_mode mode;
8942 enum tree_code code = TREE_CODE (exp);
8943 rtx subtarget, original_target;
8946 bool reduce_bit_field;
8947 location_t loc = EXPR_LOCATION (exp);
8948 struct separate_ops ops;
8949 tree treeop0, treeop1, treeop2;
8950 tree ssa_name = NULL_TREE;
8953 type = TREE_TYPE (exp);
8954 mode = TYPE_MODE (type);
8955 unsignedp = TYPE_UNSIGNED (type);
8957 treeop0 = treeop1 = treeop2 = NULL_TREE;
8958 if (!VL_EXP_CLASS_P (exp))
8959 switch (TREE_CODE_LENGTH (code))
8962 case 3: treeop2 = TREE_OPERAND (exp, 2);
8963 case 2: treeop1 = TREE_OPERAND (exp, 1);
8964 case 1: treeop0 = TREE_OPERAND (exp, 0);
8974 ignore = (target == const0_rtx
8975 || ((CONVERT_EXPR_CODE_P (code)
8976 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
8977 && TREE_CODE (type) == VOID_TYPE));
8979 /* An operation in what may be a bit-field type needs the
8980 result to be reduced to the precision of the bit-field type,
8981 which is narrower than that of the type's mode. */
8982 reduce_bit_field = (!ignore
8983 && INTEGRAL_TYPE_P (type)
8984 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
8986 /* If we are going to ignore this result, we need only do something
8987 if there is a side-effect somewhere in the expression. If there
8988 is, short-circuit the most common cases here. Note that we must
8989 not call expand_expr with anything but const0_rtx in case this
8990 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
8994 if (! TREE_SIDE_EFFECTS (exp))
8997 /* Ensure we reference a volatile object even if value is ignored, but
8998 don't do this if all we are doing is taking its address. */
8999 if (TREE_THIS_VOLATILE (exp)
9000 && TREE_CODE (exp) != FUNCTION_DECL
9001 && mode != VOIDmode && mode != BLKmode
9002 && modifier != EXPAND_CONST_ADDRESS)
9004 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
9010 if (TREE_CODE_CLASS (code) == tcc_unary
9011 || code == COMPONENT_REF || code == INDIRECT_REF)
9012 return expand_expr (treeop0, const0_rtx, VOIDmode,
9015 else if (TREE_CODE_CLASS (code) == tcc_binary
9016 || TREE_CODE_CLASS (code) == tcc_comparison
9017 || code == ARRAY_REF || code == ARRAY_RANGE_REF)
9019 expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
9020 expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
9023 else if (code == BIT_FIELD_REF)
9025 expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
9026 expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
9027 expand_expr (treeop2, const0_rtx, VOIDmode, modifier);
9034 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
9037 /* Use subtarget as the target for operand 0 of a binary operation. */
9038 subtarget = get_subtarget (target);
9039 original_target = target;
9045 tree function = decl_function_context (exp);
9047 temp = label_rtx (exp);
9048 temp = gen_rtx_LABEL_REF (Pmode, temp);
9050 if (function != current_function_decl
9052 LABEL_REF_NONLOCAL_P (temp) = 1;
9054 temp = gen_rtx_MEM (FUNCTION_MODE, temp);
9059 /* ??? ivopts calls expander, without any preparation from
9060 out-of-ssa. So fake instructions as if this was an access to the
9061 base variable. This unnecessarily allocates a pseudo, see how we can
9062 reuse it, if partition base vars have it set already. */
9063 if (!currently_expanding_to_rtl)
9064 return expand_expr_real_1 (SSA_NAME_VAR (exp), target, tmode, modifier,
9067 g = get_gimple_for_ssa_name (exp);
9068 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9070 && modifier == EXPAND_INITIALIZER
9071 && !SSA_NAME_IS_DEFAULT_DEF (exp)
9072 && (optimize || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
9073 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
9074 g = SSA_NAME_DEF_STMT (exp);
9076 return expand_expr_real (gimple_assign_rhs_to_tree (g), target, tmode,
9080 decl_rtl = get_rtx_for_ssa_name (ssa_name);
9081 exp = SSA_NAME_VAR (ssa_name);
9082 goto expand_decl_rtl;
9086 /* If a static var's type was incomplete when the decl was written,
9087 but the type is complete now, lay out the decl now. */
9088 if (DECL_SIZE (exp) == 0
9089 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
9090 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
9091 layout_decl (exp, 0);
9093 /* ... fall through ... */
9097 decl_rtl = DECL_RTL (exp);
9099 gcc_assert (decl_rtl);
9100 decl_rtl = copy_rtx (decl_rtl);
9101 /* Record writes to register variables. */
9102 if (modifier == EXPAND_WRITE
9104 && HARD_REGISTER_P (decl_rtl))
9105 add_to_hard_reg_set (&crtl->asm_clobbers,
9106 GET_MODE (decl_rtl), REGNO (decl_rtl));
9108 /* Ensure variable marked as used even if it doesn't go through
9109 a parser. If it hasn't be used yet, write out an external
9111 if (! TREE_USED (exp))
9113 assemble_external (exp);
9114 TREE_USED (exp) = 1;
9117 /* Show we haven't gotten RTL for this yet. */
9120 /* Variables inherited from containing functions should have
9121 been lowered by this point. */
9122 context = decl_function_context (exp);
9123 gcc_assert (!context
9124 || context == current_function_decl
9125 || TREE_STATIC (exp)
9126 || DECL_EXTERNAL (exp)
9127 /* ??? C++ creates functions that are not TREE_STATIC. */
9128 || TREE_CODE (exp) == FUNCTION_DECL);
9130 /* This is the case of an array whose size is to be determined
9131 from its initializer, while the initializer is still being parsed.
9134 if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
9135 temp = validize_mem (decl_rtl);
9137 /* If DECL_RTL is memory, we are in the normal case and the
9138 address is not valid, get the address into a register. */
9140 else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
9143 *alt_rtl = decl_rtl;
9144 decl_rtl = use_anchored_address (decl_rtl);
9145 if (modifier != EXPAND_CONST_ADDRESS
9146 && modifier != EXPAND_SUM
9147 && !memory_address_addr_space_p (DECL_MODE (exp),
9149 MEM_ADDR_SPACE (decl_rtl)))
9150 temp = replace_equiv_address (decl_rtl,
9151 copy_rtx (XEXP (decl_rtl, 0)));
9154 /* If we got something, return it. But first, set the alignment
9155 if the address is a register. */
9158 if (MEM_P (temp) && REG_P (XEXP (temp, 0)))
9159 mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
9164 /* If the mode of DECL_RTL does not match that of the decl,
9165 there are two cases: we are dealing with a BLKmode value
9166 that is returned in a register, or we are dealing with
9167 a promoted value. In the latter case, return a SUBREG
9168 of the wanted mode, but mark it so that we know that it
9169 was already extended. */
9170 if (REG_P (decl_rtl)
9171 && DECL_MODE (exp) != BLKmode
9172 && GET_MODE (decl_rtl) != DECL_MODE (exp))
9174 enum machine_mode pmode;
9176 /* Get the signedness to be used for this variable. Ensure we get
9177 the same mode we got when the variable was declared. */
9178 if (code == SSA_NAME
9179 && (g = SSA_NAME_DEF_STMT (ssa_name))
9180 && gimple_code (g) == GIMPLE_CALL)
9182 gcc_assert (!gimple_call_internal_p (g));
9183 pmode = promote_function_mode (type, mode, &unsignedp,
9184 gimple_call_fntype (g),
9188 pmode = promote_decl_mode (exp, &unsignedp);
9189 gcc_assert (GET_MODE (decl_rtl) == pmode);
9191 temp = gen_lowpart_SUBREG (mode, decl_rtl);
9192 SUBREG_PROMOTED_VAR_P (temp) = 1;
9193 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
9200 temp = immed_double_const (TREE_INT_CST_LOW (exp),
9201 TREE_INT_CST_HIGH (exp), mode);
9207 tree tmp = NULL_TREE;
9208 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
9209 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
9210 || GET_MODE_CLASS (mode) == MODE_VECTOR_FRACT
9211 || GET_MODE_CLASS (mode) == MODE_VECTOR_UFRACT
9212 || GET_MODE_CLASS (mode) == MODE_VECTOR_ACCUM
9213 || GET_MODE_CLASS (mode) == MODE_VECTOR_UACCUM)
9214 return const_vector_from_tree (exp);
9215 if (GET_MODE_CLASS (mode) == MODE_INT)
9217 tree type_for_mode = lang_hooks.types.type_for_mode (mode, 1);
9219 tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR, type_for_mode, exp);
9222 tmp = build_constructor_from_list (type,
9223 TREE_VECTOR_CST_ELTS (exp));
9224 return expand_expr (tmp, ignore ? const0_rtx : target,
9229 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
9232 /* If optimized, generate immediate CONST_DOUBLE
9233 which will be turned into memory by reload if necessary.
9235 We used to force a register so that loop.c could see it. But
9236 this does not allow gen_* patterns to perform optimizations with
9237 the constants. It also produces two insns in cases like "x = 1.0;".
9238 On most machines, floating-point constants are not permitted in
9239 many insns, so we'd end up copying it to a register in any case.
9241 Now, we do the copying in expand_binop, if appropriate. */
9242 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
9243 TYPE_MODE (TREE_TYPE (exp)));
9246 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
9247 TYPE_MODE (TREE_TYPE (exp)));
9250 /* Handle evaluating a complex constant in a CONCAT target. */
9251 if (original_target && GET_CODE (original_target) == CONCAT)
9253 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
9256 rtarg = XEXP (original_target, 0);
9257 itarg = XEXP (original_target, 1);
9259 /* Move the real and imaginary parts separately. */
9260 op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
9261 op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
9264 emit_move_insn (rtarg, op0);
9266 emit_move_insn (itarg, op1);
9268 return original_target;
9271 /* ... fall through ... */
9274 temp = expand_expr_constant (exp, 1, modifier);
9276 /* temp contains a constant address.
9277 On RISC machines where a constant address isn't valid,
9278 make some insns to get that address into a register. */
9279 if (modifier != EXPAND_CONST_ADDRESS
9280 && modifier != EXPAND_INITIALIZER
9281 && modifier != EXPAND_SUM
9282 && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
9283 MEM_ADDR_SPACE (temp)))
9284 return replace_equiv_address (temp,
9285 copy_rtx (XEXP (temp, 0)));
9291 rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl);
9293 if (!SAVE_EXPR_RESOLVED_P (exp))
9295 /* We can indeed still hit this case, typically via builtin
9296 expanders calling save_expr immediately before expanding
9297 something. Assume this means that we only have to deal
9298 with non-BLKmode values. */
9299 gcc_assert (GET_MODE (ret) != BLKmode);
9301 val = build_decl (EXPR_LOCATION (exp),
9302 VAR_DECL, NULL, TREE_TYPE (exp));
9303 DECL_ARTIFICIAL (val) = 1;
9304 DECL_IGNORED_P (val) = 1;
9306 TREE_OPERAND (exp, 0) = treeop0;
9307 SAVE_EXPR_RESOLVED_P (exp) = 1;
9309 if (!CONSTANT_P (ret))
9310 ret = copy_to_reg (ret);
9311 SET_DECL_RTL (val, ret);
9319 /* If we don't need the result, just ensure we evaluate any
9323 unsigned HOST_WIDE_INT idx;
9326 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
9327 expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
9332 return expand_constructor (exp, target, modifier, false);
9334 case TARGET_MEM_REF:
9337 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9338 struct mem_address addr;
9339 enum insn_code icode;
9342 get_address_description (exp, &addr);
9343 op0 = addr_for_mem_ref (&addr, as, true);
9344 op0 = memory_address_addr_space (mode, op0, as);
9345 temp = gen_rtx_MEM (mode, op0);
9346 set_mem_attributes (temp, exp, 0);
9347 set_mem_addr_space (temp, as);
9348 align = get_object_or_type_alignment (exp);
9350 && align < GET_MODE_ALIGNMENT (mode)
9351 /* If the target does not have special handling for unaligned
9352 loads of mode then it can use regular moves for them. */
9353 && ((icode = optab_handler (movmisalign_optab, mode))
9354 != CODE_FOR_nothing))
9356 struct expand_operand ops[2];
9358 /* We've already validated the memory, and we're creating a
9359 new pseudo destination. The predicates really can't fail,
9360 nor can the generator. */
9361 create_output_operand (&ops[0], NULL_RTX, mode);
9362 create_fixed_operand (&ops[1], temp);
9363 expand_insn (icode, 2, ops);
9364 return ops[0].value;
9372 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9373 enum machine_mode address_mode;
9374 tree base = TREE_OPERAND (exp, 0);
9376 enum insn_code icode;
9378 /* Handle expansion of non-aliased memory with non-BLKmode. That
9379 might end up in a register. */
9380 if (mem_ref_refers_to_non_mem_p (exp))
9382 HOST_WIDE_INT offset = mem_ref_offset (exp).low;
9385 base = TREE_OPERAND (base, 0);
9387 && host_integerp (TYPE_SIZE (TREE_TYPE (exp)), 1)
9388 && (GET_MODE_BITSIZE (DECL_MODE (base))
9389 == TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp)))))
9390 return expand_expr (build1 (VIEW_CONVERT_EXPR,
9391 TREE_TYPE (exp), base),
9392 target, tmode, modifier);
9393 bit_offset = bitsize_int (offset * BITS_PER_UNIT);
9394 bftype = TREE_TYPE (base);
9395 if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
9396 bftype = TREE_TYPE (exp);
9399 temp = assign_stack_temp (DECL_MODE (base),
9400 GET_MODE_SIZE (DECL_MODE (base)),
9402 store_expr (base, temp, 0, false);
9403 temp = adjust_address (temp, BLKmode, offset);
9404 set_mem_size (temp, int_size_in_bytes (TREE_TYPE (exp)));
9407 return expand_expr (build3 (BIT_FIELD_REF, bftype,
9409 TYPE_SIZE (TREE_TYPE (exp)),
9411 target, tmode, modifier);
9413 address_mode = targetm.addr_space.address_mode (as);
9414 base = TREE_OPERAND (exp, 0);
9415 if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
9417 tree mask = gimple_assign_rhs2 (def_stmt);
9418 base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
9419 gimple_assign_rhs1 (def_stmt), mask);
9420 TREE_OPERAND (exp, 0) = base;
9422 align = get_object_or_type_alignment (exp);
9423 op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
9424 op0 = memory_address_addr_space (address_mode, op0, as);
9425 if (!integer_zerop (TREE_OPERAND (exp, 1)))
9428 = immed_double_int_const (mem_ref_offset (exp), address_mode);
9429 op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
9431 op0 = memory_address_addr_space (mode, op0, as);
9432 temp = gen_rtx_MEM (mode, op0);
9433 set_mem_attributes (temp, exp, 0);
9434 set_mem_addr_space (temp, as);
9435 if (TREE_THIS_VOLATILE (exp))
9436 MEM_VOLATILE_P (temp) = 1;
9438 && align < GET_MODE_ALIGNMENT (mode)
9439 /* If the target does not have special handling for unaligned
9440 loads of mode then it can use regular moves for them. */
9441 && ((icode = optab_handler (movmisalign_optab, mode))
9442 != CODE_FOR_nothing))
9444 struct expand_operand ops[2];
9446 /* We've already validated the memory, and we're creating a
9447 new pseudo destination. The predicates really can't fail,
9448 nor can the generator. */
9449 create_output_operand (&ops[0], NULL_RTX, mode);
9450 create_fixed_operand (&ops[1], temp);
9451 expand_insn (icode, 2, ops);
9452 return ops[0].value;
9460 tree array = treeop0;
9461 tree index = treeop1;
9463 /* Fold an expression like: "foo"[2].
9464 This is not done in fold so it won't happen inside &.
9465 Don't fold if this is for wide characters since it's too
9466 difficult to do correctly and this is a very rare case. */
9468 if (modifier != EXPAND_CONST_ADDRESS
9469 && modifier != EXPAND_INITIALIZER
9470 && modifier != EXPAND_MEMORY)
9472 tree t = fold_read_from_constant_string (exp);
9475 return expand_expr (t, target, tmode, modifier);
9478 /* If this is a constant index into a constant array,
9479 just get the value from the array. Handle both the cases when
9480 we have an explicit constructor and when our operand is a variable
9481 that was declared const. */
9483 if (modifier != EXPAND_CONST_ADDRESS
9484 && modifier != EXPAND_INITIALIZER
9485 && modifier != EXPAND_MEMORY
9486 && TREE_CODE (array) == CONSTRUCTOR
9487 && ! TREE_SIDE_EFFECTS (array)
9488 && TREE_CODE (index) == INTEGER_CST)
9490 unsigned HOST_WIDE_INT ix;
9493 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
9495 if (tree_int_cst_equal (field, index))
9497 if (!TREE_SIDE_EFFECTS (value))
9498 return expand_expr (fold (value), target, tmode, modifier);
9503 else if (optimize >= 1
9504 && modifier != EXPAND_CONST_ADDRESS
9505 && modifier != EXPAND_INITIALIZER
9506 && modifier != EXPAND_MEMORY
9507 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
9508 && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
9509 && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK
9510 && const_value_known_p (array))
9512 if (TREE_CODE (index) == INTEGER_CST)
9514 tree init = DECL_INITIAL (array);
9516 if (TREE_CODE (init) == CONSTRUCTOR)
9518 unsigned HOST_WIDE_INT ix;
9521 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
9523 if (tree_int_cst_equal (field, index))
9525 if (TREE_SIDE_EFFECTS (value))
9528 if (TREE_CODE (value) == CONSTRUCTOR)
9530 /* If VALUE is a CONSTRUCTOR, this
9531 optimization is only useful if
9532 this doesn't store the CONSTRUCTOR
9533 into memory. If it does, it is more
9534 efficient to just load the data from
9535 the array directly. */
9536 rtx ret = expand_constructor (value, target,
9538 if (ret == NULL_RTX)
9542 return expand_expr (fold (value), target, tmode,
9546 else if(TREE_CODE (init) == STRING_CST)
9548 tree index1 = index;
9549 tree low_bound = array_ref_low_bound (exp);
9550 index1 = fold_convert_loc (loc, sizetype,
9553 /* Optimize the special-case of a zero lower bound.
9555 We convert the low_bound to sizetype to avoid some problems
9556 with constant folding. (E.g. suppose the lower bound is 1,
9557 and its mode is QI. Without the conversion,l (ARRAY
9558 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
9559 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
9561 if (! integer_zerop (low_bound))
9562 index1 = size_diffop_loc (loc, index1,
9563 fold_convert_loc (loc, sizetype,
9566 if (0 > compare_tree_int (index1,
9567 TREE_STRING_LENGTH (init)))
9569 tree type = TREE_TYPE (TREE_TYPE (init));
9570 enum machine_mode mode = TYPE_MODE (type);
9572 if (GET_MODE_CLASS (mode) == MODE_INT
9573 && GET_MODE_SIZE (mode) == 1)
9574 return gen_int_mode (TREE_STRING_POINTER (init)
9575 [TREE_INT_CST_LOW (index1)],
9582 goto normal_inner_ref;
9585 /* If the operand is a CONSTRUCTOR, we can just extract the
9586 appropriate field if it is present. */
9587 if (TREE_CODE (treeop0) == CONSTRUCTOR)
9589 unsigned HOST_WIDE_INT idx;
9592 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0),
9594 if (field == treeop1
9595 /* We can normally use the value of the field in the
9596 CONSTRUCTOR. However, if this is a bitfield in
9597 an integral mode that we can fit in a HOST_WIDE_INT,
9598 we must mask only the number of bits in the bitfield,
9599 since this is done implicitly by the constructor. If
9600 the bitfield does not meet either of those conditions,
9601 we can't do this optimization. */
9602 && (! DECL_BIT_FIELD (field)
9603 || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
9604 && (GET_MODE_PRECISION (DECL_MODE (field))
9605 <= HOST_BITS_PER_WIDE_INT))))
9607 if (DECL_BIT_FIELD (field)
9608 && modifier == EXPAND_STACK_PARM)
9610 op0 = expand_expr (value, target, tmode, modifier);
9611 if (DECL_BIT_FIELD (field))
9613 HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
9614 enum machine_mode imode = TYPE_MODE (TREE_TYPE (field));
9616 if (TYPE_UNSIGNED (TREE_TYPE (field)))
9618 op1 = GEN_INT (((HOST_WIDE_INT) 1 << bitsize) - 1);
9619 op0 = expand_and (imode, op0, op1, target);
9623 int count = GET_MODE_PRECISION (imode) - bitsize;
9625 op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
9627 op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
9635 goto normal_inner_ref;
9638 case ARRAY_RANGE_REF:
9641 enum machine_mode mode1, mode2;
9642 HOST_WIDE_INT bitsize, bitpos;
9644 int volatilep = 0, must_force_mem;
9645 bool packedp = false;
9646 tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
9647 &mode1, &unsignedp, &volatilep, true);
9648 rtx orig_op0, memloc;
9650 /* If we got back the original object, something is wrong. Perhaps
9651 we are evaluating an expression too early. In any event, don't
9652 infinitely recurse. */
9653 gcc_assert (tem != exp);
9655 if (TYPE_PACKED (TREE_TYPE (TREE_OPERAND (exp, 0)))
9656 || (TREE_CODE (TREE_OPERAND (exp, 1)) == FIELD_DECL
9657 && DECL_PACKED (TREE_OPERAND (exp, 1))))
9660 /* If TEM's type is a union of variable size, pass TARGET to the inner
9661 computation, since it will need a temporary and TARGET is known
9662 to have to do. This occurs in unchecked conversion in Ada. */
9665 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
9666 && COMPLETE_TYPE_P (TREE_TYPE (tem))
9667 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
9669 && modifier != EXPAND_STACK_PARM
9670 ? target : NULL_RTX),
9672 (modifier == EXPAND_INITIALIZER
9673 || modifier == EXPAND_CONST_ADDRESS
9674 || modifier == EXPAND_STACK_PARM)
9675 ? modifier : EXPAND_NORMAL);
9678 /* If the bitfield is volatile, we want to access it in the
9679 field's mode, not the computed mode.
9680 If a MEM has VOIDmode (external with incomplete type),
9681 use BLKmode for it instead. */
9684 if (volatilep && flag_strict_volatile_bitfields > 0)
9685 op0 = adjust_address (op0, mode1, 0);
9686 else if (GET_MODE (op0) == VOIDmode)
9687 op0 = adjust_address (op0, BLKmode, 0);
9691 = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
9693 /* If we have either an offset, a BLKmode result, or a reference
9694 outside the underlying object, we must force it to memory.
9695 Such a case can occur in Ada if we have unchecked conversion
9696 of an expression from a scalar type to an aggregate type or
9697 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9698 passed a partially uninitialized object or a view-conversion
9699 to a larger size. */
9700 must_force_mem = (offset
9702 || bitpos + bitsize > GET_MODE_BITSIZE (mode2));
9704 /* Handle CONCAT first. */
9705 if (GET_CODE (op0) == CONCAT && !must_force_mem)
9708 && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)))
9711 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
9714 op0 = XEXP (op0, 0);
9715 mode2 = GET_MODE (op0);
9717 else if (bitpos == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
9718 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1)))
9722 op0 = XEXP (op0, 1);
9724 mode2 = GET_MODE (op0);
9727 /* Otherwise force into memory. */
9731 /* If this is a constant, put it in a register if it is a legitimate
9732 constant and we don't need a memory reference. */
9733 if (CONSTANT_P (op0)
9735 && targetm.legitimate_constant_p (mode2, op0)
9737 op0 = force_reg (mode2, op0);
9739 /* Otherwise, if this is a constant, try to force it to the constant
9740 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9741 is a legitimate constant. */
9742 else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
9743 op0 = validize_mem (memloc);
9745 /* Otherwise, if this is a constant or the object is not in memory
9746 and need be, put it there. */
9747 else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
9749 tree nt = build_qualified_type (TREE_TYPE (tem),
9750 (TYPE_QUALS (TREE_TYPE (tem))
9751 | TYPE_QUAL_CONST));
9752 memloc = assign_temp (nt, 1, 1, 1);
9753 emit_move_insn (memloc, op0);
9759 enum machine_mode address_mode;
9760 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
9763 gcc_assert (MEM_P (op0));
9766 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (op0));
9767 if (GET_MODE (offset_rtx) != address_mode)
9768 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
9770 if (GET_MODE (op0) == BLKmode
9771 /* A constant address in OP0 can have VOIDmode, we must
9772 not try to call force_reg in that case. */
9773 && GET_MODE (XEXP (op0, 0)) != VOIDmode
9775 && (bitpos % bitsize) == 0
9776 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
9777 && MEM_ALIGN (op0) == GET_MODE_ALIGNMENT (mode1))
9779 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
9783 op0 = offset_address (op0, offset_rtx,
9784 highest_pow2_factor (offset));
9787 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
9788 record its alignment as BIGGEST_ALIGNMENT. */
9789 if (MEM_P (op0) && bitpos == 0 && offset != 0
9790 && is_aligning_offset (offset, tem))
9791 set_mem_align (op0, BIGGEST_ALIGNMENT);
9793 /* Don't forget about volatility even if this is a bitfield. */
9794 if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
9796 if (op0 == orig_op0)
9797 op0 = copy_rtx (op0);
9799 MEM_VOLATILE_P (op0) = 1;
9802 /* In cases where an aligned union has an unaligned object
9803 as a field, we might be extracting a BLKmode value from
9804 an integer-mode (e.g., SImode) object. Handle this case
9805 by doing the extract into an object as wide as the field
9806 (which we know to be the width of a basic mode), then
9807 storing into memory, and changing the mode to BLKmode. */
9808 if (mode1 == VOIDmode
9809 || REG_P (op0) || GET_CODE (op0) == SUBREG
9810 || (mode1 != BLKmode && ! direct_load[(int) mode1]
9811 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
9812 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
9813 && modifier != EXPAND_CONST_ADDRESS
9814 && modifier != EXPAND_INITIALIZER)
9815 /* If the field is volatile, we always want an aligned
9816 access. Do this in following two situations:
9817 1. the access is not already naturally
9818 aligned, otherwise "normal" (non-bitfield) volatile fields
9819 become non-addressable.
9820 2. the bitsize is narrower than the access size. Need
9821 to extract bitfields from the access. */
9822 || (volatilep && flag_strict_volatile_bitfields > 0
9823 && (bitpos % GET_MODE_ALIGNMENT (mode) != 0
9824 || (mode1 != BLKmode
9825 && bitsize < GET_MODE_SIZE (mode1) * BITS_PER_UNIT)))
9826 /* If the field isn't aligned enough to fetch as a memref,
9827 fetch it as a bit field. */
9828 || (mode1 != BLKmode
9829 && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
9830 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
9832 && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
9833 || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
9834 && ((modifier == EXPAND_CONST_ADDRESS
9835 || modifier == EXPAND_INITIALIZER)
9837 : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
9838 || (bitpos % BITS_PER_UNIT != 0)))
9839 /* If the type and the field are a constant size and the
9840 size of the type isn't the same size as the bitfield,
9841 we must use bitfield operations. */
9843 && TYPE_SIZE (TREE_TYPE (exp))
9844 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
9845 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
9848 enum machine_mode ext_mode = mode;
9850 if (ext_mode == BLKmode
9851 && ! (target != 0 && MEM_P (op0)
9853 && bitpos % BITS_PER_UNIT == 0))
9854 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
9856 if (ext_mode == BLKmode)
9859 target = assign_temp (type, 0, 1, 1);
9864 /* In this case, BITPOS must start at a byte boundary and
9865 TARGET, if specified, must be a MEM. */
9866 gcc_assert (MEM_P (op0)
9867 && (!target || MEM_P (target))
9868 && !(bitpos % BITS_PER_UNIT));
9870 emit_block_move (target,
9871 adjust_address (op0, VOIDmode,
9872 bitpos / BITS_PER_UNIT),
9873 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
9875 (modifier == EXPAND_STACK_PARM
9876 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
9881 op0 = validize_mem (op0);
9883 if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
9884 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
9886 op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp, packedp,
9887 (modifier == EXPAND_STACK_PARM
9888 ? NULL_RTX : target),
9889 ext_mode, ext_mode);
9891 /* If the result is a record type and BITSIZE is narrower than
9892 the mode of OP0, an integral mode, and this is a big endian
9893 machine, we must put the field into the high-order bits. */
9894 if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
9895 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
9896 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
9897 op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
9898 GET_MODE_BITSIZE (GET_MODE (op0))
9901 /* If the result type is BLKmode, store the data into a temporary
9902 of the appropriate type, but with the mode corresponding to the
9903 mode for the data we have (op0's mode). It's tempting to make
9904 this a constant type, since we know it's only being stored once,
9905 but that can cause problems if we are taking the address of this
9906 COMPONENT_REF because the MEM of any reference via that address
9907 will have flags corresponding to the type, which will not
9908 necessarily be constant. */
9909 if (mode == BLKmode)
9911 HOST_WIDE_INT size = GET_MODE_BITSIZE (ext_mode);
9914 /* If the reference doesn't use the alias set of its type,
9915 we cannot create the temporary using that type. */
9916 if (component_uses_parent_alias_set (exp))
9918 new_rtx = assign_stack_local (ext_mode, size, 0);
9919 set_mem_alias_set (new_rtx, get_alias_set (exp));
9922 new_rtx = assign_stack_temp_for_type (ext_mode, size, 0, type);
9924 emit_move_insn (new_rtx, op0);
9925 op0 = copy_rtx (new_rtx);
9926 PUT_MODE (op0, BLKmode);
9927 set_mem_attributes (op0, exp, 1);
9933 /* If the result is BLKmode, use that to access the object
9935 if (mode == BLKmode)
9938 /* Get a reference to just this component. */
9939 if (modifier == EXPAND_CONST_ADDRESS
9940 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
9941 op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
9943 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
9945 if (op0 == orig_op0)
9946 op0 = copy_rtx (op0);
9948 set_mem_attributes (op0, exp, 0);
9949 if (REG_P (XEXP (op0, 0)))
9950 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
9952 MEM_VOLATILE_P (op0) |= volatilep;
9953 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
9954 || modifier == EXPAND_CONST_ADDRESS
9955 || modifier == EXPAND_INITIALIZER)
9957 else if (target == 0)
9958 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
9960 convert_move (target, op0, unsignedp);
9965 return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
9968 /* All valid uses of __builtin_va_arg_pack () are removed during
9970 if (CALL_EXPR_VA_ARG_PACK (exp))
9971 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
9973 tree fndecl = get_callee_fndecl (exp), attr;
9976 && (attr = lookup_attribute ("error",
9977 DECL_ATTRIBUTES (fndecl))) != NULL)
9978 error ("%Kcall to %qs declared with attribute error: %s",
9979 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
9980 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
9982 && (attr = lookup_attribute ("warning",
9983 DECL_ATTRIBUTES (fndecl))) != NULL)
9984 warning_at (tree_nonartificial_location (exp),
9985 0, "%Kcall to %qs declared with attribute warning: %s",
9986 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
9987 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
9989 /* Check for a built-in function. */
9990 if (fndecl && DECL_BUILT_IN (fndecl))
9992 gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
9993 return expand_builtin (exp, target, subtarget, tmode, ignore);
9996 return expand_call (exp, target, ignore);
9998 case VIEW_CONVERT_EXPR:
10001 /* If we are converting to BLKmode, try to avoid an intermediate
10002 temporary by fetching an inner memory reference. */
10003 if (mode == BLKmode
10004 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
10005 && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
10006 && handled_component_p (treeop0))
10008 enum machine_mode mode1;
10009 HOST_WIDE_INT bitsize, bitpos;
10014 = get_inner_reference (treeop0, &bitsize, &bitpos,
10015 &offset, &mode1, &unsignedp, &volatilep,
10019 /* ??? We should work harder and deal with non-zero offsets. */
10021 && (bitpos % BITS_PER_UNIT) == 0
10023 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) == 0)
10025 /* See the normal_inner_ref case for the rationale. */
10027 = expand_expr (tem,
10028 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
10029 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
10031 && modifier != EXPAND_STACK_PARM
10032 ? target : NULL_RTX),
10034 (modifier == EXPAND_INITIALIZER
10035 || modifier == EXPAND_CONST_ADDRESS
10036 || modifier == EXPAND_STACK_PARM)
10037 ? modifier : EXPAND_NORMAL);
10039 if (MEM_P (orig_op0))
10043 /* Get a reference to just this component. */
10044 if (modifier == EXPAND_CONST_ADDRESS
10045 || modifier == EXPAND_SUM
10046 || modifier == EXPAND_INITIALIZER)
10047 op0 = adjust_address_nv (op0, mode, bitpos / BITS_PER_UNIT);
10049 op0 = adjust_address (op0, mode, bitpos / BITS_PER_UNIT);
10051 if (op0 == orig_op0)
10052 op0 = copy_rtx (op0);
10054 set_mem_attributes (op0, treeop0, 0);
10055 if (REG_P (XEXP (op0, 0)))
10056 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10058 MEM_VOLATILE_P (op0) |= volatilep;
10064 op0 = expand_expr (treeop0,
10065 NULL_RTX, VOIDmode, modifier);
10067 /* If the input and output modes are both the same, we are done. */
10068 if (mode == GET_MODE (op0))
10070 /* If neither mode is BLKmode, and both modes are the same size
10071 then we can use gen_lowpart. */
10072 else if (mode != BLKmode && GET_MODE (op0) != BLKmode
10073 && (GET_MODE_PRECISION (mode)
10074 == GET_MODE_PRECISION (GET_MODE (op0)))
10075 && !COMPLEX_MODE_P (GET_MODE (op0)))
10077 if (GET_CODE (op0) == SUBREG)
10078 op0 = force_reg (GET_MODE (op0), op0);
10079 temp = gen_lowpart_common (mode, op0);
10084 if (!REG_P (op0) && !MEM_P (op0))
10085 op0 = force_reg (GET_MODE (op0), op0);
10086 op0 = gen_lowpart (mode, op0);
10089 /* If both types are integral, convert from one mode to the other. */
10090 else if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0)))
10091 op0 = convert_modes (mode, GET_MODE (op0), op0,
10092 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10093 /* As a last resort, spill op0 to memory, and reload it in a
10095 else if (!MEM_P (op0))
10097 /* If the operand is not a MEM, force it into memory. Since we
10098 are going to be changing the mode of the MEM, don't call
10099 force_const_mem for constants because we don't allow pool
10100 constants to change mode. */
10101 tree inner_type = TREE_TYPE (treeop0);
10103 gcc_assert (!TREE_ADDRESSABLE (exp));
10105 if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
10107 = assign_stack_temp_for_type
10108 (TYPE_MODE (inner_type),
10109 GET_MODE_SIZE (TYPE_MODE (inner_type)), 0, inner_type);
10111 emit_move_insn (target, op0);
10115 /* At this point, OP0 is in the correct mode. If the output type is
10116 such that the operand is known to be aligned, indicate that it is.
10117 Otherwise, we need only be concerned about alignment for non-BLKmode
10121 enum insn_code icode;
10123 op0 = copy_rtx (op0);
10125 if (TYPE_ALIGN_OK (type))
10126 set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
10127 else if (mode != BLKmode
10128 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode)
10129 /* If the target does have special handling for unaligned
10130 loads of mode then use them. */
10131 && ((icode = optab_handler (movmisalign_optab, mode))
10132 != CODE_FOR_nothing))
10136 op0 = adjust_address (op0, mode, 0);
10137 /* We've already validated the memory, and we're creating a
10138 new pseudo destination. The predicates really can't
10140 reg = gen_reg_rtx (mode);
10142 /* Nor can the insn generator. */
10143 insn = GEN_FCN (icode) (reg, op0);
10147 else if (STRICT_ALIGNMENT
10149 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
10151 tree inner_type = TREE_TYPE (treeop0);
10152 HOST_WIDE_INT temp_size
10153 = MAX (int_size_in_bytes (inner_type),
10154 (HOST_WIDE_INT) GET_MODE_SIZE (mode));
10156 = assign_stack_temp_for_type (mode, temp_size, 0, type);
10157 rtx new_with_op0_mode
10158 = adjust_address (new_rtx, GET_MODE (op0), 0);
10160 gcc_assert (!TREE_ADDRESSABLE (exp));
10162 if (GET_MODE (op0) == BLKmode)
10163 emit_block_move (new_with_op0_mode, op0,
10164 GEN_INT (GET_MODE_SIZE (mode)),
10165 (modifier == EXPAND_STACK_PARM
10166 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
10168 emit_move_insn (new_with_op0_mode, op0);
10173 op0 = adjust_address (op0, mode, 0);
10180 tree lhs = treeop0;
10181 tree rhs = treeop1;
10182 gcc_assert (ignore);
10184 /* Check for |= or &= of a bitfield of size one into another bitfield
10185 of size 1. In this case, (unless we need the result of the
10186 assignment) we can do this more efficiently with a
10187 test followed by an assignment, if necessary.
10189 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10190 things change so we do, this code should be enhanced to
10192 if (TREE_CODE (lhs) == COMPONENT_REF
10193 && (TREE_CODE (rhs) == BIT_IOR_EXPR
10194 || TREE_CODE (rhs) == BIT_AND_EXPR)
10195 && TREE_OPERAND (rhs, 0) == lhs
10196 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
10197 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
10198 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
10200 rtx label = gen_label_rtx ();
10201 int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
10202 do_jump (TREE_OPERAND (rhs, 1),
10204 value ? 0 : label, -1);
10205 expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
10206 MOVE_NONTEMPORAL (exp));
10207 do_pending_stack_adjust ();
10208 emit_label (label);
10212 expand_assignment (lhs, rhs, MOVE_NONTEMPORAL (exp));
10217 return expand_expr_addr_expr (exp, target, tmode, modifier);
10219 case REALPART_EXPR:
10220 op0 = expand_normal (treeop0);
10221 return read_complex_part (op0, false);
10223 case IMAGPART_EXPR:
10224 op0 = expand_normal (treeop0);
10225 return read_complex_part (op0, true);
10232 /* Expanded in cfgexpand.c. */
10233 gcc_unreachable ();
10235 case TRY_CATCH_EXPR:
10237 case EH_FILTER_EXPR:
10238 case TRY_FINALLY_EXPR:
10239 /* Lowered by tree-eh.c. */
10240 gcc_unreachable ();
10242 case WITH_CLEANUP_EXPR:
10243 case CLEANUP_POINT_EXPR:
10245 case CASE_LABEL_EXPR:
10250 case COMPOUND_EXPR:
10251 case PREINCREMENT_EXPR:
10252 case PREDECREMENT_EXPR:
10253 case POSTINCREMENT_EXPR:
10254 case POSTDECREMENT_EXPR:
10257 /* Lowered by gimplify.c. */
10258 gcc_unreachable ();
10261 /* Function descriptors are not valid except for as
10262 initialization constants, and should not be expanded. */
10263 gcc_unreachable ();
10265 case WITH_SIZE_EXPR:
10266 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10267 have pulled out the size to use in whatever context it needed. */
10268 return expand_expr_real (treeop0, original_target, tmode,
10269 modifier, alt_rtl);
10271 case COMPOUND_LITERAL_EXPR:
10273 /* Initialize the anonymous variable declared in the compound
10274 literal, then return the variable. */
10275 tree decl = COMPOUND_LITERAL_EXPR_DECL (exp);
10277 /* Create RTL for this variable. */
10278 if (!DECL_RTL_SET_P (decl))
10280 if (DECL_HARD_REGISTER (decl))
10281 /* The user specified an assembler name for this variable.
10282 Set that up now. */
10283 rest_of_decl_compilation (decl, 0, 0);
10285 expand_decl (decl);
10288 return expand_expr_real (decl, original_target, tmode,
10289 modifier, alt_rtl);
10293 return expand_expr_real_2 (&ops, target, tmode, modifier);
10297 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10298 signedness of TYPE), possibly returning the result in TARGET. */
10300 reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
10302 HOST_WIDE_INT prec = TYPE_PRECISION (type);
10303 if (target && GET_MODE (target) != GET_MODE (exp))
10305 /* For constant values, reduce using build_int_cst_type. */
10306 if (CONST_INT_P (exp))
10308 HOST_WIDE_INT value = INTVAL (exp);
10309 tree t = build_int_cst_type (type, value);
10310 return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
10312 else if (TYPE_UNSIGNED (type))
10314 rtx mask = immed_double_int_const (double_int_mask (prec),
10316 return expand_and (GET_MODE (exp), exp, mask, target);
10320 int count = GET_MODE_PRECISION (GET_MODE (exp)) - prec;
10321 exp = expand_shift (LSHIFT_EXPR, GET_MODE (exp),
10322 exp, count, target, 0);
10323 return expand_shift (RSHIFT_EXPR, GET_MODE (exp),
10324 exp, count, target, 0);
10328 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10329 when applied to the address of EXP produces an address known to be
10330 aligned more than BIGGEST_ALIGNMENT. */
10333 is_aligning_offset (const_tree offset, const_tree exp)
10335 /* Strip off any conversions. */
10336 while (CONVERT_EXPR_P (offset))
10337 offset = TREE_OPERAND (offset, 0);
10339 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10340 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10341 if (TREE_CODE (offset) != BIT_AND_EXPR
10342 || !host_integerp (TREE_OPERAND (offset, 1), 1)
10343 || compare_tree_int (TREE_OPERAND (offset, 1),
10344 BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
10345 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
10348 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10349 It must be NEGATE_EXPR. Then strip any more conversions. */
10350 offset = TREE_OPERAND (offset, 0);
10351 while (CONVERT_EXPR_P (offset))
10352 offset = TREE_OPERAND (offset, 0);
10354 if (TREE_CODE (offset) != NEGATE_EXPR)
10357 offset = TREE_OPERAND (offset, 0);
10358 while (CONVERT_EXPR_P (offset))
10359 offset = TREE_OPERAND (offset, 0);
10361 /* This must now be the address of EXP. */
10362 return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
10365 /* Return the tree node if an ARG corresponds to a string constant or zero
10366 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10367 in bytes within the string that ARG is accessing. The type of the
10368 offset will be `sizetype'. */
10371 string_constant (tree arg, tree *ptr_offset)
10373 tree array, offset, lower_bound;
10376 if (TREE_CODE (arg) == ADDR_EXPR)
10378 if (TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
10380 *ptr_offset = size_zero_node;
10381 return TREE_OPERAND (arg, 0);
10383 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL)
10385 array = TREE_OPERAND (arg, 0);
10386 offset = size_zero_node;
10388 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF)
10390 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10391 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10392 if (TREE_CODE (array) != STRING_CST
10393 && TREE_CODE (array) != VAR_DECL)
10396 /* Check if the array has a nonzero lower bound. */
10397 lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
10398 if (!integer_zerop (lower_bound))
10400 /* If the offset and base aren't both constants, return 0. */
10401 if (TREE_CODE (lower_bound) != INTEGER_CST)
10403 if (TREE_CODE (offset) != INTEGER_CST)
10405 /* Adjust offset by the lower bound. */
10406 offset = size_diffop (fold_convert (sizetype, offset),
10407 fold_convert (sizetype, lower_bound));
10410 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == MEM_REF)
10412 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10413 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10414 if (TREE_CODE (array) != ADDR_EXPR)
10416 array = TREE_OPERAND (array, 0);
10417 if (TREE_CODE (array) != STRING_CST
10418 && TREE_CODE (array) != VAR_DECL)
10424 else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
10426 tree arg0 = TREE_OPERAND (arg, 0);
10427 tree arg1 = TREE_OPERAND (arg, 1);
10432 if (TREE_CODE (arg0) == ADDR_EXPR
10433 && (TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST
10434 || TREE_CODE (TREE_OPERAND (arg0, 0)) == VAR_DECL))
10436 array = TREE_OPERAND (arg0, 0);
10439 else if (TREE_CODE (arg1) == ADDR_EXPR
10440 && (TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST
10441 || TREE_CODE (TREE_OPERAND (arg1, 0)) == VAR_DECL))
10443 array = TREE_OPERAND (arg1, 0);
10452 if (TREE_CODE (array) == STRING_CST)
10454 *ptr_offset = fold_convert (sizetype, offset);
10457 else if (TREE_CODE (array) == VAR_DECL
10458 || TREE_CODE (array) == CONST_DECL)
10462 /* Variables initialized to string literals can be handled too. */
10463 if (!const_value_known_p (array)
10464 || !DECL_INITIAL (array)
10465 || TREE_CODE (DECL_INITIAL (array)) != STRING_CST)
10468 /* Avoid const char foo[4] = "abcde"; */
10469 if (DECL_SIZE_UNIT (array) == NULL_TREE
10470 || TREE_CODE (DECL_SIZE_UNIT (array)) != INTEGER_CST
10471 || (length = TREE_STRING_LENGTH (DECL_INITIAL (array))) <= 0
10472 || compare_tree_int (DECL_SIZE_UNIT (array), length) < 0)
10475 /* If variable is bigger than the string literal, OFFSET must be constant
10476 and inside of the bounds of the string literal. */
10477 offset = fold_convert (sizetype, offset);
10478 if (compare_tree_int (DECL_SIZE_UNIT (array), length) > 0
10479 && (! host_integerp (offset, 1)
10480 || compare_tree_int (offset, length) >= 0))
10483 *ptr_offset = offset;
10484 return DECL_INITIAL (array);
10490 /* Generate code to calculate OPS, and exploded expression
10491 using a store-flag instruction and return an rtx for the result.
10492 OPS reflects a comparison.
10494 If TARGET is nonzero, store the result there if convenient.
10496 Return zero if there is no suitable set-flag instruction
10497 available on this machine.
10499 Once expand_expr has been called on the arguments of the comparison,
10500 we are committed to doing the store flag, since it is not safe to
10501 re-evaluate the expression. We emit the store-flag insn by calling
10502 emit_store_flag, but only expand the arguments if we have a reason
10503 to believe that emit_store_flag will be successful. If we think that
10504 it will, but it isn't, we have to simulate the store-flag with a
10505 set/jump/set sequence. */
10508 do_store_flag (sepops ops, rtx target, enum machine_mode mode)
10510 enum rtx_code code;
10511 tree arg0, arg1, type;
10513 enum machine_mode operand_mode;
10516 rtx subtarget = target;
10517 location_t loc = ops->location;
10522 /* Don't crash if the comparison was erroneous. */
10523 if (arg0 == error_mark_node || arg1 == error_mark_node)
10526 type = TREE_TYPE (arg0);
10527 operand_mode = TYPE_MODE (type);
10528 unsignedp = TYPE_UNSIGNED (type);
10530 /* We won't bother with BLKmode store-flag operations because it would mean
10531 passing a lot of information to emit_store_flag. */
10532 if (operand_mode == BLKmode)
10535 /* We won't bother with store-flag operations involving function pointers
10536 when function pointers must be canonicalized before comparisons. */
10537 #ifdef HAVE_canonicalize_funcptr_for_compare
10538 if (HAVE_canonicalize_funcptr_for_compare
10539 && ((TREE_CODE (TREE_TYPE (arg0)) == POINTER_TYPE
10540 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0)))
10542 || (TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE
10543 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1)))
10544 == FUNCTION_TYPE))))
10551 /* For vector typed comparisons emit code to generate the desired
10552 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10553 expander for this. */
10554 if (TREE_CODE (ops->type) == VECTOR_TYPE)
10556 tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
10557 tree if_true = constant_boolean_node (true, ops->type);
10558 tree if_false = constant_boolean_node (false, ops->type);
10559 return expand_vec_cond_expr (ops->type, ifexp, if_true, if_false, target);
10562 /* For vector typed comparisons emit code to generate the desired
10563 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10564 expander for this. */
10565 if (TREE_CODE (ops->type) == VECTOR_TYPE)
10567 tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
10568 tree if_true = constant_boolean_node (true, ops->type);
10569 tree if_false = constant_boolean_node (false, ops->type);
10570 return expand_vec_cond_expr (ops->type, ifexp, if_true, if_false, target);
10573 /* Get the rtx comparison code to use. We know that EXP is a comparison
10574 operation of some type. Some comparisons against 1 and -1 can be
10575 converted to comparisons with zero. Do so here so that the tests
10576 below will be aware that we have a comparison with zero. These
10577 tests will not catch constants in the first operand, but constants
10578 are rarely passed as the first operand. */
10589 if (integer_onep (arg1))
10590 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
10592 code = unsignedp ? LTU : LT;
10595 if (! unsignedp && integer_all_onesp (arg1))
10596 arg1 = integer_zero_node, code = LT;
10598 code = unsignedp ? LEU : LE;
10601 if (! unsignedp && integer_all_onesp (arg1))
10602 arg1 = integer_zero_node, code = GE;
10604 code = unsignedp ? GTU : GT;
10607 if (integer_onep (arg1))
10608 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
10610 code = unsignedp ? GEU : GE;
10613 case UNORDERED_EXPR:
10639 gcc_unreachable ();
10642 /* Put a constant second. */
10643 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
10644 || TREE_CODE (arg0) == FIXED_CST)
10646 tem = arg0; arg0 = arg1; arg1 = tem;
10647 code = swap_condition (code);
10650 /* If this is an equality or inequality test of a single bit, we can
10651 do this by shifting the bit being tested to the low-order bit and
10652 masking the result with the constant 1. If the condition was EQ,
10653 we xor it with 1. This does not require an scc insn and is faster
10654 than an scc insn even if we have it.
10656 The code to make this transformation was moved into fold_single_bit_test,
10657 so we just call into the folder and expand its result. */
10659 if ((code == NE || code == EQ)
10660 && integer_zerop (arg1)
10661 && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
10663 gimple srcstmt = get_def_for_expr (arg0, BIT_AND_EXPR);
10665 && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
10667 enum tree_code tcode = code == NE ? NE_EXPR : EQ_EXPR;
10668 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10669 tree temp = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg1),
10670 gimple_assign_rhs1 (srcstmt),
10671 gimple_assign_rhs2 (srcstmt));
10672 temp = fold_single_bit_test (loc, tcode, temp, arg1, type);
10674 return expand_expr (temp, target, VOIDmode, EXPAND_NORMAL);
10678 if (! get_subtarget (target)
10679 || GET_MODE (subtarget) != operand_mode)
10682 expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
10685 target = gen_reg_rtx (mode);
10687 /* Try a cstore if possible. */
10688 return emit_store_flag_force (target, code, op0, op1,
10689 operand_mode, unsignedp,
10690 (TYPE_PRECISION (ops->type) == 1
10691 && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
10695 /* Stubs in case we haven't got a casesi insn. */
10696 #ifndef HAVE_casesi
10697 # define HAVE_casesi 0
10698 # define gen_casesi(a, b, c, d, e) (0)
10699 # define CODE_FOR_casesi CODE_FOR_nothing
10702 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10703 0 otherwise (i.e. if there is no casesi instruction). */
10705 try_casesi (tree index_type, tree index_expr, tree minval, tree range,
10706 rtx table_label ATTRIBUTE_UNUSED, rtx default_label,
10707 rtx fallback_label ATTRIBUTE_UNUSED)
10709 struct expand_operand ops[5];
10710 enum machine_mode index_mode = SImode;
10711 int index_bits = GET_MODE_BITSIZE (index_mode);
10712 rtx op1, op2, index;
10717 /* Convert the index to SImode. */
10718 if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
10720 enum machine_mode omode = TYPE_MODE (index_type);
10721 rtx rangertx = expand_normal (range);
10723 /* We must handle the endpoints in the original mode. */
10724 index_expr = build2 (MINUS_EXPR, index_type,
10725 index_expr, minval);
10726 minval = integer_zero_node;
10727 index = expand_normal (index_expr);
10729 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
10730 omode, 1, default_label);
10731 /* Now we can safely truncate. */
10732 index = convert_to_mode (index_mode, index, 0);
10736 if (TYPE_MODE (index_type) != index_mode)
10738 index_type = lang_hooks.types.type_for_size (index_bits, 0);
10739 index_expr = fold_convert (index_type, index_expr);
10742 index = expand_normal (index_expr);
10745 do_pending_stack_adjust ();
10747 op1 = expand_normal (minval);
10748 op2 = expand_normal (range);
10750 create_input_operand (&ops[0], index, index_mode);
10751 create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
10752 create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
10753 create_fixed_operand (&ops[3], table_label);
10754 create_fixed_operand (&ops[4], (default_label
10756 : fallback_label));
10757 expand_jump_insn (CODE_FOR_casesi, 5, ops);
10761 /* Attempt to generate a tablejump instruction; same concept. */
10762 #ifndef HAVE_tablejump
10763 #define HAVE_tablejump 0
10764 #define gen_tablejump(x, y) (0)
10767 /* Subroutine of the next function.
10769 INDEX is the value being switched on, with the lowest value
10770 in the table already subtracted.
10771 MODE is its expected mode (needed if INDEX is constant).
10772 RANGE is the length of the jump table.
10773 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10775 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10776 index value is out of range. */
10779 do_tablejump (rtx index, enum machine_mode mode, rtx range, rtx table_label,
10784 if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
10785 cfun->cfg->max_jumptable_ents = INTVAL (range);
10787 /* Do an unsigned comparison (in the proper mode) between the index
10788 expression and the value which represents the length of the range.
10789 Since we just finished subtracting the lower bound of the range
10790 from the index expression, this comparison allows us to simultaneously
10791 check that the original index expression value is both greater than
10792 or equal to the minimum value of the range and less than or equal to
10793 the maximum value of the range. */
10796 emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
10799 /* If index is in range, it must fit in Pmode.
10800 Convert to Pmode so we can index with it. */
10802 index = convert_to_mode (Pmode, index, 1);
10804 /* Don't let a MEM slip through, because then INDEX that comes
10805 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
10806 and break_out_memory_refs will go to work on it and mess it up. */
10807 #ifdef PIC_CASE_VECTOR_ADDRESS
10808 if (flag_pic && !REG_P (index))
10809 index = copy_to_mode_reg (Pmode, index);
10812 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
10813 GET_MODE_SIZE, because this indicates how large insns are. The other
10814 uses should all be Pmode, because they are addresses. This code
10815 could fail if addresses and insns are not the same size. */
10816 index = gen_rtx_PLUS (Pmode,
10817 gen_rtx_MULT (Pmode, index,
10818 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))),
10819 gen_rtx_LABEL_REF (Pmode, table_label));
10820 #ifdef PIC_CASE_VECTOR_ADDRESS
10822 index = PIC_CASE_VECTOR_ADDRESS (index);
10825 index = memory_address (CASE_VECTOR_MODE, index);
10826 temp = gen_reg_rtx (CASE_VECTOR_MODE);
10827 vector = gen_const_mem (CASE_VECTOR_MODE, index);
10828 convert_move (temp, vector, 0);
10830 emit_jump_insn (gen_tablejump (temp, table_label));
10832 /* If we are generating PIC code or if the table is PC-relative, the
10833 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
10834 if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
10839 try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
10840 rtx table_label, rtx default_label)
10844 if (! HAVE_tablejump)
10847 index_expr = fold_build2 (MINUS_EXPR, index_type,
10848 fold_convert (index_type, index_expr),
10849 fold_convert (index_type, minval));
10850 index = expand_normal (index_expr);
10851 do_pending_stack_adjust ();
10853 do_tablejump (index, TYPE_MODE (index_type),
10854 convert_modes (TYPE_MODE (index_type),
10855 TYPE_MODE (TREE_TYPE (range)),
10856 expand_normal (range),
10857 TYPE_UNSIGNED (TREE_TYPE (range))),
10858 table_label, default_label);
10862 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
10864 const_vector_from_tree (tree exp)
10869 enum machine_mode inner, mode;
10871 mode = TYPE_MODE (TREE_TYPE (exp));
10873 if (initializer_zerop (exp))
10874 return CONST0_RTX (mode);
10876 units = GET_MODE_NUNITS (mode);
10877 inner = GET_MODE_INNER (mode);
10879 v = rtvec_alloc (units);
10881 link = TREE_VECTOR_CST_ELTS (exp);
10882 for (i = 0; link; link = TREE_CHAIN (link), ++i)
10884 elt = TREE_VALUE (link);
10886 if (TREE_CODE (elt) == REAL_CST)
10887 RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
10889 else if (TREE_CODE (elt) == FIXED_CST)
10890 RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
10893 RTVEC_ELT (v, i) = immed_double_int_const (tree_to_double_int (elt),
10897 /* Initialize remaining elements to 0. */
10898 for (; i < units; ++i)
10899 RTVEC_ELT (v, i) = CONST0_RTX (inner);
10901 return gen_rtx_CONST_VECTOR (mode, v);
10904 /* Build a decl for a personality function given a language prefix. */
10907 build_personality_function (const char *lang)
10909 const char *unwind_and_version;
10913 switch (targetm_common.except_unwind_info (&global_options))
10918 unwind_and_version = "_sj0";
10922 unwind_and_version = "_v0";
10925 gcc_unreachable ();
10928 name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
10930 type = build_function_type_list (integer_type_node, integer_type_node,
10931 long_long_unsigned_type_node,
10932 ptr_type_node, ptr_type_node, NULL_TREE);
10933 decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
10934 get_identifier (name), type);
10935 DECL_ARTIFICIAL (decl) = 1;
10936 DECL_EXTERNAL (decl) = 1;
10937 TREE_PUBLIC (decl) = 1;
10939 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
10940 are the flags assigned by targetm.encode_section_info. */
10941 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
10946 /* Extracts the personality function of DECL and returns the corresponding
10950 get_personality_function (tree decl)
10952 tree personality = DECL_FUNCTION_PERSONALITY (decl);
10953 enum eh_personality_kind pk;
10955 pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
10956 if (pk == eh_personality_none)
10960 && pk == eh_personality_any)
10961 personality = lang_hooks.eh_personality ();
10963 if (pk == eh_personality_lang)
10964 gcc_assert (personality != NULL_TREE);
10966 return XEXP (DECL_RTL (personality), 0);
10969 #include "gt-expr.h"