2013-10-25 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / expr.c
blobfbd301b67d1d61c2900e66846d44dac88cc2ac2d
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-outof-ssa.h"
56 #include "target-globals.h"
57 #include "params.h"
58 #include "tree-ssa-address.h"
60 /* Decide whether a function's arguments should be processed
61 from first to last or from last to first.
63 They should if the stack and args grow in opposite directions, but
64 only if we have push insns. */
66 #ifdef PUSH_ROUNDING
68 #ifndef PUSH_ARGS_REVERSED
69 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
70 #define PUSH_ARGS_REVERSED /* If it's last to first. */
71 #endif
72 #endif
74 #endif
76 #ifndef STACK_PUSH_CODE
77 #ifdef STACK_GROWS_DOWNWARD
78 #define STACK_PUSH_CODE PRE_DEC
79 #else
80 #define STACK_PUSH_CODE PRE_INC
81 #endif
82 #endif
85 /* If this is nonzero, we do not bother generating VOLATILE
86 around volatile memory references, and we are willing to
87 output indirect addresses. If cse is to follow, we reject
88 indirect addresses so a useful potential cse is generated;
89 if it is used only once, instruction combination will produce
90 the same indirect address eventually. */
91 int cse_not_expected;
93 /* This structure is used by move_by_pieces to describe the move to
94 be performed. */
95 struct move_by_pieces_d
97 rtx to;
98 rtx to_addr;
99 int autinc_to;
100 int explicit_inc_to;
101 rtx from;
102 rtx from_addr;
103 int autinc_from;
104 int explicit_inc_from;
105 unsigned HOST_WIDE_INT len;
106 HOST_WIDE_INT offset;
107 int reverse;
110 /* This structure is used by store_by_pieces to describe the clear to
111 be performed. */
113 struct store_by_pieces_d
115 rtx to;
116 rtx to_addr;
117 int autinc_to;
118 int explicit_inc_to;
119 unsigned HOST_WIDE_INT len;
120 HOST_WIDE_INT offset;
121 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
122 void *constfundata;
123 int reverse;
126 static void move_by_pieces_1 (insn_gen_fn, machine_mode,
127 struct move_by_pieces_d *);
128 static bool block_move_libcall_safe_for_call_parm (void);
129 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned, unsigned, HOST_WIDE_INT);
130 static tree emit_block_move_libcall_fn (int);
131 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
132 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
133 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
134 static void store_by_pieces_1 (struct store_by_pieces_d *, unsigned int);
135 static void store_by_pieces_2 (insn_gen_fn, machine_mode,
136 struct store_by_pieces_d *);
137 static tree clear_storage_libcall_fn (int);
138 static rtx compress_float_constant (rtx, rtx);
139 static rtx get_subtarget (rtx);
140 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
141 HOST_WIDE_INT, enum machine_mode,
142 tree, int, alias_set_type);
143 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
144 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT,
145 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
146 enum machine_mode, tree, alias_set_type, bool);
148 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (const_tree, const_tree);
150 static int is_aligning_offset (const_tree, const_tree);
151 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
152 enum expand_modifier);
153 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
154 static rtx do_store_flag (sepops, rtx, enum machine_mode);
155 #ifdef PUSH_ROUNDING
156 static void emit_single_push_insn (enum machine_mode, rtx, tree);
157 #endif
158 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx, int);
159 static rtx const_vector_from_tree (tree);
160 static void write_complex_part (rtx, rtx, bool);
162 /* This macro is used to determine whether move_by_pieces should be called
163 to perform a structure copy. */
164 #ifndef MOVE_BY_PIECES_P
165 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
166 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
167 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
168 #endif
170 /* This macro is used to determine whether clear_by_pieces should be
171 called to clear storage. */
172 #ifndef CLEAR_BY_PIECES_P
173 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
174 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
175 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
176 #endif
178 /* This macro is used to determine whether store_by_pieces should be
179 called to "memset" storage with byte values other than zero. */
180 #ifndef SET_BY_PIECES_P
181 #define SET_BY_PIECES_P(SIZE, ALIGN) \
182 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
183 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
184 #endif
186 /* This macro is used to determine whether store_by_pieces should be
187 called to "memcpy" storage when the source is a constant string. */
188 #ifndef STORE_BY_PIECES_P
189 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
190 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
191 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
192 #endif
194 /* This is run to set up which modes can be used
195 directly in memory and to initialize the block move optab. It is run
196 at the beginning of compilation and when the target is reinitialized. */
198 void
199 init_expr_target (void)
201 rtx insn, pat;
202 enum machine_mode mode;
203 int num_clobbers;
204 rtx mem, mem1;
205 rtx reg;
207 /* Try indexing by frame ptr and try by stack ptr.
208 It is known that on the Convex the stack ptr isn't a valid index.
209 With luck, one or the other is valid on any machine. */
210 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
211 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
213 /* A scratch register we can modify in-place below to avoid
214 useless RTL allocations. */
215 reg = gen_rtx_REG (VOIDmode, -1);
217 insn = rtx_alloc (INSN);
218 pat = gen_rtx_SET (VOIDmode, NULL_RTX, NULL_RTX);
219 PATTERN (insn) = pat;
221 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
222 mode = (enum machine_mode) ((int) mode + 1))
224 int regno;
226 direct_load[(int) mode] = direct_store[(int) mode] = 0;
227 PUT_MODE (mem, mode);
228 PUT_MODE (mem1, mode);
229 PUT_MODE (reg, mode);
231 /* See if there is some register that can be used in this mode and
232 directly loaded or stored from memory. */
234 if (mode != VOIDmode && mode != BLKmode)
235 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
236 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
237 regno++)
239 if (! HARD_REGNO_MODE_OK (regno, mode))
240 continue;
242 SET_REGNO (reg, regno);
244 SET_SRC (pat) = mem;
245 SET_DEST (pat) = reg;
246 if (recog (pat, insn, &num_clobbers) >= 0)
247 direct_load[(int) mode] = 1;
249 SET_SRC (pat) = mem1;
250 SET_DEST (pat) = reg;
251 if (recog (pat, insn, &num_clobbers) >= 0)
252 direct_load[(int) mode] = 1;
254 SET_SRC (pat) = reg;
255 SET_DEST (pat) = mem;
256 if (recog (pat, insn, &num_clobbers) >= 0)
257 direct_store[(int) mode] = 1;
259 SET_SRC (pat) = reg;
260 SET_DEST (pat) = mem1;
261 if (recog (pat, insn, &num_clobbers) >= 0)
262 direct_store[(int) mode] = 1;
266 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
268 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
269 mode = GET_MODE_WIDER_MODE (mode))
271 enum machine_mode srcmode;
272 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
273 srcmode = GET_MODE_WIDER_MODE (srcmode))
275 enum insn_code ic;
277 ic = can_extend_p (mode, srcmode, 0);
278 if (ic == CODE_FOR_nothing)
279 continue;
281 PUT_MODE (mem, srcmode);
283 if (insn_operand_matches (ic, 1, mem))
284 float_extend_from_mem[mode][srcmode] = true;
289 /* This is run at the start of compiling a function. */
291 void
292 init_expr (void)
294 memset (&crtl->expr, 0, sizeof (crtl->expr));
297 /* Copy data from FROM to TO, where the machine modes are not the same.
298 Both modes may be integer, or both may be floating, or both may be
299 fixed-point.
300 UNSIGNEDP should be nonzero if FROM is an unsigned type.
301 This causes zero-extension instead of sign-extension. */
303 void
304 convert_move (rtx to, rtx from, int unsignedp)
306 enum machine_mode to_mode = GET_MODE (to);
307 enum machine_mode from_mode = GET_MODE (from);
308 int to_real = SCALAR_FLOAT_MODE_P (to_mode);
309 int from_real = SCALAR_FLOAT_MODE_P (from_mode);
310 enum insn_code code;
311 rtx libcall;
313 /* rtx code for making an equivalent value. */
314 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
315 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
318 gcc_assert (to_real == from_real);
319 gcc_assert (to_mode != BLKmode);
320 gcc_assert (from_mode != BLKmode);
322 /* If the source and destination are already the same, then there's
323 nothing to do. */
324 if (to == from)
325 return;
327 /* If FROM is a SUBREG that indicates that we have already done at least
328 the required extension, strip it. We don't handle such SUBREGs as
329 TO here. */
331 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
332 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from)))
333 >= GET_MODE_PRECISION (to_mode))
334 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
335 from = gen_lowpart (to_mode, from), from_mode = to_mode;
337 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
339 if (to_mode == from_mode
340 || (from_mode == VOIDmode && CONSTANT_P (from)))
342 emit_move_insn (to, from);
343 return;
346 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
348 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
350 if (VECTOR_MODE_P (to_mode))
351 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
352 else
353 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
355 emit_move_insn (to, from);
356 return;
359 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
361 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
362 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
363 return;
366 if (to_real)
368 rtx value, insns;
369 convert_optab tab;
371 gcc_assert ((GET_MODE_PRECISION (from_mode)
372 != GET_MODE_PRECISION (to_mode))
373 || (DECIMAL_FLOAT_MODE_P (from_mode)
374 != DECIMAL_FLOAT_MODE_P (to_mode)));
376 if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
377 /* Conversion between decimal float and binary float, same size. */
378 tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
379 else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
380 tab = sext_optab;
381 else
382 tab = trunc_optab;
384 /* Try converting directly if the insn is supported. */
386 code = convert_optab_handler (tab, to_mode, from_mode);
387 if (code != CODE_FOR_nothing)
389 emit_unop_insn (code, to, from,
390 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
391 return;
394 /* Otherwise use a libcall. */
395 libcall = convert_optab_libfunc (tab, to_mode, from_mode);
397 /* Is this conversion implemented yet? */
398 gcc_assert (libcall);
400 start_sequence ();
401 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
402 1, from, from_mode);
403 insns = get_insns ();
404 end_sequence ();
405 emit_libcall_block (insns, to, value,
406 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
407 from)
408 : gen_rtx_FLOAT_EXTEND (to_mode, from));
409 return;
412 /* Handle pointer conversion. */ /* SPEE 900220. */
413 /* Targets are expected to provide conversion insns between PxImode and
414 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
415 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
417 enum machine_mode full_mode
418 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
420 gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
421 != CODE_FOR_nothing);
423 if (full_mode != from_mode)
424 from = convert_to_mode (full_mode, from, unsignedp);
425 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
426 to, from, UNKNOWN);
427 return;
429 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
431 rtx new_from;
432 enum machine_mode full_mode
433 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
434 convert_optab ctab = unsignedp ? zext_optab : sext_optab;
435 enum insn_code icode;
437 icode = convert_optab_handler (ctab, full_mode, from_mode);
438 gcc_assert (icode != CODE_FOR_nothing);
440 if (to_mode == full_mode)
442 emit_unop_insn (icode, to, from, UNKNOWN);
443 return;
446 new_from = gen_reg_rtx (full_mode);
447 emit_unop_insn (icode, new_from, from, UNKNOWN);
449 /* else proceed to integer conversions below. */
450 from_mode = full_mode;
451 from = new_from;
454 /* Make sure both are fixed-point modes or both are not. */
455 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
456 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
457 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
459 /* If we widen from_mode to to_mode and they are in the same class,
460 we won't saturate the result.
461 Otherwise, always saturate the result to play safe. */
462 if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
463 && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
464 expand_fixed_convert (to, from, 0, 0);
465 else
466 expand_fixed_convert (to, from, 0, 1);
467 return;
470 /* Now both modes are integers. */
472 /* Handle expanding beyond a word. */
473 if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
474 && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
476 rtx insns;
477 rtx lowpart;
478 rtx fill_value;
479 rtx lowfrom;
480 int i;
481 enum machine_mode lowpart_mode;
482 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
484 /* Try converting directly if the insn is supported. */
485 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
486 != CODE_FOR_nothing)
488 /* If FROM is a SUBREG, put it into a register. Do this
489 so that we always generate the same set of insns for
490 better cse'ing; if an intermediate assignment occurred,
491 we won't be doing the operation directly on the SUBREG. */
492 if (optimize > 0 && GET_CODE (from) == SUBREG)
493 from = force_reg (from_mode, from);
494 emit_unop_insn (code, to, from, equiv_code);
495 return;
497 /* Next, try converting via full word. */
498 else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
499 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
500 != CODE_FOR_nothing))
502 rtx word_to = gen_reg_rtx (word_mode);
503 if (REG_P (to))
505 if (reg_overlap_mentioned_p (to, from))
506 from = force_reg (from_mode, from);
507 emit_clobber (to);
509 convert_move (word_to, from, unsignedp);
510 emit_unop_insn (code, to, word_to, equiv_code);
511 return;
514 /* No special multiword conversion insn; do it by hand. */
515 start_sequence ();
517 /* Since we will turn this into a no conflict block, we must ensure the
518 the source does not overlap the target so force it into an isolated
519 register when maybe so. Likewise for any MEM input, since the
520 conversion sequence might require several references to it and we
521 must ensure we're getting the same value every time. */
523 if (MEM_P (from) || reg_overlap_mentioned_p (to, from))
524 from = force_reg (from_mode, from);
526 /* Get a copy of FROM widened to a word, if necessary. */
527 if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
528 lowpart_mode = word_mode;
529 else
530 lowpart_mode = from_mode;
532 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
534 lowpart = gen_lowpart (lowpart_mode, to);
535 emit_move_insn (lowpart, lowfrom);
537 /* Compute the value to put in each remaining word. */
538 if (unsignedp)
539 fill_value = const0_rtx;
540 else
541 fill_value = emit_store_flag (gen_reg_rtx (word_mode),
542 LT, lowfrom, const0_rtx,
543 VOIDmode, 0, -1);
545 /* Fill the remaining words. */
546 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
548 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
549 rtx subword = operand_subword (to, index, 1, to_mode);
551 gcc_assert (subword);
553 if (fill_value != subword)
554 emit_move_insn (subword, fill_value);
557 insns = get_insns ();
558 end_sequence ();
560 emit_insn (insns);
561 return;
564 /* Truncating multi-word to a word or less. */
565 if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
566 && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
568 if (!((MEM_P (from)
569 && ! MEM_VOLATILE_P (from)
570 && direct_load[(int) to_mode]
571 && ! mode_dependent_address_p (XEXP (from, 0),
572 MEM_ADDR_SPACE (from)))
573 || REG_P (from)
574 || GET_CODE (from) == SUBREG))
575 from = force_reg (from_mode, from);
576 convert_move (to, gen_lowpart (word_mode, from), 0);
577 return;
580 /* Now follow all the conversions between integers
581 no more than a word long. */
583 /* For truncation, usually we can just refer to FROM in a narrower mode. */
584 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
585 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
587 if (!((MEM_P (from)
588 && ! MEM_VOLATILE_P (from)
589 && direct_load[(int) to_mode]
590 && ! mode_dependent_address_p (XEXP (from, 0),
591 MEM_ADDR_SPACE (from)))
592 || REG_P (from)
593 || GET_CODE (from) == SUBREG))
594 from = force_reg (from_mode, from);
595 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
596 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
597 from = copy_to_reg (from);
598 emit_move_insn (to, gen_lowpart (to_mode, from));
599 return;
602 /* Handle extension. */
603 if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (from_mode))
605 /* Convert directly if that works. */
606 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
607 != CODE_FOR_nothing)
609 emit_unop_insn (code, to, from, equiv_code);
610 return;
612 else
614 enum machine_mode intermediate;
615 rtx tmp;
616 int shift_amount;
618 /* Search for a mode to convert via. */
619 for (intermediate = from_mode; intermediate != VOIDmode;
620 intermediate = GET_MODE_WIDER_MODE (intermediate))
621 if (((can_extend_p (to_mode, intermediate, unsignedp)
622 != CODE_FOR_nothing)
623 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
624 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, intermediate)))
625 && (can_extend_p (intermediate, from_mode, unsignedp)
626 != CODE_FOR_nothing))
628 convert_move (to, convert_to_mode (intermediate, from,
629 unsignedp), unsignedp);
630 return;
633 /* No suitable intermediate mode.
634 Generate what we need with shifts. */
635 shift_amount = (GET_MODE_PRECISION (to_mode)
636 - GET_MODE_PRECISION (from_mode));
637 from = gen_lowpart (to_mode, force_reg (from_mode, from));
638 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
639 to, unsignedp);
640 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
641 to, unsignedp);
642 if (tmp != to)
643 emit_move_insn (to, tmp);
644 return;
648 /* Support special truncate insns for certain modes. */
649 if (convert_optab_handler (trunc_optab, to_mode,
650 from_mode) != CODE_FOR_nothing)
652 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, from_mode),
653 to, from, UNKNOWN);
654 return;
657 /* Handle truncation of volatile memrefs, and so on;
658 the things that couldn't be truncated directly,
659 and for which there was no special instruction.
661 ??? Code above formerly short-circuited this, for most integer
662 mode pairs, with a force_reg in from_mode followed by a recursive
663 call to this routine. Appears always to have been wrong. */
664 if (GET_MODE_PRECISION (to_mode) < GET_MODE_PRECISION (from_mode))
666 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
667 emit_move_insn (to, temp);
668 return;
671 /* Mode combination is not recognized. */
672 gcc_unreachable ();
675 /* Return an rtx for a value that would result
676 from converting X to mode MODE.
677 Both X and MODE may be floating, or both integer.
678 UNSIGNEDP is nonzero if X is an unsigned value.
679 This can be done by referring to a part of X in place
680 or by copying to a new temporary with conversion. */
683 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
685 return convert_modes (mode, VOIDmode, x, unsignedp);
688 /* Return an rtx for a value that would result
689 from converting X from mode OLDMODE to mode MODE.
690 Both modes may be floating, or both integer.
691 UNSIGNEDP is nonzero if X is an unsigned value.
693 This can be done by referring to a part of X in place
694 or by copying to a new temporary with conversion.
696 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
699 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
701 rtx temp;
703 /* If FROM is a SUBREG that indicates that we have already done at least
704 the required extension, strip it. */
706 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
707 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
708 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
709 x = gen_lowpart (mode, x);
711 if (GET_MODE (x) != VOIDmode)
712 oldmode = GET_MODE (x);
714 if (mode == oldmode)
715 return x;
717 /* There is one case that we must handle specially: If we are converting
718 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
719 we are to interpret the constant as unsigned, gen_lowpart will do
720 the wrong if the constant appears negative. What we want to do is
721 make the high-order word of the constant zero, not all ones. */
723 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
724 && GET_MODE_BITSIZE (mode) == HOST_BITS_PER_DOUBLE_INT
725 && CONST_INT_P (x) && INTVAL (x) < 0)
727 double_int val = double_int::from_uhwi (INTVAL (x));
729 /* We need to zero extend VAL. */
730 if (oldmode != VOIDmode)
731 val = val.zext (GET_MODE_BITSIZE (oldmode));
733 return immed_double_int_const (val, mode);
736 /* We can do this with a gen_lowpart if both desired and current modes
737 are integer, and this is either a constant integer, a register, or a
738 non-volatile MEM. Except for the constant case where MODE is no
739 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
741 if ((CONST_INT_P (x)
742 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT)
743 || (GET_MODE_CLASS (mode) == MODE_INT
744 && GET_MODE_CLASS (oldmode) == MODE_INT
745 && (CONST_DOUBLE_AS_INT_P (x)
746 || (GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (oldmode)
747 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
748 && direct_load[(int) mode])
749 || (REG_P (x)
750 && (! HARD_REGISTER_P (x)
751 || HARD_REGNO_MODE_OK (REGNO (x), mode))
752 && TRULY_NOOP_TRUNCATION_MODES_P (mode,
753 GET_MODE (x))))))))
755 /* ?? If we don't know OLDMODE, we have to assume here that
756 X does not need sign- or zero-extension. This may not be
757 the case, but it's the best we can do. */
758 if (CONST_INT_P (x) && oldmode != VOIDmode
759 && GET_MODE_PRECISION (mode) > GET_MODE_PRECISION (oldmode))
761 HOST_WIDE_INT val = INTVAL (x);
763 /* We must sign or zero-extend in this case. Start by
764 zero-extending, then sign extend if we need to. */
765 val &= GET_MODE_MASK (oldmode);
766 if (! unsignedp
767 && val_signbit_known_set_p (oldmode, val))
768 val |= ~GET_MODE_MASK (oldmode);
770 return gen_int_mode (val, mode);
773 return gen_lowpart (mode, x);
776 /* Converting from integer constant into mode is always equivalent to an
777 subreg operation. */
778 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
780 gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
781 return simplify_gen_subreg (mode, x, oldmode, 0);
784 temp = gen_reg_rtx (mode);
785 convert_move (temp, x, unsignedp);
786 return temp;
789 /* Return the largest alignment we can use for doing a move (or store)
790 of MAX_PIECES. ALIGN is the largest alignment we could use. */
792 static unsigned int
793 alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
795 enum machine_mode tmode;
797 tmode = mode_for_size (max_pieces * BITS_PER_UNIT, MODE_INT, 1);
798 if (align >= GET_MODE_ALIGNMENT (tmode))
799 align = GET_MODE_ALIGNMENT (tmode);
800 else
802 enum machine_mode tmode, xmode;
804 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
805 tmode != VOIDmode;
806 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
807 if (GET_MODE_SIZE (tmode) > max_pieces
808 || SLOW_UNALIGNED_ACCESS (tmode, align))
809 break;
811 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
814 return align;
817 /* Return the widest integer mode no wider than SIZE. If no such mode
818 can be found, return VOIDmode. */
820 static enum machine_mode
821 widest_int_mode_for_size (unsigned int size)
823 enum machine_mode tmode, mode = VOIDmode;
825 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
826 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
827 if (GET_MODE_SIZE (tmode) < size)
828 mode = tmode;
830 return mode;
833 /* STORE_MAX_PIECES is the number of bytes at a time that we can
834 store efficiently. Due to internal GCC limitations, this is
835 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
836 for an immediate constant. */
838 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
840 /* Determine whether the LEN bytes can be moved by using several move
841 instructions. Return nonzero if a call to move_by_pieces should
842 succeed. */
845 can_move_by_pieces (unsigned HOST_WIDE_INT len ATTRIBUTE_UNUSED,
846 unsigned int align ATTRIBUTE_UNUSED)
848 return MOVE_BY_PIECES_P (len, align);
851 /* Generate several move instructions to copy LEN bytes from block FROM to
852 block TO. (These are MEM rtx's with BLKmode).
854 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
855 used to push FROM to the stack.
857 ALIGN is maximum stack alignment we can assume.
859 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
860 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
861 stpcpy. */
864 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
865 unsigned int align, int endp)
867 struct move_by_pieces_d data;
868 enum machine_mode to_addr_mode;
869 enum machine_mode from_addr_mode = get_address_mode (from);
870 rtx to_addr, from_addr = XEXP (from, 0);
871 unsigned int max_size = MOVE_MAX_PIECES + 1;
872 enum insn_code icode;
874 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
876 data.offset = 0;
877 data.from_addr = from_addr;
878 if (to)
880 to_addr_mode = get_address_mode (to);
881 to_addr = XEXP (to, 0);
882 data.to = to;
883 data.autinc_to
884 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
885 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
886 data.reverse
887 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
889 else
891 to_addr_mode = VOIDmode;
892 to_addr = NULL_RTX;
893 data.to = NULL_RTX;
894 data.autinc_to = 1;
895 #ifdef STACK_GROWS_DOWNWARD
896 data.reverse = 1;
897 #else
898 data.reverse = 0;
899 #endif
901 data.to_addr = to_addr;
902 data.from = from;
903 data.autinc_from
904 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
905 || GET_CODE (from_addr) == POST_INC
906 || GET_CODE (from_addr) == POST_DEC);
908 data.explicit_inc_from = 0;
909 data.explicit_inc_to = 0;
910 if (data.reverse) data.offset = len;
911 data.len = len;
913 /* If copying requires more than two move insns,
914 copy addresses to registers (to make displacements shorter)
915 and use post-increment if available. */
916 if (!(data.autinc_from && data.autinc_to)
917 && move_by_pieces_ninsns (len, align, max_size) > 2)
919 /* Find the mode of the largest move...
920 MODE might not be used depending on the definitions of the
921 USE_* macros below. */
922 enum machine_mode mode ATTRIBUTE_UNUSED
923 = widest_int_mode_for_size (max_size);
925 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
927 data.from_addr = copy_to_mode_reg (from_addr_mode,
928 plus_constant (from_addr_mode,
929 from_addr, len));
930 data.autinc_from = 1;
931 data.explicit_inc_from = -1;
933 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
935 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
936 data.autinc_from = 1;
937 data.explicit_inc_from = 1;
939 if (!data.autinc_from && CONSTANT_P (from_addr))
940 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
941 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
943 data.to_addr = copy_to_mode_reg (to_addr_mode,
944 plus_constant (to_addr_mode,
945 to_addr, len));
946 data.autinc_to = 1;
947 data.explicit_inc_to = -1;
949 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
951 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
952 data.autinc_to = 1;
953 data.explicit_inc_to = 1;
955 if (!data.autinc_to && CONSTANT_P (to_addr))
956 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
959 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
961 /* First move what we can in the largest integer mode, then go to
962 successively smaller modes. */
964 while (max_size > 1 && data.len > 0)
966 enum machine_mode mode = widest_int_mode_for_size (max_size);
968 if (mode == VOIDmode)
969 break;
971 icode = optab_handler (mov_optab, mode);
972 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
973 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
975 max_size = GET_MODE_SIZE (mode);
978 /* The code above should have handled everything. */
979 gcc_assert (!data.len);
981 if (endp)
983 rtx to1;
985 gcc_assert (!data.reverse);
986 if (data.autinc_to)
988 if (endp == 2)
990 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
991 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
992 else
993 data.to_addr = copy_to_mode_reg (to_addr_mode,
994 plus_constant (to_addr_mode,
995 data.to_addr,
996 -1));
998 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
999 data.offset);
1001 else
1003 if (endp == 2)
1004 --data.offset;
1005 to1 = adjust_address (data.to, QImode, data.offset);
1007 return to1;
1009 else
1010 return data.to;
1013 /* Return number of insns required to move L bytes by pieces.
1014 ALIGN (in bits) is maximum alignment we can assume. */
1016 unsigned HOST_WIDE_INT
1017 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1018 unsigned int max_size)
1020 unsigned HOST_WIDE_INT n_insns = 0;
1022 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1024 while (max_size > 1 && l > 0)
1026 enum machine_mode mode;
1027 enum insn_code icode;
1029 mode = widest_int_mode_for_size (max_size);
1031 if (mode == VOIDmode)
1032 break;
1034 icode = optab_handler (mov_optab, mode);
1035 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1036 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1038 max_size = GET_MODE_SIZE (mode);
1041 gcc_assert (!l);
1042 return n_insns;
1045 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1046 with move instructions for mode MODE. GENFUN is the gen_... function
1047 to make a move insn for that mode. DATA has all the other info. */
1049 static void
1050 move_by_pieces_1 (insn_gen_fn genfun, machine_mode mode,
1051 struct move_by_pieces_d *data)
1053 unsigned int size = GET_MODE_SIZE (mode);
1054 rtx to1 = NULL_RTX, from1;
1056 while (data->len >= size)
1058 if (data->reverse)
1059 data->offset -= size;
1061 if (data->to)
1063 if (data->autinc_to)
1064 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1065 data->offset);
1066 else
1067 to1 = adjust_address (data->to, mode, data->offset);
1070 if (data->autinc_from)
1071 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1072 data->offset);
1073 else
1074 from1 = adjust_address (data->from, mode, data->offset);
1076 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1077 emit_insn (gen_add2_insn (data->to_addr,
1078 gen_int_mode (-(HOST_WIDE_INT) size,
1079 GET_MODE (data->to_addr))));
1080 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1081 emit_insn (gen_add2_insn (data->from_addr,
1082 gen_int_mode (-(HOST_WIDE_INT) size,
1083 GET_MODE (data->from_addr))));
1085 if (data->to)
1086 emit_insn ((*genfun) (to1, from1));
1087 else
1089 #ifdef PUSH_ROUNDING
1090 emit_single_push_insn (mode, from1, NULL);
1091 #else
1092 gcc_unreachable ();
1093 #endif
1096 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1097 emit_insn (gen_add2_insn (data->to_addr,
1098 gen_int_mode (size,
1099 GET_MODE (data->to_addr))));
1100 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1101 emit_insn (gen_add2_insn (data->from_addr,
1102 gen_int_mode (size,
1103 GET_MODE (data->from_addr))));
1105 if (! data->reverse)
1106 data->offset += size;
1108 data->len -= size;
1112 /* Emit code to move a block Y to a block X. This may be done with
1113 string-move instructions, with multiple scalar move instructions,
1114 or with a library call.
1116 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1117 SIZE is an rtx that says how long they are.
1118 ALIGN is the maximum alignment we can assume they have.
1119 METHOD describes what kind of copy this is, and what mechanisms may be used.
1121 Return the address of the new block, if memcpy is called and returns it,
1122 0 otherwise. */
1125 emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
1126 unsigned int expected_align, HOST_WIDE_INT expected_size)
1128 bool may_use_call;
1129 rtx retval = 0;
1130 unsigned int align;
1132 gcc_assert (size);
1133 if (CONST_INT_P (size)
1134 && INTVAL (size) == 0)
1135 return 0;
1137 switch (method)
1139 case BLOCK_OP_NORMAL:
1140 case BLOCK_OP_TAILCALL:
1141 may_use_call = true;
1142 break;
1144 case BLOCK_OP_CALL_PARM:
1145 may_use_call = block_move_libcall_safe_for_call_parm ();
1147 /* Make inhibit_defer_pop nonzero around the library call
1148 to force it to pop the arguments right away. */
1149 NO_DEFER_POP;
1150 break;
1152 case BLOCK_OP_NO_LIBCALL:
1153 may_use_call = false;
1154 break;
1156 default:
1157 gcc_unreachable ();
1160 gcc_assert (MEM_P (x) && MEM_P (y));
1161 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1162 gcc_assert (align >= BITS_PER_UNIT);
1164 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1165 block copy is more efficient for other large modes, e.g. DCmode. */
1166 x = adjust_address (x, BLKmode, 0);
1167 y = adjust_address (y, BLKmode, 0);
1169 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1170 can be incorrect is coming from __builtin_memcpy. */
1171 if (CONST_INT_P (size))
1173 x = shallow_copy_rtx (x);
1174 y = shallow_copy_rtx (y);
1175 set_mem_size (x, INTVAL (size));
1176 set_mem_size (y, INTVAL (size));
1179 if (CONST_INT_P (size) && MOVE_BY_PIECES_P (INTVAL (size), align))
1180 move_by_pieces (x, y, INTVAL (size), align, 0);
1181 else if (emit_block_move_via_movmem (x, y, size, align,
1182 expected_align, expected_size))
1184 else if (may_use_call
1185 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
1186 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
1188 /* Since x and y are passed to a libcall, mark the corresponding
1189 tree EXPR as addressable. */
1190 tree y_expr = MEM_EXPR (y);
1191 tree x_expr = MEM_EXPR (x);
1192 if (y_expr)
1193 mark_addressable (y_expr);
1194 if (x_expr)
1195 mark_addressable (x_expr);
1196 retval = emit_block_move_via_libcall (x, y, size,
1197 method == BLOCK_OP_TAILCALL);
1200 else
1201 emit_block_move_via_loop (x, y, size, align);
1203 if (method == BLOCK_OP_CALL_PARM)
1204 OK_DEFER_POP;
1206 return retval;
1210 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1212 return emit_block_move_hints (x, y, size, method, 0, -1);
1215 /* A subroutine of emit_block_move. Returns true if calling the
1216 block move libcall will not clobber any parameters which may have
1217 already been placed on the stack. */
1219 static bool
1220 block_move_libcall_safe_for_call_parm (void)
1222 #if defined (REG_PARM_STACK_SPACE)
1223 tree fn;
1224 #endif
1226 /* If arguments are pushed on the stack, then they're safe. */
1227 if (PUSH_ARGS)
1228 return true;
1230 /* If registers go on the stack anyway, any argument is sure to clobber
1231 an outgoing argument. */
1232 #if defined (REG_PARM_STACK_SPACE)
1233 fn = emit_block_move_libcall_fn (false);
1234 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1235 depend on its argument. */
1236 (void) fn;
1237 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn ? NULL_TREE : TREE_TYPE (fn)))
1238 && REG_PARM_STACK_SPACE (fn) != 0)
1239 return false;
1240 #endif
1242 /* If any argument goes in memory, then it might clobber an outgoing
1243 argument. */
1245 CUMULATIVE_ARGS args_so_far_v;
1246 cumulative_args_t args_so_far;
1247 tree fn, arg;
1249 fn = emit_block_move_libcall_fn (false);
1250 INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
1251 args_so_far = pack_cumulative_args (&args_so_far_v);
1253 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1254 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1256 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1257 rtx tmp = targetm.calls.function_arg (args_so_far, mode,
1258 NULL_TREE, true);
1259 if (!tmp || !REG_P (tmp))
1260 return false;
1261 if (targetm.calls.arg_partial_bytes (args_so_far, mode, NULL, 1))
1262 return false;
1263 targetm.calls.function_arg_advance (args_so_far, mode,
1264 NULL_TREE, true);
1267 return true;
1270 /* A subroutine of emit_block_move. Expand a movmem pattern;
1271 return true if successful. */
1273 static bool
1274 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
1275 unsigned int expected_align, HOST_WIDE_INT expected_size)
1277 int save_volatile_ok = volatile_ok;
1278 enum machine_mode mode;
1280 if (expected_align < align)
1281 expected_align = align;
1283 /* Since this is a move insn, we don't care about volatility. */
1284 volatile_ok = 1;
1286 /* Try the most limited insn first, because there's no point
1287 including more than one in the machine description unless
1288 the more limited one has some advantage. */
1290 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1291 mode = GET_MODE_WIDER_MODE (mode))
1293 enum insn_code code = direct_optab_handler (movmem_optab, mode);
1295 if (code != CODE_FOR_nothing
1296 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1297 here because if SIZE is less than the mode mask, as it is
1298 returned by the macro, it will definitely be less than the
1299 actual mode mask. */
1300 && ((CONST_INT_P (size)
1301 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1302 <= (GET_MODE_MASK (mode) >> 1)))
1303 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD))
1305 struct expand_operand ops[6];
1306 unsigned int nops;
1308 /* ??? When called via emit_block_move_for_call, it'd be
1309 nice if there were some way to inform the backend, so
1310 that it doesn't fail the expansion because it thinks
1311 emitting the libcall would be more efficient. */
1312 nops = insn_data[(int) code].n_generator_args;
1313 gcc_assert (nops == 4 || nops == 6);
1315 create_fixed_operand (&ops[0], x);
1316 create_fixed_operand (&ops[1], y);
1317 /* The check above guarantees that this size conversion is valid. */
1318 create_convert_operand_to (&ops[2], size, mode, true);
1319 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
1320 if (nops == 6)
1322 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
1323 create_integer_operand (&ops[5], expected_size);
1325 if (maybe_expand_insn (code, nops, ops))
1327 volatile_ok = save_volatile_ok;
1328 return true;
1333 volatile_ok = save_volatile_ok;
1334 return false;
1337 /* A subroutine of emit_block_move. Expand a call to memcpy.
1338 Return the return value from memcpy, 0 otherwise. */
1341 emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
1343 rtx dst_addr, src_addr;
1344 tree call_expr, fn, src_tree, dst_tree, size_tree;
1345 enum machine_mode size_mode;
1346 rtx retval;
1348 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1349 pseudos. We can then place those new pseudos into a VAR_DECL and
1350 use them later. */
1352 dst_addr = copy_addr_to_reg (XEXP (dst, 0));
1353 src_addr = copy_addr_to_reg (XEXP (src, 0));
1355 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1356 src_addr = convert_memory_address (ptr_mode, src_addr);
1358 dst_tree = make_tree (ptr_type_node, dst_addr);
1359 src_tree = make_tree (ptr_type_node, src_addr);
1361 size_mode = TYPE_MODE (sizetype);
1363 size = convert_to_mode (size_mode, size, 1);
1364 size = copy_to_mode_reg (size_mode, size);
1366 /* It is incorrect to use the libcall calling conventions to call
1367 memcpy in this context. This could be a user call to memcpy and
1368 the user may wish to examine the return value from memcpy. For
1369 targets where libcalls and normal calls have different conventions
1370 for returning pointers, we could end up generating incorrect code. */
1372 size_tree = make_tree (sizetype, size);
1374 fn = emit_block_move_libcall_fn (true);
1375 call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
1376 CALL_EXPR_TAILCALL (call_expr) = tailcall;
1378 retval = expand_normal (call_expr);
1380 return retval;
1383 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1384 for the function we use for block copies. */
1386 static GTY(()) tree block_move_fn;
1388 void
1389 init_block_move_fn (const char *asmspec)
1391 if (!block_move_fn)
1393 tree args, fn, attrs, attr_args;
1395 fn = get_identifier ("memcpy");
1396 args = build_function_type_list (ptr_type_node, ptr_type_node,
1397 const_ptr_type_node, sizetype,
1398 NULL_TREE);
1400 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
1401 DECL_EXTERNAL (fn) = 1;
1402 TREE_PUBLIC (fn) = 1;
1403 DECL_ARTIFICIAL (fn) = 1;
1404 TREE_NOTHROW (fn) = 1;
1405 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
1406 DECL_VISIBILITY_SPECIFIED (fn) = 1;
1408 attr_args = build_tree_list (NULL_TREE, build_string (1, "1"));
1409 attrs = tree_cons (get_identifier ("fn spec"), attr_args, NULL);
1411 decl_attributes (&fn, attrs, ATTR_FLAG_BUILT_IN);
1413 block_move_fn = fn;
1416 if (asmspec)
1417 set_user_assembler_name (block_move_fn, asmspec);
1420 static tree
1421 emit_block_move_libcall_fn (int for_call)
1423 static bool emitted_extern;
1425 if (!block_move_fn)
1426 init_block_move_fn (NULL);
1428 if (for_call && !emitted_extern)
1430 emitted_extern = true;
1431 make_decl_rtl (block_move_fn);
1434 return block_move_fn;
1437 /* A subroutine of emit_block_move. Copy the data via an explicit
1438 loop. This is used only when libcalls are forbidden. */
1439 /* ??? It'd be nice to copy in hunks larger than QImode. */
1441 static void
1442 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1443 unsigned int align ATTRIBUTE_UNUSED)
1445 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1446 enum machine_mode x_addr_mode = get_address_mode (x);
1447 enum machine_mode y_addr_mode = get_address_mode (y);
1448 enum machine_mode iter_mode;
1450 iter_mode = GET_MODE (size);
1451 if (iter_mode == VOIDmode)
1452 iter_mode = word_mode;
1454 top_label = gen_label_rtx ();
1455 cmp_label = gen_label_rtx ();
1456 iter = gen_reg_rtx (iter_mode);
1458 emit_move_insn (iter, const0_rtx);
1460 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1461 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1462 do_pending_stack_adjust ();
1464 emit_jump (cmp_label);
1465 emit_label (top_label);
1467 tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
1468 x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
1470 if (x_addr_mode != y_addr_mode)
1471 tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
1472 y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
1474 x = change_address (x, QImode, x_addr);
1475 y = change_address (y, QImode, y_addr);
1477 emit_move_insn (x, y);
1479 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1480 true, OPTAB_LIB_WIDEN);
1481 if (tmp != iter)
1482 emit_move_insn (iter, tmp);
1484 emit_label (cmp_label);
1486 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1487 true, top_label, REG_BR_PROB_BASE * 90 / 100);
1490 /* Copy all or part of a value X into registers starting at REGNO.
1491 The number of registers to be filled is NREGS. */
1493 void
1494 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1496 int i;
1497 #ifdef HAVE_load_multiple
1498 rtx pat;
1499 rtx last;
1500 #endif
1502 if (nregs == 0)
1503 return;
1505 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
1506 x = validize_mem (force_const_mem (mode, x));
1508 /* See if the machine can do this with a load multiple insn. */
1509 #ifdef HAVE_load_multiple
1510 if (HAVE_load_multiple)
1512 last = get_last_insn ();
1513 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1514 GEN_INT (nregs));
1515 if (pat)
1517 emit_insn (pat);
1518 return;
1520 else
1521 delete_insns_since (last);
1523 #endif
1525 for (i = 0; i < nregs; i++)
1526 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1527 operand_subword_force (x, i, mode));
1530 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1531 The number of registers to be filled is NREGS. */
1533 void
1534 move_block_from_reg (int regno, rtx x, int nregs)
1536 int i;
1538 if (nregs == 0)
1539 return;
1541 /* See if the machine can do this with a store multiple insn. */
1542 #ifdef HAVE_store_multiple
1543 if (HAVE_store_multiple)
1545 rtx last = get_last_insn ();
1546 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1547 GEN_INT (nregs));
1548 if (pat)
1550 emit_insn (pat);
1551 return;
1553 else
1554 delete_insns_since (last);
1556 #endif
1558 for (i = 0; i < nregs; i++)
1560 rtx tem = operand_subword (x, i, 1, BLKmode);
1562 gcc_assert (tem);
1564 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1568 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1569 ORIG, where ORIG is a non-consecutive group of registers represented by
1570 a PARALLEL. The clone is identical to the original except in that the
1571 original set of registers is replaced by a new set of pseudo registers.
1572 The new set has the same modes as the original set. */
1575 gen_group_rtx (rtx orig)
1577 int i, length;
1578 rtx *tmps;
1580 gcc_assert (GET_CODE (orig) == PARALLEL);
1582 length = XVECLEN (orig, 0);
1583 tmps = XALLOCAVEC (rtx, length);
1585 /* Skip a NULL entry in first slot. */
1586 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1588 if (i)
1589 tmps[0] = 0;
1591 for (; i < length; i++)
1593 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1594 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1596 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1599 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1602 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1603 except that values are placed in TMPS[i], and must later be moved
1604 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1606 static void
1607 emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
1609 rtx src;
1610 int start, i;
1611 enum machine_mode m = GET_MODE (orig_src);
1613 gcc_assert (GET_CODE (dst) == PARALLEL);
1615 if (m != VOIDmode
1616 && !SCALAR_INT_MODE_P (m)
1617 && !MEM_P (orig_src)
1618 && GET_CODE (orig_src) != CONCAT)
1620 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
1621 if (imode == BLKmode)
1622 src = assign_stack_temp (GET_MODE (orig_src), ssize);
1623 else
1624 src = gen_reg_rtx (imode);
1625 if (imode != BLKmode)
1626 src = gen_lowpart (GET_MODE (orig_src), src);
1627 emit_move_insn (src, orig_src);
1628 /* ...and back again. */
1629 if (imode != BLKmode)
1630 src = gen_lowpart (imode, src);
1631 emit_group_load_1 (tmps, dst, src, type, ssize);
1632 return;
1635 /* Check for a NULL entry, used to indicate that the parameter goes
1636 both on the stack and in registers. */
1637 if (XEXP (XVECEXP (dst, 0, 0), 0))
1638 start = 0;
1639 else
1640 start = 1;
1642 /* Process the pieces. */
1643 for (i = start; i < XVECLEN (dst, 0); i++)
1645 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1646 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1647 unsigned int bytelen = GET_MODE_SIZE (mode);
1648 int shift = 0;
1650 /* Handle trailing fragments that run over the size of the struct. */
1651 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1653 /* Arrange to shift the fragment to where it belongs.
1654 extract_bit_field loads to the lsb of the reg. */
1655 if (
1656 #ifdef BLOCK_REG_PADDING
1657 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1658 == (BYTES_BIG_ENDIAN ? upward : downward)
1659 #else
1660 BYTES_BIG_ENDIAN
1661 #endif
1663 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1664 bytelen = ssize - bytepos;
1665 gcc_assert (bytelen > 0);
1668 /* If we won't be loading directly from memory, protect the real source
1669 from strange tricks we might play; but make sure that the source can
1670 be loaded directly into the destination. */
1671 src = orig_src;
1672 if (!MEM_P (orig_src)
1673 && (!CONSTANT_P (orig_src)
1674 || (GET_MODE (orig_src) != mode
1675 && GET_MODE (orig_src) != VOIDmode)))
1677 if (GET_MODE (orig_src) == VOIDmode)
1678 src = gen_reg_rtx (mode);
1679 else
1680 src = gen_reg_rtx (GET_MODE (orig_src));
1682 emit_move_insn (src, orig_src);
1685 /* Optimize the access just a bit. */
1686 if (MEM_P (src)
1687 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1688 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1689 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1690 && bytelen == GET_MODE_SIZE (mode))
1692 tmps[i] = gen_reg_rtx (mode);
1693 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1695 else if (COMPLEX_MODE_P (mode)
1696 && GET_MODE (src) == mode
1697 && bytelen == GET_MODE_SIZE (mode))
1698 /* Let emit_move_complex do the bulk of the work. */
1699 tmps[i] = src;
1700 else if (GET_CODE (src) == CONCAT)
1702 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1703 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1705 if ((bytepos == 0 && bytelen == slen0)
1706 || (bytepos != 0 && bytepos + bytelen <= slen))
1708 /* The following assumes that the concatenated objects all
1709 have the same size. In this case, a simple calculation
1710 can be used to determine the object and the bit field
1711 to be extracted. */
1712 tmps[i] = XEXP (src, bytepos / slen0);
1713 if (! CONSTANT_P (tmps[i])
1714 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1715 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1716 (bytepos % slen0) * BITS_PER_UNIT,
1717 1, NULL_RTX, mode, mode);
1719 else
1721 rtx mem;
1723 gcc_assert (!bytepos);
1724 mem = assign_stack_temp (GET_MODE (src), slen);
1725 emit_move_insn (mem, src);
1726 tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
1727 0, 1, NULL_RTX, mode, mode);
1730 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1731 SIMD register, which is currently broken. While we get GCC
1732 to emit proper RTL for these cases, let's dump to memory. */
1733 else if (VECTOR_MODE_P (GET_MODE (dst))
1734 && REG_P (src))
1736 int slen = GET_MODE_SIZE (GET_MODE (src));
1737 rtx mem;
1739 mem = assign_stack_temp (GET_MODE (src), slen);
1740 emit_move_insn (mem, src);
1741 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1743 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1744 && XVECLEN (dst, 0) > 1)
1745 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE (dst), bytepos);
1746 else if (CONSTANT_P (src))
1748 HOST_WIDE_INT len = (HOST_WIDE_INT) bytelen;
1750 if (len == ssize)
1751 tmps[i] = src;
1752 else
1754 rtx first, second;
1756 gcc_assert (2 * len == ssize);
1757 split_double (src, &first, &second);
1758 if (i)
1759 tmps[i] = second;
1760 else
1761 tmps[i] = first;
1764 else if (REG_P (src) && GET_MODE (src) == mode)
1765 tmps[i] = src;
1766 else
1767 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1768 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1769 mode, mode);
1771 if (shift)
1772 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1773 shift, tmps[i], 0);
1777 /* Emit code to move a block SRC of type TYPE to a block DST,
1778 where DST is non-consecutive registers represented by a PARALLEL.
1779 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1780 if not known. */
1782 void
1783 emit_group_load (rtx dst, rtx src, tree type, int ssize)
1785 rtx *tmps;
1786 int i;
1788 tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
1789 emit_group_load_1 (tmps, dst, src, type, ssize);
1791 /* Copy the extracted pieces into the proper (probable) hard regs. */
1792 for (i = 0; i < XVECLEN (dst, 0); i++)
1794 rtx d = XEXP (XVECEXP (dst, 0, i), 0);
1795 if (d == NULL)
1796 continue;
1797 emit_move_insn (d, tmps[i]);
1801 /* Similar, but load SRC into new pseudos in a format that looks like
1802 PARALLEL. This can later be fed to emit_group_move to get things
1803 in the right place. */
1806 emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
1808 rtvec vec;
1809 int i;
1811 vec = rtvec_alloc (XVECLEN (parallel, 0));
1812 emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
1814 /* Convert the vector to look just like the original PARALLEL, except
1815 with the computed values. */
1816 for (i = 0; i < XVECLEN (parallel, 0); i++)
1818 rtx e = XVECEXP (parallel, 0, i);
1819 rtx d = XEXP (e, 0);
1821 if (d)
1823 d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
1824 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
1826 RTVEC_ELT (vec, i) = e;
1829 return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
1832 /* Emit code to move a block SRC to block DST, where SRC and DST are
1833 non-consecutive groups of registers, each represented by a PARALLEL. */
1835 void
1836 emit_group_move (rtx dst, rtx src)
1838 int i;
1840 gcc_assert (GET_CODE (src) == PARALLEL
1841 && GET_CODE (dst) == PARALLEL
1842 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1844 /* Skip first entry if NULL. */
1845 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1846 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1847 XEXP (XVECEXP (src, 0, i), 0));
1850 /* Move a group of registers represented by a PARALLEL into pseudos. */
1853 emit_group_move_into_temps (rtx src)
1855 rtvec vec = rtvec_alloc (XVECLEN (src, 0));
1856 int i;
1858 for (i = 0; i < XVECLEN (src, 0); i++)
1860 rtx e = XVECEXP (src, 0, i);
1861 rtx d = XEXP (e, 0);
1863 if (d)
1864 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
1865 RTVEC_ELT (vec, i) = e;
1868 return gen_rtx_PARALLEL (GET_MODE (src), vec);
1871 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1872 where SRC is non-consecutive registers represented by a PARALLEL.
1873 SSIZE represents the total size of block ORIG_DST, or -1 if not
1874 known. */
1876 void
1877 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1879 rtx *tmps, dst;
1880 int start, finish, i;
1881 enum machine_mode m = GET_MODE (orig_dst);
1883 gcc_assert (GET_CODE (src) == PARALLEL);
1885 if (!SCALAR_INT_MODE_P (m)
1886 && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
1888 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
1889 if (imode == BLKmode)
1890 dst = assign_stack_temp (GET_MODE (orig_dst), ssize);
1891 else
1892 dst = gen_reg_rtx (imode);
1893 emit_group_store (dst, src, type, ssize);
1894 if (imode != BLKmode)
1895 dst = gen_lowpart (GET_MODE (orig_dst), dst);
1896 emit_move_insn (orig_dst, dst);
1897 return;
1900 /* Check for a NULL entry, used to indicate that the parameter goes
1901 both on the stack and in registers. */
1902 if (XEXP (XVECEXP (src, 0, 0), 0))
1903 start = 0;
1904 else
1905 start = 1;
1906 finish = XVECLEN (src, 0);
1908 tmps = XALLOCAVEC (rtx, finish);
1910 /* Copy the (probable) hard regs into pseudos. */
1911 for (i = start; i < finish; i++)
1913 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1914 if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
1916 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1917 emit_move_insn (tmps[i], reg);
1919 else
1920 tmps[i] = reg;
1923 /* If we won't be storing directly into memory, protect the real destination
1924 from strange tricks we might play. */
1925 dst = orig_dst;
1926 if (GET_CODE (dst) == PARALLEL)
1928 rtx temp;
1930 /* We can get a PARALLEL dst if there is a conditional expression in
1931 a return statement. In that case, the dst and src are the same,
1932 so no action is necessary. */
1933 if (rtx_equal_p (dst, src))
1934 return;
1936 /* It is unclear if we can ever reach here, but we may as well handle
1937 it. Allocate a temporary, and split this into a store/load to/from
1938 the temporary. */
1940 temp = assign_stack_temp (GET_MODE (dst), ssize);
1941 emit_group_store (temp, src, type, ssize);
1942 emit_group_load (dst, temp, type, ssize);
1943 return;
1945 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1947 enum machine_mode outer = GET_MODE (dst);
1948 enum machine_mode inner;
1949 HOST_WIDE_INT bytepos;
1950 bool done = false;
1951 rtx temp;
1953 if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
1954 dst = gen_reg_rtx (outer);
1956 /* Make life a bit easier for combine. */
1957 /* If the first element of the vector is the low part
1958 of the destination mode, use a paradoxical subreg to
1959 initialize the destination. */
1960 if (start < finish)
1962 inner = GET_MODE (tmps[start]);
1963 bytepos = subreg_lowpart_offset (inner, outer);
1964 if (INTVAL (XEXP (XVECEXP (src, 0, start), 1)) == bytepos)
1966 temp = simplify_gen_subreg (outer, tmps[start],
1967 inner, 0);
1968 if (temp)
1970 emit_move_insn (dst, temp);
1971 done = true;
1972 start++;
1977 /* If the first element wasn't the low part, try the last. */
1978 if (!done
1979 && start < finish - 1)
1981 inner = GET_MODE (tmps[finish - 1]);
1982 bytepos = subreg_lowpart_offset (inner, outer);
1983 if (INTVAL (XEXP (XVECEXP (src, 0, finish - 1), 1)) == bytepos)
1985 temp = simplify_gen_subreg (outer, tmps[finish - 1],
1986 inner, 0);
1987 if (temp)
1989 emit_move_insn (dst, temp);
1990 done = true;
1991 finish--;
1996 /* Otherwise, simply initialize the result to zero. */
1997 if (!done)
1998 emit_move_insn (dst, CONST0_RTX (outer));
2001 /* Process the pieces. */
2002 for (i = start; i < finish; i++)
2004 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
2005 enum machine_mode mode = GET_MODE (tmps[i]);
2006 unsigned int bytelen = GET_MODE_SIZE (mode);
2007 unsigned int adj_bytelen = bytelen;
2008 rtx dest = dst;
2010 /* Handle trailing fragments that run over the size of the struct. */
2011 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2012 adj_bytelen = ssize - bytepos;
2014 if (GET_CODE (dst) == CONCAT)
2016 if (bytepos + adj_bytelen
2017 <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2018 dest = XEXP (dst, 0);
2019 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2021 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
2022 dest = XEXP (dst, 1);
2024 else
2026 enum machine_mode dest_mode = GET_MODE (dest);
2027 enum machine_mode tmp_mode = GET_MODE (tmps[i]);
2029 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
2031 if (GET_MODE_ALIGNMENT (dest_mode)
2032 >= GET_MODE_ALIGNMENT (tmp_mode))
2034 dest = assign_stack_temp (dest_mode,
2035 GET_MODE_SIZE (dest_mode));
2036 emit_move_insn (adjust_address (dest,
2037 tmp_mode,
2038 bytepos),
2039 tmps[i]);
2040 dst = dest;
2042 else
2044 dest = assign_stack_temp (tmp_mode,
2045 GET_MODE_SIZE (tmp_mode));
2046 emit_move_insn (dest, tmps[i]);
2047 dst = adjust_address (dest, dest_mode, bytepos);
2049 break;
2053 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2055 /* store_bit_field always takes its value from the lsb.
2056 Move the fragment to the lsb if it's not already there. */
2057 if (
2058 #ifdef BLOCK_REG_PADDING
2059 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
2060 == (BYTES_BIG_ENDIAN ? upward : downward)
2061 #else
2062 BYTES_BIG_ENDIAN
2063 #endif
2066 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2067 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
2068 shift, tmps[i], 0);
2070 bytelen = adj_bytelen;
2073 /* Optimize the access just a bit. */
2074 if (MEM_P (dest)
2075 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
2076 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
2077 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2078 && bytelen == GET_MODE_SIZE (mode))
2079 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2080 else
2081 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2082 0, 0, mode, tmps[i]);
2085 /* Copy from the pseudo into the (probable) hard reg. */
2086 if (orig_dst != dst)
2087 emit_move_insn (orig_dst, dst);
2090 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2091 of the value stored in X. */
2094 maybe_emit_group_store (rtx x, tree type)
2096 enum machine_mode mode = TYPE_MODE (type);
2097 gcc_checking_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
2098 if (GET_CODE (x) == PARALLEL)
2100 rtx result = gen_reg_rtx (mode);
2101 emit_group_store (result, x, type, int_size_in_bytes (type));
2102 return result;
2104 return x;
2107 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2109 This is used on targets that return BLKmode values in registers. */
2111 void
2112 copy_blkmode_from_reg (rtx target, rtx srcreg, tree type)
2114 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2115 rtx src = NULL, dst = NULL;
2116 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2117 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2118 enum machine_mode mode = GET_MODE (srcreg);
2119 enum machine_mode tmode = GET_MODE (target);
2120 enum machine_mode copy_mode;
2122 /* BLKmode registers created in the back-end shouldn't have survived. */
2123 gcc_assert (mode != BLKmode);
2125 /* If the structure doesn't take up a whole number of words, see whether
2126 SRCREG is padded on the left or on the right. If it's on the left,
2127 set PADDING_CORRECTION to the number of bits to skip.
2129 In most ABIs, the structure will be returned at the least end of
2130 the register, which translates to right padding on little-endian
2131 targets and left padding on big-endian targets. The opposite
2132 holds if the structure is returned at the most significant
2133 end of the register. */
2134 if (bytes % UNITS_PER_WORD != 0
2135 && (targetm.calls.return_in_msb (type)
2136 ? !BYTES_BIG_ENDIAN
2137 : BYTES_BIG_ENDIAN))
2138 padding_correction
2139 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2141 /* We can use a single move if we have an exact mode for the size. */
2142 else if (MEM_P (target)
2143 && (!SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target))
2144 || MEM_ALIGN (target) >= GET_MODE_ALIGNMENT (mode))
2145 && bytes == GET_MODE_SIZE (mode))
2147 emit_move_insn (adjust_address (target, mode, 0), srcreg);
2148 return;
2151 /* And if we additionally have the same mode for a register. */
2152 else if (REG_P (target)
2153 && GET_MODE (target) == mode
2154 && bytes == GET_MODE_SIZE (mode))
2156 emit_move_insn (target, srcreg);
2157 return;
2160 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2161 into a new pseudo which is a full word. */
2162 if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
2164 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
2165 mode = word_mode;
2168 /* Copy the structure BITSIZE bits at a time. If the target lives in
2169 memory, take care of not reading/writing past its end by selecting
2170 a copy mode suited to BITSIZE. This should always be possible given
2171 how it is computed.
2173 If the target lives in register, make sure not to select a copy mode
2174 larger than the mode of the register.
2176 We could probably emit more efficient code for machines which do not use
2177 strict alignment, but it doesn't seem worth the effort at the current
2178 time. */
2180 copy_mode = word_mode;
2181 if (MEM_P (target))
2183 enum machine_mode mem_mode = mode_for_size (bitsize, MODE_INT, 1);
2184 if (mem_mode != BLKmode)
2185 copy_mode = mem_mode;
2187 else if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
2188 copy_mode = tmode;
2190 for (bitpos = 0, xbitpos = padding_correction;
2191 bitpos < bytes * BITS_PER_UNIT;
2192 bitpos += bitsize, xbitpos += bitsize)
2194 /* We need a new source operand each time xbitpos is on a
2195 word boundary and when xbitpos == padding_correction
2196 (the first time through). */
2197 if (xbitpos % BITS_PER_WORD == 0 || xbitpos == padding_correction)
2198 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD, mode);
2200 /* We need a new destination operand each time bitpos is on
2201 a word boundary. */
2202 if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
2203 dst = target;
2204 else if (bitpos % BITS_PER_WORD == 0)
2205 dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, tmode);
2207 /* Use xbitpos for the source extraction (right justified) and
2208 bitpos for the destination store (left justified). */
2209 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
2210 extract_bit_field (src, bitsize,
2211 xbitpos % BITS_PER_WORD, 1,
2212 NULL_RTX, copy_mode, copy_mode));
2216 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2217 register if it contains any data, otherwise return null.
2219 This is used on targets that return BLKmode values in registers. */
2222 copy_blkmode_to_reg (enum machine_mode mode, tree src)
2224 int i, n_regs;
2225 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
2226 unsigned int bitsize;
2227 rtx *dst_words, dst, x, src_word = NULL_RTX, dst_word = NULL_RTX;
2228 enum machine_mode dst_mode;
2230 gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
2232 x = expand_normal (src);
2234 bytes = int_size_in_bytes (TREE_TYPE (src));
2235 if (bytes == 0)
2236 return NULL_RTX;
2238 /* If the structure doesn't take up a whole number of words, see
2239 whether the register value should be padded on the left or on
2240 the right. Set PADDING_CORRECTION to the number of padding
2241 bits needed on the left side.
2243 In most ABIs, the structure will be returned at the least end of
2244 the register, which translates to right padding on little-endian
2245 targets and left padding on big-endian targets. The opposite
2246 holds if the structure is returned at the most significant
2247 end of the register. */
2248 if (bytes % UNITS_PER_WORD != 0
2249 && (targetm.calls.return_in_msb (TREE_TYPE (src))
2250 ? !BYTES_BIG_ENDIAN
2251 : BYTES_BIG_ENDIAN))
2252 padding_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2253 * BITS_PER_UNIT));
2255 n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2256 dst_words = XALLOCAVEC (rtx, n_regs);
2257 bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
2259 /* Copy the structure BITSIZE bits at a time. */
2260 for (bitpos = 0, xbitpos = padding_correction;
2261 bitpos < bytes * BITS_PER_UNIT;
2262 bitpos += bitsize, xbitpos += bitsize)
2264 /* We need a new destination pseudo each time xbitpos is
2265 on a word boundary and when xbitpos == padding_correction
2266 (the first time through). */
2267 if (xbitpos % BITS_PER_WORD == 0
2268 || xbitpos == padding_correction)
2270 /* Generate an appropriate register. */
2271 dst_word = gen_reg_rtx (word_mode);
2272 dst_words[xbitpos / BITS_PER_WORD] = dst_word;
2274 /* Clear the destination before we move anything into it. */
2275 emit_move_insn (dst_word, CONST0_RTX (word_mode));
2278 /* We need a new source operand each time bitpos is on a word
2279 boundary. */
2280 if (bitpos % BITS_PER_WORD == 0)
2281 src_word = operand_subword_force (x, bitpos / BITS_PER_WORD, BLKmode);
2283 /* Use bitpos for the source extraction (left justified) and
2284 xbitpos for the destination store (right justified). */
2285 store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
2286 0, 0, word_mode,
2287 extract_bit_field (src_word, bitsize,
2288 bitpos % BITS_PER_WORD, 1,
2289 NULL_RTX, word_mode, word_mode));
2292 if (mode == BLKmode)
2294 /* Find the smallest integer mode large enough to hold the
2295 entire structure. */
2296 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2297 mode != VOIDmode;
2298 mode = GET_MODE_WIDER_MODE (mode))
2299 /* Have we found a large enough mode? */
2300 if (GET_MODE_SIZE (mode) >= bytes)
2301 break;
2303 /* A suitable mode should have been found. */
2304 gcc_assert (mode != VOIDmode);
2307 if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
2308 dst_mode = word_mode;
2309 else
2310 dst_mode = mode;
2311 dst = gen_reg_rtx (dst_mode);
2313 for (i = 0; i < n_regs; i++)
2314 emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
2316 if (mode != dst_mode)
2317 dst = gen_lowpart (mode, dst);
2319 return dst;
2322 /* Add a USE expression for REG to the (possibly empty) list pointed
2323 to by CALL_FUSAGE. REG must denote a hard register. */
2325 void
2326 use_reg_mode (rtx *call_fusage, rtx reg, enum machine_mode mode)
2328 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
2330 *call_fusage
2331 = gen_rtx_EXPR_LIST (mode, gen_rtx_USE (VOIDmode, reg), *call_fusage);
2334 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2335 starting at REGNO. All of these registers must be hard registers. */
2337 void
2338 use_regs (rtx *call_fusage, int regno, int nregs)
2340 int i;
2342 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
2344 for (i = 0; i < nregs; i++)
2345 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2348 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2349 PARALLEL REGS. This is for calls that pass values in multiple
2350 non-contiguous locations. The Irix 6 ABI has examples of this. */
2352 void
2353 use_group_regs (rtx *call_fusage, rtx regs)
2355 int i;
2357 for (i = 0; i < XVECLEN (regs, 0); i++)
2359 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2361 /* A NULL entry means the parameter goes both on the stack and in
2362 registers. This can also be a MEM for targets that pass values
2363 partially on the stack and partially in registers. */
2364 if (reg != 0 && REG_P (reg))
2365 use_reg (call_fusage, reg);
2369 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2370 assigment and the code of the expresion on the RHS is CODE. Return
2371 NULL otherwise. */
2373 static gimple
2374 get_def_for_expr (tree name, enum tree_code code)
2376 gimple def_stmt;
2378 if (TREE_CODE (name) != SSA_NAME)
2379 return NULL;
2381 def_stmt = get_gimple_for_ssa_name (name);
2382 if (!def_stmt
2383 || gimple_assign_rhs_code (def_stmt) != code)
2384 return NULL;
2386 return def_stmt;
2389 #ifdef HAVE_conditional_move
2390 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2391 assigment and the class of the expresion on the RHS is CLASS. Return
2392 NULL otherwise. */
2394 static gimple
2395 get_def_for_expr_class (tree name, enum tree_code_class tclass)
2397 gimple def_stmt;
2399 if (TREE_CODE (name) != SSA_NAME)
2400 return NULL;
2402 def_stmt = get_gimple_for_ssa_name (name);
2403 if (!def_stmt
2404 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) != tclass)
2405 return NULL;
2407 return def_stmt;
2409 #endif
2412 /* Determine whether the LEN bytes generated by CONSTFUN can be
2413 stored to memory using several move instructions. CONSTFUNDATA is
2414 a pointer which will be passed as argument in every CONSTFUN call.
2415 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2416 a memset operation and false if it's a copy of a constant string.
2417 Return nonzero if a call to store_by_pieces should succeed. */
2420 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2421 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2422 void *constfundata, unsigned int align, bool memsetp)
2424 unsigned HOST_WIDE_INT l;
2425 unsigned int max_size;
2426 HOST_WIDE_INT offset = 0;
2427 enum machine_mode mode;
2428 enum insn_code icode;
2429 int reverse;
2430 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2431 rtx cst ATTRIBUTE_UNUSED;
2433 if (len == 0)
2434 return 1;
2436 if (! (memsetp
2437 ? SET_BY_PIECES_P (len, align)
2438 : STORE_BY_PIECES_P (len, align)))
2439 return 0;
2441 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2443 /* We would first store what we can in the largest integer mode, then go to
2444 successively smaller modes. */
2446 for (reverse = 0;
2447 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2448 reverse++)
2450 l = len;
2451 max_size = STORE_MAX_PIECES + 1;
2452 while (max_size > 1 && l > 0)
2454 mode = widest_int_mode_for_size (max_size);
2456 if (mode == VOIDmode)
2457 break;
2459 icode = optab_handler (mov_optab, mode);
2460 if (icode != CODE_FOR_nothing
2461 && align >= GET_MODE_ALIGNMENT (mode))
2463 unsigned int size = GET_MODE_SIZE (mode);
2465 while (l >= size)
2467 if (reverse)
2468 offset -= size;
2470 cst = (*constfun) (constfundata, offset, mode);
2471 if (!targetm.legitimate_constant_p (mode, cst))
2472 return 0;
2474 if (!reverse)
2475 offset += size;
2477 l -= size;
2481 max_size = GET_MODE_SIZE (mode);
2484 /* The code above should have handled everything. */
2485 gcc_assert (!l);
2488 return 1;
2491 /* Generate several move instructions to store LEN bytes generated by
2492 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2493 pointer which will be passed as argument in every CONSTFUN call.
2494 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2495 a memset operation and false if it's a copy of a constant string.
2496 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2497 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2498 stpcpy. */
2501 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2502 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2503 void *constfundata, unsigned int align, bool memsetp, int endp)
2505 enum machine_mode to_addr_mode = get_address_mode (to);
2506 struct store_by_pieces_d data;
2508 if (len == 0)
2510 gcc_assert (endp != 2);
2511 return to;
2514 gcc_assert (memsetp
2515 ? SET_BY_PIECES_P (len, align)
2516 : STORE_BY_PIECES_P (len, align));
2517 data.constfun = constfun;
2518 data.constfundata = constfundata;
2519 data.len = len;
2520 data.to = to;
2521 store_by_pieces_1 (&data, align);
2522 if (endp)
2524 rtx to1;
2526 gcc_assert (!data.reverse);
2527 if (data.autinc_to)
2529 if (endp == 2)
2531 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2532 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2533 else
2534 data.to_addr = copy_to_mode_reg (to_addr_mode,
2535 plus_constant (to_addr_mode,
2536 data.to_addr,
2537 -1));
2539 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2540 data.offset);
2542 else
2544 if (endp == 2)
2545 --data.offset;
2546 to1 = adjust_address (data.to, QImode, data.offset);
2548 return to1;
2550 else
2551 return data.to;
2554 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2555 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2557 static void
2558 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2560 struct store_by_pieces_d data;
2562 if (len == 0)
2563 return;
2565 data.constfun = clear_by_pieces_1;
2566 data.constfundata = NULL;
2567 data.len = len;
2568 data.to = to;
2569 store_by_pieces_1 (&data, align);
2572 /* Callback routine for clear_by_pieces.
2573 Return const0_rtx unconditionally. */
2575 static rtx
2576 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2577 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2578 enum machine_mode mode ATTRIBUTE_UNUSED)
2580 return const0_rtx;
2583 /* Subroutine of clear_by_pieces and store_by_pieces.
2584 Generate several move instructions to store LEN bytes of block TO. (A MEM
2585 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2587 static void
2588 store_by_pieces_1 (struct store_by_pieces_d *data ATTRIBUTE_UNUSED,
2589 unsigned int align ATTRIBUTE_UNUSED)
2591 enum machine_mode to_addr_mode = get_address_mode (data->to);
2592 rtx to_addr = XEXP (data->to, 0);
2593 unsigned int max_size = STORE_MAX_PIECES + 1;
2594 enum insn_code icode;
2596 data->offset = 0;
2597 data->to_addr = to_addr;
2598 data->autinc_to
2599 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2600 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2602 data->explicit_inc_to = 0;
2603 data->reverse
2604 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2605 if (data->reverse)
2606 data->offset = data->len;
2608 /* If storing requires more than two move insns,
2609 copy addresses to registers (to make displacements shorter)
2610 and use post-increment if available. */
2611 if (!data->autinc_to
2612 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2614 /* Determine the main mode we'll be using.
2615 MODE might not be used depending on the definitions of the
2616 USE_* macros below. */
2617 enum machine_mode mode ATTRIBUTE_UNUSED
2618 = widest_int_mode_for_size (max_size);
2620 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2622 data->to_addr = copy_to_mode_reg (to_addr_mode,
2623 plus_constant (to_addr_mode,
2624 to_addr,
2625 data->len));
2626 data->autinc_to = 1;
2627 data->explicit_inc_to = -1;
2630 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2631 && ! data->autinc_to)
2633 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2634 data->autinc_to = 1;
2635 data->explicit_inc_to = 1;
2638 if ( !data->autinc_to && CONSTANT_P (to_addr))
2639 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2642 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2644 /* First store what we can in the largest integer mode, then go to
2645 successively smaller modes. */
2647 while (max_size > 1 && data->len > 0)
2649 enum machine_mode mode = widest_int_mode_for_size (max_size);
2651 if (mode == VOIDmode)
2652 break;
2654 icode = optab_handler (mov_optab, mode);
2655 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2656 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2658 max_size = GET_MODE_SIZE (mode);
2661 /* The code above should have handled everything. */
2662 gcc_assert (!data->len);
2665 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2666 with move instructions for mode MODE. GENFUN is the gen_... function
2667 to make a move insn for that mode. DATA has all the other info. */
2669 static void
2670 store_by_pieces_2 (insn_gen_fn genfun, machine_mode mode,
2671 struct store_by_pieces_d *data)
2673 unsigned int size = GET_MODE_SIZE (mode);
2674 rtx to1, cst;
2676 while (data->len >= size)
2678 if (data->reverse)
2679 data->offset -= size;
2681 if (data->autinc_to)
2682 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2683 data->offset);
2684 else
2685 to1 = adjust_address (data->to, mode, data->offset);
2687 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2688 emit_insn (gen_add2_insn (data->to_addr,
2689 gen_int_mode (-(HOST_WIDE_INT) size,
2690 GET_MODE (data->to_addr))));
2692 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2693 emit_insn ((*genfun) (to1, cst));
2695 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2696 emit_insn (gen_add2_insn (data->to_addr,
2697 gen_int_mode (size,
2698 GET_MODE (data->to_addr))));
2700 if (! data->reverse)
2701 data->offset += size;
2703 data->len -= size;
2707 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2708 its length in bytes. */
2711 clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
2712 unsigned int expected_align, HOST_WIDE_INT expected_size)
2714 enum machine_mode mode = GET_MODE (object);
2715 unsigned int align;
2717 gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
2719 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2720 just move a zero. Otherwise, do this a piece at a time. */
2721 if (mode != BLKmode
2722 && CONST_INT_P (size)
2723 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
2725 rtx zero = CONST0_RTX (mode);
2726 if (zero != NULL)
2728 emit_move_insn (object, zero);
2729 return NULL;
2732 if (COMPLEX_MODE_P (mode))
2734 zero = CONST0_RTX (GET_MODE_INNER (mode));
2735 if (zero != NULL)
2737 write_complex_part (object, zero, 0);
2738 write_complex_part (object, zero, 1);
2739 return NULL;
2744 if (size == const0_rtx)
2745 return NULL;
2747 align = MEM_ALIGN (object);
2749 if (CONST_INT_P (size)
2750 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2751 clear_by_pieces (object, INTVAL (size), align);
2752 else if (set_storage_via_setmem (object, size, const0_rtx, align,
2753 expected_align, expected_size))
2755 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
2756 return set_storage_via_libcall (object, size, const0_rtx,
2757 method == BLOCK_OP_TAILCALL);
2758 else
2759 gcc_unreachable ();
2761 return NULL;
2765 clear_storage (rtx object, rtx size, enum block_op_methods method)
2767 return clear_storage_hints (object, size, method, 0, -1);
2771 /* A subroutine of clear_storage. Expand a call to memset.
2772 Return the return value of memset, 0 otherwise. */
2775 set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
2777 tree call_expr, fn, object_tree, size_tree, val_tree;
2778 enum machine_mode size_mode;
2779 rtx retval;
2781 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2782 place those into new pseudos into a VAR_DECL and use them later. */
2784 object = copy_addr_to_reg (XEXP (object, 0));
2786 size_mode = TYPE_MODE (sizetype);
2787 size = convert_to_mode (size_mode, size, 1);
2788 size = copy_to_mode_reg (size_mode, size);
2790 /* It is incorrect to use the libcall calling conventions to call
2791 memset in this context. This could be a user call to memset and
2792 the user may wish to examine the return value from memset. For
2793 targets where libcalls and normal calls have different conventions
2794 for returning pointers, we could end up generating incorrect code. */
2796 object_tree = make_tree (ptr_type_node, object);
2797 if (!CONST_INT_P (val))
2798 val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
2799 size_tree = make_tree (sizetype, size);
2800 val_tree = make_tree (integer_type_node, val);
2802 fn = clear_storage_libcall_fn (true);
2803 call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
2804 CALL_EXPR_TAILCALL (call_expr) = tailcall;
2806 retval = expand_normal (call_expr);
2808 return retval;
2811 /* A subroutine of set_storage_via_libcall. Create the tree node
2812 for the function we use for block clears. */
2814 tree block_clear_fn;
2816 void
2817 init_block_clear_fn (const char *asmspec)
2819 if (!block_clear_fn)
2821 tree fn, args;
2823 fn = get_identifier ("memset");
2824 args = build_function_type_list (ptr_type_node, ptr_type_node,
2825 integer_type_node, sizetype,
2826 NULL_TREE);
2828 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
2829 DECL_EXTERNAL (fn) = 1;
2830 TREE_PUBLIC (fn) = 1;
2831 DECL_ARTIFICIAL (fn) = 1;
2832 TREE_NOTHROW (fn) = 1;
2833 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
2834 DECL_VISIBILITY_SPECIFIED (fn) = 1;
2836 block_clear_fn = fn;
2839 if (asmspec)
2840 set_user_assembler_name (block_clear_fn, asmspec);
2843 static tree
2844 clear_storage_libcall_fn (int for_call)
2846 static bool emitted_extern;
2848 if (!block_clear_fn)
2849 init_block_clear_fn (NULL);
2851 if (for_call && !emitted_extern)
2853 emitted_extern = true;
2854 make_decl_rtl (block_clear_fn);
2857 return block_clear_fn;
2860 /* Expand a setmem pattern; return true if successful. */
2862 bool
2863 set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
2864 unsigned int expected_align, HOST_WIDE_INT expected_size)
2866 /* Try the most limited insn first, because there's no point
2867 including more than one in the machine description unless
2868 the more limited one has some advantage. */
2870 enum machine_mode mode;
2872 if (expected_align < align)
2873 expected_align = align;
2875 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2876 mode = GET_MODE_WIDER_MODE (mode))
2878 enum insn_code code = direct_optab_handler (setmem_optab, mode);
2880 if (code != CODE_FOR_nothing
2881 /* We don't need MODE to be narrower than
2882 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2883 the mode mask, as it is returned by the macro, it will
2884 definitely be less than the actual mode mask. */
2885 && ((CONST_INT_P (size)
2886 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2887 <= (GET_MODE_MASK (mode) >> 1)))
2888 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD))
2890 struct expand_operand ops[6];
2891 unsigned int nops;
2893 nops = insn_data[(int) code].n_generator_args;
2894 gcc_assert (nops == 4 || nops == 6);
2896 create_fixed_operand (&ops[0], object);
2897 /* The check above guarantees that this size conversion is valid. */
2898 create_convert_operand_to (&ops[1], size, mode, true);
2899 create_convert_operand_from (&ops[2], val, byte_mode, true);
2900 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2901 if (nops == 6)
2903 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2904 create_integer_operand (&ops[5], expected_size);
2906 if (maybe_expand_insn (code, nops, ops))
2907 return true;
2911 return false;
2915 /* Write to one of the components of the complex value CPLX. Write VAL to
2916 the real part if IMAG_P is false, and the imaginary part if its true. */
2918 static void
2919 write_complex_part (rtx cplx, rtx val, bool imag_p)
2921 enum machine_mode cmode;
2922 enum machine_mode imode;
2923 unsigned ibitsize;
2925 if (GET_CODE (cplx) == CONCAT)
2927 emit_move_insn (XEXP (cplx, imag_p), val);
2928 return;
2931 cmode = GET_MODE (cplx);
2932 imode = GET_MODE_INNER (cmode);
2933 ibitsize = GET_MODE_BITSIZE (imode);
2935 /* For MEMs simplify_gen_subreg may generate an invalid new address
2936 because, e.g., the original address is considered mode-dependent
2937 by the target, which restricts simplify_subreg from invoking
2938 adjust_address_nv. Instead of preparing fallback support for an
2939 invalid address, we call adjust_address_nv directly. */
2940 if (MEM_P (cplx))
2942 emit_move_insn (adjust_address_nv (cplx, imode,
2943 imag_p ? GET_MODE_SIZE (imode) : 0),
2944 val);
2945 return;
2948 /* If the sub-object is at least word sized, then we know that subregging
2949 will work. This special case is important, since store_bit_field
2950 wants to operate on integer modes, and there's rarely an OImode to
2951 correspond to TCmode. */
2952 if (ibitsize >= BITS_PER_WORD
2953 /* For hard regs we have exact predicates. Assume we can split
2954 the original object if it spans an even number of hard regs.
2955 This special case is important for SCmode on 64-bit platforms
2956 where the natural size of floating-point regs is 32-bit. */
2957 || (REG_P (cplx)
2958 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2959 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2961 rtx part = simplify_gen_subreg (imode, cplx, cmode,
2962 imag_p ? GET_MODE_SIZE (imode) : 0);
2963 if (part)
2965 emit_move_insn (part, val);
2966 return;
2968 else
2969 /* simplify_gen_subreg may fail for sub-word MEMs. */
2970 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2973 store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, 0, 0, imode, val);
2976 /* Extract one of the components of the complex value CPLX. Extract the
2977 real part if IMAG_P is false, and the imaginary part if it's true. */
2979 static rtx
2980 read_complex_part (rtx cplx, bool imag_p)
2982 enum machine_mode cmode, imode;
2983 unsigned ibitsize;
2985 if (GET_CODE (cplx) == CONCAT)
2986 return XEXP (cplx, imag_p);
2988 cmode = GET_MODE (cplx);
2989 imode = GET_MODE_INNER (cmode);
2990 ibitsize = GET_MODE_BITSIZE (imode);
2992 /* Special case reads from complex constants that got spilled to memory. */
2993 if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
2995 tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
2996 if (decl && TREE_CODE (decl) == COMPLEX_CST)
2998 tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
2999 if (CONSTANT_CLASS_P (part))
3000 return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
3004 /* For MEMs simplify_gen_subreg may generate an invalid new address
3005 because, e.g., the original address is considered mode-dependent
3006 by the target, which restricts simplify_subreg from invoking
3007 adjust_address_nv. Instead of preparing fallback support for an
3008 invalid address, we call adjust_address_nv directly. */
3009 if (MEM_P (cplx))
3010 return adjust_address_nv (cplx, imode,
3011 imag_p ? GET_MODE_SIZE (imode) : 0);
3013 /* If the sub-object is at least word sized, then we know that subregging
3014 will work. This special case is important, since extract_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 ret = simplify_gen_subreg (imode, cplx, cmode,
3027 imag_p ? GET_MODE_SIZE (imode) : 0);
3028 if (ret)
3029 return ret;
3030 else
3031 /* simplify_gen_subreg may fail for sub-word MEMs. */
3032 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
3035 return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
3036 true, NULL_RTX, imode, imode);
3039 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3040 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3041 represented in NEW_MODE. If FORCE is true, this will never happen, as
3042 we'll force-create a SUBREG if needed. */
3044 static rtx
3045 emit_move_change_mode (enum machine_mode new_mode,
3046 enum machine_mode old_mode, rtx x, bool force)
3048 rtx ret;
3050 if (push_operand (x, GET_MODE (x)))
3052 ret = gen_rtx_MEM (new_mode, XEXP (x, 0));
3053 MEM_COPY_ATTRIBUTES (ret, x);
3055 else if (MEM_P (x))
3057 /* We don't have to worry about changing the address since the
3058 size in bytes is supposed to be the same. */
3059 if (reload_in_progress)
3061 /* Copy the MEM to change the mode and move any
3062 substitutions from the old MEM to the new one. */
3063 ret = adjust_address_nv (x, new_mode, 0);
3064 copy_replacements (x, ret);
3066 else
3067 ret = adjust_address (x, new_mode, 0);
3069 else
3071 /* Note that we do want simplify_subreg's behavior of validating
3072 that the new mode is ok for a hard register. If we were to use
3073 simplify_gen_subreg, we would create the subreg, but would
3074 probably run into the target not being able to implement it. */
3075 /* Except, of course, when FORCE is true, when this is exactly what
3076 we want. Which is needed for CCmodes on some targets. */
3077 if (force)
3078 ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
3079 else
3080 ret = simplify_subreg (new_mode, x, old_mode, 0);
3083 return ret;
3086 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3087 an integer mode of the same size as MODE. Returns the instruction
3088 emitted, or NULL if such a move could not be generated. */
3090 static rtx
3091 emit_move_via_integer (enum machine_mode mode, rtx x, rtx y, bool force)
3093 enum machine_mode imode;
3094 enum insn_code code;
3096 /* There must exist a mode of the exact size we require. */
3097 imode = int_mode_for_mode (mode);
3098 if (imode == BLKmode)
3099 return NULL_RTX;
3101 /* The target must support moves in this mode. */
3102 code = optab_handler (mov_optab, imode);
3103 if (code == CODE_FOR_nothing)
3104 return NULL_RTX;
3106 x = emit_move_change_mode (imode, mode, x, force);
3107 if (x == NULL_RTX)
3108 return NULL_RTX;
3109 y = emit_move_change_mode (imode, mode, y, force);
3110 if (y == NULL_RTX)
3111 return NULL_RTX;
3112 return emit_insn (GEN_FCN (code) (x, y));
3115 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3116 Return an equivalent MEM that does not use an auto-increment. */
3118 static rtx
3119 emit_move_resolve_push (enum machine_mode mode, rtx x)
3121 enum rtx_code code = GET_CODE (XEXP (x, 0));
3122 HOST_WIDE_INT adjust;
3123 rtx temp;
3125 adjust = GET_MODE_SIZE (mode);
3126 #ifdef PUSH_ROUNDING
3127 adjust = PUSH_ROUNDING (adjust);
3128 #endif
3129 if (code == PRE_DEC || code == POST_DEC)
3130 adjust = -adjust;
3131 else if (code == PRE_MODIFY || code == POST_MODIFY)
3133 rtx expr = XEXP (XEXP (x, 0), 1);
3134 HOST_WIDE_INT val;
3136 gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
3137 gcc_assert (CONST_INT_P (XEXP (expr, 1)));
3138 val = INTVAL (XEXP (expr, 1));
3139 if (GET_CODE (expr) == MINUS)
3140 val = -val;
3141 gcc_assert (adjust == val || adjust == -val);
3142 adjust = val;
3145 /* Do not use anti_adjust_stack, since we don't want to update
3146 stack_pointer_delta. */
3147 temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
3148 gen_int_mode (adjust, Pmode), stack_pointer_rtx,
3149 0, OPTAB_LIB_WIDEN);
3150 if (temp != stack_pointer_rtx)
3151 emit_move_insn (stack_pointer_rtx, temp);
3153 switch (code)
3155 case PRE_INC:
3156 case PRE_DEC:
3157 case PRE_MODIFY:
3158 temp = stack_pointer_rtx;
3159 break;
3160 case POST_INC:
3161 case POST_DEC:
3162 case POST_MODIFY:
3163 temp = plus_constant (Pmode, stack_pointer_rtx, -adjust);
3164 break;
3165 default:
3166 gcc_unreachable ();
3169 return replace_equiv_address (x, temp);
3172 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3173 X is known to satisfy push_operand, and MODE is known to be complex.
3174 Returns the last instruction emitted. */
3177 emit_move_complex_push (enum machine_mode mode, rtx x, rtx y)
3179 enum machine_mode submode = GET_MODE_INNER (mode);
3180 bool imag_first;
3182 #ifdef PUSH_ROUNDING
3183 unsigned int submodesize = GET_MODE_SIZE (submode);
3185 /* In case we output to the stack, but the size is smaller than the
3186 machine can push exactly, we need to use move instructions. */
3187 if (PUSH_ROUNDING (submodesize) != submodesize)
3189 x = emit_move_resolve_push (mode, x);
3190 return emit_move_insn (x, y);
3192 #endif
3194 /* Note that the real part always precedes the imag part in memory
3195 regardless of machine's endianness. */
3196 switch (GET_CODE (XEXP (x, 0)))
3198 case PRE_DEC:
3199 case POST_DEC:
3200 imag_first = true;
3201 break;
3202 case PRE_INC:
3203 case POST_INC:
3204 imag_first = false;
3205 break;
3206 default:
3207 gcc_unreachable ();
3210 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3211 read_complex_part (y, imag_first));
3212 return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3213 read_complex_part (y, !imag_first));
3216 /* A subroutine of emit_move_complex. Perform the move from Y to X
3217 via two moves of the parts. Returns the last instruction emitted. */
3220 emit_move_complex_parts (rtx x, rtx y)
3222 /* Show the output dies here. This is necessary for SUBREGs
3223 of pseudos since we cannot track their lifetimes correctly;
3224 hard regs shouldn't appear here except as return values. */
3225 if (!reload_completed && !reload_in_progress
3226 && REG_P (x) && !reg_overlap_mentioned_p (x, y))
3227 emit_clobber (x);
3229 write_complex_part (x, read_complex_part (y, false), false);
3230 write_complex_part (x, read_complex_part (y, true), true);
3232 return get_last_insn ();
3235 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3236 MODE is known to be complex. Returns the last instruction emitted. */
3238 static rtx
3239 emit_move_complex (enum machine_mode mode, rtx x, rtx y)
3241 bool try_int;
3243 /* Need to take special care for pushes, to maintain proper ordering
3244 of the data, and possibly extra padding. */
3245 if (push_operand (x, mode))
3246 return emit_move_complex_push (mode, x, y);
3248 /* See if we can coerce the target into moving both values at once, except
3249 for floating point where we favor moving as parts if this is easy. */
3250 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3251 && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing
3252 && !(REG_P (x)
3253 && HARD_REGISTER_P (x)
3254 && hard_regno_nregs[REGNO (x)][mode] == 1)
3255 && !(REG_P (y)
3256 && HARD_REGISTER_P (y)
3257 && hard_regno_nregs[REGNO (y)][mode] == 1))
3258 try_int = false;
3259 /* Not possible if the values are inherently not adjacent. */
3260 else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
3261 try_int = false;
3262 /* Is possible if both are registers (or subregs of registers). */
3263 else if (register_operand (x, mode) && register_operand (y, mode))
3264 try_int = true;
3265 /* If one of the operands is a memory, and alignment constraints
3266 are friendly enough, we may be able to do combined memory operations.
3267 We do not attempt this if Y is a constant because that combination is
3268 usually better with the by-parts thing below. */
3269 else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
3270 && (!STRICT_ALIGNMENT
3271 || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
3272 try_int = true;
3273 else
3274 try_int = false;
3276 if (try_int)
3278 rtx ret;
3280 /* For memory to memory moves, optimal behavior can be had with the
3281 existing block move logic. */
3282 if (MEM_P (x) && MEM_P (y))
3284 emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
3285 BLOCK_OP_NO_LIBCALL);
3286 return get_last_insn ();
3289 ret = emit_move_via_integer (mode, x, y, true);
3290 if (ret)
3291 return ret;
3294 return emit_move_complex_parts (x, y);
3297 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3298 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3300 static rtx
3301 emit_move_ccmode (enum machine_mode mode, rtx x, rtx y)
3303 rtx ret;
3305 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3306 if (mode != CCmode)
3308 enum insn_code code = optab_handler (mov_optab, CCmode);
3309 if (code != CODE_FOR_nothing)
3311 x = emit_move_change_mode (CCmode, mode, x, true);
3312 y = emit_move_change_mode (CCmode, mode, y, true);
3313 return emit_insn (GEN_FCN (code) (x, y));
3317 /* Otherwise, find the MODE_INT mode of the same width. */
3318 ret = emit_move_via_integer (mode, x, y, false);
3319 gcc_assert (ret != NULL);
3320 return ret;
3323 /* Return true if word I of OP lies entirely in the
3324 undefined bits of a paradoxical subreg. */
3326 static bool
3327 undefined_operand_subword_p (const_rtx op, int i)
3329 enum machine_mode innermode, innermostmode;
3330 int offset;
3331 if (GET_CODE (op) != SUBREG)
3332 return false;
3333 innermode = GET_MODE (op);
3334 innermostmode = GET_MODE (SUBREG_REG (op));
3335 offset = i * UNITS_PER_WORD + SUBREG_BYTE (op);
3336 /* The SUBREG_BYTE represents offset, as if the value were stored in
3337 memory, except for a paradoxical subreg where we define
3338 SUBREG_BYTE to be 0; undo this exception as in
3339 simplify_subreg. */
3340 if (SUBREG_BYTE (op) == 0
3341 && GET_MODE_SIZE (innermostmode) < GET_MODE_SIZE (innermode))
3343 int difference = (GET_MODE_SIZE (innermostmode) - GET_MODE_SIZE (innermode));
3344 if (WORDS_BIG_ENDIAN)
3345 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
3346 if (BYTES_BIG_ENDIAN)
3347 offset += difference % UNITS_PER_WORD;
3349 if (offset >= GET_MODE_SIZE (innermostmode)
3350 || offset <= -GET_MODE_SIZE (word_mode))
3351 return true;
3352 return false;
3355 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3356 MODE is any multi-word or full-word mode that lacks a move_insn
3357 pattern. Note that you will get better code if you define such
3358 patterns, even if they must turn into multiple assembler instructions. */
3360 static rtx
3361 emit_move_multi_word (enum machine_mode mode, rtx x, rtx y)
3363 rtx last_insn = 0;
3364 rtx seq, inner;
3365 bool need_clobber;
3366 int i;
3368 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
3370 /* If X is a push on the stack, do the push now and replace
3371 X with a reference to the stack pointer. */
3372 if (push_operand (x, mode))
3373 x = emit_move_resolve_push (mode, x);
3375 /* If we are in reload, see if either operand is a MEM whose address
3376 is scheduled for replacement. */
3377 if (reload_in_progress && MEM_P (x)
3378 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3379 x = replace_equiv_address_nv (x, inner);
3380 if (reload_in_progress && MEM_P (y)
3381 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3382 y = replace_equiv_address_nv (y, inner);
3384 start_sequence ();
3386 need_clobber = false;
3387 for (i = 0;
3388 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3389 i++)
3391 rtx xpart = operand_subword (x, i, 1, mode);
3392 rtx ypart;
3394 /* Do not generate code for a move if it would come entirely
3395 from the undefined bits of a paradoxical subreg. */
3396 if (undefined_operand_subword_p (y, i))
3397 continue;
3399 ypart = operand_subword (y, i, 1, mode);
3401 /* If we can't get a part of Y, put Y into memory if it is a
3402 constant. Otherwise, force it into a register. Then we must
3403 be able to get a part of Y. */
3404 if (ypart == 0 && CONSTANT_P (y))
3406 y = use_anchored_address (force_const_mem (mode, y));
3407 ypart = operand_subword (y, i, 1, mode);
3409 else if (ypart == 0)
3410 ypart = operand_subword_force (y, i, mode);
3412 gcc_assert (xpart && ypart);
3414 need_clobber |= (GET_CODE (xpart) == SUBREG);
3416 last_insn = emit_move_insn (xpart, ypart);
3419 seq = get_insns ();
3420 end_sequence ();
3422 /* Show the output dies here. This is necessary for SUBREGs
3423 of pseudos since we cannot track their lifetimes correctly;
3424 hard regs shouldn't appear here except as return values.
3425 We never want to emit such a clobber after reload. */
3426 if (x != y
3427 && ! (reload_in_progress || reload_completed)
3428 && need_clobber != 0)
3429 emit_clobber (x);
3431 emit_insn (seq);
3433 return last_insn;
3436 /* Low level part of emit_move_insn.
3437 Called just like emit_move_insn, but assumes X and Y
3438 are basically valid. */
3441 emit_move_insn_1 (rtx x, rtx y)
3443 enum machine_mode mode = GET_MODE (x);
3444 enum insn_code code;
3446 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
3448 code = optab_handler (mov_optab, mode);
3449 if (code != CODE_FOR_nothing)
3450 return emit_insn (GEN_FCN (code) (x, y));
3452 /* Expand complex moves by moving real part and imag part. */
3453 if (COMPLEX_MODE_P (mode))
3454 return emit_move_complex (mode, x, y);
3456 if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
3457 || ALL_FIXED_POINT_MODE_P (mode))
3459 rtx result = emit_move_via_integer (mode, x, y, true);
3461 /* If we can't find an integer mode, use multi words. */
3462 if (result)
3463 return result;
3464 else
3465 return emit_move_multi_word (mode, x, y);
3468 if (GET_MODE_CLASS (mode) == MODE_CC)
3469 return emit_move_ccmode (mode, x, y);
3471 /* Try using a move pattern for the corresponding integer mode. This is
3472 only safe when simplify_subreg can convert MODE constants into integer
3473 constants. At present, it can only do this reliably if the value
3474 fits within a HOST_WIDE_INT. */
3475 if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3477 rtx ret = emit_move_via_integer (mode, x, y, lra_in_progress);
3479 if (ret)
3481 if (! lra_in_progress || recog (PATTERN (ret), ret, 0) >= 0)
3482 return ret;
3486 return emit_move_multi_word (mode, x, y);
3489 /* Generate code to copy Y into X.
3490 Both Y and X must have the same mode, except that
3491 Y can be a constant with VOIDmode.
3492 This mode cannot be BLKmode; use emit_block_move for that.
3494 Return the last instruction emitted. */
3497 emit_move_insn (rtx x, rtx y)
3499 enum machine_mode mode = GET_MODE (x);
3500 rtx y_cst = NULL_RTX;
3501 rtx last_insn, set;
3503 gcc_assert (mode != BLKmode
3504 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
3506 if (CONSTANT_P (y))
3508 if (optimize
3509 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3510 && (last_insn = compress_float_constant (x, y)))
3511 return last_insn;
3513 y_cst = y;
3515 if (!targetm.legitimate_constant_p (mode, y))
3517 y = force_const_mem (mode, y);
3519 /* If the target's cannot_force_const_mem prevented the spill,
3520 assume that the target's move expanders will also take care
3521 of the non-legitimate constant. */
3522 if (!y)
3523 y = y_cst;
3524 else
3525 y = use_anchored_address (y);
3529 /* If X or Y are memory references, verify that their addresses are valid
3530 for the machine. */
3531 if (MEM_P (x)
3532 && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
3533 MEM_ADDR_SPACE (x))
3534 && ! push_operand (x, GET_MODE (x))))
3535 x = validize_mem (x);
3537 if (MEM_P (y)
3538 && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
3539 MEM_ADDR_SPACE (y)))
3540 y = validize_mem (y);
3542 gcc_assert (mode != BLKmode);
3544 last_insn = emit_move_insn_1 (x, y);
3546 if (y_cst && REG_P (x)
3547 && (set = single_set (last_insn)) != NULL_RTX
3548 && SET_DEST (set) == x
3549 && ! rtx_equal_p (y_cst, SET_SRC (set)))
3550 set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
3552 return last_insn;
3555 /* If Y is representable exactly in a narrower mode, and the target can
3556 perform the extension directly from constant or memory, then emit the
3557 move as an extension. */
3559 static rtx
3560 compress_float_constant (rtx x, rtx y)
3562 enum machine_mode dstmode = GET_MODE (x);
3563 enum machine_mode orig_srcmode = GET_MODE (y);
3564 enum machine_mode srcmode;
3565 REAL_VALUE_TYPE r;
3566 int oldcost, newcost;
3567 bool speed = optimize_insn_for_speed_p ();
3569 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3571 if (targetm.legitimate_constant_p (dstmode, y))
3572 oldcost = set_src_cost (y, speed);
3573 else
3574 oldcost = set_src_cost (force_const_mem (dstmode, y), speed);
3576 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3577 srcmode != orig_srcmode;
3578 srcmode = GET_MODE_WIDER_MODE (srcmode))
3580 enum insn_code ic;
3581 rtx trunc_y, last_insn;
3583 /* Skip if the target can't extend this way. */
3584 ic = can_extend_p (dstmode, srcmode, 0);
3585 if (ic == CODE_FOR_nothing)
3586 continue;
3588 /* Skip if the narrowed value isn't exact. */
3589 if (! exact_real_truncate (srcmode, &r))
3590 continue;
3592 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3594 if (targetm.legitimate_constant_p (srcmode, trunc_y))
3596 /* Skip if the target needs extra instructions to perform
3597 the extension. */
3598 if (!insn_operand_matches (ic, 1, trunc_y))
3599 continue;
3600 /* This is valid, but may not be cheaper than the original. */
3601 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3602 speed);
3603 if (oldcost < newcost)
3604 continue;
3606 else if (float_extend_from_mem[dstmode][srcmode])
3608 trunc_y = force_const_mem (srcmode, trunc_y);
3609 /* This is valid, but may not be cheaper than the original. */
3610 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3611 speed);
3612 if (oldcost < newcost)
3613 continue;
3614 trunc_y = validize_mem (trunc_y);
3616 else
3617 continue;
3619 /* For CSE's benefit, force the compressed constant pool entry
3620 into a new pseudo. This constant may be used in different modes,
3621 and if not, combine will put things back together for us. */
3622 trunc_y = force_reg (srcmode, trunc_y);
3623 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3624 last_insn = get_last_insn ();
3626 if (REG_P (x))
3627 set_unique_reg_note (last_insn, REG_EQUAL, y);
3629 return last_insn;
3632 return NULL_RTX;
3635 /* Pushing data onto the stack. */
3637 /* Push a block of length SIZE (perhaps variable)
3638 and return an rtx to address the beginning of the block.
3639 The value may be virtual_outgoing_args_rtx.
3641 EXTRA is the number of bytes of padding to push in addition to SIZE.
3642 BELOW nonzero means this padding comes at low addresses;
3643 otherwise, the padding comes at high addresses. */
3646 push_block (rtx size, int extra, int below)
3648 rtx temp;
3650 size = convert_modes (Pmode, ptr_mode, size, 1);
3651 if (CONSTANT_P (size))
3652 anti_adjust_stack (plus_constant (Pmode, size, extra));
3653 else if (REG_P (size) && extra == 0)
3654 anti_adjust_stack (size);
3655 else
3657 temp = copy_to_mode_reg (Pmode, size);
3658 if (extra != 0)
3659 temp = expand_binop (Pmode, add_optab, temp,
3660 gen_int_mode (extra, Pmode),
3661 temp, 0, OPTAB_LIB_WIDEN);
3662 anti_adjust_stack (temp);
3665 #ifndef STACK_GROWS_DOWNWARD
3666 if (0)
3667 #else
3668 if (1)
3669 #endif
3671 temp = virtual_outgoing_args_rtx;
3672 if (extra != 0 && below)
3673 temp = plus_constant (Pmode, temp, extra);
3675 else
3677 if (CONST_INT_P (size))
3678 temp = plus_constant (Pmode, virtual_outgoing_args_rtx,
3679 -INTVAL (size) - (below ? 0 : extra));
3680 else if (extra != 0 && !below)
3681 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3682 negate_rtx (Pmode, plus_constant (Pmode, size,
3683 extra)));
3684 else
3685 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3686 negate_rtx (Pmode, size));
3689 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3692 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3694 static rtx
3695 mem_autoinc_base (rtx mem)
3697 if (MEM_P (mem))
3699 rtx addr = XEXP (mem, 0);
3700 if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
3701 return XEXP (addr, 0);
3703 return NULL;
3706 /* A utility routine used here, in reload, and in try_split. The insns
3707 after PREV up to and including LAST are known to adjust the stack,
3708 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3709 placing notes as appropriate. PREV may be NULL, indicating the
3710 entire insn sequence prior to LAST should be scanned.
3712 The set of allowed stack pointer modifications is small:
3713 (1) One or more auto-inc style memory references (aka pushes),
3714 (2) One or more addition/subtraction with the SP as destination,
3715 (3) A single move insn with the SP as destination,
3716 (4) A call_pop insn,
3717 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3719 Insns in the sequence that do not modify the SP are ignored,
3720 except for noreturn calls.
3722 The return value is the amount of adjustment that can be trivially
3723 verified, via immediate operand or auto-inc. If the adjustment
3724 cannot be trivially extracted, the return value is INT_MIN. */
3726 HOST_WIDE_INT
3727 find_args_size_adjust (rtx insn)
3729 rtx dest, set, pat;
3730 int i;
3732 pat = PATTERN (insn);
3733 set = NULL;
3735 /* Look for a call_pop pattern. */
3736 if (CALL_P (insn))
3738 /* We have to allow non-call_pop patterns for the case
3739 of emit_single_push_insn of a TLS address. */
3740 if (GET_CODE (pat) != PARALLEL)
3741 return 0;
3743 /* All call_pop have a stack pointer adjust in the parallel.
3744 The call itself is always first, and the stack adjust is
3745 usually last, so search from the end. */
3746 for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
3748 set = XVECEXP (pat, 0, i);
3749 if (GET_CODE (set) != SET)
3750 continue;
3751 dest = SET_DEST (set);
3752 if (dest == stack_pointer_rtx)
3753 break;
3755 /* We'd better have found the stack pointer adjust. */
3756 if (i == 0)
3757 return 0;
3758 /* Fall through to process the extracted SET and DEST
3759 as if it was a standalone insn. */
3761 else if (GET_CODE (pat) == SET)
3762 set = pat;
3763 else if ((set = single_set (insn)) != NULL)
3765 else if (GET_CODE (pat) == PARALLEL)
3767 /* ??? Some older ports use a parallel with a stack adjust
3768 and a store for a PUSH_ROUNDING pattern, rather than a
3769 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3770 /* ??? See h8300 and m68k, pushqi1. */
3771 for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
3773 set = XVECEXP (pat, 0, i);
3774 if (GET_CODE (set) != SET)
3775 continue;
3776 dest = SET_DEST (set);
3777 if (dest == stack_pointer_rtx)
3778 break;
3780 /* We do not expect an auto-inc of the sp in the parallel. */
3781 gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
3782 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3783 != stack_pointer_rtx);
3785 if (i < 0)
3786 return 0;
3788 else
3789 return 0;
3791 dest = SET_DEST (set);
3793 /* Look for direct modifications of the stack pointer. */
3794 if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
3796 /* Look for a trivial adjustment, otherwise assume nothing. */
3797 /* Note that the SPU restore_stack_block pattern refers to
3798 the stack pointer in V4SImode. Consider that non-trivial. */
3799 if (SCALAR_INT_MODE_P (GET_MODE (dest))
3800 && GET_CODE (SET_SRC (set)) == PLUS
3801 && XEXP (SET_SRC (set), 0) == stack_pointer_rtx
3802 && CONST_INT_P (XEXP (SET_SRC (set), 1)))
3803 return INTVAL (XEXP (SET_SRC (set), 1));
3804 /* ??? Reload can generate no-op moves, which will be cleaned
3805 up later. Recognize it and continue searching. */
3806 else if (rtx_equal_p (dest, SET_SRC (set)))
3807 return 0;
3808 else
3809 return HOST_WIDE_INT_MIN;
3811 else
3813 rtx mem, addr;
3815 /* Otherwise only think about autoinc patterns. */
3816 if (mem_autoinc_base (dest) == stack_pointer_rtx)
3818 mem = dest;
3819 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3820 != stack_pointer_rtx);
3822 else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
3823 mem = SET_SRC (set);
3824 else
3825 return 0;
3827 addr = XEXP (mem, 0);
3828 switch (GET_CODE (addr))
3830 case PRE_INC:
3831 case POST_INC:
3832 return GET_MODE_SIZE (GET_MODE (mem));
3833 case PRE_DEC:
3834 case POST_DEC:
3835 return -GET_MODE_SIZE (GET_MODE (mem));
3836 case PRE_MODIFY:
3837 case POST_MODIFY:
3838 addr = XEXP (addr, 1);
3839 gcc_assert (GET_CODE (addr) == PLUS);
3840 gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
3841 gcc_assert (CONST_INT_P (XEXP (addr, 1)));
3842 return INTVAL (XEXP (addr, 1));
3843 default:
3844 gcc_unreachable ();
3850 fixup_args_size_notes (rtx prev, rtx last, int end_args_size)
3852 int args_size = end_args_size;
3853 bool saw_unknown = false;
3854 rtx insn;
3856 for (insn = last; insn != prev; insn = PREV_INSN (insn))
3858 HOST_WIDE_INT this_delta;
3860 if (!NONDEBUG_INSN_P (insn))
3861 continue;
3863 this_delta = find_args_size_adjust (insn);
3864 if (this_delta == 0)
3866 if (!CALL_P (insn)
3867 || ACCUMULATE_OUTGOING_ARGS
3868 || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
3869 continue;
3872 gcc_assert (!saw_unknown);
3873 if (this_delta == HOST_WIDE_INT_MIN)
3874 saw_unknown = true;
3876 add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (args_size));
3877 #ifdef STACK_GROWS_DOWNWARD
3878 this_delta = -(unsigned HOST_WIDE_INT) this_delta;
3879 #endif
3880 args_size -= this_delta;
3883 return saw_unknown ? INT_MIN : args_size;
3886 #ifdef PUSH_ROUNDING
3887 /* Emit single push insn. */
3889 static void
3890 emit_single_push_insn_1 (enum machine_mode mode, rtx x, tree type)
3892 rtx dest_addr;
3893 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3894 rtx dest;
3895 enum insn_code icode;
3897 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3898 /* If there is push pattern, use it. Otherwise try old way of throwing
3899 MEM representing push operation to move expander. */
3900 icode = optab_handler (push_optab, mode);
3901 if (icode != CODE_FOR_nothing)
3903 struct expand_operand ops[1];
3905 create_input_operand (&ops[0], x, mode);
3906 if (maybe_expand_insn (icode, 1, ops))
3907 return;
3909 if (GET_MODE_SIZE (mode) == rounded_size)
3910 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3911 /* If we are to pad downward, adjust the stack pointer first and
3912 then store X into the stack location using an offset. This is
3913 because emit_move_insn does not know how to pad; it does not have
3914 access to type. */
3915 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3917 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3918 HOST_WIDE_INT offset;
3920 emit_move_insn (stack_pointer_rtx,
3921 expand_binop (Pmode,
3922 #ifdef STACK_GROWS_DOWNWARD
3923 sub_optab,
3924 #else
3925 add_optab,
3926 #endif
3927 stack_pointer_rtx,
3928 gen_int_mode (rounded_size, Pmode),
3929 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3931 offset = (HOST_WIDE_INT) padding_size;
3932 #ifdef STACK_GROWS_DOWNWARD
3933 if (STACK_PUSH_CODE == POST_DEC)
3934 /* We have already decremented the stack pointer, so get the
3935 previous value. */
3936 offset += (HOST_WIDE_INT) rounded_size;
3937 #else
3938 if (STACK_PUSH_CODE == POST_INC)
3939 /* We have already incremented the stack pointer, so get the
3940 previous value. */
3941 offset -= (HOST_WIDE_INT) rounded_size;
3942 #endif
3943 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3944 gen_int_mode (offset, Pmode));
3946 else
3948 #ifdef STACK_GROWS_DOWNWARD
3949 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3950 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3951 gen_int_mode (-(HOST_WIDE_INT) rounded_size,
3952 Pmode));
3953 #else
3954 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3955 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3956 gen_int_mode (rounded_size, Pmode));
3957 #endif
3958 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3961 dest = gen_rtx_MEM (mode, dest_addr);
3963 if (type != 0)
3965 set_mem_attributes (dest, type, 1);
3967 if (flag_optimize_sibling_calls)
3968 /* Function incoming arguments may overlap with sibling call
3969 outgoing arguments and we cannot allow reordering of reads
3970 from function arguments with stores to outgoing arguments
3971 of sibling calls. */
3972 set_mem_alias_set (dest, 0);
3974 emit_move_insn (dest, x);
3977 /* Emit and annotate a single push insn. */
3979 static void
3980 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
3982 int delta, old_delta = stack_pointer_delta;
3983 rtx prev = get_last_insn ();
3984 rtx last;
3986 emit_single_push_insn_1 (mode, x, type);
3988 last = get_last_insn ();
3990 /* Notice the common case where we emitted exactly one insn. */
3991 if (PREV_INSN (last) == prev)
3993 add_reg_note (last, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
3994 return;
3997 delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
3998 gcc_assert (delta == INT_MIN || delta == old_delta);
4000 #endif
4002 /* Generate code to push X onto the stack, assuming it has mode MODE and
4003 type TYPE.
4004 MODE is redundant except when X is a CONST_INT (since they don't
4005 carry mode info).
4006 SIZE is an rtx for the size of data to be copied (in bytes),
4007 needed only if X is BLKmode.
4009 ALIGN (in bits) is maximum alignment we can assume.
4011 If PARTIAL and REG are both nonzero, then copy that many of the first
4012 bytes of X into registers starting with REG, and push the rest of X.
4013 The amount of space pushed is decreased by PARTIAL bytes.
4014 REG must be a hard register in this case.
4015 If REG is zero but PARTIAL is not, take any all others actions for an
4016 argument partially in registers, but do not actually load any
4017 registers.
4019 EXTRA is the amount in bytes of extra space to leave next to this arg.
4020 This is ignored if an argument block has already been allocated.
4022 On a machine that lacks real push insns, ARGS_ADDR is the address of
4023 the bottom of the argument block for this call. We use indexing off there
4024 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4025 argument block has not been preallocated.
4027 ARGS_SO_FAR is the size of args previously pushed for this call.
4029 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4030 for arguments passed in registers. If nonzero, it will be the number
4031 of bytes required. */
4033 void
4034 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
4035 unsigned int align, int partial, rtx reg, int extra,
4036 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
4037 rtx alignment_pad)
4039 rtx xinner;
4040 enum direction stack_direction
4041 #ifdef STACK_GROWS_DOWNWARD
4042 = downward;
4043 #else
4044 = upward;
4045 #endif
4047 /* Decide where to pad the argument: `downward' for below,
4048 `upward' for above, or `none' for don't pad it.
4049 Default is below for small data on big-endian machines; else above. */
4050 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
4052 /* Invert direction if stack is post-decrement.
4053 FIXME: why? */
4054 if (STACK_PUSH_CODE == POST_DEC)
4055 if (where_pad != none)
4056 where_pad = (where_pad == downward ? upward : downward);
4058 xinner = x;
4060 if (mode == BLKmode
4061 || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
4063 /* Copy a block into the stack, entirely or partially. */
4065 rtx temp;
4066 int used;
4067 int offset;
4068 int skip;
4070 offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4071 used = partial - offset;
4073 if (mode != BLKmode)
4075 /* A value is to be stored in an insufficiently aligned
4076 stack slot; copy via a suitably aligned slot if
4077 necessary. */
4078 size = GEN_INT (GET_MODE_SIZE (mode));
4079 if (!MEM_P (xinner))
4081 temp = assign_temp (type, 1, 1);
4082 emit_move_insn (temp, xinner);
4083 xinner = temp;
4087 gcc_assert (size);
4089 /* USED is now the # of bytes we need not copy to the stack
4090 because registers will take care of them. */
4092 if (partial != 0)
4093 xinner = adjust_address (xinner, BLKmode, used);
4095 /* If the partial register-part of the arg counts in its stack size,
4096 skip the part of stack space corresponding to the registers.
4097 Otherwise, start copying to the beginning of the stack space,
4098 by setting SKIP to 0. */
4099 skip = (reg_parm_stack_space == 0) ? 0 : used;
4101 #ifdef PUSH_ROUNDING
4102 /* Do it with several push insns if that doesn't take lots of insns
4103 and if there is no difficulty with push insns that skip bytes
4104 on the stack for alignment purposes. */
4105 if (args_addr == 0
4106 && PUSH_ARGS
4107 && CONST_INT_P (size)
4108 && skip == 0
4109 && MEM_ALIGN (xinner) >= align
4110 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
4111 /* Here we avoid the case of a structure whose weak alignment
4112 forces many pushes of a small amount of data,
4113 and such small pushes do rounding that causes trouble. */
4114 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
4115 || align >= BIGGEST_ALIGNMENT
4116 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
4117 == (align / BITS_PER_UNIT)))
4118 && (HOST_WIDE_INT) PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
4120 /* Push padding now if padding above and stack grows down,
4121 or if padding below and stack grows up.
4122 But if space already allocated, this has already been done. */
4123 if (extra && args_addr == 0
4124 && where_pad != none && where_pad != stack_direction)
4125 anti_adjust_stack (GEN_INT (extra));
4127 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
4129 else
4130 #endif /* PUSH_ROUNDING */
4132 rtx target;
4134 /* Otherwise make space on the stack and copy the data
4135 to the address of that space. */
4137 /* Deduct words put into registers from the size we must copy. */
4138 if (partial != 0)
4140 if (CONST_INT_P (size))
4141 size = GEN_INT (INTVAL (size) - used);
4142 else
4143 size = expand_binop (GET_MODE (size), sub_optab, size,
4144 gen_int_mode (used, GET_MODE (size)),
4145 NULL_RTX, 0, OPTAB_LIB_WIDEN);
4148 /* Get the address of the stack space.
4149 In this case, we do not deal with EXTRA separately.
4150 A single stack adjust will do. */
4151 if (! args_addr)
4153 temp = push_block (size, extra, where_pad == downward);
4154 extra = 0;
4156 else if (CONST_INT_P (args_so_far))
4157 temp = memory_address (BLKmode,
4158 plus_constant (Pmode, args_addr,
4159 skip + INTVAL (args_so_far)));
4160 else
4161 temp = memory_address (BLKmode,
4162 plus_constant (Pmode,
4163 gen_rtx_PLUS (Pmode,
4164 args_addr,
4165 args_so_far),
4166 skip));
4168 if (!ACCUMULATE_OUTGOING_ARGS)
4170 /* If the source is referenced relative to the stack pointer,
4171 copy it to another register to stabilize it. We do not need
4172 to do this if we know that we won't be changing sp. */
4174 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
4175 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
4176 temp = copy_to_reg (temp);
4179 target = gen_rtx_MEM (BLKmode, temp);
4181 /* We do *not* set_mem_attributes here, because incoming arguments
4182 may overlap with sibling call outgoing arguments and we cannot
4183 allow reordering of reads from function arguments with stores
4184 to outgoing arguments of sibling calls. We do, however, want
4185 to record the alignment of the stack slot. */
4186 /* ALIGN may well be better aligned than TYPE, e.g. due to
4187 PARM_BOUNDARY. Assume the caller isn't lying. */
4188 set_mem_align (target, align);
4190 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
4193 else if (partial > 0)
4195 /* Scalar partly in registers. */
4197 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
4198 int i;
4199 int not_stack;
4200 /* # bytes of start of argument
4201 that we must make space for but need not store. */
4202 int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4203 int args_offset = INTVAL (args_so_far);
4204 int skip;
4206 /* Push padding now if padding above and stack grows down,
4207 or if padding below and stack grows up.
4208 But if space already allocated, this has already been done. */
4209 if (extra && args_addr == 0
4210 && where_pad != none && where_pad != stack_direction)
4211 anti_adjust_stack (GEN_INT (extra));
4213 /* If we make space by pushing it, we might as well push
4214 the real data. Otherwise, we can leave OFFSET nonzero
4215 and leave the space uninitialized. */
4216 if (args_addr == 0)
4217 offset = 0;
4219 /* Now NOT_STACK gets the number of words that we don't need to
4220 allocate on the stack. Convert OFFSET to words too. */
4221 not_stack = (partial - offset) / UNITS_PER_WORD;
4222 offset /= UNITS_PER_WORD;
4224 /* If the partial register-part of the arg counts in its stack size,
4225 skip the part of stack space corresponding to the registers.
4226 Otherwise, start copying to the beginning of the stack space,
4227 by setting SKIP to 0. */
4228 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
4230 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
4231 x = validize_mem (force_const_mem (mode, x));
4233 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4234 SUBREGs of such registers are not allowed. */
4235 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
4236 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
4237 x = copy_to_reg (x);
4239 /* Loop over all the words allocated on the stack for this arg. */
4240 /* We can do it by words, because any scalar bigger than a word
4241 has a size a multiple of a word. */
4242 #ifndef PUSH_ARGS_REVERSED
4243 for (i = not_stack; i < size; i++)
4244 #else
4245 for (i = size - 1; i >= not_stack; i--)
4246 #endif
4247 if (i >= not_stack + offset)
4248 emit_push_insn (operand_subword_force (x, i, mode),
4249 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
4250 0, args_addr,
4251 GEN_INT (args_offset + ((i - not_stack + skip)
4252 * UNITS_PER_WORD)),
4253 reg_parm_stack_space, alignment_pad);
4255 else
4257 rtx addr;
4258 rtx dest;
4260 /* Push padding now if padding above and stack grows down,
4261 or if padding below and stack grows up.
4262 But if space already allocated, this has already been done. */
4263 if (extra && args_addr == 0
4264 && where_pad != none && where_pad != stack_direction)
4265 anti_adjust_stack (GEN_INT (extra));
4267 #ifdef PUSH_ROUNDING
4268 if (args_addr == 0 && PUSH_ARGS)
4269 emit_single_push_insn (mode, x, type);
4270 else
4271 #endif
4273 if (CONST_INT_P (args_so_far))
4274 addr
4275 = memory_address (mode,
4276 plus_constant (Pmode, args_addr,
4277 INTVAL (args_so_far)));
4278 else
4279 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
4280 args_so_far));
4281 dest = gen_rtx_MEM (mode, addr);
4283 /* We do *not* set_mem_attributes here, because incoming arguments
4284 may overlap with sibling call outgoing arguments and we cannot
4285 allow reordering of reads from function arguments with stores
4286 to outgoing arguments of sibling calls. We do, however, want
4287 to record the alignment of the stack slot. */
4288 /* ALIGN may well be better aligned than TYPE, e.g. due to
4289 PARM_BOUNDARY. Assume the caller isn't lying. */
4290 set_mem_align (dest, align);
4292 emit_move_insn (dest, x);
4296 /* If part should go in registers, copy that part
4297 into the appropriate registers. Do this now, at the end,
4298 since mem-to-mem copies above may do function calls. */
4299 if (partial > 0 && reg != 0)
4301 /* Handle calls that pass values in multiple non-contiguous locations.
4302 The Irix 6 ABI has examples of this. */
4303 if (GET_CODE (reg) == PARALLEL)
4304 emit_group_load (reg, x, type, -1);
4305 else
4307 gcc_assert (partial % UNITS_PER_WORD == 0);
4308 move_block_to_reg (REGNO (reg), x, partial / UNITS_PER_WORD, mode);
4312 if (extra && args_addr == 0 && where_pad == stack_direction)
4313 anti_adjust_stack (GEN_INT (extra));
4315 if (alignment_pad && args_addr == 0)
4316 anti_adjust_stack (alignment_pad);
4319 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4320 operations. */
4322 static rtx
4323 get_subtarget (rtx x)
4325 return (optimize
4326 || x == 0
4327 /* Only registers can be subtargets. */
4328 || !REG_P (x)
4329 /* Don't use hard regs to avoid extending their life. */
4330 || REGNO (x) < FIRST_PSEUDO_REGISTER
4331 ? 0 : x);
4334 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4335 FIELD is a bitfield. Returns true if the optimization was successful,
4336 and there's nothing else to do. */
4338 static bool
4339 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize,
4340 unsigned HOST_WIDE_INT bitpos,
4341 unsigned HOST_WIDE_INT bitregion_start,
4342 unsigned HOST_WIDE_INT bitregion_end,
4343 enum machine_mode mode1, rtx str_rtx,
4344 tree to, tree src)
4346 enum machine_mode str_mode = GET_MODE (str_rtx);
4347 unsigned int str_bitsize = GET_MODE_BITSIZE (str_mode);
4348 tree op0, op1;
4349 rtx value, result;
4350 optab binop;
4351 gimple srcstmt;
4352 enum tree_code code;
4354 if (mode1 != VOIDmode
4355 || bitsize >= BITS_PER_WORD
4356 || str_bitsize > BITS_PER_WORD
4357 || TREE_SIDE_EFFECTS (to)
4358 || TREE_THIS_VOLATILE (to))
4359 return false;
4361 STRIP_NOPS (src);
4362 if (TREE_CODE (src) != SSA_NAME)
4363 return false;
4364 if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
4365 return false;
4367 srcstmt = get_gimple_for_ssa_name (src);
4368 if (!srcstmt
4369 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
4370 return false;
4372 code = gimple_assign_rhs_code (srcstmt);
4374 op0 = gimple_assign_rhs1 (srcstmt);
4376 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4377 to find its initialization. Hopefully the initialization will
4378 be from a bitfield load. */
4379 if (TREE_CODE (op0) == SSA_NAME)
4381 gimple op0stmt = get_gimple_for_ssa_name (op0);
4383 /* We want to eventually have OP0 be the same as TO, which
4384 should be a bitfield. */
4385 if (!op0stmt
4386 || !is_gimple_assign (op0stmt)
4387 || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
4388 return false;
4389 op0 = gimple_assign_rhs1 (op0stmt);
4392 op1 = gimple_assign_rhs2 (srcstmt);
4394 if (!operand_equal_p (to, op0, 0))
4395 return false;
4397 if (MEM_P (str_rtx))
4399 unsigned HOST_WIDE_INT offset1;
4401 if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
4402 str_mode = word_mode;
4403 str_mode = get_best_mode (bitsize, bitpos,
4404 bitregion_start, bitregion_end,
4405 MEM_ALIGN (str_rtx), str_mode, 0);
4406 if (str_mode == VOIDmode)
4407 return false;
4408 str_bitsize = GET_MODE_BITSIZE (str_mode);
4410 offset1 = bitpos;
4411 bitpos %= str_bitsize;
4412 offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
4413 str_rtx = adjust_address (str_rtx, str_mode, offset1);
4415 else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
4416 return false;
4418 /* If the bit field covers the whole REG/MEM, store_field
4419 will likely generate better code. */
4420 if (bitsize >= str_bitsize)
4421 return false;
4423 /* We can't handle fields split across multiple entities. */
4424 if (bitpos + bitsize > str_bitsize)
4425 return false;
4427 if (BYTES_BIG_ENDIAN)
4428 bitpos = str_bitsize - bitpos - bitsize;
4430 switch (code)
4432 case PLUS_EXPR:
4433 case MINUS_EXPR:
4434 /* For now, just optimize the case of the topmost bitfield
4435 where we don't need to do any masking and also
4436 1 bit bitfields where xor can be used.
4437 We might win by one instruction for the other bitfields
4438 too if insv/extv instructions aren't used, so that
4439 can be added later. */
4440 if (bitpos + bitsize != str_bitsize
4441 && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
4442 break;
4444 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4445 value = convert_modes (str_mode,
4446 TYPE_MODE (TREE_TYPE (op1)), value,
4447 TYPE_UNSIGNED (TREE_TYPE (op1)));
4449 /* We may be accessing data outside the field, which means
4450 we can alias adjacent data. */
4451 if (MEM_P (str_rtx))
4453 str_rtx = shallow_copy_rtx (str_rtx);
4454 set_mem_alias_set (str_rtx, 0);
4455 set_mem_expr (str_rtx, 0);
4458 binop = code == PLUS_EXPR ? add_optab : sub_optab;
4459 if (bitsize == 1 && bitpos + bitsize != str_bitsize)
4461 value = expand_and (str_mode, value, const1_rtx, NULL);
4462 binop = xor_optab;
4464 value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
4465 result = expand_binop (str_mode, binop, str_rtx,
4466 value, str_rtx, 1, OPTAB_WIDEN);
4467 if (result != str_rtx)
4468 emit_move_insn (str_rtx, result);
4469 return true;
4471 case BIT_IOR_EXPR:
4472 case BIT_XOR_EXPR:
4473 if (TREE_CODE (op1) != INTEGER_CST)
4474 break;
4475 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4476 value = convert_modes (str_mode,
4477 TYPE_MODE (TREE_TYPE (op1)), value,
4478 TYPE_UNSIGNED (TREE_TYPE (op1)));
4480 /* We may be accessing data outside the field, which means
4481 we can alias adjacent data. */
4482 if (MEM_P (str_rtx))
4484 str_rtx = shallow_copy_rtx (str_rtx);
4485 set_mem_alias_set (str_rtx, 0);
4486 set_mem_expr (str_rtx, 0);
4489 binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
4490 if (bitpos + bitsize != str_bitsize)
4492 rtx mask = gen_int_mode (((unsigned HOST_WIDE_INT) 1 << bitsize) - 1,
4493 str_mode);
4494 value = expand_and (str_mode, value, mask, NULL_RTX);
4496 value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
4497 result = expand_binop (str_mode, binop, str_rtx,
4498 value, str_rtx, 1, OPTAB_WIDEN);
4499 if (result != str_rtx)
4500 emit_move_insn (str_rtx, result);
4501 return true;
4503 default:
4504 break;
4507 return false;
4510 /* In the C++ memory model, consecutive bit fields in a structure are
4511 considered one memory location.
4513 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4514 returns the bit range of consecutive bits in which this COMPONENT_REF
4515 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4516 and *OFFSET may be adjusted in the process.
4518 If the access does not need to be restricted, 0 is returned in both
4519 *BITSTART and *BITEND. */
4521 static void
4522 get_bit_range (unsigned HOST_WIDE_INT *bitstart,
4523 unsigned HOST_WIDE_INT *bitend,
4524 tree exp,
4525 HOST_WIDE_INT *bitpos,
4526 tree *offset)
4528 HOST_WIDE_INT bitoffset;
4529 tree field, repr;
4531 gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
4533 field = TREE_OPERAND (exp, 1);
4534 repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
4535 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4536 need to limit the range we can access. */
4537 if (!repr)
4539 *bitstart = *bitend = 0;
4540 return;
4543 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4544 part of a larger bit field, then the representative does not serve any
4545 useful purpose. This can occur in Ada. */
4546 if (handled_component_p (TREE_OPERAND (exp, 0)))
4548 enum machine_mode rmode;
4549 HOST_WIDE_INT rbitsize, rbitpos;
4550 tree roffset;
4551 int unsignedp;
4552 int volatilep = 0;
4553 get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
4554 &roffset, &rmode, &unsignedp, &volatilep, false);
4555 if ((rbitpos % BITS_PER_UNIT) != 0)
4557 *bitstart = *bitend = 0;
4558 return;
4562 /* Compute the adjustment to bitpos from the offset of the field
4563 relative to the representative. DECL_FIELD_OFFSET of field and
4564 repr are the same by construction if they are not constants,
4565 see finish_bitfield_layout. */
4566 if (host_integerp (DECL_FIELD_OFFSET (field), 1)
4567 && host_integerp (DECL_FIELD_OFFSET (repr), 1))
4568 bitoffset = (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
4569 - tree_low_cst (DECL_FIELD_OFFSET (repr), 1)) * BITS_PER_UNIT;
4570 else
4571 bitoffset = 0;
4572 bitoffset += (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
4573 - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1));
4575 /* If the adjustment is larger than bitpos, we would have a negative bit
4576 position for the lower bound and this may wreak havoc later. This can
4577 occur only if we have a non-null offset, so adjust offset and bitpos
4578 to make the lower bound non-negative. */
4579 if (bitoffset > *bitpos)
4581 HOST_WIDE_INT adjust = bitoffset - *bitpos;
4583 gcc_assert ((adjust % BITS_PER_UNIT) == 0);
4584 gcc_assert (*offset != NULL_TREE);
4586 *bitpos += adjust;
4587 *offset
4588 = size_binop (MINUS_EXPR, *offset, size_int (adjust / BITS_PER_UNIT));
4589 *bitstart = 0;
4591 else
4592 *bitstart = *bitpos - bitoffset;
4594 *bitend = *bitstart + tree_low_cst (DECL_SIZE (repr), 1) - 1;
4597 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4598 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4599 DECL_RTL was not set yet, return NORTL. */
4601 static inline bool
4602 addr_expr_of_non_mem_decl_p_1 (tree addr, bool nortl)
4604 if (TREE_CODE (addr) != ADDR_EXPR)
4605 return false;
4607 tree base = TREE_OPERAND (addr, 0);
4609 if (!DECL_P (base)
4610 || TREE_ADDRESSABLE (base)
4611 || DECL_MODE (base) == BLKmode)
4612 return false;
4614 if (!DECL_RTL_SET_P (base))
4615 return nortl;
4617 return (!MEM_P (DECL_RTL (base)));
4620 /* Returns true if the MEM_REF REF refers to an object that does not
4621 reside in memory and has non-BLKmode. */
4623 static inline bool
4624 mem_ref_refers_to_non_mem_p (tree ref)
4626 tree base = TREE_OPERAND (ref, 0);
4627 return addr_expr_of_non_mem_decl_p_1 (base, false);
4630 /* Return TRUE iff OP is an ADDR_EXPR of a DECL that's not
4631 addressable. This is very much like mem_ref_refers_to_non_mem_p,
4632 but instead of the MEM_REF, it takes its base, and it doesn't
4633 assume a DECL is in memory just because its RTL is not set yet. */
4635 bool
4636 addr_expr_of_non_mem_decl_p (tree op)
4638 return addr_expr_of_non_mem_decl_p_1 (op, true);
4641 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4642 is true, try generating a nontemporal store. */
4644 void
4645 expand_assignment (tree to, tree from, bool nontemporal)
4647 rtx to_rtx = 0;
4648 rtx result;
4649 enum machine_mode mode;
4650 unsigned int align;
4651 enum insn_code icode;
4653 /* Don't crash if the lhs of the assignment was erroneous. */
4654 if (TREE_CODE (to) == ERROR_MARK)
4656 expand_normal (from);
4657 return;
4660 /* Optimize away no-op moves without side-effects. */
4661 if (operand_equal_p (to, from, 0))
4662 return;
4664 /* Handle misaligned stores. */
4665 mode = TYPE_MODE (TREE_TYPE (to));
4666 if ((TREE_CODE (to) == MEM_REF
4667 || TREE_CODE (to) == TARGET_MEM_REF)
4668 && mode != BLKmode
4669 && !mem_ref_refers_to_non_mem_p (to)
4670 && ((align = get_object_alignment (to))
4671 < GET_MODE_ALIGNMENT (mode))
4672 && (((icode = optab_handler (movmisalign_optab, mode))
4673 != CODE_FOR_nothing)
4674 || SLOW_UNALIGNED_ACCESS (mode, align)))
4676 rtx reg, mem;
4678 reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4679 reg = force_not_mem (reg);
4680 mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4682 if (icode != CODE_FOR_nothing)
4684 struct expand_operand ops[2];
4686 create_fixed_operand (&ops[0], mem);
4687 create_input_operand (&ops[1], reg, mode);
4688 /* The movmisalign<mode> pattern cannot fail, else the assignment
4689 would silently be omitted. */
4690 expand_insn (icode, 2, ops);
4692 else
4693 store_bit_field (mem, GET_MODE_BITSIZE (mode),
4694 0, 0, 0, mode, reg);
4695 return;
4698 /* Assignment of a structure component needs special treatment
4699 if the structure component's rtx is not simply a MEM.
4700 Assignment of an array element at a constant index, and assignment of
4701 an array element in an unaligned packed structure field, has the same
4702 problem. Same for (partially) storing into a non-memory object. */
4703 if (handled_component_p (to)
4704 || (TREE_CODE (to) == MEM_REF
4705 && mem_ref_refers_to_non_mem_p (to))
4706 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
4708 enum machine_mode mode1;
4709 HOST_WIDE_INT bitsize, bitpos;
4710 unsigned HOST_WIDE_INT bitregion_start = 0;
4711 unsigned HOST_WIDE_INT bitregion_end = 0;
4712 tree offset;
4713 int unsignedp;
4714 int volatilep = 0;
4715 tree tem;
4717 push_temp_slots ();
4718 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
4719 &unsignedp, &volatilep, true);
4721 if (TREE_CODE (to) == COMPONENT_REF
4722 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
4723 get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
4725 to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
4727 /* If the bitfield is volatile, we want to access it in the
4728 field's mode, not the computed mode.
4729 If a MEM has VOIDmode (external with incomplete type),
4730 use BLKmode for it instead. */
4731 if (MEM_P (to_rtx))
4733 if (volatilep && flag_strict_volatile_bitfields > 0)
4734 to_rtx = adjust_address (to_rtx, mode1, 0);
4735 else if (GET_MODE (to_rtx) == VOIDmode)
4736 to_rtx = adjust_address (to_rtx, BLKmode, 0);
4739 if (offset != 0)
4741 enum machine_mode address_mode;
4742 rtx offset_rtx;
4744 if (!MEM_P (to_rtx))
4746 /* We can get constant negative offsets into arrays with broken
4747 user code. Translate this to a trap instead of ICEing. */
4748 gcc_assert (TREE_CODE (offset) == INTEGER_CST);
4749 expand_builtin_trap ();
4750 to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
4753 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
4754 address_mode = get_address_mode (to_rtx);
4755 if (GET_MODE (offset_rtx) != address_mode)
4756 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
4758 /* A constant address in TO_RTX can have VOIDmode, we must not try
4759 to call force_reg for that case. Avoid that case. */
4760 if (MEM_P (to_rtx)
4761 && GET_MODE (to_rtx) == BLKmode
4762 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
4763 && bitsize > 0
4764 && (bitpos % bitsize) == 0
4765 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
4766 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
4768 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
4769 bitpos = 0;
4772 to_rtx = offset_address (to_rtx, offset_rtx,
4773 highest_pow2_factor_for_target (to,
4774 offset));
4777 /* No action is needed if the target is not a memory and the field
4778 lies completely outside that target. This can occur if the source
4779 code contains an out-of-bounds access to a small array. */
4780 if (!MEM_P (to_rtx)
4781 && GET_MODE (to_rtx) != BLKmode
4782 && (unsigned HOST_WIDE_INT) bitpos
4783 >= GET_MODE_PRECISION (GET_MODE (to_rtx)))
4785 expand_normal (from);
4786 result = NULL;
4788 /* Handle expand_expr of a complex value returning a CONCAT. */
4789 else if (GET_CODE (to_rtx) == CONCAT)
4791 unsigned short mode_bitsize = GET_MODE_BITSIZE (GET_MODE (to_rtx));
4792 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from)))
4793 && bitpos == 0
4794 && bitsize == mode_bitsize)
4795 result = store_expr (from, to_rtx, false, nontemporal);
4796 else if (bitsize == mode_bitsize / 2
4797 && (bitpos == 0 || bitpos == mode_bitsize / 2))
4798 result = store_expr (from, XEXP (to_rtx, bitpos != 0), false,
4799 nontemporal);
4800 else if (bitpos + bitsize <= mode_bitsize / 2)
4801 result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
4802 bitregion_start, bitregion_end,
4803 mode1, from,
4804 get_alias_set (to), nontemporal);
4805 else if (bitpos >= mode_bitsize / 2)
4806 result = store_field (XEXP (to_rtx, 1), bitsize,
4807 bitpos - mode_bitsize / 2,
4808 bitregion_start, bitregion_end,
4809 mode1, from,
4810 get_alias_set (to), nontemporal);
4811 else if (bitpos == 0 && bitsize == mode_bitsize)
4813 rtx from_rtx;
4814 result = expand_normal (from);
4815 from_rtx = simplify_gen_subreg (GET_MODE (to_rtx), result,
4816 TYPE_MODE (TREE_TYPE (from)), 0);
4817 emit_move_insn (XEXP (to_rtx, 0),
4818 read_complex_part (from_rtx, false));
4819 emit_move_insn (XEXP (to_rtx, 1),
4820 read_complex_part (from_rtx, true));
4822 else
4824 rtx temp = assign_stack_temp (GET_MODE (to_rtx),
4825 GET_MODE_SIZE (GET_MODE (to_rtx)));
4826 write_complex_part (temp, XEXP (to_rtx, 0), false);
4827 write_complex_part (temp, XEXP (to_rtx, 1), true);
4828 result = store_field (temp, bitsize, bitpos,
4829 bitregion_start, bitregion_end,
4830 mode1, from,
4831 get_alias_set (to), nontemporal);
4832 emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
4833 emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
4836 else
4838 if (MEM_P (to_rtx))
4840 /* If the field is at offset zero, we could have been given the
4841 DECL_RTX of the parent struct. Don't munge it. */
4842 to_rtx = shallow_copy_rtx (to_rtx);
4843 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
4844 if (volatilep)
4845 MEM_VOLATILE_P (to_rtx) = 1;
4848 if (optimize_bitfield_assignment_op (bitsize, bitpos,
4849 bitregion_start, bitregion_end,
4850 mode1,
4851 to_rtx, to, from))
4852 result = NULL;
4853 else
4854 result = store_field (to_rtx, bitsize, bitpos,
4855 bitregion_start, bitregion_end,
4856 mode1, from,
4857 get_alias_set (to), nontemporal);
4860 if (result)
4861 preserve_temp_slots (result);
4862 pop_temp_slots ();
4863 return;
4866 /* If the rhs is a function call and its value is not an aggregate,
4867 call the function before we start to compute the lhs.
4868 This is needed for correct code for cases such as
4869 val = setjmp (buf) on machines where reference to val
4870 requires loading up part of an address in a separate insn.
4872 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4873 since it might be a promoted variable where the zero- or sign- extension
4874 needs to be done. Handling this in the normal way is safe because no
4875 computation is done before the call. The same is true for SSA names. */
4876 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
4877 && COMPLETE_TYPE_P (TREE_TYPE (from))
4878 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
4879 && ! (((TREE_CODE (to) == VAR_DECL
4880 || TREE_CODE (to) == PARM_DECL
4881 || TREE_CODE (to) == RESULT_DECL)
4882 && REG_P (DECL_RTL (to)))
4883 || TREE_CODE (to) == SSA_NAME))
4885 rtx value;
4887 push_temp_slots ();
4888 value = expand_normal (from);
4889 if (to_rtx == 0)
4890 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4892 /* Handle calls that return values in multiple non-contiguous locations.
4893 The Irix 6 ABI has examples of this. */
4894 if (GET_CODE (to_rtx) == PARALLEL)
4896 if (GET_CODE (value) == PARALLEL)
4897 emit_group_move (to_rtx, value);
4898 else
4899 emit_group_load (to_rtx, value, TREE_TYPE (from),
4900 int_size_in_bytes (TREE_TYPE (from)));
4902 else if (GET_CODE (value) == PARALLEL)
4903 emit_group_store (to_rtx, value, TREE_TYPE (from),
4904 int_size_in_bytes (TREE_TYPE (from)));
4905 else if (GET_MODE (to_rtx) == BLKmode)
4907 /* Handle calls that return BLKmode values in registers. */
4908 if (REG_P (value))
4909 copy_blkmode_from_reg (to_rtx, value, TREE_TYPE (from));
4910 else
4911 emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
4913 else
4915 if (POINTER_TYPE_P (TREE_TYPE (to)))
4916 value = convert_memory_address_addr_space
4917 (GET_MODE (to_rtx), value,
4918 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
4920 emit_move_insn (to_rtx, value);
4922 preserve_temp_slots (to_rtx);
4923 pop_temp_slots ();
4924 return;
4927 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4928 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4930 /* Don't move directly into a return register. */
4931 if (TREE_CODE (to) == RESULT_DECL
4932 && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
4934 rtx temp;
4936 push_temp_slots ();
4938 /* If the source is itself a return value, it still is in a pseudo at
4939 this point so we can move it back to the return register directly. */
4940 if (REG_P (to_rtx)
4941 && TYPE_MODE (TREE_TYPE (from)) == BLKmode
4942 && TREE_CODE (from) != CALL_EXPR)
4943 temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
4944 else
4945 temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
4947 /* Handle calls that return values in multiple non-contiguous locations.
4948 The Irix 6 ABI has examples of this. */
4949 if (GET_CODE (to_rtx) == PARALLEL)
4951 if (GET_CODE (temp) == PARALLEL)
4952 emit_group_move (to_rtx, temp);
4953 else
4954 emit_group_load (to_rtx, temp, TREE_TYPE (from),
4955 int_size_in_bytes (TREE_TYPE (from)));
4957 else if (temp)
4958 emit_move_insn (to_rtx, temp);
4960 preserve_temp_slots (to_rtx);
4961 pop_temp_slots ();
4962 return;
4965 /* In case we are returning the contents of an object which overlaps
4966 the place the value is being stored, use a safe function when copying
4967 a value through a pointer into a structure value return block. */
4968 if (TREE_CODE (to) == RESULT_DECL
4969 && TREE_CODE (from) == INDIRECT_REF
4970 && ADDR_SPACE_GENERIC_P
4971 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
4972 && refs_may_alias_p (to, from)
4973 && cfun->returns_struct
4974 && !cfun->returns_pcc_struct)
4976 rtx from_rtx, size;
4978 push_temp_slots ();
4979 size = expr_size (from);
4980 from_rtx = expand_normal (from);
4982 emit_library_call (memmove_libfunc, LCT_NORMAL,
4983 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
4984 XEXP (from_rtx, 0), Pmode,
4985 convert_to_mode (TYPE_MODE (sizetype),
4986 size, TYPE_UNSIGNED (sizetype)),
4987 TYPE_MODE (sizetype));
4989 preserve_temp_slots (to_rtx);
4990 pop_temp_slots ();
4991 return;
4994 /* Compute FROM and store the value in the rtx we got. */
4996 push_temp_slots ();
4997 result = store_expr (from, to_rtx, 0, nontemporal);
4998 preserve_temp_slots (result);
4999 pop_temp_slots ();
5000 return;
5003 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5004 succeeded, false otherwise. */
5006 bool
5007 emit_storent_insn (rtx to, rtx from)
5009 struct expand_operand ops[2];
5010 enum machine_mode mode = GET_MODE (to);
5011 enum insn_code code = optab_handler (storent_optab, mode);
5013 if (code == CODE_FOR_nothing)
5014 return false;
5016 create_fixed_operand (&ops[0], to);
5017 create_input_operand (&ops[1], from, mode);
5018 return maybe_expand_insn (code, 2, ops);
5021 /* Generate code for computing expression EXP,
5022 and storing the value into TARGET.
5024 If the mode is BLKmode then we may return TARGET itself.
5025 It turns out that in BLKmode it doesn't cause a problem.
5026 because C has no operators that could combine two different
5027 assignments into the same BLKmode object with different values
5028 with no sequence point. Will other languages need this to
5029 be more thorough?
5031 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5032 stack, and block moves may need to be treated specially.
5034 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5037 store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
5039 rtx temp;
5040 rtx alt_rtl = NULL_RTX;
5041 location_t loc = curr_insn_location ();
5043 if (VOID_TYPE_P (TREE_TYPE (exp)))
5045 /* C++ can generate ?: expressions with a throw expression in one
5046 branch and an rvalue in the other. Here, we resolve attempts to
5047 store the throw expression's nonexistent result. */
5048 gcc_assert (!call_param_p);
5049 expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
5050 return NULL_RTX;
5052 if (TREE_CODE (exp) == COMPOUND_EXPR)
5054 /* Perform first part of compound expression, then assign from second
5055 part. */
5056 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
5057 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5058 return store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
5059 nontemporal);
5061 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
5063 /* For conditional expression, get safe form of the target. Then
5064 test the condition, doing the appropriate assignment on either
5065 side. This avoids the creation of unnecessary temporaries.
5066 For non-BLKmode, it is more efficient not to do this. */
5068 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
5070 do_pending_stack_adjust ();
5071 NO_DEFER_POP;
5072 jumpifnot (TREE_OPERAND (exp, 0), lab1, -1);
5073 store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
5074 nontemporal);
5075 emit_jump_insn (gen_jump (lab2));
5076 emit_barrier ();
5077 emit_label (lab1);
5078 store_expr (TREE_OPERAND (exp, 2), target, call_param_p,
5079 nontemporal);
5080 emit_label (lab2);
5081 OK_DEFER_POP;
5083 return NULL_RTX;
5085 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
5086 /* If this is a scalar in a register that is stored in a wider mode
5087 than the declared mode, compute the result into its declared mode
5088 and then convert to the wider mode. Our value is the computed
5089 expression. */
5091 rtx inner_target = 0;
5093 /* We can do the conversion inside EXP, which will often result
5094 in some optimizations. Do the conversion in two steps: first
5095 change the signedness, if needed, then the extend. But don't
5096 do this if the type of EXP is a subtype of something else
5097 since then the conversion might involve more than just
5098 converting modes. */
5099 if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
5100 && TREE_TYPE (TREE_TYPE (exp)) == 0
5101 && GET_MODE_PRECISION (GET_MODE (target))
5102 == TYPE_PRECISION (TREE_TYPE (exp)))
5104 if (TYPE_UNSIGNED (TREE_TYPE (exp))
5105 != SUBREG_PROMOTED_UNSIGNED_P (target))
5107 /* Some types, e.g. Fortran's logical*4, won't have a signed
5108 version, so use the mode instead. */
5109 tree ntype
5110 = (signed_or_unsigned_type_for
5111 (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)));
5112 if (ntype == NULL)
5113 ntype = lang_hooks.types.type_for_mode
5114 (TYPE_MODE (TREE_TYPE (exp)),
5115 SUBREG_PROMOTED_UNSIGNED_P (target));
5117 exp = fold_convert_loc (loc, ntype, exp);
5120 exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
5121 (GET_MODE (SUBREG_REG (target)),
5122 SUBREG_PROMOTED_UNSIGNED_P (target)),
5123 exp);
5125 inner_target = SUBREG_REG (target);
5128 temp = expand_expr (exp, inner_target, VOIDmode,
5129 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5131 /* If TEMP is a VOIDmode constant, use convert_modes to make
5132 sure that we properly convert it. */
5133 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
5135 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5136 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
5137 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
5138 GET_MODE (target), temp,
5139 SUBREG_PROMOTED_UNSIGNED_P (target));
5142 convert_move (SUBREG_REG (target), temp,
5143 SUBREG_PROMOTED_UNSIGNED_P (target));
5145 return NULL_RTX;
5147 else if ((TREE_CODE (exp) == STRING_CST
5148 || (TREE_CODE (exp) == MEM_REF
5149 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
5150 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
5151 == STRING_CST
5152 && integer_zerop (TREE_OPERAND (exp, 1))))
5153 && !nontemporal && !call_param_p
5154 && MEM_P (target))
5156 /* Optimize initialization of an array with a STRING_CST. */
5157 HOST_WIDE_INT exp_len, str_copy_len;
5158 rtx dest_mem;
5159 tree str = TREE_CODE (exp) == STRING_CST
5160 ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5162 exp_len = int_expr_size (exp);
5163 if (exp_len <= 0)
5164 goto normal_expr;
5166 if (TREE_STRING_LENGTH (str) <= 0)
5167 goto normal_expr;
5169 str_copy_len = strlen (TREE_STRING_POINTER (str));
5170 if (str_copy_len < TREE_STRING_LENGTH (str) - 1)
5171 goto normal_expr;
5173 str_copy_len = TREE_STRING_LENGTH (str);
5174 if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0
5175 && TREE_STRING_POINTER (str)[TREE_STRING_LENGTH (str) - 1] == '\0')
5177 str_copy_len += STORE_MAX_PIECES - 1;
5178 str_copy_len &= ~(STORE_MAX_PIECES - 1);
5180 str_copy_len = MIN (str_copy_len, exp_len);
5181 if (!can_store_by_pieces (str_copy_len, builtin_strncpy_read_str,
5182 CONST_CAST (char *, TREE_STRING_POINTER (str)),
5183 MEM_ALIGN (target), false))
5184 goto normal_expr;
5186 dest_mem = target;
5188 dest_mem = store_by_pieces (dest_mem,
5189 str_copy_len, builtin_strncpy_read_str,
5190 CONST_CAST (char *,
5191 TREE_STRING_POINTER (str)),
5192 MEM_ALIGN (target), false,
5193 exp_len > str_copy_len ? 1 : 0);
5194 if (exp_len > str_copy_len)
5195 clear_storage (adjust_address (dest_mem, BLKmode, 0),
5196 GEN_INT (exp_len - str_copy_len),
5197 BLOCK_OP_NORMAL);
5198 return NULL_RTX;
5200 else
5202 rtx tmp_target;
5204 normal_expr:
5205 /* If we want to use a nontemporal store, force the value to
5206 register first. */
5207 tmp_target = nontemporal ? NULL_RTX : target;
5208 temp = expand_expr_real (exp, tmp_target, GET_MODE (target),
5209 (call_param_p
5210 ? EXPAND_STACK_PARM : EXPAND_NORMAL),
5211 &alt_rtl);
5214 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5215 the same as that of TARGET, adjust the constant. This is needed, for
5216 example, in case it is a CONST_DOUBLE and we want only a word-sized
5217 value. */
5218 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
5219 && TREE_CODE (exp) != ERROR_MARK
5220 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
5221 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5222 temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5224 /* If value was not generated in the target, store it there.
5225 Convert the value to TARGET's type first if necessary and emit the
5226 pending incrementations that have been queued when expanding EXP.
5227 Note that we cannot emit the whole queue blindly because this will
5228 effectively disable the POST_INC optimization later.
5230 If TEMP and TARGET compare equal according to rtx_equal_p, but
5231 one or both of them are volatile memory refs, we have to distinguish
5232 two cases:
5233 - expand_expr has used TARGET. In this case, we must not generate
5234 another copy. This can be detected by TARGET being equal according
5235 to == .
5236 - expand_expr has not used TARGET - that means that the source just
5237 happens to have the same RTX form. Since temp will have been created
5238 by expand_expr, it will compare unequal according to == .
5239 We must generate a copy in this case, to reach the correct number
5240 of volatile memory references. */
5242 if ((! rtx_equal_p (temp, target)
5243 || (temp != target && (side_effects_p (temp)
5244 || side_effects_p (target))))
5245 && TREE_CODE (exp) != ERROR_MARK
5246 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5247 but TARGET is not valid memory reference, TEMP will differ
5248 from TARGET although it is really the same location. */
5249 && !(alt_rtl
5250 && rtx_equal_p (alt_rtl, target)
5251 && !side_effects_p (alt_rtl)
5252 && !side_effects_p (target))
5253 /* If there's nothing to copy, don't bother. Don't call
5254 expr_size unless necessary, because some front-ends (C++)
5255 expr_size-hook must not be given objects that are not
5256 supposed to be bit-copied or bit-initialized. */
5257 && expr_size (exp) != const0_rtx)
5259 if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
5261 if (GET_MODE (target) == BLKmode)
5263 /* Handle calls that return BLKmode values in registers. */
5264 if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
5265 copy_blkmode_from_reg (target, temp, TREE_TYPE (exp));
5266 else
5267 store_bit_field (target,
5268 INTVAL (expr_size (exp)) * BITS_PER_UNIT,
5269 0, 0, 0, GET_MODE (temp), temp);
5271 else
5272 convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5275 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
5277 /* Handle copying a string constant into an array. The string
5278 constant may be shorter than the array. So copy just the string's
5279 actual length, and clear the rest. First get the size of the data
5280 type of the string, which is actually the size of the target. */
5281 rtx size = expr_size (exp);
5283 if (CONST_INT_P (size)
5284 && INTVAL (size) < TREE_STRING_LENGTH (exp))
5285 emit_block_move (target, temp, size,
5286 (call_param_p
5287 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5288 else
5290 enum machine_mode pointer_mode
5291 = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
5292 enum machine_mode address_mode = get_address_mode (target);
5294 /* Compute the size of the data to copy from the string. */
5295 tree copy_size
5296 = size_binop_loc (loc, MIN_EXPR,
5297 make_tree (sizetype, size),
5298 size_int (TREE_STRING_LENGTH (exp)));
5299 rtx copy_size_rtx
5300 = expand_expr (copy_size, NULL_RTX, VOIDmode,
5301 (call_param_p
5302 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
5303 rtx label = 0;
5305 /* Copy that much. */
5306 copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
5307 TYPE_UNSIGNED (sizetype));
5308 emit_block_move (target, temp, copy_size_rtx,
5309 (call_param_p
5310 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5312 /* Figure out how much is left in TARGET that we have to clear.
5313 Do all calculations in pointer_mode. */
5314 if (CONST_INT_P (copy_size_rtx))
5316 size = plus_constant (address_mode, size,
5317 -INTVAL (copy_size_rtx));
5318 target = adjust_address (target, BLKmode,
5319 INTVAL (copy_size_rtx));
5321 else
5323 size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
5324 copy_size_rtx, NULL_RTX, 0,
5325 OPTAB_LIB_WIDEN);
5327 if (GET_MODE (copy_size_rtx) != address_mode)
5328 copy_size_rtx = convert_to_mode (address_mode,
5329 copy_size_rtx,
5330 TYPE_UNSIGNED (sizetype));
5332 target = offset_address (target, copy_size_rtx,
5333 highest_pow2_factor (copy_size));
5334 label = gen_label_rtx ();
5335 emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
5336 GET_MODE (size), 0, label);
5339 if (size != const0_rtx)
5340 clear_storage (target, size, BLOCK_OP_NORMAL);
5342 if (label)
5343 emit_label (label);
5346 /* Handle calls that return values in multiple non-contiguous locations.
5347 The Irix 6 ABI has examples of this. */
5348 else if (GET_CODE (target) == PARALLEL)
5350 if (GET_CODE (temp) == PARALLEL)
5351 emit_group_move (target, temp);
5352 else
5353 emit_group_load (target, temp, TREE_TYPE (exp),
5354 int_size_in_bytes (TREE_TYPE (exp)));
5356 else if (GET_CODE (temp) == PARALLEL)
5357 emit_group_store (target, temp, TREE_TYPE (exp),
5358 int_size_in_bytes (TREE_TYPE (exp)));
5359 else if (GET_MODE (temp) == BLKmode)
5360 emit_block_move (target, temp, expr_size (exp),
5361 (call_param_p
5362 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5363 /* If we emit a nontemporal store, there is nothing else to do. */
5364 else if (nontemporal && emit_storent_insn (target, temp))
5366 else
5368 temp = force_operand (temp, target);
5369 if (temp != target)
5370 emit_move_insn (target, temp);
5374 return NULL_RTX;
5377 /* Return true if field F of structure TYPE is a flexible array. */
5379 static bool
5380 flexible_array_member_p (const_tree f, const_tree type)
5382 const_tree tf;
5384 tf = TREE_TYPE (f);
5385 return (DECL_CHAIN (f) == NULL
5386 && TREE_CODE (tf) == ARRAY_TYPE
5387 && TYPE_DOMAIN (tf)
5388 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
5389 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
5390 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
5391 && int_size_in_bytes (type) >= 0);
5394 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5395 must have in order for it to completely initialize a value of type TYPE.
5396 Return -1 if the number isn't known.
5398 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5400 static HOST_WIDE_INT
5401 count_type_elements (const_tree type, bool for_ctor_p)
5403 switch (TREE_CODE (type))
5405 case ARRAY_TYPE:
5407 tree nelts;
5409 nelts = array_type_nelts (type);
5410 if (nelts && host_integerp (nelts, 1))
5412 unsigned HOST_WIDE_INT n;
5414 n = tree_low_cst (nelts, 1) + 1;
5415 if (n == 0 || for_ctor_p)
5416 return n;
5417 else
5418 return n * count_type_elements (TREE_TYPE (type), false);
5420 return for_ctor_p ? -1 : 1;
5423 case RECORD_TYPE:
5425 unsigned HOST_WIDE_INT n;
5426 tree f;
5428 n = 0;
5429 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5430 if (TREE_CODE (f) == FIELD_DECL)
5432 if (!for_ctor_p)
5433 n += count_type_elements (TREE_TYPE (f), false);
5434 else if (!flexible_array_member_p (f, type))
5435 /* Don't count flexible arrays, which are not supposed
5436 to be initialized. */
5437 n += 1;
5440 return n;
5443 case UNION_TYPE:
5444 case QUAL_UNION_TYPE:
5446 tree f;
5447 HOST_WIDE_INT n, m;
5449 gcc_assert (!for_ctor_p);
5450 /* Estimate the number of scalars in each field and pick the
5451 maximum. Other estimates would do instead; the idea is simply
5452 to make sure that the estimate is not sensitive to the ordering
5453 of the fields. */
5454 n = 1;
5455 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5456 if (TREE_CODE (f) == FIELD_DECL)
5458 m = count_type_elements (TREE_TYPE (f), false);
5459 /* If the field doesn't span the whole union, add an extra
5460 scalar for the rest. */
5461 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
5462 TYPE_SIZE (type)) != 1)
5463 m++;
5464 if (n < m)
5465 n = m;
5467 return n;
5470 case COMPLEX_TYPE:
5471 return 2;
5473 case VECTOR_TYPE:
5474 return TYPE_VECTOR_SUBPARTS (type);
5476 case INTEGER_TYPE:
5477 case REAL_TYPE:
5478 case FIXED_POINT_TYPE:
5479 case ENUMERAL_TYPE:
5480 case BOOLEAN_TYPE:
5481 case POINTER_TYPE:
5482 case OFFSET_TYPE:
5483 case REFERENCE_TYPE:
5484 case NULLPTR_TYPE:
5485 return 1;
5487 case ERROR_MARK:
5488 return 0;
5490 case VOID_TYPE:
5491 case METHOD_TYPE:
5492 case FUNCTION_TYPE:
5493 case LANG_TYPE:
5494 default:
5495 gcc_unreachable ();
5499 /* Helper for categorize_ctor_elements. Identical interface. */
5501 static bool
5502 categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5503 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5505 unsigned HOST_WIDE_INT idx;
5506 HOST_WIDE_INT nz_elts, init_elts, num_fields;
5507 tree value, purpose, elt_type;
5509 /* Whether CTOR is a valid constant initializer, in accordance with what
5510 initializer_constant_valid_p does. If inferred from the constructor
5511 elements, true until proven otherwise. */
5512 bool const_from_elts_p = constructor_static_from_elts_p (ctor);
5513 bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
5515 nz_elts = 0;
5516 init_elts = 0;
5517 num_fields = 0;
5518 elt_type = NULL_TREE;
5520 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
5522 HOST_WIDE_INT mult = 1;
5524 if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
5526 tree lo_index = TREE_OPERAND (purpose, 0);
5527 tree hi_index = TREE_OPERAND (purpose, 1);
5529 if (host_integerp (lo_index, 1) && host_integerp (hi_index, 1))
5530 mult = (tree_low_cst (hi_index, 1)
5531 - tree_low_cst (lo_index, 1) + 1);
5533 num_fields += mult;
5534 elt_type = TREE_TYPE (value);
5536 switch (TREE_CODE (value))
5538 case CONSTRUCTOR:
5540 HOST_WIDE_INT nz = 0, ic = 0;
5542 bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &ic,
5543 p_complete);
5545 nz_elts += mult * nz;
5546 init_elts += mult * ic;
5548 if (const_from_elts_p && const_p)
5549 const_p = const_elt_p;
5551 break;
5553 case INTEGER_CST:
5554 case REAL_CST:
5555 case FIXED_CST:
5556 if (!initializer_zerop (value))
5557 nz_elts += mult;
5558 init_elts += mult;
5559 break;
5561 case STRING_CST:
5562 nz_elts += mult * TREE_STRING_LENGTH (value);
5563 init_elts += mult * TREE_STRING_LENGTH (value);
5564 break;
5566 case COMPLEX_CST:
5567 if (!initializer_zerop (TREE_REALPART (value)))
5568 nz_elts += mult;
5569 if (!initializer_zerop (TREE_IMAGPART (value)))
5570 nz_elts += mult;
5571 init_elts += mult;
5572 break;
5574 case VECTOR_CST:
5576 unsigned i;
5577 for (i = 0; i < VECTOR_CST_NELTS (value); ++i)
5579 tree v = VECTOR_CST_ELT (value, i);
5580 if (!initializer_zerop (v))
5581 nz_elts += mult;
5582 init_elts += mult;
5585 break;
5587 default:
5589 HOST_WIDE_INT tc = count_type_elements (elt_type, false);
5590 nz_elts += mult * tc;
5591 init_elts += mult * tc;
5593 if (const_from_elts_p && const_p)
5594 const_p = initializer_constant_valid_p (value, elt_type)
5595 != NULL_TREE;
5597 break;
5601 if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
5602 num_fields, elt_type))
5603 *p_complete = false;
5605 *p_nz_elts += nz_elts;
5606 *p_init_elts += init_elts;
5608 return const_p;
5611 /* Examine CTOR to discover:
5612 * how many scalar fields are set to nonzero values,
5613 and place it in *P_NZ_ELTS;
5614 * how many scalar fields in total are in CTOR,
5615 and place it in *P_ELT_COUNT.
5616 * whether the constructor is complete -- in the sense that every
5617 meaningful byte is explicitly given a value --
5618 and place it in *P_COMPLETE.
5620 Return whether or not CTOR is a valid static constant initializer, the same
5621 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5623 bool
5624 categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5625 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5627 *p_nz_elts = 0;
5628 *p_init_elts = 0;
5629 *p_complete = true;
5631 return categorize_ctor_elements_1 (ctor, p_nz_elts, p_init_elts, p_complete);
5634 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5635 of which had type LAST_TYPE. Each element was itself a complete
5636 initializer, in the sense that every meaningful byte was explicitly
5637 given a value. Return true if the same is true for the constructor
5638 as a whole. */
5640 bool
5641 complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
5642 const_tree last_type)
5644 if (TREE_CODE (type) == UNION_TYPE
5645 || TREE_CODE (type) == QUAL_UNION_TYPE)
5647 if (num_elts == 0)
5648 return false;
5650 gcc_assert (num_elts == 1 && last_type);
5652 /* ??? We could look at each element of the union, and find the
5653 largest element. Which would avoid comparing the size of the
5654 initialized element against any tail padding in the union.
5655 Doesn't seem worth the effort... */
5656 return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
5659 return count_type_elements (type, true) == num_elts;
5662 /* Return 1 if EXP contains mostly (3/4) zeros. */
5664 static int
5665 mostly_zeros_p (const_tree exp)
5667 if (TREE_CODE (exp) == CONSTRUCTOR)
5669 HOST_WIDE_INT nz_elts, init_elts;
5670 bool complete_p;
5672 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5673 return !complete_p || nz_elts < init_elts / 4;
5676 return initializer_zerop (exp);
5679 /* Return 1 if EXP contains all zeros. */
5681 static int
5682 all_zeros_p (const_tree exp)
5684 if (TREE_CODE (exp) == CONSTRUCTOR)
5686 HOST_WIDE_INT nz_elts, init_elts;
5687 bool complete_p;
5689 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5690 return nz_elts == 0;
5693 return initializer_zerop (exp);
5696 /* Helper function for store_constructor.
5697 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5698 CLEARED is as for store_constructor.
5699 ALIAS_SET is the alias set to use for any stores.
5701 This provides a recursive shortcut back to store_constructor when it isn't
5702 necessary to go through store_field. This is so that we can pass through
5703 the cleared field to let store_constructor know that we may not have to
5704 clear a substructure if the outer structure has already been cleared. */
5706 static void
5707 store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
5708 HOST_WIDE_INT bitpos, enum machine_mode mode,
5709 tree exp, int cleared, alias_set_type alias_set)
5711 if (TREE_CODE (exp) == CONSTRUCTOR
5712 /* We can only call store_constructor recursively if the size and
5713 bit position are on a byte boundary. */
5714 && bitpos % BITS_PER_UNIT == 0
5715 && (bitsize > 0 && bitsize % BITS_PER_UNIT == 0)
5716 /* If we have a nonzero bitpos for a register target, then we just
5717 let store_field do the bitfield handling. This is unlikely to
5718 generate unnecessary clear instructions anyways. */
5719 && (bitpos == 0 || MEM_P (target)))
5721 if (MEM_P (target))
5722 target
5723 = adjust_address (target,
5724 GET_MODE (target) == BLKmode
5725 || 0 != (bitpos
5726 % GET_MODE_ALIGNMENT (GET_MODE (target)))
5727 ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
5730 /* Update the alias set, if required. */
5731 if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
5732 && MEM_ALIAS_SET (target) != 0)
5734 target = copy_rtx (target);
5735 set_mem_alias_set (target, alias_set);
5738 store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
5740 else
5741 store_field (target, bitsize, bitpos, 0, 0, mode, exp, alias_set, false);
5744 /* Store the value of constructor EXP into the rtx TARGET.
5745 TARGET is either a REG or a MEM; we know it cannot conflict, since
5746 safe_from_p has been called.
5747 CLEARED is true if TARGET is known to have been zero'd.
5748 SIZE is the number of bytes of TARGET we are allowed to modify: this
5749 may not be the same as the size of EXP if we are assigning to a field
5750 which has been packed to exclude padding bits. */
5752 static void
5753 store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
5755 tree type = TREE_TYPE (exp);
5756 #ifdef WORD_REGISTER_OPERATIONS
5757 HOST_WIDE_INT exp_size = int_size_in_bytes (type);
5758 #endif
5760 switch (TREE_CODE (type))
5762 case RECORD_TYPE:
5763 case UNION_TYPE:
5764 case QUAL_UNION_TYPE:
5766 unsigned HOST_WIDE_INT idx;
5767 tree field, value;
5769 /* If size is zero or the target is already cleared, do nothing. */
5770 if (size == 0 || cleared)
5771 cleared = 1;
5772 /* We either clear the aggregate or indicate the value is dead. */
5773 else if ((TREE_CODE (type) == UNION_TYPE
5774 || TREE_CODE (type) == QUAL_UNION_TYPE)
5775 && ! CONSTRUCTOR_ELTS (exp))
5776 /* If the constructor is empty, clear the union. */
5778 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
5779 cleared = 1;
5782 /* If we are building a static constructor into a register,
5783 set the initial value as zero so we can fold the value into
5784 a constant. But if more than one register is involved,
5785 this probably loses. */
5786 else if (REG_P (target) && TREE_STATIC (exp)
5787 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
5789 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5790 cleared = 1;
5793 /* If the constructor has fewer fields than the structure or
5794 if we are initializing the structure to mostly zeros, clear
5795 the whole structure first. Don't do this if TARGET is a
5796 register whose mode size isn't equal to SIZE since
5797 clear_storage can't handle this case. */
5798 else if (size > 0
5799 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp))
5800 != fields_length (type))
5801 || mostly_zeros_p (exp))
5802 && (!REG_P (target)
5803 || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
5804 == size)))
5806 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5807 cleared = 1;
5810 if (REG_P (target) && !cleared)
5811 emit_clobber (target);
5813 /* Store each element of the constructor into the
5814 corresponding field of TARGET. */
5815 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
5817 enum machine_mode mode;
5818 HOST_WIDE_INT bitsize;
5819 HOST_WIDE_INT bitpos = 0;
5820 tree offset;
5821 rtx to_rtx = target;
5823 /* Just ignore missing fields. We cleared the whole
5824 structure, above, if any fields are missing. */
5825 if (field == 0)
5826 continue;
5828 if (cleared && initializer_zerop (value))
5829 continue;
5831 if (host_integerp (DECL_SIZE (field), 1))
5832 bitsize = tree_low_cst (DECL_SIZE (field), 1);
5833 else
5834 bitsize = -1;
5836 mode = DECL_MODE (field);
5837 if (DECL_BIT_FIELD (field))
5838 mode = VOIDmode;
5840 offset = DECL_FIELD_OFFSET (field);
5841 if (host_integerp (offset, 0)
5842 && host_integerp (bit_position (field), 0))
5844 bitpos = int_bit_position (field);
5845 offset = 0;
5847 else
5848 bitpos = tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 0);
5850 if (offset)
5852 enum machine_mode address_mode;
5853 rtx offset_rtx;
5855 offset
5856 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
5857 make_tree (TREE_TYPE (exp),
5858 target));
5860 offset_rtx = expand_normal (offset);
5861 gcc_assert (MEM_P (to_rtx));
5863 address_mode = get_address_mode (to_rtx);
5864 if (GET_MODE (offset_rtx) != address_mode)
5865 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
5867 to_rtx = offset_address (to_rtx, offset_rtx,
5868 highest_pow2_factor (offset));
5871 #ifdef WORD_REGISTER_OPERATIONS
5872 /* If this initializes a field that is smaller than a
5873 word, at the start of a word, try to widen it to a full
5874 word. This special case allows us to output C++ member
5875 function initializations in a form that the optimizers
5876 can understand. */
5877 if (REG_P (target)
5878 && bitsize < BITS_PER_WORD
5879 && bitpos % BITS_PER_WORD == 0
5880 && GET_MODE_CLASS (mode) == MODE_INT
5881 && TREE_CODE (value) == INTEGER_CST
5882 && exp_size >= 0
5883 && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
5885 tree type = TREE_TYPE (value);
5887 if (TYPE_PRECISION (type) < BITS_PER_WORD)
5889 type = lang_hooks.types.type_for_mode
5890 (word_mode, TYPE_UNSIGNED (type));
5891 value = fold_convert (type, value);
5894 if (BYTES_BIG_ENDIAN)
5895 value
5896 = fold_build2 (LSHIFT_EXPR, type, value,
5897 build_int_cst (type,
5898 BITS_PER_WORD - bitsize));
5899 bitsize = BITS_PER_WORD;
5900 mode = word_mode;
5902 #endif
5904 if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
5905 && DECL_NONADDRESSABLE_P (field))
5907 to_rtx = copy_rtx (to_rtx);
5908 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
5911 store_constructor_field (to_rtx, bitsize, bitpos, mode,
5912 value, cleared,
5913 get_alias_set (TREE_TYPE (field)));
5915 break;
5917 case ARRAY_TYPE:
5919 tree value, index;
5920 unsigned HOST_WIDE_INT i;
5921 int need_to_clear;
5922 tree domain;
5923 tree elttype = TREE_TYPE (type);
5924 int const_bounds_p;
5925 HOST_WIDE_INT minelt = 0;
5926 HOST_WIDE_INT maxelt = 0;
5928 domain = TYPE_DOMAIN (type);
5929 const_bounds_p = (TYPE_MIN_VALUE (domain)
5930 && TYPE_MAX_VALUE (domain)
5931 && host_integerp (TYPE_MIN_VALUE (domain), 0)
5932 && host_integerp (TYPE_MAX_VALUE (domain), 0));
5934 /* If we have constant bounds for the range of the type, get them. */
5935 if (const_bounds_p)
5937 minelt = tree_low_cst (TYPE_MIN_VALUE (domain), 0);
5938 maxelt = tree_low_cst (TYPE_MAX_VALUE (domain), 0);
5941 /* If the constructor has fewer elements than the array, clear
5942 the whole array first. Similarly if this is static
5943 constructor of a non-BLKmode object. */
5944 if (cleared)
5945 need_to_clear = 0;
5946 else if (REG_P (target) && TREE_STATIC (exp))
5947 need_to_clear = 1;
5948 else
5950 unsigned HOST_WIDE_INT idx;
5951 tree index, value;
5952 HOST_WIDE_INT count = 0, zero_count = 0;
5953 need_to_clear = ! const_bounds_p;
5955 /* This loop is a more accurate version of the loop in
5956 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5957 is also needed to check for missing elements. */
5958 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
5960 HOST_WIDE_INT this_node_count;
5962 if (need_to_clear)
5963 break;
5965 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5967 tree lo_index = TREE_OPERAND (index, 0);
5968 tree hi_index = TREE_OPERAND (index, 1);
5970 if (! host_integerp (lo_index, 1)
5971 || ! host_integerp (hi_index, 1))
5973 need_to_clear = 1;
5974 break;
5977 this_node_count = (tree_low_cst (hi_index, 1)
5978 - tree_low_cst (lo_index, 1) + 1);
5980 else
5981 this_node_count = 1;
5983 count += this_node_count;
5984 if (mostly_zeros_p (value))
5985 zero_count += this_node_count;
5988 /* Clear the entire array first if there are any missing
5989 elements, or if the incidence of zero elements is >=
5990 75%. */
5991 if (! need_to_clear
5992 && (count < maxelt - minelt + 1
5993 || 4 * zero_count >= 3 * count))
5994 need_to_clear = 1;
5997 if (need_to_clear && size > 0)
5999 if (REG_P (target))
6000 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6001 else
6002 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6003 cleared = 1;
6006 if (!cleared && REG_P (target))
6007 /* Inform later passes that the old value is dead. */
6008 emit_clobber (target);
6010 /* Store each element of the constructor into the
6011 corresponding element of TARGET, determined by counting the
6012 elements. */
6013 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
6015 enum machine_mode mode;
6016 HOST_WIDE_INT bitsize;
6017 HOST_WIDE_INT bitpos;
6018 rtx xtarget = target;
6020 if (cleared && initializer_zerop (value))
6021 continue;
6023 mode = TYPE_MODE (elttype);
6024 if (mode == BLKmode)
6025 bitsize = (host_integerp (TYPE_SIZE (elttype), 1)
6026 ? tree_low_cst (TYPE_SIZE (elttype), 1)
6027 : -1);
6028 else
6029 bitsize = GET_MODE_BITSIZE (mode);
6031 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
6033 tree lo_index = TREE_OPERAND (index, 0);
6034 tree hi_index = TREE_OPERAND (index, 1);
6035 rtx index_r, pos_rtx;
6036 HOST_WIDE_INT lo, hi, count;
6037 tree position;
6039 /* If the range is constant and "small", unroll the loop. */
6040 if (const_bounds_p
6041 && host_integerp (lo_index, 0)
6042 && host_integerp (hi_index, 0)
6043 && (lo = tree_low_cst (lo_index, 0),
6044 hi = tree_low_cst (hi_index, 0),
6045 count = hi - lo + 1,
6046 (!MEM_P (target)
6047 || count <= 2
6048 || (host_integerp (TYPE_SIZE (elttype), 1)
6049 && (tree_low_cst (TYPE_SIZE (elttype), 1) * count
6050 <= 40 * 8)))))
6052 lo -= minelt; hi -= minelt;
6053 for (; lo <= hi; lo++)
6055 bitpos = lo * tree_low_cst (TYPE_SIZE (elttype), 0);
6057 if (MEM_P (target)
6058 && !MEM_KEEP_ALIAS_SET_P (target)
6059 && TREE_CODE (type) == ARRAY_TYPE
6060 && TYPE_NONALIASED_COMPONENT (type))
6062 target = copy_rtx (target);
6063 MEM_KEEP_ALIAS_SET_P (target) = 1;
6066 store_constructor_field
6067 (target, bitsize, bitpos, mode, value, cleared,
6068 get_alias_set (elttype));
6071 else
6073 rtx loop_start = gen_label_rtx ();
6074 rtx loop_end = gen_label_rtx ();
6075 tree exit_cond;
6077 expand_normal (hi_index);
6079 index = build_decl (EXPR_LOCATION (exp),
6080 VAR_DECL, NULL_TREE, domain);
6081 index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
6082 SET_DECL_RTL (index, index_r);
6083 store_expr (lo_index, index_r, 0, false);
6085 /* Build the head of the loop. */
6086 do_pending_stack_adjust ();
6087 emit_label (loop_start);
6089 /* Assign value to element index. */
6090 position =
6091 fold_convert (ssizetype,
6092 fold_build2 (MINUS_EXPR,
6093 TREE_TYPE (index),
6094 index,
6095 TYPE_MIN_VALUE (domain)));
6097 position =
6098 size_binop (MULT_EXPR, position,
6099 fold_convert (ssizetype,
6100 TYPE_SIZE_UNIT (elttype)));
6102 pos_rtx = expand_normal (position);
6103 xtarget = offset_address (target, pos_rtx,
6104 highest_pow2_factor (position));
6105 xtarget = adjust_address (xtarget, mode, 0);
6106 if (TREE_CODE (value) == CONSTRUCTOR)
6107 store_constructor (value, xtarget, cleared,
6108 bitsize / BITS_PER_UNIT);
6109 else
6110 store_expr (value, xtarget, 0, false);
6112 /* Generate a conditional jump to exit the loop. */
6113 exit_cond = build2 (LT_EXPR, integer_type_node,
6114 index, hi_index);
6115 jumpif (exit_cond, loop_end, -1);
6117 /* Update the loop counter, and jump to the head of
6118 the loop. */
6119 expand_assignment (index,
6120 build2 (PLUS_EXPR, TREE_TYPE (index),
6121 index, integer_one_node),
6122 false);
6124 emit_jump (loop_start);
6126 /* Build the end of the loop. */
6127 emit_label (loop_end);
6130 else if ((index != 0 && ! host_integerp (index, 0))
6131 || ! host_integerp (TYPE_SIZE (elttype), 1))
6133 tree position;
6135 if (index == 0)
6136 index = ssize_int (1);
6138 if (minelt)
6139 index = fold_convert (ssizetype,
6140 fold_build2 (MINUS_EXPR,
6141 TREE_TYPE (index),
6142 index,
6143 TYPE_MIN_VALUE (domain)));
6145 position =
6146 size_binop (MULT_EXPR, index,
6147 fold_convert (ssizetype,
6148 TYPE_SIZE_UNIT (elttype)));
6149 xtarget = offset_address (target,
6150 expand_normal (position),
6151 highest_pow2_factor (position));
6152 xtarget = adjust_address (xtarget, mode, 0);
6153 store_expr (value, xtarget, 0, false);
6155 else
6157 if (index != 0)
6158 bitpos = ((tree_low_cst (index, 0) - minelt)
6159 * tree_low_cst (TYPE_SIZE (elttype), 1));
6160 else
6161 bitpos = (i * tree_low_cst (TYPE_SIZE (elttype), 1));
6163 if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
6164 && TREE_CODE (type) == ARRAY_TYPE
6165 && TYPE_NONALIASED_COMPONENT (type))
6167 target = copy_rtx (target);
6168 MEM_KEEP_ALIAS_SET_P (target) = 1;
6170 store_constructor_field (target, bitsize, bitpos, mode, value,
6171 cleared, get_alias_set (elttype));
6174 break;
6177 case VECTOR_TYPE:
6179 unsigned HOST_WIDE_INT idx;
6180 constructor_elt *ce;
6181 int i;
6182 int need_to_clear;
6183 int icode = CODE_FOR_nothing;
6184 tree elttype = TREE_TYPE (type);
6185 int elt_size = tree_low_cst (TYPE_SIZE (elttype), 1);
6186 enum machine_mode eltmode = TYPE_MODE (elttype);
6187 HOST_WIDE_INT bitsize;
6188 HOST_WIDE_INT bitpos;
6189 rtvec vector = NULL;
6190 unsigned n_elts;
6191 alias_set_type alias;
6193 gcc_assert (eltmode != BLKmode);
6195 n_elts = TYPE_VECTOR_SUBPARTS (type);
6196 if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
6198 enum machine_mode mode = GET_MODE (target);
6200 icode = (int) optab_handler (vec_init_optab, mode);
6201 if (icode != CODE_FOR_nothing)
6203 unsigned int i;
6205 vector = rtvec_alloc (n_elts);
6206 for (i = 0; i < n_elts; i++)
6207 RTVEC_ELT (vector, i) = CONST0_RTX (GET_MODE_INNER (mode));
6211 /* If the constructor has fewer elements than the vector,
6212 clear the whole array first. Similarly if this is static
6213 constructor of a non-BLKmode object. */
6214 if (cleared)
6215 need_to_clear = 0;
6216 else if (REG_P (target) && TREE_STATIC (exp))
6217 need_to_clear = 1;
6218 else
6220 unsigned HOST_WIDE_INT count = 0, zero_count = 0;
6221 tree value;
6223 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
6225 int n_elts_here = tree_low_cst
6226 (int_const_binop (TRUNC_DIV_EXPR,
6227 TYPE_SIZE (TREE_TYPE (value)),
6228 TYPE_SIZE (elttype)), 1);
6230 count += n_elts_here;
6231 if (mostly_zeros_p (value))
6232 zero_count += n_elts_here;
6235 /* Clear the entire vector first if there are any missing elements,
6236 or if the incidence of zero elements is >= 75%. */
6237 need_to_clear = (count < n_elts || 4 * zero_count >= 3 * count);
6240 if (need_to_clear && size > 0 && !vector)
6242 if (REG_P (target))
6243 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6244 else
6245 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6246 cleared = 1;
6249 /* Inform later passes that the old value is dead. */
6250 if (!cleared && !vector && REG_P (target))
6251 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6253 if (MEM_P (target))
6254 alias = MEM_ALIAS_SET (target);
6255 else
6256 alias = get_alias_set (elttype);
6258 /* Store each element of the constructor into the corresponding
6259 element of TARGET, determined by counting the elements. */
6260 for (idx = 0, i = 0;
6261 vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
6262 idx++, i += bitsize / elt_size)
6264 HOST_WIDE_INT eltpos;
6265 tree value = ce->value;
6267 bitsize = tree_low_cst (TYPE_SIZE (TREE_TYPE (value)), 1);
6268 if (cleared && initializer_zerop (value))
6269 continue;
6271 if (ce->index)
6272 eltpos = tree_low_cst (ce->index, 1);
6273 else
6274 eltpos = i;
6276 if (vector)
6278 /* Vector CONSTRUCTORs should only be built from smaller
6279 vectors in the case of BLKmode vectors. */
6280 gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
6281 RTVEC_ELT (vector, eltpos)
6282 = expand_normal (value);
6284 else
6286 enum machine_mode value_mode =
6287 TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
6288 ? TYPE_MODE (TREE_TYPE (value))
6289 : eltmode;
6290 bitpos = eltpos * elt_size;
6291 store_constructor_field (target, bitsize, bitpos, value_mode,
6292 value, cleared, alias);
6296 if (vector)
6297 emit_insn (GEN_FCN (icode)
6298 (target,
6299 gen_rtx_PARALLEL (GET_MODE (target), vector)));
6300 break;
6303 default:
6304 gcc_unreachable ();
6308 /* Store the value of EXP (an expression tree)
6309 into a subfield of TARGET which has mode MODE and occupies
6310 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6311 If MODE is VOIDmode, it means that we are storing into a bit-field.
6313 BITREGION_START is bitpos of the first bitfield in this region.
6314 BITREGION_END is the bitpos of the ending bitfield in this region.
6315 These two fields are 0, if the C++ memory model does not apply,
6316 or we are not interested in keeping track of bitfield regions.
6318 Always return const0_rtx unless we have something particular to
6319 return.
6321 ALIAS_SET is the alias set for the destination. This value will
6322 (in general) be different from that for TARGET, since TARGET is a
6323 reference to the containing structure.
6325 If NONTEMPORAL is true, try generating a nontemporal store. */
6327 static rtx
6328 store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
6329 unsigned HOST_WIDE_INT bitregion_start,
6330 unsigned HOST_WIDE_INT bitregion_end,
6331 enum machine_mode mode, tree exp,
6332 alias_set_type alias_set, bool nontemporal)
6334 if (TREE_CODE (exp) == ERROR_MARK)
6335 return const0_rtx;
6337 /* If we have nothing to store, do nothing unless the expression has
6338 side-effects. */
6339 if (bitsize == 0)
6340 return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
6342 if (GET_CODE (target) == CONCAT)
6344 /* We're storing into a struct containing a single __complex. */
6346 gcc_assert (!bitpos);
6347 return store_expr (exp, target, 0, nontemporal);
6350 /* If the structure is in a register or if the component
6351 is a bit field, we cannot use addressing to access it.
6352 Use bit-field techniques or SUBREG to store in it. */
6354 if (mode == VOIDmode
6355 || (mode != BLKmode && ! direct_store[(int) mode]
6356 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
6357 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
6358 || REG_P (target)
6359 || GET_CODE (target) == SUBREG
6360 /* If the field isn't aligned enough to store as an ordinary memref,
6361 store it as a bit field. */
6362 || (mode != BLKmode
6363 && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
6364 || bitpos % GET_MODE_ALIGNMENT (mode))
6365 && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
6366 || (bitpos % BITS_PER_UNIT != 0)))
6367 || (bitsize >= 0 && mode != BLKmode
6368 && GET_MODE_BITSIZE (mode) > bitsize)
6369 /* If the RHS and field are a constant size and the size of the
6370 RHS isn't the same size as the bitfield, we must use bitfield
6371 operations. */
6372 || (bitsize >= 0
6373 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
6374 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0)
6375 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6376 decl we must use bitfield operations. */
6377 || (bitsize >= 0
6378 && TREE_CODE (exp) == MEM_REF
6379 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6380 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6381 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0),0 ))
6382 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
6384 rtx temp;
6385 gimple nop_def;
6387 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6388 implies a mask operation. If the precision is the same size as
6389 the field we're storing into, that mask is redundant. This is
6390 particularly common with bit field assignments generated by the
6391 C front end. */
6392 nop_def = get_def_for_expr (exp, NOP_EXPR);
6393 if (nop_def)
6395 tree type = TREE_TYPE (exp);
6396 if (INTEGRAL_TYPE_P (type)
6397 && TYPE_PRECISION (type) < GET_MODE_BITSIZE (TYPE_MODE (type))
6398 && bitsize == TYPE_PRECISION (type))
6400 tree op = gimple_assign_rhs1 (nop_def);
6401 type = TREE_TYPE (op);
6402 if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) >= bitsize)
6403 exp = op;
6407 temp = expand_normal (exp);
6409 /* If BITSIZE is narrower than the size of the type of EXP
6410 we will be narrowing TEMP. Normally, what's wanted are the
6411 low-order bits. However, if EXP's type is a record and this is
6412 big-endian machine, we want the upper BITSIZE bits. */
6413 if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
6414 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
6415 && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
6416 temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
6417 GET_MODE_BITSIZE (GET_MODE (temp)) - bitsize,
6418 NULL_RTX, 1);
6420 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6421 if (mode != VOIDmode && mode != BLKmode
6422 && mode != TYPE_MODE (TREE_TYPE (exp)))
6423 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
6425 /* If the modes of TEMP and TARGET are both BLKmode, both
6426 must be in memory and BITPOS must be aligned on a byte
6427 boundary. If so, we simply do a block copy. Likewise
6428 for a BLKmode-like TARGET. */
6429 if (GET_MODE (temp) == BLKmode
6430 && (GET_MODE (target) == BLKmode
6431 || (MEM_P (target)
6432 && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
6433 && (bitpos % BITS_PER_UNIT) == 0
6434 && (bitsize % BITS_PER_UNIT) == 0)))
6436 gcc_assert (MEM_P (target) && MEM_P (temp)
6437 && (bitpos % BITS_PER_UNIT) == 0);
6439 target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
6440 emit_block_move (target, temp,
6441 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
6442 / BITS_PER_UNIT),
6443 BLOCK_OP_NORMAL);
6445 return const0_rtx;
6448 /* Handle calls that return values in multiple non-contiguous locations.
6449 The Irix 6 ABI has examples of this. */
6450 if (GET_CODE (temp) == PARALLEL)
6452 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
6453 rtx temp_target;
6454 if (mode == BLKmode)
6455 mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
6456 temp_target = gen_reg_rtx (mode);
6457 emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
6458 temp = temp_target;
6460 else if (mode == BLKmode)
6462 /* Handle calls that return BLKmode values in registers. */
6463 if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
6465 rtx temp_target = gen_reg_rtx (GET_MODE (temp));
6466 copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp));
6467 temp = temp_target;
6469 else
6471 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
6472 rtx temp_target;
6473 mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
6474 temp_target = gen_reg_rtx (mode);
6475 temp_target
6476 = extract_bit_field (temp, size * BITS_PER_UNIT, 0, 1,
6477 temp_target, mode, mode);
6478 temp = temp_target;
6482 /* Store the value in the bitfield. */
6483 store_bit_field (target, bitsize, bitpos,
6484 bitregion_start, bitregion_end,
6485 mode, temp);
6487 return const0_rtx;
6489 else
6491 /* Now build a reference to just the desired component. */
6492 rtx to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
6494 if (to_rtx == target)
6495 to_rtx = copy_rtx (to_rtx);
6497 if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
6498 set_mem_alias_set (to_rtx, alias_set);
6500 return store_expr (exp, to_rtx, 0, nontemporal);
6504 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6505 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6506 codes and find the ultimate containing object, which we return.
6508 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6509 bit position, and *PUNSIGNEDP to the signedness of the field.
6510 If the position of the field is variable, we store a tree
6511 giving the variable offset (in units) in *POFFSET.
6512 This offset is in addition to the bit position.
6513 If the position is not variable, we store 0 in *POFFSET.
6515 If any of the extraction expressions is volatile,
6516 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6518 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6519 Otherwise, it is a mode that can be used to access the field.
6521 If the field describes a variable-sized object, *PMODE is set to
6522 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6523 this case, but the address of the object can be found.
6525 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6526 look through nodes that serve as markers of a greater alignment than
6527 the one that can be deduced from the expression. These nodes make it
6528 possible for front-ends to prevent temporaries from being created by
6529 the middle-end on alignment considerations. For that purpose, the
6530 normal operating mode at high-level is to always pass FALSE so that
6531 the ultimate containing object is really returned; moreover, the
6532 associated predicate handled_component_p will always return TRUE
6533 on these nodes, thus indicating that they are essentially handled
6534 by get_inner_reference. TRUE should only be passed when the caller
6535 is scanning the expression in order to build another representation
6536 and specifically knows how to handle these nodes; as such, this is
6537 the normal operating mode in the RTL expanders. */
6539 tree
6540 get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
6541 HOST_WIDE_INT *pbitpos, tree *poffset,
6542 enum machine_mode *pmode, int *punsignedp,
6543 int *pvolatilep, bool keep_aligning)
6545 tree size_tree = 0;
6546 enum machine_mode mode = VOIDmode;
6547 bool blkmode_bitfield = false;
6548 tree offset = size_zero_node;
6549 double_int bit_offset = double_int_zero;
6551 /* First get the mode, signedness, and size. We do this from just the
6552 outermost expression. */
6553 *pbitsize = -1;
6554 if (TREE_CODE (exp) == COMPONENT_REF)
6556 tree field = TREE_OPERAND (exp, 1);
6557 size_tree = DECL_SIZE (field);
6558 if (flag_strict_volatile_bitfields > 0
6559 && TREE_THIS_VOLATILE (exp)
6560 && DECL_BIT_FIELD_TYPE (field)
6561 && DECL_MODE (field) != BLKmode)
6562 /* Volatile bitfields should be accessed in the mode of the
6563 field's type, not the mode computed based on the bit
6564 size. */
6565 mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
6566 else if (!DECL_BIT_FIELD (field))
6567 mode = DECL_MODE (field);
6568 else if (DECL_MODE (field) == BLKmode)
6569 blkmode_bitfield = true;
6571 *punsignedp = DECL_UNSIGNED (field);
6573 else if (TREE_CODE (exp) == BIT_FIELD_REF)
6575 size_tree = TREE_OPERAND (exp, 1);
6576 *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
6577 || TYPE_UNSIGNED (TREE_TYPE (exp)));
6579 /* For vector types, with the correct size of access, use the mode of
6580 inner type. */
6581 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
6582 && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
6583 && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
6584 mode = TYPE_MODE (TREE_TYPE (exp));
6586 else
6588 mode = TYPE_MODE (TREE_TYPE (exp));
6589 *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
6591 if (mode == BLKmode)
6592 size_tree = TYPE_SIZE (TREE_TYPE (exp));
6593 else
6594 *pbitsize = GET_MODE_BITSIZE (mode);
6597 if (size_tree != 0)
6599 if (! host_integerp (size_tree, 1))
6600 mode = BLKmode, *pbitsize = -1;
6601 else
6602 *pbitsize = tree_low_cst (size_tree, 1);
6605 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6606 and find the ultimate containing object. */
6607 while (1)
6609 switch (TREE_CODE (exp))
6611 case BIT_FIELD_REF:
6612 bit_offset += tree_to_double_int (TREE_OPERAND (exp, 2));
6613 break;
6615 case COMPONENT_REF:
6617 tree field = TREE_OPERAND (exp, 1);
6618 tree this_offset = component_ref_field_offset (exp);
6620 /* If this field hasn't been filled in yet, don't go past it.
6621 This should only happen when folding expressions made during
6622 type construction. */
6623 if (this_offset == 0)
6624 break;
6626 offset = size_binop (PLUS_EXPR, offset, this_offset);
6627 bit_offset += tree_to_double_int (DECL_FIELD_BIT_OFFSET (field));
6629 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6631 break;
6633 case ARRAY_REF:
6634 case ARRAY_RANGE_REF:
6636 tree index = TREE_OPERAND (exp, 1);
6637 tree low_bound = array_ref_low_bound (exp);
6638 tree unit_size = array_ref_element_size (exp);
6640 /* We assume all arrays have sizes that are a multiple of a byte.
6641 First subtract the lower bound, if any, in the type of the
6642 index, then convert to sizetype and multiply by the size of
6643 the array element. */
6644 if (! integer_zerop (low_bound))
6645 index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
6646 index, low_bound);
6648 offset = size_binop (PLUS_EXPR, offset,
6649 size_binop (MULT_EXPR,
6650 fold_convert (sizetype, index),
6651 unit_size));
6653 break;
6655 case REALPART_EXPR:
6656 break;
6658 case IMAGPART_EXPR:
6659 bit_offset += double_int::from_uhwi (*pbitsize);
6660 break;
6662 case VIEW_CONVERT_EXPR:
6663 if (keep_aligning && STRICT_ALIGNMENT
6664 && (TYPE_ALIGN (TREE_TYPE (exp))
6665 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
6666 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
6667 < BIGGEST_ALIGNMENT)
6668 && (TYPE_ALIGN_OK (TREE_TYPE (exp))
6669 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp, 0)))))
6670 goto done;
6671 break;
6673 case MEM_REF:
6674 /* Hand back the decl for MEM[&decl, off]. */
6675 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
6677 tree off = TREE_OPERAND (exp, 1);
6678 if (!integer_zerop (off))
6680 double_int boff, coff = mem_ref_offset (exp);
6681 boff = coff.lshift (BITS_PER_UNIT == 8
6682 ? 3 : exact_log2 (BITS_PER_UNIT));
6683 bit_offset += boff;
6685 exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6687 goto done;
6689 default:
6690 goto done;
6693 /* If any reference in the chain is volatile, the effect is volatile. */
6694 if (TREE_THIS_VOLATILE (exp))
6695 *pvolatilep = 1;
6697 exp = TREE_OPERAND (exp, 0);
6699 done:
6701 /* If OFFSET is constant, see if we can return the whole thing as a
6702 constant bit position. Make sure to handle overflow during
6703 this conversion. */
6704 if (TREE_CODE (offset) == INTEGER_CST)
6706 double_int tem = tree_to_double_int (offset);
6707 tem = tem.sext (TYPE_PRECISION (sizetype));
6708 tem = tem.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
6709 tem += bit_offset;
6710 if (tem.fits_shwi ())
6712 *pbitpos = tem.to_shwi ();
6713 *poffset = offset = NULL_TREE;
6717 /* Otherwise, split it up. */
6718 if (offset)
6720 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6721 if (bit_offset.is_negative ())
6723 double_int mask
6724 = double_int::mask (BITS_PER_UNIT == 8
6725 ? 3 : exact_log2 (BITS_PER_UNIT));
6726 double_int tem = bit_offset.and_not (mask);
6727 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6728 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6729 bit_offset -= tem;
6730 tem = tem.arshift (BITS_PER_UNIT == 8
6731 ? 3 : exact_log2 (BITS_PER_UNIT),
6732 HOST_BITS_PER_DOUBLE_INT);
6733 offset = size_binop (PLUS_EXPR, offset,
6734 double_int_to_tree (sizetype, tem));
6737 *pbitpos = bit_offset.to_shwi ();
6738 *poffset = offset;
6741 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6742 if (mode == VOIDmode
6743 && blkmode_bitfield
6744 && (*pbitpos % BITS_PER_UNIT) == 0
6745 && (*pbitsize % BITS_PER_UNIT) == 0)
6746 *pmode = BLKmode;
6747 else
6748 *pmode = mode;
6750 return exp;
6753 /* Return a tree of sizetype representing the size, in bytes, of the element
6754 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6756 tree
6757 array_ref_element_size (tree exp)
6759 tree aligned_size = TREE_OPERAND (exp, 3);
6760 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
6761 location_t loc = EXPR_LOCATION (exp);
6763 /* If a size was specified in the ARRAY_REF, it's the size measured
6764 in alignment units of the element type. So multiply by that value. */
6765 if (aligned_size)
6767 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6768 sizetype from another type of the same width and signedness. */
6769 if (TREE_TYPE (aligned_size) != sizetype)
6770 aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
6771 return size_binop_loc (loc, MULT_EXPR, aligned_size,
6772 size_int (TYPE_ALIGN_UNIT (elmt_type)));
6775 /* Otherwise, take the size from that of the element type. Substitute
6776 any PLACEHOLDER_EXPR that we have. */
6777 else
6778 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
6781 /* Return a tree representing the lower bound of the array mentioned in
6782 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6784 tree
6785 array_ref_low_bound (tree exp)
6787 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
6789 /* If a lower bound is specified in EXP, use it. */
6790 if (TREE_OPERAND (exp, 2))
6791 return TREE_OPERAND (exp, 2);
6793 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6794 substituting for a PLACEHOLDER_EXPR as needed. */
6795 if (domain_type && TYPE_MIN_VALUE (domain_type))
6796 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
6798 /* Otherwise, return a zero of the appropriate type. */
6799 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp, 1)), 0);
6802 /* Returns true if REF is an array reference to an array at the end of
6803 a structure. If this is the case, the array may be allocated larger
6804 than its upper bound implies. */
6806 bool
6807 array_at_struct_end_p (tree ref)
6809 if (TREE_CODE (ref) != ARRAY_REF
6810 && TREE_CODE (ref) != ARRAY_RANGE_REF)
6811 return false;
6813 while (handled_component_p (ref))
6815 /* If the reference chain contains a component reference to a
6816 non-union type and there follows another field the reference
6817 is not at the end of a structure. */
6818 if (TREE_CODE (ref) == COMPONENT_REF
6819 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
6821 tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
6822 while (nextf && TREE_CODE (nextf) != FIELD_DECL)
6823 nextf = DECL_CHAIN (nextf);
6824 if (nextf)
6825 return false;
6828 ref = TREE_OPERAND (ref, 0);
6831 /* If the reference is based on a declared entity, the size of the array
6832 is constrained by its given domain. */
6833 if (DECL_P (ref))
6834 return false;
6836 return true;
6839 /* Return a tree representing the upper bound of the array mentioned in
6840 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6842 tree
6843 array_ref_up_bound (tree exp)
6845 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
6847 /* If there is a domain type and it has an upper bound, use it, substituting
6848 for a PLACEHOLDER_EXPR as needed. */
6849 if (domain_type && TYPE_MAX_VALUE (domain_type))
6850 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
6852 /* Otherwise fail. */
6853 return NULL_TREE;
6856 /* Return a tree representing the offset, in bytes, of the field referenced
6857 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6859 tree
6860 component_ref_field_offset (tree exp)
6862 tree aligned_offset = TREE_OPERAND (exp, 2);
6863 tree field = TREE_OPERAND (exp, 1);
6864 location_t loc = EXPR_LOCATION (exp);
6866 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6867 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6868 value. */
6869 if (aligned_offset)
6871 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6872 sizetype from another type of the same width and signedness. */
6873 if (TREE_TYPE (aligned_offset) != sizetype)
6874 aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
6875 return size_binop_loc (loc, MULT_EXPR, aligned_offset,
6876 size_int (DECL_OFFSET_ALIGN (field)
6877 / BITS_PER_UNIT));
6880 /* Otherwise, take the offset from that of the field. Substitute
6881 any PLACEHOLDER_EXPR that we have. */
6882 else
6883 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
6886 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6888 static unsigned HOST_WIDE_INT
6889 target_align (const_tree target)
6891 /* We might have a chain of nested references with intermediate misaligning
6892 bitfields components, so need to recurse to find out. */
6894 unsigned HOST_WIDE_INT this_align, outer_align;
6896 switch (TREE_CODE (target))
6898 case BIT_FIELD_REF:
6899 return 1;
6901 case COMPONENT_REF:
6902 this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
6903 outer_align = target_align (TREE_OPERAND (target, 0));
6904 return MIN (this_align, outer_align);
6906 case ARRAY_REF:
6907 case ARRAY_RANGE_REF:
6908 this_align = TYPE_ALIGN (TREE_TYPE (target));
6909 outer_align = target_align (TREE_OPERAND (target, 0));
6910 return MIN (this_align, outer_align);
6912 CASE_CONVERT:
6913 case NON_LVALUE_EXPR:
6914 case VIEW_CONVERT_EXPR:
6915 this_align = TYPE_ALIGN (TREE_TYPE (target));
6916 outer_align = target_align (TREE_OPERAND (target, 0));
6917 return MAX (this_align, outer_align);
6919 default:
6920 return TYPE_ALIGN (TREE_TYPE (target));
6925 /* Given an rtx VALUE that may contain additions and multiplications, return
6926 an equivalent value that just refers to a register, memory, or constant.
6927 This is done by generating instructions to perform the arithmetic and
6928 returning a pseudo-register containing the value.
6930 The returned value may be a REG, SUBREG, MEM or constant. */
6933 force_operand (rtx value, rtx target)
6935 rtx op1, op2;
6936 /* Use subtarget as the target for operand 0 of a binary operation. */
6937 rtx subtarget = get_subtarget (target);
6938 enum rtx_code code = GET_CODE (value);
6940 /* Check for subreg applied to an expression produced by loop optimizer. */
6941 if (code == SUBREG
6942 && !REG_P (SUBREG_REG (value))
6943 && !MEM_P (SUBREG_REG (value)))
6945 value
6946 = simplify_gen_subreg (GET_MODE (value),
6947 force_reg (GET_MODE (SUBREG_REG (value)),
6948 force_operand (SUBREG_REG (value),
6949 NULL_RTX)),
6950 GET_MODE (SUBREG_REG (value)),
6951 SUBREG_BYTE (value));
6952 code = GET_CODE (value);
6955 /* Check for a PIC address load. */
6956 if ((code == PLUS || code == MINUS)
6957 && XEXP (value, 0) == pic_offset_table_rtx
6958 && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
6959 || GET_CODE (XEXP (value, 1)) == LABEL_REF
6960 || GET_CODE (XEXP (value, 1)) == CONST))
6962 if (!subtarget)
6963 subtarget = gen_reg_rtx (GET_MODE (value));
6964 emit_move_insn (subtarget, value);
6965 return subtarget;
6968 if (ARITHMETIC_P (value))
6970 op2 = XEXP (value, 1);
6971 if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
6972 subtarget = 0;
6973 if (code == MINUS && CONST_INT_P (op2))
6975 code = PLUS;
6976 op2 = negate_rtx (GET_MODE (value), op2);
6979 /* Check for an addition with OP2 a constant integer and our first
6980 operand a PLUS of a virtual register and something else. In that
6981 case, we want to emit the sum of the virtual register and the
6982 constant first and then add the other value. This allows virtual
6983 register instantiation to simply modify the constant rather than
6984 creating another one around this addition. */
6985 if (code == PLUS && CONST_INT_P (op2)
6986 && GET_CODE (XEXP (value, 0)) == PLUS
6987 && REG_P (XEXP (XEXP (value, 0), 0))
6988 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
6989 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
6991 rtx temp = expand_simple_binop (GET_MODE (value), code,
6992 XEXP (XEXP (value, 0), 0), op2,
6993 subtarget, 0, OPTAB_LIB_WIDEN);
6994 return expand_simple_binop (GET_MODE (value), code, temp,
6995 force_operand (XEXP (XEXP (value,
6996 0), 1), 0),
6997 target, 0, OPTAB_LIB_WIDEN);
7000 op1 = force_operand (XEXP (value, 0), subtarget);
7001 op2 = force_operand (op2, NULL_RTX);
7002 switch (code)
7004 case MULT:
7005 return expand_mult (GET_MODE (value), op1, op2, target, 1);
7006 case DIV:
7007 if (!INTEGRAL_MODE_P (GET_MODE (value)))
7008 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7009 target, 1, OPTAB_LIB_WIDEN);
7010 else
7011 return expand_divmod (0,
7012 FLOAT_MODE_P (GET_MODE (value))
7013 ? RDIV_EXPR : TRUNC_DIV_EXPR,
7014 GET_MODE (value), op1, op2, target, 0);
7015 case MOD:
7016 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7017 target, 0);
7018 case UDIV:
7019 return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
7020 target, 1);
7021 case UMOD:
7022 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7023 target, 1);
7024 case ASHIFTRT:
7025 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7026 target, 0, OPTAB_LIB_WIDEN);
7027 default:
7028 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7029 target, 1, OPTAB_LIB_WIDEN);
7032 if (UNARY_P (value))
7034 if (!target)
7035 target = gen_reg_rtx (GET_MODE (value));
7036 op1 = force_operand (XEXP (value, 0), NULL_RTX);
7037 switch (code)
7039 case ZERO_EXTEND:
7040 case SIGN_EXTEND:
7041 case TRUNCATE:
7042 case FLOAT_EXTEND:
7043 case FLOAT_TRUNCATE:
7044 convert_move (target, op1, code == ZERO_EXTEND);
7045 return target;
7047 case FIX:
7048 case UNSIGNED_FIX:
7049 expand_fix (target, op1, code == UNSIGNED_FIX);
7050 return target;
7052 case FLOAT:
7053 case UNSIGNED_FLOAT:
7054 expand_float (target, op1, code == UNSIGNED_FLOAT);
7055 return target;
7057 default:
7058 return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
7062 #ifdef INSN_SCHEDULING
7063 /* On machines that have insn scheduling, we want all memory reference to be
7064 explicit, so we need to deal with such paradoxical SUBREGs. */
7065 if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
7066 value
7067 = simplify_gen_subreg (GET_MODE (value),
7068 force_reg (GET_MODE (SUBREG_REG (value)),
7069 force_operand (SUBREG_REG (value),
7070 NULL_RTX)),
7071 GET_MODE (SUBREG_REG (value)),
7072 SUBREG_BYTE (value));
7073 #endif
7075 return value;
7078 /* Subroutine of expand_expr: return nonzero iff there is no way that
7079 EXP can reference X, which is being modified. TOP_P is nonzero if this
7080 call is going to be used to determine whether we need a temporary
7081 for EXP, as opposed to a recursive call to this function.
7083 It is always safe for this routine to return zero since it merely
7084 searches for optimization opportunities. */
7087 safe_from_p (const_rtx x, tree exp, int top_p)
7089 rtx exp_rtl = 0;
7090 int i, nops;
7092 if (x == 0
7093 /* If EXP has varying size, we MUST use a target since we currently
7094 have no way of allocating temporaries of variable size
7095 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7096 So we assume here that something at a higher level has prevented a
7097 clash. This is somewhat bogus, but the best we can do. Only
7098 do this when X is BLKmode and when we are at the top level. */
7099 || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
7100 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
7101 && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
7102 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
7103 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
7104 != INTEGER_CST)
7105 && GET_MODE (x) == BLKmode)
7106 /* If X is in the outgoing argument area, it is always safe. */
7107 || (MEM_P (x)
7108 && (XEXP (x, 0) == virtual_outgoing_args_rtx
7109 || (GET_CODE (XEXP (x, 0)) == PLUS
7110 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
7111 return 1;
7113 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7114 find the underlying pseudo. */
7115 if (GET_CODE (x) == SUBREG)
7117 x = SUBREG_REG (x);
7118 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7119 return 0;
7122 /* Now look at our tree code and possibly recurse. */
7123 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
7125 case tcc_declaration:
7126 exp_rtl = DECL_RTL_IF_SET (exp);
7127 break;
7129 case tcc_constant:
7130 return 1;
7132 case tcc_exceptional:
7133 if (TREE_CODE (exp) == TREE_LIST)
7135 while (1)
7137 if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
7138 return 0;
7139 exp = TREE_CHAIN (exp);
7140 if (!exp)
7141 return 1;
7142 if (TREE_CODE (exp) != TREE_LIST)
7143 return safe_from_p (x, exp, 0);
7146 else if (TREE_CODE (exp) == CONSTRUCTOR)
7148 constructor_elt *ce;
7149 unsigned HOST_WIDE_INT idx;
7151 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
7152 if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
7153 || !safe_from_p (x, ce->value, 0))
7154 return 0;
7155 return 1;
7157 else if (TREE_CODE (exp) == ERROR_MARK)
7158 return 1; /* An already-visited SAVE_EXPR? */
7159 else
7160 return 0;
7162 case tcc_statement:
7163 /* The only case we look at here is the DECL_INITIAL inside a
7164 DECL_EXPR. */
7165 return (TREE_CODE (exp) != DECL_EXPR
7166 || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
7167 || !DECL_INITIAL (DECL_EXPR_DECL (exp))
7168 || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
7170 case tcc_binary:
7171 case tcc_comparison:
7172 if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
7173 return 0;
7174 /* Fall through. */
7176 case tcc_unary:
7177 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7179 case tcc_expression:
7180 case tcc_reference:
7181 case tcc_vl_exp:
7182 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7183 the expression. If it is set, we conflict iff we are that rtx or
7184 both are in memory. Otherwise, we check all operands of the
7185 expression recursively. */
7187 switch (TREE_CODE (exp))
7189 case ADDR_EXPR:
7190 /* If the operand is static or we are static, we can't conflict.
7191 Likewise if we don't conflict with the operand at all. */
7192 if (staticp (TREE_OPERAND (exp, 0))
7193 || TREE_STATIC (exp)
7194 || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
7195 return 1;
7197 /* Otherwise, the only way this can conflict is if we are taking
7198 the address of a DECL a that address if part of X, which is
7199 very rare. */
7200 exp = TREE_OPERAND (exp, 0);
7201 if (DECL_P (exp))
7203 if (!DECL_RTL_SET_P (exp)
7204 || !MEM_P (DECL_RTL (exp)))
7205 return 0;
7206 else
7207 exp_rtl = XEXP (DECL_RTL (exp), 0);
7209 break;
7211 case MEM_REF:
7212 if (MEM_P (x)
7213 && alias_sets_conflict_p (MEM_ALIAS_SET (x),
7214 get_alias_set (exp)))
7215 return 0;
7216 break;
7218 case CALL_EXPR:
7219 /* Assume that the call will clobber all hard registers and
7220 all of memory. */
7221 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7222 || MEM_P (x))
7223 return 0;
7224 break;
7226 case WITH_CLEANUP_EXPR:
7227 case CLEANUP_POINT_EXPR:
7228 /* Lowered by gimplify.c. */
7229 gcc_unreachable ();
7231 case SAVE_EXPR:
7232 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7234 default:
7235 break;
7238 /* If we have an rtx, we do not need to scan our operands. */
7239 if (exp_rtl)
7240 break;
7242 nops = TREE_OPERAND_LENGTH (exp);
7243 for (i = 0; i < nops; i++)
7244 if (TREE_OPERAND (exp, i) != 0
7245 && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
7246 return 0;
7248 break;
7250 case tcc_type:
7251 /* Should never get a type here. */
7252 gcc_unreachable ();
7255 /* If we have an rtl, find any enclosed object. Then see if we conflict
7256 with it. */
7257 if (exp_rtl)
7259 if (GET_CODE (exp_rtl) == SUBREG)
7261 exp_rtl = SUBREG_REG (exp_rtl);
7262 if (REG_P (exp_rtl)
7263 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
7264 return 0;
7267 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7268 are memory and they conflict. */
7269 return ! (rtx_equal_p (x, exp_rtl)
7270 || (MEM_P (x) && MEM_P (exp_rtl)
7271 && true_dependence (exp_rtl, VOIDmode, x)));
7274 /* If we reach here, it is safe. */
7275 return 1;
7279 /* Return the highest power of two that EXP is known to be a multiple of.
7280 This is used in updating alignment of MEMs in array references. */
7282 unsigned HOST_WIDE_INT
7283 highest_pow2_factor (const_tree exp)
7285 unsigned HOST_WIDE_INT c0, c1;
7287 switch (TREE_CODE (exp))
7289 case INTEGER_CST:
7290 /* We can find the lowest bit that's a one. If the low
7291 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
7292 We need to handle this case since we can find it in a COND_EXPR,
7293 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
7294 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
7295 later ICE. */
7296 if (TREE_OVERFLOW (exp))
7297 return BIGGEST_ALIGNMENT;
7298 else
7300 /* Note: tree_low_cst is intentionally not used here,
7301 we don't care about the upper bits. */
7302 c0 = TREE_INT_CST_LOW (exp);
7303 c0 &= -c0;
7304 return c0 ? c0 : BIGGEST_ALIGNMENT;
7306 break;
7308 case PLUS_EXPR: case MINUS_EXPR: case MIN_EXPR: case MAX_EXPR:
7309 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7310 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7311 return MIN (c0, c1);
7313 case MULT_EXPR:
7314 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7315 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7316 return c0 * c1;
7318 case ROUND_DIV_EXPR: case TRUNC_DIV_EXPR: case FLOOR_DIV_EXPR:
7319 case CEIL_DIV_EXPR:
7320 if (integer_pow2p (TREE_OPERAND (exp, 1))
7321 && host_integerp (TREE_OPERAND (exp, 1), 1))
7323 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7324 c1 = tree_low_cst (TREE_OPERAND (exp, 1), 1);
7325 return MAX (1, c0 / c1);
7327 break;
7329 case BIT_AND_EXPR:
7330 /* The highest power of two of a bit-and expression is the maximum of
7331 that of its operands. We typically get here for a complex LHS and
7332 a constant negative power of two on the RHS to force an explicit
7333 alignment, so don't bother looking at the LHS. */
7334 return highest_pow2_factor (TREE_OPERAND (exp, 1));
7336 CASE_CONVERT:
7337 case SAVE_EXPR:
7338 return highest_pow2_factor (TREE_OPERAND (exp, 0));
7340 case COMPOUND_EXPR:
7341 return highest_pow2_factor (TREE_OPERAND (exp, 1));
7343 case COND_EXPR:
7344 c0 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7345 c1 = highest_pow2_factor (TREE_OPERAND (exp, 2));
7346 return MIN (c0, c1);
7348 default:
7349 break;
7352 return 1;
7355 /* Similar, except that the alignment requirements of TARGET are
7356 taken into account. Assume it is at least as aligned as its
7357 type, unless it is a COMPONENT_REF in which case the layout of
7358 the structure gives the alignment. */
7360 static unsigned HOST_WIDE_INT
7361 highest_pow2_factor_for_target (const_tree target, const_tree exp)
7363 unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
7364 unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
7366 return MAX (factor, talign);
7369 #ifdef HAVE_conditional_move
7370 /* Convert the tree comparison code TCODE to the rtl one where the
7371 signedness is UNSIGNEDP. */
7373 static enum rtx_code
7374 convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
7376 enum rtx_code code;
7377 switch (tcode)
7379 case EQ_EXPR:
7380 code = EQ;
7381 break;
7382 case NE_EXPR:
7383 code = NE;
7384 break;
7385 case LT_EXPR:
7386 code = unsignedp ? LTU : LT;
7387 break;
7388 case LE_EXPR:
7389 code = unsignedp ? LEU : LE;
7390 break;
7391 case GT_EXPR:
7392 code = unsignedp ? GTU : GT;
7393 break;
7394 case GE_EXPR:
7395 code = unsignedp ? GEU : GE;
7396 break;
7397 case UNORDERED_EXPR:
7398 code = UNORDERED;
7399 break;
7400 case ORDERED_EXPR:
7401 code = ORDERED;
7402 break;
7403 case UNLT_EXPR:
7404 code = UNLT;
7405 break;
7406 case UNLE_EXPR:
7407 code = UNLE;
7408 break;
7409 case UNGT_EXPR:
7410 code = UNGT;
7411 break;
7412 case UNGE_EXPR:
7413 code = UNGE;
7414 break;
7415 case UNEQ_EXPR:
7416 code = UNEQ;
7417 break;
7418 case LTGT_EXPR:
7419 code = LTGT;
7420 break;
7422 default:
7423 gcc_unreachable ();
7425 return code;
7427 #endif
7429 /* Subroutine of expand_expr. Expand the two operands of a binary
7430 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7431 The value may be stored in TARGET if TARGET is nonzero. The
7432 MODIFIER argument is as documented by expand_expr. */
7434 static void
7435 expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
7436 enum expand_modifier modifier)
7438 if (! safe_from_p (target, exp1, 1))
7439 target = 0;
7440 if (operand_equal_p (exp0, exp1, 0))
7442 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7443 *op1 = copy_rtx (*op0);
7445 else
7447 /* If we need to preserve evaluation order, copy exp0 into its own
7448 temporary variable so that it can't be clobbered by exp1. */
7449 if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
7450 exp0 = save_expr (exp0);
7451 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7452 *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
7457 /* Return a MEM that contains constant EXP. DEFER is as for
7458 output_constant_def and MODIFIER is as for expand_expr. */
7460 static rtx
7461 expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
7463 rtx mem;
7465 mem = output_constant_def (exp, defer);
7466 if (modifier != EXPAND_INITIALIZER)
7467 mem = use_anchored_address (mem);
7468 return mem;
7471 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7472 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7474 static rtx
7475 expand_expr_addr_expr_1 (tree exp, rtx target, enum machine_mode tmode,
7476 enum expand_modifier modifier, addr_space_t as)
7478 rtx result, subtarget;
7479 tree inner, offset;
7480 HOST_WIDE_INT bitsize, bitpos;
7481 int volatilep, unsignedp;
7482 enum machine_mode mode1;
7484 /* If we are taking the address of a constant and are at the top level,
7485 we have to use output_constant_def since we can't call force_const_mem
7486 at top level. */
7487 /* ??? This should be considered a front-end bug. We should not be
7488 generating ADDR_EXPR of something that isn't an LVALUE. The only
7489 exception here is STRING_CST. */
7490 if (CONSTANT_CLASS_P (exp))
7492 result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
7493 if (modifier < EXPAND_SUM)
7494 result = force_operand (result, target);
7495 return result;
7498 /* Everything must be something allowed by is_gimple_addressable. */
7499 switch (TREE_CODE (exp))
7501 case INDIRECT_REF:
7502 /* This case will happen via recursion for &a->b. */
7503 return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7505 case MEM_REF:
7507 tree tem = TREE_OPERAND (exp, 0);
7508 if (!integer_zerop (TREE_OPERAND (exp, 1)))
7509 tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
7510 return expand_expr (tem, target, tmode, modifier);
7513 case CONST_DECL:
7514 /* Expand the initializer like constants above. */
7515 result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
7516 0, modifier), 0);
7517 if (modifier < EXPAND_SUM)
7518 result = force_operand (result, target);
7519 return result;
7521 case REALPART_EXPR:
7522 /* The real part of the complex number is always first, therefore
7523 the address is the same as the address of the parent object. */
7524 offset = 0;
7525 bitpos = 0;
7526 inner = TREE_OPERAND (exp, 0);
7527 break;
7529 case IMAGPART_EXPR:
7530 /* The imaginary part of the complex number is always second.
7531 The expression is therefore always offset by the size of the
7532 scalar type. */
7533 offset = 0;
7534 bitpos = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)));
7535 inner = TREE_OPERAND (exp, 0);
7536 break;
7538 case COMPOUND_LITERAL_EXPR:
7539 /* Allow COMPOUND_LITERAL_EXPR in initializers, if e.g.
7540 rtl_for_decl_init is called on DECL_INITIAL with
7541 COMPOUNT_LITERAL_EXPRs in it, they aren't gimplified. */
7542 if (modifier == EXPAND_INITIALIZER
7543 && COMPOUND_LITERAL_EXPR_DECL (exp))
7544 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
7545 target, tmode, modifier, as);
7546 /* FALLTHRU */
7547 default:
7548 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7549 expand_expr, as that can have various side effects; LABEL_DECLs for
7550 example, may not have their DECL_RTL set yet. Expand the rtl of
7551 CONSTRUCTORs too, which should yield a memory reference for the
7552 constructor's contents. Assume language specific tree nodes can
7553 be expanded in some interesting way. */
7554 gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
7555 if (DECL_P (exp)
7556 || TREE_CODE (exp) == CONSTRUCTOR
7557 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
7559 result = expand_expr (exp, target, tmode,
7560 modifier == EXPAND_INITIALIZER
7561 ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
7563 /* If the DECL isn't in memory, then the DECL wasn't properly
7564 marked TREE_ADDRESSABLE, which will be either a front-end
7565 or a tree optimizer bug. */
7567 if (TREE_ADDRESSABLE (exp)
7568 && ! MEM_P (result)
7569 && ! targetm.calls.allocate_stack_slots_for_args ())
7571 error ("local frame unavailable (naked function?)");
7572 return result;
7574 else
7575 gcc_assert (MEM_P (result));
7576 result = XEXP (result, 0);
7578 /* ??? Is this needed anymore? */
7579 if (DECL_P (exp))
7580 TREE_USED (exp) = 1;
7582 if (modifier != EXPAND_INITIALIZER
7583 && modifier != EXPAND_CONST_ADDRESS
7584 && modifier != EXPAND_SUM)
7585 result = force_operand (result, target);
7586 return result;
7589 /* Pass FALSE as the last argument to get_inner_reference although
7590 we are expanding to RTL. The rationale is that we know how to
7591 handle "aligning nodes" here: we can just bypass them because
7592 they won't change the final object whose address will be returned
7593 (they actually exist only for that purpose). */
7594 inner = get_inner_reference (exp, &bitsize, &bitpos, &offset,
7595 &mode1, &unsignedp, &volatilep, false);
7596 break;
7599 /* We must have made progress. */
7600 gcc_assert (inner != exp);
7602 subtarget = offset || bitpos ? NULL_RTX : target;
7603 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7604 inner alignment, force the inner to be sufficiently aligned. */
7605 if (CONSTANT_CLASS_P (inner)
7606 && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
7608 inner = copy_node (inner);
7609 TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
7610 TYPE_ALIGN (TREE_TYPE (inner)) = TYPE_ALIGN (TREE_TYPE (exp));
7611 TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
7613 result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
7615 if (offset)
7617 rtx tmp;
7619 if (modifier != EXPAND_NORMAL)
7620 result = force_operand (result, NULL);
7621 tmp = expand_expr (offset, NULL_RTX, tmode,
7622 modifier == EXPAND_INITIALIZER
7623 ? EXPAND_INITIALIZER : EXPAND_NORMAL);
7625 result = convert_memory_address_addr_space (tmode, result, as);
7626 tmp = convert_memory_address_addr_space (tmode, tmp, as);
7628 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7629 result = simplify_gen_binary (PLUS, tmode, result, tmp);
7630 else
7632 subtarget = bitpos ? NULL_RTX : target;
7633 result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
7634 1, OPTAB_LIB_WIDEN);
7638 if (bitpos)
7640 /* Someone beforehand should have rejected taking the address
7641 of such an object. */
7642 gcc_assert ((bitpos % BITS_PER_UNIT) == 0);
7644 result = convert_memory_address_addr_space (tmode, result, as);
7645 result = plus_constant (tmode, result, bitpos / BITS_PER_UNIT);
7646 if (modifier < EXPAND_SUM)
7647 result = force_operand (result, target);
7650 return result;
7653 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7654 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7656 static rtx
7657 expand_expr_addr_expr (tree exp, rtx target, enum machine_mode tmode,
7658 enum expand_modifier modifier)
7660 addr_space_t as = ADDR_SPACE_GENERIC;
7661 enum machine_mode address_mode = Pmode;
7662 enum machine_mode pointer_mode = ptr_mode;
7663 enum machine_mode rmode;
7664 rtx result;
7666 /* Target mode of VOIDmode says "whatever's natural". */
7667 if (tmode == VOIDmode)
7668 tmode = TYPE_MODE (TREE_TYPE (exp));
7670 if (POINTER_TYPE_P (TREE_TYPE (exp)))
7672 as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
7673 address_mode = targetm.addr_space.address_mode (as);
7674 pointer_mode = targetm.addr_space.pointer_mode (as);
7677 /* We can get called with some Weird Things if the user does silliness
7678 like "(short) &a". In that case, convert_memory_address won't do
7679 the right thing, so ignore the given target mode. */
7680 if (tmode != address_mode && tmode != pointer_mode)
7681 tmode = address_mode;
7683 result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
7684 tmode, modifier, as);
7686 /* Despite expand_expr claims concerning ignoring TMODE when not
7687 strictly convenient, stuff breaks if we don't honor it. Note
7688 that combined with the above, we only do this for pointer modes. */
7689 rmode = GET_MODE (result);
7690 if (rmode == VOIDmode)
7691 rmode = tmode;
7692 if (rmode != tmode)
7693 result = convert_memory_address_addr_space (tmode, result, as);
7695 return result;
7698 /* Generate code for computing CONSTRUCTOR EXP.
7699 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7700 is TRUE, instead of creating a temporary variable in memory
7701 NULL is returned and the caller needs to handle it differently. */
7703 static rtx
7704 expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
7705 bool avoid_temp_mem)
7707 tree type = TREE_TYPE (exp);
7708 enum machine_mode mode = TYPE_MODE (type);
7710 /* Try to avoid creating a temporary at all. This is possible
7711 if all of the initializer is zero.
7712 FIXME: try to handle all [0..255] initializers we can handle
7713 with memset. */
7714 if (TREE_STATIC (exp)
7715 && !TREE_ADDRESSABLE (exp)
7716 && target != 0 && mode == BLKmode
7717 && all_zeros_p (exp))
7719 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7720 return target;
7723 /* All elts simple constants => refer to a constant in memory. But
7724 if this is a non-BLKmode mode, let it store a field at a time
7725 since that should make a CONST_INT or CONST_DOUBLE when we
7726 fold. Likewise, if we have a target we can use, it is best to
7727 store directly into the target unless the type is large enough
7728 that memcpy will be used. If we are making an initializer and
7729 all operands are constant, put it in memory as well.
7731 FIXME: Avoid trying to fill vector constructors piece-meal.
7732 Output them with output_constant_def below unless we're sure
7733 they're zeros. This should go away when vector initializers
7734 are treated like VECTOR_CST instead of arrays. */
7735 if ((TREE_STATIC (exp)
7736 && ((mode == BLKmode
7737 && ! (target != 0 && safe_from_p (target, exp, 1)))
7738 || TREE_ADDRESSABLE (exp)
7739 || (host_integerp (TYPE_SIZE_UNIT (type), 1)
7740 && (! MOVE_BY_PIECES_P
7741 (tree_low_cst (TYPE_SIZE_UNIT (type), 1),
7742 TYPE_ALIGN (type)))
7743 && ! mostly_zeros_p (exp))))
7744 || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
7745 && TREE_CONSTANT (exp)))
7747 rtx constructor;
7749 if (avoid_temp_mem)
7750 return NULL_RTX;
7752 constructor = expand_expr_constant (exp, 1, modifier);
7754 if (modifier != EXPAND_CONST_ADDRESS
7755 && modifier != EXPAND_INITIALIZER
7756 && modifier != EXPAND_SUM)
7757 constructor = validize_mem (constructor);
7759 return constructor;
7762 /* Handle calls that pass values in multiple non-contiguous
7763 locations. The Irix 6 ABI has examples of this. */
7764 if (target == 0 || ! safe_from_p (target, exp, 1)
7765 || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM)
7767 if (avoid_temp_mem)
7768 return NULL_RTX;
7770 target
7771 = assign_temp (build_qualified_type (type, (TYPE_QUALS (type)
7772 | (TREE_READONLY (exp)
7773 * TYPE_QUAL_CONST))),
7774 TREE_ADDRESSABLE (exp), 1);
7777 store_constructor (exp, target, 0, int_expr_size (exp));
7778 return target;
7782 /* expand_expr: generate code for computing expression EXP.
7783 An rtx for the computed value is returned. The value is never null.
7784 In the case of a void EXP, const0_rtx is returned.
7786 The value may be stored in TARGET if TARGET is nonzero.
7787 TARGET is just a suggestion; callers must assume that
7788 the rtx returned may not be the same as TARGET.
7790 If TARGET is CONST0_RTX, it means that the value will be ignored.
7792 If TMODE is not VOIDmode, it suggests generating the
7793 result in mode TMODE. But this is done only when convenient.
7794 Otherwise, TMODE is ignored and the value generated in its natural mode.
7795 TMODE is just a suggestion; callers must assume that
7796 the rtx returned may not have mode TMODE.
7798 Note that TARGET may have neither TMODE nor MODE. In that case, it
7799 probably will not be used.
7801 If MODIFIER is EXPAND_SUM then when EXP is an addition
7802 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7803 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7804 products as above, or REG or MEM, or constant.
7805 Ordinarily in such cases we would output mul or add instructions
7806 and then return a pseudo reg containing the sum.
7808 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7809 it also marks a label as absolutely required (it can't be dead).
7810 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7811 This is used for outputting expressions used in initializers.
7813 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7814 with a constant address even if that address is not normally legitimate.
7815 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7817 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7818 a call parameter. Such targets require special care as we haven't yet
7819 marked TARGET so that it's safe from being trashed by libcalls. We
7820 don't want to use TARGET for anything but the final result;
7821 Intermediate values must go elsewhere. Additionally, calls to
7822 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7824 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7825 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7826 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7827 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7828 recursively. */
7831 expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
7832 enum expand_modifier modifier, rtx *alt_rtl)
7834 rtx ret;
7836 /* Handle ERROR_MARK before anybody tries to access its type. */
7837 if (TREE_CODE (exp) == ERROR_MARK
7838 || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
7840 ret = CONST0_RTX (tmode);
7841 return ret ? ret : const0_rtx;
7844 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
7845 return ret;
7848 /* Try to expand the conditional expression which is represented by
7849 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7850 return the rtl reg which repsents the result. Otherwise return
7851 NULL_RTL. */
7853 static rtx
7854 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
7855 tree treeop1 ATTRIBUTE_UNUSED,
7856 tree treeop2 ATTRIBUTE_UNUSED)
7858 #ifdef HAVE_conditional_move
7859 rtx insn;
7860 rtx op00, op01, op1, op2;
7861 enum rtx_code comparison_code;
7862 enum machine_mode comparison_mode;
7863 gimple srcstmt;
7864 rtx temp;
7865 tree type = TREE_TYPE (treeop1);
7866 int unsignedp = TYPE_UNSIGNED (type);
7867 enum machine_mode mode = TYPE_MODE (type);
7868 enum machine_mode orig_mode = mode;
7870 /* If we cannot do a conditional move on the mode, try doing it
7871 with the promoted mode. */
7872 if (!can_conditionally_move_p (mode))
7874 mode = promote_mode (type, mode, &unsignedp);
7875 if (!can_conditionally_move_p (mode))
7876 return NULL_RTX;
7877 temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */
7879 else
7880 temp = assign_temp (type, 0, 1);
7882 start_sequence ();
7883 expand_operands (treeop1, treeop2,
7884 temp, &op1, &op2, EXPAND_NORMAL);
7886 if (TREE_CODE (treeop0) == SSA_NAME
7887 && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison)))
7889 tree type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
7890 enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
7891 op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
7892 op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
7893 comparison_mode = TYPE_MODE (type);
7894 unsignedp = TYPE_UNSIGNED (type);
7895 comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
7897 else if (TREE_CODE_CLASS (TREE_CODE (treeop0)) == tcc_comparison)
7899 tree type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
7900 enum tree_code cmpcode = TREE_CODE (treeop0);
7901 op00 = expand_normal (TREE_OPERAND (treeop0, 0));
7902 op01 = expand_normal (TREE_OPERAND (treeop0, 1));
7903 unsignedp = TYPE_UNSIGNED (type);
7904 comparison_mode = TYPE_MODE (type);
7905 comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
7907 else
7909 op00 = expand_normal (treeop0);
7910 op01 = const0_rtx;
7911 comparison_code = NE;
7912 comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
7915 if (GET_MODE (op1) != mode)
7916 op1 = gen_lowpart (mode, op1);
7918 if (GET_MODE (op2) != mode)
7919 op2 = gen_lowpart (mode, op2);
7921 /* Try to emit the conditional move. */
7922 insn = emit_conditional_move (temp, comparison_code,
7923 op00, op01, comparison_mode,
7924 op1, op2, mode,
7925 unsignedp);
7927 /* If we could do the conditional move, emit the sequence,
7928 and return. */
7929 if (insn)
7931 rtx seq = get_insns ();
7932 end_sequence ();
7933 emit_insn (seq);
7934 return convert_modes (orig_mode, mode, temp, 0);
7937 /* Otherwise discard the sequence and fall back to code with
7938 branches. */
7939 end_sequence ();
7940 #endif
7941 return NULL_RTX;
7945 expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
7946 enum expand_modifier modifier)
7948 rtx op0, op1, op2, temp;
7949 tree type;
7950 int unsignedp;
7951 enum machine_mode mode;
7952 enum tree_code code = ops->code;
7953 optab this_optab;
7954 rtx subtarget, original_target;
7955 int ignore;
7956 bool reduce_bit_field;
7957 location_t loc = ops->location;
7958 tree treeop0, treeop1, treeop2;
7959 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
7960 ? reduce_to_bit_field_precision ((expr), \
7961 target, \
7962 type) \
7963 : (expr))
7965 type = ops->type;
7966 mode = TYPE_MODE (type);
7967 unsignedp = TYPE_UNSIGNED (type);
7969 treeop0 = ops->op0;
7970 treeop1 = ops->op1;
7971 treeop2 = ops->op2;
7973 /* We should be called only on simple (binary or unary) expressions,
7974 exactly those that are valid in gimple expressions that aren't
7975 GIMPLE_SINGLE_RHS (or invalid). */
7976 gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
7977 || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
7978 || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
7980 ignore = (target == const0_rtx
7981 || ((CONVERT_EXPR_CODE_P (code)
7982 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
7983 && TREE_CODE (type) == VOID_TYPE));
7985 /* We should be called only if we need the result. */
7986 gcc_assert (!ignore);
7988 /* An operation in what may be a bit-field type needs the
7989 result to be reduced to the precision of the bit-field type,
7990 which is narrower than that of the type's mode. */
7991 reduce_bit_field = (INTEGRAL_TYPE_P (type)
7992 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
7994 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
7995 target = 0;
7997 /* Use subtarget as the target for operand 0 of a binary operation. */
7998 subtarget = get_subtarget (target);
7999 original_target = target;
8001 switch (code)
8003 case NON_LVALUE_EXPR:
8004 case PAREN_EXPR:
8005 CASE_CONVERT:
8006 if (treeop0 == error_mark_node)
8007 return const0_rtx;
8009 if (TREE_CODE (type) == UNION_TYPE)
8011 tree valtype = TREE_TYPE (treeop0);
8013 /* If both input and output are BLKmode, this conversion isn't doing
8014 anything except possibly changing memory attribute. */
8015 if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
8017 rtx result = expand_expr (treeop0, target, tmode,
8018 modifier);
8020 result = copy_rtx (result);
8021 set_mem_attributes (result, type, 0);
8022 return result;
8025 if (target == 0)
8027 if (TYPE_MODE (type) != BLKmode)
8028 target = gen_reg_rtx (TYPE_MODE (type));
8029 else
8030 target = assign_temp (type, 1, 1);
8033 if (MEM_P (target))
8034 /* Store data into beginning of memory target. */
8035 store_expr (treeop0,
8036 adjust_address (target, TYPE_MODE (valtype), 0),
8037 modifier == EXPAND_STACK_PARM,
8038 false);
8040 else
8042 gcc_assert (REG_P (target));
8044 /* Store this field into a union of the proper type. */
8045 store_field (target,
8046 MIN ((int_size_in_bytes (TREE_TYPE
8047 (treeop0))
8048 * BITS_PER_UNIT),
8049 (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
8050 0, 0, 0, TYPE_MODE (valtype), treeop0, 0, false);
8053 /* Return the entire union. */
8054 return target;
8057 if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
8059 op0 = expand_expr (treeop0, target, VOIDmode,
8060 modifier);
8062 /* If the signedness of the conversion differs and OP0 is
8063 a promoted SUBREG, clear that indication since we now
8064 have to do the proper extension. */
8065 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)) != unsignedp
8066 && GET_CODE (op0) == SUBREG)
8067 SUBREG_PROMOTED_VAR_P (op0) = 0;
8069 return REDUCE_BIT_FIELD (op0);
8072 op0 = expand_expr (treeop0, NULL_RTX, mode,
8073 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
8074 if (GET_MODE (op0) == mode)
8077 /* If OP0 is a constant, just convert it into the proper mode. */
8078 else if (CONSTANT_P (op0))
8080 tree inner_type = TREE_TYPE (treeop0);
8081 enum machine_mode inner_mode = GET_MODE (op0);
8083 if (inner_mode == VOIDmode)
8084 inner_mode = TYPE_MODE (inner_type);
8086 if (modifier == EXPAND_INITIALIZER)
8087 op0 = simplify_gen_subreg (mode, op0, inner_mode,
8088 subreg_lowpart_offset (mode,
8089 inner_mode));
8090 else
8091 op0= convert_modes (mode, inner_mode, op0,
8092 TYPE_UNSIGNED (inner_type));
8095 else if (modifier == EXPAND_INITIALIZER)
8096 op0 = gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
8098 else if (target == 0)
8099 op0 = convert_to_mode (mode, op0,
8100 TYPE_UNSIGNED (TREE_TYPE
8101 (treeop0)));
8102 else
8104 convert_move (target, op0,
8105 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8106 op0 = target;
8109 return REDUCE_BIT_FIELD (op0);
8111 case ADDR_SPACE_CONVERT_EXPR:
8113 tree treeop0_type = TREE_TYPE (treeop0);
8114 addr_space_t as_to;
8115 addr_space_t as_from;
8117 gcc_assert (POINTER_TYPE_P (type));
8118 gcc_assert (POINTER_TYPE_P (treeop0_type));
8120 as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
8121 as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
8123 /* Conversions between pointers to the same address space should
8124 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8125 gcc_assert (as_to != as_from);
8127 /* Ask target code to handle conversion between pointers
8128 to overlapping address spaces. */
8129 if (targetm.addr_space.subset_p (as_to, as_from)
8130 || targetm.addr_space.subset_p (as_from, as_to))
8132 op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
8133 op0 = targetm.addr_space.convert (op0, treeop0_type, type);
8134 gcc_assert (op0);
8135 return op0;
8138 /* For disjoint address spaces, converting anything but
8139 a null pointer invokes undefined behaviour. We simply
8140 always return a null pointer here. */
8141 return CONST0_RTX (mode);
8144 case POINTER_PLUS_EXPR:
8145 /* Even though the sizetype mode and the pointer's mode can be different
8146 expand is able to handle this correctly and get the correct result out
8147 of the PLUS_EXPR code. */
8148 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8149 if sizetype precision is smaller than pointer precision. */
8150 if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
8151 treeop1 = fold_convert_loc (loc, type,
8152 fold_convert_loc (loc, ssizetype,
8153 treeop1));
8154 /* If sizetype precision is larger than pointer precision, truncate the
8155 offset to have matching modes. */
8156 else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
8157 treeop1 = fold_convert_loc (loc, type, treeop1);
8159 case PLUS_EXPR:
8160 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8161 something else, make sure we add the register to the constant and
8162 then to the other thing. This case can occur during strength
8163 reduction and doing it this way will produce better code if the
8164 frame pointer or argument pointer is eliminated.
8166 fold-const.c will ensure that the constant is always in the inner
8167 PLUS_EXPR, so the only case we need to do anything about is if
8168 sp, ap, or fp is our second argument, in which case we must swap
8169 the innermost first argument and our second argument. */
8171 if (TREE_CODE (treeop0) == PLUS_EXPR
8172 && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
8173 && TREE_CODE (treeop1) == VAR_DECL
8174 && (DECL_RTL (treeop1) == frame_pointer_rtx
8175 || DECL_RTL (treeop1) == stack_pointer_rtx
8176 || DECL_RTL (treeop1) == arg_pointer_rtx))
8178 gcc_unreachable ();
8181 /* If the result is to be ptr_mode and we are adding an integer to
8182 something, we might be forming a constant. So try to use
8183 plus_constant. If it produces a sum and we can't accept it,
8184 use force_operand. This allows P = &ARR[const] to generate
8185 efficient code on machines where a SYMBOL_REF is not a valid
8186 address.
8188 If this is an EXPAND_SUM call, always return the sum. */
8189 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
8190 || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
8192 if (modifier == EXPAND_STACK_PARM)
8193 target = 0;
8194 if (TREE_CODE (treeop0) == INTEGER_CST
8195 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8196 && TREE_CONSTANT (treeop1))
8198 rtx constant_part;
8200 op1 = expand_expr (treeop1, subtarget, VOIDmode,
8201 EXPAND_SUM);
8202 /* Use immed_double_const to ensure that the constant is
8203 truncated according to the mode of OP1, then sign extended
8204 to a HOST_WIDE_INT. Using the constant directly can result
8205 in non-canonical RTL in a 64x32 cross compile. */
8206 constant_part
8207 = immed_double_const (TREE_INT_CST_LOW (treeop0),
8208 (HOST_WIDE_INT) 0,
8209 TYPE_MODE (TREE_TYPE (treeop1)));
8210 op1 = plus_constant (mode, op1, INTVAL (constant_part));
8211 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8212 op1 = force_operand (op1, target);
8213 return REDUCE_BIT_FIELD (op1);
8216 else if (TREE_CODE (treeop1) == INTEGER_CST
8217 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8218 && TREE_CONSTANT (treeop0))
8220 rtx constant_part;
8222 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8223 (modifier == EXPAND_INITIALIZER
8224 ? EXPAND_INITIALIZER : EXPAND_SUM));
8225 if (! CONSTANT_P (op0))
8227 op1 = expand_expr (treeop1, NULL_RTX,
8228 VOIDmode, modifier);
8229 /* Return a PLUS if modifier says it's OK. */
8230 if (modifier == EXPAND_SUM
8231 || modifier == EXPAND_INITIALIZER)
8232 return simplify_gen_binary (PLUS, mode, op0, op1);
8233 goto binop2;
8235 /* Use immed_double_const to ensure that the constant is
8236 truncated according to the mode of OP1, then sign extended
8237 to a HOST_WIDE_INT. Using the constant directly can result
8238 in non-canonical RTL in a 64x32 cross compile. */
8239 constant_part
8240 = immed_double_const (TREE_INT_CST_LOW (treeop1),
8241 (HOST_WIDE_INT) 0,
8242 TYPE_MODE (TREE_TYPE (treeop0)));
8243 op0 = plus_constant (mode, op0, INTVAL (constant_part));
8244 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8245 op0 = force_operand (op0, target);
8246 return REDUCE_BIT_FIELD (op0);
8250 /* Use TER to expand pointer addition of a negated value
8251 as pointer subtraction. */
8252 if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
8253 || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
8254 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
8255 && TREE_CODE (treeop1) == SSA_NAME
8256 && TYPE_MODE (TREE_TYPE (treeop0))
8257 == TYPE_MODE (TREE_TYPE (treeop1)))
8259 gimple def = get_def_for_expr (treeop1, NEGATE_EXPR);
8260 if (def)
8262 treeop1 = gimple_assign_rhs1 (def);
8263 code = MINUS_EXPR;
8264 goto do_minus;
8268 /* No sense saving up arithmetic to be done
8269 if it's all in the wrong mode to form part of an address.
8270 And force_operand won't know whether to sign-extend or
8271 zero-extend. */
8272 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8273 || mode != ptr_mode)
8275 expand_operands (treeop0, treeop1,
8276 subtarget, &op0, &op1, EXPAND_NORMAL);
8277 if (op0 == const0_rtx)
8278 return op1;
8279 if (op1 == const0_rtx)
8280 return op0;
8281 goto binop2;
8284 expand_operands (treeop0, treeop1,
8285 subtarget, &op0, &op1, modifier);
8286 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8288 case MINUS_EXPR:
8289 do_minus:
8290 /* For initializers, we are allowed to return a MINUS of two
8291 symbolic constants. Here we handle all cases when both operands
8292 are constant. */
8293 /* Handle difference of two symbolic constants,
8294 for the sake of an initializer. */
8295 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8296 && really_constant_p (treeop0)
8297 && really_constant_p (treeop1))
8299 expand_operands (treeop0, treeop1,
8300 NULL_RTX, &op0, &op1, modifier);
8302 /* If the last operand is a CONST_INT, use plus_constant of
8303 the negated constant. Else make the MINUS. */
8304 if (CONST_INT_P (op1))
8305 return REDUCE_BIT_FIELD (plus_constant (mode, op0,
8306 -INTVAL (op1)));
8307 else
8308 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode, op0, op1));
8311 /* No sense saving up arithmetic to be done
8312 if it's all in the wrong mode to form part of an address.
8313 And force_operand won't know whether to sign-extend or
8314 zero-extend. */
8315 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8316 || mode != ptr_mode)
8317 goto binop;
8319 expand_operands (treeop0, treeop1,
8320 subtarget, &op0, &op1, modifier);
8322 /* Convert A - const to A + (-const). */
8323 if (CONST_INT_P (op1))
8325 op1 = negate_rtx (mode, op1);
8326 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8329 goto binop2;
8331 case WIDEN_MULT_PLUS_EXPR:
8332 case WIDEN_MULT_MINUS_EXPR:
8333 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8334 op2 = expand_normal (treeop2);
8335 target = expand_widen_pattern_expr (ops, op0, op1, op2,
8336 target, unsignedp);
8337 return target;
8339 case WIDEN_MULT_EXPR:
8340 /* If first operand is constant, swap them.
8341 Thus the following special case checks need only
8342 check the second operand. */
8343 if (TREE_CODE (treeop0) == INTEGER_CST)
8345 tree t1 = treeop0;
8346 treeop0 = treeop1;
8347 treeop1 = t1;
8350 /* First, check if we have a multiplication of one signed and one
8351 unsigned operand. */
8352 if (TREE_CODE (treeop1) != INTEGER_CST
8353 && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
8354 != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
8356 enum machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
8357 this_optab = usmul_widen_optab;
8358 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8359 != CODE_FOR_nothing)
8361 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8362 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8363 EXPAND_NORMAL);
8364 else
8365 expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
8366 EXPAND_NORMAL);
8367 /* op0 and op1 might still be constant, despite the above
8368 != INTEGER_CST check. Handle it. */
8369 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8371 op0 = convert_modes (innermode, mode, op0, true);
8372 op1 = convert_modes (innermode, mode, op1, false);
8373 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
8374 target, unsignedp));
8376 goto binop3;
8379 /* Check for a multiplication with matching signedness. */
8380 else if ((TREE_CODE (treeop1) == INTEGER_CST
8381 && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
8382 || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
8383 == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
8385 tree op0type = TREE_TYPE (treeop0);
8386 enum machine_mode innermode = TYPE_MODE (op0type);
8387 bool zextend_p = TYPE_UNSIGNED (op0type);
8388 optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
8389 this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
8391 if (TREE_CODE (treeop0) != INTEGER_CST)
8393 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8394 != CODE_FOR_nothing)
8396 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8397 EXPAND_NORMAL);
8398 /* op0 and op1 might still be constant, despite the above
8399 != INTEGER_CST check. Handle it. */
8400 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8402 widen_mult_const:
8403 op0 = convert_modes (innermode, mode, op0, zextend_p);
8405 = convert_modes (innermode, mode, op1,
8406 TYPE_UNSIGNED (TREE_TYPE (treeop1)));
8407 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
8408 target,
8409 unsignedp));
8411 temp = expand_widening_mult (mode, op0, op1, target,
8412 unsignedp, this_optab);
8413 return REDUCE_BIT_FIELD (temp);
8415 if (find_widening_optab_handler (other_optab, mode, innermode, 0)
8416 != CODE_FOR_nothing
8417 && innermode == word_mode)
8419 rtx htem, hipart;
8420 op0 = expand_normal (treeop0);
8421 if (TREE_CODE (treeop1) == INTEGER_CST)
8422 op1 = convert_modes (innermode, mode,
8423 expand_normal (treeop1),
8424 TYPE_UNSIGNED (TREE_TYPE (treeop1)));
8425 else
8426 op1 = expand_normal (treeop1);
8427 /* op0 and op1 might still be constant, despite the above
8428 != INTEGER_CST check. Handle it. */
8429 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8430 goto widen_mult_const;
8431 temp = expand_binop (mode, other_optab, op0, op1, target,
8432 unsignedp, OPTAB_LIB_WIDEN);
8433 hipart = gen_highpart (innermode, temp);
8434 htem = expand_mult_highpart_adjust (innermode, hipart,
8435 op0, op1, hipart,
8436 zextend_p);
8437 if (htem != hipart)
8438 emit_move_insn (hipart, htem);
8439 return REDUCE_BIT_FIELD (temp);
8443 treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
8444 treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
8445 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8446 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8448 case FMA_EXPR:
8450 optab opt = fma_optab;
8451 gimple def0, def2;
8453 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8454 call. */
8455 if (optab_handler (fma_optab, mode) == CODE_FOR_nothing)
8457 tree fn = mathfn_built_in (TREE_TYPE (treeop0), BUILT_IN_FMA);
8458 tree call_expr;
8460 gcc_assert (fn != NULL_TREE);
8461 call_expr = build_call_expr (fn, 3, treeop0, treeop1, treeop2);
8462 return expand_builtin (call_expr, target, subtarget, mode, false);
8465 def0 = get_def_for_expr (treeop0, NEGATE_EXPR);
8466 def2 = get_def_for_expr (treeop2, NEGATE_EXPR);
8468 op0 = op2 = NULL;
8470 if (def0 && def2
8471 && optab_handler (fnms_optab, mode) != CODE_FOR_nothing)
8473 opt = fnms_optab;
8474 op0 = expand_normal (gimple_assign_rhs1 (def0));
8475 op2 = expand_normal (gimple_assign_rhs1 (def2));
8477 else if (def0
8478 && optab_handler (fnma_optab, mode) != CODE_FOR_nothing)
8480 opt = fnma_optab;
8481 op0 = expand_normal (gimple_assign_rhs1 (def0));
8483 else if (def2
8484 && optab_handler (fms_optab, mode) != CODE_FOR_nothing)
8486 opt = fms_optab;
8487 op2 = expand_normal (gimple_assign_rhs1 (def2));
8490 if (op0 == NULL)
8491 op0 = expand_expr (treeop0, subtarget, VOIDmode, EXPAND_NORMAL);
8492 if (op2 == NULL)
8493 op2 = expand_normal (treeop2);
8494 op1 = expand_normal (treeop1);
8496 return expand_ternary_op (TYPE_MODE (type), opt,
8497 op0, op1, op2, target, 0);
8500 case MULT_EXPR:
8501 /* If this is a fixed-point operation, then we cannot use the code
8502 below because "expand_mult" doesn't support sat/no-sat fixed-point
8503 multiplications. */
8504 if (ALL_FIXED_POINT_MODE_P (mode))
8505 goto binop;
8507 /* If first operand is constant, swap them.
8508 Thus the following special case checks need only
8509 check the second operand. */
8510 if (TREE_CODE (treeop0) == INTEGER_CST)
8512 tree t1 = treeop0;
8513 treeop0 = treeop1;
8514 treeop1 = t1;
8517 /* Attempt to return something suitable for generating an
8518 indexed address, for machines that support that. */
8520 if (modifier == EXPAND_SUM && mode == ptr_mode
8521 && host_integerp (treeop1, 0))
8523 tree exp1 = treeop1;
8525 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8526 EXPAND_SUM);
8528 if (!REG_P (op0))
8529 op0 = force_operand (op0, NULL_RTX);
8530 if (!REG_P (op0))
8531 op0 = copy_to_mode_reg (mode, op0);
8533 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0,
8534 gen_int_mode (tree_low_cst (exp1, 0),
8535 TYPE_MODE (TREE_TYPE (exp1)))));
8538 if (modifier == EXPAND_STACK_PARM)
8539 target = 0;
8541 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8542 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8544 case TRUNC_DIV_EXPR:
8545 case FLOOR_DIV_EXPR:
8546 case CEIL_DIV_EXPR:
8547 case ROUND_DIV_EXPR:
8548 case EXACT_DIV_EXPR:
8549 /* If this is a fixed-point operation, then we cannot use the code
8550 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8551 divisions. */
8552 if (ALL_FIXED_POINT_MODE_P (mode))
8553 goto binop;
8555 if (modifier == EXPAND_STACK_PARM)
8556 target = 0;
8557 /* Possible optimization: compute the dividend with EXPAND_SUM
8558 then if the divisor is constant can optimize the case
8559 where some terms of the dividend have coeffs divisible by it. */
8560 expand_operands (treeop0, treeop1,
8561 subtarget, &op0, &op1, EXPAND_NORMAL);
8562 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
8564 case RDIV_EXPR:
8565 goto binop;
8567 case MULT_HIGHPART_EXPR:
8568 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8569 temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
8570 gcc_assert (temp);
8571 return temp;
8573 case TRUNC_MOD_EXPR:
8574 case FLOOR_MOD_EXPR:
8575 case CEIL_MOD_EXPR:
8576 case ROUND_MOD_EXPR:
8577 if (modifier == EXPAND_STACK_PARM)
8578 target = 0;
8579 expand_operands (treeop0, treeop1,
8580 subtarget, &op0, &op1, EXPAND_NORMAL);
8581 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
8583 case FIXED_CONVERT_EXPR:
8584 op0 = expand_normal (treeop0);
8585 if (target == 0 || modifier == EXPAND_STACK_PARM)
8586 target = gen_reg_rtx (mode);
8588 if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
8589 && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8590 || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
8591 expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
8592 else
8593 expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
8594 return target;
8596 case FIX_TRUNC_EXPR:
8597 op0 = expand_normal (treeop0);
8598 if (target == 0 || modifier == EXPAND_STACK_PARM)
8599 target = gen_reg_rtx (mode);
8600 expand_fix (target, op0, unsignedp);
8601 return target;
8603 case FLOAT_EXPR:
8604 op0 = expand_normal (treeop0);
8605 if (target == 0 || modifier == EXPAND_STACK_PARM)
8606 target = gen_reg_rtx (mode);
8607 /* expand_float can't figure out what to do if FROM has VOIDmode.
8608 So give it the correct mode. With -O, cse will optimize this. */
8609 if (GET_MODE (op0) == VOIDmode)
8610 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
8611 op0);
8612 expand_float (target, op0,
8613 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8614 return target;
8616 case NEGATE_EXPR:
8617 op0 = expand_expr (treeop0, subtarget,
8618 VOIDmode, EXPAND_NORMAL);
8619 if (modifier == EXPAND_STACK_PARM)
8620 target = 0;
8621 temp = expand_unop (mode,
8622 optab_for_tree_code (NEGATE_EXPR, type,
8623 optab_default),
8624 op0, target, 0);
8625 gcc_assert (temp);
8626 return REDUCE_BIT_FIELD (temp);
8628 case ABS_EXPR:
8629 op0 = expand_expr (treeop0, subtarget,
8630 VOIDmode, EXPAND_NORMAL);
8631 if (modifier == EXPAND_STACK_PARM)
8632 target = 0;
8634 /* ABS_EXPR is not valid for complex arguments. */
8635 gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8636 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
8638 /* Unsigned abs is simply the operand. Testing here means we don't
8639 risk generating incorrect code below. */
8640 if (TYPE_UNSIGNED (type))
8641 return op0;
8643 return expand_abs (mode, op0, target, unsignedp,
8644 safe_from_p (target, treeop0, 1));
8646 case MAX_EXPR:
8647 case MIN_EXPR:
8648 target = original_target;
8649 if (target == 0
8650 || modifier == EXPAND_STACK_PARM
8651 || (MEM_P (target) && MEM_VOLATILE_P (target))
8652 || GET_MODE (target) != mode
8653 || (REG_P (target)
8654 && REGNO (target) < FIRST_PSEUDO_REGISTER))
8655 target = gen_reg_rtx (mode);
8656 expand_operands (treeop0, treeop1,
8657 target, &op0, &op1, EXPAND_NORMAL);
8659 /* First try to do it with a special MIN or MAX instruction.
8660 If that does not win, use a conditional jump to select the proper
8661 value. */
8662 this_optab = optab_for_tree_code (code, type, optab_default);
8663 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8664 OPTAB_WIDEN);
8665 if (temp != 0)
8666 return temp;
8668 /* At this point, a MEM target is no longer useful; we will get better
8669 code without it. */
8671 if (! REG_P (target))
8672 target = gen_reg_rtx (mode);
8674 /* If op1 was placed in target, swap op0 and op1. */
8675 if (target != op0 && target == op1)
8677 temp = op0;
8678 op0 = op1;
8679 op1 = temp;
8682 /* We generate better code and avoid problems with op1 mentioning
8683 target by forcing op1 into a pseudo if it isn't a constant. */
8684 if (! CONSTANT_P (op1))
8685 op1 = force_reg (mode, op1);
8688 enum rtx_code comparison_code;
8689 rtx cmpop1 = op1;
8691 if (code == MAX_EXPR)
8692 comparison_code = unsignedp ? GEU : GE;
8693 else
8694 comparison_code = unsignedp ? LEU : LE;
8696 /* Canonicalize to comparisons against 0. */
8697 if (op1 == const1_rtx)
8699 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8700 or (a != 0 ? a : 1) for unsigned.
8701 For MIN we are safe converting (a <= 1 ? a : 1)
8702 into (a <= 0 ? a : 1) */
8703 cmpop1 = const0_rtx;
8704 if (code == MAX_EXPR)
8705 comparison_code = unsignedp ? NE : GT;
8707 if (op1 == constm1_rtx && !unsignedp)
8709 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8710 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8711 cmpop1 = const0_rtx;
8712 if (code == MIN_EXPR)
8713 comparison_code = LT;
8715 #ifdef HAVE_conditional_move
8716 /* Use a conditional move if possible. */
8717 if (can_conditionally_move_p (mode))
8719 rtx insn;
8721 /* ??? Same problem as in expmed.c: emit_conditional_move
8722 forces a stack adjustment via compare_from_rtx, and we
8723 lose the stack adjustment if the sequence we are about
8724 to create is discarded. */
8725 do_pending_stack_adjust ();
8727 start_sequence ();
8729 /* Try to emit the conditional move. */
8730 insn = emit_conditional_move (target, comparison_code,
8731 op0, cmpop1, mode,
8732 op0, op1, mode,
8733 unsignedp);
8735 /* If we could do the conditional move, emit the sequence,
8736 and return. */
8737 if (insn)
8739 rtx seq = get_insns ();
8740 end_sequence ();
8741 emit_insn (seq);
8742 return target;
8745 /* Otherwise discard the sequence and fall back to code with
8746 branches. */
8747 end_sequence ();
8749 #endif
8750 if (target != op0)
8751 emit_move_insn (target, op0);
8753 temp = gen_label_rtx ();
8754 do_compare_rtx_and_jump (target, cmpop1, comparison_code,
8755 unsignedp, mode, NULL_RTX, NULL_RTX, temp,
8756 -1);
8758 emit_move_insn (target, op1);
8759 emit_label (temp);
8760 return target;
8762 case BIT_NOT_EXPR:
8763 op0 = expand_expr (treeop0, subtarget,
8764 VOIDmode, EXPAND_NORMAL);
8765 if (modifier == EXPAND_STACK_PARM)
8766 target = 0;
8767 /* In case we have to reduce the result to bitfield precision
8768 for unsigned bitfield expand this as XOR with a proper constant
8769 instead. */
8770 if (reduce_bit_field && TYPE_UNSIGNED (type))
8771 temp = expand_binop (mode, xor_optab, op0,
8772 immed_double_int_const
8773 (double_int::mask (TYPE_PRECISION (type)), mode),
8774 target, 1, OPTAB_LIB_WIDEN);
8775 else
8776 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
8777 gcc_assert (temp);
8778 return temp;
8780 /* ??? Can optimize bitwise operations with one arg constant.
8781 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8782 and (a bitwise1 b) bitwise2 b (etc)
8783 but that is probably not worth while. */
8785 case BIT_AND_EXPR:
8786 case BIT_IOR_EXPR:
8787 case BIT_XOR_EXPR:
8788 goto binop;
8790 case LROTATE_EXPR:
8791 case RROTATE_EXPR:
8792 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
8793 || (GET_MODE_PRECISION (TYPE_MODE (type))
8794 == TYPE_PRECISION (type)));
8795 /* fall through */
8797 case LSHIFT_EXPR:
8798 case RSHIFT_EXPR:
8799 /* If this is a fixed-point operation, then we cannot use the code
8800 below because "expand_shift" doesn't support sat/no-sat fixed-point
8801 shifts. */
8802 if (ALL_FIXED_POINT_MODE_P (mode))
8803 goto binop;
8805 if (! safe_from_p (subtarget, treeop1, 1))
8806 subtarget = 0;
8807 if (modifier == EXPAND_STACK_PARM)
8808 target = 0;
8809 op0 = expand_expr (treeop0, subtarget,
8810 VOIDmode, EXPAND_NORMAL);
8811 temp = expand_variable_shift (code, mode, op0, treeop1, target,
8812 unsignedp);
8813 if (code == LSHIFT_EXPR)
8814 temp = REDUCE_BIT_FIELD (temp);
8815 return temp;
8817 /* Could determine the answer when only additive constants differ. Also,
8818 the addition of one can be handled by changing the condition. */
8819 case LT_EXPR:
8820 case LE_EXPR:
8821 case GT_EXPR:
8822 case GE_EXPR:
8823 case EQ_EXPR:
8824 case NE_EXPR:
8825 case UNORDERED_EXPR:
8826 case ORDERED_EXPR:
8827 case UNLT_EXPR:
8828 case UNLE_EXPR:
8829 case UNGT_EXPR:
8830 case UNGE_EXPR:
8831 case UNEQ_EXPR:
8832 case LTGT_EXPR:
8833 temp = do_store_flag (ops,
8834 modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
8835 tmode != VOIDmode ? tmode : mode);
8836 if (temp)
8837 return temp;
8839 /* Use a compare and a jump for BLKmode comparisons, or for function
8840 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8842 if ((target == 0
8843 || modifier == EXPAND_STACK_PARM
8844 || ! safe_from_p (target, treeop0, 1)
8845 || ! safe_from_p (target, treeop1, 1)
8846 /* Make sure we don't have a hard reg (such as function's return
8847 value) live across basic blocks, if not optimizing. */
8848 || (!optimize && REG_P (target)
8849 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
8850 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
8852 emit_move_insn (target, const0_rtx);
8854 op1 = gen_label_rtx ();
8855 jumpifnot_1 (code, treeop0, treeop1, op1, -1);
8857 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
8858 emit_move_insn (target, constm1_rtx);
8859 else
8860 emit_move_insn (target, const1_rtx);
8862 emit_label (op1);
8863 return target;
8865 case COMPLEX_EXPR:
8866 /* Get the rtx code of the operands. */
8867 op0 = expand_normal (treeop0);
8868 op1 = expand_normal (treeop1);
8870 if (!target)
8871 target = gen_reg_rtx (TYPE_MODE (type));
8872 else
8873 /* If target overlaps with op1, then either we need to force
8874 op1 into a pseudo (if target also overlaps with op0),
8875 or write the complex parts in reverse order. */
8876 switch (GET_CODE (target))
8878 case CONCAT:
8879 if (reg_overlap_mentioned_p (XEXP (target, 0), op1))
8881 if (reg_overlap_mentioned_p (XEXP (target, 1), op0))
8883 complex_expr_force_op1:
8884 temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target)));
8885 emit_move_insn (temp, op1);
8886 op1 = temp;
8887 break;
8889 complex_expr_swap_order:
8890 /* Move the imaginary (op1) and real (op0) parts to their
8891 location. */
8892 write_complex_part (target, op1, true);
8893 write_complex_part (target, op0, false);
8895 return target;
8897 break;
8898 case MEM:
8899 temp = adjust_address_nv (target,
8900 GET_MODE_INNER (GET_MODE (target)), 0);
8901 if (reg_overlap_mentioned_p (temp, op1))
8903 enum machine_mode imode = GET_MODE_INNER (GET_MODE (target));
8904 temp = adjust_address_nv (target, imode,
8905 GET_MODE_SIZE (imode));
8906 if (reg_overlap_mentioned_p (temp, op0))
8907 goto complex_expr_force_op1;
8908 goto complex_expr_swap_order;
8910 break;
8911 default:
8912 if (reg_overlap_mentioned_p (target, op1))
8914 if (reg_overlap_mentioned_p (target, op0))
8915 goto complex_expr_force_op1;
8916 goto complex_expr_swap_order;
8918 break;
8921 /* Move the real (op0) and imaginary (op1) parts to their location. */
8922 write_complex_part (target, op0, false);
8923 write_complex_part (target, op1, true);
8925 return target;
8927 case WIDEN_SUM_EXPR:
8929 tree oprnd0 = treeop0;
8930 tree oprnd1 = treeop1;
8932 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8933 target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
8934 target, unsignedp);
8935 return target;
8938 case REDUC_MAX_EXPR:
8939 case REDUC_MIN_EXPR:
8940 case REDUC_PLUS_EXPR:
8942 op0 = expand_normal (treeop0);
8943 this_optab = optab_for_tree_code (code, type, optab_default);
8944 temp = expand_unop (mode, this_optab, op0, target, unsignedp);
8945 gcc_assert (temp);
8946 return temp;
8949 case VEC_LSHIFT_EXPR:
8950 case VEC_RSHIFT_EXPR:
8952 target = expand_vec_shift_expr (ops, target);
8953 return target;
8956 case VEC_UNPACK_HI_EXPR:
8957 case VEC_UNPACK_LO_EXPR:
8959 op0 = expand_normal (treeop0);
8960 temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
8961 target, unsignedp);
8962 gcc_assert (temp);
8963 return temp;
8966 case VEC_UNPACK_FLOAT_HI_EXPR:
8967 case VEC_UNPACK_FLOAT_LO_EXPR:
8969 op0 = expand_normal (treeop0);
8970 /* The signedness is determined from input operand. */
8971 temp = expand_widen_pattern_expr
8972 (ops, op0, NULL_RTX, NULL_RTX,
8973 target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8975 gcc_assert (temp);
8976 return temp;
8979 case VEC_WIDEN_MULT_HI_EXPR:
8980 case VEC_WIDEN_MULT_LO_EXPR:
8981 case VEC_WIDEN_MULT_EVEN_EXPR:
8982 case VEC_WIDEN_MULT_ODD_EXPR:
8983 case VEC_WIDEN_LSHIFT_HI_EXPR:
8984 case VEC_WIDEN_LSHIFT_LO_EXPR:
8985 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8986 target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
8987 target, unsignedp);
8988 gcc_assert (target);
8989 return target;
8991 case VEC_PACK_TRUNC_EXPR:
8992 case VEC_PACK_SAT_EXPR:
8993 case VEC_PACK_FIX_TRUNC_EXPR:
8994 mode = TYPE_MODE (TREE_TYPE (treeop0));
8995 goto binop;
8997 case VEC_PERM_EXPR:
8998 expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
8999 op2 = expand_normal (treeop2);
9001 /* Careful here: if the target doesn't support integral vector modes,
9002 a constant selection vector could wind up smooshed into a normal
9003 integral constant. */
9004 if (CONSTANT_P (op2) && GET_CODE (op2) != CONST_VECTOR)
9006 tree sel_type = TREE_TYPE (treeop2);
9007 enum machine_mode vmode
9008 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type)),
9009 TYPE_VECTOR_SUBPARTS (sel_type));
9010 gcc_assert (GET_MODE_CLASS (vmode) == MODE_VECTOR_INT);
9011 op2 = simplify_subreg (vmode, op2, TYPE_MODE (sel_type), 0);
9012 gcc_assert (op2 && GET_CODE (op2) == CONST_VECTOR);
9014 else
9015 gcc_assert (GET_MODE_CLASS (GET_MODE (op2)) == MODE_VECTOR_INT);
9017 temp = expand_vec_perm (mode, op0, op1, op2, target);
9018 gcc_assert (temp);
9019 return temp;
9021 case DOT_PROD_EXPR:
9023 tree oprnd0 = treeop0;
9024 tree oprnd1 = treeop1;
9025 tree oprnd2 = treeop2;
9026 rtx op2;
9028 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9029 op2 = expand_normal (oprnd2);
9030 target = expand_widen_pattern_expr (ops, op0, op1, op2,
9031 target, unsignedp);
9032 return target;
9035 case REALIGN_LOAD_EXPR:
9037 tree oprnd0 = treeop0;
9038 tree oprnd1 = treeop1;
9039 tree oprnd2 = treeop2;
9040 rtx op2;
9042 this_optab = optab_for_tree_code (code, type, optab_default);
9043 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9044 op2 = expand_normal (oprnd2);
9045 temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
9046 target, unsignedp);
9047 gcc_assert (temp);
9048 return temp;
9051 case COND_EXPR:
9052 /* A COND_EXPR with its type being VOID_TYPE represents a
9053 conditional jump and is handled in
9054 expand_gimple_cond_expr. */
9055 gcc_assert (!VOID_TYPE_P (type));
9057 /* Note that COND_EXPRs whose type is a structure or union
9058 are required to be constructed to contain assignments of
9059 a temporary variable, so that we can evaluate them here
9060 for side effect only. If type is void, we must do likewise. */
9062 gcc_assert (!TREE_ADDRESSABLE (type)
9063 && !ignore
9064 && TREE_TYPE (treeop1) != void_type_node
9065 && TREE_TYPE (treeop2) != void_type_node);
9067 temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
9068 if (temp)
9069 return temp;
9071 /* If we are not to produce a result, we have no target. Otherwise,
9072 if a target was specified use it; it will not be used as an
9073 intermediate target unless it is safe. If no target, use a
9074 temporary. */
9076 if (modifier != EXPAND_STACK_PARM
9077 && original_target
9078 && safe_from_p (original_target, treeop0, 1)
9079 && GET_MODE (original_target) == mode
9080 && !MEM_P (original_target))
9081 temp = original_target;
9082 else
9083 temp = assign_temp (type, 0, 1);
9085 do_pending_stack_adjust ();
9086 NO_DEFER_POP;
9087 op0 = gen_label_rtx ();
9088 op1 = gen_label_rtx ();
9089 jumpifnot (treeop0, op0, -1);
9090 store_expr (treeop1, temp,
9091 modifier == EXPAND_STACK_PARM,
9092 false);
9094 emit_jump_insn (gen_jump (op1));
9095 emit_barrier ();
9096 emit_label (op0);
9097 store_expr (treeop2, temp,
9098 modifier == EXPAND_STACK_PARM,
9099 false);
9101 emit_label (op1);
9102 OK_DEFER_POP;
9103 return temp;
9105 case VEC_COND_EXPR:
9106 target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target);
9107 return target;
9109 default:
9110 gcc_unreachable ();
9113 /* Here to do an ordinary binary operator. */
9114 binop:
9115 expand_operands (treeop0, treeop1,
9116 subtarget, &op0, &op1, EXPAND_NORMAL);
9117 binop2:
9118 this_optab = optab_for_tree_code (code, type, optab_default);
9119 binop3:
9120 if (modifier == EXPAND_STACK_PARM)
9121 target = 0;
9122 temp = expand_binop (mode, this_optab, op0, op1, target,
9123 unsignedp, OPTAB_LIB_WIDEN);
9124 gcc_assert (temp);
9125 /* Bitwise operations do not need bitfield reduction as we expect their
9126 operands being properly truncated. */
9127 if (code == BIT_XOR_EXPR
9128 || code == BIT_AND_EXPR
9129 || code == BIT_IOR_EXPR)
9130 return temp;
9131 return REDUCE_BIT_FIELD (temp);
9133 #undef REDUCE_BIT_FIELD
9136 /* Return TRUE if expression STMT is suitable for replacement.
9137 Never consider memory loads as replaceable, because those don't ever lead
9138 into constant expressions. */
9140 static bool
9141 stmt_is_replaceable_p (gimple stmt)
9143 if (ssa_is_replaceable_p (stmt))
9145 /* Don't move around loads. */
9146 if (!gimple_assign_single_p (stmt)
9147 || is_gimple_val (gimple_assign_rhs1 (stmt)))
9148 return true;
9150 return false;
9154 expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
9155 enum expand_modifier modifier, rtx *alt_rtl)
9157 rtx op0, op1, temp, decl_rtl;
9158 tree type;
9159 int unsignedp;
9160 enum machine_mode mode;
9161 enum tree_code code = TREE_CODE (exp);
9162 rtx subtarget, original_target;
9163 int ignore;
9164 tree context;
9165 bool reduce_bit_field;
9166 location_t loc = EXPR_LOCATION (exp);
9167 struct separate_ops ops;
9168 tree treeop0, treeop1, treeop2;
9169 tree ssa_name = NULL_TREE;
9170 gimple g;
9172 type = TREE_TYPE (exp);
9173 mode = TYPE_MODE (type);
9174 unsignedp = TYPE_UNSIGNED (type);
9176 treeop0 = treeop1 = treeop2 = NULL_TREE;
9177 if (!VL_EXP_CLASS_P (exp))
9178 switch (TREE_CODE_LENGTH (code))
9180 default:
9181 case 3: treeop2 = TREE_OPERAND (exp, 2);
9182 case 2: treeop1 = TREE_OPERAND (exp, 1);
9183 case 1: treeop0 = TREE_OPERAND (exp, 0);
9184 case 0: break;
9186 ops.code = code;
9187 ops.type = type;
9188 ops.op0 = treeop0;
9189 ops.op1 = treeop1;
9190 ops.op2 = treeop2;
9191 ops.location = loc;
9193 ignore = (target == const0_rtx
9194 || ((CONVERT_EXPR_CODE_P (code)
9195 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
9196 && TREE_CODE (type) == VOID_TYPE));
9198 /* An operation in what may be a bit-field type needs the
9199 result to be reduced to the precision of the bit-field type,
9200 which is narrower than that of the type's mode. */
9201 reduce_bit_field = (!ignore
9202 && INTEGRAL_TYPE_P (type)
9203 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
9205 /* If we are going to ignore this result, we need only do something
9206 if there is a side-effect somewhere in the expression. If there
9207 is, short-circuit the most common cases here. Note that we must
9208 not call expand_expr with anything but const0_rtx in case this
9209 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9211 if (ignore)
9213 if (! TREE_SIDE_EFFECTS (exp))
9214 return const0_rtx;
9216 /* Ensure we reference a volatile object even if value is ignored, but
9217 don't do this if all we are doing is taking its address. */
9218 if (TREE_THIS_VOLATILE (exp)
9219 && TREE_CODE (exp) != FUNCTION_DECL
9220 && mode != VOIDmode && mode != BLKmode
9221 && modifier != EXPAND_CONST_ADDRESS)
9223 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
9224 if (MEM_P (temp))
9225 copy_to_reg (temp);
9226 return const0_rtx;
9229 if (TREE_CODE_CLASS (code) == tcc_unary
9230 || code == BIT_FIELD_REF
9231 || code == COMPONENT_REF
9232 || code == INDIRECT_REF)
9233 return expand_expr (treeop0, const0_rtx, VOIDmode,
9234 modifier);
9236 else if (TREE_CODE_CLASS (code) == tcc_binary
9237 || TREE_CODE_CLASS (code) == tcc_comparison
9238 || code == ARRAY_REF || code == ARRAY_RANGE_REF)
9240 expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
9241 expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
9242 return const0_rtx;
9245 target = 0;
9248 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
9249 target = 0;
9251 /* Use subtarget as the target for operand 0 of a binary operation. */
9252 subtarget = get_subtarget (target);
9253 original_target = target;
9255 switch (code)
9257 case LABEL_DECL:
9259 tree function = decl_function_context (exp);
9261 temp = label_rtx (exp);
9262 temp = gen_rtx_LABEL_REF (Pmode, temp);
9264 if (function != current_function_decl
9265 && function != 0)
9266 LABEL_REF_NONLOCAL_P (temp) = 1;
9268 temp = gen_rtx_MEM (FUNCTION_MODE, temp);
9269 return temp;
9272 case SSA_NAME:
9273 /* ??? ivopts calls expander, without any preparation from
9274 out-of-ssa. So fake instructions as if this was an access to the
9275 base variable. This unnecessarily allocates a pseudo, see how we can
9276 reuse it, if partition base vars have it set already. */
9277 if (!currently_expanding_to_rtl)
9279 tree var = SSA_NAME_VAR (exp);
9280 if (var && DECL_RTL_SET_P (var))
9281 return DECL_RTL (var);
9282 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
9283 LAST_VIRTUAL_REGISTER + 1);
9286 g = get_gimple_for_ssa_name (exp);
9287 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9288 if (g == NULL
9289 && modifier == EXPAND_INITIALIZER
9290 && !SSA_NAME_IS_DEFAULT_DEF (exp)
9291 && (optimize || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
9292 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
9293 g = SSA_NAME_DEF_STMT (exp);
9294 if (g)
9296 rtx r;
9297 location_t saved_loc = curr_insn_location ();
9299 set_curr_insn_location (gimple_location (g));
9300 r = expand_expr_real (gimple_assign_rhs_to_tree (g), target,
9301 tmode, modifier, NULL);
9302 set_curr_insn_location (saved_loc);
9303 if (REG_P (r) && !REG_EXPR (r))
9304 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp), r);
9305 return r;
9308 ssa_name = exp;
9309 decl_rtl = get_rtx_for_ssa_name (ssa_name);
9310 exp = SSA_NAME_VAR (ssa_name);
9311 goto expand_decl_rtl;
9313 case PARM_DECL:
9314 case VAR_DECL:
9315 /* If a static var's type was incomplete when the decl was written,
9316 but the type is complete now, lay out the decl now. */
9317 if (DECL_SIZE (exp) == 0
9318 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
9319 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
9320 layout_decl (exp, 0);
9322 /* ... fall through ... */
9324 case FUNCTION_DECL:
9325 case RESULT_DECL:
9326 decl_rtl = DECL_RTL (exp);
9327 expand_decl_rtl:
9328 gcc_assert (decl_rtl);
9329 decl_rtl = copy_rtx (decl_rtl);
9330 /* Record writes to register variables. */
9331 if (modifier == EXPAND_WRITE
9332 && REG_P (decl_rtl)
9333 && HARD_REGISTER_P (decl_rtl))
9334 add_to_hard_reg_set (&crtl->asm_clobbers,
9335 GET_MODE (decl_rtl), REGNO (decl_rtl));
9337 /* Ensure variable marked as used even if it doesn't go through
9338 a parser. If it hasn't be used yet, write out an external
9339 definition. */
9340 TREE_USED (exp) = 1;
9342 /* Show we haven't gotten RTL for this yet. */
9343 temp = 0;
9345 /* Variables inherited from containing functions should have
9346 been lowered by this point. */
9347 context = decl_function_context (exp);
9348 gcc_assert (SCOPE_FILE_SCOPE_P (context)
9349 || context == current_function_decl
9350 || TREE_STATIC (exp)
9351 || DECL_EXTERNAL (exp)
9352 /* ??? C++ creates functions that are not TREE_STATIC. */
9353 || TREE_CODE (exp) == FUNCTION_DECL);
9355 /* This is the case of an array whose size is to be determined
9356 from its initializer, while the initializer is still being parsed.
9357 ??? We aren't parsing while expanding anymore. */
9359 if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
9360 temp = validize_mem (decl_rtl);
9362 /* If DECL_RTL is memory, we are in the normal case and the
9363 address is not valid, get the address into a register. */
9365 else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
9367 if (alt_rtl)
9368 *alt_rtl = decl_rtl;
9369 decl_rtl = use_anchored_address (decl_rtl);
9370 if (modifier != EXPAND_CONST_ADDRESS
9371 && modifier != EXPAND_SUM
9372 && !memory_address_addr_space_p (DECL_MODE (exp),
9373 XEXP (decl_rtl, 0),
9374 MEM_ADDR_SPACE (decl_rtl)))
9375 temp = replace_equiv_address (decl_rtl,
9376 copy_rtx (XEXP (decl_rtl, 0)));
9379 /* If we got something, return it. But first, set the alignment
9380 if the address is a register. */
9381 if (temp != 0)
9383 if (MEM_P (temp) && REG_P (XEXP (temp, 0)))
9384 mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
9386 return temp;
9389 /* If the mode of DECL_RTL does not match that of the decl,
9390 there are two cases: we are dealing with a BLKmode value
9391 that is returned in a register, or we are dealing with
9392 a promoted value. In the latter case, return a SUBREG
9393 of the wanted mode, but mark it so that we know that it
9394 was already extended. */
9395 if (REG_P (decl_rtl)
9396 && DECL_MODE (exp) != BLKmode
9397 && GET_MODE (decl_rtl) != DECL_MODE (exp))
9399 enum machine_mode pmode;
9401 /* Get the signedness to be used for this variable. Ensure we get
9402 the same mode we got when the variable was declared. */
9403 if (code == SSA_NAME
9404 && (g = SSA_NAME_DEF_STMT (ssa_name))
9405 && gimple_code (g) == GIMPLE_CALL)
9407 gcc_assert (!gimple_call_internal_p (g));
9408 pmode = promote_function_mode (type, mode, &unsignedp,
9409 gimple_call_fntype (g),
9412 else
9413 pmode = promote_decl_mode (exp, &unsignedp);
9414 gcc_assert (GET_MODE (decl_rtl) == pmode);
9416 temp = gen_lowpart_SUBREG (mode, decl_rtl);
9417 SUBREG_PROMOTED_VAR_P (temp) = 1;
9418 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
9419 return temp;
9422 return decl_rtl;
9424 case INTEGER_CST:
9425 temp = immed_double_const (TREE_INT_CST_LOW (exp),
9426 TREE_INT_CST_HIGH (exp), mode);
9428 return temp;
9430 case VECTOR_CST:
9432 tree tmp = NULL_TREE;
9433 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
9434 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
9435 || GET_MODE_CLASS (mode) == MODE_VECTOR_FRACT
9436 || GET_MODE_CLASS (mode) == MODE_VECTOR_UFRACT
9437 || GET_MODE_CLASS (mode) == MODE_VECTOR_ACCUM
9438 || GET_MODE_CLASS (mode) == MODE_VECTOR_UACCUM)
9439 return const_vector_from_tree (exp);
9440 if (GET_MODE_CLASS (mode) == MODE_INT)
9442 tree type_for_mode = lang_hooks.types.type_for_mode (mode, 1);
9443 if (type_for_mode)
9444 tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR, type_for_mode, exp);
9446 if (!tmp)
9448 vec<constructor_elt, va_gc> *v;
9449 unsigned i;
9450 vec_alloc (v, VECTOR_CST_NELTS (exp));
9451 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
9452 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
9453 tmp = build_constructor (type, v);
9455 return expand_expr (tmp, ignore ? const0_rtx : target,
9456 tmode, modifier);
9459 case CONST_DECL:
9460 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
9462 case REAL_CST:
9463 /* If optimized, generate immediate CONST_DOUBLE
9464 which will be turned into memory by reload if necessary.
9466 We used to force a register so that loop.c could see it. But
9467 this does not allow gen_* patterns to perform optimizations with
9468 the constants. It also produces two insns in cases like "x = 1.0;".
9469 On most machines, floating-point constants are not permitted in
9470 many insns, so we'd end up copying it to a register in any case.
9472 Now, we do the copying in expand_binop, if appropriate. */
9473 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
9474 TYPE_MODE (TREE_TYPE (exp)));
9476 case FIXED_CST:
9477 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
9478 TYPE_MODE (TREE_TYPE (exp)));
9480 case COMPLEX_CST:
9481 /* Handle evaluating a complex constant in a CONCAT target. */
9482 if (original_target && GET_CODE (original_target) == CONCAT)
9484 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
9485 rtx rtarg, itarg;
9487 rtarg = XEXP (original_target, 0);
9488 itarg = XEXP (original_target, 1);
9490 /* Move the real and imaginary parts separately. */
9491 op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
9492 op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
9494 if (op0 != rtarg)
9495 emit_move_insn (rtarg, op0);
9496 if (op1 != itarg)
9497 emit_move_insn (itarg, op1);
9499 return original_target;
9502 /* ... fall through ... */
9504 case STRING_CST:
9505 temp = expand_expr_constant (exp, 1, modifier);
9507 /* temp contains a constant address.
9508 On RISC machines where a constant address isn't valid,
9509 make some insns to get that address into a register. */
9510 if (modifier != EXPAND_CONST_ADDRESS
9511 && modifier != EXPAND_INITIALIZER
9512 && modifier != EXPAND_SUM
9513 && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
9514 MEM_ADDR_SPACE (temp)))
9515 return replace_equiv_address (temp,
9516 copy_rtx (XEXP (temp, 0)));
9517 return temp;
9519 case SAVE_EXPR:
9521 tree val = treeop0;
9522 rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl);
9524 if (!SAVE_EXPR_RESOLVED_P (exp))
9526 /* We can indeed still hit this case, typically via builtin
9527 expanders calling save_expr immediately before expanding
9528 something. Assume this means that we only have to deal
9529 with non-BLKmode values. */
9530 gcc_assert (GET_MODE (ret) != BLKmode);
9532 val = build_decl (curr_insn_location (),
9533 VAR_DECL, NULL, TREE_TYPE (exp));
9534 DECL_ARTIFICIAL (val) = 1;
9535 DECL_IGNORED_P (val) = 1;
9536 treeop0 = val;
9537 TREE_OPERAND (exp, 0) = treeop0;
9538 SAVE_EXPR_RESOLVED_P (exp) = 1;
9540 if (!CONSTANT_P (ret))
9541 ret = copy_to_reg (ret);
9542 SET_DECL_RTL (val, ret);
9545 return ret;
9549 case CONSTRUCTOR:
9550 /* If we don't need the result, just ensure we evaluate any
9551 subexpressions. */
9552 if (ignore)
9554 unsigned HOST_WIDE_INT idx;
9555 tree value;
9557 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
9558 expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
9560 return const0_rtx;
9563 return expand_constructor (exp, target, modifier, false);
9565 case TARGET_MEM_REF:
9567 addr_space_t as
9568 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9569 enum insn_code icode;
9570 unsigned int align;
9572 op0 = addr_for_mem_ref (exp, as, true);
9573 op0 = memory_address_addr_space (mode, op0, as);
9574 temp = gen_rtx_MEM (mode, op0);
9575 set_mem_attributes (temp, exp, 0);
9576 set_mem_addr_space (temp, as);
9577 align = get_object_alignment (exp);
9578 if (modifier != EXPAND_WRITE
9579 && modifier != EXPAND_MEMORY
9580 && mode != BLKmode
9581 && align < GET_MODE_ALIGNMENT (mode)
9582 /* If the target does not have special handling for unaligned
9583 loads of mode then it can use regular moves for them. */
9584 && ((icode = optab_handler (movmisalign_optab, mode))
9585 != CODE_FOR_nothing))
9587 struct expand_operand ops[2];
9589 /* We've already validated the memory, and we're creating a
9590 new pseudo destination. The predicates really can't fail,
9591 nor can the generator. */
9592 create_output_operand (&ops[0], NULL_RTX, mode);
9593 create_fixed_operand (&ops[1], temp);
9594 expand_insn (icode, 2, ops);
9595 temp = ops[0].value;
9597 return temp;
9600 case MEM_REF:
9602 addr_space_t as
9603 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9604 enum machine_mode address_mode;
9605 tree base = TREE_OPERAND (exp, 0);
9606 gimple def_stmt;
9607 enum insn_code icode;
9608 unsigned align;
9609 /* Handle expansion of non-aliased memory with non-BLKmode. That
9610 might end up in a register. */
9611 if (mem_ref_refers_to_non_mem_p (exp))
9613 HOST_WIDE_INT offset = mem_ref_offset (exp).low;
9614 base = TREE_OPERAND (base, 0);
9615 if (offset == 0
9616 && host_integerp (TYPE_SIZE (type), 1)
9617 && (GET_MODE_BITSIZE (DECL_MODE (base))
9618 == TREE_INT_CST_LOW (TYPE_SIZE (type))))
9619 return expand_expr (build1 (VIEW_CONVERT_EXPR, type, base),
9620 target, tmode, modifier);
9621 if (TYPE_MODE (type) == BLKmode)
9623 temp = assign_stack_temp (DECL_MODE (base),
9624 GET_MODE_SIZE (DECL_MODE (base)));
9625 store_expr (base, temp, 0, false);
9626 temp = adjust_address (temp, BLKmode, offset);
9627 set_mem_size (temp, int_size_in_bytes (type));
9628 return temp;
9630 exp = build3 (BIT_FIELD_REF, type, base, TYPE_SIZE (type),
9631 bitsize_int (offset * BITS_PER_UNIT));
9632 return expand_expr (exp, target, tmode, modifier);
9634 address_mode = targetm.addr_space.address_mode (as);
9635 base = TREE_OPERAND (exp, 0);
9636 if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
9638 tree mask = gimple_assign_rhs2 (def_stmt);
9639 base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
9640 gimple_assign_rhs1 (def_stmt), mask);
9641 TREE_OPERAND (exp, 0) = base;
9643 align = get_object_alignment (exp);
9644 op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
9645 op0 = memory_address_addr_space (mode, op0, as);
9646 if (!integer_zerop (TREE_OPERAND (exp, 1)))
9648 rtx off
9649 = immed_double_int_const (mem_ref_offset (exp), address_mode);
9650 op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
9652 op0 = memory_address_addr_space (mode, op0, as);
9653 temp = gen_rtx_MEM (mode, op0);
9654 set_mem_attributes (temp, exp, 0);
9655 set_mem_addr_space (temp, as);
9656 if (TREE_THIS_VOLATILE (exp))
9657 MEM_VOLATILE_P (temp) = 1;
9658 if (modifier != EXPAND_WRITE
9659 && modifier != EXPAND_MEMORY
9660 && mode != BLKmode
9661 && align < GET_MODE_ALIGNMENT (mode))
9663 if ((icode = optab_handler (movmisalign_optab, mode))
9664 != CODE_FOR_nothing)
9666 struct expand_operand ops[2];
9668 /* We've already validated the memory, and we're creating a
9669 new pseudo destination. The predicates really can't fail,
9670 nor can the generator. */
9671 create_output_operand (&ops[0], NULL_RTX, mode);
9672 create_fixed_operand (&ops[1], temp);
9673 expand_insn (icode, 2, ops);
9674 temp = ops[0].value;
9676 else if (SLOW_UNALIGNED_ACCESS (mode, align))
9677 temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode),
9678 0, TYPE_UNSIGNED (TREE_TYPE (exp)),
9679 (modifier == EXPAND_STACK_PARM
9680 ? NULL_RTX : target),
9681 mode, mode);
9683 return temp;
9686 case ARRAY_REF:
9689 tree array = treeop0;
9690 tree index = treeop1;
9691 tree init;
9693 /* Fold an expression like: "foo"[2].
9694 This is not done in fold so it won't happen inside &.
9695 Don't fold if this is for wide characters since it's too
9696 difficult to do correctly and this is a very rare case. */
9698 if (modifier != EXPAND_CONST_ADDRESS
9699 && modifier != EXPAND_INITIALIZER
9700 && modifier != EXPAND_MEMORY)
9702 tree t = fold_read_from_constant_string (exp);
9704 if (t)
9705 return expand_expr (t, target, tmode, modifier);
9708 /* If this is a constant index into a constant array,
9709 just get the value from the array. Handle both the cases when
9710 we have an explicit constructor and when our operand is a variable
9711 that was declared const. */
9713 if (modifier != EXPAND_CONST_ADDRESS
9714 && modifier != EXPAND_INITIALIZER
9715 && modifier != EXPAND_MEMORY
9716 && TREE_CODE (array) == CONSTRUCTOR
9717 && ! TREE_SIDE_EFFECTS (array)
9718 && TREE_CODE (index) == INTEGER_CST)
9720 unsigned HOST_WIDE_INT ix;
9721 tree field, value;
9723 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
9724 field, value)
9725 if (tree_int_cst_equal (field, index))
9727 if (!TREE_SIDE_EFFECTS (value))
9728 return expand_expr (fold (value), target, tmode, modifier);
9729 break;
9733 else if (optimize >= 1
9734 && modifier != EXPAND_CONST_ADDRESS
9735 && modifier != EXPAND_INITIALIZER
9736 && modifier != EXPAND_MEMORY
9737 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
9738 && TREE_CODE (index) == INTEGER_CST
9739 && (TREE_CODE (array) == VAR_DECL
9740 || TREE_CODE (array) == CONST_DECL)
9741 && (init = ctor_for_folding (array)) != error_mark_node)
9743 if (TREE_CODE (init) == CONSTRUCTOR)
9745 unsigned HOST_WIDE_INT ix;
9746 tree field, value;
9748 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
9749 field, value)
9750 if (tree_int_cst_equal (field, index))
9752 if (TREE_SIDE_EFFECTS (value))
9753 break;
9755 if (TREE_CODE (value) == CONSTRUCTOR)
9757 /* If VALUE is a CONSTRUCTOR, this
9758 optimization is only useful if
9759 this doesn't store the CONSTRUCTOR
9760 into memory. If it does, it is more
9761 efficient to just load the data from
9762 the array directly. */
9763 rtx ret = expand_constructor (value, target,
9764 modifier, true);
9765 if (ret == NULL_RTX)
9766 break;
9769 return
9770 expand_expr (fold (value), target, tmode, modifier);
9773 else if (TREE_CODE (init) == STRING_CST)
9775 tree low_bound = array_ref_low_bound (exp);
9776 tree index1 = fold_convert_loc (loc, sizetype, treeop1);
9778 /* Optimize the special case of a zero lower bound.
9780 We convert the lower bound to sizetype to avoid problems
9781 with constant folding. E.g. suppose the lower bound is
9782 1 and its mode is QI. Without the conversion
9783 (ARRAY + (INDEX - (unsigned char)1))
9784 becomes
9785 (ARRAY + (-(unsigned char)1) + INDEX)
9786 which becomes
9787 (ARRAY + 255 + INDEX). Oops! */
9788 if (!integer_zerop (low_bound))
9789 index1 = size_diffop_loc (loc, index1,
9790 fold_convert_loc (loc, sizetype,
9791 low_bound));
9793 if (compare_tree_int (index1, TREE_STRING_LENGTH (init)) < 0)
9795 tree type = TREE_TYPE (TREE_TYPE (init));
9796 enum machine_mode mode = TYPE_MODE (type);
9798 if (GET_MODE_CLASS (mode) == MODE_INT
9799 && GET_MODE_SIZE (mode) == 1)
9800 return gen_int_mode (TREE_STRING_POINTER (init)
9801 [TREE_INT_CST_LOW (index1)],
9802 mode);
9807 goto normal_inner_ref;
9809 case COMPONENT_REF:
9810 /* If the operand is a CONSTRUCTOR, we can just extract the
9811 appropriate field if it is present. */
9812 if (TREE_CODE (treeop0) == CONSTRUCTOR)
9814 unsigned HOST_WIDE_INT idx;
9815 tree field, value;
9817 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0),
9818 idx, field, value)
9819 if (field == treeop1
9820 /* We can normally use the value of the field in the
9821 CONSTRUCTOR. However, if this is a bitfield in
9822 an integral mode that we can fit in a HOST_WIDE_INT,
9823 we must mask only the number of bits in the bitfield,
9824 since this is done implicitly by the constructor. If
9825 the bitfield does not meet either of those conditions,
9826 we can't do this optimization. */
9827 && (! DECL_BIT_FIELD (field)
9828 || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
9829 && (GET_MODE_PRECISION (DECL_MODE (field))
9830 <= HOST_BITS_PER_WIDE_INT))))
9832 if (DECL_BIT_FIELD (field)
9833 && modifier == EXPAND_STACK_PARM)
9834 target = 0;
9835 op0 = expand_expr (value, target, tmode, modifier);
9836 if (DECL_BIT_FIELD (field))
9838 HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
9839 enum machine_mode imode = TYPE_MODE (TREE_TYPE (field));
9841 if (TYPE_UNSIGNED (TREE_TYPE (field)))
9843 op1 = gen_int_mode (((HOST_WIDE_INT) 1 << bitsize) - 1,
9844 imode);
9845 op0 = expand_and (imode, op0, op1, target);
9847 else
9849 int count = GET_MODE_PRECISION (imode) - bitsize;
9851 op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
9852 target, 0);
9853 op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
9854 target, 0);
9858 return op0;
9861 goto normal_inner_ref;
9863 case BIT_FIELD_REF:
9864 case ARRAY_RANGE_REF:
9865 normal_inner_ref:
9867 enum machine_mode mode1, mode2;
9868 HOST_WIDE_INT bitsize, bitpos;
9869 tree offset;
9870 int volatilep = 0, must_force_mem;
9871 tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
9872 &mode1, &unsignedp, &volatilep, true);
9873 rtx orig_op0, memloc;
9874 bool mem_attrs_from_type = false;
9876 /* If we got back the original object, something is wrong. Perhaps
9877 we are evaluating an expression too early. In any event, don't
9878 infinitely recurse. */
9879 gcc_assert (tem != exp);
9881 /* If TEM's type is a union of variable size, pass TARGET to the inner
9882 computation, since it will need a temporary and TARGET is known
9883 to have to do. This occurs in unchecked conversion in Ada. */
9884 orig_op0 = op0
9885 = expand_expr (tem,
9886 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
9887 && COMPLETE_TYPE_P (TREE_TYPE (tem))
9888 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
9889 != INTEGER_CST)
9890 && modifier != EXPAND_STACK_PARM
9891 ? target : NULL_RTX),
9892 VOIDmode,
9893 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
9895 /* If the bitfield is volatile, we want to access it in the
9896 field's mode, not the computed mode.
9897 If a MEM has VOIDmode (external with incomplete type),
9898 use BLKmode for it instead. */
9899 if (MEM_P (op0))
9901 if (volatilep && flag_strict_volatile_bitfields > 0)
9902 op0 = adjust_address (op0, mode1, 0);
9903 else if (GET_MODE (op0) == VOIDmode)
9904 op0 = adjust_address (op0, BLKmode, 0);
9907 mode2
9908 = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
9910 /* If we have either an offset, a BLKmode result, or a reference
9911 outside the underlying object, we must force it to memory.
9912 Such a case can occur in Ada if we have unchecked conversion
9913 of an expression from a scalar type to an aggregate type or
9914 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9915 passed a partially uninitialized object or a view-conversion
9916 to a larger size. */
9917 must_force_mem = (offset
9918 || mode1 == BLKmode
9919 || bitpos + bitsize > GET_MODE_BITSIZE (mode2));
9921 /* Handle CONCAT first. */
9922 if (GET_CODE (op0) == CONCAT && !must_force_mem)
9924 if (bitpos == 0
9925 && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)))
9926 return op0;
9927 if (bitpos == 0
9928 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
9929 && bitsize)
9931 op0 = XEXP (op0, 0);
9932 mode2 = GET_MODE (op0);
9934 else if (bitpos == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
9935 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1)))
9936 && bitpos
9937 && bitsize)
9939 op0 = XEXP (op0, 1);
9940 bitpos = 0;
9941 mode2 = GET_MODE (op0);
9943 else
9944 /* Otherwise force into memory. */
9945 must_force_mem = 1;
9948 /* If this is a constant, put it in a register if it is a legitimate
9949 constant and we don't need a memory reference. */
9950 if (CONSTANT_P (op0)
9951 && mode2 != BLKmode
9952 && targetm.legitimate_constant_p (mode2, op0)
9953 && !must_force_mem)
9954 op0 = force_reg (mode2, op0);
9956 /* Otherwise, if this is a constant, try to force it to the constant
9957 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9958 is a legitimate constant. */
9959 else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
9960 op0 = validize_mem (memloc);
9962 /* Otherwise, if this is a constant or the object is not in memory
9963 and need be, put it there. */
9964 else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
9966 tree nt = build_qualified_type (TREE_TYPE (tem),
9967 (TYPE_QUALS (TREE_TYPE (tem))
9968 | TYPE_QUAL_CONST));
9969 memloc = assign_temp (nt, 1, 1);
9970 emit_move_insn (memloc, op0);
9971 op0 = memloc;
9972 mem_attrs_from_type = true;
9975 if (offset)
9977 enum machine_mode address_mode;
9978 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
9979 EXPAND_SUM);
9981 gcc_assert (MEM_P (op0));
9983 address_mode = get_address_mode (op0);
9984 if (GET_MODE (offset_rtx) != address_mode)
9985 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
9987 if (GET_MODE (op0) == BLKmode
9988 /* A constant address in OP0 can have VOIDmode, we must
9989 not try to call force_reg in that case. */
9990 && GET_MODE (XEXP (op0, 0)) != VOIDmode
9991 && bitsize != 0
9992 && (bitpos % bitsize) == 0
9993 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
9994 && MEM_ALIGN (op0) == GET_MODE_ALIGNMENT (mode1))
9996 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
9997 bitpos = 0;
10000 op0 = offset_address (op0, offset_rtx,
10001 highest_pow2_factor (offset));
10004 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10005 record its alignment as BIGGEST_ALIGNMENT. */
10006 if (MEM_P (op0) && bitpos == 0 && offset != 0
10007 && is_aligning_offset (offset, tem))
10008 set_mem_align (op0, BIGGEST_ALIGNMENT);
10010 /* Don't forget about volatility even if this is a bitfield. */
10011 if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
10013 if (op0 == orig_op0)
10014 op0 = copy_rtx (op0);
10016 MEM_VOLATILE_P (op0) = 1;
10019 /* In cases where an aligned union has an unaligned object
10020 as a field, we might be extracting a BLKmode value from
10021 an integer-mode (e.g., SImode) object. Handle this case
10022 by doing the extract into an object as wide as the field
10023 (which we know to be the width of a basic mode), then
10024 storing into memory, and changing the mode to BLKmode. */
10025 if (mode1 == VOIDmode
10026 || REG_P (op0) || GET_CODE (op0) == SUBREG
10027 || (mode1 != BLKmode && ! direct_load[(int) mode1]
10028 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
10029 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
10030 && modifier != EXPAND_CONST_ADDRESS
10031 && modifier != EXPAND_INITIALIZER
10032 && modifier != EXPAND_MEMORY)
10033 /* If the field is volatile, we always want an aligned
10034 access. Do this in following two situations:
10035 1. the access is not already naturally
10036 aligned, otherwise "normal" (non-bitfield) volatile fields
10037 become non-addressable.
10038 2. the bitsize is narrower than the access size. Need
10039 to extract bitfields from the access. */
10040 || (volatilep && flag_strict_volatile_bitfields > 0
10041 && (bitpos % GET_MODE_ALIGNMENT (mode) != 0
10042 || (mode1 != BLKmode
10043 && bitsize < GET_MODE_SIZE (mode1) * BITS_PER_UNIT)))
10044 /* If the field isn't aligned enough to fetch as a memref,
10045 fetch it as a bit field. */
10046 || (mode1 != BLKmode
10047 && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
10048 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
10049 || (MEM_P (op0)
10050 && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
10051 || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
10052 && modifier != EXPAND_MEMORY
10053 && ((modifier == EXPAND_CONST_ADDRESS
10054 || modifier == EXPAND_INITIALIZER)
10055 ? STRICT_ALIGNMENT
10056 : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
10057 || (bitpos % BITS_PER_UNIT != 0)))
10058 /* If the type and the field are a constant size and the
10059 size of the type isn't the same size as the bitfield,
10060 we must use bitfield operations. */
10061 || (bitsize >= 0
10062 && TYPE_SIZE (TREE_TYPE (exp))
10063 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
10064 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
10065 bitsize)))
10067 enum machine_mode ext_mode = mode;
10069 if (ext_mode == BLKmode
10070 && ! (target != 0 && MEM_P (op0)
10071 && MEM_P (target)
10072 && bitpos % BITS_PER_UNIT == 0))
10073 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
10075 if (ext_mode == BLKmode)
10077 if (target == 0)
10078 target = assign_temp (type, 1, 1);
10080 if (bitsize == 0)
10081 return target;
10083 /* In this case, BITPOS must start at a byte boundary and
10084 TARGET, if specified, must be a MEM. */
10085 gcc_assert (MEM_P (op0)
10086 && (!target || MEM_P (target))
10087 && !(bitpos % BITS_PER_UNIT));
10089 emit_block_move (target,
10090 adjust_address (op0, VOIDmode,
10091 bitpos / BITS_PER_UNIT),
10092 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
10093 / BITS_PER_UNIT),
10094 (modifier == EXPAND_STACK_PARM
10095 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
10097 return target;
10100 op0 = validize_mem (op0);
10102 if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
10103 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10105 op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
10106 (modifier == EXPAND_STACK_PARM
10107 ? NULL_RTX : target),
10108 ext_mode, ext_mode);
10110 /* If the result is a record type and BITSIZE is narrower than
10111 the mode of OP0, an integral mode, and this is a big endian
10112 machine, we must put the field into the high-order bits. */
10113 if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
10114 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
10115 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
10116 op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
10117 GET_MODE_BITSIZE (GET_MODE (op0))
10118 - bitsize, op0, 1);
10120 /* If the result type is BLKmode, store the data into a temporary
10121 of the appropriate type, but with the mode corresponding to the
10122 mode for the data we have (op0's mode). It's tempting to make
10123 this a constant type, since we know it's only being stored once,
10124 but that can cause problems if we are taking the address of this
10125 COMPONENT_REF because the MEM of any reference via that address
10126 will have flags corresponding to the type, which will not
10127 necessarily be constant. */
10128 if (mode == BLKmode)
10130 rtx new_rtx;
10132 new_rtx = assign_stack_temp_for_type (ext_mode,
10133 GET_MODE_BITSIZE (ext_mode),
10134 type);
10135 emit_move_insn (new_rtx, op0);
10136 op0 = copy_rtx (new_rtx);
10137 PUT_MODE (op0, BLKmode);
10140 return op0;
10143 /* If the result is BLKmode, use that to access the object
10144 now as well. */
10145 if (mode == BLKmode)
10146 mode1 = BLKmode;
10148 /* Get a reference to just this component. */
10149 if (modifier == EXPAND_CONST_ADDRESS
10150 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
10151 op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
10152 else
10153 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
10155 if (op0 == orig_op0)
10156 op0 = copy_rtx (op0);
10158 /* If op0 is a temporary because of forcing to memory, pass only the
10159 type to set_mem_attributes so that the original expression is never
10160 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10161 if (mem_attrs_from_type)
10162 set_mem_attributes (op0, type, 0);
10163 else
10164 set_mem_attributes (op0, exp, 0);
10166 if (REG_P (XEXP (op0, 0)))
10167 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10169 MEM_VOLATILE_P (op0) |= volatilep;
10170 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
10171 || modifier == EXPAND_CONST_ADDRESS
10172 || modifier == EXPAND_INITIALIZER)
10173 return op0;
10175 if (target == 0)
10176 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
10178 convert_move (target, op0, unsignedp);
10179 return target;
10182 case OBJ_TYPE_REF:
10183 return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
10185 case CALL_EXPR:
10186 /* All valid uses of __builtin_va_arg_pack () are removed during
10187 inlining. */
10188 if (CALL_EXPR_VA_ARG_PACK (exp))
10189 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
10191 tree fndecl = get_callee_fndecl (exp), attr;
10193 if (fndecl
10194 && (attr = lookup_attribute ("error",
10195 DECL_ATTRIBUTES (fndecl))) != NULL)
10196 error ("%Kcall to %qs declared with attribute error: %s",
10197 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
10198 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
10199 if (fndecl
10200 && (attr = lookup_attribute ("warning",
10201 DECL_ATTRIBUTES (fndecl))) != NULL)
10202 warning_at (tree_nonartificial_location (exp),
10203 0, "%Kcall to %qs declared with attribute warning: %s",
10204 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
10205 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
10207 /* Check for a built-in function. */
10208 if (fndecl && DECL_BUILT_IN (fndecl))
10210 gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
10211 return expand_builtin (exp, target, subtarget, tmode, ignore);
10214 return expand_call (exp, target, ignore);
10216 case VIEW_CONVERT_EXPR:
10217 op0 = NULL_RTX;
10219 /* If we are converting to BLKmode, try to avoid an intermediate
10220 temporary by fetching an inner memory reference. */
10221 if (mode == BLKmode
10222 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
10223 && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
10224 && handled_component_p (treeop0))
10226 enum machine_mode mode1;
10227 HOST_WIDE_INT bitsize, bitpos;
10228 tree offset;
10229 int unsignedp;
10230 int volatilep = 0;
10231 tree tem
10232 = get_inner_reference (treeop0, &bitsize, &bitpos,
10233 &offset, &mode1, &unsignedp, &volatilep,
10234 true);
10235 rtx orig_op0;
10237 /* ??? We should work harder and deal with non-zero offsets. */
10238 if (!offset
10239 && (bitpos % BITS_PER_UNIT) == 0
10240 && bitsize >= 0
10241 && compare_tree_int (TYPE_SIZE (type), bitsize) == 0)
10243 /* See the normal_inner_ref case for the rationale. */
10244 orig_op0
10245 = expand_expr (tem,
10246 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
10247 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
10248 != INTEGER_CST)
10249 && modifier != EXPAND_STACK_PARM
10250 ? target : NULL_RTX),
10251 VOIDmode,
10252 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
10254 if (MEM_P (orig_op0))
10256 op0 = orig_op0;
10258 /* Get a reference to just this component. */
10259 if (modifier == EXPAND_CONST_ADDRESS
10260 || modifier == EXPAND_SUM
10261 || modifier == EXPAND_INITIALIZER)
10262 op0 = adjust_address_nv (op0, mode, bitpos / BITS_PER_UNIT);
10263 else
10264 op0 = adjust_address (op0, mode, bitpos / BITS_PER_UNIT);
10266 if (op0 == orig_op0)
10267 op0 = copy_rtx (op0);
10269 set_mem_attributes (op0, treeop0, 0);
10270 if (REG_P (XEXP (op0, 0)))
10271 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10273 MEM_VOLATILE_P (op0) |= volatilep;
10278 if (!op0)
10279 op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
10281 /* If the input and output modes are both the same, we are done. */
10282 if (mode == GET_MODE (op0))
10284 /* If neither mode is BLKmode, and both modes are the same size
10285 then we can use gen_lowpart. */
10286 else if (mode != BLKmode && GET_MODE (op0) != BLKmode
10287 && (GET_MODE_PRECISION (mode)
10288 == GET_MODE_PRECISION (GET_MODE (op0)))
10289 && !COMPLEX_MODE_P (GET_MODE (op0)))
10291 if (GET_CODE (op0) == SUBREG)
10292 op0 = force_reg (GET_MODE (op0), op0);
10293 temp = gen_lowpart_common (mode, op0);
10294 if (temp)
10295 op0 = temp;
10296 else
10298 if (!REG_P (op0) && !MEM_P (op0))
10299 op0 = force_reg (GET_MODE (op0), op0);
10300 op0 = gen_lowpart (mode, op0);
10303 /* If both types are integral, convert from one mode to the other. */
10304 else if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0)))
10305 op0 = convert_modes (mode, GET_MODE (op0), op0,
10306 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10307 /* As a last resort, spill op0 to memory, and reload it in a
10308 different mode. */
10309 else if (!MEM_P (op0))
10311 /* If the operand is not a MEM, force it into memory. Since we
10312 are going to be changing the mode of the MEM, don't call
10313 force_const_mem for constants because we don't allow pool
10314 constants to change mode. */
10315 tree inner_type = TREE_TYPE (treeop0);
10317 gcc_assert (!TREE_ADDRESSABLE (exp));
10319 if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
10320 target
10321 = assign_stack_temp_for_type
10322 (TYPE_MODE (inner_type),
10323 GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
10325 emit_move_insn (target, op0);
10326 op0 = target;
10329 /* At this point, OP0 is in the correct mode. If the output type is
10330 such that the operand is known to be aligned, indicate that it is.
10331 Otherwise, we need only be concerned about alignment for non-BLKmode
10332 results. */
10333 if (MEM_P (op0))
10335 enum insn_code icode;
10337 if (TYPE_ALIGN_OK (type))
10339 /* ??? Copying the MEM without substantially changing it might
10340 run afoul of the code handling volatile memory references in
10341 store_expr, which assumes that TARGET is returned unmodified
10342 if it has been used. */
10343 op0 = copy_rtx (op0);
10344 set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
10346 else if (mode != BLKmode
10347 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode)
10348 /* If the target does have special handling for unaligned
10349 loads of mode then use them. */
10350 && ((icode = optab_handler (movmisalign_optab, mode))
10351 != CODE_FOR_nothing))
10353 rtx reg, insn;
10355 op0 = adjust_address (op0, mode, 0);
10356 /* We've already validated the memory, and we're creating a
10357 new pseudo destination. The predicates really can't
10358 fail. */
10359 reg = gen_reg_rtx (mode);
10361 /* Nor can the insn generator. */
10362 insn = GEN_FCN (icode) (reg, op0);
10363 emit_insn (insn);
10364 return reg;
10366 else if (STRICT_ALIGNMENT
10367 && mode != BLKmode
10368 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
10370 tree inner_type = TREE_TYPE (treeop0);
10371 HOST_WIDE_INT temp_size
10372 = MAX (int_size_in_bytes (inner_type),
10373 (HOST_WIDE_INT) GET_MODE_SIZE (mode));
10374 rtx new_rtx
10375 = assign_stack_temp_for_type (mode, temp_size, type);
10376 rtx new_with_op0_mode
10377 = adjust_address (new_rtx, GET_MODE (op0), 0);
10379 gcc_assert (!TREE_ADDRESSABLE (exp));
10381 if (GET_MODE (op0) == BLKmode)
10382 emit_block_move (new_with_op0_mode, op0,
10383 GEN_INT (GET_MODE_SIZE (mode)),
10384 (modifier == EXPAND_STACK_PARM
10385 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
10386 else
10387 emit_move_insn (new_with_op0_mode, op0);
10389 op0 = new_rtx;
10392 op0 = adjust_address (op0, mode, 0);
10395 return op0;
10397 case MODIFY_EXPR:
10399 tree lhs = treeop0;
10400 tree rhs = treeop1;
10401 gcc_assert (ignore);
10403 /* Check for |= or &= of a bitfield of size one into another bitfield
10404 of size 1. In this case, (unless we need the result of the
10405 assignment) we can do this more efficiently with a
10406 test followed by an assignment, if necessary.
10408 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10409 things change so we do, this code should be enhanced to
10410 support it. */
10411 if (TREE_CODE (lhs) == COMPONENT_REF
10412 && (TREE_CODE (rhs) == BIT_IOR_EXPR
10413 || TREE_CODE (rhs) == BIT_AND_EXPR)
10414 && TREE_OPERAND (rhs, 0) == lhs
10415 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
10416 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
10417 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
10419 rtx label = gen_label_rtx ();
10420 int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
10421 do_jump (TREE_OPERAND (rhs, 1),
10422 value ? label : 0,
10423 value ? 0 : label, -1);
10424 expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
10425 false);
10426 do_pending_stack_adjust ();
10427 emit_label (label);
10428 return const0_rtx;
10431 expand_assignment (lhs, rhs, false);
10432 return const0_rtx;
10435 case ADDR_EXPR:
10436 return expand_expr_addr_expr (exp, target, tmode, modifier);
10438 case REALPART_EXPR:
10439 op0 = expand_normal (treeop0);
10440 return read_complex_part (op0, false);
10442 case IMAGPART_EXPR:
10443 op0 = expand_normal (treeop0);
10444 return read_complex_part (op0, true);
10446 case RETURN_EXPR:
10447 case LABEL_EXPR:
10448 case GOTO_EXPR:
10449 case SWITCH_EXPR:
10450 case ASM_EXPR:
10451 /* Expanded in cfgexpand.c. */
10452 gcc_unreachable ();
10454 case TRY_CATCH_EXPR:
10455 case CATCH_EXPR:
10456 case EH_FILTER_EXPR:
10457 case TRY_FINALLY_EXPR:
10458 /* Lowered by tree-eh.c. */
10459 gcc_unreachable ();
10461 case WITH_CLEANUP_EXPR:
10462 case CLEANUP_POINT_EXPR:
10463 case TARGET_EXPR:
10464 case CASE_LABEL_EXPR:
10465 case VA_ARG_EXPR:
10466 case BIND_EXPR:
10467 case INIT_EXPR:
10468 case CONJ_EXPR:
10469 case COMPOUND_EXPR:
10470 case PREINCREMENT_EXPR:
10471 case PREDECREMENT_EXPR:
10472 case POSTINCREMENT_EXPR:
10473 case POSTDECREMENT_EXPR:
10474 case LOOP_EXPR:
10475 case EXIT_EXPR:
10476 case COMPOUND_LITERAL_EXPR:
10477 /* Lowered by gimplify.c. */
10478 gcc_unreachable ();
10480 case FDESC_EXPR:
10481 /* Function descriptors are not valid except for as
10482 initialization constants, and should not be expanded. */
10483 gcc_unreachable ();
10485 case WITH_SIZE_EXPR:
10486 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10487 have pulled out the size to use in whatever context it needed. */
10488 return expand_expr_real (treeop0, original_target, tmode,
10489 modifier, alt_rtl);
10491 default:
10492 return expand_expr_real_2 (&ops, target, tmode, modifier);
10496 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10497 signedness of TYPE), possibly returning the result in TARGET. */
10498 static rtx
10499 reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
10501 HOST_WIDE_INT prec = TYPE_PRECISION (type);
10502 if (target && GET_MODE (target) != GET_MODE (exp))
10503 target = 0;
10504 /* For constant values, reduce using build_int_cst_type. */
10505 if (CONST_INT_P (exp))
10507 HOST_WIDE_INT value = INTVAL (exp);
10508 tree t = build_int_cst_type (type, value);
10509 return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
10511 else if (TYPE_UNSIGNED (type))
10513 rtx mask = immed_double_int_const (double_int::mask (prec),
10514 GET_MODE (exp));
10515 return expand_and (GET_MODE (exp), exp, mask, target);
10517 else
10519 int count = GET_MODE_PRECISION (GET_MODE (exp)) - prec;
10520 exp = expand_shift (LSHIFT_EXPR, GET_MODE (exp),
10521 exp, count, target, 0);
10522 return expand_shift (RSHIFT_EXPR, GET_MODE (exp),
10523 exp, count, target, 0);
10527 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10528 when applied to the address of EXP produces an address known to be
10529 aligned more than BIGGEST_ALIGNMENT. */
10531 static int
10532 is_aligning_offset (const_tree offset, const_tree exp)
10534 /* Strip off any conversions. */
10535 while (CONVERT_EXPR_P (offset))
10536 offset = TREE_OPERAND (offset, 0);
10538 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10539 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10540 if (TREE_CODE (offset) != BIT_AND_EXPR
10541 || !host_integerp (TREE_OPERAND (offset, 1), 1)
10542 || compare_tree_int (TREE_OPERAND (offset, 1),
10543 BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
10544 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
10545 return 0;
10547 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10548 It must be NEGATE_EXPR. Then strip any more conversions. */
10549 offset = TREE_OPERAND (offset, 0);
10550 while (CONVERT_EXPR_P (offset))
10551 offset = TREE_OPERAND (offset, 0);
10553 if (TREE_CODE (offset) != NEGATE_EXPR)
10554 return 0;
10556 offset = TREE_OPERAND (offset, 0);
10557 while (CONVERT_EXPR_P (offset))
10558 offset = TREE_OPERAND (offset, 0);
10560 /* This must now be the address of EXP. */
10561 return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
10564 /* Return the tree node if an ARG corresponds to a string constant or zero
10565 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10566 in bytes within the string that ARG is accessing. The type of the
10567 offset will be `sizetype'. */
10569 tree
10570 string_constant (tree arg, tree *ptr_offset)
10572 tree array, offset, lower_bound;
10573 STRIP_NOPS (arg);
10575 if (TREE_CODE (arg) == ADDR_EXPR)
10577 if (TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
10579 *ptr_offset = size_zero_node;
10580 return TREE_OPERAND (arg, 0);
10582 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL)
10584 array = TREE_OPERAND (arg, 0);
10585 offset = size_zero_node;
10587 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF)
10589 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10590 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10591 if (TREE_CODE (array) != STRING_CST
10592 && TREE_CODE (array) != VAR_DECL)
10593 return 0;
10595 /* Check if the array has a nonzero lower bound. */
10596 lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
10597 if (!integer_zerop (lower_bound))
10599 /* If the offset and base aren't both constants, return 0. */
10600 if (TREE_CODE (lower_bound) != INTEGER_CST)
10601 return 0;
10602 if (TREE_CODE (offset) != INTEGER_CST)
10603 return 0;
10604 /* Adjust offset by the lower bound. */
10605 offset = size_diffop (fold_convert (sizetype, offset),
10606 fold_convert (sizetype, lower_bound));
10609 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == MEM_REF)
10611 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10612 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10613 if (TREE_CODE (array) != ADDR_EXPR)
10614 return 0;
10615 array = TREE_OPERAND (array, 0);
10616 if (TREE_CODE (array) != STRING_CST
10617 && TREE_CODE (array) != VAR_DECL)
10618 return 0;
10620 else
10621 return 0;
10623 else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
10625 tree arg0 = TREE_OPERAND (arg, 0);
10626 tree arg1 = TREE_OPERAND (arg, 1);
10628 STRIP_NOPS (arg0);
10629 STRIP_NOPS (arg1);
10631 if (TREE_CODE (arg0) == ADDR_EXPR
10632 && (TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST
10633 || TREE_CODE (TREE_OPERAND (arg0, 0)) == VAR_DECL))
10635 array = TREE_OPERAND (arg0, 0);
10636 offset = arg1;
10638 else if (TREE_CODE (arg1) == ADDR_EXPR
10639 && (TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST
10640 || TREE_CODE (TREE_OPERAND (arg1, 0)) == VAR_DECL))
10642 array = TREE_OPERAND (arg1, 0);
10643 offset = arg0;
10645 else
10646 return 0;
10648 else
10649 return 0;
10651 if (TREE_CODE (array) == STRING_CST)
10653 *ptr_offset = fold_convert (sizetype, offset);
10654 return array;
10656 else if (TREE_CODE (array) == VAR_DECL
10657 || TREE_CODE (array) == CONST_DECL)
10659 int length;
10660 tree init = ctor_for_folding (array);
10662 /* Variables initialized to string literals can be handled too. */
10663 if (init == error_mark_node
10664 || !init
10665 || TREE_CODE (init) != STRING_CST)
10666 return 0;
10668 /* Avoid const char foo[4] = "abcde"; */
10669 if (DECL_SIZE_UNIT (array) == NULL_TREE
10670 || TREE_CODE (DECL_SIZE_UNIT (array)) != INTEGER_CST
10671 || (length = TREE_STRING_LENGTH (init)) <= 0
10672 || compare_tree_int (DECL_SIZE_UNIT (array), length) < 0)
10673 return 0;
10675 /* If variable is bigger than the string literal, OFFSET must be constant
10676 and inside of the bounds of the string literal. */
10677 offset = fold_convert (sizetype, offset);
10678 if (compare_tree_int (DECL_SIZE_UNIT (array), length) > 0
10679 && (! host_integerp (offset, 1)
10680 || compare_tree_int (offset, length) >= 0))
10681 return 0;
10683 *ptr_offset = offset;
10684 return init;
10687 return 0;
10690 /* Generate code to calculate OPS, and exploded expression
10691 using a store-flag instruction and return an rtx for the result.
10692 OPS reflects a comparison.
10694 If TARGET is nonzero, store the result there if convenient.
10696 Return zero if there is no suitable set-flag instruction
10697 available on this machine.
10699 Once expand_expr has been called on the arguments of the comparison,
10700 we are committed to doing the store flag, since it is not safe to
10701 re-evaluate the expression. We emit the store-flag insn by calling
10702 emit_store_flag, but only expand the arguments if we have a reason
10703 to believe that emit_store_flag will be successful. If we think that
10704 it will, but it isn't, we have to simulate the store-flag with a
10705 set/jump/set sequence. */
10707 static rtx
10708 do_store_flag (sepops ops, rtx target, enum machine_mode mode)
10710 enum rtx_code code;
10711 tree arg0, arg1, type;
10712 tree tem;
10713 enum machine_mode operand_mode;
10714 int unsignedp;
10715 rtx op0, op1;
10716 rtx subtarget = target;
10717 location_t loc = ops->location;
10719 arg0 = ops->op0;
10720 arg1 = ops->op1;
10722 /* Don't crash if the comparison was erroneous. */
10723 if (arg0 == error_mark_node || arg1 == error_mark_node)
10724 return const0_rtx;
10726 type = TREE_TYPE (arg0);
10727 operand_mode = TYPE_MODE (type);
10728 unsignedp = TYPE_UNSIGNED (type);
10730 /* We won't bother with BLKmode store-flag operations because it would mean
10731 passing a lot of information to emit_store_flag. */
10732 if (operand_mode == BLKmode)
10733 return 0;
10735 /* We won't bother with store-flag operations involving function pointers
10736 when function pointers must be canonicalized before comparisons. */
10737 #ifdef HAVE_canonicalize_funcptr_for_compare
10738 if (HAVE_canonicalize_funcptr_for_compare
10739 && ((TREE_CODE (TREE_TYPE (arg0)) == POINTER_TYPE
10740 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0)))
10741 == FUNCTION_TYPE))
10742 || (TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE
10743 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1)))
10744 == FUNCTION_TYPE))))
10745 return 0;
10746 #endif
10748 STRIP_NOPS (arg0);
10749 STRIP_NOPS (arg1);
10751 /* For vector typed comparisons emit code to generate the desired
10752 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10753 expander for this. */
10754 if (TREE_CODE (ops->type) == VECTOR_TYPE)
10756 tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
10757 tree if_true = constant_boolean_node (true, ops->type);
10758 tree if_false = constant_boolean_node (false, ops->type);
10759 return expand_vec_cond_expr (ops->type, ifexp, if_true, if_false, target);
10762 /* Get the rtx comparison code to use. We know that EXP is a comparison
10763 operation of some type. Some comparisons against 1 and -1 can be
10764 converted to comparisons with zero. Do so here so that the tests
10765 below will be aware that we have a comparison with zero. These
10766 tests will not catch constants in the first operand, but constants
10767 are rarely passed as the first operand. */
10769 switch (ops->code)
10771 case EQ_EXPR:
10772 code = EQ;
10773 break;
10774 case NE_EXPR:
10775 code = NE;
10776 break;
10777 case LT_EXPR:
10778 if (integer_onep (arg1))
10779 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
10780 else
10781 code = unsignedp ? LTU : LT;
10782 break;
10783 case LE_EXPR:
10784 if (! unsignedp && integer_all_onesp (arg1))
10785 arg1 = integer_zero_node, code = LT;
10786 else
10787 code = unsignedp ? LEU : LE;
10788 break;
10789 case GT_EXPR:
10790 if (! unsignedp && integer_all_onesp (arg1))
10791 arg1 = integer_zero_node, code = GE;
10792 else
10793 code = unsignedp ? GTU : GT;
10794 break;
10795 case GE_EXPR:
10796 if (integer_onep (arg1))
10797 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
10798 else
10799 code = unsignedp ? GEU : GE;
10800 break;
10802 case UNORDERED_EXPR:
10803 code = UNORDERED;
10804 break;
10805 case ORDERED_EXPR:
10806 code = ORDERED;
10807 break;
10808 case UNLT_EXPR:
10809 code = UNLT;
10810 break;
10811 case UNLE_EXPR:
10812 code = UNLE;
10813 break;
10814 case UNGT_EXPR:
10815 code = UNGT;
10816 break;
10817 case UNGE_EXPR:
10818 code = UNGE;
10819 break;
10820 case UNEQ_EXPR:
10821 code = UNEQ;
10822 break;
10823 case LTGT_EXPR:
10824 code = LTGT;
10825 break;
10827 default:
10828 gcc_unreachable ();
10831 /* Put a constant second. */
10832 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
10833 || TREE_CODE (arg0) == FIXED_CST)
10835 tem = arg0; arg0 = arg1; arg1 = tem;
10836 code = swap_condition (code);
10839 /* If this is an equality or inequality test of a single bit, we can
10840 do this by shifting the bit being tested to the low-order bit and
10841 masking the result with the constant 1. If the condition was EQ,
10842 we xor it with 1. This does not require an scc insn and is faster
10843 than an scc insn even if we have it.
10845 The code to make this transformation was moved into fold_single_bit_test,
10846 so we just call into the folder and expand its result. */
10848 if ((code == NE || code == EQ)
10849 && integer_zerop (arg1)
10850 && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
10852 gimple srcstmt = get_def_for_expr (arg0, BIT_AND_EXPR);
10853 if (srcstmt
10854 && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
10856 enum tree_code tcode = code == NE ? NE_EXPR : EQ_EXPR;
10857 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10858 tree temp = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg1),
10859 gimple_assign_rhs1 (srcstmt),
10860 gimple_assign_rhs2 (srcstmt));
10861 temp = fold_single_bit_test (loc, tcode, temp, arg1, type);
10862 if (temp)
10863 return expand_expr (temp, target, VOIDmode, EXPAND_NORMAL);
10867 if (! get_subtarget (target)
10868 || GET_MODE (subtarget) != operand_mode)
10869 subtarget = 0;
10871 expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
10873 if (target == 0)
10874 target = gen_reg_rtx (mode);
10876 /* Try a cstore if possible. */
10877 return emit_store_flag_force (target, code, op0, op1,
10878 operand_mode, unsignedp,
10879 (TYPE_PRECISION (ops->type) == 1
10880 && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
10884 /* Stubs in case we haven't got a casesi insn. */
10885 #ifndef HAVE_casesi
10886 # define HAVE_casesi 0
10887 # define gen_casesi(a, b, c, d, e) (0)
10888 # define CODE_FOR_casesi CODE_FOR_nothing
10889 #endif
10891 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10892 0 otherwise (i.e. if there is no casesi instruction).
10894 DEFAULT_PROBABILITY is the probability of jumping to the default
10895 label. */
10897 try_casesi (tree index_type, tree index_expr, tree minval, tree range,
10898 rtx table_label, rtx default_label, rtx fallback_label,
10899 int default_probability)
10901 struct expand_operand ops[5];
10902 enum machine_mode index_mode = SImode;
10903 rtx op1, op2, index;
10905 if (! HAVE_casesi)
10906 return 0;
10908 /* Convert the index to SImode. */
10909 if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
10911 enum machine_mode omode = TYPE_MODE (index_type);
10912 rtx rangertx = expand_normal (range);
10914 /* We must handle the endpoints in the original mode. */
10915 index_expr = build2 (MINUS_EXPR, index_type,
10916 index_expr, minval);
10917 minval = integer_zero_node;
10918 index = expand_normal (index_expr);
10919 if (default_label)
10920 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
10921 omode, 1, default_label,
10922 default_probability);
10923 /* Now we can safely truncate. */
10924 index = convert_to_mode (index_mode, index, 0);
10926 else
10928 if (TYPE_MODE (index_type) != index_mode)
10930 index_type = lang_hooks.types.type_for_mode (index_mode, 0);
10931 index_expr = fold_convert (index_type, index_expr);
10934 index = expand_normal (index_expr);
10937 do_pending_stack_adjust ();
10939 op1 = expand_normal (minval);
10940 op2 = expand_normal (range);
10942 create_input_operand (&ops[0], index, index_mode);
10943 create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
10944 create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
10945 create_fixed_operand (&ops[3], table_label);
10946 create_fixed_operand (&ops[4], (default_label
10947 ? default_label
10948 : fallback_label));
10949 expand_jump_insn (CODE_FOR_casesi, 5, ops);
10950 return 1;
10953 /* Attempt to generate a tablejump instruction; same concept. */
10954 #ifndef HAVE_tablejump
10955 #define HAVE_tablejump 0
10956 #define gen_tablejump(x, y) (0)
10957 #endif
10959 /* Subroutine of the next function.
10961 INDEX is the value being switched on, with the lowest value
10962 in the table already subtracted.
10963 MODE is its expected mode (needed if INDEX is constant).
10964 RANGE is the length of the jump table.
10965 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10967 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10968 index value is out of range.
10969 DEFAULT_PROBABILITY is the probability of jumping to
10970 the default label. */
10972 static void
10973 do_tablejump (rtx index, enum machine_mode mode, rtx range, rtx table_label,
10974 rtx default_label, int default_probability)
10976 rtx temp, vector;
10978 if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
10979 cfun->cfg->max_jumptable_ents = INTVAL (range);
10981 /* Do an unsigned comparison (in the proper mode) between the index
10982 expression and the value which represents the length of the range.
10983 Since we just finished subtracting the lower bound of the range
10984 from the index expression, this comparison allows us to simultaneously
10985 check that the original index expression value is both greater than
10986 or equal to the minimum value of the range and less than or equal to
10987 the maximum value of the range. */
10989 if (default_label)
10990 emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
10991 default_label, default_probability);
10994 /* If index is in range, it must fit in Pmode.
10995 Convert to Pmode so we can index with it. */
10996 if (mode != Pmode)
10997 index = convert_to_mode (Pmode, index, 1);
10999 /* Don't let a MEM slip through, because then INDEX that comes
11000 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11001 and break_out_memory_refs will go to work on it and mess it up. */
11002 #ifdef PIC_CASE_VECTOR_ADDRESS
11003 if (flag_pic && !REG_P (index))
11004 index = copy_to_mode_reg (Pmode, index);
11005 #endif
11007 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11008 GET_MODE_SIZE, because this indicates how large insns are. The other
11009 uses should all be Pmode, because they are addresses. This code
11010 could fail if addresses and insns are not the same size. */
11011 index = gen_rtx_PLUS
11012 (Pmode,
11013 gen_rtx_MULT (Pmode, index,
11014 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE), Pmode)),
11015 gen_rtx_LABEL_REF (Pmode, table_label));
11016 #ifdef PIC_CASE_VECTOR_ADDRESS
11017 if (flag_pic)
11018 index = PIC_CASE_VECTOR_ADDRESS (index);
11019 else
11020 #endif
11021 index = memory_address (CASE_VECTOR_MODE, index);
11022 temp = gen_reg_rtx (CASE_VECTOR_MODE);
11023 vector = gen_const_mem (CASE_VECTOR_MODE, index);
11024 convert_move (temp, vector, 0);
11026 emit_jump_insn (gen_tablejump (temp, table_label));
11028 /* If we are generating PIC code or if the table is PC-relative, the
11029 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11030 if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
11031 emit_barrier ();
11035 try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
11036 rtx table_label, rtx default_label, int default_probability)
11038 rtx index;
11040 if (! HAVE_tablejump)
11041 return 0;
11043 index_expr = fold_build2 (MINUS_EXPR, index_type,
11044 fold_convert (index_type, index_expr),
11045 fold_convert (index_type, minval));
11046 index = expand_normal (index_expr);
11047 do_pending_stack_adjust ();
11049 do_tablejump (index, TYPE_MODE (index_type),
11050 convert_modes (TYPE_MODE (index_type),
11051 TYPE_MODE (TREE_TYPE (range)),
11052 expand_normal (range),
11053 TYPE_UNSIGNED (TREE_TYPE (range))),
11054 table_label, default_label, default_probability);
11055 return 1;
11058 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11059 static rtx
11060 const_vector_from_tree (tree exp)
11062 rtvec v;
11063 unsigned i;
11064 int units;
11065 tree elt;
11066 enum machine_mode inner, mode;
11068 mode = TYPE_MODE (TREE_TYPE (exp));
11070 if (initializer_zerop (exp))
11071 return CONST0_RTX (mode);
11073 units = GET_MODE_NUNITS (mode);
11074 inner = GET_MODE_INNER (mode);
11076 v = rtvec_alloc (units);
11078 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
11080 elt = VECTOR_CST_ELT (exp, i);
11082 if (TREE_CODE (elt) == REAL_CST)
11083 RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
11084 inner);
11085 else if (TREE_CODE (elt) == FIXED_CST)
11086 RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
11087 inner);
11088 else
11089 RTVEC_ELT (v, i) = immed_double_int_const (tree_to_double_int (elt),
11090 inner);
11093 return gen_rtx_CONST_VECTOR (mode, v);
11096 /* Build a decl for a personality function given a language prefix. */
11098 tree
11099 build_personality_function (const char *lang)
11101 const char *unwind_and_version;
11102 tree decl, type;
11103 char *name;
11105 switch (targetm_common.except_unwind_info (&global_options))
11107 case UI_NONE:
11108 return NULL;
11109 case UI_SJLJ:
11110 unwind_and_version = "_sj0";
11111 break;
11112 case UI_DWARF2:
11113 case UI_TARGET:
11114 unwind_and_version = "_v0";
11115 break;
11116 case UI_SEH:
11117 unwind_and_version = "_seh0";
11118 break;
11119 default:
11120 gcc_unreachable ();
11123 name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
11125 type = build_function_type_list (integer_type_node, integer_type_node,
11126 long_long_unsigned_type_node,
11127 ptr_type_node, ptr_type_node, NULL_TREE);
11128 decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
11129 get_identifier (name), type);
11130 DECL_ARTIFICIAL (decl) = 1;
11131 DECL_EXTERNAL (decl) = 1;
11132 TREE_PUBLIC (decl) = 1;
11134 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11135 are the flags assigned by targetm.encode_section_info. */
11136 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
11138 return decl;
11141 /* Extracts the personality function of DECL and returns the corresponding
11142 libfunc. */
11145 get_personality_function (tree decl)
11147 tree personality = DECL_FUNCTION_PERSONALITY (decl);
11148 enum eh_personality_kind pk;
11150 pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
11151 if (pk == eh_personality_none)
11152 return NULL;
11154 if (!personality
11155 && pk == eh_personality_any)
11156 personality = lang_hooks.eh_personality ();
11158 if (pk == eh_personality_lang)
11159 gcc_assert (personality != NULL_TREE);
11161 return XEXP (DECL_RTL (personality), 0);
11164 #include "gt-expr.h"