* libgcov-driver.c (get_gcov_dump_complete): Update comments.
[official-gcc.git] / gcc / expr.c
blobf4d03ab80267ee666ff8f2a370f7e78efc2b06b2
1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "machmode.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "flags.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "except.h"
31 #include "function.h"
32 #include "insn-config.h"
33 #include "insn-attr.h"
34 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
35 #include "expr.h"
36 #include "optabs.h"
37 #include "libfuncs.h"
38 #include "recog.h"
39 #include "reload.h"
40 #include "typeclass.h"
41 #include "toplev.h"
42 #include "langhooks.h"
43 #include "intl.h"
44 #include "tm_p.h"
45 #include "tree-iterator.h"
46 #include "gimple.h"
47 #include "gimple-ssa.h"
48 #include "cgraph.h"
49 #include "tree-ssanames.h"
50 #include "target.h"
51 #include "common/common-target.h"
52 #include "timevar.h"
53 #include "df.h"
54 #include "diagnostic.h"
55 #include "tree-ssa-live.h"
56 #include "tree-outof-ssa.h"
57 #include "target-globals.h"
58 #include "params.h"
59 #include "tree-ssa-address.h"
60 #include "cfgexpand.h"
62 /* Decide whether a function's arguments should be processed
63 from first to last or from last to first.
65 They should if the stack and args grow in opposite directions, but
66 only if we have push insns. */
68 #ifdef PUSH_ROUNDING
70 #ifndef PUSH_ARGS_REVERSED
71 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
72 #define PUSH_ARGS_REVERSED /* If it's last to first. */
73 #endif
74 #endif
76 #endif
78 #ifndef STACK_PUSH_CODE
79 #ifdef STACK_GROWS_DOWNWARD
80 #define STACK_PUSH_CODE PRE_DEC
81 #else
82 #define STACK_PUSH_CODE PRE_INC
83 #endif
84 #endif
87 /* If this is nonzero, we do not bother generating VOLATILE
88 around volatile memory references, and we are willing to
89 output indirect addresses. If cse is to follow, we reject
90 indirect addresses so a useful potential cse is generated;
91 if it is used only once, instruction combination will produce
92 the same indirect address eventually. */
93 int cse_not_expected;
95 /* This structure is used by move_by_pieces to describe the move to
96 be performed. */
97 struct move_by_pieces_d
99 rtx to;
100 rtx to_addr;
101 int autinc_to;
102 int explicit_inc_to;
103 rtx from;
104 rtx from_addr;
105 int autinc_from;
106 int explicit_inc_from;
107 unsigned HOST_WIDE_INT len;
108 HOST_WIDE_INT offset;
109 int reverse;
112 /* This structure is used by store_by_pieces to describe the clear to
113 be performed. */
115 struct store_by_pieces_d
117 rtx to;
118 rtx to_addr;
119 int autinc_to;
120 int explicit_inc_to;
121 unsigned HOST_WIDE_INT len;
122 HOST_WIDE_INT offset;
123 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
124 void *constfundata;
125 int reverse;
128 static void move_by_pieces_1 (insn_gen_fn, machine_mode,
129 struct move_by_pieces_d *);
130 static bool block_move_libcall_safe_for_call_parm (void);
131 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned, unsigned, HOST_WIDE_INT,
132 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
133 static tree emit_block_move_libcall_fn (int);
134 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
135 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
136 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
137 static void store_by_pieces_1 (struct store_by_pieces_d *, unsigned int);
138 static void store_by_pieces_2 (insn_gen_fn, machine_mode,
139 struct store_by_pieces_d *);
140 static tree clear_storage_libcall_fn (int);
141 static rtx compress_float_constant (rtx, rtx);
142 static rtx get_subtarget (rtx);
143 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
144 HOST_WIDE_INT, enum machine_mode,
145 tree, int, alias_set_type);
146 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
147 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT,
148 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
149 enum machine_mode, tree, alias_set_type, bool);
151 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (const_tree, const_tree);
153 static int is_aligning_offset (const_tree, const_tree);
154 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
155 enum expand_modifier);
156 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
157 static rtx do_store_flag (sepops, rtx, enum machine_mode);
158 #ifdef PUSH_ROUNDING
159 static void emit_single_push_insn (enum machine_mode, rtx, tree);
160 #endif
161 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx, int);
162 static rtx const_vector_from_tree (tree);
163 static void write_complex_part (rtx, rtx, bool);
165 /* This macro is used to determine whether move_by_pieces should be called
166 to perform a structure copy. */
167 #ifndef MOVE_BY_PIECES_P
168 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
169 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
170 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
171 #endif
173 /* This macro is used to determine whether clear_by_pieces should be
174 called to clear storage. */
175 #ifndef CLEAR_BY_PIECES_P
176 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
177 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
178 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
179 #endif
181 /* This macro is used to determine whether store_by_pieces should be
182 called to "memset" storage with byte values other than zero. */
183 #ifndef SET_BY_PIECES_P
184 #define SET_BY_PIECES_P(SIZE, ALIGN) \
185 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
186 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
187 #endif
189 /* This macro is used to determine whether store_by_pieces should be
190 called to "memcpy" storage when the source is a constant string. */
191 #ifndef STORE_BY_PIECES_P
192 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
193 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
194 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
195 #endif
197 /* This is run to set up which modes can be used
198 directly in memory and to initialize the block move optab. It is run
199 at the beginning of compilation and when the target is reinitialized. */
201 void
202 init_expr_target (void)
204 rtx insn, pat;
205 enum machine_mode mode;
206 int num_clobbers;
207 rtx mem, mem1;
208 rtx reg;
210 /* Try indexing by frame ptr and try by stack ptr.
211 It is known that on the Convex the stack ptr isn't a valid index.
212 With luck, one or the other is valid on any machine. */
213 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
214 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
216 /* A scratch register we can modify in-place below to avoid
217 useless RTL allocations. */
218 reg = gen_rtx_REG (VOIDmode, -1);
220 insn = rtx_alloc (INSN);
221 pat = gen_rtx_SET (VOIDmode, NULL_RTX, NULL_RTX);
222 PATTERN (insn) = pat;
224 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
225 mode = (enum machine_mode) ((int) mode + 1))
227 int regno;
229 direct_load[(int) mode] = direct_store[(int) mode] = 0;
230 PUT_MODE (mem, mode);
231 PUT_MODE (mem1, mode);
232 PUT_MODE (reg, mode);
234 /* See if there is some register that can be used in this mode and
235 directly loaded or stored from memory. */
237 if (mode != VOIDmode && mode != BLKmode)
238 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
239 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
240 regno++)
242 if (! HARD_REGNO_MODE_OK (regno, mode))
243 continue;
245 SET_REGNO (reg, regno);
247 SET_SRC (pat) = mem;
248 SET_DEST (pat) = reg;
249 if (recog (pat, insn, &num_clobbers) >= 0)
250 direct_load[(int) mode] = 1;
252 SET_SRC (pat) = mem1;
253 SET_DEST (pat) = reg;
254 if (recog (pat, insn, &num_clobbers) >= 0)
255 direct_load[(int) mode] = 1;
257 SET_SRC (pat) = reg;
258 SET_DEST (pat) = mem;
259 if (recog (pat, insn, &num_clobbers) >= 0)
260 direct_store[(int) mode] = 1;
262 SET_SRC (pat) = reg;
263 SET_DEST (pat) = mem1;
264 if (recog (pat, insn, &num_clobbers) >= 0)
265 direct_store[(int) mode] = 1;
269 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
271 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
272 mode = GET_MODE_WIDER_MODE (mode))
274 enum machine_mode srcmode;
275 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
276 srcmode = GET_MODE_WIDER_MODE (srcmode))
278 enum insn_code ic;
280 ic = can_extend_p (mode, srcmode, 0);
281 if (ic == CODE_FOR_nothing)
282 continue;
284 PUT_MODE (mem, srcmode);
286 if (insn_operand_matches (ic, 1, mem))
287 float_extend_from_mem[mode][srcmode] = true;
292 /* This is run at the start of compiling a function. */
294 void
295 init_expr (void)
297 memset (&crtl->expr, 0, sizeof (crtl->expr));
300 /* Copy data from FROM to TO, where the machine modes are not the same.
301 Both modes may be integer, or both may be floating, or both may be
302 fixed-point.
303 UNSIGNEDP should be nonzero if FROM is an unsigned type.
304 This causes zero-extension instead of sign-extension. */
306 void
307 convert_move (rtx to, rtx from, int unsignedp)
309 enum machine_mode to_mode = GET_MODE (to);
310 enum machine_mode from_mode = GET_MODE (from);
311 int to_real = SCALAR_FLOAT_MODE_P (to_mode);
312 int from_real = SCALAR_FLOAT_MODE_P (from_mode);
313 enum insn_code code;
314 rtx libcall;
316 /* rtx code for making an equivalent value. */
317 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
318 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
321 gcc_assert (to_real == from_real);
322 gcc_assert (to_mode != BLKmode);
323 gcc_assert (from_mode != BLKmode);
325 /* If the source and destination are already the same, then there's
326 nothing to do. */
327 if (to == from)
328 return;
330 /* If FROM is a SUBREG that indicates that we have already done at least
331 the required extension, strip it. We don't handle such SUBREGs as
332 TO here. */
334 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
335 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from)))
336 >= GET_MODE_PRECISION (to_mode))
337 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
338 from = gen_lowpart (to_mode, from), from_mode = to_mode;
340 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
342 if (to_mode == from_mode
343 || (from_mode == VOIDmode && CONSTANT_P (from)))
345 emit_move_insn (to, from);
346 return;
349 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
351 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
353 if (VECTOR_MODE_P (to_mode))
354 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
355 else
356 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
358 emit_move_insn (to, from);
359 return;
362 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
364 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
365 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
366 return;
369 if (to_real)
371 rtx value, insns;
372 convert_optab tab;
374 gcc_assert ((GET_MODE_PRECISION (from_mode)
375 != GET_MODE_PRECISION (to_mode))
376 || (DECIMAL_FLOAT_MODE_P (from_mode)
377 != DECIMAL_FLOAT_MODE_P (to_mode)));
379 if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
380 /* Conversion between decimal float and binary float, same size. */
381 tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
382 else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
383 tab = sext_optab;
384 else
385 tab = trunc_optab;
387 /* Try converting directly if the insn is supported. */
389 code = convert_optab_handler (tab, to_mode, from_mode);
390 if (code != CODE_FOR_nothing)
392 emit_unop_insn (code, to, from,
393 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
394 return;
397 /* Otherwise use a libcall. */
398 libcall = convert_optab_libfunc (tab, to_mode, from_mode);
400 /* Is this conversion implemented yet? */
401 gcc_assert (libcall);
403 start_sequence ();
404 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
405 1, from, from_mode);
406 insns = get_insns ();
407 end_sequence ();
408 emit_libcall_block (insns, to, value,
409 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
410 from)
411 : gen_rtx_FLOAT_EXTEND (to_mode, from));
412 return;
415 /* Handle pointer conversion. */ /* SPEE 900220. */
416 /* Targets are expected to provide conversion insns between PxImode and
417 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
418 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
420 enum machine_mode full_mode
421 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
423 gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
424 != CODE_FOR_nothing);
426 if (full_mode != from_mode)
427 from = convert_to_mode (full_mode, from, unsignedp);
428 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
429 to, from, UNKNOWN);
430 return;
432 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
434 rtx new_from;
435 enum machine_mode full_mode
436 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
437 convert_optab ctab = unsignedp ? zext_optab : sext_optab;
438 enum insn_code icode;
440 icode = convert_optab_handler (ctab, full_mode, from_mode);
441 gcc_assert (icode != CODE_FOR_nothing);
443 if (to_mode == full_mode)
445 emit_unop_insn (icode, to, from, UNKNOWN);
446 return;
449 new_from = gen_reg_rtx (full_mode);
450 emit_unop_insn (icode, new_from, from, UNKNOWN);
452 /* else proceed to integer conversions below. */
453 from_mode = full_mode;
454 from = new_from;
457 /* Make sure both are fixed-point modes or both are not. */
458 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
459 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
460 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
462 /* If we widen from_mode to to_mode and they are in the same class,
463 we won't saturate the result.
464 Otherwise, always saturate the result to play safe. */
465 if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
466 && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
467 expand_fixed_convert (to, from, 0, 0);
468 else
469 expand_fixed_convert (to, from, 0, 1);
470 return;
473 /* Now both modes are integers. */
475 /* Handle expanding beyond a word. */
476 if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
477 && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
479 rtx insns;
480 rtx lowpart;
481 rtx fill_value;
482 rtx lowfrom;
483 int i;
484 enum machine_mode lowpart_mode;
485 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
487 /* Try converting directly if the insn is supported. */
488 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
489 != CODE_FOR_nothing)
491 /* If FROM is a SUBREG, put it into a register. Do this
492 so that we always generate the same set of insns for
493 better cse'ing; if an intermediate assignment occurred,
494 we won't be doing the operation directly on the SUBREG. */
495 if (optimize > 0 && GET_CODE (from) == SUBREG)
496 from = force_reg (from_mode, from);
497 emit_unop_insn (code, to, from, equiv_code);
498 return;
500 /* Next, try converting via full word. */
501 else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
502 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
503 != CODE_FOR_nothing))
505 rtx word_to = gen_reg_rtx (word_mode);
506 if (REG_P (to))
508 if (reg_overlap_mentioned_p (to, from))
509 from = force_reg (from_mode, from);
510 emit_clobber (to);
512 convert_move (word_to, from, unsignedp);
513 emit_unop_insn (code, to, word_to, equiv_code);
514 return;
517 /* No special multiword conversion insn; do it by hand. */
518 start_sequence ();
520 /* Since we will turn this into a no conflict block, we must ensure the
521 the source does not overlap the target so force it into an isolated
522 register when maybe so. Likewise for any MEM input, since the
523 conversion sequence might require several references to it and we
524 must ensure we're getting the same value every time. */
526 if (MEM_P (from) || reg_overlap_mentioned_p (to, from))
527 from = force_reg (from_mode, from);
529 /* Get a copy of FROM widened to a word, if necessary. */
530 if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
531 lowpart_mode = word_mode;
532 else
533 lowpart_mode = from_mode;
535 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
537 lowpart = gen_lowpart (lowpart_mode, to);
538 emit_move_insn (lowpart, lowfrom);
540 /* Compute the value to put in each remaining word. */
541 if (unsignedp)
542 fill_value = const0_rtx;
543 else
544 fill_value = emit_store_flag (gen_reg_rtx (word_mode),
545 LT, lowfrom, const0_rtx,
546 VOIDmode, 0, -1);
548 /* Fill the remaining words. */
549 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
551 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
552 rtx subword = operand_subword (to, index, 1, to_mode);
554 gcc_assert (subword);
556 if (fill_value != subword)
557 emit_move_insn (subword, fill_value);
560 insns = get_insns ();
561 end_sequence ();
563 emit_insn (insns);
564 return;
567 /* Truncating multi-word to a word or less. */
568 if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
569 && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
571 if (!((MEM_P (from)
572 && ! MEM_VOLATILE_P (from)
573 && direct_load[(int) to_mode]
574 && ! mode_dependent_address_p (XEXP (from, 0),
575 MEM_ADDR_SPACE (from)))
576 || REG_P (from)
577 || GET_CODE (from) == SUBREG))
578 from = force_reg (from_mode, from);
579 convert_move (to, gen_lowpart (word_mode, from), 0);
580 return;
583 /* Now follow all the conversions between integers
584 no more than a word long. */
586 /* For truncation, usually we can just refer to FROM in a narrower mode. */
587 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
588 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
590 if (!((MEM_P (from)
591 && ! MEM_VOLATILE_P (from)
592 && direct_load[(int) to_mode]
593 && ! mode_dependent_address_p (XEXP (from, 0),
594 MEM_ADDR_SPACE (from)))
595 || REG_P (from)
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));
602 return;
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))
610 != CODE_FOR_nothing)
612 emit_unop_insn (code, to, from, equiv_code);
613 return;
615 else
617 enum machine_mode intermediate;
618 rtx tmp;
619 int shift_amount;
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)
625 != CODE_FOR_nothing)
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);
633 return;
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,
642 to, unsignedp);
643 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
644 to, unsignedp);
645 if (tmp != to)
646 emit_move_insn (to, tmp);
647 return;
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),
656 to, from, UNKNOWN);
657 return;
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);
671 return;
674 /* Mode combination is not recognized. */
675 gcc_unreachable ();
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)
704 rtx temp;
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);
717 if (mode == oldmode)
718 return 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) == HOST_BITS_PER_DOUBLE_INT
728 && CONST_INT_P (x) && INTVAL (x) < 0)
730 double_int val = double_int::from_uhwi (INTVAL (x));
732 /* We need to zero extend VAL. */
733 if (oldmode != VOIDmode)
734 val = val.zext (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. */
744 if ((CONST_INT_P (x)
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 && (CONST_DOUBLE_AS_INT_P (x)
749 || (GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (oldmode)
750 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
751 && direct_load[(int) mode])
752 || (REG_P (x)
753 && (! HARD_REGISTER_P (x)
754 || HARD_REGNO_MODE_OK (REGNO (x), mode))
755 && TRULY_NOOP_TRUNCATION_MODES_P (mode,
756 GET_MODE (x))))))))
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);
769 if (! unsignedp
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
780 subreg operation. */
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);
789 return temp;
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. */
795 static unsigned int
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);
803 else
805 enum machine_mode tmode, xmode;
807 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
808 tmode != VOIDmode;
809 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
810 if (GET_MODE_SIZE (tmode) > max_pieces
811 || SLOW_UNALIGNED_ACCESS (tmode, align))
812 break;
814 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
817 return align;
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)
831 mode = tmode;
833 return mode;
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
845 succeed. */
848 can_move_by_pieces (unsigned HOST_WIDE_INT len ATTRIBUTE_UNUSED,
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
864 stpcpy. */
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;
872 enum machine_mode from_addr_mode = get_address_mode (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));
879 data.offset = 0;
880 data.from_addr = from_addr;
881 if (to)
883 to_addr_mode = get_address_mode (to);
884 to_addr = XEXP (to, 0);
885 data.to = to;
886 data.autinc_to
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);
889 data.reverse
890 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
892 else
894 to_addr_mode = VOIDmode;
895 to_addr = NULL_RTX;
896 data.to = NULL_RTX;
897 data.autinc_to = 1;
898 #ifdef STACK_GROWS_DOWNWARD
899 data.reverse = 1;
900 #else
901 data.reverse = 0;
902 #endif
904 data.to_addr = to_addr;
905 data.from = from;
906 data.autinc_from
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;
914 data.len = 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_mode,
932 from_addr, len));
933 data.autinc_from = 1;
934 data.explicit_inc_from = -1;
936 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
938 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
939 data.autinc_from = 1;
940 data.explicit_inc_from = 1;
942 if (!data.autinc_from && CONSTANT_P (from_addr))
943 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
944 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
946 data.to_addr = copy_to_mode_reg (to_addr_mode,
947 plus_constant (to_addr_mode,
948 to_addr, len));
949 data.autinc_to = 1;
950 data.explicit_inc_to = -1;
952 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
954 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
955 data.autinc_to = 1;
956 data.explicit_inc_to = 1;
958 if (!data.autinc_to && CONSTANT_P (to_addr))
959 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
962 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
964 /* First move what we can in the largest integer mode, then go to
965 successively smaller modes. */
967 while (max_size > 1 && data.len > 0)
969 enum machine_mode mode = widest_int_mode_for_size (max_size);
971 if (mode == VOIDmode)
972 break;
974 icode = optab_handler (mov_optab, mode);
975 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
976 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
978 max_size = GET_MODE_SIZE (mode);
981 /* The code above should have handled everything. */
982 gcc_assert (!data.len);
984 if (endp)
986 rtx to1;
988 gcc_assert (!data.reverse);
989 if (data.autinc_to)
991 if (endp == 2)
993 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
994 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
995 else
996 data.to_addr = copy_to_mode_reg (to_addr_mode,
997 plus_constant (to_addr_mode,
998 data.to_addr,
999 -1));
1001 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
1002 data.offset);
1004 else
1006 if (endp == 2)
1007 --data.offset;
1008 to1 = adjust_address (data.to, QImode, data.offset);
1010 return to1;
1012 else
1013 return data.to;
1016 /* Return number of insns required to move L bytes by pieces.
1017 ALIGN (in bits) is maximum alignment we can assume. */
1019 unsigned HOST_WIDE_INT
1020 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1021 unsigned int max_size)
1023 unsigned HOST_WIDE_INT n_insns = 0;
1025 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1027 while (max_size > 1 && l > 0)
1029 enum machine_mode mode;
1030 enum insn_code icode;
1032 mode = widest_int_mode_for_size (max_size);
1034 if (mode == VOIDmode)
1035 break;
1037 icode = optab_handler (mov_optab, mode);
1038 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1039 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1041 max_size = GET_MODE_SIZE (mode);
1044 gcc_assert (!l);
1045 return n_insns;
1048 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1049 with move instructions for mode MODE. GENFUN is the gen_... function
1050 to make a move insn for that mode. DATA has all the other info. */
1052 static void
1053 move_by_pieces_1 (insn_gen_fn genfun, machine_mode mode,
1054 struct move_by_pieces_d *data)
1056 unsigned int size = GET_MODE_SIZE (mode);
1057 rtx to1 = NULL_RTX, from1;
1059 while (data->len >= size)
1061 if (data->reverse)
1062 data->offset -= size;
1064 if (data->to)
1066 if (data->autinc_to)
1067 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1068 data->offset);
1069 else
1070 to1 = adjust_address (data->to, mode, data->offset);
1073 if (data->autinc_from)
1074 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1075 data->offset);
1076 else
1077 from1 = adjust_address (data->from, mode, data->offset);
1079 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1080 emit_insn (gen_add2_insn (data->to_addr,
1081 gen_int_mode (-(HOST_WIDE_INT) size,
1082 GET_MODE (data->to_addr))));
1083 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1084 emit_insn (gen_add2_insn (data->from_addr,
1085 gen_int_mode (-(HOST_WIDE_INT) size,
1086 GET_MODE (data->from_addr))));
1088 if (data->to)
1089 emit_insn ((*genfun) (to1, from1));
1090 else
1092 #ifdef PUSH_ROUNDING
1093 emit_single_push_insn (mode, from1, NULL);
1094 #else
1095 gcc_unreachable ();
1096 #endif
1099 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1100 emit_insn (gen_add2_insn (data->to_addr,
1101 gen_int_mode (size,
1102 GET_MODE (data->to_addr))));
1103 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1104 emit_insn (gen_add2_insn (data->from_addr,
1105 gen_int_mode (size,
1106 GET_MODE (data->from_addr))));
1108 if (! data->reverse)
1109 data->offset += size;
1111 data->len -= size;
1115 /* Emit code to move a block Y to a block X. This may be done with
1116 string-move instructions, with multiple scalar move instructions,
1117 or with a library call.
1119 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1120 SIZE is an rtx that says how long they are.
1121 ALIGN is the maximum alignment we can assume they have.
1122 METHOD describes what kind of copy this is, and what mechanisms may be used.
1123 MIN_SIZE is the minimal size of block to move
1124 MAX_SIZE is the maximal size of block to move, if it can not be represented
1125 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1127 Return the address of the new block, if memcpy is called and returns it,
1128 0 otherwise. */
1131 emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
1132 unsigned int expected_align, HOST_WIDE_INT expected_size,
1133 unsigned HOST_WIDE_INT min_size,
1134 unsigned HOST_WIDE_INT max_size)
1136 bool may_use_call;
1137 rtx retval = 0;
1138 unsigned int align;
1140 gcc_assert (size);
1141 if (CONST_INT_P (size)
1142 && INTVAL (size) == 0)
1143 return 0;
1145 switch (method)
1147 case BLOCK_OP_NORMAL:
1148 case BLOCK_OP_TAILCALL:
1149 may_use_call = true;
1150 break;
1152 case BLOCK_OP_CALL_PARM:
1153 may_use_call = block_move_libcall_safe_for_call_parm ();
1155 /* Make inhibit_defer_pop nonzero around the library call
1156 to force it to pop the arguments right away. */
1157 NO_DEFER_POP;
1158 break;
1160 case BLOCK_OP_NO_LIBCALL:
1161 may_use_call = false;
1162 break;
1164 default:
1165 gcc_unreachable ();
1168 gcc_assert (MEM_P (x) && MEM_P (y));
1169 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1170 gcc_assert (align >= BITS_PER_UNIT);
1172 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1173 block copy is more efficient for other large modes, e.g. DCmode. */
1174 x = adjust_address (x, BLKmode, 0);
1175 y = adjust_address (y, BLKmode, 0);
1177 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1178 can be incorrect is coming from __builtin_memcpy. */
1179 if (CONST_INT_P (size))
1181 x = shallow_copy_rtx (x);
1182 y = shallow_copy_rtx (y);
1183 set_mem_size (x, INTVAL (size));
1184 set_mem_size (y, INTVAL (size));
1187 if (CONST_INT_P (size) && MOVE_BY_PIECES_P (INTVAL (size), align))
1188 move_by_pieces (x, y, INTVAL (size), align, 0);
1189 else if (emit_block_move_via_movmem (x, y, size, align,
1190 expected_align, expected_size,
1191 min_size, max_size))
1193 else if (may_use_call
1194 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
1195 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
1197 /* Since x and y are passed to a libcall, mark the corresponding
1198 tree EXPR as addressable. */
1199 tree y_expr = MEM_EXPR (y);
1200 tree x_expr = MEM_EXPR (x);
1201 if (y_expr)
1202 mark_addressable (y_expr);
1203 if (x_expr)
1204 mark_addressable (x_expr);
1205 retval = emit_block_move_via_libcall (x, y, size,
1206 method == BLOCK_OP_TAILCALL);
1209 else
1210 emit_block_move_via_loop (x, y, size, align);
1212 if (method == BLOCK_OP_CALL_PARM)
1213 OK_DEFER_POP;
1215 return retval;
1219 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1221 unsigned HOST_WIDE_INT max, min = 0;
1222 if (GET_CODE (size) == CONST_INT)
1223 min = max = UINTVAL (size);
1224 else
1225 max = GET_MODE_MASK (GET_MODE (size));
1226 return emit_block_move_hints (x, y, size, method, 0, -1,
1227 min, max);
1230 /* A subroutine of emit_block_move. Returns true if calling the
1231 block move libcall will not clobber any parameters which may have
1232 already been placed on the stack. */
1234 static bool
1235 block_move_libcall_safe_for_call_parm (void)
1237 #if defined (REG_PARM_STACK_SPACE)
1238 tree fn;
1239 #endif
1241 /* If arguments are pushed on the stack, then they're safe. */
1242 if (PUSH_ARGS)
1243 return true;
1245 /* If registers go on the stack anyway, any argument is sure to clobber
1246 an outgoing argument. */
1247 #if defined (REG_PARM_STACK_SPACE)
1248 fn = emit_block_move_libcall_fn (false);
1249 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1250 depend on its argument. */
1251 (void) fn;
1252 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn ? NULL_TREE : TREE_TYPE (fn)))
1253 && REG_PARM_STACK_SPACE (fn) != 0)
1254 return false;
1255 #endif
1257 /* If any argument goes in memory, then it might clobber an outgoing
1258 argument. */
1260 CUMULATIVE_ARGS args_so_far_v;
1261 cumulative_args_t args_so_far;
1262 tree fn, arg;
1264 fn = emit_block_move_libcall_fn (false);
1265 INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
1266 args_so_far = pack_cumulative_args (&args_so_far_v);
1268 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1269 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1271 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1272 rtx tmp = targetm.calls.function_arg (args_so_far, mode,
1273 NULL_TREE, true);
1274 if (!tmp || !REG_P (tmp))
1275 return false;
1276 if (targetm.calls.arg_partial_bytes (args_so_far, mode, NULL, 1))
1277 return false;
1278 targetm.calls.function_arg_advance (args_so_far, mode,
1279 NULL_TREE, true);
1282 return true;
1285 /* A subroutine of emit_block_move. Expand a movmem pattern;
1286 return true if successful. */
1288 static bool
1289 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
1290 unsigned int expected_align, HOST_WIDE_INT expected_size,
1291 unsigned HOST_WIDE_INT min_size,
1292 unsigned HOST_WIDE_INT max_size)
1294 int save_volatile_ok = volatile_ok;
1295 enum machine_mode mode;
1297 if (expected_align < align)
1298 expected_align = align;
1299 if (expected_size != -1)
1301 if ((unsigned HOST_WIDE_INT)expected_size > max_size)
1302 expected_size = max_size;
1303 if ((unsigned HOST_WIDE_INT)expected_size < min_size)
1304 expected_size = min_size;
1307 /* Since this is a move insn, we don't care about volatility. */
1308 volatile_ok = 1;
1310 /* Try the most limited insn first, because there's no point
1311 including more than one in the machine description unless
1312 the more limited one has some advantage. */
1314 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1315 mode = GET_MODE_WIDER_MODE (mode))
1317 enum insn_code code = direct_optab_handler (movmem_optab, mode);
1319 if (code != CODE_FOR_nothing
1320 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1321 here because if SIZE is less than the mode mask, as it is
1322 returned by the macro, it will definitely be less than the
1323 actual mode mask. Since SIZE is within the Pmode address
1324 space, we limit MODE to Pmode. */
1325 && ((CONST_INT_P (size)
1326 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1327 <= (GET_MODE_MASK (mode) >> 1)))
1328 || max_size <= (GET_MODE_MASK (mode) >> 1)
1329 || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
1331 struct expand_operand ops[8];
1332 unsigned int nops;
1334 /* ??? When called via emit_block_move_for_call, it'd be
1335 nice if there were some way to inform the backend, so
1336 that it doesn't fail the expansion because it thinks
1337 emitting the libcall would be more efficient. */
1338 nops = insn_data[(int) code].n_generator_args;
1339 gcc_assert (nops == 4 || nops == 6 || nops == 8);
1341 create_fixed_operand (&ops[0], x);
1342 create_fixed_operand (&ops[1], y);
1343 /* The check above guarantees that this size conversion is valid. */
1344 create_convert_operand_to (&ops[2], size, mode, true);
1345 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
1346 if (nops >= 6)
1348 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
1349 create_integer_operand (&ops[5], expected_size);
1351 if (nops == 8)
1353 create_integer_operand (&ops[6], min_size);
1354 /* If we can not represent the maximal size,
1355 make parameter NULL. */
1356 if ((HOST_WIDE_INT) max_size != -1)
1357 create_integer_operand (&ops[7], max_size);
1358 else
1359 create_fixed_operand (&ops[7], NULL);
1361 if (maybe_expand_insn (code, nops, ops))
1363 volatile_ok = save_volatile_ok;
1364 return true;
1369 volatile_ok = save_volatile_ok;
1370 return false;
1373 /* A subroutine of emit_block_move. Expand a call to memcpy.
1374 Return the return value from memcpy, 0 otherwise. */
1377 emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
1379 rtx dst_addr, src_addr;
1380 tree call_expr, fn, src_tree, dst_tree, size_tree;
1381 enum machine_mode size_mode;
1382 rtx retval;
1384 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1385 pseudos. We can then place those new pseudos into a VAR_DECL and
1386 use them later. */
1388 dst_addr = copy_addr_to_reg (XEXP (dst, 0));
1389 src_addr = copy_addr_to_reg (XEXP (src, 0));
1391 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1392 src_addr = convert_memory_address (ptr_mode, src_addr);
1394 dst_tree = make_tree (ptr_type_node, dst_addr);
1395 src_tree = make_tree (ptr_type_node, src_addr);
1397 size_mode = TYPE_MODE (sizetype);
1399 size = convert_to_mode (size_mode, size, 1);
1400 size = copy_to_mode_reg (size_mode, size);
1402 /* It is incorrect to use the libcall calling conventions to call
1403 memcpy in this context. This could be a user call to memcpy and
1404 the user may wish to examine the return value from memcpy. For
1405 targets where libcalls and normal calls have different conventions
1406 for returning pointers, we could end up generating incorrect code. */
1408 size_tree = make_tree (sizetype, size);
1410 fn = emit_block_move_libcall_fn (true);
1411 call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
1412 CALL_EXPR_TAILCALL (call_expr) = tailcall;
1414 retval = expand_normal (call_expr);
1416 return retval;
1419 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1420 for the function we use for block copies. */
1422 static GTY(()) tree block_move_fn;
1424 void
1425 init_block_move_fn (const char *asmspec)
1427 if (!block_move_fn)
1429 tree args, fn, attrs, attr_args;
1431 fn = get_identifier ("memcpy");
1432 args = build_function_type_list (ptr_type_node, ptr_type_node,
1433 const_ptr_type_node, sizetype,
1434 NULL_TREE);
1436 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
1437 DECL_EXTERNAL (fn) = 1;
1438 TREE_PUBLIC (fn) = 1;
1439 DECL_ARTIFICIAL (fn) = 1;
1440 TREE_NOTHROW (fn) = 1;
1441 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
1442 DECL_VISIBILITY_SPECIFIED (fn) = 1;
1444 attr_args = build_tree_list (NULL_TREE, build_string (1, "1"));
1445 attrs = tree_cons (get_identifier ("fn spec"), attr_args, NULL);
1447 decl_attributes (&fn, attrs, ATTR_FLAG_BUILT_IN);
1449 block_move_fn = fn;
1452 if (asmspec)
1453 set_user_assembler_name (block_move_fn, asmspec);
1456 static tree
1457 emit_block_move_libcall_fn (int for_call)
1459 static bool emitted_extern;
1461 if (!block_move_fn)
1462 init_block_move_fn (NULL);
1464 if (for_call && !emitted_extern)
1466 emitted_extern = true;
1467 make_decl_rtl (block_move_fn);
1470 return block_move_fn;
1473 /* A subroutine of emit_block_move. Copy the data via an explicit
1474 loop. This is used only when libcalls are forbidden. */
1475 /* ??? It'd be nice to copy in hunks larger than QImode. */
1477 static void
1478 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1479 unsigned int align ATTRIBUTE_UNUSED)
1481 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1482 enum machine_mode x_addr_mode = get_address_mode (x);
1483 enum machine_mode y_addr_mode = get_address_mode (y);
1484 enum machine_mode iter_mode;
1486 iter_mode = GET_MODE (size);
1487 if (iter_mode == VOIDmode)
1488 iter_mode = word_mode;
1490 top_label = gen_label_rtx ();
1491 cmp_label = gen_label_rtx ();
1492 iter = gen_reg_rtx (iter_mode);
1494 emit_move_insn (iter, const0_rtx);
1496 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1497 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1498 do_pending_stack_adjust ();
1500 emit_jump (cmp_label);
1501 emit_label (top_label);
1503 tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
1504 x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
1506 if (x_addr_mode != y_addr_mode)
1507 tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
1508 y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
1510 x = change_address (x, QImode, x_addr);
1511 y = change_address (y, QImode, y_addr);
1513 emit_move_insn (x, y);
1515 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1516 true, OPTAB_LIB_WIDEN);
1517 if (tmp != iter)
1518 emit_move_insn (iter, tmp);
1520 emit_label (cmp_label);
1522 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1523 true, top_label, REG_BR_PROB_BASE * 90 / 100);
1526 /* Copy all or part of a value X into registers starting at REGNO.
1527 The number of registers to be filled is NREGS. */
1529 void
1530 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1532 int i;
1533 #ifdef HAVE_load_multiple
1534 rtx pat;
1535 rtx last;
1536 #endif
1538 if (nregs == 0)
1539 return;
1541 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
1542 x = validize_mem (force_const_mem (mode, x));
1544 /* See if the machine can do this with a load multiple insn. */
1545 #ifdef HAVE_load_multiple
1546 if (HAVE_load_multiple)
1548 last = get_last_insn ();
1549 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1550 GEN_INT (nregs));
1551 if (pat)
1553 emit_insn (pat);
1554 return;
1556 else
1557 delete_insns_since (last);
1559 #endif
1561 for (i = 0; i < nregs; i++)
1562 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1563 operand_subword_force (x, i, mode));
1566 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1567 The number of registers to be filled is NREGS. */
1569 void
1570 move_block_from_reg (int regno, rtx x, int nregs)
1572 int i;
1574 if (nregs == 0)
1575 return;
1577 /* See if the machine can do this with a store multiple insn. */
1578 #ifdef HAVE_store_multiple
1579 if (HAVE_store_multiple)
1581 rtx last = get_last_insn ();
1582 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1583 GEN_INT (nregs));
1584 if (pat)
1586 emit_insn (pat);
1587 return;
1589 else
1590 delete_insns_since (last);
1592 #endif
1594 for (i = 0; i < nregs; i++)
1596 rtx tem = operand_subword (x, i, 1, BLKmode);
1598 gcc_assert (tem);
1600 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1604 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1605 ORIG, where ORIG is a non-consecutive group of registers represented by
1606 a PARALLEL. The clone is identical to the original except in that the
1607 original set of registers is replaced by a new set of pseudo registers.
1608 The new set has the same modes as the original set. */
1611 gen_group_rtx (rtx orig)
1613 int i, length;
1614 rtx *tmps;
1616 gcc_assert (GET_CODE (orig) == PARALLEL);
1618 length = XVECLEN (orig, 0);
1619 tmps = XALLOCAVEC (rtx, length);
1621 /* Skip a NULL entry in first slot. */
1622 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1624 if (i)
1625 tmps[0] = 0;
1627 for (; i < length; i++)
1629 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1630 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1632 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1635 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1638 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1639 except that values are placed in TMPS[i], and must later be moved
1640 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1642 static void
1643 emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
1645 rtx src;
1646 int start, i;
1647 enum machine_mode m = GET_MODE (orig_src);
1649 gcc_assert (GET_CODE (dst) == PARALLEL);
1651 if (m != VOIDmode
1652 && !SCALAR_INT_MODE_P (m)
1653 && !MEM_P (orig_src)
1654 && GET_CODE (orig_src) != CONCAT)
1656 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
1657 if (imode == BLKmode)
1658 src = assign_stack_temp (GET_MODE (orig_src), ssize);
1659 else
1660 src = gen_reg_rtx (imode);
1661 if (imode != BLKmode)
1662 src = gen_lowpart (GET_MODE (orig_src), src);
1663 emit_move_insn (src, orig_src);
1664 /* ...and back again. */
1665 if (imode != BLKmode)
1666 src = gen_lowpart (imode, src);
1667 emit_group_load_1 (tmps, dst, src, type, ssize);
1668 return;
1671 /* Check for a NULL entry, used to indicate that the parameter goes
1672 both on the stack and in registers. */
1673 if (XEXP (XVECEXP (dst, 0, 0), 0))
1674 start = 0;
1675 else
1676 start = 1;
1678 /* Process the pieces. */
1679 for (i = start; i < XVECLEN (dst, 0); i++)
1681 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1682 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1683 unsigned int bytelen = GET_MODE_SIZE (mode);
1684 int shift = 0;
1686 /* Handle trailing fragments that run over the size of the struct. */
1687 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1689 /* Arrange to shift the fragment to where it belongs.
1690 extract_bit_field loads to the lsb of the reg. */
1691 if (
1692 #ifdef BLOCK_REG_PADDING
1693 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1694 == (BYTES_BIG_ENDIAN ? upward : downward)
1695 #else
1696 BYTES_BIG_ENDIAN
1697 #endif
1699 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1700 bytelen = ssize - bytepos;
1701 gcc_assert (bytelen > 0);
1704 /* If we won't be loading directly from memory, protect the real source
1705 from strange tricks we might play; but make sure that the source can
1706 be loaded directly into the destination. */
1707 src = orig_src;
1708 if (!MEM_P (orig_src)
1709 && (!CONSTANT_P (orig_src)
1710 || (GET_MODE (orig_src) != mode
1711 && GET_MODE (orig_src) != VOIDmode)))
1713 if (GET_MODE (orig_src) == VOIDmode)
1714 src = gen_reg_rtx (mode);
1715 else
1716 src = gen_reg_rtx (GET_MODE (orig_src));
1718 emit_move_insn (src, orig_src);
1721 /* Optimize the access just a bit. */
1722 if (MEM_P (src)
1723 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1724 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1725 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1726 && bytelen == GET_MODE_SIZE (mode))
1728 tmps[i] = gen_reg_rtx (mode);
1729 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1731 else if (COMPLEX_MODE_P (mode)
1732 && GET_MODE (src) == mode
1733 && bytelen == GET_MODE_SIZE (mode))
1734 /* Let emit_move_complex do the bulk of the work. */
1735 tmps[i] = src;
1736 else if (GET_CODE (src) == CONCAT)
1738 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1739 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1741 if ((bytepos == 0 && bytelen == slen0)
1742 || (bytepos != 0 && bytepos + bytelen <= slen))
1744 /* The following assumes that the concatenated objects all
1745 have the same size. In this case, a simple calculation
1746 can be used to determine the object and the bit field
1747 to be extracted. */
1748 tmps[i] = XEXP (src, bytepos / slen0);
1749 if (! CONSTANT_P (tmps[i])
1750 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1751 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1752 (bytepos % slen0) * BITS_PER_UNIT,
1753 1, NULL_RTX, mode, mode);
1755 else
1757 rtx mem;
1759 gcc_assert (!bytepos);
1760 mem = assign_stack_temp (GET_MODE (src), slen);
1761 emit_move_insn (mem, src);
1762 tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
1763 0, 1, NULL_RTX, mode, mode);
1766 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1767 SIMD register, which is currently broken. While we get GCC
1768 to emit proper RTL for these cases, let's dump to memory. */
1769 else if (VECTOR_MODE_P (GET_MODE (dst))
1770 && REG_P (src))
1772 int slen = GET_MODE_SIZE (GET_MODE (src));
1773 rtx mem;
1775 mem = assign_stack_temp (GET_MODE (src), slen);
1776 emit_move_insn (mem, src);
1777 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1779 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1780 && XVECLEN (dst, 0) > 1)
1781 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE (dst), bytepos);
1782 else if (CONSTANT_P (src))
1784 HOST_WIDE_INT len = (HOST_WIDE_INT) bytelen;
1786 if (len == ssize)
1787 tmps[i] = src;
1788 else
1790 rtx first, second;
1792 gcc_assert (2 * len == ssize);
1793 split_double (src, &first, &second);
1794 if (i)
1795 tmps[i] = second;
1796 else
1797 tmps[i] = first;
1800 else if (REG_P (src) && GET_MODE (src) == mode)
1801 tmps[i] = src;
1802 else
1803 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1804 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1805 mode, mode);
1807 if (shift)
1808 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1809 shift, tmps[i], 0);
1813 /* Emit code to move a block SRC of type TYPE to a block DST,
1814 where DST is non-consecutive registers represented by a PARALLEL.
1815 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1816 if not known. */
1818 void
1819 emit_group_load (rtx dst, rtx src, tree type, int ssize)
1821 rtx *tmps;
1822 int i;
1824 tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
1825 emit_group_load_1 (tmps, dst, src, type, ssize);
1827 /* Copy the extracted pieces into the proper (probable) hard regs. */
1828 for (i = 0; i < XVECLEN (dst, 0); i++)
1830 rtx d = XEXP (XVECEXP (dst, 0, i), 0);
1831 if (d == NULL)
1832 continue;
1833 emit_move_insn (d, tmps[i]);
1837 /* Similar, but load SRC into new pseudos in a format that looks like
1838 PARALLEL. This can later be fed to emit_group_move to get things
1839 in the right place. */
1842 emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
1844 rtvec vec;
1845 int i;
1847 vec = rtvec_alloc (XVECLEN (parallel, 0));
1848 emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
1850 /* Convert the vector to look just like the original PARALLEL, except
1851 with the computed values. */
1852 for (i = 0; i < XVECLEN (parallel, 0); i++)
1854 rtx e = XVECEXP (parallel, 0, i);
1855 rtx d = XEXP (e, 0);
1857 if (d)
1859 d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
1860 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
1862 RTVEC_ELT (vec, i) = e;
1865 return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
1868 /* Emit code to move a block SRC to block DST, where SRC and DST are
1869 non-consecutive groups of registers, each represented by a PARALLEL. */
1871 void
1872 emit_group_move (rtx dst, rtx src)
1874 int i;
1876 gcc_assert (GET_CODE (src) == PARALLEL
1877 && GET_CODE (dst) == PARALLEL
1878 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1880 /* Skip first entry if NULL. */
1881 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1882 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1883 XEXP (XVECEXP (src, 0, i), 0));
1886 /* Move a group of registers represented by a PARALLEL into pseudos. */
1889 emit_group_move_into_temps (rtx src)
1891 rtvec vec = rtvec_alloc (XVECLEN (src, 0));
1892 int i;
1894 for (i = 0; i < XVECLEN (src, 0); i++)
1896 rtx e = XVECEXP (src, 0, i);
1897 rtx d = XEXP (e, 0);
1899 if (d)
1900 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
1901 RTVEC_ELT (vec, i) = e;
1904 return gen_rtx_PARALLEL (GET_MODE (src), vec);
1907 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1908 where SRC is non-consecutive registers represented by a PARALLEL.
1909 SSIZE represents the total size of block ORIG_DST, or -1 if not
1910 known. */
1912 void
1913 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1915 rtx *tmps, dst;
1916 int start, finish, i;
1917 enum machine_mode m = GET_MODE (orig_dst);
1919 gcc_assert (GET_CODE (src) == PARALLEL);
1921 if (!SCALAR_INT_MODE_P (m)
1922 && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
1924 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
1925 if (imode == BLKmode)
1926 dst = assign_stack_temp (GET_MODE (orig_dst), ssize);
1927 else
1928 dst = gen_reg_rtx (imode);
1929 emit_group_store (dst, src, type, ssize);
1930 if (imode != BLKmode)
1931 dst = gen_lowpart (GET_MODE (orig_dst), dst);
1932 emit_move_insn (orig_dst, dst);
1933 return;
1936 /* Check for a NULL entry, used to indicate that the parameter goes
1937 both on the stack and in registers. */
1938 if (XEXP (XVECEXP (src, 0, 0), 0))
1939 start = 0;
1940 else
1941 start = 1;
1942 finish = XVECLEN (src, 0);
1944 tmps = XALLOCAVEC (rtx, finish);
1946 /* Copy the (probable) hard regs into pseudos. */
1947 for (i = start; i < finish; i++)
1949 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1950 if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
1952 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1953 emit_move_insn (tmps[i], reg);
1955 else
1956 tmps[i] = reg;
1959 /* If we won't be storing directly into memory, protect the real destination
1960 from strange tricks we might play. */
1961 dst = orig_dst;
1962 if (GET_CODE (dst) == PARALLEL)
1964 rtx temp;
1966 /* We can get a PARALLEL dst if there is a conditional expression in
1967 a return statement. In that case, the dst and src are the same,
1968 so no action is necessary. */
1969 if (rtx_equal_p (dst, src))
1970 return;
1972 /* It is unclear if we can ever reach here, but we may as well handle
1973 it. Allocate a temporary, and split this into a store/load to/from
1974 the temporary. */
1976 temp = assign_stack_temp (GET_MODE (dst), ssize);
1977 emit_group_store (temp, src, type, ssize);
1978 emit_group_load (dst, temp, type, ssize);
1979 return;
1981 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1983 enum machine_mode outer = GET_MODE (dst);
1984 enum machine_mode inner;
1985 HOST_WIDE_INT bytepos;
1986 bool done = false;
1987 rtx temp;
1989 if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
1990 dst = gen_reg_rtx (outer);
1992 /* Make life a bit easier for combine. */
1993 /* If the first element of the vector is the low part
1994 of the destination mode, use a paradoxical subreg to
1995 initialize the destination. */
1996 if (start < finish)
1998 inner = GET_MODE (tmps[start]);
1999 bytepos = subreg_lowpart_offset (inner, outer);
2000 if (INTVAL (XEXP (XVECEXP (src, 0, start), 1)) == bytepos)
2002 temp = simplify_gen_subreg (outer, tmps[start],
2003 inner, 0);
2004 if (temp)
2006 emit_move_insn (dst, temp);
2007 done = true;
2008 start++;
2013 /* If the first element wasn't the low part, try the last. */
2014 if (!done
2015 && start < finish - 1)
2017 inner = GET_MODE (tmps[finish - 1]);
2018 bytepos = subreg_lowpart_offset (inner, outer);
2019 if (INTVAL (XEXP (XVECEXP (src, 0, finish - 1), 1)) == bytepos)
2021 temp = simplify_gen_subreg (outer, tmps[finish - 1],
2022 inner, 0);
2023 if (temp)
2025 emit_move_insn (dst, temp);
2026 done = true;
2027 finish--;
2032 /* Otherwise, simply initialize the result to zero. */
2033 if (!done)
2034 emit_move_insn (dst, CONST0_RTX (outer));
2037 /* Process the pieces. */
2038 for (i = start; i < finish; i++)
2040 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
2041 enum machine_mode mode = GET_MODE (tmps[i]);
2042 unsigned int bytelen = GET_MODE_SIZE (mode);
2043 unsigned int adj_bytelen = bytelen;
2044 rtx dest = dst;
2046 /* Handle trailing fragments that run over the size of the struct. */
2047 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2048 adj_bytelen = ssize - bytepos;
2050 if (GET_CODE (dst) == CONCAT)
2052 if (bytepos + adj_bytelen
2053 <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2054 dest = XEXP (dst, 0);
2055 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2057 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
2058 dest = XEXP (dst, 1);
2060 else
2062 enum machine_mode dest_mode = GET_MODE (dest);
2063 enum machine_mode tmp_mode = GET_MODE (tmps[i]);
2065 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
2067 if (GET_MODE_ALIGNMENT (dest_mode)
2068 >= GET_MODE_ALIGNMENT (tmp_mode))
2070 dest = assign_stack_temp (dest_mode,
2071 GET_MODE_SIZE (dest_mode));
2072 emit_move_insn (adjust_address (dest,
2073 tmp_mode,
2074 bytepos),
2075 tmps[i]);
2076 dst = dest;
2078 else
2080 dest = assign_stack_temp (tmp_mode,
2081 GET_MODE_SIZE (tmp_mode));
2082 emit_move_insn (dest, tmps[i]);
2083 dst = adjust_address (dest, dest_mode, bytepos);
2085 break;
2089 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2091 /* store_bit_field always takes its value from the lsb.
2092 Move the fragment to the lsb if it's not already there. */
2093 if (
2094 #ifdef BLOCK_REG_PADDING
2095 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
2096 == (BYTES_BIG_ENDIAN ? upward : downward)
2097 #else
2098 BYTES_BIG_ENDIAN
2099 #endif
2102 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2103 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
2104 shift, tmps[i], 0);
2106 bytelen = adj_bytelen;
2109 /* Optimize the access just a bit. */
2110 if (MEM_P (dest)
2111 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
2112 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
2113 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2114 && bytelen == GET_MODE_SIZE (mode))
2115 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2116 else
2117 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2118 0, 0, mode, tmps[i]);
2121 /* Copy from the pseudo into the (probable) hard reg. */
2122 if (orig_dst != dst)
2123 emit_move_insn (orig_dst, dst);
2126 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2127 of the value stored in X. */
2130 maybe_emit_group_store (rtx x, tree type)
2132 enum machine_mode mode = TYPE_MODE (type);
2133 gcc_checking_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
2134 if (GET_CODE (x) == PARALLEL)
2136 rtx result = gen_reg_rtx (mode);
2137 emit_group_store (result, x, type, int_size_in_bytes (type));
2138 return result;
2140 return x;
2143 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2145 This is used on targets that return BLKmode values in registers. */
2147 void
2148 copy_blkmode_from_reg (rtx target, rtx srcreg, tree type)
2150 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2151 rtx src = NULL, dst = NULL;
2152 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2153 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2154 enum machine_mode mode = GET_MODE (srcreg);
2155 enum machine_mode tmode = GET_MODE (target);
2156 enum machine_mode copy_mode;
2158 /* BLKmode registers created in the back-end shouldn't have survived. */
2159 gcc_assert (mode != BLKmode);
2161 /* If the structure doesn't take up a whole number of words, see whether
2162 SRCREG is padded on the left or on the right. If it's on the left,
2163 set PADDING_CORRECTION to the number of bits to skip.
2165 In most ABIs, the structure will be returned at the least end of
2166 the register, which translates to right padding on little-endian
2167 targets and left padding on big-endian targets. The opposite
2168 holds if the structure is returned at the most significant
2169 end of the register. */
2170 if (bytes % UNITS_PER_WORD != 0
2171 && (targetm.calls.return_in_msb (type)
2172 ? !BYTES_BIG_ENDIAN
2173 : BYTES_BIG_ENDIAN))
2174 padding_correction
2175 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2177 /* We can use a single move if we have an exact mode for the size. */
2178 else if (MEM_P (target)
2179 && (!SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target))
2180 || MEM_ALIGN (target) >= GET_MODE_ALIGNMENT (mode))
2181 && bytes == GET_MODE_SIZE (mode))
2183 emit_move_insn (adjust_address (target, mode, 0), srcreg);
2184 return;
2187 /* And if we additionally have the same mode for a register. */
2188 else if (REG_P (target)
2189 && GET_MODE (target) == mode
2190 && bytes == GET_MODE_SIZE (mode))
2192 emit_move_insn (target, srcreg);
2193 return;
2196 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2197 into a new pseudo which is a full word. */
2198 if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
2200 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
2201 mode = word_mode;
2204 /* Copy the structure BITSIZE bits at a time. If the target lives in
2205 memory, take care of not reading/writing past its end by selecting
2206 a copy mode suited to BITSIZE. This should always be possible given
2207 how it is computed.
2209 If the target lives in register, make sure not to select a copy mode
2210 larger than the mode of the register.
2212 We could probably emit more efficient code for machines which do not use
2213 strict alignment, but it doesn't seem worth the effort at the current
2214 time. */
2216 copy_mode = word_mode;
2217 if (MEM_P (target))
2219 enum machine_mode mem_mode = mode_for_size (bitsize, MODE_INT, 1);
2220 if (mem_mode != BLKmode)
2221 copy_mode = mem_mode;
2223 else if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
2224 copy_mode = tmode;
2226 for (bitpos = 0, xbitpos = padding_correction;
2227 bitpos < bytes * BITS_PER_UNIT;
2228 bitpos += bitsize, xbitpos += bitsize)
2230 /* We need a new source operand each time xbitpos is on a
2231 word boundary and when xbitpos == padding_correction
2232 (the first time through). */
2233 if (xbitpos % BITS_PER_WORD == 0 || xbitpos == padding_correction)
2234 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD, mode);
2236 /* We need a new destination operand each time bitpos is on
2237 a word boundary. */
2238 if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
2239 dst = target;
2240 else if (bitpos % BITS_PER_WORD == 0)
2241 dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, tmode);
2243 /* Use xbitpos for the source extraction (right justified) and
2244 bitpos for the destination store (left justified). */
2245 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
2246 extract_bit_field (src, bitsize,
2247 xbitpos % BITS_PER_WORD, 1,
2248 NULL_RTX, copy_mode, copy_mode));
2252 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2253 register if it contains any data, otherwise return null.
2255 This is used on targets that return BLKmode values in registers. */
2258 copy_blkmode_to_reg (enum machine_mode mode, tree src)
2260 int i, n_regs;
2261 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
2262 unsigned int bitsize;
2263 rtx *dst_words, dst, x, src_word = NULL_RTX, dst_word = NULL_RTX;
2264 enum machine_mode dst_mode;
2266 gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
2268 x = expand_normal (src);
2270 bytes = int_size_in_bytes (TREE_TYPE (src));
2271 if (bytes == 0)
2272 return NULL_RTX;
2274 /* If the structure doesn't take up a whole number of words, see
2275 whether the register value should be padded on the left or on
2276 the right. Set PADDING_CORRECTION to the number of padding
2277 bits needed on the left side.
2279 In most ABIs, the structure will be returned at the least end of
2280 the register, which translates to right padding on little-endian
2281 targets and left padding on big-endian targets. The opposite
2282 holds if the structure is returned at the most significant
2283 end of the register. */
2284 if (bytes % UNITS_PER_WORD != 0
2285 && (targetm.calls.return_in_msb (TREE_TYPE (src))
2286 ? !BYTES_BIG_ENDIAN
2287 : BYTES_BIG_ENDIAN))
2288 padding_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2289 * BITS_PER_UNIT));
2291 n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2292 dst_words = XALLOCAVEC (rtx, n_regs);
2293 bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
2295 /* Copy the structure BITSIZE bits at a time. */
2296 for (bitpos = 0, xbitpos = padding_correction;
2297 bitpos < bytes * BITS_PER_UNIT;
2298 bitpos += bitsize, xbitpos += bitsize)
2300 /* We need a new destination pseudo each time xbitpos is
2301 on a word boundary and when xbitpos == padding_correction
2302 (the first time through). */
2303 if (xbitpos % BITS_PER_WORD == 0
2304 || xbitpos == padding_correction)
2306 /* Generate an appropriate register. */
2307 dst_word = gen_reg_rtx (word_mode);
2308 dst_words[xbitpos / BITS_PER_WORD] = dst_word;
2310 /* Clear the destination before we move anything into it. */
2311 emit_move_insn (dst_word, CONST0_RTX (word_mode));
2314 /* We need a new source operand each time bitpos is on a word
2315 boundary. */
2316 if (bitpos % BITS_PER_WORD == 0)
2317 src_word = operand_subword_force (x, bitpos / BITS_PER_WORD, BLKmode);
2319 /* Use bitpos for the source extraction (left justified) and
2320 xbitpos for the destination store (right justified). */
2321 store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
2322 0, 0, word_mode,
2323 extract_bit_field (src_word, bitsize,
2324 bitpos % BITS_PER_WORD, 1,
2325 NULL_RTX, word_mode, word_mode));
2328 if (mode == BLKmode)
2330 /* Find the smallest integer mode large enough to hold the
2331 entire structure. */
2332 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2333 mode != VOIDmode;
2334 mode = GET_MODE_WIDER_MODE (mode))
2335 /* Have we found a large enough mode? */
2336 if (GET_MODE_SIZE (mode) >= bytes)
2337 break;
2339 /* A suitable mode should have been found. */
2340 gcc_assert (mode != VOIDmode);
2343 if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
2344 dst_mode = word_mode;
2345 else
2346 dst_mode = mode;
2347 dst = gen_reg_rtx (dst_mode);
2349 for (i = 0; i < n_regs; i++)
2350 emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
2352 if (mode != dst_mode)
2353 dst = gen_lowpart (mode, dst);
2355 return dst;
2358 /* Add a USE expression for REG to the (possibly empty) list pointed
2359 to by CALL_FUSAGE. REG must denote a hard register. */
2361 void
2362 use_reg_mode (rtx *call_fusage, rtx reg, enum machine_mode mode)
2364 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
2366 *call_fusage
2367 = gen_rtx_EXPR_LIST (mode, gen_rtx_USE (VOIDmode, reg), *call_fusage);
2370 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2371 starting at REGNO. All of these registers must be hard registers. */
2373 void
2374 use_regs (rtx *call_fusage, int regno, int nregs)
2376 int i;
2378 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
2380 for (i = 0; i < nregs; i++)
2381 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2384 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2385 PARALLEL REGS. This is for calls that pass values in multiple
2386 non-contiguous locations. The Irix 6 ABI has examples of this. */
2388 void
2389 use_group_regs (rtx *call_fusage, rtx regs)
2391 int i;
2393 for (i = 0; i < XVECLEN (regs, 0); i++)
2395 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2397 /* A NULL entry means the parameter goes both on the stack and in
2398 registers. This can also be a MEM for targets that pass values
2399 partially on the stack and partially in registers. */
2400 if (reg != 0 && REG_P (reg))
2401 use_reg (call_fusage, reg);
2405 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2406 assigment and the code of the expresion on the RHS is CODE. Return
2407 NULL otherwise. */
2409 static gimple
2410 get_def_for_expr (tree name, enum tree_code code)
2412 gimple def_stmt;
2414 if (TREE_CODE (name) != SSA_NAME)
2415 return NULL;
2417 def_stmt = get_gimple_for_ssa_name (name);
2418 if (!def_stmt
2419 || gimple_assign_rhs_code (def_stmt) != code)
2420 return NULL;
2422 return def_stmt;
2425 #ifdef HAVE_conditional_move
2426 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2427 assigment and the class of the expresion on the RHS is CLASS. Return
2428 NULL otherwise. */
2430 static gimple
2431 get_def_for_expr_class (tree name, enum tree_code_class tclass)
2433 gimple def_stmt;
2435 if (TREE_CODE (name) != SSA_NAME)
2436 return NULL;
2438 def_stmt = get_gimple_for_ssa_name (name);
2439 if (!def_stmt
2440 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) != tclass)
2441 return NULL;
2443 return def_stmt;
2445 #endif
2448 /* Determine whether the LEN bytes generated by CONSTFUN can be
2449 stored to memory using several move instructions. CONSTFUNDATA is
2450 a pointer which will be passed as argument in every CONSTFUN call.
2451 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2452 a memset operation and false if it's a copy of a constant string.
2453 Return nonzero if a call to store_by_pieces should succeed. */
2456 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2457 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2458 void *constfundata, unsigned int align, bool memsetp)
2460 unsigned HOST_WIDE_INT l;
2461 unsigned int max_size;
2462 HOST_WIDE_INT offset = 0;
2463 enum machine_mode mode;
2464 enum insn_code icode;
2465 int reverse;
2466 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2467 rtx cst ATTRIBUTE_UNUSED;
2469 if (len == 0)
2470 return 1;
2472 if (! (memsetp
2473 ? SET_BY_PIECES_P (len, align)
2474 : STORE_BY_PIECES_P (len, align)))
2475 return 0;
2477 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2479 /* We would first store what we can in the largest integer mode, then go to
2480 successively smaller modes. */
2482 for (reverse = 0;
2483 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2484 reverse++)
2486 l = len;
2487 max_size = STORE_MAX_PIECES + 1;
2488 while (max_size > 1 && l > 0)
2490 mode = widest_int_mode_for_size (max_size);
2492 if (mode == VOIDmode)
2493 break;
2495 icode = optab_handler (mov_optab, mode);
2496 if (icode != CODE_FOR_nothing
2497 && align >= GET_MODE_ALIGNMENT (mode))
2499 unsigned int size = GET_MODE_SIZE (mode);
2501 while (l >= size)
2503 if (reverse)
2504 offset -= size;
2506 cst = (*constfun) (constfundata, offset, mode);
2507 if (!targetm.legitimate_constant_p (mode, cst))
2508 return 0;
2510 if (!reverse)
2511 offset += size;
2513 l -= size;
2517 max_size = GET_MODE_SIZE (mode);
2520 /* The code above should have handled everything. */
2521 gcc_assert (!l);
2524 return 1;
2527 /* Generate several move instructions to store LEN bytes generated by
2528 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2529 pointer which will be passed as argument in every CONSTFUN call.
2530 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2531 a memset operation and false if it's a copy of a constant string.
2532 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2533 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2534 stpcpy. */
2537 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2538 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2539 void *constfundata, unsigned int align, bool memsetp, int endp)
2541 enum machine_mode to_addr_mode = get_address_mode (to);
2542 struct store_by_pieces_d data;
2544 if (len == 0)
2546 gcc_assert (endp != 2);
2547 return to;
2550 gcc_assert (memsetp
2551 ? SET_BY_PIECES_P (len, align)
2552 : STORE_BY_PIECES_P (len, align));
2553 data.constfun = constfun;
2554 data.constfundata = constfundata;
2555 data.len = len;
2556 data.to = to;
2557 store_by_pieces_1 (&data, align);
2558 if (endp)
2560 rtx to1;
2562 gcc_assert (!data.reverse);
2563 if (data.autinc_to)
2565 if (endp == 2)
2567 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2568 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2569 else
2570 data.to_addr = copy_to_mode_reg (to_addr_mode,
2571 plus_constant (to_addr_mode,
2572 data.to_addr,
2573 -1));
2575 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2576 data.offset);
2578 else
2580 if (endp == 2)
2581 --data.offset;
2582 to1 = adjust_address (data.to, QImode, data.offset);
2584 return to1;
2586 else
2587 return data.to;
2590 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2591 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2593 static void
2594 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2596 struct store_by_pieces_d data;
2598 if (len == 0)
2599 return;
2601 data.constfun = clear_by_pieces_1;
2602 data.constfundata = NULL;
2603 data.len = len;
2604 data.to = to;
2605 store_by_pieces_1 (&data, align);
2608 /* Callback routine for clear_by_pieces.
2609 Return const0_rtx unconditionally. */
2611 static rtx
2612 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2613 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2614 enum machine_mode mode ATTRIBUTE_UNUSED)
2616 return const0_rtx;
2619 /* Subroutine of clear_by_pieces and store_by_pieces.
2620 Generate several move instructions to store LEN bytes of block TO. (A MEM
2621 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2623 static void
2624 store_by_pieces_1 (struct store_by_pieces_d *data ATTRIBUTE_UNUSED,
2625 unsigned int align ATTRIBUTE_UNUSED)
2627 enum machine_mode to_addr_mode = get_address_mode (data->to);
2628 rtx to_addr = XEXP (data->to, 0);
2629 unsigned int max_size = STORE_MAX_PIECES + 1;
2630 enum insn_code icode;
2632 data->offset = 0;
2633 data->to_addr = to_addr;
2634 data->autinc_to
2635 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2636 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2638 data->explicit_inc_to = 0;
2639 data->reverse
2640 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2641 if (data->reverse)
2642 data->offset = data->len;
2644 /* If storing requires more than two move insns,
2645 copy addresses to registers (to make displacements shorter)
2646 and use post-increment if available. */
2647 if (!data->autinc_to
2648 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2650 /* Determine the main mode we'll be using.
2651 MODE might not be used depending on the definitions of the
2652 USE_* macros below. */
2653 enum machine_mode mode ATTRIBUTE_UNUSED
2654 = widest_int_mode_for_size (max_size);
2656 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2658 data->to_addr = copy_to_mode_reg (to_addr_mode,
2659 plus_constant (to_addr_mode,
2660 to_addr,
2661 data->len));
2662 data->autinc_to = 1;
2663 data->explicit_inc_to = -1;
2666 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2667 && ! data->autinc_to)
2669 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2670 data->autinc_to = 1;
2671 data->explicit_inc_to = 1;
2674 if ( !data->autinc_to && CONSTANT_P (to_addr))
2675 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2678 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2680 /* First store what we can in the largest integer mode, then go to
2681 successively smaller modes. */
2683 while (max_size > 1 && data->len > 0)
2685 enum machine_mode mode = widest_int_mode_for_size (max_size);
2687 if (mode == VOIDmode)
2688 break;
2690 icode = optab_handler (mov_optab, mode);
2691 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2692 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2694 max_size = GET_MODE_SIZE (mode);
2697 /* The code above should have handled everything. */
2698 gcc_assert (!data->len);
2701 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2702 with move instructions for mode MODE. GENFUN is the gen_... function
2703 to make a move insn for that mode. DATA has all the other info. */
2705 static void
2706 store_by_pieces_2 (insn_gen_fn genfun, machine_mode mode,
2707 struct store_by_pieces_d *data)
2709 unsigned int size = GET_MODE_SIZE (mode);
2710 rtx to1, cst;
2712 while (data->len >= size)
2714 if (data->reverse)
2715 data->offset -= size;
2717 if (data->autinc_to)
2718 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2719 data->offset);
2720 else
2721 to1 = adjust_address (data->to, mode, data->offset);
2723 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2724 emit_insn (gen_add2_insn (data->to_addr,
2725 gen_int_mode (-(HOST_WIDE_INT) size,
2726 GET_MODE (data->to_addr))));
2728 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2729 emit_insn ((*genfun) (to1, cst));
2731 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2732 emit_insn (gen_add2_insn (data->to_addr,
2733 gen_int_mode (size,
2734 GET_MODE (data->to_addr))));
2736 if (! data->reverse)
2737 data->offset += size;
2739 data->len -= size;
2743 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2744 its length in bytes. */
2747 clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
2748 unsigned int expected_align, HOST_WIDE_INT expected_size,
2749 unsigned HOST_WIDE_INT min_size,
2750 unsigned HOST_WIDE_INT max_size)
2752 enum machine_mode mode = GET_MODE (object);
2753 unsigned int align;
2755 gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
2757 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2758 just move a zero. Otherwise, do this a piece at a time. */
2759 if (mode != BLKmode
2760 && CONST_INT_P (size)
2761 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
2763 rtx zero = CONST0_RTX (mode);
2764 if (zero != NULL)
2766 emit_move_insn (object, zero);
2767 return NULL;
2770 if (COMPLEX_MODE_P (mode))
2772 zero = CONST0_RTX (GET_MODE_INNER (mode));
2773 if (zero != NULL)
2775 write_complex_part (object, zero, 0);
2776 write_complex_part (object, zero, 1);
2777 return NULL;
2782 if (size == const0_rtx)
2783 return NULL;
2785 align = MEM_ALIGN (object);
2787 if (CONST_INT_P (size)
2788 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2789 clear_by_pieces (object, INTVAL (size), align);
2790 else if (set_storage_via_setmem (object, size, const0_rtx, align,
2791 expected_align, expected_size,
2792 min_size, max_size))
2794 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
2795 return set_storage_via_libcall (object, size, const0_rtx,
2796 method == BLOCK_OP_TAILCALL);
2797 else
2798 gcc_unreachable ();
2800 return NULL;
2804 clear_storage (rtx object, rtx size, enum block_op_methods method)
2806 unsigned HOST_WIDE_INT max, min = 0;
2807 if (GET_CODE (size) == CONST_INT)
2808 min = max = UINTVAL (size);
2809 else
2810 max = GET_MODE_MASK (GET_MODE (size));
2811 return clear_storage_hints (object, size, method, 0, -1, min, max);
2815 /* A subroutine of clear_storage. Expand a call to memset.
2816 Return the return value of memset, 0 otherwise. */
2819 set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
2821 tree call_expr, fn, object_tree, size_tree, val_tree;
2822 enum machine_mode size_mode;
2823 rtx retval;
2825 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2826 place those into new pseudos into a VAR_DECL and use them later. */
2828 object = copy_addr_to_reg (XEXP (object, 0));
2830 size_mode = TYPE_MODE (sizetype);
2831 size = convert_to_mode (size_mode, size, 1);
2832 size = copy_to_mode_reg (size_mode, size);
2834 /* It is incorrect to use the libcall calling conventions to call
2835 memset in this context. This could be a user call to memset and
2836 the user may wish to examine the return value from memset. For
2837 targets where libcalls and normal calls have different conventions
2838 for returning pointers, we could end up generating incorrect code. */
2840 object_tree = make_tree (ptr_type_node, object);
2841 if (!CONST_INT_P (val))
2842 val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
2843 size_tree = make_tree (sizetype, size);
2844 val_tree = make_tree (integer_type_node, val);
2846 fn = clear_storage_libcall_fn (true);
2847 call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
2848 CALL_EXPR_TAILCALL (call_expr) = tailcall;
2850 retval = expand_normal (call_expr);
2852 return retval;
2855 /* A subroutine of set_storage_via_libcall. Create the tree node
2856 for the function we use for block clears. */
2858 tree block_clear_fn;
2860 void
2861 init_block_clear_fn (const char *asmspec)
2863 if (!block_clear_fn)
2865 tree fn, args;
2867 fn = get_identifier ("memset");
2868 args = build_function_type_list (ptr_type_node, ptr_type_node,
2869 integer_type_node, sizetype,
2870 NULL_TREE);
2872 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
2873 DECL_EXTERNAL (fn) = 1;
2874 TREE_PUBLIC (fn) = 1;
2875 DECL_ARTIFICIAL (fn) = 1;
2876 TREE_NOTHROW (fn) = 1;
2877 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
2878 DECL_VISIBILITY_SPECIFIED (fn) = 1;
2880 block_clear_fn = fn;
2883 if (asmspec)
2884 set_user_assembler_name (block_clear_fn, asmspec);
2887 static tree
2888 clear_storage_libcall_fn (int for_call)
2890 static bool emitted_extern;
2892 if (!block_clear_fn)
2893 init_block_clear_fn (NULL);
2895 if (for_call && !emitted_extern)
2897 emitted_extern = true;
2898 make_decl_rtl (block_clear_fn);
2901 return block_clear_fn;
2904 /* Expand a setmem pattern; return true if successful. */
2906 bool
2907 set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
2908 unsigned int expected_align, HOST_WIDE_INT expected_size,
2909 unsigned HOST_WIDE_INT min_size,
2910 unsigned HOST_WIDE_INT max_size)
2912 /* Try the most limited insn first, because there's no point
2913 including more than one in the machine description unless
2914 the more limited one has some advantage. */
2916 enum machine_mode mode;
2918 if (expected_align < align)
2919 expected_align = align;
2920 if (expected_size != -1)
2922 if ((unsigned HOST_WIDE_INT)expected_size > max_size)
2923 expected_size = max_size;
2924 if ((unsigned HOST_WIDE_INT)expected_size < min_size)
2925 expected_size = min_size;
2928 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2929 mode = GET_MODE_WIDER_MODE (mode))
2931 enum insn_code code = direct_optab_handler (setmem_optab, mode);
2933 if (code != CODE_FOR_nothing
2934 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2935 here because if SIZE is less than the mode mask, as it is
2936 returned by the macro, it will definitely be less than the
2937 actual mode mask. Since SIZE is within the Pmode address
2938 space, we limit MODE to Pmode. */
2939 && ((CONST_INT_P (size)
2940 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2941 <= (GET_MODE_MASK (mode) >> 1)))
2942 || max_size <= (GET_MODE_MASK (mode) >> 1)
2943 || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
2945 struct expand_operand ops[8];
2946 unsigned int nops;
2948 nops = insn_data[(int) code].n_generator_args;
2949 gcc_assert (nops == 4 || nops == 6 || nops == 8);
2951 create_fixed_operand (&ops[0], object);
2952 /* The check above guarantees that this size conversion is valid. */
2953 create_convert_operand_to (&ops[1], size, mode, true);
2954 create_convert_operand_from (&ops[2], val, byte_mode, true);
2955 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2956 if (nops >= 6)
2958 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2959 create_integer_operand (&ops[5], expected_size);
2961 if (nops == 8)
2963 create_integer_operand (&ops[6], min_size);
2964 /* If we can not represent the maximal size,
2965 make parameter NULL. */
2966 if ((HOST_WIDE_INT) max_size != -1)
2967 create_integer_operand (&ops[7], max_size);
2968 else
2969 create_fixed_operand (&ops[7], NULL);
2971 if (maybe_expand_insn (code, nops, ops))
2972 return true;
2976 return false;
2980 /* Write to one of the components of the complex value CPLX. Write VAL to
2981 the real part if IMAG_P is false, and the imaginary part if its true. */
2983 static void
2984 write_complex_part (rtx cplx, rtx val, bool imag_p)
2986 enum machine_mode cmode;
2987 enum machine_mode imode;
2988 unsigned ibitsize;
2990 if (GET_CODE (cplx) == CONCAT)
2992 emit_move_insn (XEXP (cplx, imag_p), val);
2993 return;
2996 cmode = GET_MODE (cplx);
2997 imode = GET_MODE_INNER (cmode);
2998 ibitsize = GET_MODE_BITSIZE (imode);
3000 /* For MEMs simplify_gen_subreg may generate an invalid new address
3001 because, e.g., the original address is considered mode-dependent
3002 by the target, which restricts simplify_subreg from invoking
3003 adjust_address_nv. Instead of preparing fallback support for an
3004 invalid address, we call adjust_address_nv directly. */
3005 if (MEM_P (cplx))
3007 emit_move_insn (adjust_address_nv (cplx, imode,
3008 imag_p ? GET_MODE_SIZE (imode) : 0),
3009 val);
3010 return;
3013 /* If the sub-object is at least word sized, then we know that subregging
3014 will work. This special case is important, since store_bit_field
3015 wants to operate on integer modes, and there's rarely an OImode to
3016 correspond to TCmode. */
3017 if (ibitsize >= BITS_PER_WORD
3018 /* For hard regs we have exact predicates. Assume we can split
3019 the original object if it spans an even number of hard regs.
3020 This special case is important for SCmode on 64-bit platforms
3021 where the natural size of floating-point regs is 32-bit. */
3022 || (REG_P (cplx)
3023 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
3024 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
3026 rtx part = simplify_gen_subreg (imode, cplx, cmode,
3027 imag_p ? GET_MODE_SIZE (imode) : 0);
3028 if (part)
3030 emit_move_insn (part, val);
3031 return;
3033 else
3034 /* simplify_gen_subreg may fail for sub-word MEMs. */
3035 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
3038 store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, 0, 0, imode, val);
3041 /* Extract one of the components of the complex value CPLX. Extract the
3042 real part if IMAG_P is false, and the imaginary part if it's true. */
3044 static rtx
3045 read_complex_part (rtx cplx, bool imag_p)
3047 enum machine_mode cmode, imode;
3048 unsigned ibitsize;
3050 if (GET_CODE (cplx) == CONCAT)
3051 return XEXP (cplx, imag_p);
3053 cmode = GET_MODE (cplx);
3054 imode = GET_MODE_INNER (cmode);
3055 ibitsize = GET_MODE_BITSIZE (imode);
3057 /* Special case reads from complex constants that got spilled to memory. */
3058 if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
3060 tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
3061 if (decl && TREE_CODE (decl) == COMPLEX_CST)
3063 tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
3064 if (CONSTANT_CLASS_P (part))
3065 return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
3069 /* For MEMs simplify_gen_subreg may generate an invalid new address
3070 because, e.g., the original address is considered mode-dependent
3071 by the target, which restricts simplify_subreg from invoking
3072 adjust_address_nv. Instead of preparing fallback support for an
3073 invalid address, we call adjust_address_nv directly. */
3074 if (MEM_P (cplx))
3075 return adjust_address_nv (cplx, imode,
3076 imag_p ? GET_MODE_SIZE (imode) : 0);
3078 /* If the sub-object is at least word sized, then we know that subregging
3079 will work. This special case is important, since extract_bit_field
3080 wants to operate on integer modes, and there's rarely an OImode to
3081 correspond to TCmode. */
3082 if (ibitsize >= BITS_PER_WORD
3083 /* For hard regs we have exact predicates. Assume we can split
3084 the original object if it spans an even number of hard regs.
3085 This special case is important for SCmode on 64-bit platforms
3086 where the natural size of floating-point regs is 32-bit. */
3087 || (REG_P (cplx)
3088 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
3089 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
3091 rtx ret = simplify_gen_subreg (imode, cplx, cmode,
3092 imag_p ? GET_MODE_SIZE (imode) : 0);
3093 if (ret)
3094 return ret;
3095 else
3096 /* simplify_gen_subreg may fail for sub-word MEMs. */
3097 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
3100 return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
3101 true, NULL_RTX, imode, imode);
3104 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3105 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3106 represented in NEW_MODE. If FORCE is true, this will never happen, as
3107 we'll force-create a SUBREG if needed. */
3109 static rtx
3110 emit_move_change_mode (enum machine_mode new_mode,
3111 enum machine_mode old_mode, rtx x, bool force)
3113 rtx ret;
3115 if (push_operand (x, GET_MODE (x)))
3117 ret = gen_rtx_MEM (new_mode, XEXP (x, 0));
3118 MEM_COPY_ATTRIBUTES (ret, x);
3120 else if (MEM_P (x))
3122 /* We don't have to worry about changing the address since the
3123 size in bytes is supposed to be the same. */
3124 if (reload_in_progress)
3126 /* Copy the MEM to change the mode and move any
3127 substitutions from the old MEM to the new one. */
3128 ret = adjust_address_nv (x, new_mode, 0);
3129 copy_replacements (x, ret);
3131 else
3132 ret = adjust_address (x, new_mode, 0);
3134 else
3136 /* Note that we do want simplify_subreg's behavior of validating
3137 that the new mode is ok for a hard register. If we were to use
3138 simplify_gen_subreg, we would create the subreg, but would
3139 probably run into the target not being able to implement it. */
3140 /* Except, of course, when FORCE is true, when this is exactly what
3141 we want. Which is needed for CCmodes on some targets. */
3142 if (force)
3143 ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
3144 else
3145 ret = simplify_subreg (new_mode, x, old_mode, 0);
3148 return ret;
3151 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3152 an integer mode of the same size as MODE. Returns the instruction
3153 emitted, or NULL if such a move could not be generated. */
3155 static rtx
3156 emit_move_via_integer (enum machine_mode mode, rtx x, rtx y, bool force)
3158 enum machine_mode imode;
3159 enum insn_code code;
3161 /* There must exist a mode of the exact size we require. */
3162 imode = int_mode_for_mode (mode);
3163 if (imode == BLKmode)
3164 return NULL_RTX;
3166 /* The target must support moves in this mode. */
3167 code = optab_handler (mov_optab, imode);
3168 if (code == CODE_FOR_nothing)
3169 return NULL_RTX;
3171 x = emit_move_change_mode (imode, mode, x, force);
3172 if (x == NULL_RTX)
3173 return NULL_RTX;
3174 y = emit_move_change_mode (imode, mode, y, force);
3175 if (y == NULL_RTX)
3176 return NULL_RTX;
3177 return emit_insn (GEN_FCN (code) (x, y));
3180 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3181 Return an equivalent MEM that does not use an auto-increment. */
3183 static rtx
3184 emit_move_resolve_push (enum machine_mode mode, rtx x)
3186 enum rtx_code code = GET_CODE (XEXP (x, 0));
3187 HOST_WIDE_INT adjust;
3188 rtx temp;
3190 adjust = GET_MODE_SIZE (mode);
3191 #ifdef PUSH_ROUNDING
3192 adjust = PUSH_ROUNDING (adjust);
3193 #endif
3194 if (code == PRE_DEC || code == POST_DEC)
3195 adjust = -adjust;
3196 else if (code == PRE_MODIFY || code == POST_MODIFY)
3198 rtx expr = XEXP (XEXP (x, 0), 1);
3199 HOST_WIDE_INT val;
3201 gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
3202 gcc_assert (CONST_INT_P (XEXP (expr, 1)));
3203 val = INTVAL (XEXP (expr, 1));
3204 if (GET_CODE (expr) == MINUS)
3205 val = -val;
3206 gcc_assert (adjust == val || adjust == -val);
3207 adjust = val;
3210 /* Do not use anti_adjust_stack, since we don't want to update
3211 stack_pointer_delta. */
3212 temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
3213 gen_int_mode (adjust, Pmode), stack_pointer_rtx,
3214 0, OPTAB_LIB_WIDEN);
3215 if (temp != stack_pointer_rtx)
3216 emit_move_insn (stack_pointer_rtx, temp);
3218 switch (code)
3220 case PRE_INC:
3221 case PRE_DEC:
3222 case PRE_MODIFY:
3223 temp = stack_pointer_rtx;
3224 break;
3225 case POST_INC:
3226 case POST_DEC:
3227 case POST_MODIFY:
3228 temp = plus_constant (Pmode, stack_pointer_rtx, -adjust);
3229 break;
3230 default:
3231 gcc_unreachable ();
3234 return replace_equiv_address (x, temp);
3237 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3238 X is known to satisfy push_operand, and MODE is known to be complex.
3239 Returns the last instruction emitted. */
3242 emit_move_complex_push (enum machine_mode mode, rtx x, rtx y)
3244 enum machine_mode submode = GET_MODE_INNER (mode);
3245 bool imag_first;
3247 #ifdef PUSH_ROUNDING
3248 unsigned int submodesize = GET_MODE_SIZE (submode);
3250 /* In case we output to the stack, but the size is smaller than the
3251 machine can push exactly, we need to use move instructions. */
3252 if (PUSH_ROUNDING (submodesize) != submodesize)
3254 x = emit_move_resolve_push (mode, x);
3255 return emit_move_insn (x, y);
3257 #endif
3259 /* Note that the real part always precedes the imag part in memory
3260 regardless of machine's endianness. */
3261 switch (GET_CODE (XEXP (x, 0)))
3263 case PRE_DEC:
3264 case POST_DEC:
3265 imag_first = true;
3266 break;
3267 case PRE_INC:
3268 case POST_INC:
3269 imag_first = false;
3270 break;
3271 default:
3272 gcc_unreachable ();
3275 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3276 read_complex_part (y, imag_first));
3277 return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3278 read_complex_part (y, !imag_first));
3281 /* A subroutine of emit_move_complex. Perform the move from Y to X
3282 via two moves of the parts. Returns the last instruction emitted. */
3285 emit_move_complex_parts (rtx x, rtx y)
3287 /* Show the output dies here. This is necessary for SUBREGs
3288 of pseudos since we cannot track their lifetimes correctly;
3289 hard regs shouldn't appear here except as return values. */
3290 if (!reload_completed && !reload_in_progress
3291 && REG_P (x) && !reg_overlap_mentioned_p (x, y))
3292 emit_clobber (x);
3294 write_complex_part (x, read_complex_part (y, false), false);
3295 write_complex_part (x, read_complex_part (y, true), true);
3297 return get_last_insn ();
3300 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3301 MODE is known to be complex. Returns the last instruction emitted. */
3303 static rtx
3304 emit_move_complex (enum machine_mode mode, rtx x, rtx y)
3306 bool try_int;
3308 /* Need to take special care for pushes, to maintain proper ordering
3309 of the data, and possibly extra padding. */
3310 if (push_operand (x, mode))
3311 return emit_move_complex_push (mode, x, y);
3313 /* See if we can coerce the target into moving both values at once, except
3314 for floating point where we favor moving as parts if this is easy. */
3315 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3316 && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing
3317 && !(REG_P (x)
3318 && HARD_REGISTER_P (x)
3319 && hard_regno_nregs[REGNO (x)][mode] == 1)
3320 && !(REG_P (y)
3321 && HARD_REGISTER_P (y)
3322 && hard_regno_nregs[REGNO (y)][mode] == 1))
3323 try_int = false;
3324 /* Not possible if the values are inherently not adjacent. */
3325 else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
3326 try_int = false;
3327 /* Is possible if both are registers (or subregs of registers). */
3328 else if (register_operand (x, mode) && register_operand (y, mode))
3329 try_int = true;
3330 /* If one of the operands is a memory, and alignment constraints
3331 are friendly enough, we may be able to do combined memory operations.
3332 We do not attempt this if Y is a constant because that combination is
3333 usually better with the by-parts thing below. */
3334 else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
3335 && (!STRICT_ALIGNMENT
3336 || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
3337 try_int = true;
3338 else
3339 try_int = false;
3341 if (try_int)
3343 rtx ret;
3345 /* For memory to memory moves, optimal behavior can be had with the
3346 existing block move logic. */
3347 if (MEM_P (x) && MEM_P (y))
3349 emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
3350 BLOCK_OP_NO_LIBCALL);
3351 return get_last_insn ();
3354 ret = emit_move_via_integer (mode, x, y, true);
3355 if (ret)
3356 return ret;
3359 return emit_move_complex_parts (x, y);
3362 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3363 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3365 static rtx
3366 emit_move_ccmode (enum machine_mode mode, rtx x, rtx y)
3368 rtx ret;
3370 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3371 if (mode != CCmode)
3373 enum insn_code code = optab_handler (mov_optab, CCmode);
3374 if (code != CODE_FOR_nothing)
3376 x = emit_move_change_mode (CCmode, mode, x, true);
3377 y = emit_move_change_mode (CCmode, mode, y, true);
3378 return emit_insn (GEN_FCN (code) (x, y));
3382 /* Otherwise, find the MODE_INT mode of the same width. */
3383 ret = emit_move_via_integer (mode, x, y, false);
3384 gcc_assert (ret != NULL);
3385 return ret;
3388 /* Return true if word I of OP lies entirely in the
3389 undefined bits of a paradoxical subreg. */
3391 static bool
3392 undefined_operand_subword_p (const_rtx op, int i)
3394 enum machine_mode innermode, innermostmode;
3395 int offset;
3396 if (GET_CODE (op) != SUBREG)
3397 return false;
3398 innermode = GET_MODE (op);
3399 innermostmode = GET_MODE (SUBREG_REG (op));
3400 offset = i * UNITS_PER_WORD + SUBREG_BYTE (op);
3401 /* The SUBREG_BYTE represents offset, as if the value were stored in
3402 memory, except for a paradoxical subreg where we define
3403 SUBREG_BYTE to be 0; undo this exception as in
3404 simplify_subreg. */
3405 if (SUBREG_BYTE (op) == 0
3406 && GET_MODE_SIZE (innermostmode) < GET_MODE_SIZE (innermode))
3408 int difference = (GET_MODE_SIZE (innermostmode) - GET_MODE_SIZE (innermode));
3409 if (WORDS_BIG_ENDIAN)
3410 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
3411 if (BYTES_BIG_ENDIAN)
3412 offset += difference % UNITS_PER_WORD;
3414 if (offset >= GET_MODE_SIZE (innermostmode)
3415 || offset <= -GET_MODE_SIZE (word_mode))
3416 return true;
3417 return false;
3420 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3421 MODE is any multi-word or full-word mode that lacks a move_insn
3422 pattern. Note that you will get better code if you define such
3423 patterns, even if they must turn into multiple assembler instructions. */
3425 static rtx
3426 emit_move_multi_word (enum machine_mode mode, rtx x, rtx y)
3428 rtx last_insn = 0;
3429 rtx seq, inner;
3430 bool need_clobber;
3431 int i;
3433 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
3435 /* If X is a push on the stack, do the push now and replace
3436 X with a reference to the stack pointer. */
3437 if (push_operand (x, mode))
3438 x = emit_move_resolve_push (mode, x);
3440 /* If we are in reload, see if either operand is a MEM whose address
3441 is scheduled for replacement. */
3442 if (reload_in_progress && MEM_P (x)
3443 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3444 x = replace_equiv_address_nv (x, inner);
3445 if (reload_in_progress && MEM_P (y)
3446 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3447 y = replace_equiv_address_nv (y, inner);
3449 start_sequence ();
3451 need_clobber = false;
3452 for (i = 0;
3453 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3454 i++)
3456 rtx xpart = operand_subword (x, i, 1, mode);
3457 rtx ypart;
3459 /* Do not generate code for a move if it would come entirely
3460 from the undefined bits of a paradoxical subreg. */
3461 if (undefined_operand_subword_p (y, i))
3462 continue;
3464 ypart = operand_subword (y, i, 1, mode);
3466 /* If we can't get a part of Y, put Y into memory if it is a
3467 constant. Otherwise, force it into a register. Then we must
3468 be able to get a part of Y. */
3469 if (ypart == 0 && CONSTANT_P (y))
3471 y = use_anchored_address (force_const_mem (mode, y));
3472 ypart = operand_subword (y, i, 1, mode);
3474 else if (ypart == 0)
3475 ypart = operand_subword_force (y, i, mode);
3477 gcc_assert (xpart && ypart);
3479 need_clobber |= (GET_CODE (xpart) == SUBREG);
3481 last_insn = emit_move_insn (xpart, ypart);
3484 seq = get_insns ();
3485 end_sequence ();
3487 /* Show the output dies here. This is necessary for SUBREGs
3488 of pseudos since we cannot track their lifetimes correctly;
3489 hard regs shouldn't appear here except as return values.
3490 We never want to emit such a clobber after reload. */
3491 if (x != y
3492 && ! (reload_in_progress || reload_completed)
3493 && need_clobber != 0)
3494 emit_clobber (x);
3496 emit_insn (seq);
3498 return last_insn;
3501 /* Low level part of emit_move_insn.
3502 Called just like emit_move_insn, but assumes X and Y
3503 are basically valid. */
3506 emit_move_insn_1 (rtx x, rtx y)
3508 enum machine_mode mode = GET_MODE (x);
3509 enum insn_code code;
3511 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
3513 code = optab_handler (mov_optab, mode);
3514 if (code != CODE_FOR_nothing)
3515 return emit_insn (GEN_FCN (code) (x, y));
3517 /* Expand complex moves by moving real part and imag part. */
3518 if (COMPLEX_MODE_P (mode))
3519 return emit_move_complex (mode, x, y);
3521 if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
3522 || ALL_FIXED_POINT_MODE_P (mode))
3524 rtx result = emit_move_via_integer (mode, x, y, true);
3526 /* If we can't find an integer mode, use multi words. */
3527 if (result)
3528 return result;
3529 else
3530 return emit_move_multi_word (mode, x, y);
3533 if (GET_MODE_CLASS (mode) == MODE_CC)
3534 return emit_move_ccmode (mode, x, y);
3536 /* Try using a move pattern for the corresponding integer mode. This is
3537 only safe when simplify_subreg can convert MODE constants into integer
3538 constants. At present, it can only do this reliably if the value
3539 fits within a HOST_WIDE_INT. */
3540 if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3542 rtx ret = emit_move_via_integer (mode, x, y, lra_in_progress);
3544 if (ret)
3546 if (! lra_in_progress || recog (PATTERN (ret), ret, 0) >= 0)
3547 return ret;
3551 return emit_move_multi_word (mode, x, y);
3554 /* Generate code to copy Y into X.
3555 Both Y and X must have the same mode, except that
3556 Y can be a constant with VOIDmode.
3557 This mode cannot be BLKmode; use emit_block_move for that.
3559 Return the last instruction emitted. */
3562 emit_move_insn (rtx x, rtx y)
3564 enum machine_mode mode = GET_MODE (x);
3565 rtx y_cst = NULL_RTX;
3566 rtx last_insn, set;
3568 gcc_assert (mode != BLKmode
3569 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
3571 if (CONSTANT_P (y))
3573 if (optimize
3574 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3575 && (last_insn = compress_float_constant (x, y)))
3576 return last_insn;
3578 y_cst = y;
3580 if (!targetm.legitimate_constant_p (mode, y))
3582 y = force_const_mem (mode, y);
3584 /* If the target's cannot_force_const_mem prevented the spill,
3585 assume that the target's move expanders will also take care
3586 of the non-legitimate constant. */
3587 if (!y)
3588 y = y_cst;
3589 else
3590 y = use_anchored_address (y);
3594 /* If X or Y are memory references, verify that their addresses are valid
3595 for the machine. */
3596 if (MEM_P (x)
3597 && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
3598 MEM_ADDR_SPACE (x))
3599 && ! push_operand (x, GET_MODE (x))))
3600 x = validize_mem (x);
3602 if (MEM_P (y)
3603 && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
3604 MEM_ADDR_SPACE (y)))
3605 y = validize_mem (y);
3607 gcc_assert (mode != BLKmode);
3609 last_insn = emit_move_insn_1 (x, y);
3611 if (y_cst && REG_P (x)
3612 && (set = single_set (last_insn)) != NULL_RTX
3613 && SET_DEST (set) == x
3614 && ! rtx_equal_p (y_cst, SET_SRC (set)))
3615 set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
3617 return last_insn;
3620 /* If Y is representable exactly in a narrower mode, and the target can
3621 perform the extension directly from constant or memory, then emit the
3622 move as an extension. */
3624 static rtx
3625 compress_float_constant (rtx x, rtx y)
3627 enum machine_mode dstmode = GET_MODE (x);
3628 enum machine_mode orig_srcmode = GET_MODE (y);
3629 enum machine_mode srcmode;
3630 REAL_VALUE_TYPE r;
3631 int oldcost, newcost;
3632 bool speed = optimize_insn_for_speed_p ();
3634 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3636 if (targetm.legitimate_constant_p (dstmode, y))
3637 oldcost = set_src_cost (y, speed);
3638 else
3639 oldcost = set_src_cost (force_const_mem (dstmode, y), speed);
3641 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3642 srcmode != orig_srcmode;
3643 srcmode = GET_MODE_WIDER_MODE (srcmode))
3645 enum insn_code ic;
3646 rtx trunc_y, last_insn;
3648 /* Skip if the target can't extend this way. */
3649 ic = can_extend_p (dstmode, srcmode, 0);
3650 if (ic == CODE_FOR_nothing)
3651 continue;
3653 /* Skip if the narrowed value isn't exact. */
3654 if (! exact_real_truncate (srcmode, &r))
3655 continue;
3657 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3659 if (targetm.legitimate_constant_p (srcmode, trunc_y))
3661 /* Skip if the target needs extra instructions to perform
3662 the extension. */
3663 if (!insn_operand_matches (ic, 1, trunc_y))
3664 continue;
3665 /* This is valid, but may not be cheaper than the original. */
3666 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3667 speed);
3668 if (oldcost < newcost)
3669 continue;
3671 else if (float_extend_from_mem[dstmode][srcmode])
3673 trunc_y = force_const_mem (srcmode, trunc_y);
3674 /* This is valid, but may not be cheaper than the original. */
3675 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3676 speed);
3677 if (oldcost < newcost)
3678 continue;
3679 trunc_y = validize_mem (trunc_y);
3681 else
3682 continue;
3684 /* For CSE's benefit, force the compressed constant pool entry
3685 into a new pseudo. This constant may be used in different modes,
3686 and if not, combine will put things back together for us. */
3687 trunc_y = force_reg (srcmode, trunc_y);
3688 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3689 last_insn = get_last_insn ();
3691 if (REG_P (x))
3692 set_unique_reg_note (last_insn, REG_EQUAL, y);
3694 return last_insn;
3697 return NULL_RTX;
3700 /* Pushing data onto the stack. */
3702 /* Push a block of length SIZE (perhaps variable)
3703 and return an rtx to address the beginning of the block.
3704 The value may be virtual_outgoing_args_rtx.
3706 EXTRA is the number of bytes of padding to push in addition to SIZE.
3707 BELOW nonzero means this padding comes at low addresses;
3708 otherwise, the padding comes at high addresses. */
3711 push_block (rtx size, int extra, int below)
3713 rtx temp;
3715 size = convert_modes (Pmode, ptr_mode, size, 1);
3716 if (CONSTANT_P (size))
3717 anti_adjust_stack (plus_constant (Pmode, size, extra));
3718 else if (REG_P (size) && extra == 0)
3719 anti_adjust_stack (size);
3720 else
3722 temp = copy_to_mode_reg (Pmode, size);
3723 if (extra != 0)
3724 temp = expand_binop (Pmode, add_optab, temp,
3725 gen_int_mode (extra, Pmode),
3726 temp, 0, OPTAB_LIB_WIDEN);
3727 anti_adjust_stack (temp);
3730 #ifndef STACK_GROWS_DOWNWARD
3731 if (0)
3732 #else
3733 if (1)
3734 #endif
3736 temp = virtual_outgoing_args_rtx;
3737 if (extra != 0 && below)
3738 temp = plus_constant (Pmode, temp, extra);
3740 else
3742 if (CONST_INT_P (size))
3743 temp = plus_constant (Pmode, virtual_outgoing_args_rtx,
3744 -INTVAL (size) - (below ? 0 : extra));
3745 else if (extra != 0 && !below)
3746 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3747 negate_rtx (Pmode, plus_constant (Pmode, size,
3748 extra)));
3749 else
3750 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3751 negate_rtx (Pmode, size));
3754 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3757 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3759 static rtx
3760 mem_autoinc_base (rtx mem)
3762 if (MEM_P (mem))
3764 rtx addr = XEXP (mem, 0);
3765 if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
3766 return XEXP (addr, 0);
3768 return NULL;
3771 /* A utility routine used here, in reload, and in try_split. The insns
3772 after PREV up to and including LAST are known to adjust the stack,
3773 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3774 placing notes as appropriate. PREV may be NULL, indicating the
3775 entire insn sequence prior to LAST should be scanned.
3777 The set of allowed stack pointer modifications is small:
3778 (1) One or more auto-inc style memory references (aka pushes),
3779 (2) One or more addition/subtraction with the SP as destination,
3780 (3) A single move insn with the SP as destination,
3781 (4) A call_pop insn,
3782 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3784 Insns in the sequence that do not modify the SP are ignored,
3785 except for noreturn calls.
3787 The return value is the amount of adjustment that can be trivially
3788 verified, via immediate operand or auto-inc. If the adjustment
3789 cannot be trivially extracted, the return value is INT_MIN. */
3791 HOST_WIDE_INT
3792 find_args_size_adjust (rtx insn)
3794 rtx dest, set, pat;
3795 int i;
3797 pat = PATTERN (insn);
3798 set = NULL;
3800 /* Look for a call_pop pattern. */
3801 if (CALL_P (insn))
3803 /* We have to allow non-call_pop patterns for the case
3804 of emit_single_push_insn of a TLS address. */
3805 if (GET_CODE (pat) != PARALLEL)
3806 return 0;
3808 /* All call_pop have a stack pointer adjust in the parallel.
3809 The call itself is always first, and the stack adjust is
3810 usually last, so search from the end. */
3811 for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
3813 set = XVECEXP (pat, 0, i);
3814 if (GET_CODE (set) != SET)
3815 continue;
3816 dest = SET_DEST (set);
3817 if (dest == stack_pointer_rtx)
3818 break;
3820 /* We'd better have found the stack pointer adjust. */
3821 if (i == 0)
3822 return 0;
3823 /* Fall through to process the extracted SET and DEST
3824 as if it was a standalone insn. */
3826 else if (GET_CODE (pat) == SET)
3827 set = pat;
3828 else if ((set = single_set (insn)) != NULL)
3830 else if (GET_CODE (pat) == PARALLEL)
3832 /* ??? Some older ports use a parallel with a stack adjust
3833 and a store for a PUSH_ROUNDING pattern, rather than a
3834 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3835 /* ??? See h8300 and m68k, pushqi1. */
3836 for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
3838 set = XVECEXP (pat, 0, i);
3839 if (GET_CODE (set) != SET)
3840 continue;
3841 dest = SET_DEST (set);
3842 if (dest == stack_pointer_rtx)
3843 break;
3845 /* We do not expect an auto-inc of the sp in the parallel. */
3846 gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
3847 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3848 != stack_pointer_rtx);
3850 if (i < 0)
3851 return 0;
3853 else
3854 return 0;
3856 dest = SET_DEST (set);
3858 /* Look for direct modifications of the stack pointer. */
3859 if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
3861 /* Look for a trivial adjustment, otherwise assume nothing. */
3862 /* Note that the SPU restore_stack_block pattern refers to
3863 the stack pointer in V4SImode. Consider that non-trivial. */
3864 if (SCALAR_INT_MODE_P (GET_MODE (dest))
3865 && GET_CODE (SET_SRC (set)) == PLUS
3866 && XEXP (SET_SRC (set), 0) == stack_pointer_rtx
3867 && CONST_INT_P (XEXP (SET_SRC (set), 1)))
3868 return INTVAL (XEXP (SET_SRC (set), 1));
3869 /* ??? Reload can generate no-op moves, which will be cleaned
3870 up later. Recognize it and continue searching. */
3871 else if (rtx_equal_p (dest, SET_SRC (set)))
3872 return 0;
3873 else
3874 return HOST_WIDE_INT_MIN;
3876 else
3878 rtx mem, addr;
3880 /* Otherwise only think about autoinc patterns. */
3881 if (mem_autoinc_base (dest) == stack_pointer_rtx)
3883 mem = dest;
3884 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3885 != stack_pointer_rtx);
3887 else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
3888 mem = SET_SRC (set);
3889 else
3890 return 0;
3892 addr = XEXP (mem, 0);
3893 switch (GET_CODE (addr))
3895 case PRE_INC:
3896 case POST_INC:
3897 return GET_MODE_SIZE (GET_MODE (mem));
3898 case PRE_DEC:
3899 case POST_DEC:
3900 return -GET_MODE_SIZE (GET_MODE (mem));
3901 case PRE_MODIFY:
3902 case POST_MODIFY:
3903 addr = XEXP (addr, 1);
3904 gcc_assert (GET_CODE (addr) == PLUS);
3905 gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
3906 gcc_assert (CONST_INT_P (XEXP (addr, 1)));
3907 return INTVAL (XEXP (addr, 1));
3908 default:
3909 gcc_unreachable ();
3915 fixup_args_size_notes (rtx prev, rtx last, int end_args_size)
3917 int args_size = end_args_size;
3918 bool saw_unknown = false;
3919 rtx insn;
3921 for (insn = last; insn != prev; insn = PREV_INSN (insn))
3923 HOST_WIDE_INT this_delta;
3925 if (!NONDEBUG_INSN_P (insn))
3926 continue;
3928 this_delta = find_args_size_adjust (insn);
3929 if (this_delta == 0)
3931 if (!CALL_P (insn)
3932 || ACCUMULATE_OUTGOING_ARGS
3933 || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
3934 continue;
3937 gcc_assert (!saw_unknown);
3938 if (this_delta == HOST_WIDE_INT_MIN)
3939 saw_unknown = true;
3941 add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (args_size));
3942 #ifdef STACK_GROWS_DOWNWARD
3943 this_delta = -(unsigned HOST_WIDE_INT) this_delta;
3944 #endif
3945 args_size -= this_delta;
3948 return saw_unknown ? INT_MIN : args_size;
3951 #ifdef PUSH_ROUNDING
3952 /* Emit single push insn. */
3954 static void
3955 emit_single_push_insn_1 (enum machine_mode mode, rtx x, tree type)
3957 rtx dest_addr;
3958 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3959 rtx dest;
3960 enum insn_code icode;
3962 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3963 /* If there is push pattern, use it. Otherwise try old way of throwing
3964 MEM representing push operation to move expander. */
3965 icode = optab_handler (push_optab, mode);
3966 if (icode != CODE_FOR_nothing)
3968 struct expand_operand ops[1];
3970 create_input_operand (&ops[0], x, mode);
3971 if (maybe_expand_insn (icode, 1, ops))
3972 return;
3974 if (GET_MODE_SIZE (mode) == rounded_size)
3975 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3976 /* If we are to pad downward, adjust the stack pointer first and
3977 then store X into the stack location using an offset. This is
3978 because emit_move_insn does not know how to pad; it does not have
3979 access to type. */
3980 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3982 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3983 HOST_WIDE_INT offset;
3985 emit_move_insn (stack_pointer_rtx,
3986 expand_binop (Pmode,
3987 #ifdef STACK_GROWS_DOWNWARD
3988 sub_optab,
3989 #else
3990 add_optab,
3991 #endif
3992 stack_pointer_rtx,
3993 gen_int_mode (rounded_size, Pmode),
3994 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3996 offset = (HOST_WIDE_INT) padding_size;
3997 #ifdef STACK_GROWS_DOWNWARD
3998 if (STACK_PUSH_CODE == POST_DEC)
3999 /* We have already decremented the stack pointer, so get the
4000 previous value. */
4001 offset += (HOST_WIDE_INT) rounded_size;
4002 #else
4003 if (STACK_PUSH_CODE == POST_INC)
4004 /* We have already incremented the stack pointer, so get the
4005 previous value. */
4006 offset -= (HOST_WIDE_INT) rounded_size;
4007 #endif
4008 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4009 gen_int_mode (offset, Pmode));
4011 else
4013 #ifdef STACK_GROWS_DOWNWARD
4014 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4015 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4016 gen_int_mode (-(HOST_WIDE_INT) rounded_size,
4017 Pmode));
4018 #else
4019 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4020 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4021 gen_int_mode (rounded_size, Pmode));
4022 #endif
4023 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
4026 dest = gen_rtx_MEM (mode, dest_addr);
4028 if (type != 0)
4030 set_mem_attributes (dest, type, 1);
4032 if (flag_optimize_sibling_calls)
4033 /* Function incoming arguments may overlap with sibling call
4034 outgoing arguments and we cannot allow reordering of reads
4035 from function arguments with stores to outgoing arguments
4036 of sibling calls. */
4037 set_mem_alias_set (dest, 0);
4039 emit_move_insn (dest, x);
4042 /* Emit and annotate a single push insn. */
4044 static void
4045 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
4047 int delta, old_delta = stack_pointer_delta;
4048 rtx prev = get_last_insn ();
4049 rtx last;
4051 emit_single_push_insn_1 (mode, x, type);
4053 last = get_last_insn ();
4055 /* Notice the common case where we emitted exactly one insn. */
4056 if (PREV_INSN (last) == prev)
4058 add_reg_note (last, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
4059 return;
4062 delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
4063 gcc_assert (delta == INT_MIN || delta == old_delta);
4065 #endif
4067 /* Generate code to push X onto the stack, assuming it has mode MODE and
4068 type TYPE.
4069 MODE is redundant except when X is a CONST_INT (since they don't
4070 carry mode info).
4071 SIZE is an rtx for the size of data to be copied (in bytes),
4072 needed only if X is BLKmode.
4074 ALIGN (in bits) is maximum alignment we can assume.
4076 If PARTIAL and REG are both nonzero, then copy that many of the first
4077 bytes of X into registers starting with REG, and push the rest of X.
4078 The amount of space pushed is decreased by PARTIAL bytes.
4079 REG must be a hard register in this case.
4080 If REG is zero but PARTIAL is not, take any all others actions for an
4081 argument partially in registers, but do not actually load any
4082 registers.
4084 EXTRA is the amount in bytes of extra space to leave next to this arg.
4085 This is ignored if an argument block has already been allocated.
4087 On a machine that lacks real push insns, ARGS_ADDR is the address of
4088 the bottom of the argument block for this call. We use indexing off there
4089 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4090 argument block has not been preallocated.
4092 ARGS_SO_FAR is the size of args previously pushed for this call.
4094 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4095 for arguments passed in registers. If nonzero, it will be the number
4096 of bytes required. */
4098 void
4099 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
4100 unsigned int align, int partial, rtx reg, int extra,
4101 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
4102 rtx alignment_pad)
4104 rtx xinner;
4105 enum direction stack_direction
4106 #ifdef STACK_GROWS_DOWNWARD
4107 = downward;
4108 #else
4109 = upward;
4110 #endif
4112 /* Decide where to pad the argument: `downward' for below,
4113 `upward' for above, or `none' for don't pad it.
4114 Default is below for small data on big-endian machines; else above. */
4115 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
4117 /* Invert direction if stack is post-decrement.
4118 FIXME: why? */
4119 if (STACK_PUSH_CODE == POST_DEC)
4120 if (where_pad != none)
4121 where_pad = (where_pad == downward ? upward : downward);
4123 xinner = x;
4125 if (mode == BLKmode
4126 || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
4128 /* Copy a block into the stack, entirely or partially. */
4130 rtx temp;
4131 int used;
4132 int offset;
4133 int skip;
4135 offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4136 used = partial - offset;
4138 if (mode != BLKmode)
4140 /* A value is to be stored in an insufficiently aligned
4141 stack slot; copy via a suitably aligned slot if
4142 necessary. */
4143 size = GEN_INT (GET_MODE_SIZE (mode));
4144 if (!MEM_P (xinner))
4146 temp = assign_temp (type, 1, 1);
4147 emit_move_insn (temp, xinner);
4148 xinner = temp;
4152 gcc_assert (size);
4154 /* USED is now the # of bytes we need not copy to the stack
4155 because registers will take care of them. */
4157 if (partial != 0)
4158 xinner = adjust_address (xinner, BLKmode, used);
4160 /* If the partial register-part of the arg counts in its stack size,
4161 skip the part of stack space corresponding to the registers.
4162 Otherwise, start copying to the beginning of the stack space,
4163 by setting SKIP to 0. */
4164 skip = (reg_parm_stack_space == 0) ? 0 : used;
4166 #ifdef PUSH_ROUNDING
4167 /* Do it with several push insns if that doesn't take lots of insns
4168 and if there is no difficulty with push insns that skip bytes
4169 on the stack for alignment purposes. */
4170 if (args_addr == 0
4171 && PUSH_ARGS
4172 && CONST_INT_P (size)
4173 && skip == 0
4174 && MEM_ALIGN (xinner) >= align
4175 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
4176 /* Here we avoid the case of a structure whose weak alignment
4177 forces many pushes of a small amount of data,
4178 and such small pushes do rounding that causes trouble. */
4179 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
4180 || align >= BIGGEST_ALIGNMENT
4181 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
4182 == (align / BITS_PER_UNIT)))
4183 && (HOST_WIDE_INT) PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
4185 /* Push padding now if padding above and stack grows down,
4186 or if padding below and stack grows up.
4187 But if space already allocated, this has already been done. */
4188 if (extra && args_addr == 0
4189 && where_pad != none && where_pad != stack_direction)
4190 anti_adjust_stack (GEN_INT (extra));
4192 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
4194 else
4195 #endif /* PUSH_ROUNDING */
4197 rtx target;
4199 /* Otherwise make space on the stack and copy the data
4200 to the address of that space. */
4202 /* Deduct words put into registers from the size we must copy. */
4203 if (partial != 0)
4205 if (CONST_INT_P (size))
4206 size = GEN_INT (INTVAL (size) - used);
4207 else
4208 size = expand_binop (GET_MODE (size), sub_optab, size,
4209 gen_int_mode (used, GET_MODE (size)),
4210 NULL_RTX, 0, OPTAB_LIB_WIDEN);
4213 /* Get the address of the stack space.
4214 In this case, we do not deal with EXTRA separately.
4215 A single stack adjust will do. */
4216 if (! args_addr)
4218 temp = push_block (size, extra, where_pad == downward);
4219 extra = 0;
4221 else if (CONST_INT_P (args_so_far))
4222 temp = memory_address (BLKmode,
4223 plus_constant (Pmode, args_addr,
4224 skip + INTVAL (args_so_far)));
4225 else
4226 temp = memory_address (BLKmode,
4227 plus_constant (Pmode,
4228 gen_rtx_PLUS (Pmode,
4229 args_addr,
4230 args_so_far),
4231 skip));
4233 if (!ACCUMULATE_OUTGOING_ARGS)
4235 /* If the source is referenced relative to the stack pointer,
4236 copy it to another register to stabilize it. We do not need
4237 to do this if we know that we won't be changing sp. */
4239 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
4240 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
4241 temp = copy_to_reg (temp);
4244 target = gen_rtx_MEM (BLKmode, temp);
4246 /* We do *not* set_mem_attributes here, because incoming arguments
4247 may overlap with sibling call outgoing arguments and we cannot
4248 allow reordering of reads from function arguments with stores
4249 to outgoing arguments of sibling calls. We do, however, want
4250 to record the alignment of the stack slot. */
4251 /* ALIGN may well be better aligned than TYPE, e.g. due to
4252 PARM_BOUNDARY. Assume the caller isn't lying. */
4253 set_mem_align (target, align);
4255 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
4258 else if (partial > 0)
4260 /* Scalar partly in registers. */
4262 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
4263 int i;
4264 int not_stack;
4265 /* # bytes of start of argument
4266 that we must make space for but need not store. */
4267 int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4268 int args_offset = INTVAL (args_so_far);
4269 int skip;
4271 /* Push padding now if padding above and stack grows down,
4272 or if padding below and stack grows up.
4273 But if space already allocated, this has already been done. */
4274 if (extra && args_addr == 0
4275 && where_pad != none && where_pad != stack_direction)
4276 anti_adjust_stack (GEN_INT (extra));
4278 /* If we make space by pushing it, we might as well push
4279 the real data. Otherwise, we can leave OFFSET nonzero
4280 and leave the space uninitialized. */
4281 if (args_addr == 0)
4282 offset = 0;
4284 /* Now NOT_STACK gets the number of words that we don't need to
4285 allocate on the stack. Convert OFFSET to words too. */
4286 not_stack = (partial - offset) / UNITS_PER_WORD;
4287 offset /= UNITS_PER_WORD;
4289 /* If the partial register-part of the arg counts in its stack size,
4290 skip the part of stack space corresponding to the registers.
4291 Otherwise, start copying to the beginning of the stack space,
4292 by setting SKIP to 0. */
4293 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
4295 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
4296 x = validize_mem (force_const_mem (mode, x));
4298 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4299 SUBREGs of such registers are not allowed. */
4300 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
4301 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
4302 x = copy_to_reg (x);
4304 /* Loop over all the words allocated on the stack for this arg. */
4305 /* We can do it by words, because any scalar bigger than a word
4306 has a size a multiple of a word. */
4307 #ifndef PUSH_ARGS_REVERSED
4308 for (i = not_stack; i < size; i++)
4309 #else
4310 for (i = size - 1; i >= not_stack; i--)
4311 #endif
4312 if (i >= not_stack + offset)
4313 emit_push_insn (operand_subword_force (x, i, mode),
4314 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
4315 0, args_addr,
4316 GEN_INT (args_offset + ((i - not_stack + skip)
4317 * UNITS_PER_WORD)),
4318 reg_parm_stack_space, alignment_pad);
4320 else
4322 rtx addr;
4323 rtx dest;
4325 /* Push padding now if padding above and stack grows down,
4326 or if padding below and stack grows up.
4327 But if space already allocated, this has already been done. */
4328 if (extra && args_addr == 0
4329 && where_pad != none && where_pad != stack_direction)
4330 anti_adjust_stack (GEN_INT (extra));
4332 #ifdef PUSH_ROUNDING
4333 if (args_addr == 0 && PUSH_ARGS)
4334 emit_single_push_insn (mode, x, type);
4335 else
4336 #endif
4338 if (CONST_INT_P (args_so_far))
4339 addr
4340 = memory_address (mode,
4341 plus_constant (Pmode, args_addr,
4342 INTVAL (args_so_far)));
4343 else
4344 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
4345 args_so_far));
4346 dest = gen_rtx_MEM (mode, addr);
4348 /* We do *not* set_mem_attributes here, because incoming arguments
4349 may overlap with sibling call outgoing arguments and we cannot
4350 allow reordering of reads from function arguments with stores
4351 to outgoing arguments of sibling calls. We do, however, want
4352 to record the alignment of the stack slot. */
4353 /* ALIGN may well be better aligned than TYPE, e.g. due to
4354 PARM_BOUNDARY. Assume the caller isn't lying. */
4355 set_mem_align (dest, align);
4357 emit_move_insn (dest, x);
4361 /* If part should go in registers, copy that part
4362 into the appropriate registers. Do this now, at the end,
4363 since mem-to-mem copies above may do function calls. */
4364 if (partial > 0 && reg != 0)
4366 /* Handle calls that pass values in multiple non-contiguous locations.
4367 The Irix 6 ABI has examples of this. */
4368 if (GET_CODE (reg) == PARALLEL)
4369 emit_group_load (reg, x, type, -1);
4370 else
4372 gcc_assert (partial % UNITS_PER_WORD == 0);
4373 move_block_to_reg (REGNO (reg), x, partial / UNITS_PER_WORD, mode);
4377 if (extra && args_addr == 0 && where_pad == stack_direction)
4378 anti_adjust_stack (GEN_INT (extra));
4380 if (alignment_pad && args_addr == 0)
4381 anti_adjust_stack (alignment_pad);
4384 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4385 operations. */
4387 static rtx
4388 get_subtarget (rtx x)
4390 return (optimize
4391 || x == 0
4392 /* Only registers can be subtargets. */
4393 || !REG_P (x)
4394 /* Don't use hard regs to avoid extending their life. */
4395 || REGNO (x) < FIRST_PSEUDO_REGISTER
4396 ? 0 : x);
4399 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4400 FIELD is a bitfield. Returns true if the optimization was successful,
4401 and there's nothing else to do. */
4403 static bool
4404 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize,
4405 unsigned HOST_WIDE_INT bitpos,
4406 unsigned HOST_WIDE_INT bitregion_start,
4407 unsigned HOST_WIDE_INT bitregion_end,
4408 enum machine_mode mode1, rtx str_rtx,
4409 tree to, tree src)
4411 enum machine_mode str_mode = GET_MODE (str_rtx);
4412 unsigned int str_bitsize = GET_MODE_BITSIZE (str_mode);
4413 tree op0, op1;
4414 rtx value, result;
4415 optab binop;
4416 gimple srcstmt;
4417 enum tree_code code;
4419 if (mode1 != VOIDmode
4420 || bitsize >= BITS_PER_WORD
4421 || str_bitsize > BITS_PER_WORD
4422 || TREE_SIDE_EFFECTS (to)
4423 || TREE_THIS_VOLATILE (to))
4424 return false;
4426 STRIP_NOPS (src);
4427 if (TREE_CODE (src) != SSA_NAME)
4428 return false;
4429 if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
4430 return false;
4432 srcstmt = get_gimple_for_ssa_name (src);
4433 if (!srcstmt
4434 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
4435 return false;
4437 code = gimple_assign_rhs_code (srcstmt);
4439 op0 = gimple_assign_rhs1 (srcstmt);
4441 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4442 to find its initialization. Hopefully the initialization will
4443 be from a bitfield load. */
4444 if (TREE_CODE (op0) == SSA_NAME)
4446 gimple op0stmt = get_gimple_for_ssa_name (op0);
4448 /* We want to eventually have OP0 be the same as TO, which
4449 should be a bitfield. */
4450 if (!op0stmt
4451 || !is_gimple_assign (op0stmt)
4452 || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
4453 return false;
4454 op0 = gimple_assign_rhs1 (op0stmt);
4457 op1 = gimple_assign_rhs2 (srcstmt);
4459 if (!operand_equal_p (to, op0, 0))
4460 return false;
4462 if (MEM_P (str_rtx))
4464 unsigned HOST_WIDE_INT offset1;
4466 if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
4467 str_mode = word_mode;
4468 str_mode = get_best_mode (bitsize, bitpos,
4469 bitregion_start, bitregion_end,
4470 MEM_ALIGN (str_rtx), str_mode, 0);
4471 if (str_mode == VOIDmode)
4472 return false;
4473 str_bitsize = GET_MODE_BITSIZE (str_mode);
4475 offset1 = bitpos;
4476 bitpos %= str_bitsize;
4477 offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
4478 str_rtx = adjust_address (str_rtx, str_mode, offset1);
4480 else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
4481 return false;
4483 /* If the bit field covers the whole REG/MEM, store_field
4484 will likely generate better code. */
4485 if (bitsize >= str_bitsize)
4486 return false;
4488 /* We can't handle fields split across multiple entities. */
4489 if (bitpos + bitsize > str_bitsize)
4490 return false;
4492 if (BYTES_BIG_ENDIAN)
4493 bitpos = str_bitsize - bitpos - bitsize;
4495 switch (code)
4497 case PLUS_EXPR:
4498 case MINUS_EXPR:
4499 /* For now, just optimize the case of the topmost bitfield
4500 where we don't need to do any masking and also
4501 1 bit bitfields where xor can be used.
4502 We might win by one instruction for the other bitfields
4503 too if insv/extv instructions aren't used, so that
4504 can be added later. */
4505 if (bitpos + bitsize != str_bitsize
4506 && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
4507 break;
4509 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4510 value = convert_modes (str_mode,
4511 TYPE_MODE (TREE_TYPE (op1)), value,
4512 TYPE_UNSIGNED (TREE_TYPE (op1)));
4514 /* We may be accessing data outside the field, which means
4515 we can alias adjacent data. */
4516 if (MEM_P (str_rtx))
4518 str_rtx = shallow_copy_rtx (str_rtx);
4519 set_mem_alias_set (str_rtx, 0);
4520 set_mem_expr (str_rtx, 0);
4523 binop = code == PLUS_EXPR ? add_optab : sub_optab;
4524 if (bitsize == 1 && bitpos + bitsize != str_bitsize)
4526 value = expand_and (str_mode, value, const1_rtx, NULL);
4527 binop = xor_optab;
4529 value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
4530 result = expand_binop (str_mode, binop, str_rtx,
4531 value, str_rtx, 1, OPTAB_WIDEN);
4532 if (result != str_rtx)
4533 emit_move_insn (str_rtx, result);
4534 return true;
4536 case BIT_IOR_EXPR:
4537 case BIT_XOR_EXPR:
4538 if (TREE_CODE (op1) != INTEGER_CST)
4539 break;
4540 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4541 value = convert_modes (str_mode,
4542 TYPE_MODE (TREE_TYPE (op1)), value,
4543 TYPE_UNSIGNED (TREE_TYPE (op1)));
4545 /* We may be accessing data outside the field, which means
4546 we can alias adjacent data. */
4547 if (MEM_P (str_rtx))
4549 str_rtx = shallow_copy_rtx (str_rtx);
4550 set_mem_alias_set (str_rtx, 0);
4551 set_mem_expr (str_rtx, 0);
4554 binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
4555 if (bitpos + bitsize != str_bitsize)
4557 rtx mask = gen_int_mode (((unsigned HOST_WIDE_INT) 1 << bitsize) - 1,
4558 str_mode);
4559 value = expand_and (str_mode, value, mask, NULL_RTX);
4561 value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
4562 result = expand_binop (str_mode, binop, str_rtx,
4563 value, str_rtx, 1, OPTAB_WIDEN);
4564 if (result != str_rtx)
4565 emit_move_insn (str_rtx, result);
4566 return true;
4568 default:
4569 break;
4572 return false;
4575 /* In the C++ memory model, consecutive bit fields in a structure are
4576 considered one memory location.
4578 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4579 returns the bit range of consecutive bits in which this COMPONENT_REF
4580 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4581 and *OFFSET may be adjusted in the process.
4583 If the access does not need to be restricted, 0 is returned in both
4584 *BITSTART and *BITEND. */
4586 static void
4587 get_bit_range (unsigned HOST_WIDE_INT *bitstart,
4588 unsigned HOST_WIDE_INT *bitend,
4589 tree exp,
4590 HOST_WIDE_INT *bitpos,
4591 tree *offset)
4593 HOST_WIDE_INT bitoffset;
4594 tree field, repr;
4596 gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
4598 field = TREE_OPERAND (exp, 1);
4599 repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
4600 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4601 need to limit the range we can access. */
4602 if (!repr)
4604 *bitstart = *bitend = 0;
4605 return;
4608 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4609 part of a larger bit field, then the representative does not serve any
4610 useful purpose. This can occur in Ada. */
4611 if (handled_component_p (TREE_OPERAND (exp, 0)))
4613 enum machine_mode rmode;
4614 HOST_WIDE_INT rbitsize, rbitpos;
4615 tree roffset;
4616 int unsignedp;
4617 int volatilep = 0;
4618 get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
4619 &roffset, &rmode, &unsignedp, &volatilep, false);
4620 if ((rbitpos % BITS_PER_UNIT) != 0)
4622 *bitstart = *bitend = 0;
4623 return;
4627 /* Compute the adjustment to bitpos from the offset of the field
4628 relative to the representative. DECL_FIELD_OFFSET of field and
4629 repr are the same by construction if they are not constants,
4630 see finish_bitfield_layout. */
4631 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field))
4632 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr)))
4633 bitoffset = (tree_to_uhwi (DECL_FIELD_OFFSET (field))
4634 - tree_to_uhwi (DECL_FIELD_OFFSET (repr))) * BITS_PER_UNIT;
4635 else
4636 bitoffset = 0;
4637 bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
4638 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
4640 /* If the adjustment is larger than bitpos, we would have a negative bit
4641 position for the lower bound and this may wreak havoc later. Adjust
4642 offset and bitpos to make the lower bound non-negative in that case. */
4643 if (bitoffset > *bitpos)
4645 HOST_WIDE_INT adjust = bitoffset - *bitpos;
4646 gcc_assert ((adjust % BITS_PER_UNIT) == 0);
4648 *bitpos += adjust;
4649 if (*offset == NULL_TREE)
4650 *offset = size_int (-adjust / BITS_PER_UNIT);
4651 else
4652 *offset
4653 = size_binop (MINUS_EXPR, *offset, size_int (adjust / BITS_PER_UNIT));
4654 *bitstart = 0;
4656 else
4657 *bitstart = *bitpos - bitoffset;
4659 *bitend = *bitstart + tree_to_uhwi (DECL_SIZE (repr)) - 1;
4662 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4663 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4664 DECL_RTL was not set yet, return NORTL. */
4666 static inline bool
4667 addr_expr_of_non_mem_decl_p_1 (tree addr, bool nortl)
4669 if (TREE_CODE (addr) != ADDR_EXPR)
4670 return false;
4672 tree base = TREE_OPERAND (addr, 0);
4674 if (!DECL_P (base)
4675 || TREE_ADDRESSABLE (base)
4676 || DECL_MODE (base) == BLKmode)
4677 return false;
4679 if (!DECL_RTL_SET_P (base))
4680 return nortl;
4682 return (!MEM_P (DECL_RTL (base)));
4685 /* Returns true if the MEM_REF REF refers to an object that does not
4686 reside in memory and has non-BLKmode. */
4688 static inline bool
4689 mem_ref_refers_to_non_mem_p (tree ref)
4691 tree base = TREE_OPERAND (ref, 0);
4692 return addr_expr_of_non_mem_decl_p_1 (base, false);
4695 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4696 is true, try generating a nontemporal store. */
4698 void
4699 expand_assignment (tree to, tree from, bool nontemporal)
4701 rtx to_rtx = 0;
4702 rtx result;
4703 enum machine_mode mode;
4704 unsigned int align;
4705 enum insn_code icode;
4707 /* Don't crash if the lhs of the assignment was erroneous. */
4708 if (TREE_CODE (to) == ERROR_MARK)
4710 expand_normal (from);
4711 return;
4714 /* Optimize away no-op moves without side-effects. */
4715 if (operand_equal_p (to, from, 0))
4716 return;
4718 /* Handle misaligned stores. */
4719 mode = TYPE_MODE (TREE_TYPE (to));
4720 if ((TREE_CODE (to) == MEM_REF
4721 || TREE_CODE (to) == TARGET_MEM_REF)
4722 && mode != BLKmode
4723 && !mem_ref_refers_to_non_mem_p (to)
4724 && ((align = get_object_alignment (to))
4725 < GET_MODE_ALIGNMENT (mode))
4726 && (((icode = optab_handler (movmisalign_optab, mode))
4727 != CODE_FOR_nothing)
4728 || SLOW_UNALIGNED_ACCESS (mode, align)))
4730 rtx reg, mem;
4732 reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4733 reg = force_not_mem (reg);
4734 mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4736 if (icode != CODE_FOR_nothing)
4738 struct expand_operand ops[2];
4740 create_fixed_operand (&ops[0], mem);
4741 create_input_operand (&ops[1], reg, mode);
4742 /* The movmisalign<mode> pattern cannot fail, else the assignment
4743 would silently be omitted. */
4744 expand_insn (icode, 2, ops);
4746 else
4747 store_bit_field (mem, GET_MODE_BITSIZE (mode),
4748 0, 0, 0, mode, reg);
4749 return;
4752 /* Assignment of a structure component needs special treatment
4753 if the structure component's rtx is not simply a MEM.
4754 Assignment of an array element at a constant index, and assignment of
4755 an array element in an unaligned packed structure field, has the same
4756 problem. Same for (partially) storing into a non-memory object. */
4757 if (handled_component_p (to)
4758 || (TREE_CODE (to) == MEM_REF
4759 && mem_ref_refers_to_non_mem_p (to))
4760 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
4762 enum machine_mode mode1;
4763 HOST_WIDE_INT bitsize, bitpos;
4764 unsigned HOST_WIDE_INT bitregion_start = 0;
4765 unsigned HOST_WIDE_INT bitregion_end = 0;
4766 tree offset;
4767 int unsignedp;
4768 int volatilep = 0;
4769 tree tem;
4771 push_temp_slots ();
4772 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
4773 &unsignedp, &volatilep, true);
4775 /* Make sure bitpos is not negative, it can wreak havoc later. */
4776 if (bitpos < 0)
4778 gcc_assert (offset == NULL_TREE);
4779 offset = size_int (bitpos >> (BITS_PER_UNIT == 8
4780 ? 3 : exact_log2 (BITS_PER_UNIT)));
4781 bitpos &= BITS_PER_UNIT - 1;
4784 if (TREE_CODE (to) == COMPONENT_REF
4785 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
4786 get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
4788 to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
4790 /* If the bitfield is volatile, we want to access it in the
4791 field's mode, not the computed mode.
4792 If a MEM has VOIDmode (external with incomplete type),
4793 use BLKmode for it instead. */
4794 if (MEM_P (to_rtx))
4796 if (volatilep && flag_strict_volatile_bitfields > 0)
4797 to_rtx = adjust_address (to_rtx, mode1, 0);
4798 else if (GET_MODE (to_rtx) == VOIDmode)
4799 to_rtx = adjust_address (to_rtx, BLKmode, 0);
4802 if (offset != 0)
4804 enum machine_mode address_mode;
4805 rtx offset_rtx;
4807 if (!MEM_P (to_rtx))
4809 /* We can get constant negative offsets into arrays with broken
4810 user code. Translate this to a trap instead of ICEing. */
4811 gcc_assert (TREE_CODE (offset) == INTEGER_CST);
4812 expand_builtin_trap ();
4813 to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
4816 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
4817 address_mode = get_address_mode (to_rtx);
4818 if (GET_MODE (offset_rtx) != address_mode)
4819 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
4821 /* A constant address in TO_RTX can have VOIDmode, we must not try
4822 to call force_reg for that case. Avoid that case. */
4823 if (MEM_P (to_rtx)
4824 && GET_MODE (to_rtx) == BLKmode
4825 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
4826 && bitsize > 0
4827 && (bitpos % bitsize) == 0
4828 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
4829 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
4831 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
4832 bitpos = 0;
4835 to_rtx = offset_address (to_rtx, offset_rtx,
4836 highest_pow2_factor_for_target (to,
4837 offset));
4840 /* No action is needed if the target is not a memory and the field
4841 lies completely outside that target. This can occur if the source
4842 code contains an out-of-bounds access to a small array. */
4843 if (!MEM_P (to_rtx)
4844 && GET_MODE (to_rtx) != BLKmode
4845 && (unsigned HOST_WIDE_INT) bitpos
4846 >= GET_MODE_PRECISION (GET_MODE (to_rtx)))
4848 expand_normal (from);
4849 result = NULL;
4851 /* Handle expand_expr of a complex value returning a CONCAT. */
4852 else if (GET_CODE (to_rtx) == CONCAT)
4854 unsigned short mode_bitsize = GET_MODE_BITSIZE (GET_MODE (to_rtx));
4855 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from)))
4856 && bitpos == 0
4857 && bitsize == mode_bitsize)
4858 result = store_expr (from, to_rtx, false, nontemporal);
4859 else if (bitsize == mode_bitsize / 2
4860 && (bitpos == 0 || bitpos == mode_bitsize / 2))
4861 result = store_expr (from, XEXP (to_rtx, bitpos != 0), false,
4862 nontemporal);
4863 else if (bitpos + bitsize <= mode_bitsize / 2)
4864 result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
4865 bitregion_start, bitregion_end,
4866 mode1, from,
4867 get_alias_set (to), nontemporal);
4868 else if (bitpos >= mode_bitsize / 2)
4869 result = store_field (XEXP (to_rtx, 1), bitsize,
4870 bitpos - mode_bitsize / 2,
4871 bitregion_start, bitregion_end,
4872 mode1, from,
4873 get_alias_set (to), nontemporal);
4874 else if (bitpos == 0 && bitsize == mode_bitsize)
4876 rtx from_rtx;
4877 result = expand_normal (from);
4878 from_rtx = simplify_gen_subreg (GET_MODE (to_rtx), result,
4879 TYPE_MODE (TREE_TYPE (from)), 0);
4880 emit_move_insn (XEXP (to_rtx, 0),
4881 read_complex_part (from_rtx, false));
4882 emit_move_insn (XEXP (to_rtx, 1),
4883 read_complex_part (from_rtx, true));
4885 else
4887 rtx temp = assign_stack_temp (GET_MODE (to_rtx),
4888 GET_MODE_SIZE (GET_MODE (to_rtx)));
4889 write_complex_part (temp, XEXP (to_rtx, 0), false);
4890 write_complex_part (temp, XEXP (to_rtx, 1), true);
4891 result = store_field (temp, bitsize, bitpos,
4892 bitregion_start, bitregion_end,
4893 mode1, from,
4894 get_alias_set (to), nontemporal);
4895 emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
4896 emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
4899 else
4901 if (MEM_P (to_rtx))
4903 /* If the field is at offset zero, we could have been given the
4904 DECL_RTX of the parent struct. Don't munge it. */
4905 to_rtx = shallow_copy_rtx (to_rtx);
4906 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
4907 if (volatilep)
4908 MEM_VOLATILE_P (to_rtx) = 1;
4911 if (optimize_bitfield_assignment_op (bitsize, bitpos,
4912 bitregion_start, bitregion_end,
4913 mode1,
4914 to_rtx, to, from))
4915 result = NULL;
4916 else
4917 result = store_field (to_rtx, bitsize, bitpos,
4918 bitregion_start, bitregion_end,
4919 mode1, from,
4920 get_alias_set (to), nontemporal);
4923 if (result)
4924 preserve_temp_slots (result);
4925 pop_temp_slots ();
4926 return;
4929 /* If the rhs is a function call and its value is not an aggregate,
4930 call the function before we start to compute the lhs.
4931 This is needed for correct code for cases such as
4932 val = setjmp (buf) on machines where reference to val
4933 requires loading up part of an address in a separate insn.
4935 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4936 since it might be a promoted variable where the zero- or sign- extension
4937 needs to be done. Handling this in the normal way is safe because no
4938 computation is done before the call. The same is true for SSA names. */
4939 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
4940 && COMPLETE_TYPE_P (TREE_TYPE (from))
4941 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
4942 && ! (((TREE_CODE (to) == VAR_DECL
4943 || TREE_CODE (to) == PARM_DECL
4944 || TREE_CODE (to) == RESULT_DECL)
4945 && REG_P (DECL_RTL (to)))
4946 || TREE_CODE (to) == SSA_NAME))
4948 rtx value;
4950 push_temp_slots ();
4951 value = expand_normal (from);
4952 if (to_rtx == 0)
4953 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4955 /* Handle calls that return values in multiple non-contiguous locations.
4956 The Irix 6 ABI has examples of this. */
4957 if (GET_CODE (to_rtx) == PARALLEL)
4959 if (GET_CODE (value) == PARALLEL)
4960 emit_group_move (to_rtx, value);
4961 else
4962 emit_group_load (to_rtx, value, TREE_TYPE (from),
4963 int_size_in_bytes (TREE_TYPE (from)));
4965 else if (GET_CODE (value) == PARALLEL)
4966 emit_group_store (to_rtx, value, TREE_TYPE (from),
4967 int_size_in_bytes (TREE_TYPE (from)));
4968 else if (GET_MODE (to_rtx) == BLKmode)
4970 /* Handle calls that return BLKmode values in registers. */
4971 if (REG_P (value))
4972 copy_blkmode_from_reg (to_rtx, value, TREE_TYPE (from));
4973 else
4974 emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
4976 else
4978 if (POINTER_TYPE_P (TREE_TYPE (to)))
4979 value = convert_memory_address_addr_space
4980 (GET_MODE (to_rtx), value,
4981 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
4983 emit_move_insn (to_rtx, value);
4985 preserve_temp_slots (to_rtx);
4986 pop_temp_slots ();
4987 return;
4990 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4991 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4993 /* Don't move directly into a return register. */
4994 if (TREE_CODE (to) == RESULT_DECL
4995 && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
4997 rtx temp;
4999 push_temp_slots ();
5001 /* If the source is itself a return value, it still is in a pseudo at
5002 this point so we can move it back to the return register directly. */
5003 if (REG_P (to_rtx)
5004 && TYPE_MODE (TREE_TYPE (from)) == BLKmode
5005 && TREE_CODE (from) != CALL_EXPR)
5006 temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
5007 else
5008 temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
5010 /* Handle calls that return values in multiple non-contiguous locations.
5011 The Irix 6 ABI has examples of this. */
5012 if (GET_CODE (to_rtx) == PARALLEL)
5014 if (GET_CODE (temp) == PARALLEL)
5015 emit_group_move (to_rtx, temp);
5016 else
5017 emit_group_load (to_rtx, temp, TREE_TYPE (from),
5018 int_size_in_bytes (TREE_TYPE (from)));
5020 else if (temp)
5021 emit_move_insn (to_rtx, temp);
5023 preserve_temp_slots (to_rtx);
5024 pop_temp_slots ();
5025 return;
5028 /* In case we are returning the contents of an object which overlaps
5029 the place the value is being stored, use a safe function when copying
5030 a value through a pointer into a structure value return block. */
5031 if (TREE_CODE (to) == RESULT_DECL
5032 && TREE_CODE (from) == INDIRECT_REF
5033 && ADDR_SPACE_GENERIC_P
5034 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
5035 && refs_may_alias_p (to, from)
5036 && cfun->returns_struct
5037 && !cfun->returns_pcc_struct)
5039 rtx from_rtx, size;
5041 push_temp_slots ();
5042 size = expr_size (from);
5043 from_rtx = expand_normal (from);
5045 emit_library_call (memmove_libfunc, LCT_NORMAL,
5046 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
5047 XEXP (from_rtx, 0), Pmode,
5048 convert_to_mode (TYPE_MODE (sizetype),
5049 size, TYPE_UNSIGNED (sizetype)),
5050 TYPE_MODE (sizetype));
5052 preserve_temp_slots (to_rtx);
5053 pop_temp_slots ();
5054 return;
5057 /* Compute FROM and store the value in the rtx we got. */
5059 push_temp_slots ();
5060 result = store_expr (from, to_rtx, 0, nontemporal);
5061 preserve_temp_slots (result);
5062 pop_temp_slots ();
5063 return;
5066 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5067 succeeded, false otherwise. */
5069 bool
5070 emit_storent_insn (rtx to, rtx from)
5072 struct expand_operand ops[2];
5073 enum machine_mode mode = GET_MODE (to);
5074 enum insn_code code = optab_handler (storent_optab, mode);
5076 if (code == CODE_FOR_nothing)
5077 return false;
5079 create_fixed_operand (&ops[0], to);
5080 create_input_operand (&ops[1], from, mode);
5081 return maybe_expand_insn (code, 2, ops);
5084 /* Generate code for computing expression EXP,
5085 and storing the value into TARGET.
5087 If the mode is BLKmode then we may return TARGET itself.
5088 It turns out that in BLKmode it doesn't cause a problem.
5089 because C has no operators that could combine two different
5090 assignments into the same BLKmode object with different values
5091 with no sequence point. Will other languages need this to
5092 be more thorough?
5094 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5095 stack, and block moves may need to be treated specially.
5097 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5100 store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
5102 rtx temp;
5103 rtx alt_rtl = NULL_RTX;
5104 location_t loc = curr_insn_location ();
5106 if (VOID_TYPE_P (TREE_TYPE (exp)))
5108 /* C++ can generate ?: expressions with a throw expression in one
5109 branch and an rvalue in the other. Here, we resolve attempts to
5110 store the throw expression's nonexistent result. */
5111 gcc_assert (!call_param_p);
5112 expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
5113 return NULL_RTX;
5115 if (TREE_CODE (exp) == COMPOUND_EXPR)
5117 /* Perform first part of compound expression, then assign from second
5118 part. */
5119 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
5120 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5121 return store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
5122 nontemporal);
5124 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
5126 /* For conditional expression, get safe form of the target. Then
5127 test the condition, doing the appropriate assignment on either
5128 side. This avoids the creation of unnecessary temporaries.
5129 For non-BLKmode, it is more efficient not to do this. */
5131 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
5133 do_pending_stack_adjust ();
5134 NO_DEFER_POP;
5135 jumpifnot (TREE_OPERAND (exp, 0), lab1, -1);
5136 store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
5137 nontemporal);
5138 emit_jump_insn (gen_jump (lab2));
5139 emit_barrier ();
5140 emit_label (lab1);
5141 store_expr (TREE_OPERAND (exp, 2), target, call_param_p,
5142 nontemporal);
5143 emit_label (lab2);
5144 OK_DEFER_POP;
5146 return NULL_RTX;
5148 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
5149 /* If this is a scalar in a register that is stored in a wider mode
5150 than the declared mode, compute the result into its declared mode
5151 and then convert to the wider mode. Our value is the computed
5152 expression. */
5154 rtx inner_target = 0;
5156 /* We can do the conversion inside EXP, which will often result
5157 in some optimizations. Do the conversion in two steps: first
5158 change the signedness, if needed, then the extend. But don't
5159 do this if the type of EXP is a subtype of something else
5160 since then the conversion might involve more than just
5161 converting modes. */
5162 if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
5163 && TREE_TYPE (TREE_TYPE (exp)) == 0
5164 && GET_MODE_PRECISION (GET_MODE (target))
5165 == TYPE_PRECISION (TREE_TYPE (exp)))
5167 if (TYPE_UNSIGNED (TREE_TYPE (exp))
5168 != SUBREG_PROMOTED_UNSIGNED_P (target))
5170 /* Some types, e.g. Fortran's logical*4, won't have a signed
5171 version, so use the mode instead. */
5172 tree ntype
5173 = (signed_or_unsigned_type_for
5174 (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)));
5175 if (ntype == NULL)
5176 ntype = lang_hooks.types.type_for_mode
5177 (TYPE_MODE (TREE_TYPE (exp)),
5178 SUBREG_PROMOTED_UNSIGNED_P (target));
5180 exp = fold_convert_loc (loc, ntype, exp);
5183 exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
5184 (GET_MODE (SUBREG_REG (target)),
5185 SUBREG_PROMOTED_UNSIGNED_P (target)),
5186 exp);
5188 inner_target = SUBREG_REG (target);
5191 temp = expand_expr (exp, inner_target, VOIDmode,
5192 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5194 /* If TEMP is a VOIDmode constant, use convert_modes to make
5195 sure that we properly convert it. */
5196 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
5198 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5199 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
5200 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
5201 GET_MODE (target), temp,
5202 SUBREG_PROMOTED_UNSIGNED_P (target));
5205 convert_move (SUBREG_REG (target), temp,
5206 SUBREG_PROMOTED_UNSIGNED_P (target));
5208 return NULL_RTX;
5210 else if ((TREE_CODE (exp) == STRING_CST
5211 || (TREE_CODE (exp) == MEM_REF
5212 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
5213 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
5214 == STRING_CST
5215 && integer_zerop (TREE_OPERAND (exp, 1))))
5216 && !nontemporal && !call_param_p
5217 && MEM_P (target))
5219 /* Optimize initialization of an array with a STRING_CST. */
5220 HOST_WIDE_INT exp_len, str_copy_len;
5221 rtx dest_mem;
5222 tree str = TREE_CODE (exp) == STRING_CST
5223 ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5225 exp_len = int_expr_size (exp);
5226 if (exp_len <= 0)
5227 goto normal_expr;
5229 if (TREE_STRING_LENGTH (str) <= 0)
5230 goto normal_expr;
5232 str_copy_len = strlen (TREE_STRING_POINTER (str));
5233 if (str_copy_len < TREE_STRING_LENGTH (str) - 1)
5234 goto normal_expr;
5236 str_copy_len = TREE_STRING_LENGTH (str);
5237 if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0
5238 && TREE_STRING_POINTER (str)[TREE_STRING_LENGTH (str) - 1] == '\0')
5240 str_copy_len += STORE_MAX_PIECES - 1;
5241 str_copy_len &= ~(STORE_MAX_PIECES - 1);
5243 str_copy_len = MIN (str_copy_len, exp_len);
5244 if (!can_store_by_pieces (str_copy_len, builtin_strncpy_read_str,
5245 CONST_CAST (char *, TREE_STRING_POINTER (str)),
5246 MEM_ALIGN (target), false))
5247 goto normal_expr;
5249 dest_mem = target;
5251 dest_mem = store_by_pieces (dest_mem,
5252 str_copy_len, builtin_strncpy_read_str,
5253 CONST_CAST (char *,
5254 TREE_STRING_POINTER (str)),
5255 MEM_ALIGN (target), false,
5256 exp_len > str_copy_len ? 1 : 0);
5257 if (exp_len > str_copy_len)
5258 clear_storage (adjust_address (dest_mem, BLKmode, 0),
5259 GEN_INT (exp_len - str_copy_len),
5260 BLOCK_OP_NORMAL);
5261 return NULL_RTX;
5263 else
5265 rtx tmp_target;
5267 normal_expr:
5268 /* If we want to use a nontemporal store, force the value to
5269 register first. */
5270 tmp_target = nontemporal ? NULL_RTX : target;
5271 temp = expand_expr_real (exp, tmp_target, GET_MODE (target),
5272 (call_param_p
5273 ? EXPAND_STACK_PARM : EXPAND_NORMAL),
5274 &alt_rtl);
5277 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5278 the same as that of TARGET, adjust the constant. This is needed, for
5279 example, in case it is a CONST_DOUBLE and we want only a word-sized
5280 value. */
5281 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
5282 && TREE_CODE (exp) != ERROR_MARK
5283 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
5284 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5285 temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5287 /* If value was not generated in the target, store it there.
5288 Convert the value to TARGET's type first if necessary and emit the
5289 pending incrementations that have been queued when expanding EXP.
5290 Note that we cannot emit the whole queue blindly because this will
5291 effectively disable the POST_INC optimization later.
5293 If TEMP and TARGET compare equal according to rtx_equal_p, but
5294 one or both of them are volatile memory refs, we have to distinguish
5295 two cases:
5296 - expand_expr has used TARGET. In this case, we must not generate
5297 another copy. This can be detected by TARGET being equal according
5298 to == .
5299 - expand_expr has not used TARGET - that means that the source just
5300 happens to have the same RTX form. Since temp will have been created
5301 by expand_expr, it will compare unequal according to == .
5302 We must generate a copy in this case, to reach the correct number
5303 of volatile memory references. */
5305 if ((! rtx_equal_p (temp, target)
5306 || (temp != target && (side_effects_p (temp)
5307 || side_effects_p (target))))
5308 && TREE_CODE (exp) != ERROR_MARK
5309 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5310 but TARGET is not valid memory reference, TEMP will differ
5311 from TARGET although it is really the same location. */
5312 && !(alt_rtl
5313 && rtx_equal_p (alt_rtl, target)
5314 && !side_effects_p (alt_rtl)
5315 && !side_effects_p (target))
5316 /* If there's nothing to copy, don't bother. Don't call
5317 expr_size unless necessary, because some front-ends (C++)
5318 expr_size-hook must not be given objects that are not
5319 supposed to be bit-copied or bit-initialized. */
5320 && expr_size (exp) != const0_rtx)
5322 if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
5324 if (GET_MODE (target) == BLKmode)
5326 /* Handle calls that return BLKmode values in registers. */
5327 if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
5328 copy_blkmode_from_reg (target, temp, TREE_TYPE (exp));
5329 else
5330 store_bit_field (target,
5331 INTVAL (expr_size (exp)) * BITS_PER_UNIT,
5332 0, 0, 0, GET_MODE (temp), temp);
5334 else
5335 convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5338 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
5340 /* Handle copying a string constant into an array. The string
5341 constant may be shorter than the array. So copy just the string's
5342 actual length, and clear the rest. First get the size of the data
5343 type of the string, which is actually the size of the target. */
5344 rtx size = expr_size (exp);
5346 if (CONST_INT_P (size)
5347 && INTVAL (size) < TREE_STRING_LENGTH (exp))
5348 emit_block_move (target, temp, size,
5349 (call_param_p
5350 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5351 else
5353 enum machine_mode pointer_mode
5354 = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
5355 enum machine_mode address_mode = get_address_mode (target);
5357 /* Compute the size of the data to copy from the string. */
5358 tree copy_size
5359 = size_binop_loc (loc, MIN_EXPR,
5360 make_tree (sizetype, size),
5361 size_int (TREE_STRING_LENGTH (exp)));
5362 rtx copy_size_rtx
5363 = expand_expr (copy_size, NULL_RTX, VOIDmode,
5364 (call_param_p
5365 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
5366 rtx label = 0;
5368 /* Copy that much. */
5369 copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
5370 TYPE_UNSIGNED (sizetype));
5371 emit_block_move (target, temp, copy_size_rtx,
5372 (call_param_p
5373 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5375 /* Figure out how much is left in TARGET that we have to clear.
5376 Do all calculations in pointer_mode. */
5377 if (CONST_INT_P (copy_size_rtx))
5379 size = plus_constant (address_mode, size,
5380 -INTVAL (copy_size_rtx));
5381 target = adjust_address (target, BLKmode,
5382 INTVAL (copy_size_rtx));
5384 else
5386 size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
5387 copy_size_rtx, NULL_RTX, 0,
5388 OPTAB_LIB_WIDEN);
5390 if (GET_MODE (copy_size_rtx) != address_mode)
5391 copy_size_rtx = convert_to_mode (address_mode,
5392 copy_size_rtx,
5393 TYPE_UNSIGNED (sizetype));
5395 target = offset_address (target, copy_size_rtx,
5396 highest_pow2_factor (copy_size));
5397 label = gen_label_rtx ();
5398 emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
5399 GET_MODE (size), 0, label);
5402 if (size != const0_rtx)
5403 clear_storage (target, size, BLOCK_OP_NORMAL);
5405 if (label)
5406 emit_label (label);
5409 /* Handle calls that return values in multiple non-contiguous locations.
5410 The Irix 6 ABI has examples of this. */
5411 else if (GET_CODE (target) == PARALLEL)
5413 if (GET_CODE (temp) == PARALLEL)
5414 emit_group_move (target, temp);
5415 else
5416 emit_group_load (target, temp, TREE_TYPE (exp),
5417 int_size_in_bytes (TREE_TYPE (exp)));
5419 else if (GET_CODE (temp) == PARALLEL)
5420 emit_group_store (target, temp, TREE_TYPE (exp),
5421 int_size_in_bytes (TREE_TYPE (exp)));
5422 else if (GET_MODE (temp) == BLKmode)
5423 emit_block_move (target, temp, expr_size (exp),
5424 (call_param_p
5425 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5426 /* If we emit a nontemporal store, there is nothing else to do. */
5427 else if (nontemporal && emit_storent_insn (target, temp))
5429 else
5431 temp = force_operand (temp, target);
5432 if (temp != target)
5433 emit_move_insn (target, temp);
5437 return NULL_RTX;
5440 /* Return true if field F of structure TYPE is a flexible array. */
5442 static bool
5443 flexible_array_member_p (const_tree f, const_tree type)
5445 const_tree tf;
5447 tf = TREE_TYPE (f);
5448 return (DECL_CHAIN (f) == NULL
5449 && TREE_CODE (tf) == ARRAY_TYPE
5450 && TYPE_DOMAIN (tf)
5451 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
5452 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
5453 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
5454 && int_size_in_bytes (type) >= 0);
5457 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5458 must have in order for it to completely initialize a value of type TYPE.
5459 Return -1 if the number isn't known.
5461 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5463 static HOST_WIDE_INT
5464 count_type_elements (const_tree type, bool for_ctor_p)
5466 switch (TREE_CODE (type))
5468 case ARRAY_TYPE:
5470 tree nelts;
5472 nelts = array_type_nelts (type);
5473 if (nelts && tree_fits_uhwi_p (nelts))
5475 unsigned HOST_WIDE_INT n;
5477 n = tree_to_uhwi (nelts) + 1;
5478 if (n == 0 || for_ctor_p)
5479 return n;
5480 else
5481 return n * count_type_elements (TREE_TYPE (type), false);
5483 return for_ctor_p ? -1 : 1;
5486 case RECORD_TYPE:
5488 unsigned HOST_WIDE_INT n;
5489 tree f;
5491 n = 0;
5492 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5493 if (TREE_CODE (f) == FIELD_DECL)
5495 if (!for_ctor_p)
5496 n += count_type_elements (TREE_TYPE (f), false);
5497 else if (!flexible_array_member_p (f, type))
5498 /* Don't count flexible arrays, which are not supposed
5499 to be initialized. */
5500 n += 1;
5503 return n;
5506 case UNION_TYPE:
5507 case QUAL_UNION_TYPE:
5509 tree f;
5510 HOST_WIDE_INT n, m;
5512 gcc_assert (!for_ctor_p);
5513 /* Estimate the number of scalars in each field and pick the
5514 maximum. Other estimates would do instead; the idea is simply
5515 to make sure that the estimate is not sensitive to the ordering
5516 of the fields. */
5517 n = 1;
5518 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5519 if (TREE_CODE (f) == FIELD_DECL)
5521 m = count_type_elements (TREE_TYPE (f), false);
5522 /* If the field doesn't span the whole union, add an extra
5523 scalar for the rest. */
5524 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
5525 TYPE_SIZE (type)) != 1)
5526 m++;
5527 if (n < m)
5528 n = m;
5530 return n;
5533 case COMPLEX_TYPE:
5534 return 2;
5536 case VECTOR_TYPE:
5537 return TYPE_VECTOR_SUBPARTS (type);
5539 case INTEGER_TYPE:
5540 case REAL_TYPE:
5541 case FIXED_POINT_TYPE:
5542 case ENUMERAL_TYPE:
5543 case BOOLEAN_TYPE:
5544 case POINTER_TYPE:
5545 case OFFSET_TYPE:
5546 case REFERENCE_TYPE:
5547 case NULLPTR_TYPE:
5548 return 1;
5550 case ERROR_MARK:
5551 return 0;
5553 case VOID_TYPE:
5554 case METHOD_TYPE:
5555 case FUNCTION_TYPE:
5556 case LANG_TYPE:
5557 default:
5558 gcc_unreachable ();
5562 /* Helper for categorize_ctor_elements. Identical interface. */
5564 static bool
5565 categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5566 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5568 unsigned HOST_WIDE_INT idx;
5569 HOST_WIDE_INT nz_elts, init_elts, num_fields;
5570 tree value, purpose, elt_type;
5572 /* Whether CTOR is a valid constant initializer, in accordance with what
5573 initializer_constant_valid_p does. If inferred from the constructor
5574 elements, true until proven otherwise. */
5575 bool const_from_elts_p = constructor_static_from_elts_p (ctor);
5576 bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
5578 nz_elts = 0;
5579 init_elts = 0;
5580 num_fields = 0;
5581 elt_type = NULL_TREE;
5583 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
5585 HOST_WIDE_INT mult = 1;
5587 if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
5589 tree lo_index = TREE_OPERAND (purpose, 0);
5590 tree hi_index = TREE_OPERAND (purpose, 1);
5592 if (tree_fits_uhwi_p (lo_index) && tree_fits_uhwi_p (hi_index))
5593 mult = (tree_to_uhwi (hi_index)
5594 - tree_to_uhwi (lo_index) + 1);
5596 num_fields += mult;
5597 elt_type = TREE_TYPE (value);
5599 switch (TREE_CODE (value))
5601 case CONSTRUCTOR:
5603 HOST_WIDE_INT nz = 0, ic = 0;
5605 bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &ic,
5606 p_complete);
5608 nz_elts += mult * nz;
5609 init_elts += mult * ic;
5611 if (const_from_elts_p && const_p)
5612 const_p = const_elt_p;
5614 break;
5616 case INTEGER_CST:
5617 case REAL_CST:
5618 case FIXED_CST:
5619 if (!initializer_zerop (value))
5620 nz_elts += mult;
5621 init_elts += mult;
5622 break;
5624 case STRING_CST:
5625 nz_elts += mult * TREE_STRING_LENGTH (value);
5626 init_elts += mult * TREE_STRING_LENGTH (value);
5627 break;
5629 case COMPLEX_CST:
5630 if (!initializer_zerop (TREE_REALPART (value)))
5631 nz_elts += mult;
5632 if (!initializer_zerop (TREE_IMAGPART (value)))
5633 nz_elts += mult;
5634 init_elts += mult;
5635 break;
5637 case VECTOR_CST:
5639 unsigned i;
5640 for (i = 0; i < VECTOR_CST_NELTS (value); ++i)
5642 tree v = VECTOR_CST_ELT (value, i);
5643 if (!initializer_zerop (v))
5644 nz_elts += mult;
5645 init_elts += mult;
5648 break;
5650 default:
5652 HOST_WIDE_INT tc = count_type_elements (elt_type, false);
5653 nz_elts += mult * tc;
5654 init_elts += mult * tc;
5656 if (const_from_elts_p && const_p)
5657 const_p = initializer_constant_valid_p (value, elt_type)
5658 != NULL_TREE;
5660 break;
5664 if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
5665 num_fields, elt_type))
5666 *p_complete = false;
5668 *p_nz_elts += nz_elts;
5669 *p_init_elts += init_elts;
5671 return const_p;
5674 /* Examine CTOR to discover:
5675 * how many scalar fields are set to nonzero values,
5676 and place it in *P_NZ_ELTS;
5677 * how many scalar fields in total are in CTOR,
5678 and place it in *P_ELT_COUNT.
5679 * whether the constructor is complete -- in the sense that every
5680 meaningful byte is explicitly given a value --
5681 and place it in *P_COMPLETE.
5683 Return whether or not CTOR is a valid static constant initializer, the same
5684 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5686 bool
5687 categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5688 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5690 *p_nz_elts = 0;
5691 *p_init_elts = 0;
5692 *p_complete = true;
5694 return categorize_ctor_elements_1 (ctor, p_nz_elts, p_init_elts, p_complete);
5697 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5698 of which had type LAST_TYPE. Each element was itself a complete
5699 initializer, in the sense that every meaningful byte was explicitly
5700 given a value. Return true if the same is true for the constructor
5701 as a whole. */
5703 bool
5704 complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
5705 const_tree last_type)
5707 if (TREE_CODE (type) == UNION_TYPE
5708 || TREE_CODE (type) == QUAL_UNION_TYPE)
5710 if (num_elts == 0)
5711 return false;
5713 gcc_assert (num_elts == 1 && last_type);
5715 /* ??? We could look at each element of the union, and find the
5716 largest element. Which would avoid comparing the size of the
5717 initialized element against any tail padding in the union.
5718 Doesn't seem worth the effort... */
5719 return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
5722 return count_type_elements (type, true) == num_elts;
5725 /* Return 1 if EXP contains mostly (3/4) zeros. */
5727 static int
5728 mostly_zeros_p (const_tree exp)
5730 if (TREE_CODE (exp) == CONSTRUCTOR)
5732 HOST_WIDE_INT nz_elts, init_elts;
5733 bool complete_p;
5735 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5736 return !complete_p || nz_elts < init_elts / 4;
5739 return initializer_zerop (exp);
5742 /* Return 1 if EXP contains all zeros. */
5744 static int
5745 all_zeros_p (const_tree exp)
5747 if (TREE_CODE (exp) == CONSTRUCTOR)
5749 HOST_WIDE_INT nz_elts, init_elts;
5750 bool complete_p;
5752 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5753 return nz_elts == 0;
5756 return initializer_zerop (exp);
5759 /* Helper function for store_constructor.
5760 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5761 CLEARED is as for store_constructor.
5762 ALIAS_SET is the alias set to use for any stores.
5764 This provides a recursive shortcut back to store_constructor when it isn't
5765 necessary to go through store_field. This is so that we can pass through
5766 the cleared field to let store_constructor know that we may not have to
5767 clear a substructure if the outer structure has already been cleared. */
5769 static void
5770 store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
5771 HOST_WIDE_INT bitpos, enum machine_mode mode,
5772 tree exp, int cleared, alias_set_type alias_set)
5774 if (TREE_CODE (exp) == CONSTRUCTOR
5775 /* We can only call store_constructor recursively if the size and
5776 bit position are on a byte boundary. */
5777 && bitpos % BITS_PER_UNIT == 0
5778 && (bitsize > 0 && bitsize % BITS_PER_UNIT == 0)
5779 /* If we have a nonzero bitpos for a register target, then we just
5780 let store_field do the bitfield handling. This is unlikely to
5781 generate unnecessary clear instructions anyways. */
5782 && (bitpos == 0 || MEM_P (target)))
5784 if (MEM_P (target))
5785 target
5786 = adjust_address (target,
5787 GET_MODE (target) == BLKmode
5788 || 0 != (bitpos
5789 % GET_MODE_ALIGNMENT (GET_MODE (target)))
5790 ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
5793 /* Update the alias set, if required. */
5794 if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
5795 && MEM_ALIAS_SET (target) != 0)
5797 target = copy_rtx (target);
5798 set_mem_alias_set (target, alias_set);
5801 store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
5803 else
5804 store_field (target, bitsize, bitpos, 0, 0, mode, exp, alias_set, false);
5808 /* Returns the number of FIELD_DECLs in TYPE. */
5810 static int
5811 fields_length (const_tree type)
5813 tree t = TYPE_FIELDS (type);
5814 int count = 0;
5816 for (; t; t = DECL_CHAIN (t))
5817 if (TREE_CODE (t) == FIELD_DECL)
5818 ++count;
5820 return count;
5824 /* Store the value of constructor EXP into the rtx TARGET.
5825 TARGET is either a REG or a MEM; we know it cannot conflict, since
5826 safe_from_p has been called.
5827 CLEARED is true if TARGET is known to have been zero'd.
5828 SIZE is the number of bytes of TARGET we are allowed to modify: this
5829 may not be the same as the size of EXP if we are assigning to a field
5830 which has been packed to exclude padding bits. */
5832 static void
5833 store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
5835 tree type = TREE_TYPE (exp);
5836 #ifdef WORD_REGISTER_OPERATIONS
5837 HOST_WIDE_INT exp_size = int_size_in_bytes (type);
5838 #endif
5840 switch (TREE_CODE (type))
5842 case RECORD_TYPE:
5843 case UNION_TYPE:
5844 case QUAL_UNION_TYPE:
5846 unsigned HOST_WIDE_INT idx;
5847 tree field, value;
5849 /* If size is zero or the target is already cleared, do nothing. */
5850 if (size == 0 || cleared)
5851 cleared = 1;
5852 /* We either clear the aggregate or indicate the value is dead. */
5853 else if ((TREE_CODE (type) == UNION_TYPE
5854 || TREE_CODE (type) == QUAL_UNION_TYPE)
5855 && ! CONSTRUCTOR_ELTS (exp))
5856 /* If the constructor is empty, clear the union. */
5858 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
5859 cleared = 1;
5862 /* If we are building a static constructor into a register,
5863 set the initial value as zero so we can fold the value into
5864 a constant. But if more than one register is involved,
5865 this probably loses. */
5866 else if (REG_P (target) && TREE_STATIC (exp)
5867 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
5869 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5870 cleared = 1;
5873 /* If the constructor has fewer fields than the structure or
5874 if we are initializing the structure to mostly zeros, clear
5875 the whole structure first. Don't do this if TARGET is a
5876 register whose mode size isn't equal to SIZE since
5877 clear_storage can't handle this case. */
5878 else if (size > 0
5879 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp))
5880 != fields_length (type))
5881 || mostly_zeros_p (exp))
5882 && (!REG_P (target)
5883 || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
5884 == size)))
5886 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5887 cleared = 1;
5890 if (REG_P (target) && !cleared)
5891 emit_clobber (target);
5893 /* Store each element of the constructor into the
5894 corresponding field of TARGET. */
5895 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
5897 enum machine_mode mode;
5898 HOST_WIDE_INT bitsize;
5899 HOST_WIDE_INT bitpos = 0;
5900 tree offset;
5901 rtx to_rtx = target;
5903 /* Just ignore missing fields. We cleared the whole
5904 structure, above, if any fields are missing. */
5905 if (field == 0)
5906 continue;
5908 if (cleared && initializer_zerop (value))
5909 continue;
5911 if (tree_fits_uhwi_p (DECL_SIZE (field)))
5912 bitsize = tree_to_uhwi (DECL_SIZE (field));
5913 else
5914 bitsize = -1;
5916 mode = DECL_MODE (field);
5917 if (DECL_BIT_FIELD (field))
5918 mode = VOIDmode;
5920 offset = DECL_FIELD_OFFSET (field);
5921 if (tree_fits_shwi_p (offset)
5922 && tree_fits_shwi_p (bit_position (field)))
5924 bitpos = int_bit_position (field);
5925 offset = 0;
5927 else
5928 bitpos = tree_to_shwi (DECL_FIELD_BIT_OFFSET (field));
5930 if (offset)
5932 enum machine_mode address_mode;
5933 rtx offset_rtx;
5935 offset
5936 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
5937 make_tree (TREE_TYPE (exp),
5938 target));
5940 offset_rtx = expand_normal (offset);
5941 gcc_assert (MEM_P (to_rtx));
5943 address_mode = get_address_mode (to_rtx);
5944 if (GET_MODE (offset_rtx) != address_mode)
5945 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
5947 to_rtx = offset_address (to_rtx, offset_rtx,
5948 highest_pow2_factor (offset));
5951 #ifdef WORD_REGISTER_OPERATIONS
5952 /* If this initializes a field that is smaller than a
5953 word, at the start of a word, try to widen it to a full
5954 word. This special case allows us to output C++ member
5955 function initializations in a form that the optimizers
5956 can understand. */
5957 if (REG_P (target)
5958 && bitsize < BITS_PER_WORD
5959 && bitpos % BITS_PER_WORD == 0
5960 && GET_MODE_CLASS (mode) == MODE_INT
5961 && TREE_CODE (value) == INTEGER_CST
5962 && exp_size >= 0
5963 && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
5965 tree type = TREE_TYPE (value);
5967 if (TYPE_PRECISION (type) < BITS_PER_WORD)
5969 type = lang_hooks.types.type_for_mode
5970 (word_mode, TYPE_UNSIGNED (type));
5971 value = fold_convert (type, value);
5974 if (BYTES_BIG_ENDIAN)
5975 value
5976 = fold_build2 (LSHIFT_EXPR, type, value,
5977 build_int_cst (type,
5978 BITS_PER_WORD - bitsize));
5979 bitsize = BITS_PER_WORD;
5980 mode = word_mode;
5982 #endif
5984 if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
5985 && DECL_NONADDRESSABLE_P (field))
5987 to_rtx = copy_rtx (to_rtx);
5988 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
5991 store_constructor_field (to_rtx, bitsize, bitpos, mode,
5992 value, cleared,
5993 get_alias_set (TREE_TYPE (field)));
5995 break;
5997 case ARRAY_TYPE:
5999 tree value, index;
6000 unsigned HOST_WIDE_INT i;
6001 int need_to_clear;
6002 tree domain;
6003 tree elttype = TREE_TYPE (type);
6004 int const_bounds_p;
6005 HOST_WIDE_INT minelt = 0;
6006 HOST_WIDE_INT maxelt = 0;
6008 domain = TYPE_DOMAIN (type);
6009 const_bounds_p = (TYPE_MIN_VALUE (domain)
6010 && TYPE_MAX_VALUE (domain)
6011 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain))
6012 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain)));
6014 /* If we have constant bounds for the range of the type, get them. */
6015 if (const_bounds_p)
6017 minelt = tree_to_shwi (TYPE_MIN_VALUE (domain));
6018 maxelt = tree_to_shwi (TYPE_MAX_VALUE (domain));
6021 /* If the constructor has fewer elements than the array, clear
6022 the whole array first. Similarly if this is static
6023 constructor of a non-BLKmode object. */
6024 if (cleared)
6025 need_to_clear = 0;
6026 else if (REG_P (target) && TREE_STATIC (exp))
6027 need_to_clear = 1;
6028 else
6030 unsigned HOST_WIDE_INT idx;
6031 tree index, value;
6032 HOST_WIDE_INT count = 0, zero_count = 0;
6033 need_to_clear = ! const_bounds_p;
6035 /* This loop is a more accurate version of the loop in
6036 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6037 is also needed to check for missing elements. */
6038 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
6040 HOST_WIDE_INT this_node_count;
6042 if (need_to_clear)
6043 break;
6045 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
6047 tree lo_index = TREE_OPERAND (index, 0);
6048 tree hi_index = TREE_OPERAND (index, 1);
6050 if (! tree_fits_uhwi_p (lo_index)
6051 || ! tree_fits_uhwi_p (hi_index))
6053 need_to_clear = 1;
6054 break;
6057 this_node_count = (tree_to_uhwi (hi_index)
6058 - tree_to_uhwi (lo_index) + 1);
6060 else
6061 this_node_count = 1;
6063 count += this_node_count;
6064 if (mostly_zeros_p (value))
6065 zero_count += this_node_count;
6068 /* Clear the entire array first if there are any missing
6069 elements, or if the incidence of zero elements is >=
6070 75%. */
6071 if (! need_to_clear
6072 && (count < maxelt - minelt + 1
6073 || 4 * zero_count >= 3 * count))
6074 need_to_clear = 1;
6077 if (need_to_clear && size > 0)
6079 if (REG_P (target))
6080 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6081 else
6082 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6083 cleared = 1;
6086 if (!cleared && REG_P (target))
6087 /* Inform later passes that the old value is dead. */
6088 emit_clobber (target);
6090 /* Store each element of the constructor into the
6091 corresponding element of TARGET, determined by counting the
6092 elements. */
6093 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
6095 enum machine_mode mode;
6096 HOST_WIDE_INT bitsize;
6097 HOST_WIDE_INT bitpos;
6098 rtx xtarget = target;
6100 if (cleared && initializer_zerop (value))
6101 continue;
6103 mode = TYPE_MODE (elttype);
6104 if (mode == BLKmode)
6105 bitsize = (tree_fits_uhwi_p (TYPE_SIZE (elttype))
6106 ? tree_to_uhwi (TYPE_SIZE (elttype))
6107 : -1);
6108 else
6109 bitsize = GET_MODE_BITSIZE (mode);
6111 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
6113 tree lo_index = TREE_OPERAND (index, 0);
6114 tree hi_index = TREE_OPERAND (index, 1);
6115 rtx index_r, pos_rtx;
6116 HOST_WIDE_INT lo, hi, count;
6117 tree position;
6119 /* If the range is constant and "small", unroll the loop. */
6120 if (const_bounds_p
6121 && tree_fits_shwi_p (lo_index)
6122 && tree_fits_shwi_p (hi_index)
6123 && (lo = tree_to_shwi (lo_index),
6124 hi = tree_to_shwi (hi_index),
6125 count = hi - lo + 1,
6126 (!MEM_P (target)
6127 || count <= 2
6128 || (tree_fits_uhwi_p (TYPE_SIZE (elttype))
6129 && (tree_to_uhwi (TYPE_SIZE (elttype)) * count
6130 <= 40 * 8)))))
6132 lo -= minelt; hi -= minelt;
6133 for (; lo <= hi; lo++)
6135 bitpos = lo * tree_to_shwi (TYPE_SIZE (elttype));
6137 if (MEM_P (target)
6138 && !MEM_KEEP_ALIAS_SET_P (target)
6139 && TREE_CODE (type) == ARRAY_TYPE
6140 && TYPE_NONALIASED_COMPONENT (type))
6142 target = copy_rtx (target);
6143 MEM_KEEP_ALIAS_SET_P (target) = 1;
6146 store_constructor_field
6147 (target, bitsize, bitpos, mode, value, cleared,
6148 get_alias_set (elttype));
6151 else
6153 rtx loop_start = gen_label_rtx ();
6154 rtx loop_end = gen_label_rtx ();
6155 tree exit_cond;
6157 expand_normal (hi_index);
6159 index = build_decl (EXPR_LOCATION (exp),
6160 VAR_DECL, NULL_TREE, domain);
6161 index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
6162 SET_DECL_RTL (index, index_r);
6163 store_expr (lo_index, index_r, 0, false);
6165 /* Build the head of the loop. */
6166 do_pending_stack_adjust ();
6167 emit_label (loop_start);
6169 /* Assign value to element index. */
6170 position =
6171 fold_convert (ssizetype,
6172 fold_build2 (MINUS_EXPR,
6173 TREE_TYPE (index),
6174 index,
6175 TYPE_MIN_VALUE (domain)));
6177 position =
6178 size_binop (MULT_EXPR, position,
6179 fold_convert (ssizetype,
6180 TYPE_SIZE_UNIT (elttype)));
6182 pos_rtx = expand_normal (position);
6183 xtarget = offset_address (target, pos_rtx,
6184 highest_pow2_factor (position));
6185 xtarget = adjust_address (xtarget, mode, 0);
6186 if (TREE_CODE (value) == CONSTRUCTOR)
6187 store_constructor (value, xtarget, cleared,
6188 bitsize / BITS_PER_UNIT);
6189 else
6190 store_expr (value, xtarget, 0, false);
6192 /* Generate a conditional jump to exit the loop. */
6193 exit_cond = build2 (LT_EXPR, integer_type_node,
6194 index, hi_index);
6195 jumpif (exit_cond, loop_end, -1);
6197 /* Update the loop counter, and jump to the head of
6198 the loop. */
6199 expand_assignment (index,
6200 build2 (PLUS_EXPR, TREE_TYPE (index),
6201 index, integer_one_node),
6202 false);
6204 emit_jump (loop_start);
6206 /* Build the end of the loop. */
6207 emit_label (loop_end);
6210 else if ((index != 0 && ! tree_fits_shwi_p (index))
6211 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype)))
6213 tree position;
6215 if (index == 0)
6216 index = ssize_int (1);
6218 if (minelt)
6219 index = fold_convert (ssizetype,
6220 fold_build2 (MINUS_EXPR,
6221 TREE_TYPE (index),
6222 index,
6223 TYPE_MIN_VALUE (domain)));
6225 position =
6226 size_binop (MULT_EXPR, index,
6227 fold_convert (ssizetype,
6228 TYPE_SIZE_UNIT (elttype)));
6229 xtarget = offset_address (target,
6230 expand_normal (position),
6231 highest_pow2_factor (position));
6232 xtarget = adjust_address (xtarget, mode, 0);
6233 store_expr (value, xtarget, 0, false);
6235 else
6237 if (index != 0)
6238 bitpos = ((tree_to_shwi (index) - minelt)
6239 * tree_to_uhwi (TYPE_SIZE (elttype)));
6240 else
6241 bitpos = (i * tree_to_uhwi (TYPE_SIZE (elttype)));
6243 if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
6244 && TREE_CODE (type) == ARRAY_TYPE
6245 && TYPE_NONALIASED_COMPONENT (type))
6247 target = copy_rtx (target);
6248 MEM_KEEP_ALIAS_SET_P (target) = 1;
6250 store_constructor_field (target, bitsize, bitpos, mode, value,
6251 cleared, get_alias_set (elttype));
6254 break;
6257 case VECTOR_TYPE:
6259 unsigned HOST_WIDE_INT idx;
6260 constructor_elt *ce;
6261 int i;
6262 int need_to_clear;
6263 int icode = CODE_FOR_nothing;
6264 tree elttype = TREE_TYPE (type);
6265 int elt_size = tree_to_uhwi (TYPE_SIZE (elttype));
6266 enum machine_mode eltmode = TYPE_MODE (elttype);
6267 HOST_WIDE_INT bitsize;
6268 HOST_WIDE_INT bitpos;
6269 rtvec vector = NULL;
6270 unsigned n_elts;
6271 alias_set_type alias;
6273 gcc_assert (eltmode != BLKmode);
6275 n_elts = TYPE_VECTOR_SUBPARTS (type);
6276 if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
6278 enum machine_mode mode = GET_MODE (target);
6280 icode = (int) optab_handler (vec_init_optab, mode);
6281 if (icode != CODE_FOR_nothing)
6283 unsigned int i;
6285 vector = rtvec_alloc (n_elts);
6286 for (i = 0; i < n_elts; i++)
6287 RTVEC_ELT (vector, i) = CONST0_RTX (GET_MODE_INNER (mode));
6291 /* If the constructor has fewer elements than the vector,
6292 clear the whole array first. Similarly if this is static
6293 constructor of a non-BLKmode object. */
6294 if (cleared)
6295 need_to_clear = 0;
6296 else if (REG_P (target) && TREE_STATIC (exp))
6297 need_to_clear = 1;
6298 else
6300 unsigned HOST_WIDE_INT count = 0, zero_count = 0;
6301 tree value;
6303 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
6305 int n_elts_here = tree_to_uhwi
6306 (int_const_binop (TRUNC_DIV_EXPR,
6307 TYPE_SIZE (TREE_TYPE (value)),
6308 TYPE_SIZE (elttype)));
6310 count += n_elts_here;
6311 if (mostly_zeros_p (value))
6312 zero_count += n_elts_here;
6315 /* Clear the entire vector first if there are any missing elements,
6316 or if the incidence of zero elements is >= 75%. */
6317 need_to_clear = (count < n_elts || 4 * zero_count >= 3 * count);
6320 if (need_to_clear && size > 0 && !vector)
6322 if (REG_P (target))
6323 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6324 else
6325 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6326 cleared = 1;
6329 /* Inform later passes that the old value is dead. */
6330 if (!cleared && !vector && REG_P (target))
6331 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6333 if (MEM_P (target))
6334 alias = MEM_ALIAS_SET (target);
6335 else
6336 alias = get_alias_set (elttype);
6338 /* Store each element of the constructor into the corresponding
6339 element of TARGET, determined by counting the elements. */
6340 for (idx = 0, i = 0;
6341 vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
6342 idx++, i += bitsize / elt_size)
6344 HOST_WIDE_INT eltpos;
6345 tree value = ce->value;
6347 bitsize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value)));
6348 if (cleared && initializer_zerop (value))
6349 continue;
6351 if (ce->index)
6352 eltpos = tree_to_uhwi (ce->index);
6353 else
6354 eltpos = i;
6356 if (vector)
6358 /* Vector CONSTRUCTORs should only be built from smaller
6359 vectors in the case of BLKmode vectors. */
6360 gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
6361 RTVEC_ELT (vector, eltpos)
6362 = expand_normal (value);
6364 else
6366 enum machine_mode value_mode =
6367 TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
6368 ? TYPE_MODE (TREE_TYPE (value))
6369 : eltmode;
6370 bitpos = eltpos * elt_size;
6371 store_constructor_field (target, bitsize, bitpos, value_mode,
6372 value, cleared, alias);
6376 if (vector)
6377 emit_insn (GEN_FCN (icode)
6378 (target,
6379 gen_rtx_PARALLEL (GET_MODE (target), vector)));
6380 break;
6383 default:
6384 gcc_unreachable ();
6388 /* Store the value of EXP (an expression tree)
6389 into a subfield of TARGET which has mode MODE and occupies
6390 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6391 If MODE is VOIDmode, it means that we are storing into a bit-field.
6393 BITREGION_START is bitpos of the first bitfield in this region.
6394 BITREGION_END is the bitpos of the ending bitfield in this region.
6395 These two fields are 0, if the C++ memory model does not apply,
6396 or we are not interested in keeping track of bitfield regions.
6398 Always return const0_rtx unless we have something particular to
6399 return.
6401 ALIAS_SET is the alias set for the destination. This value will
6402 (in general) be different from that for TARGET, since TARGET is a
6403 reference to the containing structure.
6405 If NONTEMPORAL is true, try generating a nontemporal store. */
6407 static rtx
6408 store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
6409 unsigned HOST_WIDE_INT bitregion_start,
6410 unsigned HOST_WIDE_INT bitregion_end,
6411 enum machine_mode mode, tree exp,
6412 alias_set_type alias_set, bool nontemporal)
6414 if (TREE_CODE (exp) == ERROR_MARK)
6415 return const0_rtx;
6417 /* If we have nothing to store, do nothing unless the expression has
6418 side-effects. */
6419 if (bitsize == 0)
6420 return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
6422 if (GET_CODE (target) == CONCAT)
6424 /* We're storing into a struct containing a single __complex. */
6426 gcc_assert (!bitpos);
6427 return store_expr (exp, target, 0, nontemporal);
6430 /* If the structure is in a register or if the component
6431 is a bit field, we cannot use addressing to access it.
6432 Use bit-field techniques or SUBREG to store in it. */
6434 if (mode == VOIDmode
6435 || (mode != BLKmode && ! direct_store[(int) mode]
6436 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
6437 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
6438 || REG_P (target)
6439 || GET_CODE (target) == SUBREG
6440 /* If the field isn't aligned enough to store as an ordinary memref,
6441 store it as a bit field. */
6442 || (mode != BLKmode
6443 && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
6444 || bitpos % GET_MODE_ALIGNMENT (mode))
6445 && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
6446 || (bitpos % BITS_PER_UNIT != 0)))
6447 || (bitsize >= 0 && mode != BLKmode
6448 && GET_MODE_BITSIZE (mode) > bitsize)
6449 /* If the RHS and field are a constant size and the size of the
6450 RHS isn't the same size as the bitfield, we must use bitfield
6451 operations. */
6452 || (bitsize >= 0
6453 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
6454 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0)
6455 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6456 decl we must use bitfield operations. */
6457 || (bitsize >= 0
6458 && TREE_CODE (exp) == MEM_REF
6459 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6460 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6461 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0),0 ))
6462 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
6464 rtx temp;
6465 gimple nop_def;
6467 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6468 implies a mask operation. If the precision is the same size as
6469 the field we're storing into, that mask is redundant. This is
6470 particularly common with bit field assignments generated by the
6471 C front end. */
6472 nop_def = get_def_for_expr (exp, NOP_EXPR);
6473 if (nop_def)
6475 tree type = TREE_TYPE (exp);
6476 if (INTEGRAL_TYPE_P (type)
6477 && TYPE_PRECISION (type) < GET_MODE_BITSIZE (TYPE_MODE (type))
6478 && bitsize == TYPE_PRECISION (type))
6480 tree op = gimple_assign_rhs1 (nop_def);
6481 type = TREE_TYPE (op);
6482 if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) >= bitsize)
6483 exp = op;
6487 temp = expand_normal (exp);
6489 /* If BITSIZE is narrower than the size of the type of EXP
6490 we will be narrowing TEMP. Normally, what's wanted are the
6491 low-order bits. However, if EXP's type is a record and this is
6492 big-endian machine, we want the upper BITSIZE bits. */
6493 if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
6494 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
6495 && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
6496 temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
6497 GET_MODE_BITSIZE (GET_MODE (temp)) - bitsize,
6498 NULL_RTX, 1);
6500 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6501 if (mode != VOIDmode && mode != BLKmode
6502 && mode != TYPE_MODE (TREE_TYPE (exp)))
6503 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
6505 /* If the modes of TEMP and TARGET are both BLKmode, both
6506 must be in memory and BITPOS must be aligned on a byte
6507 boundary. If so, we simply do a block copy. Likewise
6508 for a BLKmode-like TARGET. */
6509 if (GET_MODE (temp) == BLKmode
6510 && (GET_MODE (target) == BLKmode
6511 || (MEM_P (target)
6512 && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
6513 && (bitpos % BITS_PER_UNIT) == 0
6514 && (bitsize % BITS_PER_UNIT) == 0)))
6516 gcc_assert (MEM_P (target) && MEM_P (temp)
6517 && (bitpos % BITS_PER_UNIT) == 0);
6519 target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
6520 emit_block_move (target, temp,
6521 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
6522 / BITS_PER_UNIT),
6523 BLOCK_OP_NORMAL);
6525 return const0_rtx;
6528 /* Handle calls that return values in multiple non-contiguous locations.
6529 The Irix 6 ABI has examples of this. */
6530 if (GET_CODE (temp) == PARALLEL)
6532 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
6533 rtx temp_target;
6534 if (mode == BLKmode)
6535 mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
6536 temp_target = gen_reg_rtx (mode);
6537 emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
6538 temp = temp_target;
6540 else if (mode == BLKmode)
6542 /* Handle calls that return BLKmode values in registers. */
6543 if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
6545 rtx temp_target = gen_reg_rtx (GET_MODE (temp));
6546 copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp));
6547 temp = temp_target;
6549 else
6551 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
6552 rtx temp_target;
6553 mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
6554 temp_target = gen_reg_rtx (mode);
6555 temp_target
6556 = extract_bit_field (temp, size * BITS_PER_UNIT, 0, 1,
6557 temp_target, mode, mode);
6558 temp = temp_target;
6562 /* Store the value in the bitfield. */
6563 store_bit_field (target, bitsize, bitpos,
6564 bitregion_start, bitregion_end,
6565 mode, temp);
6567 return const0_rtx;
6569 else
6571 /* Now build a reference to just the desired component. */
6572 rtx to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
6574 if (to_rtx == target)
6575 to_rtx = copy_rtx (to_rtx);
6577 if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
6578 set_mem_alias_set (to_rtx, alias_set);
6580 return store_expr (exp, to_rtx, 0, nontemporal);
6584 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6585 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6586 codes and find the ultimate containing object, which we return.
6588 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6589 bit position, and *PUNSIGNEDP to the signedness of the field.
6590 If the position of the field is variable, we store a tree
6591 giving the variable offset (in units) in *POFFSET.
6592 This offset is in addition to the bit position.
6593 If the position is not variable, we store 0 in *POFFSET.
6595 If any of the extraction expressions is volatile,
6596 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6598 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6599 Otherwise, it is a mode that can be used to access the field.
6601 If the field describes a variable-sized object, *PMODE is set to
6602 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6603 this case, but the address of the object can be found.
6605 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6606 look through nodes that serve as markers of a greater alignment than
6607 the one that can be deduced from the expression. These nodes make it
6608 possible for front-ends to prevent temporaries from being created by
6609 the middle-end on alignment considerations. For that purpose, the
6610 normal operating mode at high-level is to always pass FALSE so that
6611 the ultimate containing object is really returned; moreover, the
6612 associated predicate handled_component_p will always return TRUE
6613 on these nodes, thus indicating that they are essentially handled
6614 by get_inner_reference. TRUE should only be passed when the caller
6615 is scanning the expression in order to build another representation
6616 and specifically knows how to handle these nodes; as such, this is
6617 the normal operating mode in the RTL expanders. */
6619 tree
6620 get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
6621 HOST_WIDE_INT *pbitpos, tree *poffset,
6622 enum machine_mode *pmode, int *punsignedp,
6623 int *pvolatilep, bool keep_aligning)
6625 tree size_tree = 0;
6626 enum machine_mode mode = VOIDmode;
6627 bool blkmode_bitfield = false;
6628 tree offset = size_zero_node;
6629 double_int bit_offset = double_int_zero;
6631 /* First get the mode, signedness, and size. We do this from just the
6632 outermost expression. */
6633 *pbitsize = -1;
6634 if (TREE_CODE (exp) == COMPONENT_REF)
6636 tree field = TREE_OPERAND (exp, 1);
6637 size_tree = DECL_SIZE (field);
6638 if (flag_strict_volatile_bitfields > 0
6639 && TREE_THIS_VOLATILE (exp)
6640 && DECL_BIT_FIELD_TYPE (field)
6641 && DECL_MODE (field) != BLKmode)
6642 /* Volatile bitfields should be accessed in the mode of the
6643 field's type, not the mode computed based on the bit
6644 size. */
6645 mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
6646 else if (!DECL_BIT_FIELD (field))
6647 mode = DECL_MODE (field);
6648 else if (DECL_MODE (field) == BLKmode)
6649 blkmode_bitfield = true;
6651 *punsignedp = DECL_UNSIGNED (field);
6653 else if (TREE_CODE (exp) == BIT_FIELD_REF)
6655 size_tree = TREE_OPERAND (exp, 1);
6656 *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
6657 || TYPE_UNSIGNED (TREE_TYPE (exp)));
6659 /* For vector types, with the correct size of access, use the mode of
6660 inner type. */
6661 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
6662 && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
6663 && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
6664 mode = TYPE_MODE (TREE_TYPE (exp));
6666 else
6668 mode = TYPE_MODE (TREE_TYPE (exp));
6669 *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
6671 if (mode == BLKmode)
6672 size_tree = TYPE_SIZE (TREE_TYPE (exp));
6673 else
6674 *pbitsize = GET_MODE_BITSIZE (mode);
6677 if (size_tree != 0)
6679 if (! tree_fits_uhwi_p (size_tree))
6680 mode = BLKmode, *pbitsize = -1;
6681 else
6682 *pbitsize = tree_to_uhwi (size_tree);
6685 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6686 and find the ultimate containing object. */
6687 while (1)
6689 switch (TREE_CODE (exp))
6691 case BIT_FIELD_REF:
6692 bit_offset += tree_to_double_int (TREE_OPERAND (exp, 2));
6693 break;
6695 case COMPONENT_REF:
6697 tree field = TREE_OPERAND (exp, 1);
6698 tree this_offset = component_ref_field_offset (exp);
6700 /* If this field hasn't been filled in yet, don't go past it.
6701 This should only happen when folding expressions made during
6702 type construction. */
6703 if (this_offset == 0)
6704 break;
6706 offset = size_binop (PLUS_EXPR, offset, this_offset);
6707 bit_offset += tree_to_double_int (DECL_FIELD_BIT_OFFSET (field));
6709 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6711 break;
6713 case ARRAY_REF:
6714 case ARRAY_RANGE_REF:
6716 tree index = TREE_OPERAND (exp, 1);
6717 tree low_bound = array_ref_low_bound (exp);
6718 tree unit_size = array_ref_element_size (exp);
6720 /* We assume all arrays have sizes that are a multiple of a byte.
6721 First subtract the lower bound, if any, in the type of the
6722 index, then convert to sizetype and multiply by the size of
6723 the array element. */
6724 if (! integer_zerop (low_bound))
6725 index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
6726 index, low_bound);
6728 offset = size_binop (PLUS_EXPR, offset,
6729 size_binop (MULT_EXPR,
6730 fold_convert (sizetype, index),
6731 unit_size));
6733 break;
6735 case REALPART_EXPR:
6736 break;
6738 case IMAGPART_EXPR:
6739 bit_offset += double_int::from_uhwi (*pbitsize);
6740 break;
6742 case VIEW_CONVERT_EXPR:
6743 if (keep_aligning && STRICT_ALIGNMENT
6744 && (TYPE_ALIGN (TREE_TYPE (exp))
6745 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
6746 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
6747 < BIGGEST_ALIGNMENT)
6748 && (TYPE_ALIGN_OK (TREE_TYPE (exp))
6749 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp, 0)))))
6750 goto done;
6751 break;
6753 case MEM_REF:
6754 /* Hand back the decl for MEM[&decl, off]. */
6755 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
6757 tree off = TREE_OPERAND (exp, 1);
6758 if (!integer_zerop (off))
6760 double_int boff, coff = mem_ref_offset (exp);
6761 boff = coff.lshift (BITS_PER_UNIT == 8
6762 ? 3 : exact_log2 (BITS_PER_UNIT));
6763 bit_offset += boff;
6765 exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6767 goto done;
6769 default:
6770 goto done;
6773 /* If any reference in the chain is volatile, the effect is volatile. */
6774 if (TREE_THIS_VOLATILE (exp))
6775 *pvolatilep = 1;
6777 exp = TREE_OPERAND (exp, 0);
6779 done:
6781 /* If OFFSET is constant, see if we can return the whole thing as a
6782 constant bit position. Make sure to handle overflow during
6783 this conversion. */
6784 if (TREE_CODE (offset) == INTEGER_CST)
6786 double_int tem = tree_to_double_int (offset);
6787 tem = tem.sext (TYPE_PRECISION (sizetype));
6788 tem = tem.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
6789 tem += bit_offset;
6790 if (tem.fits_shwi ())
6792 *pbitpos = tem.to_shwi ();
6793 *poffset = offset = NULL_TREE;
6797 /* Otherwise, split it up. */
6798 if (offset)
6800 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6801 if (bit_offset.is_negative ())
6803 double_int mask
6804 = double_int::mask (BITS_PER_UNIT == 8
6805 ? 3 : exact_log2 (BITS_PER_UNIT));
6806 double_int tem = bit_offset.and_not (mask);
6807 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6808 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6809 bit_offset -= tem;
6810 tem = tem.arshift (BITS_PER_UNIT == 8
6811 ? 3 : exact_log2 (BITS_PER_UNIT),
6812 HOST_BITS_PER_DOUBLE_INT);
6813 offset = size_binop (PLUS_EXPR, offset,
6814 double_int_to_tree (sizetype, tem));
6817 *pbitpos = bit_offset.to_shwi ();
6818 *poffset = offset;
6821 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6822 if (mode == VOIDmode
6823 && blkmode_bitfield
6824 && (*pbitpos % BITS_PER_UNIT) == 0
6825 && (*pbitsize % BITS_PER_UNIT) == 0)
6826 *pmode = BLKmode;
6827 else
6828 *pmode = mode;
6830 return exp;
6833 /* Return a tree of sizetype representing the size, in bytes, of the element
6834 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6836 tree
6837 array_ref_element_size (tree exp)
6839 tree aligned_size = TREE_OPERAND (exp, 3);
6840 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
6841 location_t loc = EXPR_LOCATION (exp);
6843 /* If a size was specified in the ARRAY_REF, it's the size measured
6844 in alignment units of the element type. So multiply by that value. */
6845 if (aligned_size)
6847 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6848 sizetype from another type of the same width and signedness. */
6849 if (TREE_TYPE (aligned_size) != sizetype)
6850 aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
6851 return size_binop_loc (loc, MULT_EXPR, aligned_size,
6852 size_int (TYPE_ALIGN_UNIT (elmt_type)));
6855 /* Otherwise, take the size from that of the element type. Substitute
6856 any PLACEHOLDER_EXPR that we have. */
6857 else
6858 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
6861 /* Return a tree representing the lower bound of the array mentioned in
6862 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6864 tree
6865 array_ref_low_bound (tree exp)
6867 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
6869 /* If a lower bound is specified in EXP, use it. */
6870 if (TREE_OPERAND (exp, 2))
6871 return TREE_OPERAND (exp, 2);
6873 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6874 substituting for a PLACEHOLDER_EXPR as needed. */
6875 if (domain_type && TYPE_MIN_VALUE (domain_type))
6876 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
6878 /* Otherwise, return a zero of the appropriate type. */
6879 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp, 1)), 0);
6882 /* Returns true if REF is an array reference to an array at the end of
6883 a structure. If this is the case, the array may be allocated larger
6884 than its upper bound implies. */
6886 bool
6887 array_at_struct_end_p (tree ref)
6889 if (TREE_CODE (ref) != ARRAY_REF
6890 && TREE_CODE (ref) != ARRAY_RANGE_REF)
6891 return false;
6893 while (handled_component_p (ref))
6895 /* If the reference chain contains a component reference to a
6896 non-union type and there follows another field the reference
6897 is not at the end of a structure. */
6898 if (TREE_CODE (ref) == COMPONENT_REF
6899 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
6901 tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
6902 while (nextf && TREE_CODE (nextf) != FIELD_DECL)
6903 nextf = DECL_CHAIN (nextf);
6904 if (nextf)
6905 return false;
6908 ref = TREE_OPERAND (ref, 0);
6911 /* If the reference is based on a declared entity, the size of the array
6912 is constrained by its given domain. */
6913 if (DECL_P (ref))
6914 return false;
6916 return true;
6919 /* Return a tree representing the upper bound of the array mentioned in
6920 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6922 tree
6923 array_ref_up_bound (tree exp)
6925 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
6927 /* If there is a domain type and it has an upper bound, use it, substituting
6928 for a PLACEHOLDER_EXPR as needed. */
6929 if (domain_type && TYPE_MAX_VALUE (domain_type))
6930 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
6932 /* Otherwise fail. */
6933 return NULL_TREE;
6936 /* Return a tree representing the offset, in bytes, of the field referenced
6937 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6939 tree
6940 component_ref_field_offset (tree exp)
6942 tree aligned_offset = TREE_OPERAND (exp, 2);
6943 tree field = TREE_OPERAND (exp, 1);
6944 location_t loc = EXPR_LOCATION (exp);
6946 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6947 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6948 value. */
6949 if (aligned_offset)
6951 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6952 sizetype from another type of the same width and signedness. */
6953 if (TREE_TYPE (aligned_offset) != sizetype)
6954 aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
6955 return size_binop_loc (loc, MULT_EXPR, aligned_offset,
6956 size_int (DECL_OFFSET_ALIGN (field)
6957 / BITS_PER_UNIT));
6960 /* Otherwise, take the offset from that of the field. Substitute
6961 any PLACEHOLDER_EXPR that we have. */
6962 else
6963 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
6966 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6968 static unsigned HOST_WIDE_INT
6969 target_align (const_tree target)
6971 /* We might have a chain of nested references with intermediate misaligning
6972 bitfields components, so need to recurse to find out. */
6974 unsigned HOST_WIDE_INT this_align, outer_align;
6976 switch (TREE_CODE (target))
6978 case BIT_FIELD_REF:
6979 return 1;
6981 case COMPONENT_REF:
6982 this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
6983 outer_align = target_align (TREE_OPERAND (target, 0));
6984 return MIN (this_align, outer_align);
6986 case ARRAY_REF:
6987 case ARRAY_RANGE_REF:
6988 this_align = TYPE_ALIGN (TREE_TYPE (target));
6989 outer_align = target_align (TREE_OPERAND (target, 0));
6990 return MIN (this_align, outer_align);
6992 CASE_CONVERT:
6993 case NON_LVALUE_EXPR:
6994 case VIEW_CONVERT_EXPR:
6995 this_align = TYPE_ALIGN (TREE_TYPE (target));
6996 outer_align = target_align (TREE_OPERAND (target, 0));
6997 return MAX (this_align, outer_align);
6999 default:
7000 return TYPE_ALIGN (TREE_TYPE (target));
7005 /* Given an rtx VALUE that may contain additions and multiplications, return
7006 an equivalent value that just refers to a register, memory, or constant.
7007 This is done by generating instructions to perform the arithmetic and
7008 returning a pseudo-register containing the value.
7010 The returned value may be a REG, SUBREG, MEM or constant. */
7013 force_operand (rtx value, rtx target)
7015 rtx op1, op2;
7016 /* Use subtarget as the target for operand 0 of a binary operation. */
7017 rtx subtarget = get_subtarget (target);
7018 enum rtx_code code = GET_CODE (value);
7020 /* Check for subreg applied to an expression produced by loop optimizer. */
7021 if (code == SUBREG
7022 && !REG_P (SUBREG_REG (value))
7023 && !MEM_P (SUBREG_REG (value)))
7025 value
7026 = simplify_gen_subreg (GET_MODE (value),
7027 force_reg (GET_MODE (SUBREG_REG (value)),
7028 force_operand (SUBREG_REG (value),
7029 NULL_RTX)),
7030 GET_MODE (SUBREG_REG (value)),
7031 SUBREG_BYTE (value));
7032 code = GET_CODE (value);
7035 /* Check for a PIC address load. */
7036 if ((code == PLUS || code == MINUS)
7037 && XEXP (value, 0) == pic_offset_table_rtx
7038 && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
7039 || GET_CODE (XEXP (value, 1)) == LABEL_REF
7040 || GET_CODE (XEXP (value, 1)) == CONST))
7042 if (!subtarget)
7043 subtarget = gen_reg_rtx (GET_MODE (value));
7044 emit_move_insn (subtarget, value);
7045 return subtarget;
7048 if (ARITHMETIC_P (value))
7050 op2 = XEXP (value, 1);
7051 if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
7052 subtarget = 0;
7053 if (code == MINUS && CONST_INT_P (op2))
7055 code = PLUS;
7056 op2 = negate_rtx (GET_MODE (value), op2);
7059 /* Check for an addition with OP2 a constant integer and our first
7060 operand a PLUS of a virtual register and something else. In that
7061 case, we want to emit the sum of the virtual register and the
7062 constant first and then add the other value. This allows virtual
7063 register instantiation to simply modify the constant rather than
7064 creating another one around this addition. */
7065 if (code == PLUS && CONST_INT_P (op2)
7066 && GET_CODE (XEXP (value, 0)) == PLUS
7067 && REG_P (XEXP (XEXP (value, 0), 0))
7068 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7069 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
7071 rtx temp = expand_simple_binop (GET_MODE (value), code,
7072 XEXP (XEXP (value, 0), 0), op2,
7073 subtarget, 0, OPTAB_LIB_WIDEN);
7074 return expand_simple_binop (GET_MODE (value), code, temp,
7075 force_operand (XEXP (XEXP (value,
7076 0), 1), 0),
7077 target, 0, OPTAB_LIB_WIDEN);
7080 op1 = force_operand (XEXP (value, 0), subtarget);
7081 op2 = force_operand (op2, NULL_RTX);
7082 switch (code)
7084 case MULT:
7085 return expand_mult (GET_MODE (value), op1, op2, target, 1);
7086 case DIV:
7087 if (!INTEGRAL_MODE_P (GET_MODE (value)))
7088 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7089 target, 1, OPTAB_LIB_WIDEN);
7090 else
7091 return expand_divmod (0,
7092 FLOAT_MODE_P (GET_MODE (value))
7093 ? RDIV_EXPR : TRUNC_DIV_EXPR,
7094 GET_MODE (value), op1, op2, target, 0);
7095 case MOD:
7096 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7097 target, 0);
7098 case UDIV:
7099 return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
7100 target, 1);
7101 case UMOD:
7102 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7103 target, 1);
7104 case ASHIFTRT:
7105 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7106 target, 0, OPTAB_LIB_WIDEN);
7107 default:
7108 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7109 target, 1, OPTAB_LIB_WIDEN);
7112 if (UNARY_P (value))
7114 if (!target)
7115 target = gen_reg_rtx (GET_MODE (value));
7116 op1 = force_operand (XEXP (value, 0), NULL_RTX);
7117 switch (code)
7119 case ZERO_EXTEND:
7120 case SIGN_EXTEND:
7121 case TRUNCATE:
7122 case FLOAT_EXTEND:
7123 case FLOAT_TRUNCATE:
7124 convert_move (target, op1, code == ZERO_EXTEND);
7125 return target;
7127 case FIX:
7128 case UNSIGNED_FIX:
7129 expand_fix (target, op1, code == UNSIGNED_FIX);
7130 return target;
7132 case FLOAT:
7133 case UNSIGNED_FLOAT:
7134 expand_float (target, op1, code == UNSIGNED_FLOAT);
7135 return target;
7137 default:
7138 return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
7142 #ifdef INSN_SCHEDULING
7143 /* On machines that have insn scheduling, we want all memory reference to be
7144 explicit, so we need to deal with such paradoxical SUBREGs. */
7145 if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
7146 value
7147 = simplify_gen_subreg (GET_MODE (value),
7148 force_reg (GET_MODE (SUBREG_REG (value)),
7149 force_operand (SUBREG_REG (value),
7150 NULL_RTX)),
7151 GET_MODE (SUBREG_REG (value)),
7152 SUBREG_BYTE (value));
7153 #endif
7155 return value;
7158 /* Subroutine of expand_expr: return nonzero iff there is no way that
7159 EXP can reference X, which is being modified. TOP_P is nonzero if this
7160 call is going to be used to determine whether we need a temporary
7161 for EXP, as opposed to a recursive call to this function.
7163 It is always safe for this routine to return zero since it merely
7164 searches for optimization opportunities. */
7167 safe_from_p (const_rtx x, tree exp, int top_p)
7169 rtx exp_rtl = 0;
7170 int i, nops;
7172 if (x == 0
7173 /* If EXP has varying size, we MUST use a target since we currently
7174 have no way of allocating temporaries of variable size
7175 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7176 So we assume here that something at a higher level has prevented a
7177 clash. This is somewhat bogus, but the best we can do. Only
7178 do this when X is BLKmode and when we are at the top level. */
7179 || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
7180 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
7181 && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
7182 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
7183 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
7184 != INTEGER_CST)
7185 && GET_MODE (x) == BLKmode)
7186 /* If X is in the outgoing argument area, it is always safe. */
7187 || (MEM_P (x)
7188 && (XEXP (x, 0) == virtual_outgoing_args_rtx
7189 || (GET_CODE (XEXP (x, 0)) == PLUS
7190 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
7191 return 1;
7193 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7194 find the underlying pseudo. */
7195 if (GET_CODE (x) == SUBREG)
7197 x = SUBREG_REG (x);
7198 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7199 return 0;
7202 /* Now look at our tree code and possibly recurse. */
7203 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
7205 case tcc_declaration:
7206 exp_rtl = DECL_RTL_IF_SET (exp);
7207 break;
7209 case tcc_constant:
7210 return 1;
7212 case tcc_exceptional:
7213 if (TREE_CODE (exp) == TREE_LIST)
7215 while (1)
7217 if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
7218 return 0;
7219 exp = TREE_CHAIN (exp);
7220 if (!exp)
7221 return 1;
7222 if (TREE_CODE (exp) != TREE_LIST)
7223 return safe_from_p (x, exp, 0);
7226 else if (TREE_CODE (exp) == CONSTRUCTOR)
7228 constructor_elt *ce;
7229 unsigned HOST_WIDE_INT idx;
7231 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
7232 if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
7233 || !safe_from_p (x, ce->value, 0))
7234 return 0;
7235 return 1;
7237 else if (TREE_CODE (exp) == ERROR_MARK)
7238 return 1; /* An already-visited SAVE_EXPR? */
7239 else
7240 return 0;
7242 case tcc_statement:
7243 /* The only case we look at here is the DECL_INITIAL inside a
7244 DECL_EXPR. */
7245 return (TREE_CODE (exp) != DECL_EXPR
7246 || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
7247 || !DECL_INITIAL (DECL_EXPR_DECL (exp))
7248 || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
7250 case tcc_binary:
7251 case tcc_comparison:
7252 if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
7253 return 0;
7254 /* Fall through. */
7256 case tcc_unary:
7257 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7259 case tcc_expression:
7260 case tcc_reference:
7261 case tcc_vl_exp:
7262 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7263 the expression. If it is set, we conflict iff we are that rtx or
7264 both are in memory. Otherwise, we check all operands of the
7265 expression recursively. */
7267 switch (TREE_CODE (exp))
7269 case ADDR_EXPR:
7270 /* If the operand is static or we are static, we can't conflict.
7271 Likewise if we don't conflict with the operand at all. */
7272 if (staticp (TREE_OPERAND (exp, 0))
7273 || TREE_STATIC (exp)
7274 || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
7275 return 1;
7277 /* Otherwise, the only way this can conflict is if we are taking
7278 the address of a DECL a that address if part of X, which is
7279 very rare. */
7280 exp = TREE_OPERAND (exp, 0);
7281 if (DECL_P (exp))
7283 if (!DECL_RTL_SET_P (exp)
7284 || !MEM_P (DECL_RTL (exp)))
7285 return 0;
7286 else
7287 exp_rtl = XEXP (DECL_RTL (exp), 0);
7289 break;
7291 case MEM_REF:
7292 if (MEM_P (x)
7293 && alias_sets_conflict_p (MEM_ALIAS_SET (x),
7294 get_alias_set (exp)))
7295 return 0;
7296 break;
7298 case CALL_EXPR:
7299 /* Assume that the call will clobber all hard registers and
7300 all of memory. */
7301 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7302 || MEM_P (x))
7303 return 0;
7304 break;
7306 case WITH_CLEANUP_EXPR:
7307 case CLEANUP_POINT_EXPR:
7308 /* Lowered by gimplify.c. */
7309 gcc_unreachable ();
7311 case SAVE_EXPR:
7312 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7314 default:
7315 break;
7318 /* If we have an rtx, we do not need to scan our operands. */
7319 if (exp_rtl)
7320 break;
7322 nops = TREE_OPERAND_LENGTH (exp);
7323 for (i = 0; i < nops; i++)
7324 if (TREE_OPERAND (exp, i) != 0
7325 && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
7326 return 0;
7328 break;
7330 case tcc_type:
7331 /* Should never get a type here. */
7332 gcc_unreachable ();
7335 /* If we have an rtl, find any enclosed object. Then see if we conflict
7336 with it. */
7337 if (exp_rtl)
7339 if (GET_CODE (exp_rtl) == SUBREG)
7341 exp_rtl = SUBREG_REG (exp_rtl);
7342 if (REG_P (exp_rtl)
7343 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
7344 return 0;
7347 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7348 are memory and they conflict. */
7349 return ! (rtx_equal_p (x, exp_rtl)
7350 || (MEM_P (x) && MEM_P (exp_rtl)
7351 && true_dependence (exp_rtl, VOIDmode, x)));
7354 /* If we reach here, it is safe. */
7355 return 1;
7359 /* Return the highest power of two that EXP is known to be a multiple of.
7360 This is used in updating alignment of MEMs in array references. */
7362 unsigned HOST_WIDE_INT
7363 highest_pow2_factor (const_tree exp)
7365 unsigned HOST_WIDE_INT ret;
7366 int trailing_zeros = tree_ctz (exp);
7367 if (trailing_zeros >= HOST_BITS_PER_WIDE_INT)
7368 return BIGGEST_ALIGNMENT;
7369 ret = (unsigned HOST_WIDE_INT) 1 << trailing_zeros;
7370 if (ret > BIGGEST_ALIGNMENT)
7371 return BIGGEST_ALIGNMENT;
7372 return ret;
7375 /* Similar, except that the alignment requirements of TARGET are
7376 taken into account. Assume it is at least as aligned as its
7377 type, unless it is a COMPONENT_REF in which case the layout of
7378 the structure gives the alignment. */
7380 static unsigned HOST_WIDE_INT
7381 highest_pow2_factor_for_target (const_tree target, const_tree exp)
7383 unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
7384 unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
7386 return MAX (factor, talign);
7389 #ifdef HAVE_conditional_move
7390 /* Convert the tree comparison code TCODE to the rtl one where the
7391 signedness is UNSIGNEDP. */
7393 static enum rtx_code
7394 convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
7396 enum rtx_code code;
7397 switch (tcode)
7399 case EQ_EXPR:
7400 code = EQ;
7401 break;
7402 case NE_EXPR:
7403 code = NE;
7404 break;
7405 case LT_EXPR:
7406 code = unsignedp ? LTU : LT;
7407 break;
7408 case LE_EXPR:
7409 code = unsignedp ? LEU : LE;
7410 break;
7411 case GT_EXPR:
7412 code = unsignedp ? GTU : GT;
7413 break;
7414 case GE_EXPR:
7415 code = unsignedp ? GEU : GE;
7416 break;
7417 case UNORDERED_EXPR:
7418 code = UNORDERED;
7419 break;
7420 case ORDERED_EXPR:
7421 code = ORDERED;
7422 break;
7423 case UNLT_EXPR:
7424 code = UNLT;
7425 break;
7426 case UNLE_EXPR:
7427 code = UNLE;
7428 break;
7429 case UNGT_EXPR:
7430 code = UNGT;
7431 break;
7432 case UNGE_EXPR:
7433 code = UNGE;
7434 break;
7435 case UNEQ_EXPR:
7436 code = UNEQ;
7437 break;
7438 case LTGT_EXPR:
7439 code = LTGT;
7440 break;
7442 default:
7443 gcc_unreachable ();
7445 return code;
7447 #endif
7449 /* Subroutine of expand_expr. Expand the two operands of a binary
7450 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7451 The value may be stored in TARGET if TARGET is nonzero. The
7452 MODIFIER argument is as documented by expand_expr. */
7454 static void
7455 expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
7456 enum expand_modifier modifier)
7458 if (! safe_from_p (target, exp1, 1))
7459 target = 0;
7460 if (operand_equal_p (exp0, exp1, 0))
7462 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7463 *op1 = copy_rtx (*op0);
7465 else
7467 /* If we need to preserve evaluation order, copy exp0 into its own
7468 temporary variable so that it can't be clobbered by exp1. */
7469 if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
7470 exp0 = save_expr (exp0);
7471 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7472 *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
7477 /* Return a MEM that contains constant EXP. DEFER is as for
7478 output_constant_def and MODIFIER is as for expand_expr. */
7480 static rtx
7481 expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
7483 rtx mem;
7485 mem = output_constant_def (exp, defer);
7486 if (modifier != EXPAND_INITIALIZER)
7487 mem = use_anchored_address (mem);
7488 return mem;
7491 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7492 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7494 static rtx
7495 expand_expr_addr_expr_1 (tree exp, rtx target, enum machine_mode tmode,
7496 enum expand_modifier modifier, addr_space_t as)
7498 rtx result, subtarget;
7499 tree inner, offset;
7500 HOST_WIDE_INT bitsize, bitpos;
7501 int volatilep, unsignedp;
7502 enum machine_mode mode1;
7504 /* If we are taking the address of a constant and are at the top level,
7505 we have to use output_constant_def since we can't call force_const_mem
7506 at top level. */
7507 /* ??? This should be considered a front-end bug. We should not be
7508 generating ADDR_EXPR of something that isn't an LVALUE. The only
7509 exception here is STRING_CST. */
7510 if (CONSTANT_CLASS_P (exp))
7512 result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
7513 if (modifier < EXPAND_SUM)
7514 result = force_operand (result, target);
7515 return result;
7518 /* Everything must be something allowed by is_gimple_addressable. */
7519 switch (TREE_CODE (exp))
7521 case INDIRECT_REF:
7522 /* This case will happen via recursion for &a->b. */
7523 return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7525 case MEM_REF:
7527 tree tem = TREE_OPERAND (exp, 0);
7528 if (!integer_zerop (TREE_OPERAND (exp, 1)))
7529 tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
7530 return expand_expr (tem, target, tmode, modifier);
7533 case CONST_DECL:
7534 /* Expand the initializer like constants above. */
7535 result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
7536 0, modifier), 0);
7537 if (modifier < EXPAND_SUM)
7538 result = force_operand (result, target);
7539 return result;
7541 case REALPART_EXPR:
7542 /* The real part of the complex number is always first, therefore
7543 the address is the same as the address of the parent object. */
7544 offset = 0;
7545 bitpos = 0;
7546 inner = TREE_OPERAND (exp, 0);
7547 break;
7549 case IMAGPART_EXPR:
7550 /* The imaginary part of the complex number is always second.
7551 The expression is therefore always offset by the size of the
7552 scalar type. */
7553 offset = 0;
7554 bitpos = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)));
7555 inner = TREE_OPERAND (exp, 0);
7556 break;
7558 case COMPOUND_LITERAL_EXPR:
7559 /* Allow COMPOUND_LITERAL_EXPR in initializers, if e.g.
7560 rtl_for_decl_init is called on DECL_INITIAL with
7561 COMPOUNT_LITERAL_EXPRs in it, they aren't gimplified. */
7562 if (modifier == EXPAND_INITIALIZER
7563 && COMPOUND_LITERAL_EXPR_DECL (exp))
7564 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
7565 target, tmode, modifier, as);
7566 /* FALLTHRU */
7567 default:
7568 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7569 expand_expr, as that can have various side effects; LABEL_DECLs for
7570 example, may not have their DECL_RTL set yet. Expand the rtl of
7571 CONSTRUCTORs too, which should yield a memory reference for the
7572 constructor's contents. Assume language specific tree nodes can
7573 be expanded in some interesting way. */
7574 gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
7575 if (DECL_P (exp)
7576 || TREE_CODE (exp) == CONSTRUCTOR
7577 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
7579 result = expand_expr (exp, target, tmode,
7580 modifier == EXPAND_INITIALIZER
7581 ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
7583 /* If the DECL isn't in memory, then the DECL wasn't properly
7584 marked TREE_ADDRESSABLE, which will be either a front-end
7585 or a tree optimizer bug. */
7587 if (TREE_ADDRESSABLE (exp)
7588 && ! MEM_P (result)
7589 && ! targetm.calls.allocate_stack_slots_for_args ())
7591 error ("local frame unavailable (naked function?)");
7592 return result;
7594 else
7595 gcc_assert (MEM_P (result));
7596 result = XEXP (result, 0);
7598 /* ??? Is this needed anymore? */
7599 if (DECL_P (exp))
7600 TREE_USED (exp) = 1;
7602 if (modifier != EXPAND_INITIALIZER
7603 && modifier != EXPAND_CONST_ADDRESS
7604 && modifier != EXPAND_SUM)
7605 result = force_operand (result, target);
7606 return result;
7609 /* Pass FALSE as the last argument to get_inner_reference although
7610 we are expanding to RTL. The rationale is that we know how to
7611 handle "aligning nodes" here: we can just bypass them because
7612 they won't change the final object whose address will be returned
7613 (they actually exist only for that purpose). */
7614 inner = get_inner_reference (exp, &bitsize, &bitpos, &offset,
7615 &mode1, &unsignedp, &volatilep, false);
7616 break;
7619 /* We must have made progress. */
7620 gcc_assert (inner != exp);
7622 subtarget = offset || bitpos ? NULL_RTX : target;
7623 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7624 inner alignment, force the inner to be sufficiently aligned. */
7625 if (CONSTANT_CLASS_P (inner)
7626 && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
7628 inner = copy_node (inner);
7629 TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
7630 TYPE_ALIGN (TREE_TYPE (inner)) = TYPE_ALIGN (TREE_TYPE (exp));
7631 TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
7633 result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
7635 if (offset)
7637 rtx tmp;
7639 if (modifier != EXPAND_NORMAL)
7640 result = force_operand (result, NULL);
7641 tmp = expand_expr (offset, NULL_RTX, tmode,
7642 modifier == EXPAND_INITIALIZER
7643 ? EXPAND_INITIALIZER : EXPAND_NORMAL);
7645 result = convert_memory_address_addr_space (tmode, result, as);
7646 tmp = convert_memory_address_addr_space (tmode, tmp, as);
7648 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7649 result = simplify_gen_binary (PLUS, tmode, result, tmp);
7650 else
7652 subtarget = bitpos ? NULL_RTX : target;
7653 result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
7654 1, OPTAB_LIB_WIDEN);
7658 if (bitpos)
7660 /* Someone beforehand should have rejected taking the address
7661 of such an object. */
7662 gcc_assert ((bitpos % BITS_PER_UNIT) == 0);
7664 result = convert_memory_address_addr_space (tmode, result, as);
7665 result = plus_constant (tmode, result, bitpos / BITS_PER_UNIT);
7666 if (modifier < EXPAND_SUM)
7667 result = force_operand (result, target);
7670 return result;
7673 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7674 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7676 static rtx
7677 expand_expr_addr_expr (tree exp, rtx target, enum machine_mode tmode,
7678 enum expand_modifier modifier)
7680 addr_space_t as = ADDR_SPACE_GENERIC;
7681 enum machine_mode address_mode = Pmode;
7682 enum machine_mode pointer_mode = ptr_mode;
7683 enum machine_mode rmode;
7684 rtx result;
7686 /* Target mode of VOIDmode says "whatever's natural". */
7687 if (tmode == VOIDmode)
7688 tmode = TYPE_MODE (TREE_TYPE (exp));
7690 if (POINTER_TYPE_P (TREE_TYPE (exp)))
7692 as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
7693 address_mode = targetm.addr_space.address_mode (as);
7694 pointer_mode = targetm.addr_space.pointer_mode (as);
7697 /* We can get called with some Weird Things if the user does silliness
7698 like "(short) &a". In that case, convert_memory_address won't do
7699 the right thing, so ignore the given target mode. */
7700 if (tmode != address_mode && tmode != pointer_mode)
7701 tmode = address_mode;
7703 result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
7704 tmode, modifier, as);
7706 /* Despite expand_expr claims concerning ignoring TMODE when not
7707 strictly convenient, stuff breaks if we don't honor it. Note
7708 that combined with the above, we only do this for pointer modes. */
7709 rmode = GET_MODE (result);
7710 if (rmode == VOIDmode)
7711 rmode = tmode;
7712 if (rmode != tmode)
7713 result = convert_memory_address_addr_space (tmode, result, as);
7715 return result;
7718 /* Generate code for computing CONSTRUCTOR EXP.
7719 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7720 is TRUE, instead of creating a temporary variable in memory
7721 NULL is returned and the caller needs to handle it differently. */
7723 static rtx
7724 expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
7725 bool avoid_temp_mem)
7727 tree type = TREE_TYPE (exp);
7728 enum machine_mode mode = TYPE_MODE (type);
7730 /* Try to avoid creating a temporary at all. This is possible
7731 if all of the initializer is zero.
7732 FIXME: try to handle all [0..255] initializers we can handle
7733 with memset. */
7734 if (TREE_STATIC (exp)
7735 && !TREE_ADDRESSABLE (exp)
7736 && target != 0 && mode == BLKmode
7737 && all_zeros_p (exp))
7739 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7740 return target;
7743 /* All elts simple constants => refer to a constant in memory. But
7744 if this is a non-BLKmode mode, let it store a field at a time
7745 since that should make a CONST_INT or CONST_DOUBLE when we
7746 fold. Likewise, if we have a target we can use, it is best to
7747 store directly into the target unless the type is large enough
7748 that memcpy will be used. If we are making an initializer and
7749 all operands are constant, put it in memory as well.
7751 FIXME: Avoid trying to fill vector constructors piece-meal.
7752 Output them with output_constant_def below unless we're sure
7753 they're zeros. This should go away when vector initializers
7754 are treated like VECTOR_CST instead of arrays. */
7755 if ((TREE_STATIC (exp)
7756 && ((mode == BLKmode
7757 && ! (target != 0 && safe_from_p (target, exp, 1)))
7758 || TREE_ADDRESSABLE (exp)
7759 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
7760 && (! MOVE_BY_PIECES_P
7761 (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
7762 TYPE_ALIGN (type)))
7763 && ! mostly_zeros_p (exp))))
7764 || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
7765 && TREE_CONSTANT (exp)))
7767 rtx constructor;
7769 if (avoid_temp_mem)
7770 return NULL_RTX;
7772 constructor = expand_expr_constant (exp, 1, modifier);
7774 if (modifier != EXPAND_CONST_ADDRESS
7775 && modifier != EXPAND_INITIALIZER
7776 && modifier != EXPAND_SUM)
7777 constructor = validize_mem (constructor);
7779 return constructor;
7782 /* Handle calls that pass values in multiple non-contiguous
7783 locations. The Irix 6 ABI has examples of this. */
7784 if (target == 0 || ! safe_from_p (target, exp, 1)
7785 || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM)
7787 if (avoid_temp_mem)
7788 return NULL_RTX;
7790 target
7791 = assign_temp (build_qualified_type (type, (TYPE_QUALS (type)
7792 | (TREE_READONLY (exp)
7793 * TYPE_QUAL_CONST))),
7794 TREE_ADDRESSABLE (exp), 1);
7797 store_constructor (exp, target, 0, int_expr_size (exp));
7798 return target;
7802 /* expand_expr: generate code for computing expression EXP.
7803 An rtx for the computed value is returned. The value is never null.
7804 In the case of a void EXP, const0_rtx is returned.
7806 The value may be stored in TARGET if TARGET is nonzero.
7807 TARGET is just a suggestion; callers must assume that
7808 the rtx returned may not be the same as TARGET.
7810 If TARGET is CONST0_RTX, it means that the value will be ignored.
7812 If TMODE is not VOIDmode, it suggests generating the
7813 result in mode TMODE. But this is done only when convenient.
7814 Otherwise, TMODE is ignored and the value generated in its natural mode.
7815 TMODE is just a suggestion; callers must assume that
7816 the rtx returned may not have mode TMODE.
7818 Note that TARGET may have neither TMODE nor MODE. In that case, it
7819 probably will not be used.
7821 If MODIFIER is EXPAND_SUM then when EXP is an addition
7822 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7823 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7824 products as above, or REG or MEM, or constant.
7825 Ordinarily in such cases we would output mul or add instructions
7826 and then return a pseudo reg containing the sum.
7828 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7829 it also marks a label as absolutely required (it can't be dead).
7830 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7831 This is used for outputting expressions used in initializers.
7833 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7834 with a constant address even if that address is not normally legitimate.
7835 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7837 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7838 a call parameter. Such targets require special care as we haven't yet
7839 marked TARGET so that it's safe from being trashed by libcalls. We
7840 don't want to use TARGET for anything but the final result;
7841 Intermediate values must go elsewhere. Additionally, calls to
7842 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7844 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7845 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7846 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7847 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7848 recursively. */
7851 expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
7852 enum expand_modifier modifier, rtx *alt_rtl)
7854 rtx ret;
7856 /* Handle ERROR_MARK before anybody tries to access its type. */
7857 if (TREE_CODE (exp) == ERROR_MARK
7858 || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
7860 ret = CONST0_RTX (tmode);
7861 return ret ? ret : const0_rtx;
7864 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
7865 return ret;
7868 /* Try to expand the conditional expression which is represented by
7869 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7870 return the rtl reg which repsents the result. Otherwise return
7871 NULL_RTL. */
7873 static rtx
7874 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
7875 tree treeop1 ATTRIBUTE_UNUSED,
7876 tree treeop2 ATTRIBUTE_UNUSED)
7878 #ifdef HAVE_conditional_move
7879 rtx insn;
7880 rtx op00, op01, op1, op2;
7881 enum rtx_code comparison_code;
7882 enum machine_mode comparison_mode;
7883 gimple srcstmt;
7884 rtx temp;
7885 tree type = TREE_TYPE (treeop1);
7886 int unsignedp = TYPE_UNSIGNED (type);
7887 enum machine_mode mode = TYPE_MODE (type);
7888 enum machine_mode orig_mode = mode;
7890 /* If we cannot do a conditional move on the mode, try doing it
7891 with the promoted mode. */
7892 if (!can_conditionally_move_p (mode))
7894 mode = promote_mode (type, mode, &unsignedp);
7895 if (!can_conditionally_move_p (mode))
7896 return NULL_RTX;
7897 temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */
7899 else
7900 temp = assign_temp (type, 0, 1);
7902 start_sequence ();
7903 expand_operands (treeop1, treeop2,
7904 temp, &op1, &op2, EXPAND_NORMAL);
7906 if (TREE_CODE (treeop0) == SSA_NAME
7907 && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison)))
7909 tree type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
7910 enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
7911 op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
7912 op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
7913 comparison_mode = TYPE_MODE (type);
7914 unsignedp = TYPE_UNSIGNED (type);
7915 comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
7917 else if (TREE_CODE_CLASS (TREE_CODE (treeop0)) == tcc_comparison)
7919 tree type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
7920 enum tree_code cmpcode = TREE_CODE (treeop0);
7921 op00 = expand_normal (TREE_OPERAND (treeop0, 0));
7922 op01 = expand_normal (TREE_OPERAND (treeop0, 1));
7923 unsignedp = TYPE_UNSIGNED (type);
7924 comparison_mode = TYPE_MODE (type);
7925 comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
7927 else
7929 op00 = expand_normal (treeop0);
7930 op01 = const0_rtx;
7931 comparison_code = NE;
7932 comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
7935 if (GET_MODE (op1) != mode)
7936 op1 = gen_lowpart (mode, op1);
7938 if (GET_MODE (op2) != mode)
7939 op2 = gen_lowpart (mode, op2);
7941 /* Try to emit the conditional move. */
7942 insn = emit_conditional_move (temp, comparison_code,
7943 op00, op01, comparison_mode,
7944 op1, op2, mode,
7945 unsignedp);
7947 /* If we could do the conditional move, emit the sequence,
7948 and return. */
7949 if (insn)
7951 rtx seq = get_insns ();
7952 end_sequence ();
7953 emit_insn (seq);
7954 return convert_modes (orig_mode, mode, temp, 0);
7957 /* Otherwise discard the sequence and fall back to code with
7958 branches. */
7959 end_sequence ();
7960 #endif
7961 return NULL_RTX;
7965 expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
7966 enum expand_modifier modifier)
7968 rtx op0, op1, op2, temp;
7969 tree type;
7970 int unsignedp;
7971 enum machine_mode mode;
7972 enum tree_code code = ops->code;
7973 optab this_optab;
7974 rtx subtarget, original_target;
7975 int ignore;
7976 bool reduce_bit_field;
7977 location_t loc = ops->location;
7978 tree treeop0, treeop1, treeop2;
7979 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
7980 ? reduce_to_bit_field_precision ((expr), \
7981 target, \
7982 type) \
7983 : (expr))
7985 type = ops->type;
7986 mode = TYPE_MODE (type);
7987 unsignedp = TYPE_UNSIGNED (type);
7989 treeop0 = ops->op0;
7990 treeop1 = ops->op1;
7991 treeop2 = ops->op2;
7993 /* We should be called only on simple (binary or unary) expressions,
7994 exactly those that are valid in gimple expressions that aren't
7995 GIMPLE_SINGLE_RHS (or invalid). */
7996 gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
7997 || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
7998 || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
8000 ignore = (target == const0_rtx
8001 || ((CONVERT_EXPR_CODE_P (code)
8002 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
8003 && TREE_CODE (type) == VOID_TYPE));
8005 /* We should be called only if we need the result. */
8006 gcc_assert (!ignore);
8008 /* An operation in what may be a bit-field type needs the
8009 result to be reduced to the precision of the bit-field type,
8010 which is narrower than that of the type's mode. */
8011 reduce_bit_field = (INTEGRAL_TYPE_P (type)
8012 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
8014 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
8015 target = 0;
8017 /* Use subtarget as the target for operand 0 of a binary operation. */
8018 subtarget = get_subtarget (target);
8019 original_target = target;
8021 switch (code)
8023 case NON_LVALUE_EXPR:
8024 case PAREN_EXPR:
8025 CASE_CONVERT:
8026 if (treeop0 == error_mark_node)
8027 return const0_rtx;
8029 if (TREE_CODE (type) == UNION_TYPE)
8031 tree valtype = TREE_TYPE (treeop0);
8033 /* If both input and output are BLKmode, this conversion isn't doing
8034 anything except possibly changing memory attribute. */
8035 if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
8037 rtx result = expand_expr (treeop0, target, tmode,
8038 modifier);
8040 result = copy_rtx (result);
8041 set_mem_attributes (result, type, 0);
8042 return result;
8045 if (target == 0)
8047 if (TYPE_MODE (type) != BLKmode)
8048 target = gen_reg_rtx (TYPE_MODE (type));
8049 else
8050 target = assign_temp (type, 1, 1);
8053 if (MEM_P (target))
8054 /* Store data into beginning of memory target. */
8055 store_expr (treeop0,
8056 adjust_address (target, TYPE_MODE (valtype), 0),
8057 modifier == EXPAND_STACK_PARM,
8058 false);
8060 else
8062 gcc_assert (REG_P (target));
8064 /* Store this field into a union of the proper type. */
8065 store_field (target,
8066 MIN ((int_size_in_bytes (TREE_TYPE
8067 (treeop0))
8068 * BITS_PER_UNIT),
8069 (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
8070 0, 0, 0, TYPE_MODE (valtype), treeop0, 0, false);
8073 /* Return the entire union. */
8074 return target;
8077 if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
8079 op0 = expand_expr (treeop0, target, VOIDmode,
8080 modifier);
8082 /* If the signedness of the conversion differs and OP0 is
8083 a promoted SUBREG, clear that indication since we now
8084 have to do the proper extension. */
8085 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)) != unsignedp
8086 && GET_CODE (op0) == SUBREG)
8087 SUBREG_PROMOTED_VAR_P (op0) = 0;
8089 return REDUCE_BIT_FIELD (op0);
8092 op0 = expand_expr (treeop0, NULL_RTX, mode,
8093 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
8094 if (GET_MODE (op0) == mode)
8097 /* If OP0 is a constant, just convert it into the proper mode. */
8098 else if (CONSTANT_P (op0))
8100 tree inner_type = TREE_TYPE (treeop0);
8101 enum machine_mode inner_mode = GET_MODE (op0);
8103 if (inner_mode == VOIDmode)
8104 inner_mode = TYPE_MODE (inner_type);
8106 if (modifier == EXPAND_INITIALIZER)
8107 op0 = simplify_gen_subreg (mode, op0, inner_mode,
8108 subreg_lowpart_offset (mode,
8109 inner_mode));
8110 else
8111 op0= convert_modes (mode, inner_mode, op0,
8112 TYPE_UNSIGNED (inner_type));
8115 else if (modifier == EXPAND_INITIALIZER)
8116 op0 = gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
8118 else if (target == 0)
8119 op0 = convert_to_mode (mode, op0,
8120 TYPE_UNSIGNED (TREE_TYPE
8121 (treeop0)));
8122 else
8124 convert_move (target, op0,
8125 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8126 op0 = target;
8129 return REDUCE_BIT_FIELD (op0);
8131 case ADDR_SPACE_CONVERT_EXPR:
8133 tree treeop0_type = TREE_TYPE (treeop0);
8134 addr_space_t as_to;
8135 addr_space_t as_from;
8137 gcc_assert (POINTER_TYPE_P (type));
8138 gcc_assert (POINTER_TYPE_P (treeop0_type));
8140 as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
8141 as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
8143 /* Conversions between pointers to the same address space should
8144 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8145 gcc_assert (as_to != as_from);
8147 /* Ask target code to handle conversion between pointers
8148 to overlapping address spaces. */
8149 if (targetm.addr_space.subset_p (as_to, as_from)
8150 || targetm.addr_space.subset_p (as_from, as_to))
8152 op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
8153 op0 = targetm.addr_space.convert (op0, treeop0_type, type);
8154 gcc_assert (op0);
8155 return op0;
8158 /* For disjoint address spaces, converting anything but
8159 a null pointer invokes undefined behaviour. We simply
8160 always return a null pointer here. */
8161 return CONST0_RTX (mode);
8164 case POINTER_PLUS_EXPR:
8165 /* Even though the sizetype mode and the pointer's mode can be different
8166 expand is able to handle this correctly and get the correct result out
8167 of the PLUS_EXPR code. */
8168 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8169 if sizetype precision is smaller than pointer precision. */
8170 if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
8171 treeop1 = fold_convert_loc (loc, type,
8172 fold_convert_loc (loc, ssizetype,
8173 treeop1));
8174 /* If sizetype precision is larger than pointer precision, truncate the
8175 offset to have matching modes. */
8176 else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
8177 treeop1 = fold_convert_loc (loc, type, treeop1);
8179 case PLUS_EXPR:
8180 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8181 something else, make sure we add the register to the constant and
8182 then to the other thing. This case can occur during strength
8183 reduction and doing it this way will produce better code if the
8184 frame pointer or argument pointer is eliminated.
8186 fold-const.c will ensure that the constant is always in the inner
8187 PLUS_EXPR, so the only case we need to do anything about is if
8188 sp, ap, or fp is our second argument, in which case we must swap
8189 the innermost first argument and our second argument. */
8191 if (TREE_CODE (treeop0) == PLUS_EXPR
8192 && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
8193 && TREE_CODE (treeop1) == VAR_DECL
8194 && (DECL_RTL (treeop1) == frame_pointer_rtx
8195 || DECL_RTL (treeop1) == stack_pointer_rtx
8196 || DECL_RTL (treeop1) == arg_pointer_rtx))
8198 gcc_unreachable ();
8201 /* If the result is to be ptr_mode and we are adding an integer to
8202 something, we might be forming a constant. So try to use
8203 plus_constant. If it produces a sum and we can't accept it,
8204 use force_operand. This allows P = &ARR[const] to generate
8205 efficient code on machines where a SYMBOL_REF is not a valid
8206 address.
8208 If this is an EXPAND_SUM call, always return the sum. */
8209 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
8210 || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
8212 if (modifier == EXPAND_STACK_PARM)
8213 target = 0;
8214 if (TREE_CODE (treeop0) == INTEGER_CST
8215 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8216 && TREE_CONSTANT (treeop1))
8218 rtx constant_part;
8220 op1 = expand_expr (treeop1, subtarget, VOIDmode,
8221 EXPAND_SUM);
8222 /* Use immed_double_const to ensure that the constant is
8223 truncated according to the mode of OP1, then sign extended
8224 to a HOST_WIDE_INT. Using the constant directly can result
8225 in non-canonical RTL in a 64x32 cross compile. */
8226 constant_part
8227 = immed_double_const (TREE_INT_CST_LOW (treeop0),
8228 (HOST_WIDE_INT) 0,
8229 TYPE_MODE (TREE_TYPE (treeop1)));
8230 op1 = plus_constant (mode, op1, INTVAL (constant_part));
8231 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8232 op1 = force_operand (op1, target);
8233 return REDUCE_BIT_FIELD (op1);
8236 else if (TREE_CODE (treeop1) == INTEGER_CST
8237 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8238 && TREE_CONSTANT (treeop0))
8240 rtx constant_part;
8242 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8243 (modifier == EXPAND_INITIALIZER
8244 ? EXPAND_INITIALIZER : EXPAND_SUM));
8245 if (! CONSTANT_P (op0))
8247 op1 = expand_expr (treeop1, NULL_RTX,
8248 VOIDmode, modifier);
8249 /* Return a PLUS if modifier says it's OK. */
8250 if (modifier == EXPAND_SUM
8251 || modifier == EXPAND_INITIALIZER)
8252 return simplify_gen_binary (PLUS, mode, op0, op1);
8253 goto binop2;
8255 /* Use immed_double_const to ensure that the constant is
8256 truncated according to the mode of OP1, then sign extended
8257 to a HOST_WIDE_INT. Using the constant directly can result
8258 in non-canonical RTL in a 64x32 cross compile. */
8259 constant_part
8260 = immed_double_const (TREE_INT_CST_LOW (treeop1),
8261 (HOST_WIDE_INT) 0,
8262 TYPE_MODE (TREE_TYPE (treeop0)));
8263 op0 = plus_constant (mode, op0, INTVAL (constant_part));
8264 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8265 op0 = force_operand (op0, target);
8266 return REDUCE_BIT_FIELD (op0);
8270 /* Use TER to expand pointer addition of a negated value
8271 as pointer subtraction. */
8272 if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
8273 || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
8274 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
8275 && TREE_CODE (treeop1) == SSA_NAME
8276 && TYPE_MODE (TREE_TYPE (treeop0))
8277 == TYPE_MODE (TREE_TYPE (treeop1)))
8279 gimple def = get_def_for_expr (treeop1, NEGATE_EXPR);
8280 if (def)
8282 treeop1 = gimple_assign_rhs1 (def);
8283 code = MINUS_EXPR;
8284 goto do_minus;
8288 /* No sense saving up arithmetic to be done
8289 if it's all in the wrong mode to form part of an address.
8290 And force_operand won't know whether to sign-extend or
8291 zero-extend. */
8292 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8293 || mode != ptr_mode)
8295 expand_operands (treeop0, treeop1,
8296 subtarget, &op0, &op1, EXPAND_NORMAL);
8297 if (op0 == const0_rtx)
8298 return op1;
8299 if (op1 == const0_rtx)
8300 return op0;
8301 goto binop2;
8304 expand_operands (treeop0, treeop1,
8305 subtarget, &op0, &op1, modifier);
8306 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8308 case MINUS_EXPR:
8309 do_minus:
8310 /* For initializers, we are allowed to return a MINUS of two
8311 symbolic constants. Here we handle all cases when both operands
8312 are constant. */
8313 /* Handle difference of two symbolic constants,
8314 for the sake of an initializer. */
8315 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8316 && really_constant_p (treeop0)
8317 && really_constant_p (treeop1))
8319 expand_operands (treeop0, treeop1,
8320 NULL_RTX, &op0, &op1, modifier);
8322 /* If the last operand is a CONST_INT, use plus_constant of
8323 the negated constant. Else make the MINUS. */
8324 if (CONST_INT_P (op1))
8325 return REDUCE_BIT_FIELD (plus_constant (mode, op0,
8326 -INTVAL (op1)));
8327 else
8328 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode, op0, op1));
8331 /* No sense saving up arithmetic to be done
8332 if it's all in the wrong mode to form part of an address.
8333 And force_operand won't know whether to sign-extend or
8334 zero-extend. */
8335 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8336 || mode != ptr_mode)
8337 goto binop;
8339 expand_operands (treeop0, treeop1,
8340 subtarget, &op0, &op1, modifier);
8342 /* Convert A - const to A + (-const). */
8343 if (CONST_INT_P (op1))
8345 op1 = negate_rtx (mode, op1);
8346 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8349 goto binop2;
8351 case WIDEN_MULT_PLUS_EXPR:
8352 case WIDEN_MULT_MINUS_EXPR:
8353 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8354 op2 = expand_normal (treeop2);
8355 target = expand_widen_pattern_expr (ops, op0, op1, op2,
8356 target, unsignedp);
8357 return target;
8359 case WIDEN_MULT_EXPR:
8360 /* If first operand is constant, swap them.
8361 Thus the following special case checks need only
8362 check the second operand. */
8363 if (TREE_CODE (treeop0) == INTEGER_CST)
8365 tree t1 = treeop0;
8366 treeop0 = treeop1;
8367 treeop1 = t1;
8370 /* First, check if we have a multiplication of one signed and one
8371 unsigned operand. */
8372 if (TREE_CODE (treeop1) != INTEGER_CST
8373 && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
8374 != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
8376 enum machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
8377 this_optab = usmul_widen_optab;
8378 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8379 != CODE_FOR_nothing)
8381 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8382 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8383 EXPAND_NORMAL);
8384 else
8385 expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
8386 EXPAND_NORMAL);
8387 /* op0 and op1 might still be constant, despite the above
8388 != INTEGER_CST check. Handle it. */
8389 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8391 op0 = convert_modes (innermode, mode, op0, true);
8392 op1 = convert_modes (innermode, mode, op1, false);
8393 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
8394 target, unsignedp));
8396 goto binop3;
8399 /* Check for a multiplication with matching signedness. */
8400 else if ((TREE_CODE (treeop1) == INTEGER_CST
8401 && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
8402 || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
8403 == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
8405 tree op0type = TREE_TYPE (treeop0);
8406 enum machine_mode innermode = TYPE_MODE (op0type);
8407 bool zextend_p = TYPE_UNSIGNED (op0type);
8408 optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
8409 this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
8411 if (TREE_CODE (treeop0) != INTEGER_CST)
8413 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8414 != CODE_FOR_nothing)
8416 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8417 EXPAND_NORMAL);
8418 /* op0 and op1 might still be constant, despite the above
8419 != INTEGER_CST check. Handle it. */
8420 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8422 widen_mult_const:
8423 op0 = convert_modes (innermode, mode, op0, zextend_p);
8425 = convert_modes (innermode, mode, op1,
8426 TYPE_UNSIGNED (TREE_TYPE (treeop1)));
8427 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
8428 target,
8429 unsignedp));
8431 temp = expand_widening_mult (mode, op0, op1, target,
8432 unsignedp, this_optab);
8433 return REDUCE_BIT_FIELD (temp);
8435 if (find_widening_optab_handler (other_optab, mode, innermode, 0)
8436 != CODE_FOR_nothing
8437 && innermode == word_mode)
8439 rtx htem, hipart;
8440 op0 = expand_normal (treeop0);
8441 if (TREE_CODE (treeop1) == INTEGER_CST)
8442 op1 = convert_modes (innermode, mode,
8443 expand_normal (treeop1),
8444 TYPE_UNSIGNED (TREE_TYPE (treeop1)));
8445 else
8446 op1 = expand_normal (treeop1);
8447 /* op0 and op1 might still be constant, despite the above
8448 != INTEGER_CST check. Handle it. */
8449 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8450 goto widen_mult_const;
8451 temp = expand_binop (mode, other_optab, op0, op1, target,
8452 unsignedp, OPTAB_LIB_WIDEN);
8453 hipart = gen_highpart (innermode, temp);
8454 htem = expand_mult_highpart_adjust (innermode, hipart,
8455 op0, op1, hipart,
8456 zextend_p);
8457 if (htem != hipart)
8458 emit_move_insn (hipart, htem);
8459 return REDUCE_BIT_FIELD (temp);
8463 treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
8464 treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
8465 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8466 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8468 case FMA_EXPR:
8470 optab opt = fma_optab;
8471 gimple def0, def2;
8473 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8474 call. */
8475 if (optab_handler (fma_optab, mode) == CODE_FOR_nothing)
8477 tree fn = mathfn_built_in (TREE_TYPE (treeop0), BUILT_IN_FMA);
8478 tree call_expr;
8480 gcc_assert (fn != NULL_TREE);
8481 call_expr = build_call_expr (fn, 3, treeop0, treeop1, treeop2);
8482 return expand_builtin (call_expr, target, subtarget, mode, false);
8485 def0 = get_def_for_expr (treeop0, NEGATE_EXPR);
8486 def2 = get_def_for_expr (treeop2, NEGATE_EXPR);
8488 op0 = op2 = NULL;
8490 if (def0 && def2
8491 && optab_handler (fnms_optab, mode) != CODE_FOR_nothing)
8493 opt = fnms_optab;
8494 op0 = expand_normal (gimple_assign_rhs1 (def0));
8495 op2 = expand_normal (gimple_assign_rhs1 (def2));
8497 else if (def0
8498 && optab_handler (fnma_optab, mode) != CODE_FOR_nothing)
8500 opt = fnma_optab;
8501 op0 = expand_normal (gimple_assign_rhs1 (def0));
8503 else if (def2
8504 && optab_handler (fms_optab, mode) != CODE_FOR_nothing)
8506 opt = fms_optab;
8507 op2 = expand_normal (gimple_assign_rhs1 (def2));
8510 if (op0 == NULL)
8511 op0 = expand_expr (treeop0, subtarget, VOIDmode, EXPAND_NORMAL);
8512 if (op2 == NULL)
8513 op2 = expand_normal (treeop2);
8514 op1 = expand_normal (treeop1);
8516 return expand_ternary_op (TYPE_MODE (type), opt,
8517 op0, op1, op2, target, 0);
8520 case MULT_EXPR:
8521 /* If this is a fixed-point operation, then we cannot use the code
8522 below because "expand_mult" doesn't support sat/no-sat fixed-point
8523 multiplications. */
8524 if (ALL_FIXED_POINT_MODE_P (mode))
8525 goto binop;
8527 /* If first operand is constant, swap them.
8528 Thus the following special case checks need only
8529 check the second operand. */
8530 if (TREE_CODE (treeop0) == INTEGER_CST)
8532 tree t1 = treeop0;
8533 treeop0 = treeop1;
8534 treeop1 = t1;
8537 /* Attempt to return something suitable for generating an
8538 indexed address, for machines that support that. */
8540 if (modifier == EXPAND_SUM && mode == ptr_mode
8541 && tree_fits_shwi_p (treeop1))
8543 tree exp1 = treeop1;
8545 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8546 EXPAND_SUM);
8548 if (!REG_P (op0))
8549 op0 = force_operand (op0, NULL_RTX);
8550 if (!REG_P (op0))
8551 op0 = copy_to_mode_reg (mode, op0);
8553 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0,
8554 gen_int_mode (tree_to_shwi (exp1),
8555 TYPE_MODE (TREE_TYPE (exp1)))));
8558 if (modifier == EXPAND_STACK_PARM)
8559 target = 0;
8561 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8562 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8564 case TRUNC_DIV_EXPR:
8565 case FLOOR_DIV_EXPR:
8566 case CEIL_DIV_EXPR:
8567 case ROUND_DIV_EXPR:
8568 case EXACT_DIV_EXPR:
8569 /* If this is a fixed-point operation, then we cannot use the code
8570 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8571 divisions. */
8572 if (ALL_FIXED_POINT_MODE_P (mode))
8573 goto binop;
8575 if (modifier == EXPAND_STACK_PARM)
8576 target = 0;
8577 /* Possible optimization: compute the dividend with EXPAND_SUM
8578 then if the divisor is constant can optimize the case
8579 where some terms of the dividend have coeffs divisible by it. */
8580 expand_operands (treeop0, treeop1,
8581 subtarget, &op0, &op1, EXPAND_NORMAL);
8582 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
8584 case RDIV_EXPR:
8585 goto binop;
8587 case MULT_HIGHPART_EXPR:
8588 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8589 temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
8590 gcc_assert (temp);
8591 return temp;
8593 case TRUNC_MOD_EXPR:
8594 case FLOOR_MOD_EXPR:
8595 case CEIL_MOD_EXPR:
8596 case ROUND_MOD_EXPR:
8597 if (modifier == EXPAND_STACK_PARM)
8598 target = 0;
8599 expand_operands (treeop0, treeop1,
8600 subtarget, &op0, &op1, EXPAND_NORMAL);
8601 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
8603 case FIXED_CONVERT_EXPR:
8604 op0 = expand_normal (treeop0);
8605 if (target == 0 || modifier == EXPAND_STACK_PARM)
8606 target = gen_reg_rtx (mode);
8608 if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
8609 && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8610 || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
8611 expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
8612 else
8613 expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
8614 return target;
8616 case FIX_TRUNC_EXPR:
8617 op0 = expand_normal (treeop0);
8618 if (target == 0 || modifier == EXPAND_STACK_PARM)
8619 target = gen_reg_rtx (mode);
8620 expand_fix (target, op0, unsignedp);
8621 return target;
8623 case FLOAT_EXPR:
8624 op0 = expand_normal (treeop0);
8625 if (target == 0 || modifier == EXPAND_STACK_PARM)
8626 target = gen_reg_rtx (mode);
8627 /* expand_float can't figure out what to do if FROM has VOIDmode.
8628 So give it the correct mode. With -O, cse will optimize this. */
8629 if (GET_MODE (op0) == VOIDmode)
8630 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
8631 op0);
8632 expand_float (target, op0,
8633 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8634 return target;
8636 case NEGATE_EXPR:
8637 op0 = expand_expr (treeop0, subtarget,
8638 VOIDmode, EXPAND_NORMAL);
8639 if (modifier == EXPAND_STACK_PARM)
8640 target = 0;
8641 temp = expand_unop (mode,
8642 optab_for_tree_code (NEGATE_EXPR, type,
8643 optab_default),
8644 op0, target, 0);
8645 gcc_assert (temp);
8646 return REDUCE_BIT_FIELD (temp);
8648 case ABS_EXPR:
8649 op0 = expand_expr (treeop0, subtarget,
8650 VOIDmode, EXPAND_NORMAL);
8651 if (modifier == EXPAND_STACK_PARM)
8652 target = 0;
8654 /* ABS_EXPR is not valid for complex arguments. */
8655 gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8656 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
8658 /* Unsigned abs is simply the operand. Testing here means we don't
8659 risk generating incorrect code below. */
8660 if (TYPE_UNSIGNED (type))
8661 return op0;
8663 return expand_abs (mode, op0, target, unsignedp,
8664 safe_from_p (target, treeop0, 1));
8666 case MAX_EXPR:
8667 case MIN_EXPR:
8668 target = original_target;
8669 if (target == 0
8670 || modifier == EXPAND_STACK_PARM
8671 || (MEM_P (target) && MEM_VOLATILE_P (target))
8672 || GET_MODE (target) != mode
8673 || (REG_P (target)
8674 && REGNO (target) < FIRST_PSEUDO_REGISTER))
8675 target = gen_reg_rtx (mode);
8676 expand_operands (treeop0, treeop1,
8677 target, &op0, &op1, EXPAND_NORMAL);
8679 /* First try to do it with a special MIN or MAX instruction.
8680 If that does not win, use a conditional jump to select the proper
8681 value. */
8682 this_optab = optab_for_tree_code (code, type, optab_default);
8683 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8684 OPTAB_WIDEN);
8685 if (temp != 0)
8686 return temp;
8688 /* At this point, a MEM target is no longer useful; we will get better
8689 code without it. */
8691 if (! REG_P (target))
8692 target = gen_reg_rtx (mode);
8694 /* If op1 was placed in target, swap op0 and op1. */
8695 if (target != op0 && target == op1)
8697 temp = op0;
8698 op0 = op1;
8699 op1 = temp;
8702 /* We generate better code and avoid problems with op1 mentioning
8703 target by forcing op1 into a pseudo if it isn't a constant. */
8704 if (! CONSTANT_P (op1))
8705 op1 = force_reg (mode, op1);
8708 enum rtx_code comparison_code;
8709 rtx cmpop1 = op1;
8711 if (code == MAX_EXPR)
8712 comparison_code = unsignedp ? GEU : GE;
8713 else
8714 comparison_code = unsignedp ? LEU : LE;
8716 /* Canonicalize to comparisons against 0. */
8717 if (op1 == const1_rtx)
8719 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8720 or (a != 0 ? a : 1) for unsigned.
8721 For MIN we are safe converting (a <= 1 ? a : 1)
8722 into (a <= 0 ? a : 1) */
8723 cmpop1 = const0_rtx;
8724 if (code == MAX_EXPR)
8725 comparison_code = unsignedp ? NE : GT;
8727 if (op1 == constm1_rtx && !unsignedp)
8729 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8730 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8731 cmpop1 = const0_rtx;
8732 if (code == MIN_EXPR)
8733 comparison_code = LT;
8735 #ifdef HAVE_conditional_move
8736 /* Use a conditional move if possible. */
8737 if (can_conditionally_move_p (mode))
8739 rtx insn;
8741 /* ??? Same problem as in expmed.c: emit_conditional_move
8742 forces a stack adjustment via compare_from_rtx, and we
8743 lose the stack adjustment if the sequence we are about
8744 to create is discarded. */
8745 do_pending_stack_adjust ();
8747 start_sequence ();
8749 /* Try to emit the conditional move. */
8750 insn = emit_conditional_move (target, comparison_code,
8751 op0, cmpop1, mode,
8752 op0, op1, mode,
8753 unsignedp);
8755 /* If we could do the conditional move, emit the sequence,
8756 and return. */
8757 if (insn)
8759 rtx seq = get_insns ();
8760 end_sequence ();
8761 emit_insn (seq);
8762 return target;
8765 /* Otherwise discard the sequence and fall back to code with
8766 branches. */
8767 end_sequence ();
8769 #endif
8770 if (target != op0)
8771 emit_move_insn (target, op0);
8773 temp = gen_label_rtx ();
8774 do_compare_rtx_and_jump (target, cmpop1, comparison_code,
8775 unsignedp, mode, NULL_RTX, NULL_RTX, temp,
8776 -1);
8778 emit_move_insn (target, op1);
8779 emit_label (temp);
8780 return target;
8782 case BIT_NOT_EXPR:
8783 op0 = expand_expr (treeop0, subtarget,
8784 VOIDmode, EXPAND_NORMAL);
8785 if (modifier == EXPAND_STACK_PARM)
8786 target = 0;
8787 /* In case we have to reduce the result to bitfield precision
8788 for unsigned bitfield expand this as XOR with a proper constant
8789 instead. */
8790 if (reduce_bit_field && TYPE_UNSIGNED (type))
8791 temp = expand_binop (mode, xor_optab, op0,
8792 immed_double_int_const
8793 (double_int::mask (TYPE_PRECISION (type)), mode),
8794 target, 1, OPTAB_LIB_WIDEN);
8795 else
8796 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
8797 gcc_assert (temp);
8798 return temp;
8800 /* ??? Can optimize bitwise operations with one arg constant.
8801 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8802 and (a bitwise1 b) bitwise2 b (etc)
8803 but that is probably not worth while. */
8805 case BIT_AND_EXPR:
8806 case BIT_IOR_EXPR:
8807 case BIT_XOR_EXPR:
8808 goto binop;
8810 case LROTATE_EXPR:
8811 case RROTATE_EXPR:
8812 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
8813 || (GET_MODE_PRECISION (TYPE_MODE (type))
8814 == TYPE_PRECISION (type)));
8815 /* fall through */
8817 case LSHIFT_EXPR:
8818 case RSHIFT_EXPR:
8819 /* If this is a fixed-point operation, then we cannot use the code
8820 below because "expand_shift" doesn't support sat/no-sat fixed-point
8821 shifts. */
8822 if (ALL_FIXED_POINT_MODE_P (mode))
8823 goto binop;
8825 if (! safe_from_p (subtarget, treeop1, 1))
8826 subtarget = 0;
8827 if (modifier == EXPAND_STACK_PARM)
8828 target = 0;
8829 op0 = expand_expr (treeop0, subtarget,
8830 VOIDmode, EXPAND_NORMAL);
8831 temp = expand_variable_shift (code, mode, op0, treeop1, target,
8832 unsignedp);
8833 if (code == LSHIFT_EXPR)
8834 temp = REDUCE_BIT_FIELD (temp);
8835 return temp;
8837 /* Could determine the answer when only additive constants differ. Also,
8838 the addition of one can be handled by changing the condition. */
8839 case LT_EXPR:
8840 case LE_EXPR:
8841 case GT_EXPR:
8842 case GE_EXPR:
8843 case EQ_EXPR:
8844 case NE_EXPR:
8845 case UNORDERED_EXPR:
8846 case ORDERED_EXPR:
8847 case UNLT_EXPR:
8848 case UNLE_EXPR:
8849 case UNGT_EXPR:
8850 case UNGE_EXPR:
8851 case UNEQ_EXPR:
8852 case LTGT_EXPR:
8853 temp = do_store_flag (ops,
8854 modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
8855 tmode != VOIDmode ? tmode : mode);
8856 if (temp)
8857 return temp;
8859 /* Use a compare and a jump for BLKmode comparisons, or for function
8860 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8862 if ((target == 0
8863 || modifier == EXPAND_STACK_PARM
8864 || ! safe_from_p (target, treeop0, 1)
8865 || ! safe_from_p (target, treeop1, 1)
8866 /* Make sure we don't have a hard reg (such as function's return
8867 value) live across basic blocks, if not optimizing. */
8868 || (!optimize && REG_P (target)
8869 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
8870 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
8872 emit_move_insn (target, const0_rtx);
8874 op1 = gen_label_rtx ();
8875 jumpifnot_1 (code, treeop0, treeop1, op1, -1);
8877 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
8878 emit_move_insn (target, constm1_rtx);
8879 else
8880 emit_move_insn (target, const1_rtx);
8882 emit_label (op1);
8883 return target;
8885 case COMPLEX_EXPR:
8886 /* Get the rtx code of the operands. */
8887 op0 = expand_normal (treeop0);
8888 op1 = expand_normal (treeop1);
8890 if (!target)
8891 target = gen_reg_rtx (TYPE_MODE (type));
8892 else
8893 /* If target overlaps with op1, then either we need to force
8894 op1 into a pseudo (if target also overlaps with op0),
8895 or write the complex parts in reverse order. */
8896 switch (GET_CODE (target))
8898 case CONCAT:
8899 if (reg_overlap_mentioned_p (XEXP (target, 0), op1))
8901 if (reg_overlap_mentioned_p (XEXP (target, 1), op0))
8903 complex_expr_force_op1:
8904 temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target)));
8905 emit_move_insn (temp, op1);
8906 op1 = temp;
8907 break;
8909 complex_expr_swap_order:
8910 /* Move the imaginary (op1) and real (op0) parts to their
8911 location. */
8912 write_complex_part (target, op1, true);
8913 write_complex_part (target, op0, false);
8915 return target;
8917 break;
8918 case MEM:
8919 temp = adjust_address_nv (target,
8920 GET_MODE_INNER (GET_MODE (target)), 0);
8921 if (reg_overlap_mentioned_p (temp, op1))
8923 enum machine_mode imode = GET_MODE_INNER (GET_MODE (target));
8924 temp = adjust_address_nv (target, imode,
8925 GET_MODE_SIZE (imode));
8926 if (reg_overlap_mentioned_p (temp, op0))
8927 goto complex_expr_force_op1;
8928 goto complex_expr_swap_order;
8930 break;
8931 default:
8932 if (reg_overlap_mentioned_p (target, op1))
8934 if (reg_overlap_mentioned_p (target, op0))
8935 goto complex_expr_force_op1;
8936 goto complex_expr_swap_order;
8938 break;
8941 /* Move the real (op0) and imaginary (op1) parts to their location. */
8942 write_complex_part (target, op0, false);
8943 write_complex_part (target, op1, true);
8945 return target;
8947 case WIDEN_SUM_EXPR:
8949 tree oprnd0 = treeop0;
8950 tree oprnd1 = treeop1;
8952 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8953 target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
8954 target, unsignedp);
8955 return target;
8958 case REDUC_MAX_EXPR:
8959 case REDUC_MIN_EXPR:
8960 case REDUC_PLUS_EXPR:
8962 op0 = expand_normal (treeop0);
8963 this_optab = optab_for_tree_code (code, type, optab_default);
8964 temp = expand_unop (mode, this_optab, op0, target, unsignedp);
8965 gcc_assert (temp);
8966 return temp;
8969 case VEC_LSHIFT_EXPR:
8970 case VEC_RSHIFT_EXPR:
8972 target = expand_vec_shift_expr (ops, target);
8973 return target;
8976 case VEC_UNPACK_HI_EXPR:
8977 case VEC_UNPACK_LO_EXPR:
8979 op0 = expand_normal (treeop0);
8980 temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
8981 target, unsignedp);
8982 gcc_assert (temp);
8983 return temp;
8986 case VEC_UNPACK_FLOAT_HI_EXPR:
8987 case VEC_UNPACK_FLOAT_LO_EXPR:
8989 op0 = expand_normal (treeop0);
8990 /* The signedness is determined from input operand. */
8991 temp = expand_widen_pattern_expr
8992 (ops, op0, NULL_RTX, NULL_RTX,
8993 target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8995 gcc_assert (temp);
8996 return temp;
8999 case VEC_WIDEN_MULT_HI_EXPR:
9000 case VEC_WIDEN_MULT_LO_EXPR:
9001 case VEC_WIDEN_MULT_EVEN_EXPR:
9002 case VEC_WIDEN_MULT_ODD_EXPR:
9003 case VEC_WIDEN_LSHIFT_HI_EXPR:
9004 case VEC_WIDEN_LSHIFT_LO_EXPR:
9005 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9006 target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
9007 target, unsignedp);
9008 gcc_assert (target);
9009 return target;
9011 case VEC_PACK_TRUNC_EXPR:
9012 case VEC_PACK_SAT_EXPR:
9013 case VEC_PACK_FIX_TRUNC_EXPR:
9014 mode = TYPE_MODE (TREE_TYPE (treeop0));
9015 goto binop;
9017 case VEC_PERM_EXPR:
9018 expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
9019 op2 = expand_normal (treeop2);
9021 /* Careful here: if the target doesn't support integral vector modes,
9022 a constant selection vector could wind up smooshed into a normal
9023 integral constant. */
9024 if (CONSTANT_P (op2) && GET_CODE (op2) != CONST_VECTOR)
9026 tree sel_type = TREE_TYPE (treeop2);
9027 enum machine_mode vmode
9028 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type)),
9029 TYPE_VECTOR_SUBPARTS (sel_type));
9030 gcc_assert (GET_MODE_CLASS (vmode) == MODE_VECTOR_INT);
9031 op2 = simplify_subreg (vmode, op2, TYPE_MODE (sel_type), 0);
9032 gcc_assert (op2 && GET_CODE (op2) == CONST_VECTOR);
9034 else
9035 gcc_assert (GET_MODE_CLASS (GET_MODE (op2)) == MODE_VECTOR_INT);
9037 temp = expand_vec_perm (mode, op0, op1, op2, target);
9038 gcc_assert (temp);
9039 return temp;
9041 case DOT_PROD_EXPR:
9043 tree oprnd0 = treeop0;
9044 tree oprnd1 = treeop1;
9045 tree oprnd2 = treeop2;
9046 rtx op2;
9048 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9049 op2 = expand_normal (oprnd2);
9050 target = expand_widen_pattern_expr (ops, op0, op1, op2,
9051 target, unsignedp);
9052 return target;
9055 case REALIGN_LOAD_EXPR:
9057 tree oprnd0 = treeop0;
9058 tree oprnd1 = treeop1;
9059 tree oprnd2 = treeop2;
9060 rtx op2;
9062 this_optab = optab_for_tree_code (code, type, optab_default);
9063 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9064 op2 = expand_normal (oprnd2);
9065 temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
9066 target, unsignedp);
9067 gcc_assert (temp);
9068 return temp;
9071 case COND_EXPR:
9072 /* A COND_EXPR with its type being VOID_TYPE represents a
9073 conditional jump and is handled in
9074 expand_gimple_cond_expr. */
9075 gcc_assert (!VOID_TYPE_P (type));
9077 /* Note that COND_EXPRs whose type is a structure or union
9078 are required to be constructed to contain assignments of
9079 a temporary variable, so that we can evaluate them here
9080 for side effect only. If type is void, we must do likewise. */
9082 gcc_assert (!TREE_ADDRESSABLE (type)
9083 && !ignore
9084 && TREE_TYPE (treeop1) != void_type_node
9085 && TREE_TYPE (treeop2) != void_type_node);
9087 temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
9088 if (temp)
9089 return temp;
9091 /* If we are not to produce a result, we have no target. Otherwise,
9092 if a target was specified use it; it will not be used as an
9093 intermediate target unless it is safe. If no target, use a
9094 temporary. */
9096 if (modifier != EXPAND_STACK_PARM
9097 && original_target
9098 && safe_from_p (original_target, treeop0, 1)
9099 && GET_MODE (original_target) == mode
9100 && !MEM_P (original_target))
9101 temp = original_target;
9102 else
9103 temp = assign_temp (type, 0, 1);
9105 do_pending_stack_adjust ();
9106 NO_DEFER_POP;
9107 op0 = gen_label_rtx ();
9108 op1 = gen_label_rtx ();
9109 jumpifnot (treeop0, op0, -1);
9110 store_expr (treeop1, temp,
9111 modifier == EXPAND_STACK_PARM,
9112 false);
9114 emit_jump_insn (gen_jump (op1));
9115 emit_barrier ();
9116 emit_label (op0);
9117 store_expr (treeop2, temp,
9118 modifier == EXPAND_STACK_PARM,
9119 false);
9121 emit_label (op1);
9122 OK_DEFER_POP;
9123 return temp;
9125 case VEC_COND_EXPR:
9126 target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target);
9127 return target;
9129 default:
9130 gcc_unreachable ();
9133 /* Here to do an ordinary binary operator. */
9134 binop:
9135 expand_operands (treeop0, treeop1,
9136 subtarget, &op0, &op1, EXPAND_NORMAL);
9137 binop2:
9138 this_optab = optab_for_tree_code (code, type, optab_default);
9139 binop3:
9140 if (modifier == EXPAND_STACK_PARM)
9141 target = 0;
9142 temp = expand_binop (mode, this_optab, op0, op1, target,
9143 unsignedp, OPTAB_LIB_WIDEN);
9144 gcc_assert (temp);
9145 /* Bitwise operations do not need bitfield reduction as we expect their
9146 operands being properly truncated. */
9147 if (code == BIT_XOR_EXPR
9148 || code == BIT_AND_EXPR
9149 || code == BIT_IOR_EXPR)
9150 return temp;
9151 return REDUCE_BIT_FIELD (temp);
9153 #undef REDUCE_BIT_FIELD
9156 /* Return TRUE if expression STMT is suitable for replacement.
9157 Never consider memory loads as replaceable, because those don't ever lead
9158 into constant expressions. */
9160 static bool
9161 stmt_is_replaceable_p (gimple stmt)
9163 if (ssa_is_replaceable_p (stmt))
9165 /* Don't move around loads. */
9166 if (!gimple_assign_single_p (stmt)
9167 || is_gimple_val (gimple_assign_rhs1 (stmt)))
9168 return true;
9170 return false;
9174 expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
9175 enum expand_modifier modifier, rtx *alt_rtl)
9177 rtx op0, op1, temp, decl_rtl;
9178 tree type;
9179 int unsignedp;
9180 enum machine_mode mode;
9181 enum tree_code code = TREE_CODE (exp);
9182 rtx subtarget, original_target;
9183 int ignore;
9184 tree context;
9185 bool reduce_bit_field;
9186 location_t loc = EXPR_LOCATION (exp);
9187 struct separate_ops ops;
9188 tree treeop0, treeop1, treeop2;
9189 tree ssa_name = NULL_TREE;
9190 gimple g;
9192 type = TREE_TYPE (exp);
9193 mode = TYPE_MODE (type);
9194 unsignedp = TYPE_UNSIGNED (type);
9196 treeop0 = treeop1 = treeop2 = NULL_TREE;
9197 if (!VL_EXP_CLASS_P (exp))
9198 switch (TREE_CODE_LENGTH (code))
9200 default:
9201 case 3: treeop2 = TREE_OPERAND (exp, 2);
9202 case 2: treeop1 = TREE_OPERAND (exp, 1);
9203 case 1: treeop0 = TREE_OPERAND (exp, 0);
9204 case 0: break;
9206 ops.code = code;
9207 ops.type = type;
9208 ops.op0 = treeop0;
9209 ops.op1 = treeop1;
9210 ops.op2 = treeop2;
9211 ops.location = loc;
9213 ignore = (target == const0_rtx
9214 || ((CONVERT_EXPR_CODE_P (code)
9215 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
9216 && TREE_CODE (type) == VOID_TYPE));
9218 /* An operation in what may be a bit-field type needs the
9219 result to be reduced to the precision of the bit-field type,
9220 which is narrower than that of the type's mode. */
9221 reduce_bit_field = (!ignore
9222 && INTEGRAL_TYPE_P (type)
9223 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
9225 /* If we are going to ignore this result, we need only do something
9226 if there is a side-effect somewhere in the expression. If there
9227 is, short-circuit the most common cases here. Note that we must
9228 not call expand_expr with anything but const0_rtx in case this
9229 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9231 if (ignore)
9233 if (! TREE_SIDE_EFFECTS (exp))
9234 return const0_rtx;
9236 /* Ensure we reference a volatile object even if value is ignored, but
9237 don't do this if all we are doing is taking its address. */
9238 if (TREE_THIS_VOLATILE (exp)
9239 && TREE_CODE (exp) != FUNCTION_DECL
9240 && mode != VOIDmode && mode != BLKmode
9241 && modifier != EXPAND_CONST_ADDRESS)
9243 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
9244 if (MEM_P (temp))
9245 copy_to_reg (temp);
9246 return const0_rtx;
9249 if (TREE_CODE_CLASS (code) == tcc_unary
9250 || code == BIT_FIELD_REF
9251 || code == COMPONENT_REF
9252 || code == INDIRECT_REF)
9253 return expand_expr (treeop0, const0_rtx, VOIDmode,
9254 modifier);
9256 else if (TREE_CODE_CLASS (code) == tcc_binary
9257 || TREE_CODE_CLASS (code) == tcc_comparison
9258 || code == ARRAY_REF || code == ARRAY_RANGE_REF)
9260 expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
9261 expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
9262 return const0_rtx;
9265 target = 0;
9268 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
9269 target = 0;
9271 /* Use subtarget as the target for operand 0 of a binary operation. */
9272 subtarget = get_subtarget (target);
9273 original_target = target;
9275 switch (code)
9277 case LABEL_DECL:
9279 tree function = decl_function_context (exp);
9281 temp = label_rtx (exp);
9282 temp = gen_rtx_LABEL_REF (Pmode, temp);
9284 if (function != current_function_decl
9285 && function != 0)
9286 LABEL_REF_NONLOCAL_P (temp) = 1;
9288 temp = gen_rtx_MEM (FUNCTION_MODE, temp);
9289 return temp;
9292 case SSA_NAME:
9293 /* ??? ivopts calls expander, without any preparation from
9294 out-of-ssa. So fake instructions as if this was an access to the
9295 base variable. This unnecessarily allocates a pseudo, see how we can
9296 reuse it, if partition base vars have it set already. */
9297 if (!currently_expanding_to_rtl)
9299 tree var = SSA_NAME_VAR (exp);
9300 if (var && DECL_RTL_SET_P (var))
9301 return DECL_RTL (var);
9302 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
9303 LAST_VIRTUAL_REGISTER + 1);
9306 g = get_gimple_for_ssa_name (exp);
9307 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9308 if (g == NULL
9309 && modifier == EXPAND_INITIALIZER
9310 && !SSA_NAME_IS_DEFAULT_DEF (exp)
9311 && (optimize || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
9312 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
9313 g = SSA_NAME_DEF_STMT (exp);
9314 if (g)
9316 rtx r;
9317 location_t saved_loc = curr_insn_location ();
9319 set_curr_insn_location (gimple_location (g));
9320 r = expand_expr_real (gimple_assign_rhs_to_tree (g), target,
9321 tmode, modifier, NULL);
9322 set_curr_insn_location (saved_loc);
9323 if (REG_P (r) && !REG_EXPR (r))
9324 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp), r);
9325 return r;
9328 ssa_name = exp;
9329 decl_rtl = get_rtx_for_ssa_name (ssa_name);
9330 exp = SSA_NAME_VAR (ssa_name);
9331 goto expand_decl_rtl;
9333 case PARM_DECL:
9334 case VAR_DECL:
9335 /* If a static var's type was incomplete when the decl was written,
9336 but the type is complete now, lay out the decl now. */
9337 if (DECL_SIZE (exp) == 0
9338 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
9339 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
9340 layout_decl (exp, 0);
9342 /* ... fall through ... */
9344 case FUNCTION_DECL:
9345 case RESULT_DECL:
9346 decl_rtl = DECL_RTL (exp);
9347 expand_decl_rtl:
9348 gcc_assert (decl_rtl);
9349 decl_rtl = copy_rtx (decl_rtl);
9350 /* Record writes to register variables. */
9351 if (modifier == EXPAND_WRITE
9352 && REG_P (decl_rtl)
9353 && HARD_REGISTER_P (decl_rtl))
9354 add_to_hard_reg_set (&crtl->asm_clobbers,
9355 GET_MODE (decl_rtl), REGNO (decl_rtl));
9357 /* Ensure variable marked as used even if it doesn't go through
9358 a parser. If it hasn't be used yet, write out an external
9359 definition. */
9360 TREE_USED (exp) = 1;
9362 /* Show we haven't gotten RTL for this yet. */
9363 temp = 0;
9365 /* Variables inherited from containing functions should have
9366 been lowered by this point. */
9367 context = decl_function_context (exp);
9368 gcc_assert (SCOPE_FILE_SCOPE_P (context)
9369 || context == current_function_decl
9370 || TREE_STATIC (exp)
9371 || DECL_EXTERNAL (exp)
9372 /* ??? C++ creates functions that are not TREE_STATIC. */
9373 || TREE_CODE (exp) == FUNCTION_DECL);
9375 /* This is the case of an array whose size is to be determined
9376 from its initializer, while the initializer is still being parsed.
9377 ??? We aren't parsing while expanding anymore. */
9379 if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
9380 temp = validize_mem (decl_rtl);
9382 /* If DECL_RTL is memory, we are in the normal case and the
9383 address is not valid, get the address into a register. */
9385 else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
9387 if (alt_rtl)
9388 *alt_rtl = decl_rtl;
9389 decl_rtl = use_anchored_address (decl_rtl);
9390 if (modifier != EXPAND_CONST_ADDRESS
9391 && modifier != EXPAND_SUM
9392 && !memory_address_addr_space_p (DECL_MODE (exp),
9393 XEXP (decl_rtl, 0),
9394 MEM_ADDR_SPACE (decl_rtl)))
9395 temp = replace_equiv_address (decl_rtl,
9396 copy_rtx (XEXP (decl_rtl, 0)));
9399 /* If we got something, return it. But first, set the alignment
9400 if the address is a register. */
9401 if (temp != 0)
9403 if (MEM_P (temp) && REG_P (XEXP (temp, 0)))
9404 mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
9406 return temp;
9409 /* If the mode of DECL_RTL does not match that of the decl,
9410 there are two cases: we are dealing with a BLKmode value
9411 that is returned in a register, or we are dealing with
9412 a promoted value. In the latter case, return a SUBREG
9413 of the wanted mode, but mark it so that we know that it
9414 was already extended. */
9415 if (REG_P (decl_rtl)
9416 && DECL_MODE (exp) != BLKmode
9417 && GET_MODE (decl_rtl) != DECL_MODE (exp))
9419 enum machine_mode pmode;
9421 /* Get the signedness to be used for this variable. Ensure we get
9422 the same mode we got when the variable was declared. */
9423 if (code == SSA_NAME
9424 && (g = SSA_NAME_DEF_STMT (ssa_name))
9425 && gimple_code (g) == GIMPLE_CALL)
9427 gcc_assert (!gimple_call_internal_p (g));
9428 pmode = promote_function_mode (type, mode, &unsignedp,
9429 gimple_call_fntype (g),
9432 else
9433 pmode = promote_decl_mode (exp, &unsignedp);
9434 gcc_assert (GET_MODE (decl_rtl) == pmode);
9436 temp = gen_lowpart_SUBREG (mode, decl_rtl);
9437 SUBREG_PROMOTED_VAR_P (temp) = 1;
9438 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
9439 return temp;
9442 return decl_rtl;
9444 case INTEGER_CST:
9445 temp = immed_double_const (TREE_INT_CST_LOW (exp),
9446 TREE_INT_CST_HIGH (exp), mode);
9448 return temp;
9450 case VECTOR_CST:
9452 tree tmp = NULL_TREE;
9453 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
9454 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
9455 || GET_MODE_CLASS (mode) == MODE_VECTOR_FRACT
9456 || GET_MODE_CLASS (mode) == MODE_VECTOR_UFRACT
9457 || GET_MODE_CLASS (mode) == MODE_VECTOR_ACCUM
9458 || GET_MODE_CLASS (mode) == MODE_VECTOR_UACCUM)
9459 return const_vector_from_tree (exp);
9460 if (GET_MODE_CLASS (mode) == MODE_INT)
9462 tree type_for_mode = lang_hooks.types.type_for_mode (mode, 1);
9463 if (type_for_mode)
9464 tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR, type_for_mode, exp);
9466 if (!tmp)
9468 vec<constructor_elt, va_gc> *v;
9469 unsigned i;
9470 vec_alloc (v, VECTOR_CST_NELTS (exp));
9471 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
9472 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
9473 tmp = build_constructor (type, v);
9475 return expand_expr (tmp, ignore ? const0_rtx : target,
9476 tmode, modifier);
9479 case CONST_DECL:
9480 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
9482 case REAL_CST:
9483 /* If optimized, generate immediate CONST_DOUBLE
9484 which will be turned into memory by reload if necessary.
9486 We used to force a register so that loop.c could see it. But
9487 this does not allow gen_* patterns to perform optimizations with
9488 the constants. It also produces two insns in cases like "x = 1.0;".
9489 On most machines, floating-point constants are not permitted in
9490 many insns, so we'd end up copying it to a register in any case.
9492 Now, we do the copying in expand_binop, if appropriate. */
9493 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
9494 TYPE_MODE (TREE_TYPE (exp)));
9496 case FIXED_CST:
9497 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
9498 TYPE_MODE (TREE_TYPE (exp)));
9500 case COMPLEX_CST:
9501 /* Handle evaluating a complex constant in a CONCAT target. */
9502 if (original_target && GET_CODE (original_target) == CONCAT)
9504 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
9505 rtx rtarg, itarg;
9507 rtarg = XEXP (original_target, 0);
9508 itarg = XEXP (original_target, 1);
9510 /* Move the real and imaginary parts separately. */
9511 op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
9512 op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
9514 if (op0 != rtarg)
9515 emit_move_insn (rtarg, op0);
9516 if (op1 != itarg)
9517 emit_move_insn (itarg, op1);
9519 return original_target;
9522 /* ... fall through ... */
9524 case STRING_CST:
9525 temp = expand_expr_constant (exp, 1, modifier);
9527 /* temp contains a constant address.
9528 On RISC machines where a constant address isn't valid,
9529 make some insns to get that address into a register. */
9530 if (modifier != EXPAND_CONST_ADDRESS
9531 && modifier != EXPAND_INITIALIZER
9532 && modifier != EXPAND_SUM
9533 && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
9534 MEM_ADDR_SPACE (temp)))
9535 return replace_equiv_address (temp,
9536 copy_rtx (XEXP (temp, 0)));
9537 return temp;
9539 case SAVE_EXPR:
9541 tree val = treeop0;
9542 rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl);
9544 if (!SAVE_EXPR_RESOLVED_P (exp))
9546 /* We can indeed still hit this case, typically via builtin
9547 expanders calling save_expr immediately before expanding
9548 something. Assume this means that we only have to deal
9549 with non-BLKmode values. */
9550 gcc_assert (GET_MODE (ret) != BLKmode);
9552 val = build_decl (curr_insn_location (),
9553 VAR_DECL, NULL, TREE_TYPE (exp));
9554 DECL_ARTIFICIAL (val) = 1;
9555 DECL_IGNORED_P (val) = 1;
9556 treeop0 = val;
9557 TREE_OPERAND (exp, 0) = treeop0;
9558 SAVE_EXPR_RESOLVED_P (exp) = 1;
9560 if (!CONSTANT_P (ret))
9561 ret = copy_to_reg (ret);
9562 SET_DECL_RTL (val, ret);
9565 return ret;
9569 case CONSTRUCTOR:
9570 /* If we don't need the result, just ensure we evaluate any
9571 subexpressions. */
9572 if (ignore)
9574 unsigned HOST_WIDE_INT idx;
9575 tree value;
9577 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
9578 expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
9580 return const0_rtx;
9583 return expand_constructor (exp, target, modifier, false);
9585 case TARGET_MEM_REF:
9587 addr_space_t as
9588 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9589 enum insn_code icode;
9590 unsigned int align;
9592 op0 = addr_for_mem_ref (exp, as, true);
9593 op0 = memory_address_addr_space (mode, op0, as);
9594 temp = gen_rtx_MEM (mode, op0);
9595 set_mem_attributes (temp, exp, 0);
9596 set_mem_addr_space (temp, as);
9597 align = get_object_alignment (exp);
9598 if (modifier != EXPAND_WRITE
9599 && modifier != EXPAND_MEMORY
9600 && mode != BLKmode
9601 && align < GET_MODE_ALIGNMENT (mode)
9602 /* If the target does not have special handling for unaligned
9603 loads of mode then it can use regular moves for them. */
9604 && ((icode = optab_handler (movmisalign_optab, mode))
9605 != CODE_FOR_nothing))
9607 struct expand_operand ops[2];
9609 /* We've already validated the memory, and we're creating a
9610 new pseudo destination. The predicates really can't fail,
9611 nor can the generator. */
9612 create_output_operand (&ops[0], NULL_RTX, mode);
9613 create_fixed_operand (&ops[1], temp);
9614 expand_insn (icode, 2, ops);
9615 temp = ops[0].value;
9617 return temp;
9620 case MEM_REF:
9622 addr_space_t as
9623 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9624 enum machine_mode address_mode;
9625 tree base = TREE_OPERAND (exp, 0);
9626 gimple def_stmt;
9627 enum insn_code icode;
9628 unsigned align;
9629 /* Handle expansion of non-aliased memory with non-BLKmode. That
9630 might end up in a register. */
9631 if (mem_ref_refers_to_non_mem_p (exp))
9633 HOST_WIDE_INT offset = mem_ref_offset (exp).low;
9634 base = TREE_OPERAND (base, 0);
9635 if (offset == 0
9636 && tree_fits_uhwi_p (TYPE_SIZE (type))
9637 && (GET_MODE_BITSIZE (DECL_MODE (base))
9638 == TREE_INT_CST_LOW (TYPE_SIZE (type))))
9639 return expand_expr (build1 (VIEW_CONVERT_EXPR, type, base),
9640 target, tmode, modifier);
9641 if (TYPE_MODE (type) == BLKmode)
9643 temp = assign_stack_temp (DECL_MODE (base),
9644 GET_MODE_SIZE (DECL_MODE (base)));
9645 store_expr (base, temp, 0, false);
9646 temp = adjust_address (temp, BLKmode, offset);
9647 set_mem_size (temp, int_size_in_bytes (type));
9648 return temp;
9650 exp = build3 (BIT_FIELD_REF, type, base, TYPE_SIZE (type),
9651 bitsize_int (offset * BITS_PER_UNIT));
9652 return expand_expr (exp, target, tmode, modifier);
9654 address_mode = targetm.addr_space.address_mode (as);
9655 base = TREE_OPERAND (exp, 0);
9656 if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
9658 tree mask = gimple_assign_rhs2 (def_stmt);
9659 base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
9660 gimple_assign_rhs1 (def_stmt), mask);
9661 TREE_OPERAND (exp, 0) = base;
9663 align = get_object_alignment (exp);
9664 op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
9665 op0 = memory_address_addr_space (mode, op0, as);
9666 if (!integer_zerop (TREE_OPERAND (exp, 1)))
9668 rtx off
9669 = immed_double_int_const (mem_ref_offset (exp), address_mode);
9670 op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
9671 op0 = memory_address_addr_space (mode, op0, as);
9673 temp = gen_rtx_MEM (mode, op0);
9674 set_mem_attributes (temp, exp, 0);
9675 set_mem_addr_space (temp, as);
9676 if (TREE_THIS_VOLATILE (exp))
9677 MEM_VOLATILE_P (temp) = 1;
9678 if (modifier != EXPAND_WRITE
9679 && modifier != EXPAND_MEMORY
9680 && mode != BLKmode
9681 && align < GET_MODE_ALIGNMENT (mode))
9683 if ((icode = optab_handler (movmisalign_optab, mode))
9684 != CODE_FOR_nothing)
9686 struct expand_operand ops[2];
9688 /* We've already validated the memory, and we're creating a
9689 new pseudo destination. The predicates really can't fail,
9690 nor can the generator. */
9691 create_output_operand (&ops[0], NULL_RTX, mode);
9692 create_fixed_operand (&ops[1], temp);
9693 expand_insn (icode, 2, ops);
9694 temp = ops[0].value;
9696 else if (SLOW_UNALIGNED_ACCESS (mode, align))
9697 temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode),
9698 0, TYPE_UNSIGNED (TREE_TYPE (exp)),
9699 (modifier == EXPAND_STACK_PARM
9700 ? NULL_RTX : target),
9701 mode, mode);
9703 return temp;
9706 case ARRAY_REF:
9709 tree array = treeop0;
9710 tree index = treeop1;
9711 tree init;
9713 /* Fold an expression like: "foo"[2].
9714 This is not done in fold so it won't happen inside &.
9715 Don't fold if this is for wide characters since it's too
9716 difficult to do correctly and this is a very rare case. */
9718 if (modifier != EXPAND_CONST_ADDRESS
9719 && modifier != EXPAND_INITIALIZER
9720 && modifier != EXPAND_MEMORY)
9722 tree t = fold_read_from_constant_string (exp);
9724 if (t)
9725 return expand_expr (t, target, tmode, modifier);
9728 /* If this is a constant index into a constant array,
9729 just get the value from the array. Handle both the cases when
9730 we have an explicit constructor and when our operand is a variable
9731 that was declared const. */
9733 if (modifier != EXPAND_CONST_ADDRESS
9734 && modifier != EXPAND_INITIALIZER
9735 && modifier != EXPAND_MEMORY
9736 && TREE_CODE (array) == CONSTRUCTOR
9737 && ! TREE_SIDE_EFFECTS (array)
9738 && TREE_CODE (index) == INTEGER_CST)
9740 unsigned HOST_WIDE_INT ix;
9741 tree field, value;
9743 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
9744 field, value)
9745 if (tree_int_cst_equal (field, index))
9747 if (!TREE_SIDE_EFFECTS (value))
9748 return expand_expr (fold (value), target, tmode, modifier);
9749 break;
9753 else if (optimize >= 1
9754 && modifier != EXPAND_CONST_ADDRESS
9755 && modifier != EXPAND_INITIALIZER
9756 && modifier != EXPAND_MEMORY
9757 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
9758 && TREE_CODE (index) == INTEGER_CST
9759 && (TREE_CODE (array) == VAR_DECL
9760 || TREE_CODE (array) == CONST_DECL)
9761 && (init = ctor_for_folding (array)) != error_mark_node)
9763 if (TREE_CODE (init) == CONSTRUCTOR)
9765 unsigned HOST_WIDE_INT ix;
9766 tree field, value;
9768 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
9769 field, value)
9770 if (tree_int_cst_equal (field, index))
9772 if (TREE_SIDE_EFFECTS (value))
9773 break;
9775 if (TREE_CODE (value) == CONSTRUCTOR)
9777 /* If VALUE is a CONSTRUCTOR, this
9778 optimization is only useful if
9779 this doesn't store the CONSTRUCTOR
9780 into memory. If it does, it is more
9781 efficient to just load the data from
9782 the array directly. */
9783 rtx ret = expand_constructor (value, target,
9784 modifier, true);
9785 if (ret == NULL_RTX)
9786 break;
9789 return
9790 expand_expr (fold (value), target, tmode, modifier);
9793 else if (TREE_CODE (init) == STRING_CST)
9795 tree low_bound = array_ref_low_bound (exp);
9796 tree index1 = fold_convert_loc (loc, sizetype, treeop1);
9798 /* Optimize the special case of a zero lower bound.
9800 We convert the lower bound to sizetype to avoid problems
9801 with constant folding. E.g. suppose the lower bound is
9802 1 and its mode is QI. Without the conversion
9803 (ARRAY + (INDEX - (unsigned char)1))
9804 becomes
9805 (ARRAY + (-(unsigned char)1) + INDEX)
9806 which becomes
9807 (ARRAY + 255 + INDEX). Oops! */
9808 if (!integer_zerop (low_bound))
9809 index1 = size_diffop_loc (loc, index1,
9810 fold_convert_loc (loc, sizetype,
9811 low_bound));
9813 if (compare_tree_int (index1, TREE_STRING_LENGTH (init)) < 0)
9815 tree type = TREE_TYPE (TREE_TYPE (init));
9816 enum machine_mode mode = TYPE_MODE (type);
9818 if (GET_MODE_CLASS (mode) == MODE_INT
9819 && GET_MODE_SIZE (mode) == 1)
9820 return gen_int_mode (TREE_STRING_POINTER (init)
9821 [TREE_INT_CST_LOW (index1)],
9822 mode);
9827 goto normal_inner_ref;
9829 case COMPONENT_REF:
9830 /* If the operand is a CONSTRUCTOR, we can just extract the
9831 appropriate field if it is present. */
9832 if (TREE_CODE (treeop0) == CONSTRUCTOR)
9834 unsigned HOST_WIDE_INT idx;
9835 tree field, value;
9837 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0),
9838 idx, field, value)
9839 if (field == treeop1
9840 /* We can normally use the value of the field in the
9841 CONSTRUCTOR. However, if this is a bitfield in
9842 an integral mode that we can fit in a HOST_WIDE_INT,
9843 we must mask only the number of bits in the bitfield,
9844 since this is done implicitly by the constructor. If
9845 the bitfield does not meet either of those conditions,
9846 we can't do this optimization. */
9847 && (! DECL_BIT_FIELD (field)
9848 || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
9849 && (GET_MODE_PRECISION (DECL_MODE (field))
9850 <= HOST_BITS_PER_WIDE_INT))))
9852 if (DECL_BIT_FIELD (field)
9853 && modifier == EXPAND_STACK_PARM)
9854 target = 0;
9855 op0 = expand_expr (value, target, tmode, modifier);
9856 if (DECL_BIT_FIELD (field))
9858 HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
9859 enum machine_mode imode = TYPE_MODE (TREE_TYPE (field));
9861 if (TYPE_UNSIGNED (TREE_TYPE (field)))
9863 op1 = gen_int_mode (((HOST_WIDE_INT) 1 << bitsize) - 1,
9864 imode);
9865 op0 = expand_and (imode, op0, op1, target);
9867 else
9869 int count = GET_MODE_PRECISION (imode) - bitsize;
9871 op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
9872 target, 0);
9873 op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
9874 target, 0);
9878 return op0;
9881 goto normal_inner_ref;
9883 case BIT_FIELD_REF:
9884 case ARRAY_RANGE_REF:
9885 normal_inner_ref:
9887 enum machine_mode mode1, mode2;
9888 HOST_WIDE_INT bitsize, bitpos;
9889 tree offset;
9890 int volatilep = 0, must_force_mem;
9891 tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
9892 &mode1, &unsignedp, &volatilep, true);
9893 rtx orig_op0, memloc;
9894 bool mem_attrs_from_type = false;
9896 /* If we got back the original object, something is wrong. Perhaps
9897 we are evaluating an expression too early. In any event, don't
9898 infinitely recurse. */
9899 gcc_assert (tem != exp);
9901 /* If TEM's type is a union of variable size, pass TARGET to the inner
9902 computation, since it will need a temporary and TARGET is known
9903 to have to do. This occurs in unchecked conversion in Ada. */
9904 orig_op0 = op0
9905 = expand_expr (tem,
9906 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
9907 && COMPLETE_TYPE_P (TREE_TYPE (tem))
9908 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
9909 != INTEGER_CST)
9910 && modifier != EXPAND_STACK_PARM
9911 ? target : NULL_RTX),
9912 VOIDmode,
9913 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
9915 /* If the bitfield is volatile, we want to access it in the
9916 field's mode, not the computed mode.
9917 If a MEM has VOIDmode (external with incomplete type),
9918 use BLKmode for it instead. */
9919 if (MEM_P (op0))
9921 if (volatilep && flag_strict_volatile_bitfields > 0)
9922 op0 = adjust_address (op0, mode1, 0);
9923 else if (GET_MODE (op0) == VOIDmode)
9924 op0 = adjust_address (op0, BLKmode, 0);
9927 mode2
9928 = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
9930 /* If we have either an offset, a BLKmode result, or a reference
9931 outside the underlying object, we must force it to memory.
9932 Such a case can occur in Ada if we have unchecked conversion
9933 of an expression from a scalar type to an aggregate type or
9934 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9935 passed a partially uninitialized object or a view-conversion
9936 to a larger size. */
9937 must_force_mem = (offset
9938 || mode1 == BLKmode
9939 || bitpos + bitsize > GET_MODE_BITSIZE (mode2));
9941 /* Handle CONCAT first. */
9942 if (GET_CODE (op0) == CONCAT && !must_force_mem)
9944 if (bitpos == 0
9945 && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)))
9946 return op0;
9947 if (bitpos == 0
9948 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
9949 && bitsize)
9951 op0 = XEXP (op0, 0);
9952 mode2 = GET_MODE (op0);
9954 else if (bitpos == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
9955 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1)))
9956 && bitpos
9957 && bitsize)
9959 op0 = XEXP (op0, 1);
9960 bitpos = 0;
9961 mode2 = GET_MODE (op0);
9963 else
9964 /* Otherwise force into memory. */
9965 must_force_mem = 1;
9968 /* If this is a constant, put it in a register if it is a legitimate
9969 constant and we don't need a memory reference. */
9970 if (CONSTANT_P (op0)
9971 && mode2 != BLKmode
9972 && targetm.legitimate_constant_p (mode2, op0)
9973 && !must_force_mem)
9974 op0 = force_reg (mode2, op0);
9976 /* Otherwise, if this is a constant, try to force it to the constant
9977 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9978 is a legitimate constant. */
9979 else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
9980 op0 = validize_mem (memloc);
9982 /* Otherwise, if this is a constant or the object is not in memory
9983 and need be, put it there. */
9984 else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
9986 tree nt = build_qualified_type (TREE_TYPE (tem),
9987 (TYPE_QUALS (TREE_TYPE (tem))
9988 | TYPE_QUAL_CONST));
9989 memloc = assign_temp (nt, 1, 1);
9990 emit_move_insn (memloc, op0);
9991 op0 = memloc;
9992 mem_attrs_from_type = true;
9995 if (offset)
9997 enum machine_mode address_mode;
9998 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
9999 EXPAND_SUM);
10001 gcc_assert (MEM_P (op0));
10003 address_mode = get_address_mode (op0);
10004 if (GET_MODE (offset_rtx) != address_mode)
10005 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
10007 if (GET_MODE (op0) == BLKmode
10008 /* A constant address in OP0 can have VOIDmode, we must
10009 not try to call force_reg in that case. */
10010 && GET_MODE (XEXP (op0, 0)) != VOIDmode
10011 && bitsize != 0
10012 && (bitpos % bitsize) == 0
10013 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
10014 && MEM_ALIGN (op0) == GET_MODE_ALIGNMENT (mode1))
10016 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
10017 bitpos = 0;
10020 op0 = offset_address (op0, offset_rtx,
10021 highest_pow2_factor (offset));
10024 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10025 record its alignment as BIGGEST_ALIGNMENT. */
10026 if (MEM_P (op0) && bitpos == 0 && offset != 0
10027 && is_aligning_offset (offset, tem))
10028 set_mem_align (op0, BIGGEST_ALIGNMENT);
10030 /* Don't forget about volatility even if this is a bitfield. */
10031 if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
10033 if (op0 == orig_op0)
10034 op0 = copy_rtx (op0);
10036 MEM_VOLATILE_P (op0) = 1;
10039 /* In cases where an aligned union has an unaligned object
10040 as a field, we might be extracting a BLKmode value from
10041 an integer-mode (e.g., SImode) object. Handle this case
10042 by doing the extract into an object as wide as the field
10043 (which we know to be the width of a basic mode), then
10044 storing into memory, and changing the mode to BLKmode. */
10045 if (mode1 == VOIDmode
10046 || REG_P (op0) || GET_CODE (op0) == SUBREG
10047 || (mode1 != BLKmode && ! direct_load[(int) mode1]
10048 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
10049 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
10050 && modifier != EXPAND_CONST_ADDRESS
10051 && modifier != EXPAND_INITIALIZER
10052 && modifier != EXPAND_MEMORY)
10053 /* If the field is volatile, we always want an aligned
10054 access. Do this in following two situations:
10055 1. the access is not already naturally
10056 aligned, otherwise "normal" (non-bitfield) volatile fields
10057 become non-addressable.
10058 2. the bitsize is narrower than the access size. Need
10059 to extract bitfields from the access. */
10060 || (volatilep && flag_strict_volatile_bitfields > 0
10061 && (bitpos % GET_MODE_ALIGNMENT (mode) != 0
10062 || (mode1 != BLKmode
10063 && bitsize < GET_MODE_SIZE (mode1) * BITS_PER_UNIT)))
10064 /* If the field isn't aligned enough to fetch as a memref,
10065 fetch it as a bit field. */
10066 || (mode1 != BLKmode
10067 && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
10068 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
10069 || (MEM_P (op0)
10070 && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
10071 || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
10072 && modifier != EXPAND_MEMORY
10073 && ((modifier == EXPAND_CONST_ADDRESS
10074 || modifier == EXPAND_INITIALIZER)
10075 ? STRICT_ALIGNMENT
10076 : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
10077 || (bitpos % BITS_PER_UNIT != 0)))
10078 /* If the type and the field are a constant size and the
10079 size of the type isn't the same size as the bitfield,
10080 we must use bitfield operations. */
10081 || (bitsize >= 0
10082 && TYPE_SIZE (TREE_TYPE (exp))
10083 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
10084 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
10085 bitsize)))
10087 enum machine_mode ext_mode = mode;
10089 if (ext_mode == BLKmode
10090 && ! (target != 0 && MEM_P (op0)
10091 && MEM_P (target)
10092 && bitpos % BITS_PER_UNIT == 0))
10093 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
10095 if (ext_mode == BLKmode)
10097 if (target == 0)
10098 target = assign_temp (type, 1, 1);
10100 if (bitsize == 0)
10101 return target;
10103 /* In this case, BITPOS must start at a byte boundary and
10104 TARGET, if specified, must be a MEM. */
10105 gcc_assert (MEM_P (op0)
10106 && (!target || MEM_P (target))
10107 && !(bitpos % BITS_PER_UNIT));
10109 emit_block_move (target,
10110 adjust_address (op0, VOIDmode,
10111 bitpos / BITS_PER_UNIT),
10112 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
10113 / BITS_PER_UNIT),
10114 (modifier == EXPAND_STACK_PARM
10115 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
10117 return target;
10120 op0 = validize_mem (op0);
10122 if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
10123 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10125 op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
10126 (modifier == EXPAND_STACK_PARM
10127 ? NULL_RTX : target),
10128 ext_mode, ext_mode);
10130 /* If the result is a record type and BITSIZE is narrower than
10131 the mode of OP0, an integral mode, and this is a big endian
10132 machine, we must put the field into the high-order bits. */
10133 if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
10134 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
10135 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
10136 op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
10137 GET_MODE_BITSIZE (GET_MODE (op0))
10138 - bitsize, op0, 1);
10140 /* If the result type is BLKmode, store the data into a temporary
10141 of the appropriate type, but with the mode corresponding to the
10142 mode for the data we have (op0's mode). It's tempting to make
10143 this a constant type, since we know it's only being stored once,
10144 but that can cause problems if we are taking the address of this
10145 COMPONENT_REF because the MEM of any reference via that address
10146 will have flags corresponding to the type, which will not
10147 necessarily be constant. */
10148 if (mode == BLKmode)
10150 rtx new_rtx;
10152 new_rtx = assign_stack_temp_for_type (ext_mode,
10153 GET_MODE_BITSIZE (ext_mode),
10154 type);
10155 emit_move_insn (new_rtx, op0);
10156 op0 = copy_rtx (new_rtx);
10157 PUT_MODE (op0, BLKmode);
10160 return op0;
10163 /* If the result is BLKmode, use that to access the object
10164 now as well. */
10165 if (mode == BLKmode)
10166 mode1 = BLKmode;
10168 /* Get a reference to just this component. */
10169 if (modifier == EXPAND_CONST_ADDRESS
10170 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
10171 op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
10172 else
10173 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
10175 if (op0 == orig_op0)
10176 op0 = copy_rtx (op0);
10178 /* If op0 is a temporary because of forcing to memory, pass only the
10179 type to set_mem_attributes so that the original expression is never
10180 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10181 if (mem_attrs_from_type)
10182 set_mem_attributes (op0, type, 0);
10183 else
10184 set_mem_attributes (op0, exp, 0);
10186 if (REG_P (XEXP (op0, 0)))
10187 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10189 MEM_VOLATILE_P (op0) |= volatilep;
10190 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
10191 || modifier == EXPAND_CONST_ADDRESS
10192 || modifier == EXPAND_INITIALIZER)
10193 return op0;
10195 if (target == 0)
10196 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
10198 convert_move (target, op0, unsignedp);
10199 return target;
10202 case OBJ_TYPE_REF:
10203 return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
10205 case CALL_EXPR:
10206 /* All valid uses of __builtin_va_arg_pack () are removed during
10207 inlining. */
10208 if (CALL_EXPR_VA_ARG_PACK (exp))
10209 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
10211 tree fndecl = get_callee_fndecl (exp), attr;
10213 if (fndecl
10214 && (attr = lookup_attribute ("error",
10215 DECL_ATTRIBUTES (fndecl))) != NULL)
10216 error ("%Kcall to %qs declared with attribute error: %s",
10217 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
10218 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
10219 if (fndecl
10220 && (attr = lookup_attribute ("warning",
10221 DECL_ATTRIBUTES (fndecl))) != NULL)
10222 warning_at (tree_nonartificial_location (exp),
10223 0, "%Kcall to %qs declared with attribute warning: %s",
10224 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
10225 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
10227 /* Check for a built-in function. */
10228 if (fndecl && DECL_BUILT_IN (fndecl))
10230 gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
10231 return expand_builtin (exp, target, subtarget, tmode, ignore);
10234 return expand_call (exp, target, ignore);
10236 case VIEW_CONVERT_EXPR:
10237 op0 = NULL_RTX;
10239 /* If we are converting to BLKmode, try to avoid an intermediate
10240 temporary by fetching an inner memory reference. */
10241 if (mode == BLKmode
10242 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
10243 && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
10244 && handled_component_p (treeop0))
10246 enum machine_mode mode1;
10247 HOST_WIDE_INT bitsize, bitpos;
10248 tree offset;
10249 int unsignedp;
10250 int volatilep = 0;
10251 tree tem
10252 = get_inner_reference (treeop0, &bitsize, &bitpos,
10253 &offset, &mode1, &unsignedp, &volatilep,
10254 true);
10255 rtx orig_op0;
10257 /* ??? We should work harder and deal with non-zero offsets. */
10258 if (!offset
10259 && (bitpos % BITS_PER_UNIT) == 0
10260 && bitsize >= 0
10261 && compare_tree_int (TYPE_SIZE (type), bitsize) == 0)
10263 /* See the normal_inner_ref case for the rationale. */
10264 orig_op0
10265 = expand_expr (tem,
10266 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
10267 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
10268 != INTEGER_CST)
10269 && modifier != EXPAND_STACK_PARM
10270 ? target : NULL_RTX),
10271 VOIDmode,
10272 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
10274 if (MEM_P (orig_op0))
10276 op0 = orig_op0;
10278 /* Get a reference to just this component. */
10279 if (modifier == EXPAND_CONST_ADDRESS
10280 || modifier == EXPAND_SUM
10281 || modifier == EXPAND_INITIALIZER)
10282 op0 = adjust_address_nv (op0, mode, bitpos / BITS_PER_UNIT);
10283 else
10284 op0 = adjust_address (op0, mode, bitpos / BITS_PER_UNIT);
10286 if (op0 == orig_op0)
10287 op0 = copy_rtx (op0);
10289 set_mem_attributes (op0, treeop0, 0);
10290 if (REG_P (XEXP (op0, 0)))
10291 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10293 MEM_VOLATILE_P (op0) |= volatilep;
10298 if (!op0)
10299 op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
10301 /* If the input and output modes are both the same, we are done. */
10302 if (mode == GET_MODE (op0))
10304 /* If neither mode is BLKmode, and both modes are the same size
10305 then we can use gen_lowpart. */
10306 else if (mode != BLKmode && GET_MODE (op0) != BLKmode
10307 && (GET_MODE_PRECISION (mode)
10308 == GET_MODE_PRECISION (GET_MODE (op0)))
10309 && !COMPLEX_MODE_P (GET_MODE (op0)))
10311 if (GET_CODE (op0) == SUBREG)
10312 op0 = force_reg (GET_MODE (op0), op0);
10313 temp = gen_lowpart_common (mode, op0);
10314 if (temp)
10315 op0 = temp;
10316 else
10318 if (!REG_P (op0) && !MEM_P (op0))
10319 op0 = force_reg (GET_MODE (op0), op0);
10320 op0 = gen_lowpart (mode, op0);
10323 /* If both types are integral, convert from one mode to the other. */
10324 else if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0)))
10325 op0 = convert_modes (mode, GET_MODE (op0), op0,
10326 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10327 /* As a last resort, spill op0 to memory, and reload it in a
10328 different mode. */
10329 else if (!MEM_P (op0))
10331 /* If the operand is not a MEM, force it into memory. Since we
10332 are going to be changing the mode of the MEM, don't call
10333 force_const_mem for constants because we don't allow pool
10334 constants to change mode. */
10335 tree inner_type = TREE_TYPE (treeop0);
10337 gcc_assert (!TREE_ADDRESSABLE (exp));
10339 if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
10340 target
10341 = assign_stack_temp_for_type
10342 (TYPE_MODE (inner_type),
10343 GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
10345 emit_move_insn (target, op0);
10346 op0 = target;
10349 /* At this point, OP0 is in the correct mode. If the output type is
10350 such that the operand is known to be aligned, indicate that it is.
10351 Otherwise, we need only be concerned about alignment for non-BLKmode
10352 results. */
10353 if (MEM_P (op0))
10355 enum insn_code icode;
10357 if (TYPE_ALIGN_OK (type))
10359 /* ??? Copying the MEM without substantially changing it might
10360 run afoul of the code handling volatile memory references in
10361 store_expr, which assumes that TARGET is returned unmodified
10362 if it has been used. */
10363 op0 = copy_rtx (op0);
10364 set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
10366 else if (mode != BLKmode
10367 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode)
10368 /* If the target does have special handling for unaligned
10369 loads of mode then use them. */
10370 && ((icode = optab_handler (movmisalign_optab, mode))
10371 != CODE_FOR_nothing))
10373 rtx reg, insn;
10375 op0 = adjust_address (op0, mode, 0);
10376 /* We've already validated the memory, and we're creating a
10377 new pseudo destination. The predicates really can't
10378 fail. */
10379 reg = gen_reg_rtx (mode);
10381 /* Nor can the insn generator. */
10382 insn = GEN_FCN (icode) (reg, op0);
10383 emit_insn (insn);
10384 return reg;
10386 else if (STRICT_ALIGNMENT
10387 && mode != BLKmode
10388 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
10390 tree inner_type = TREE_TYPE (treeop0);
10391 HOST_WIDE_INT temp_size
10392 = MAX (int_size_in_bytes (inner_type),
10393 (HOST_WIDE_INT) GET_MODE_SIZE (mode));
10394 rtx new_rtx
10395 = assign_stack_temp_for_type (mode, temp_size, type);
10396 rtx new_with_op0_mode
10397 = adjust_address (new_rtx, GET_MODE (op0), 0);
10399 gcc_assert (!TREE_ADDRESSABLE (exp));
10401 if (GET_MODE (op0) == BLKmode)
10402 emit_block_move (new_with_op0_mode, op0,
10403 GEN_INT (GET_MODE_SIZE (mode)),
10404 (modifier == EXPAND_STACK_PARM
10405 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
10406 else
10407 emit_move_insn (new_with_op0_mode, op0);
10409 op0 = new_rtx;
10412 op0 = adjust_address (op0, mode, 0);
10415 return op0;
10417 case MODIFY_EXPR:
10419 tree lhs = treeop0;
10420 tree rhs = treeop1;
10421 gcc_assert (ignore);
10423 /* Check for |= or &= of a bitfield of size one into another bitfield
10424 of size 1. In this case, (unless we need the result of the
10425 assignment) we can do this more efficiently with a
10426 test followed by an assignment, if necessary.
10428 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10429 things change so we do, this code should be enhanced to
10430 support it. */
10431 if (TREE_CODE (lhs) == COMPONENT_REF
10432 && (TREE_CODE (rhs) == BIT_IOR_EXPR
10433 || TREE_CODE (rhs) == BIT_AND_EXPR)
10434 && TREE_OPERAND (rhs, 0) == lhs
10435 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
10436 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
10437 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
10439 rtx label = gen_label_rtx ();
10440 int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
10441 do_jump (TREE_OPERAND (rhs, 1),
10442 value ? label : 0,
10443 value ? 0 : label, -1);
10444 expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
10445 false);
10446 do_pending_stack_adjust ();
10447 emit_label (label);
10448 return const0_rtx;
10451 expand_assignment (lhs, rhs, false);
10452 return const0_rtx;
10455 case ADDR_EXPR:
10456 return expand_expr_addr_expr (exp, target, tmode, modifier);
10458 case REALPART_EXPR:
10459 op0 = expand_normal (treeop0);
10460 return read_complex_part (op0, false);
10462 case IMAGPART_EXPR:
10463 op0 = expand_normal (treeop0);
10464 return read_complex_part (op0, true);
10466 case RETURN_EXPR:
10467 case LABEL_EXPR:
10468 case GOTO_EXPR:
10469 case SWITCH_EXPR:
10470 case ASM_EXPR:
10471 /* Expanded in cfgexpand.c. */
10472 gcc_unreachable ();
10474 case TRY_CATCH_EXPR:
10475 case CATCH_EXPR:
10476 case EH_FILTER_EXPR:
10477 case TRY_FINALLY_EXPR:
10478 /* Lowered by tree-eh.c. */
10479 gcc_unreachable ();
10481 case WITH_CLEANUP_EXPR:
10482 case CLEANUP_POINT_EXPR:
10483 case TARGET_EXPR:
10484 case CASE_LABEL_EXPR:
10485 case VA_ARG_EXPR:
10486 case BIND_EXPR:
10487 case INIT_EXPR:
10488 case CONJ_EXPR:
10489 case COMPOUND_EXPR:
10490 case PREINCREMENT_EXPR:
10491 case PREDECREMENT_EXPR:
10492 case POSTINCREMENT_EXPR:
10493 case POSTDECREMENT_EXPR:
10494 case LOOP_EXPR:
10495 case EXIT_EXPR:
10496 case COMPOUND_LITERAL_EXPR:
10497 /* Lowered by gimplify.c. */
10498 gcc_unreachable ();
10500 case FDESC_EXPR:
10501 /* Function descriptors are not valid except for as
10502 initialization constants, and should not be expanded. */
10503 gcc_unreachable ();
10505 case WITH_SIZE_EXPR:
10506 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10507 have pulled out the size to use in whatever context it needed. */
10508 return expand_expr_real (treeop0, original_target, tmode,
10509 modifier, alt_rtl);
10511 default:
10512 return expand_expr_real_2 (&ops, target, tmode, modifier);
10516 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10517 signedness of TYPE), possibly returning the result in TARGET. */
10518 static rtx
10519 reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
10521 HOST_WIDE_INT prec = TYPE_PRECISION (type);
10522 if (target && GET_MODE (target) != GET_MODE (exp))
10523 target = 0;
10524 /* For constant values, reduce using build_int_cst_type. */
10525 if (CONST_INT_P (exp))
10527 HOST_WIDE_INT value = INTVAL (exp);
10528 tree t = build_int_cst_type (type, value);
10529 return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
10531 else if (TYPE_UNSIGNED (type))
10533 rtx mask = immed_double_int_const (double_int::mask (prec),
10534 GET_MODE (exp));
10535 return expand_and (GET_MODE (exp), exp, mask, target);
10537 else
10539 int count = GET_MODE_PRECISION (GET_MODE (exp)) - prec;
10540 exp = expand_shift (LSHIFT_EXPR, GET_MODE (exp),
10541 exp, count, target, 0);
10542 return expand_shift (RSHIFT_EXPR, GET_MODE (exp),
10543 exp, count, target, 0);
10547 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10548 when applied to the address of EXP produces an address known to be
10549 aligned more than BIGGEST_ALIGNMENT. */
10551 static int
10552 is_aligning_offset (const_tree offset, const_tree exp)
10554 /* Strip off any conversions. */
10555 while (CONVERT_EXPR_P (offset))
10556 offset = TREE_OPERAND (offset, 0);
10558 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10559 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10560 if (TREE_CODE (offset) != BIT_AND_EXPR
10561 || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
10562 || compare_tree_int (TREE_OPERAND (offset, 1),
10563 BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
10564 || !exact_log2 (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1) < 0)
10565 return 0;
10567 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10568 It must be NEGATE_EXPR. Then strip any more conversions. */
10569 offset = TREE_OPERAND (offset, 0);
10570 while (CONVERT_EXPR_P (offset))
10571 offset = TREE_OPERAND (offset, 0);
10573 if (TREE_CODE (offset) != NEGATE_EXPR)
10574 return 0;
10576 offset = TREE_OPERAND (offset, 0);
10577 while (CONVERT_EXPR_P (offset))
10578 offset = TREE_OPERAND (offset, 0);
10580 /* This must now be the address of EXP. */
10581 return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
10584 /* Return the tree node if an ARG corresponds to a string constant or zero
10585 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10586 in bytes within the string that ARG is accessing. The type of the
10587 offset will be `sizetype'. */
10589 tree
10590 string_constant (tree arg, tree *ptr_offset)
10592 tree array, offset, lower_bound;
10593 STRIP_NOPS (arg);
10595 if (TREE_CODE (arg) == ADDR_EXPR)
10597 if (TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
10599 *ptr_offset = size_zero_node;
10600 return TREE_OPERAND (arg, 0);
10602 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL)
10604 array = TREE_OPERAND (arg, 0);
10605 offset = size_zero_node;
10607 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF)
10609 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10610 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10611 if (TREE_CODE (array) != STRING_CST
10612 && TREE_CODE (array) != VAR_DECL)
10613 return 0;
10615 /* Check if the array has a nonzero lower bound. */
10616 lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
10617 if (!integer_zerop (lower_bound))
10619 /* If the offset and base aren't both constants, return 0. */
10620 if (TREE_CODE (lower_bound) != INTEGER_CST)
10621 return 0;
10622 if (TREE_CODE (offset) != INTEGER_CST)
10623 return 0;
10624 /* Adjust offset by the lower bound. */
10625 offset = size_diffop (fold_convert (sizetype, offset),
10626 fold_convert (sizetype, lower_bound));
10629 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == MEM_REF)
10631 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10632 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10633 if (TREE_CODE (array) != ADDR_EXPR)
10634 return 0;
10635 array = TREE_OPERAND (array, 0);
10636 if (TREE_CODE (array) != STRING_CST
10637 && TREE_CODE (array) != VAR_DECL)
10638 return 0;
10640 else
10641 return 0;
10643 else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
10645 tree arg0 = TREE_OPERAND (arg, 0);
10646 tree arg1 = TREE_OPERAND (arg, 1);
10648 STRIP_NOPS (arg0);
10649 STRIP_NOPS (arg1);
10651 if (TREE_CODE (arg0) == ADDR_EXPR
10652 && (TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST
10653 || TREE_CODE (TREE_OPERAND (arg0, 0)) == VAR_DECL))
10655 array = TREE_OPERAND (arg0, 0);
10656 offset = arg1;
10658 else if (TREE_CODE (arg1) == ADDR_EXPR
10659 && (TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST
10660 || TREE_CODE (TREE_OPERAND (arg1, 0)) == VAR_DECL))
10662 array = TREE_OPERAND (arg1, 0);
10663 offset = arg0;
10665 else
10666 return 0;
10668 else
10669 return 0;
10671 if (TREE_CODE (array) == STRING_CST)
10673 *ptr_offset = fold_convert (sizetype, offset);
10674 return array;
10676 else if (TREE_CODE (array) == VAR_DECL
10677 || TREE_CODE (array) == CONST_DECL)
10679 int length;
10680 tree init = ctor_for_folding (array);
10682 /* Variables initialized to string literals can be handled too. */
10683 if (init == error_mark_node
10684 || !init
10685 || TREE_CODE (init) != STRING_CST)
10686 return 0;
10688 /* Avoid const char foo[4] = "abcde"; */
10689 if (DECL_SIZE_UNIT (array) == NULL_TREE
10690 || TREE_CODE (DECL_SIZE_UNIT (array)) != INTEGER_CST
10691 || (length = TREE_STRING_LENGTH (init)) <= 0
10692 || compare_tree_int (DECL_SIZE_UNIT (array), length) < 0)
10693 return 0;
10695 /* If variable is bigger than the string literal, OFFSET must be constant
10696 and inside of the bounds of the string literal. */
10697 offset = fold_convert (sizetype, offset);
10698 if (compare_tree_int (DECL_SIZE_UNIT (array), length) > 0
10699 && (! tree_fits_uhwi_p (offset)
10700 || compare_tree_int (offset, length) >= 0))
10701 return 0;
10703 *ptr_offset = offset;
10704 return init;
10707 return 0;
10710 /* Generate code to calculate OPS, and exploded expression
10711 using a store-flag instruction and return an rtx for the result.
10712 OPS reflects a comparison.
10714 If TARGET is nonzero, store the result there if convenient.
10716 Return zero if there is no suitable set-flag instruction
10717 available on this machine.
10719 Once expand_expr has been called on the arguments of the comparison,
10720 we are committed to doing the store flag, since it is not safe to
10721 re-evaluate the expression. We emit the store-flag insn by calling
10722 emit_store_flag, but only expand the arguments if we have a reason
10723 to believe that emit_store_flag will be successful. If we think that
10724 it will, but it isn't, we have to simulate the store-flag with a
10725 set/jump/set sequence. */
10727 static rtx
10728 do_store_flag (sepops ops, rtx target, enum machine_mode mode)
10730 enum rtx_code code;
10731 tree arg0, arg1, type;
10732 tree tem;
10733 enum machine_mode operand_mode;
10734 int unsignedp;
10735 rtx op0, op1;
10736 rtx subtarget = target;
10737 location_t loc = ops->location;
10739 arg0 = ops->op0;
10740 arg1 = ops->op1;
10742 /* Don't crash if the comparison was erroneous. */
10743 if (arg0 == error_mark_node || arg1 == error_mark_node)
10744 return const0_rtx;
10746 type = TREE_TYPE (arg0);
10747 operand_mode = TYPE_MODE (type);
10748 unsignedp = TYPE_UNSIGNED (type);
10750 /* We won't bother with BLKmode store-flag operations because it would mean
10751 passing a lot of information to emit_store_flag. */
10752 if (operand_mode == BLKmode)
10753 return 0;
10755 /* We won't bother with store-flag operations involving function pointers
10756 when function pointers must be canonicalized before comparisons. */
10757 #ifdef HAVE_canonicalize_funcptr_for_compare
10758 if (HAVE_canonicalize_funcptr_for_compare
10759 && ((TREE_CODE (TREE_TYPE (arg0)) == POINTER_TYPE
10760 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0)))
10761 == FUNCTION_TYPE))
10762 || (TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE
10763 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1)))
10764 == FUNCTION_TYPE))))
10765 return 0;
10766 #endif
10768 STRIP_NOPS (arg0);
10769 STRIP_NOPS (arg1);
10771 /* For vector typed comparisons emit code to generate the desired
10772 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10773 expander for this. */
10774 if (TREE_CODE (ops->type) == VECTOR_TYPE)
10776 tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
10777 tree if_true = constant_boolean_node (true, ops->type);
10778 tree if_false = constant_boolean_node (false, ops->type);
10779 return expand_vec_cond_expr (ops->type, ifexp, if_true, if_false, target);
10782 /* Get the rtx comparison code to use. We know that EXP is a comparison
10783 operation of some type. Some comparisons against 1 and -1 can be
10784 converted to comparisons with zero. Do so here so that the tests
10785 below will be aware that we have a comparison with zero. These
10786 tests will not catch constants in the first operand, but constants
10787 are rarely passed as the first operand. */
10789 switch (ops->code)
10791 case EQ_EXPR:
10792 code = EQ;
10793 break;
10794 case NE_EXPR:
10795 code = NE;
10796 break;
10797 case LT_EXPR:
10798 if (integer_onep (arg1))
10799 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
10800 else
10801 code = unsignedp ? LTU : LT;
10802 break;
10803 case LE_EXPR:
10804 if (! unsignedp && integer_all_onesp (arg1))
10805 arg1 = integer_zero_node, code = LT;
10806 else
10807 code = unsignedp ? LEU : LE;
10808 break;
10809 case GT_EXPR:
10810 if (! unsignedp && integer_all_onesp (arg1))
10811 arg1 = integer_zero_node, code = GE;
10812 else
10813 code = unsignedp ? GTU : GT;
10814 break;
10815 case GE_EXPR:
10816 if (integer_onep (arg1))
10817 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
10818 else
10819 code = unsignedp ? GEU : GE;
10820 break;
10822 case UNORDERED_EXPR:
10823 code = UNORDERED;
10824 break;
10825 case ORDERED_EXPR:
10826 code = ORDERED;
10827 break;
10828 case UNLT_EXPR:
10829 code = UNLT;
10830 break;
10831 case UNLE_EXPR:
10832 code = UNLE;
10833 break;
10834 case UNGT_EXPR:
10835 code = UNGT;
10836 break;
10837 case UNGE_EXPR:
10838 code = UNGE;
10839 break;
10840 case UNEQ_EXPR:
10841 code = UNEQ;
10842 break;
10843 case LTGT_EXPR:
10844 code = LTGT;
10845 break;
10847 default:
10848 gcc_unreachable ();
10851 /* Put a constant second. */
10852 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
10853 || TREE_CODE (arg0) == FIXED_CST)
10855 tem = arg0; arg0 = arg1; arg1 = tem;
10856 code = swap_condition (code);
10859 /* If this is an equality or inequality test of a single bit, we can
10860 do this by shifting the bit being tested to the low-order bit and
10861 masking the result with the constant 1. If the condition was EQ,
10862 we xor it with 1. This does not require an scc insn and is faster
10863 than an scc insn even if we have it.
10865 The code to make this transformation was moved into fold_single_bit_test,
10866 so we just call into the folder and expand its result. */
10868 if ((code == NE || code == EQ)
10869 && integer_zerop (arg1)
10870 && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
10872 gimple srcstmt = get_def_for_expr (arg0, BIT_AND_EXPR);
10873 if (srcstmt
10874 && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
10876 enum tree_code tcode = code == NE ? NE_EXPR : EQ_EXPR;
10877 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10878 tree temp = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg1),
10879 gimple_assign_rhs1 (srcstmt),
10880 gimple_assign_rhs2 (srcstmt));
10881 temp = fold_single_bit_test (loc, tcode, temp, arg1, type);
10882 if (temp)
10883 return expand_expr (temp, target, VOIDmode, EXPAND_NORMAL);
10887 if (! get_subtarget (target)
10888 || GET_MODE (subtarget) != operand_mode)
10889 subtarget = 0;
10891 expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
10893 if (target == 0)
10894 target = gen_reg_rtx (mode);
10896 /* Try a cstore if possible. */
10897 return emit_store_flag_force (target, code, op0, op1,
10898 operand_mode, unsignedp,
10899 (TYPE_PRECISION (ops->type) == 1
10900 && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
10904 /* Stubs in case we haven't got a casesi insn. */
10905 #ifndef HAVE_casesi
10906 # define HAVE_casesi 0
10907 # define gen_casesi(a, b, c, d, e) (0)
10908 # define CODE_FOR_casesi CODE_FOR_nothing
10909 #endif
10911 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10912 0 otherwise (i.e. if there is no casesi instruction).
10914 DEFAULT_PROBABILITY is the probability of jumping to the default
10915 label. */
10917 try_casesi (tree index_type, tree index_expr, tree minval, tree range,
10918 rtx table_label, rtx default_label, rtx fallback_label,
10919 int default_probability)
10921 struct expand_operand ops[5];
10922 enum machine_mode index_mode = SImode;
10923 rtx op1, op2, index;
10925 if (! HAVE_casesi)
10926 return 0;
10928 /* Convert the index to SImode. */
10929 if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
10931 enum machine_mode omode = TYPE_MODE (index_type);
10932 rtx rangertx = expand_normal (range);
10934 /* We must handle the endpoints in the original mode. */
10935 index_expr = build2 (MINUS_EXPR, index_type,
10936 index_expr, minval);
10937 minval = integer_zero_node;
10938 index = expand_normal (index_expr);
10939 if (default_label)
10940 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
10941 omode, 1, default_label,
10942 default_probability);
10943 /* Now we can safely truncate. */
10944 index = convert_to_mode (index_mode, index, 0);
10946 else
10948 if (TYPE_MODE (index_type) != index_mode)
10950 index_type = lang_hooks.types.type_for_mode (index_mode, 0);
10951 index_expr = fold_convert (index_type, index_expr);
10954 index = expand_normal (index_expr);
10957 do_pending_stack_adjust ();
10959 op1 = expand_normal (minval);
10960 op2 = expand_normal (range);
10962 create_input_operand (&ops[0], index, index_mode);
10963 create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
10964 create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
10965 create_fixed_operand (&ops[3], table_label);
10966 create_fixed_operand (&ops[4], (default_label
10967 ? default_label
10968 : fallback_label));
10969 expand_jump_insn (CODE_FOR_casesi, 5, ops);
10970 return 1;
10973 /* Attempt to generate a tablejump instruction; same concept. */
10974 #ifndef HAVE_tablejump
10975 #define HAVE_tablejump 0
10976 #define gen_tablejump(x, y) (0)
10977 #endif
10979 /* Subroutine of the next function.
10981 INDEX is the value being switched on, with the lowest value
10982 in the table already subtracted.
10983 MODE is its expected mode (needed if INDEX is constant).
10984 RANGE is the length of the jump table.
10985 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10987 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10988 index value is out of range.
10989 DEFAULT_PROBABILITY is the probability of jumping to
10990 the default label. */
10992 static void
10993 do_tablejump (rtx index, enum machine_mode mode, rtx range, rtx table_label,
10994 rtx default_label, int default_probability)
10996 rtx temp, vector;
10998 if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
10999 cfun->cfg->max_jumptable_ents = INTVAL (range);
11001 /* Do an unsigned comparison (in the proper mode) between the index
11002 expression and the value which represents the length of the range.
11003 Since we just finished subtracting the lower bound of the range
11004 from the index expression, this comparison allows us to simultaneously
11005 check that the original index expression value is both greater than
11006 or equal to the minimum value of the range and less than or equal to
11007 the maximum value of the range. */
11009 if (default_label)
11010 emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
11011 default_label, default_probability);
11014 /* If index is in range, it must fit in Pmode.
11015 Convert to Pmode so we can index with it. */
11016 if (mode != Pmode)
11017 index = convert_to_mode (Pmode, index, 1);
11019 /* Don't let a MEM slip through, because then INDEX that comes
11020 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11021 and break_out_memory_refs will go to work on it and mess it up. */
11022 #ifdef PIC_CASE_VECTOR_ADDRESS
11023 if (flag_pic && !REG_P (index))
11024 index = copy_to_mode_reg (Pmode, index);
11025 #endif
11027 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11028 GET_MODE_SIZE, because this indicates how large insns are. The other
11029 uses should all be Pmode, because they are addresses. This code
11030 could fail if addresses and insns are not the same size. */
11031 index = gen_rtx_PLUS
11032 (Pmode,
11033 gen_rtx_MULT (Pmode, index,
11034 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE), Pmode)),
11035 gen_rtx_LABEL_REF (Pmode, table_label));
11036 #ifdef PIC_CASE_VECTOR_ADDRESS
11037 if (flag_pic)
11038 index = PIC_CASE_VECTOR_ADDRESS (index);
11039 else
11040 #endif
11041 index = memory_address (CASE_VECTOR_MODE, index);
11042 temp = gen_reg_rtx (CASE_VECTOR_MODE);
11043 vector = gen_const_mem (CASE_VECTOR_MODE, index);
11044 convert_move (temp, vector, 0);
11046 emit_jump_insn (gen_tablejump (temp, table_label));
11048 /* If we are generating PIC code or if the table is PC-relative, the
11049 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11050 if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
11051 emit_barrier ();
11055 try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
11056 rtx table_label, rtx default_label, int default_probability)
11058 rtx index;
11060 if (! HAVE_tablejump)
11061 return 0;
11063 index_expr = fold_build2 (MINUS_EXPR, index_type,
11064 fold_convert (index_type, index_expr),
11065 fold_convert (index_type, minval));
11066 index = expand_normal (index_expr);
11067 do_pending_stack_adjust ();
11069 do_tablejump (index, TYPE_MODE (index_type),
11070 convert_modes (TYPE_MODE (index_type),
11071 TYPE_MODE (TREE_TYPE (range)),
11072 expand_normal (range),
11073 TYPE_UNSIGNED (TREE_TYPE (range))),
11074 table_label, default_label, default_probability);
11075 return 1;
11078 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11079 static rtx
11080 const_vector_from_tree (tree exp)
11082 rtvec v;
11083 unsigned i;
11084 int units;
11085 tree elt;
11086 enum machine_mode inner, mode;
11088 mode = TYPE_MODE (TREE_TYPE (exp));
11090 if (initializer_zerop (exp))
11091 return CONST0_RTX (mode);
11093 units = GET_MODE_NUNITS (mode);
11094 inner = GET_MODE_INNER (mode);
11096 v = rtvec_alloc (units);
11098 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
11100 elt = VECTOR_CST_ELT (exp, i);
11102 if (TREE_CODE (elt) == REAL_CST)
11103 RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
11104 inner);
11105 else if (TREE_CODE (elt) == FIXED_CST)
11106 RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
11107 inner);
11108 else
11109 RTVEC_ELT (v, i) = immed_double_int_const (tree_to_double_int (elt),
11110 inner);
11113 return gen_rtx_CONST_VECTOR (mode, v);
11116 /* Build a decl for a personality function given a language prefix. */
11118 tree
11119 build_personality_function (const char *lang)
11121 const char *unwind_and_version;
11122 tree decl, type;
11123 char *name;
11125 switch (targetm_common.except_unwind_info (&global_options))
11127 case UI_NONE:
11128 return NULL;
11129 case UI_SJLJ:
11130 unwind_and_version = "_sj0";
11131 break;
11132 case UI_DWARF2:
11133 case UI_TARGET:
11134 unwind_and_version = "_v0";
11135 break;
11136 case UI_SEH:
11137 unwind_and_version = "_seh0";
11138 break;
11139 default:
11140 gcc_unreachable ();
11143 name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
11145 type = build_function_type_list (integer_type_node, integer_type_node,
11146 long_long_unsigned_type_node,
11147 ptr_type_node, ptr_type_node, NULL_TREE);
11148 decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
11149 get_identifier (name), type);
11150 DECL_ARTIFICIAL (decl) = 1;
11151 DECL_EXTERNAL (decl) = 1;
11152 TREE_PUBLIC (decl) = 1;
11154 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11155 are the flags assigned by targetm.encode_section_info. */
11156 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
11158 return decl;
11161 /* Extracts the personality function of DECL and returns the corresponding
11162 libfunc. */
11165 get_personality_function (tree decl)
11167 tree personality = DECL_FUNCTION_PERSONALITY (decl);
11168 enum eh_personality_kind pk;
11170 pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
11171 if (pk == eh_personality_none)
11172 return NULL;
11174 if (!personality
11175 && pk == eh_personality_any)
11176 personality = lang_hooks.eh_personality ();
11178 if (pk == eh_personality_lang)
11179 gcc_assert (personality != NULL_TREE);
11181 return XEXP (DECL_RTL (personality), 0);
11184 #include "gt-expr.h"