* config/epiphany/epiphany.h (EPIPHANY_LIBRARY_EXTRA_SPEC): Define.
[official-gcc.git] / gcc / expr.c
blob48e2581bdaf22003b29602d36ef6ed19a3c662cc
1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
4 2012 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "machmode.h"
27 #include "rtl.h"
28 #include "tree.h"
29 #include "flags.h"
30 #include "regs.h"
31 #include "hard-reg-set.h"
32 #include "except.h"
33 #include "function.h"
34 #include "insn-config.h"
35 #include "insn-attr.h"
36 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
37 #include "expr.h"
38 #include "optabs.h"
39 #include "libfuncs.h"
40 #include "recog.h"
41 #include "reload.h"
42 #include "typeclass.h"
43 #include "toplev.h"
44 #include "langhooks.h"
45 #include "intl.h"
46 #include "tm_p.h"
47 #include "tree-iterator.h"
48 #include "tree-flow.h"
49 #include "target.h"
50 #include "common/common-target.h"
51 #include "timevar.h"
52 #include "df.h"
53 #include "diagnostic.h"
54 #include "ssaexpand.h"
55 #include "target-globals.h"
56 #include "params.h"
58 /* Decide whether a function's arguments should be processed
59 from first to last or from last to first.
61 They should if the stack and args grow in opposite directions, but
62 only if we have push insns. */
64 #ifdef PUSH_ROUNDING
66 #ifndef PUSH_ARGS_REVERSED
67 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
68 #define PUSH_ARGS_REVERSED /* If it's last to first. */
69 #endif
70 #endif
72 #endif
74 #ifndef STACK_PUSH_CODE
75 #ifdef STACK_GROWS_DOWNWARD
76 #define STACK_PUSH_CODE PRE_DEC
77 #else
78 #define STACK_PUSH_CODE PRE_INC
79 #endif
80 #endif
83 /* If this is nonzero, we do not bother generating VOLATILE
84 around volatile memory references, and we are willing to
85 output indirect addresses. If cse is to follow, we reject
86 indirect addresses so a useful potential cse is generated;
87 if it is used only once, instruction combination will produce
88 the same indirect address eventually. */
89 int cse_not_expected;
91 /* This structure is used by move_by_pieces to describe the move to
92 be performed. */
93 struct move_by_pieces_d
95 rtx to;
96 rtx to_addr;
97 int autinc_to;
98 int explicit_inc_to;
99 rtx from;
100 rtx from_addr;
101 int autinc_from;
102 int explicit_inc_from;
103 unsigned HOST_WIDE_INT len;
104 HOST_WIDE_INT offset;
105 int reverse;
108 /* This structure is used by store_by_pieces to describe the clear to
109 be performed. */
111 struct store_by_pieces_d
113 rtx to;
114 rtx to_addr;
115 int autinc_to;
116 int explicit_inc_to;
117 unsigned HOST_WIDE_INT len;
118 HOST_WIDE_INT offset;
119 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
120 void *constfundata;
121 int reverse;
124 static void move_by_pieces_1 (rtx (*) (rtx, ...), enum machine_mode,
125 struct move_by_pieces_d *);
126 static bool block_move_libcall_safe_for_call_parm (void);
127 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned, unsigned, HOST_WIDE_INT);
128 static tree emit_block_move_libcall_fn (int);
129 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
130 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
131 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
132 static void store_by_pieces_1 (struct store_by_pieces_d *, unsigned int);
133 static void store_by_pieces_2 (rtx (*) (rtx, ...), enum machine_mode,
134 struct store_by_pieces_d *);
135 static tree clear_storage_libcall_fn (int);
136 static rtx compress_float_constant (rtx, rtx);
137 static rtx get_subtarget (rtx);
138 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
139 HOST_WIDE_INT, enum machine_mode,
140 tree, int, alias_set_type);
141 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
142 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT,
143 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
144 enum machine_mode, tree, alias_set_type, bool);
146 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (const_tree, const_tree);
148 static int is_aligning_offset (const_tree, const_tree);
149 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
150 enum expand_modifier);
151 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
152 static rtx do_store_flag (sepops, rtx, enum machine_mode);
153 #ifdef PUSH_ROUNDING
154 static void emit_single_push_insn (enum machine_mode, rtx, tree);
155 #endif
156 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx, int);
157 static rtx const_vector_from_tree (tree);
158 static void write_complex_part (rtx, rtx, bool);
160 /* This macro is used to determine whether move_by_pieces should be called
161 to perform a structure copy. */
162 #ifndef MOVE_BY_PIECES_P
163 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
164 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
165 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
166 #endif
168 /* This macro is used to determine whether clear_by_pieces should be
169 called to clear storage. */
170 #ifndef CLEAR_BY_PIECES_P
171 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
172 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
173 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
174 #endif
176 /* This macro is used to determine whether store_by_pieces should be
177 called to "memset" storage with byte values other than zero. */
178 #ifndef SET_BY_PIECES_P
179 #define SET_BY_PIECES_P(SIZE, ALIGN) \
180 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
181 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
182 #endif
184 /* This macro is used to determine whether store_by_pieces should be
185 called to "memcpy" storage when the source is a constant string. */
186 #ifndef STORE_BY_PIECES_P
187 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
188 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
189 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
190 #endif
192 /* This is run to set up which modes can be used
193 directly in memory and to initialize the block move optab. It is run
194 at the beginning of compilation and when the target is reinitialized. */
196 void
197 init_expr_target (void)
199 rtx insn, pat;
200 enum machine_mode mode;
201 int num_clobbers;
202 rtx mem, mem1;
203 rtx reg;
205 /* Try indexing by frame ptr and try by stack ptr.
206 It is known that on the Convex the stack ptr isn't a valid index.
207 With luck, one or the other is valid on any machine. */
208 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
209 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
211 /* A scratch register we can modify in-place below to avoid
212 useless RTL allocations. */
213 reg = gen_rtx_REG (VOIDmode, -1);
215 insn = rtx_alloc (INSN);
216 pat = gen_rtx_SET (VOIDmode, NULL_RTX, NULL_RTX);
217 PATTERN (insn) = pat;
219 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
220 mode = (enum machine_mode) ((int) mode + 1))
222 int regno;
224 direct_load[(int) mode] = direct_store[(int) mode] = 0;
225 PUT_MODE (mem, mode);
226 PUT_MODE (mem1, mode);
227 PUT_MODE (reg, mode);
229 /* See if there is some register that can be used in this mode and
230 directly loaded or stored from memory. */
232 if (mode != VOIDmode && mode != BLKmode)
233 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
234 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
235 regno++)
237 if (! HARD_REGNO_MODE_OK (regno, mode))
238 continue;
240 SET_REGNO (reg, regno);
242 SET_SRC (pat) = mem;
243 SET_DEST (pat) = reg;
244 if (recog (pat, insn, &num_clobbers) >= 0)
245 direct_load[(int) mode] = 1;
247 SET_SRC (pat) = mem1;
248 SET_DEST (pat) = reg;
249 if (recog (pat, insn, &num_clobbers) >= 0)
250 direct_load[(int) mode] = 1;
252 SET_SRC (pat) = reg;
253 SET_DEST (pat) = mem;
254 if (recog (pat, insn, &num_clobbers) >= 0)
255 direct_store[(int) mode] = 1;
257 SET_SRC (pat) = reg;
258 SET_DEST (pat) = mem1;
259 if (recog (pat, insn, &num_clobbers) >= 0)
260 direct_store[(int) mode] = 1;
264 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
266 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
267 mode = GET_MODE_WIDER_MODE (mode))
269 enum machine_mode srcmode;
270 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
271 srcmode = GET_MODE_WIDER_MODE (srcmode))
273 enum insn_code ic;
275 ic = can_extend_p (mode, srcmode, 0);
276 if (ic == CODE_FOR_nothing)
277 continue;
279 PUT_MODE (mem, srcmode);
281 if (insn_operand_matches (ic, 1, mem))
282 float_extend_from_mem[mode][srcmode] = true;
287 /* This is run at the start of compiling a function. */
289 void
290 init_expr (void)
292 memset (&crtl->expr, 0, sizeof (crtl->expr));
295 /* Copy data from FROM to TO, where the machine modes are not the same.
296 Both modes may be integer, or both may be floating, or both may be
297 fixed-point.
298 UNSIGNEDP should be nonzero if FROM is an unsigned type.
299 This causes zero-extension instead of sign-extension. */
301 void
302 convert_move (rtx to, rtx from, int unsignedp)
304 enum machine_mode to_mode = GET_MODE (to);
305 enum machine_mode from_mode = GET_MODE (from);
306 int to_real = SCALAR_FLOAT_MODE_P (to_mode);
307 int from_real = SCALAR_FLOAT_MODE_P (from_mode);
308 enum insn_code code;
309 rtx libcall;
311 /* rtx code for making an equivalent value. */
312 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
313 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
316 gcc_assert (to_real == from_real);
317 gcc_assert (to_mode != BLKmode);
318 gcc_assert (from_mode != BLKmode);
320 /* If the source and destination are already the same, then there's
321 nothing to do. */
322 if (to == from)
323 return;
325 /* If FROM is a SUBREG that indicates that we have already done at least
326 the required extension, strip it. We don't handle such SUBREGs as
327 TO here. */
329 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
330 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from)))
331 >= GET_MODE_PRECISION (to_mode))
332 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
333 from = gen_lowpart (to_mode, from), from_mode = to_mode;
335 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
337 if (to_mode == from_mode
338 || (from_mode == VOIDmode && CONSTANT_P (from)))
340 emit_move_insn (to, from);
341 return;
344 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
346 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
348 if (VECTOR_MODE_P (to_mode))
349 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
350 else
351 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
353 emit_move_insn (to, from);
354 return;
357 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
359 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
360 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
361 return;
364 if (to_real)
366 rtx value, insns;
367 convert_optab tab;
369 gcc_assert ((GET_MODE_PRECISION (from_mode)
370 != GET_MODE_PRECISION (to_mode))
371 || (DECIMAL_FLOAT_MODE_P (from_mode)
372 != DECIMAL_FLOAT_MODE_P (to_mode)));
374 if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
375 /* Conversion between decimal float and binary float, same size. */
376 tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
377 else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
378 tab = sext_optab;
379 else
380 tab = trunc_optab;
382 /* Try converting directly if the insn is supported. */
384 code = convert_optab_handler (tab, to_mode, from_mode);
385 if (code != CODE_FOR_nothing)
387 emit_unop_insn (code, to, from,
388 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
389 return;
392 /* Otherwise use a libcall. */
393 libcall = convert_optab_libfunc (tab, to_mode, from_mode);
395 /* Is this conversion implemented yet? */
396 gcc_assert (libcall);
398 start_sequence ();
399 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
400 1, from, from_mode);
401 insns = get_insns ();
402 end_sequence ();
403 emit_libcall_block (insns, to, value,
404 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
405 from)
406 : gen_rtx_FLOAT_EXTEND (to_mode, from));
407 return;
410 /* Handle pointer conversion. */ /* SPEE 900220. */
411 /* Targets are expected to provide conversion insns between PxImode and
412 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
413 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
415 enum machine_mode full_mode
416 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
418 gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
419 != CODE_FOR_nothing);
421 if (full_mode != from_mode)
422 from = convert_to_mode (full_mode, from, unsignedp);
423 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
424 to, from, UNKNOWN);
425 return;
427 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
429 rtx new_from;
430 enum machine_mode full_mode
431 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
432 convert_optab ctab = unsignedp ? zext_optab : sext_optab;
433 enum insn_code icode;
435 icode = convert_optab_handler (ctab, full_mode, from_mode);
436 gcc_assert (icode != CODE_FOR_nothing);
438 if (to_mode == full_mode)
440 emit_unop_insn (icode, to, from, UNKNOWN);
441 return;
444 new_from = gen_reg_rtx (full_mode);
445 emit_unop_insn (icode, new_from, from, UNKNOWN);
447 /* else proceed to integer conversions below. */
448 from_mode = full_mode;
449 from = new_from;
452 /* Make sure both are fixed-point modes or both are not. */
453 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
454 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
455 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
457 /* If we widen from_mode to to_mode and they are in the same class,
458 we won't saturate the result.
459 Otherwise, always saturate the result to play safe. */
460 if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
461 && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
462 expand_fixed_convert (to, from, 0, 0);
463 else
464 expand_fixed_convert (to, from, 0, 1);
465 return;
468 /* Now both modes are integers. */
470 /* Handle expanding beyond a word. */
471 if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
472 && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
474 rtx insns;
475 rtx lowpart;
476 rtx fill_value;
477 rtx lowfrom;
478 int i;
479 enum machine_mode lowpart_mode;
480 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
482 /* Try converting directly if the insn is supported. */
483 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
484 != CODE_FOR_nothing)
486 /* If FROM is a SUBREG, put it into a register. Do this
487 so that we always generate the same set of insns for
488 better cse'ing; if an intermediate assignment occurred,
489 we won't be doing the operation directly on the SUBREG. */
490 if (optimize > 0 && GET_CODE (from) == SUBREG)
491 from = force_reg (from_mode, from);
492 emit_unop_insn (code, to, from, equiv_code);
493 return;
495 /* Next, try converting via full word. */
496 else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
497 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
498 != CODE_FOR_nothing))
500 rtx word_to = gen_reg_rtx (word_mode);
501 if (REG_P (to))
503 if (reg_overlap_mentioned_p (to, from))
504 from = force_reg (from_mode, from);
505 emit_clobber (to);
507 convert_move (word_to, from, unsignedp);
508 emit_unop_insn (code, to, word_to, equiv_code);
509 return;
512 /* No special multiword conversion insn; do it by hand. */
513 start_sequence ();
515 /* Since we will turn this into a no conflict block, we must ensure the
516 the source does not overlap the target so force it into an isolated
517 register when maybe so. Likewise for any MEM input, since the
518 conversion sequence might require several references to it and we
519 must ensure we're getting the same value every time. */
521 if (MEM_P (from) || reg_overlap_mentioned_p (to, from))
522 from = force_reg (from_mode, from);
524 /* Get a copy of FROM widened to a word, if necessary. */
525 if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
526 lowpart_mode = word_mode;
527 else
528 lowpart_mode = from_mode;
530 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
532 lowpart = gen_lowpart (lowpart_mode, to);
533 emit_move_insn (lowpart, lowfrom);
535 /* Compute the value to put in each remaining word. */
536 if (unsignedp)
537 fill_value = const0_rtx;
538 else
539 fill_value = emit_store_flag (gen_reg_rtx (word_mode),
540 LT, lowfrom, const0_rtx,
541 VOIDmode, 0, -1);
543 /* Fill the remaining words. */
544 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
546 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
547 rtx subword = operand_subword (to, index, 1, to_mode);
549 gcc_assert (subword);
551 if (fill_value != subword)
552 emit_move_insn (subword, fill_value);
555 insns = get_insns ();
556 end_sequence ();
558 emit_insn (insns);
559 return;
562 /* Truncating multi-word to a word or less. */
563 if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
564 && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
566 if (!((MEM_P (from)
567 && ! MEM_VOLATILE_P (from)
568 && direct_load[(int) to_mode]
569 && ! mode_dependent_address_p (XEXP (from, 0),
570 MEM_ADDR_SPACE (from)))
571 || REG_P (from)
572 || GET_CODE (from) == SUBREG))
573 from = force_reg (from_mode, from);
574 convert_move (to, gen_lowpart (word_mode, from), 0);
575 return;
578 /* Now follow all the conversions between integers
579 no more than a word long. */
581 /* For truncation, usually we can just refer to FROM in a narrower mode. */
582 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
583 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
585 if (!((MEM_P (from)
586 && ! MEM_VOLATILE_P (from)
587 && direct_load[(int) to_mode]
588 && ! mode_dependent_address_p (XEXP (from, 0),
589 MEM_ADDR_SPACE (from)))
590 || REG_P (from)
591 || GET_CODE (from) == SUBREG))
592 from = force_reg (from_mode, from);
593 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
594 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
595 from = copy_to_reg (from);
596 emit_move_insn (to, gen_lowpart (to_mode, from));
597 return;
600 /* Handle extension. */
601 if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (from_mode))
603 /* Convert directly if that works. */
604 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
605 != CODE_FOR_nothing)
607 emit_unop_insn (code, to, from, equiv_code);
608 return;
610 else
612 enum machine_mode intermediate;
613 rtx tmp;
614 int shift_amount;
616 /* Search for a mode to convert via. */
617 for (intermediate = from_mode; intermediate != VOIDmode;
618 intermediate = GET_MODE_WIDER_MODE (intermediate))
619 if (((can_extend_p (to_mode, intermediate, unsignedp)
620 != CODE_FOR_nothing)
621 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
622 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, intermediate)))
623 && (can_extend_p (intermediate, from_mode, unsignedp)
624 != CODE_FOR_nothing))
626 convert_move (to, convert_to_mode (intermediate, from,
627 unsignedp), unsignedp);
628 return;
631 /* No suitable intermediate mode.
632 Generate what we need with shifts. */
633 shift_amount = (GET_MODE_PRECISION (to_mode)
634 - GET_MODE_PRECISION (from_mode));
635 from = gen_lowpart (to_mode, force_reg (from_mode, from));
636 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
637 to, unsignedp);
638 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
639 to, unsignedp);
640 if (tmp != to)
641 emit_move_insn (to, tmp);
642 return;
646 /* Support special truncate insns for certain modes. */
647 if (convert_optab_handler (trunc_optab, to_mode,
648 from_mode) != CODE_FOR_nothing)
650 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, from_mode),
651 to, from, UNKNOWN);
652 return;
655 /* Handle truncation of volatile memrefs, and so on;
656 the things that couldn't be truncated directly,
657 and for which there was no special instruction.
659 ??? Code above formerly short-circuited this, for most integer
660 mode pairs, with a force_reg in from_mode followed by a recursive
661 call to this routine. Appears always to have been wrong. */
662 if (GET_MODE_PRECISION (to_mode) < GET_MODE_PRECISION (from_mode))
664 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
665 emit_move_insn (to, temp);
666 return;
669 /* Mode combination is not recognized. */
670 gcc_unreachable ();
673 /* Return an rtx for a value that would result
674 from converting X to mode MODE.
675 Both X and MODE may be floating, or both integer.
676 UNSIGNEDP is nonzero if X is an unsigned value.
677 This can be done by referring to a part of X in place
678 or by copying to a new temporary with conversion. */
681 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
683 return convert_modes (mode, VOIDmode, x, unsignedp);
686 /* Return an rtx for a value that would result
687 from converting X from mode OLDMODE to mode MODE.
688 Both modes may be floating, or both integer.
689 UNSIGNEDP is nonzero if X is an unsigned value.
691 This can be done by referring to a part of X in place
692 or by copying to a new temporary with conversion.
694 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
697 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
699 rtx temp;
701 /* If FROM is a SUBREG that indicates that we have already done at least
702 the required extension, strip it. */
704 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
705 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
706 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
707 x = gen_lowpart (mode, x);
709 if (GET_MODE (x) != VOIDmode)
710 oldmode = GET_MODE (x);
712 if (mode == oldmode)
713 return x;
715 /* There is one case that we must handle specially: If we are converting
716 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
717 we are to interpret the constant as unsigned, gen_lowpart will do
718 the wrong if the constant appears negative. What we want to do is
719 make the high-order word of the constant zero, not all ones. */
721 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
722 && GET_MODE_BITSIZE (mode) == HOST_BITS_PER_DOUBLE_INT
723 && CONST_INT_P (x) && INTVAL (x) < 0)
725 double_int val = double_int::from_uhwi (INTVAL (x));
727 /* We need to zero extend VAL. */
728 if (oldmode != VOIDmode)
729 val = val.zext (GET_MODE_BITSIZE (oldmode));
731 return immed_double_int_const (val, mode);
734 /* We can do this with a gen_lowpart if both desired and current modes
735 are integer, and this is either a constant integer, a register, or a
736 non-volatile MEM. Except for the constant case where MODE is no
737 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
739 if ((CONST_INT_P (x)
740 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT)
741 || (GET_MODE_CLASS (mode) == MODE_INT
742 && GET_MODE_CLASS (oldmode) == MODE_INT
743 && (CONST_DOUBLE_AS_INT_P (x)
744 || (GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (oldmode)
745 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
746 && direct_load[(int) mode])
747 || (REG_P (x)
748 && (! HARD_REGISTER_P (x)
749 || HARD_REGNO_MODE_OK (REGNO (x), mode))
750 && TRULY_NOOP_TRUNCATION_MODES_P (mode,
751 GET_MODE (x))))))))
753 /* ?? If we don't know OLDMODE, we have to assume here that
754 X does not need sign- or zero-extension. This may not be
755 the case, but it's the best we can do. */
756 if (CONST_INT_P (x) && oldmode != VOIDmode
757 && GET_MODE_PRECISION (mode) > GET_MODE_PRECISION (oldmode))
759 HOST_WIDE_INT val = INTVAL (x);
761 /* We must sign or zero-extend in this case. Start by
762 zero-extending, then sign extend if we need to. */
763 val &= GET_MODE_MASK (oldmode);
764 if (! unsignedp
765 && val_signbit_known_set_p (oldmode, val))
766 val |= ~GET_MODE_MASK (oldmode);
768 return gen_int_mode (val, mode);
771 return gen_lowpart (mode, x);
774 /* Converting from integer constant into mode is always equivalent to an
775 subreg operation. */
776 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
778 gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
779 return simplify_gen_subreg (mode, x, oldmode, 0);
782 temp = gen_reg_rtx (mode);
783 convert_move (temp, x, unsignedp);
784 return temp;
787 /* Return the largest alignment we can use for doing a move (or store)
788 of MAX_PIECES. ALIGN is the largest alignment we could use. */
790 static unsigned int
791 alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
793 enum machine_mode tmode;
795 tmode = mode_for_size (max_pieces * BITS_PER_UNIT, MODE_INT, 1);
796 if (align >= GET_MODE_ALIGNMENT (tmode))
797 align = GET_MODE_ALIGNMENT (tmode);
798 else
800 enum machine_mode tmode, xmode;
802 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
803 tmode != VOIDmode;
804 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
805 if (GET_MODE_SIZE (tmode) > max_pieces
806 || SLOW_UNALIGNED_ACCESS (tmode, align))
807 break;
809 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
812 return align;
815 /* Return the widest integer mode no wider than SIZE. If no such mode
816 can be found, return VOIDmode. */
818 static enum machine_mode
819 widest_int_mode_for_size (unsigned int size)
821 enum machine_mode tmode, mode = VOIDmode;
823 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
824 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
825 if (GET_MODE_SIZE (tmode) < size)
826 mode = tmode;
828 return mode;
831 /* STORE_MAX_PIECES is the number of bytes at a time that we can
832 store efficiently. Due to internal GCC limitations, this is
833 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
834 for an immediate constant. */
836 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
838 /* Determine whether the LEN bytes can be moved by using several move
839 instructions. Return nonzero if a call to move_by_pieces should
840 succeed. */
843 can_move_by_pieces (unsigned HOST_WIDE_INT len ATTRIBUTE_UNUSED,
844 unsigned int align ATTRIBUTE_UNUSED)
846 return MOVE_BY_PIECES_P (len, align);
849 /* Generate several move instructions to copy LEN bytes from block FROM to
850 block TO. (These are MEM rtx's with BLKmode).
852 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
853 used to push FROM to the stack.
855 ALIGN is maximum stack alignment we can assume.
857 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
858 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
859 stpcpy. */
862 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
863 unsigned int align, int endp)
865 struct move_by_pieces_d data;
866 enum machine_mode to_addr_mode;
867 enum machine_mode from_addr_mode = get_address_mode (from);
868 rtx to_addr, from_addr = XEXP (from, 0);
869 unsigned int max_size = MOVE_MAX_PIECES + 1;
870 enum insn_code icode;
872 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
874 data.offset = 0;
875 data.from_addr = from_addr;
876 if (to)
878 to_addr_mode = get_address_mode (to);
879 to_addr = XEXP (to, 0);
880 data.to = to;
881 data.autinc_to
882 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
883 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
884 data.reverse
885 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
887 else
889 to_addr_mode = VOIDmode;
890 to_addr = NULL_RTX;
891 data.to = NULL_RTX;
892 data.autinc_to = 1;
893 #ifdef STACK_GROWS_DOWNWARD
894 data.reverse = 1;
895 #else
896 data.reverse = 0;
897 #endif
899 data.to_addr = to_addr;
900 data.from = from;
901 data.autinc_from
902 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
903 || GET_CODE (from_addr) == POST_INC
904 || GET_CODE (from_addr) == POST_DEC);
906 data.explicit_inc_from = 0;
907 data.explicit_inc_to = 0;
908 if (data.reverse) data.offset = len;
909 data.len = len;
911 /* If copying requires more than two move insns,
912 copy addresses to registers (to make displacements shorter)
913 and use post-increment if available. */
914 if (!(data.autinc_from && data.autinc_to)
915 && move_by_pieces_ninsns (len, align, max_size) > 2)
917 /* Find the mode of the largest move...
918 MODE might not be used depending on the definitions of the
919 USE_* macros below. */
920 enum machine_mode mode ATTRIBUTE_UNUSED
921 = widest_int_mode_for_size (max_size);
923 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
925 data.from_addr = copy_to_mode_reg (from_addr_mode,
926 plus_constant (from_addr_mode,
927 from_addr, len));
928 data.autinc_from = 1;
929 data.explicit_inc_from = -1;
931 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
933 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
934 data.autinc_from = 1;
935 data.explicit_inc_from = 1;
937 if (!data.autinc_from && CONSTANT_P (from_addr))
938 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
939 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
941 data.to_addr = copy_to_mode_reg (to_addr_mode,
942 plus_constant (to_addr_mode,
943 to_addr, len));
944 data.autinc_to = 1;
945 data.explicit_inc_to = -1;
947 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
949 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
950 data.autinc_to = 1;
951 data.explicit_inc_to = 1;
953 if (!data.autinc_to && CONSTANT_P (to_addr))
954 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
957 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
959 /* First move what we can in the largest integer mode, then go to
960 successively smaller modes. */
962 while (max_size > 1 && data.len > 0)
964 enum machine_mode mode = widest_int_mode_for_size (max_size);
966 if (mode == VOIDmode)
967 break;
969 icode = optab_handler (mov_optab, mode);
970 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
971 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
973 max_size = GET_MODE_SIZE (mode);
976 /* The code above should have handled everything. */
977 gcc_assert (!data.len);
979 if (endp)
981 rtx to1;
983 gcc_assert (!data.reverse);
984 if (data.autinc_to)
986 if (endp == 2)
988 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
989 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
990 else
991 data.to_addr = copy_to_mode_reg (to_addr_mode,
992 plus_constant (to_addr_mode,
993 data.to_addr,
994 -1));
996 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
997 data.offset);
999 else
1001 if (endp == 2)
1002 --data.offset;
1003 to1 = adjust_address (data.to, QImode, data.offset);
1005 return to1;
1007 else
1008 return data.to;
1011 /* Return number of insns required to move L bytes by pieces.
1012 ALIGN (in bits) is maximum alignment we can assume. */
1014 unsigned HOST_WIDE_INT
1015 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1016 unsigned int max_size)
1018 unsigned HOST_WIDE_INT n_insns = 0;
1020 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1022 while (max_size > 1 && l > 0)
1024 enum machine_mode mode;
1025 enum insn_code icode;
1027 mode = widest_int_mode_for_size (max_size);
1029 if (mode == VOIDmode)
1030 break;
1032 icode = optab_handler (mov_optab, mode);
1033 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1034 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1036 max_size = GET_MODE_SIZE (mode);
1039 gcc_assert (!l);
1040 return n_insns;
1043 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1044 with move instructions for mode MODE. GENFUN is the gen_... function
1045 to make a move insn for that mode. DATA has all the other info. */
1047 static void
1048 move_by_pieces_1 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
1049 struct move_by_pieces_d *data)
1051 unsigned int size = GET_MODE_SIZE (mode);
1052 rtx to1 = NULL_RTX, from1;
1054 while (data->len >= size)
1056 if (data->reverse)
1057 data->offset -= size;
1059 if (data->to)
1061 if (data->autinc_to)
1062 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1063 data->offset);
1064 else
1065 to1 = adjust_address (data->to, mode, data->offset);
1068 if (data->autinc_from)
1069 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1070 data->offset);
1071 else
1072 from1 = adjust_address (data->from, mode, data->offset);
1074 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1075 emit_insn (gen_add2_insn (data->to_addr,
1076 GEN_INT (-(HOST_WIDE_INT)size)));
1077 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1078 emit_insn (gen_add2_insn (data->from_addr,
1079 GEN_INT (-(HOST_WIDE_INT)size)));
1081 if (data->to)
1082 emit_insn ((*genfun) (to1, from1));
1083 else
1085 #ifdef PUSH_ROUNDING
1086 emit_single_push_insn (mode, from1, NULL);
1087 #else
1088 gcc_unreachable ();
1089 #endif
1092 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1093 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1094 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1095 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1097 if (! data->reverse)
1098 data->offset += size;
1100 data->len -= size;
1104 /* Emit code to move a block Y to a block X. This may be done with
1105 string-move instructions, with multiple scalar move instructions,
1106 or with a library call.
1108 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1109 SIZE is an rtx that says how long they are.
1110 ALIGN is the maximum alignment we can assume they have.
1111 METHOD describes what kind of copy this is, and what mechanisms may be used.
1113 Return the address of the new block, if memcpy is called and returns it,
1114 0 otherwise. */
1117 emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
1118 unsigned int expected_align, HOST_WIDE_INT expected_size)
1120 bool may_use_call;
1121 rtx retval = 0;
1122 unsigned int align;
1124 gcc_assert (size);
1125 if (CONST_INT_P (size)
1126 && INTVAL (size) == 0)
1127 return 0;
1129 switch (method)
1131 case BLOCK_OP_NORMAL:
1132 case BLOCK_OP_TAILCALL:
1133 may_use_call = true;
1134 break;
1136 case BLOCK_OP_CALL_PARM:
1137 may_use_call = block_move_libcall_safe_for_call_parm ();
1139 /* Make inhibit_defer_pop nonzero around the library call
1140 to force it to pop the arguments right away. */
1141 NO_DEFER_POP;
1142 break;
1144 case BLOCK_OP_NO_LIBCALL:
1145 may_use_call = false;
1146 break;
1148 default:
1149 gcc_unreachable ();
1152 gcc_assert (MEM_P (x) && MEM_P (y));
1153 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1154 gcc_assert (align >= BITS_PER_UNIT);
1156 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1157 block copy is more efficient for other large modes, e.g. DCmode. */
1158 x = adjust_address (x, BLKmode, 0);
1159 y = adjust_address (y, BLKmode, 0);
1161 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1162 can be incorrect is coming from __builtin_memcpy. */
1163 if (CONST_INT_P (size))
1165 x = shallow_copy_rtx (x);
1166 y = shallow_copy_rtx (y);
1167 set_mem_size (x, INTVAL (size));
1168 set_mem_size (y, INTVAL (size));
1171 if (CONST_INT_P (size) && MOVE_BY_PIECES_P (INTVAL (size), align))
1172 move_by_pieces (x, y, INTVAL (size), align, 0);
1173 else if (emit_block_move_via_movmem (x, y, size, align,
1174 expected_align, expected_size))
1176 else if (may_use_call
1177 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
1178 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
1180 /* Since x and y are passed to a libcall, mark the corresponding
1181 tree EXPR as addressable. */
1182 tree y_expr = MEM_EXPR (y);
1183 tree x_expr = MEM_EXPR (x);
1184 if (y_expr)
1185 mark_addressable (y_expr);
1186 if (x_expr)
1187 mark_addressable (x_expr);
1188 retval = emit_block_move_via_libcall (x, y, size,
1189 method == BLOCK_OP_TAILCALL);
1192 else
1193 emit_block_move_via_loop (x, y, size, align);
1195 if (method == BLOCK_OP_CALL_PARM)
1196 OK_DEFER_POP;
1198 return retval;
1202 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1204 return emit_block_move_hints (x, y, size, method, 0, -1);
1207 /* A subroutine of emit_block_move. Returns true if calling the
1208 block move libcall will not clobber any parameters which may have
1209 already been placed on the stack. */
1211 static bool
1212 block_move_libcall_safe_for_call_parm (void)
1214 #if defined (REG_PARM_STACK_SPACE)
1215 tree fn;
1216 #endif
1218 /* If arguments are pushed on the stack, then they're safe. */
1219 if (PUSH_ARGS)
1220 return true;
1222 /* If registers go on the stack anyway, any argument is sure to clobber
1223 an outgoing argument. */
1224 #if defined (REG_PARM_STACK_SPACE)
1225 fn = emit_block_move_libcall_fn (false);
1226 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1227 depend on its argument. */
1228 (void) fn;
1229 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn ? NULL_TREE : TREE_TYPE (fn)))
1230 && REG_PARM_STACK_SPACE (fn) != 0)
1231 return false;
1232 #endif
1234 /* If any argument goes in memory, then it might clobber an outgoing
1235 argument. */
1237 CUMULATIVE_ARGS args_so_far_v;
1238 cumulative_args_t args_so_far;
1239 tree fn, arg;
1241 fn = emit_block_move_libcall_fn (false);
1242 INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
1243 args_so_far = pack_cumulative_args (&args_so_far_v);
1245 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1246 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1248 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1249 rtx tmp = targetm.calls.function_arg (args_so_far, mode,
1250 NULL_TREE, true);
1251 if (!tmp || !REG_P (tmp))
1252 return false;
1253 if (targetm.calls.arg_partial_bytes (args_so_far, mode, NULL, 1))
1254 return false;
1255 targetm.calls.function_arg_advance (args_so_far, mode,
1256 NULL_TREE, true);
1259 return true;
1262 /* A subroutine of emit_block_move. Expand a movmem pattern;
1263 return true if successful. */
1265 static bool
1266 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
1267 unsigned int expected_align, HOST_WIDE_INT expected_size)
1269 int save_volatile_ok = volatile_ok;
1270 enum machine_mode mode;
1272 if (expected_align < align)
1273 expected_align = align;
1275 /* Since this is a move insn, we don't care about volatility. */
1276 volatile_ok = 1;
1278 /* Try the most limited insn first, because there's no point
1279 including more than one in the machine description unless
1280 the more limited one has some advantage. */
1282 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1283 mode = GET_MODE_WIDER_MODE (mode))
1285 enum insn_code code = direct_optab_handler (movmem_optab, mode);
1287 if (code != CODE_FOR_nothing
1288 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1289 here because if SIZE is less than the mode mask, as it is
1290 returned by the macro, it will definitely be less than the
1291 actual mode mask. */
1292 && ((CONST_INT_P (size)
1293 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1294 <= (GET_MODE_MASK (mode) >> 1)))
1295 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD))
1297 struct expand_operand ops[6];
1298 unsigned int nops;
1300 /* ??? When called via emit_block_move_for_call, it'd be
1301 nice if there were some way to inform the backend, so
1302 that it doesn't fail the expansion because it thinks
1303 emitting the libcall would be more efficient. */
1304 nops = insn_data[(int) code].n_generator_args;
1305 gcc_assert (nops == 4 || nops == 6);
1307 create_fixed_operand (&ops[0], x);
1308 create_fixed_operand (&ops[1], y);
1309 /* The check above guarantees that this size conversion is valid. */
1310 create_convert_operand_to (&ops[2], size, mode, true);
1311 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
1312 if (nops == 6)
1314 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
1315 create_integer_operand (&ops[5], expected_size);
1317 if (maybe_expand_insn (code, nops, ops))
1319 volatile_ok = save_volatile_ok;
1320 return true;
1325 volatile_ok = save_volatile_ok;
1326 return false;
1329 /* A subroutine of emit_block_move. Expand a call to memcpy.
1330 Return the return value from memcpy, 0 otherwise. */
1333 emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
1335 rtx dst_addr, src_addr;
1336 tree call_expr, fn, src_tree, dst_tree, size_tree;
1337 enum machine_mode size_mode;
1338 rtx retval;
1340 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1341 pseudos. We can then place those new pseudos into a VAR_DECL and
1342 use them later. */
1344 dst_addr = copy_addr_to_reg (XEXP (dst, 0));
1345 src_addr = copy_addr_to_reg (XEXP (src, 0));
1347 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1348 src_addr = convert_memory_address (ptr_mode, src_addr);
1350 dst_tree = make_tree (ptr_type_node, dst_addr);
1351 src_tree = make_tree (ptr_type_node, src_addr);
1353 size_mode = TYPE_MODE (sizetype);
1355 size = convert_to_mode (size_mode, size, 1);
1356 size = copy_to_mode_reg (size_mode, size);
1358 /* It is incorrect to use the libcall calling conventions to call
1359 memcpy in this context. This could be a user call to memcpy and
1360 the user may wish to examine the return value from memcpy. For
1361 targets where libcalls and normal calls have different conventions
1362 for returning pointers, we could end up generating incorrect code. */
1364 size_tree = make_tree (sizetype, size);
1366 fn = emit_block_move_libcall_fn (true);
1367 call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
1368 CALL_EXPR_TAILCALL (call_expr) = tailcall;
1370 retval = expand_normal (call_expr);
1372 return retval;
1375 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1376 for the function we use for block copies. */
1378 static GTY(()) tree block_move_fn;
1380 void
1381 init_block_move_fn (const char *asmspec)
1383 if (!block_move_fn)
1385 tree args, fn, attrs, attr_args;
1387 fn = get_identifier ("memcpy");
1388 args = build_function_type_list (ptr_type_node, ptr_type_node,
1389 const_ptr_type_node, sizetype,
1390 NULL_TREE);
1392 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
1393 DECL_EXTERNAL (fn) = 1;
1394 TREE_PUBLIC (fn) = 1;
1395 DECL_ARTIFICIAL (fn) = 1;
1396 TREE_NOTHROW (fn) = 1;
1397 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
1398 DECL_VISIBILITY_SPECIFIED (fn) = 1;
1400 attr_args = build_tree_list (NULL_TREE, build_string (1, "1"));
1401 attrs = tree_cons (get_identifier ("fn spec"), attr_args, NULL);
1403 decl_attributes (&fn, attrs, ATTR_FLAG_BUILT_IN);
1405 block_move_fn = fn;
1408 if (asmspec)
1409 set_user_assembler_name (block_move_fn, asmspec);
1412 static tree
1413 emit_block_move_libcall_fn (int for_call)
1415 static bool emitted_extern;
1417 if (!block_move_fn)
1418 init_block_move_fn (NULL);
1420 if (for_call && !emitted_extern)
1422 emitted_extern = true;
1423 make_decl_rtl (block_move_fn);
1426 return block_move_fn;
1429 /* A subroutine of emit_block_move. Copy the data via an explicit
1430 loop. This is used only when libcalls are forbidden. */
1431 /* ??? It'd be nice to copy in hunks larger than QImode. */
1433 static void
1434 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1435 unsigned int align ATTRIBUTE_UNUSED)
1437 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1438 enum machine_mode x_addr_mode = get_address_mode (x);
1439 enum machine_mode y_addr_mode = get_address_mode (y);
1440 enum machine_mode iter_mode;
1442 iter_mode = GET_MODE (size);
1443 if (iter_mode == VOIDmode)
1444 iter_mode = word_mode;
1446 top_label = gen_label_rtx ();
1447 cmp_label = gen_label_rtx ();
1448 iter = gen_reg_rtx (iter_mode);
1450 emit_move_insn (iter, const0_rtx);
1452 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1453 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1454 do_pending_stack_adjust ();
1456 emit_jump (cmp_label);
1457 emit_label (top_label);
1459 tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
1460 x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
1462 if (x_addr_mode != y_addr_mode)
1463 tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
1464 y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
1466 x = change_address (x, QImode, x_addr);
1467 y = change_address (y, QImode, y_addr);
1469 emit_move_insn (x, y);
1471 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1472 true, OPTAB_LIB_WIDEN);
1473 if (tmp != iter)
1474 emit_move_insn (iter, tmp);
1476 emit_label (cmp_label);
1478 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1479 true, top_label, REG_BR_PROB_BASE * 90 / 100);
1482 /* Copy all or part of a value X into registers starting at REGNO.
1483 The number of registers to be filled is NREGS. */
1485 void
1486 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1488 int i;
1489 #ifdef HAVE_load_multiple
1490 rtx pat;
1491 rtx last;
1492 #endif
1494 if (nregs == 0)
1495 return;
1497 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
1498 x = validize_mem (force_const_mem (mode, x));
1500 /* See if the machine can do this with a load multiple insn. */
1501 #ifdef HAVE_load_multiple
1502 if (HAVE_load_multiple)
1504 last = get_last_insn ();
1505 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1506 GEN_INT (nregs));
1507 if (pat)
1509 emit_insn (pat);
1510 return;
1512 else
1513 delete_insns_since (last);
1515 #endif
1517 for (i = 0; i < nregs; i++)
1518 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1519 operand_subword_force (x, i, mode));
1522 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1523 The number of registers to be filled is NREGS. */
1525 void
1526 move_block_from_reg (int regno, rtx x, int nregs)
1528 int i;
1530 if (nregs == 0)
1531 return;
1533 /* See if the machine can do this with a store multiple insn. */
1534 #ifdef HAVE_store_multiple
1535 if (HAVE_store_multiple)
1537 rtx last = get_last_insn ();
1538 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1539 GEN_INT (nregs));
1540 if (pat)
1542 emit_insn (pat);
1543 return;
1545 else
1546 delete_insns_since (last);
1548 #endif
1550 for (i = 0; i < nregs; i++)
1552 rtx tem = operand_subword (x, i, 1, BLKmode);
1554 gcc_assert (tem);
1556 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1560 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1561 ORIG, where ORIG is a non-consecutive group of registers represented by
1562 a PARALLEL. The clone is identical to the original except in that the
1563 original set of registers is replaced by a new set of pseudo registers.
1564 The new set has the same modes as the original set. */
1567 gen_group_rtx (rtx orig)
1569 int i, length;
1570 rtx *tmps;
1572 gcc_assert (GET_CODE (orig) == PARALLEL);
1574 length = XVECLEN (orig, 0);
1575 tmps = XALLOCAVEC (rtx, length);
1577 /* Skip a NULL entry in first slot. */
1578 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1580 if (i)
1581 tmps[0] = 0;
1583 for (; i < length; i++)
1585 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1586 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1588 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1591 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1594 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1595 except that values are placed in TMPS[i], and must later be moved
1596 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1598 static void
1599 emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
1601 rtx src;
1602 int start, i;
1603 enum machine_mode m = GET_MODE (orig_src);
1605 gcc_assert (GET_CODE (dst) == PARALLEL);
1607 if (m != VOIDmode
1608 && !SCALAR_INT_MODE_P (m)
1609 && !MEM_P (orig_src)
1610 && GET_CODE (orig_src) != CONCAT)
1612 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
1613 if (imode == BLKmode)
1614 src = assign_stack_temp (GET_MODE (orig_src), ssize);
1615 else
1616 src = gen_reg_rtx (imode);
1617 if (imode != BLKmode)
1618 src = gen_lowpart (GET_MODE (orig_src), src);
1619 emit_move_insn (src, orig_src);
1620 /* ...and back again. */
1621 if (imode != BLKmode)
1622 src = gen_lowpart (imode, src);
1623 emit_group_load_1 (tmps, dst, src, type, ssize);
1624 return;
1627 /* Check for a NULL entry, used to indicate that the parameter goes
1628 both on the stack and in registers. */
1629 if (XEXP (XVECEXP (dst, 0, 0), 0))
1630 start = 0;
1631 else
1632 start = 1;
1634 /* Process the pieces. */
1635 for (i = start; i < XVECLEN (dst, 0); i++)
1637 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1638 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1639 unsigned int bytelen = GET_MODE_SIZE (mode);
1640 int shift = 0;
1642 /* Handle trailing fragments that run over the size of the struct. */
1643 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1645 /* Arrange to shift the fragment to where it belongs.
1646 extract_bit_field loads to the lsb of the reg. */
1647 if (
1648 #ifdef BLOCK_REG_PADDING
1649 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1650 == (BYTES_BIG_ENDIAN ? upward : downward)
1651 #else
1652 BYTES_BIG_ENDIAN
1653 #endif
1655 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1656 bytelen = ssize - bytepos;
1657 gcc_assert (bytelen > 0);
1660 /* If we won't be loading directly from memory, protect the real source
1661 from strange tricks we might play; but make sure that the source can
1662 be loaded directly into the destination. */
1663 src = orig_src;
1664 if (!MEM_P (orig_src)
1665 && (!CONSTANT_P (orig_src)
1666 || (GET_MODE (orig_src) != mode
1667 && GET_MODE (orig_src) != VOIDmode)))
1669 if (GET_MODE (orig_src) == VOIDmode)
1670 src = gen_reg_rtx (mode);
1671 else
1672 src = gen_reg_rtx (GET_MODE (orig_src));
1674 emit_move_insn (src, orig_src);
1677 /* Optimize the access just a bit. */
1678 if (MEM_P (src)
1679 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1680 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1681 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1682 && bytelen == GET_MODE_SIZE (mode))
1684 tmps[i] = gen_reg_rtx (mode);
1685 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1687 else if (COMPLEX_MODE_P (mode)
1688 && GET_MODE (src) == mode
1689 && bytelen == GET_MODE_SIZE (mode))
1690 /* Let emit_move_complex do the bulk of the work. */
1691 tmps[i] = src;
1692 else if (GET_CODE (src) == CONCAT)
1694 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1695 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1697 if ((bytepos == 0 && bytelen == slen0)
1698 || (bytepos != 0 && bytepos + bytelen <= slen))
1700 /* The following assumes that the concatenated objects all
1701 have the same size. In this case, a simple calculation
1702 can be used to determine the object and the bit field
1703 to be extracted. */
1704 tmps[i] = XEXP (src, bytepos / slen0);
1705 if (! CONSTANT_P (tmps[i])
1706 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1707 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1708 (bytepos % slen0) * BITS_PER_UNIT,
1709 1, false, NULL_RTX, mode, mode);
1711 else
1713 rtx mem;
1715 gcc_assert (!bytepos);
1716 mem = assign_stack_temp (GET_MODE (src), slen);
1717 emit_move_insn (mem, src);
1718 tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
1719 0, 1, false, NULL_RTX, mode, mode);
1722 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1723 SIMD register, which is currently broken. While we get GCC
1724 to emit proper RTL for these cases, let's dump to memory. */
1725 else if (VECTOR_MODE_P (GET_MODE (dst))
1726 && REG_P (src))
1728 int slen = GET_MODE_SIZE (GET_MODE (src));
1729 rtx mem;
1731 mem = assign_stack_temp (GET_MODE (src), slen);
1732 emit_move_insn (mem, src);
1733 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1735 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1736 && XVECLEN (dst, 0) > 1)
1737 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE(dst), bytepos);
1738 else if (CONSTANT_P (src))
1740 HOST_WIDE_INT len = (HOST_WIDE_INT) bytelen;
1742 if (len == ssize)
1743 tmps[i] = src;
1744 else
1746 rtx first, second;
1748 gcc_assert (2 * len == ssize);
1749 split_double (src, &first, &second);
1750 if (i)
1751 tmps[i] = second;
1752 else
1753 tmps[i] = first;
1756 else if (REG_P (src) && GET_MODE (src) == mode)
1757 tmps[i] = src;
1758 else
1759 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1760 bytepos * BITS_PER_UNIT, 1, false, NULL_RTX,
1761 mode, mode);
1763 if (shift)
1764 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1765 shift, tmps[i], 0);
1769 /* Emit code to move a block SRC of type TYPE to a block DST,
1770 where DST is non-consecutive registers represented by a PARALLEL.
1771 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1772 if not known. */
1774 void
1775 emit_group_load (rtx dst, rtx src, tree type, int ssize)
1777 rtx *tmps;
1778 int i;
1780 tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
1781 emit_group_load_1 (tmps, dst, src, type, ssize);
1783 /* Copy the extracted pieces into the proper (probable) hard regs. */
1784 for (i = 0; i < XVECLEN (dst, 0); i++)
1786 rtx d = XEXP (XVECEXP (dst, 0, i), 0);
1787 if (d == NULL)
1788 continue;
1789 emit_move_insn (d, tmps[i]);
1793 /* Similar, but load SRC into new pseudos in a format that looks like
1794 PARALLEL. This can later be fed to emit_group_move to get things
1795 in the right place. */
1798 emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
1800 rtvec vec;
1801 int i;
1803 vec = rtvec_alloc (XVECLEN (parallel, 0));
1804 emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
1806 /* Convert the vector to look just like the original PARALLEL, except
1807 with the computed values. */
1808 for (i = 0; i < XVECLEN (parallel, 0); i++)
1810 rtx e = XVECEXP (parallel, 0, i);
1811 rtx d = XEXP (e, 0);
1813 if (d)
1815 d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
1816 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
1818 RTVEC_ELT (vec, i) = e;
1821 return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
1824 /* Emit code to move a block SRC to block DST, where SRC and DST are
1825 non-consecutive groups of registers, each represented by a PARALLEL. */
1827 void
1828 emit_group_move (rtx dst, rtx src)
1830 int i;
1832 gcc_assert (GET_CODE (src) == PARALLEL
1833 && GET_CODE (dst) == PARALLEL
1834 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1836 /* Skip first entry if NULL. */
1837 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1838 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1839 XEXP (XVECEXP (src, 0, i), 0));
1842 /* Move a group of registers represented by a PARALLEL into pseudos. */
1845 emit_group_move_into_temps (rtx src)
1847 rtvec vec = rtvec_alloc (XVECLEN (src, 0));
1848 int i;
1850 for (i = 0; i < XVECLEN (src, 0); i++)
1852 rtx e = XVECEXP (src, 0, i);
1853 rtx d = XEXP (e, 0);
1855 if (d)
1856 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
1857 RTVEC_ELT (vec, i) = e;
1860 return gen_rtx_PARALLEL (GET_MODE (src), vec);
1863 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1864 where SRC is non-consecutive registers represented by a PARALLEL.
1865 SSIZE represents the total size of block ORIG_DST, or -1 if not
1866 known. */
1868 void
1869 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1871 rtx *tmps, dst;
1872 int start, finish, i;
1873 enum machine_mode m = GET_MODE (orig_dst);
1875 gcc_assert (GET_CODE (src) == PARALLEL);
1877 if (!SCALAR_INT_MODE_P (m)
1878 && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
1880 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
1881 if (imode == BLKmode)
1882 dst = assign_stack_temp (GET_MODE (orig_dst), ssize);
1883 else
1884 dst = gen_reg_rtx (imode);
1885 emit_group_store (dst, src, type, ssize);
1886 if (imode != BLKmode)
1887 dst = gen_lowpart (GET_MODE (orig_dst), dst);
1888 emit_move_insn (orig_dst, dst);
1889 return;
1892 /* Check for a NULL entry, used to indicate that the parameter goes
1893 both on the stack and in registers. */
1894 if (XEXP (XVECEXP (src, 0, 0), 0))
1895 start = 0;
1896 else
1897 start = 1;
1898 finish = XVECLEN (src, 0);
1900 tmps = XALLOCAVEC (rtx, finish);
1902 /* Copy the (probable) hard regs into pseudos. */
1903 for (i = start; i < finish; i++)
1905 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1906 if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
1908 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1909 emit_move_insn (tmps[i], reg);
1911 else
1912 tmps[i] = reg;
1915 /* If we won't be storing directly into memory, protect the real destination
1916 from strange tricks we might play. */
1917 dst = orig_dst;
1918 if (GET_CODE (dst) == PARALLEL)
1920 rtx temp;
1922 /* We can get a PARALLEL dst if there is a conditional expression in
1923 a return statement. In that case, the dst and src are the same,
1924 so no action is necessary. */
1925 if (rtx_equal_p (dst, src))
1926 return;
1928 /* It is unclear if we can ever reach here, but we may as well handle
1929 it. Allocate a temporary, and split this into a store/load to/from
1930 the temporary. */
1932 temp = assign_stack_temp (GET_MODE (dst), ssize);
1933 emit_group_store (temp, src, type, ssize);
1934 emit_group_load (dst, temp, type, ssize);
1935 return;
1937 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1939 enum machine_mode outer = GET_MODE (dst);
1940 enum machine_mode inner;
1941 HOST_WIDE_INT bytepos;
1942 bool done = false;
1943 rtx temp;
1945 if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
1946 dst = gen_reg_rtx (outer);
1948 /* Make life a bit easier for combine. */
1949 /* If the first element of the vector is the low part
1950 of the destination mode, use a paradoxical subreg to
1951 initialize the destination. */
1952 if (start < finish)
1954 inner = GET_MODE (tmps[start]);
1955 bytepos = subreg_lowpart_offset (inner, outer);
1956 if (INTVAL (XEXP (XVECEXP (src, 0, start), 1)) == bytepos)
1958 temp = simplify_gen_subreg (outer, tmps[start],
1959 inner, 0);
1960 if (temp)
1962 emit_move_insn (dst, temp);
1963 done = true;
1964 start++;
1969 /* If the first element wasn't the low part, try the last. */
1970 if (!done
1971 && start < finish - 1)
1973 inner = GET_MODE (tmps[finish - 1]);
1974 bytepos = subreg_lowpart_offset (inner, outer);
1975 if (INTVAL (XEXP (XVECEXP (src, 0, finish - 1), 1)) == bytepos)
1977 temp = simplify_gen_subreg (outer, tmps[finish - 1],
1978 inner, 0);
1979 if (temp)
1981 emit_move_insn (dst, temp);
1982 done = true;
1983 finish--;
1988 /* Otherwise, simply initialize the result to zero. */
1989 if (!done)
1990 emit_move_insn (dst, CONST0_RTX (outer));
1993 /* Process the pieces. */
1994 for (i = start; i < finish; i++)
1996 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
1997 enum machine_mode mode = GET_MODE (tmps[i]);
1998 unsigned int bytelen = GET_MODE_SIZE (mode);
1999 unsigned int adj_bytelen = bytelen;
2000 rtx dest = dst;
2002 /* Handle trailing fragments that run over the size of the struct. */
2003 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2004 adj_bytelen = ssize - bytepos;
2006 if (GET_CODE (dst) == CONCAT)
2008 if (bytepos + adj_bytelen
2009 <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2010 dest = XEXP (dst, 0);
2011 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2013 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
2014 dest = XEXP (dst, 1);
2016 else
2018 enum machine_mode dest_mode = GET_MODE (dest);
2019 enum machine_mode tmp_mode = GET_MODE (tmps[i]);
2021 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
2023 if (GET_MODE_ALIGNMENT (dest_mode)
2024 >= GET_MODE_ALIGNMENT (tmp_mode))
2026 dest = assign_stack_temp (dest_mode,
2027 GET_MODE_SIZE (dest_mode));
2028 emit_move_insn (adjust_address (dest,
2029 tmp_mode,
2030 bytepos),
2031 tmps[i]);
2032 dst = dest;
2034 else
2036 dest = assign_stack_temp (tmp_mode,
2037 GET_MODE_SIZE (tmp_mode));
2038 emit_move_insn (dest, tmps[i]);
2039 dst = adjust_address (dest, dest_mode, bytepos);
2041 break;
2045 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2047 /* store_bit_field always takes its value from the lsb.
2048 Move the fragment to the lsb if it's not already there. */
2049 if (
2050 #ifdef BLOCK_REG_PADDING
2051 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
2052 == (BYTES_BIG_ENDIAN ? upward : downward)
2053 #else
2054 BYTES_BIG_ENDIAN
2055 #endif
2058 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2059 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
2060 shift, tmps[i], 0);
2062 bytelen = adj_bytelen;
2065 /* Optimize the access just a bit. */
2066 if (MEM_P (dest)
2067 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
2068 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
2069 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2070 && bytelen == GET_MODE_SIZE (mode))
2071 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2072 else
2073 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2074 0, 0, mode, tmps[i]);
2077 /* Copy from the pseudo into the (probable) hard reg. */
2078 if (orig_dst != dst)
2079 emit_move_insn (orig_dst, dst);
2082 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2084 This is used on targets that return BLKmode values in registers. */
2086 void
2087 copy_blkmode_from_reg (rtx target, rtx srcreg, tree type)
2089 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2090 rtx src = NULL, dst = NULL;
2091 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2092 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2093 enum machine_mode mode = GET_MODE (srcreg);
2094 enum machine_mode tmode = GET_MODE (target);
2095 enum machine_mode copy_mode;
2097 /* BLKmode registers created in the back-end shouldn't have survived. */
2098 gcc_assert (mode != BLKmode);
2100 /* If the structure doesn't take up a whole number of words, see whether
2101 SRCREG is padded on the left or on the right. If it's on the left,
2102 set PADDING_CORRECTION to the number of bits to skip.
2104 In most ABIs, the structure will be returned at the least end of
2105 the register, which translates to right padding on little-endian
2106 targets and left padding on big-endian targets. The opposite
2107 holds if the structure is returned at the most significant
2108 end of the register. */
2109 if (bytes % UNITS_PER_WORD != 0
2110 && (targetm.calls.return_in_msb (type)
2111 ? !BYTES_BIG_ENDIAN
2112 : BYTES_BIG_ENDIAN))
2113 padding_correction
2114 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2116 /* We can use a single move if we have an exact mode for the size. */
2117 else if (MEM_P (target)
2118 && (!SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target))
2119 || MEM_ALIGN (target) >= GET_MODE_ALIGNMENT (mode))
2120 && bytes == GET_MODE_SIZE (mode))
2122 emit_move_insn (adjust_address (target, mode, 0), srcreg);
2123 return;
2126 /* And if we additionally have the same mode for a register. */
2127 else if (REG_P (target)
2128 && GET_MODE (target) == mode
2129 && bytes == GET_MODE_SIZE (mode))
2131 emit_move_insn (target, srcreg);
2132 return;
2135 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2136 into a new pseudo which is a full word. */
2137 if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
2139 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
2140 mode = word_mode;
2143 /* Copy the structure BITSIZE bits at a time. If the target lives in
2144 memory, take care of not reading/writing past its end by selecting
2145 a copy mode suited to BITSIZE. This should always be possible given
2146 how it is computed.
2148 If the target lives in register, make sure not to select a copy mode
2149 larger than the mode of the register.
2151 We could probably emit more efficient code for machines which do not use
2152 strict alignment, but it doesn't seem worth the effort at the current
2153 time. */
2155 copy_mode = word_mode;
2156 if (MEM_P (target))
2158 enum machine_mode mem_mode = mode_for_size (bitsize, MODE_INT, 1);
2159 if (mem_mode != BLKmode)
2160 copy_mode = mem_mode;
2162 else if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
2163 copy_mode = tmode;
2165 for (bitpos = 0, xbitpos = padding_correction;
2166 bitpos < bytes * BITS_PER_UNIT;
2167 bitpos += bitsize, xbitpos += bitsize)
2169 /* We need a new source operand each time xbitpos is on a
2170 word boundary and when xbitpos == padding_correction
2171 (the first time through). */
2172 if (xbitpos % BITS_PER_WORD == 0 || xbitpos == padding_correction)
2173 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD, mode);
2175 /* We need a new destination operand each time bitpos is on
2176 a word boundary. */
2177 if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
2178 dst = target;
2179 else if (bitpos % BITS_PER_WORD == 0)
2180 dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, tmode);
2182 /* Use xbitpos for the source extraction (right justified) and
2183 bitpos for the destination store (left justified). */
2184 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
2185 extract_bit_field (src, bitsize,
2186 xbitpos % BITS_PER_WORD, 1, false,
2187 NULL_RTX, copy_mode, copy_mode));
2191 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2192 register if it contains any data, otherwise return null.
2194 This is used on targets that return BLKmode values in registers. */
2197 copy_blkmode_to_reg (enum machine_mode mode, tree src)
2199 int i, n_regs;
2200 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
2201 unsigned int bitsize;
2202 rtx *dst_words, dst, x, src_word = NULL_RTX, dst_word = NULL_RTX;
2203 enum machine_mode dst_mode;
2205 gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
2207 x = expand_normal (src);
2209 bytes = int_size_in_bytes (TREE_TYPE (src));
2210 if (bytes == 0)
2211 return NULL_RTX;
2213 /* If the structure doesn't take up a whole number of words, see
2214 whether the register value should be padded on the left or on
2215 the right. Set PADDING_CORRECTION to the number of padding
2216 bits needed on the left side.
2218 In most ABIs, the structure will be returned at the least end of
2219 the register, which translates to right padding on little-endian
2220 targets and left padding on big-endian targets. The opposite
2221 holds if the structure is returned at the most significant
2222 end of the register. */
2223 if (bytes % UNITS_PER_WORD != 0
2224 && (targetm.calls.return_in_msb (TREE_TYPE (src))
2225 ? !BYTES_BIG_ENDIAN
2226 : BYTES_BIG_ENDIAN))
2227 padding_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2228 * BITS_PER_UNIT));
2230 n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2231 dst_words = XALLOCAVEC (rtx, n_regs);
2232 bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
2234 /* Copy the structure BITSIZE bits at a time. */
2235 for (bitpos = 0, xbitpos = padding_correction;
2236 bitpos < bytes * BITS_PER_UNIT;
2237 bitpos += bitsize, xbitpos += bitsize)
2239 /* We need a new destination pseudo each time xbitpos is
2240 on a word boundary and when xbitpos == padding_correction
2241 (the first time through). */
2242 if (xbitpos % BITS_PER_WORD == 0
2243 || xbitpos == padding_correction)
2245 /* Generate an appropriate register. */
2246 dst_word = gen_reg_rtx (word_mode);
2247 dst_words[xbitpos / BITS_PER_WORD] = dst_word;
2249 /* Clear the destination before we move anything into it. */
2250 emit_move_insn (dst_word, CONST0_RTX (word_mode));
2253 /* We need a new source operand each time bitpos is on a word
2254 boundary. */
2255 if (bitpos % BITS_PER_WORD == 0)
2256 src_word = operand_subword_force (x, bitpos / BITS_PER_WORD, BLKmode);
2258 /* Use bitpos for the source extraction (left justified) and
2259 xbitpos for the destination store (right justified). */
2260 store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
2261 0, 0, word_mode,
2262 extract_bit_field (src_word, bitsize,
2263 bitpos % BITS_PER_WORD, 1, false,
2264 NULL_RTX, word_mode, word_mode));
2267 if (mode == BLKmode)
2269 /* Find the smallest integer mode large enough to hold the
2270 entire structure. */
2271 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2272 mode != VOIDmode;
2273 mode = GET_MODE_WIDER_MODE (mode))
2274 /* Have we found a large enough mode? */
2275 if (GET_MODE_SIZE (mode) >= bytes)
2276 break;
2278 /* A suitable mode should have been found. */
2279 gcc_assert (mode != VOIDmode);
2282 if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
2283 dst_mode = word_mode;
2284 else
2285 dst_mode = mode;
2286 dst = gen_reg_rtx (dst_mode);
2288 for (i = 0; i < n_regs; i++)
2289 emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
2291 if (mode != dst_mode)
2292 dst = gen_lowpart (mode, dst);
2294 return dst;
2297 /* Add a USE expression for REG to the (possibly empty) list pointed
2298 to by CALL_FUSAGE. REG must denote a hard register. */
2300 void
2301 use_reg_mode (rtx *call_fusage, rtx reg, enum machine_mode mode)
2303 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
2305 *call_fusage
2306 = gen_rtx_EXPR_LIST (mode, gen_rtx_USE (VOIDmode, reg), *call_fusage);
2309 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2310 starting at REGNO. All of these registers must be hard registers. */
2312 void
2313 use_regs (rtx *call_fusage, int regno, int nregs)
2315 int i;
2317 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
2319 for (i = 0; i < nregs; i++)
2320 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2323 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2324 PARALLEL REGS. This is for calls that pass values in multiple
2325 non-contiguous locations. The Irix 6 ABI has examples of this. */
2327 void
2328 use_group_regs (rtx *call_fusage, rtx regs)
2330 int i;
2332 for (i = 0; i < XVECLEN (regs, 0); i++)
2334 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2336 /* A NULL entry means the parameter goes both on the stack and in
2337 registers. This can also be a MEM for targets that pass values
2338 partially on the stack and partially in registers. */
2339 if (reg != 0 && REG_P (reg))
2340 use_reg (call_fusage, reg);
2344 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2345 assigment and the code of the expresion on the RHS is CODE. Return
2346 NULL otherwise. */
2348 static gimple
2349 get_def_for_expr (tree name, enum tree_code code)
2351 gimple def_stmt;
2353 if (TREE_CODE (name) != SSA_NAME)
2354 return NULL;
2356 def_stmt = get_gimple_for_ssa_name (name);
2357 if (!def_stmt
2358 || gimple_assign_rhs_code (def_stmt) != code)
2359 return NULL;
2361 return def_stmt;
2364 #ifdef HAVE_conditional_move
2365 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2366 assigment and the class of the expresion on the RHS is CLASS. Return
2367 NULL otherwise. */
2369 static gimple
2370 get_def_for_expr_class (tree name, enum tree_code_class tclass)
2372 gimple def_stmt;
2374 if (TREE_CODE (name) != SSA_NAME)
2375 return NULL;
2377 def_stmt = get_gimple_for_ssa_name (name);
2378 if (!def_stmt
2379 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) != tclass)
2380 return NULL;
2382 return def_stmt;
2384 #endif
2387 /* Determine whether the LEN bytes generated by CONSTFUN can be
2388 stored to memory using several move instructions. CONSTFUNDATA is
2389 a pointer which will be passed as argument in every CONSTFUN call.
2390 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2391 a memset operation and false if it's a copy of a constant string.
2392 Return nonzero if a call to store_by_pieces should succeed. */
2395 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2396 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2397 void *constfundata, unsigned int align, bool memsetp)
2399 unsigned HOST_WIDE_INT l;
2400 unsigned int max_size;
2401 HOST_WIDE_INT offset = 0;
2402 enum machine_mode mode;
2403 enum insn_code icode;
2404 int reverse;
2405 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2406 rtx cst ATTRIBUTE_UNUSED;
2408 if (len == 0)
2409 return 1;
2411 if (! (memsetp
2412 ? SET_BY_PIECES_P (len, align)
2413 : STORE_BY_PIECES_P (len, align)))
2414 return 0;
2416 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2418 /* We would first store what we can in the largest integer mode, then go to
2419 successively smaller modes. */
2421 for (reverse = 0;
2422 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2423 reverse++)
2425 l = len;
2426 max_size = STORE_MAX_PIECES + 1;
2427 while (max_size > 1 && l > 0)
2429 mode = widest_int_mode_for_size (max_size);
2431 if (mode == VOIDmode)
2432 break;
2434 icode = optab_handler (mov_optab, mode);
2435 if (icode != CODE_FOR_nothing
2436 && align >= GET_MODE_ALIGNMENT (mode))
2438 unsigned int size = GET_MODE_SIZE (mode);
2440 while (l >= size)
2442 if (reverse)
2443 offset -= size;
2445 cst = (*constfun) (constfundata, offset, mode);
2446 if (!targetm.legitimate_constant_p (mode, cst))
2447 return 0;
2449 if (!reverse)
2450 offset += size;
2452 l -= size;
2456 max_size = GET_MODE_SIZE (mode);
2459 /* The code above should have handled everything. */
2460 gcc_assert (!l);
2463 return 1;
2466 /* Generate several move instructions to store LEN bytes generated by
2467 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2468 pointer which will be passed as argument in every CONSTFUN call.
2469 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2470 a memset operation and false if it's a copy of a constant string.
2471 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2472 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2473 stpcpy. */
2476 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2477 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2478 void *constfundata, unsigned int align, bool memsetp, int endp)
2480 enum machine_mode to_addr_mode = get_address_mode (to);
2481 struct store_by_pieces_d data;
2483 if (len == 0)
2485 gcc_assert (endp != 2);
2486 return to;
2489 gcc_assert (memsetp
2490 ? SET_BY_PIECES_P (len, align)
2491 : STORE_BY_PIECES_P (len, align));
2492 data.constfun = constfun;
2493 data.constfundata = constfundata;
2494 data.len = len;
2495 data.to = to;
2496 store_by_pieces_1 (&data, align);
2497 if (endp)
2499 rtx to1;
2501 gcc_assert (!data.reverse);
2502 if (data.autinc_to)
2504 if (endp == 2)
2506 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2507 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2508 else
2509 data.to_addr = copy_to_mode_reg (to_addr_mode,
2510 plus_constant (to_addr_mode,
2511 data.to_addr,
2512 -1));
2514 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2515 data.offset);
2517 else
2519 if (endp == 2)
2520 --data.offset;
2521 to1 = adjust_address (data.to, QImode, data.offset);
2523 return to1;
2525 else
2526 return data.to;
2529 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2530 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2532 static void
2533 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2535 struct store_by_pieces_d data;
2537 if (len == 0)
2538 return;
2540 data.constfun = clear_by_pieces_1;
2541 data.constfundata = NULL;
2542 data.len = len;
2543 data.to = to;
2544 store_by_pieces_1 (&data, align);
2547 /* Callback routine for clear_by_pieces.
2548 Return const0_rtx unconditionally. */
2550 static rtx
2551 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2552 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2553 enum machine_mode mode ATTRIBUTE_UNUSED)
2555 return const0_rtx;
2558 /* Subroutine of clear_by_pieces and store_by_pieces.
2559 Generate several move instructions to store LEN bytes of block TO. (A MEM
2560 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2562 static void
2563 store_by_pieces_1 (struct store_by_pieces_d *data ATTRIBUTE_UNUSED,
2564 unsigned int align ATTRIBUTE_UNUSED)
2566 enum machine_mode to_addr_mode = get_address_mode (data->to);
2567 rtx to_addr = XEXP (data->to, 0);
2568 unsigned int max_size = STORE_MAX_PIECES + 1;
2569 enum insn_code icode;
2571 data->offset = 0;
2572 data->to_addr = to_addr;
2573 data->autinc_to
2574 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2575 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2577 data->explicit_inc_to = 0;
2578 data->reverse
2579 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2580 if (data->reverse)
2581 data->offset = data->len;
2583 /* If storing requires more than two move insns,
2584 copy addresses to registers (to make displacements shorter)
2585 and use post-increment if available. */
2586 if (!data->autinc_to
2587 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2589 /* Determine the main mode we'll be using.
2590 MODE might not be used depending on the definitions of the
2591 USE_* macros below. */
2592 enum machine_mode mode ATTRIBUTE_UNUSED
2593 = widest_int_mode_for_size (max_size);
2595 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2597 data->to_addr = copy_to_mode_reg (to_addr_mode,
2598 plus_constant (to_addr_mode,
2599 to_addr,
2600 data->len));
2601 data->autinc_to = 1;
2602 data->explicit_inc_to = -1;
2605 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2606 && ! data->autinc_to)
2608 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2609 data->autinc_to = 1;
2610 data->explicit_inc_to = 1;
2613 if ( !data->autinc_to && CONSTANT_P (to_addr))
2614 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2617 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2619 /* First store what we can in the largest integer mode, then go to
2620 successively smaller modes. */
2622 while (max_size > 1 && data->len > 0)
2624 enum machine_mode mode = widest_int_mode_for_size (max_size);
2626 if (mode == VOIDmode)
2627 break;
2629 icode = optab_handler (mov_optab, mode);
2630 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2631 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2633 max_size = GET_MODE_SIZE (mode);
2636 /* The code above should have handled everything. */
2637 gcc_assert (!data->len);
2640 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2641 with move instructions for mode MODE. GENFUN is the gen_... function
2642 to make a move insn for that mode. DATA has all the other info. */
2644 static void
2645 store_by_pieces_2 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
2646 struct store_by_pieces_d *data)
2648 unsigned int size = GET_MODE_SIZE (mode);
2649 rtx to1, cst;
2651 while (data->len >= size)
2653 if (data->reverse)
2654 data->offset -= size;
2656 if (data->autinc_to)
2657 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2658 data->offset);
2659 else
2660 to1 = adjust_address (data->to, mode, data->offset);
2662 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2663 emit_insn (gen_add2_insn (data->to_addr,
2664 GEN_INT (-(HOST_WIDE_INT) size)));
2666 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2667 emit_insn ((*genfun) (to1, cst));
2669 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2670 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2672 if (! data->reverse)
2673 data->offset += size;
2675 data->len -= size;
2679 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2680 its length in bytes. */
2683 clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
2684 unsigned int expected_align, HOST_WIDE_INT expected_size)
2686 enum machine_mode mode = GET_MODE (object);
2687 unsigned int align;
2689 gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
2691 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2692 just move a zero. Otherwise, do this a piece at a time. */
2693 if (mode != BLKmode
2694 && CONST_INT_P (size)
2695 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
2697 rtx zero = CONST0_RTX (mode);
2698 if (zero != NULL)
2700 emit_move_insn (object, zero);
2701 return NULL;
2704 if (COMPLEX_MODE_P (mode))
2706 zero = CONST0_RTX (GET_MODE_INNER (mode));
2707 if (zero != NULL)
2709 write_complex_part (object, zero, 0);
2710 write_complex_part (object, zero, 1);
2711 return NULL;
2716 if (size == const0_rtx)
2717 return NULL;
2719 align = MEM_ALIGN (object);
2721 if (CONST_INT_P (size)
2722 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2723 clear_by_pieces (object, INTVAL (size), align);
2724 else if (set_storage_via_setmem (object, size, const0_rtx, align,
2725 expected_align, expected_size))
2727 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
2728 return set_storage_via_libcall (object, size, const0_rtx,
2729 method == BLOCK_OP_TAILCALL);
2730 else
2731 gcc_unreachable ();
2733 return NULL;
2737 clear_storage (rtx object, rtx size, enum block_op_methods method)
2739 return clear_storage_hints (object, size, method, 0, -1);
2743 /* A subroutine of clear_storage. Expand a call to memset.
2744 Return the return value of memset, 0 otherwise. */
2747 set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
2749 tree call_expr, fn, object_tree, size_tree, val_tree;
2750 enum machine_mode size_mode;
2751 rtx retval;
2753 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2754 place those into new pseudos into a VAR_DECL and use them later. */
2756 object = copy_addr_to_reg (XEXP (object, 0));
2758 size_mode = TYPE_MODE (sizetype);
2759 size = convert_to_mode (size_mode, size, 1);
2760 size = copy_to_mode_reg (size_mode, size);
2762 /* It is incorrect to use the libcall calling conventions to call
2763 memset in this context. This could be a user call to memset and
2764 the user may wish to examine the return value from memset. For
2765 targets where libcalls and normal calls have different conventions
2766 for returning pointers, we could end up generating incorrect code. */
2768 object_tree = make_tree (ptr_type_node, object);
2769 if (!CONST_INT_P (val))
2770 val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
2771 size_tree = make_tree (sizetype, size);
2772 val_tree = make_tree (integer_type_node, val);
2774 fn = clear_storage_libcall_fn (true);
2775 call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
2776 CALL_EXPR_TAILCALL (call_expr) = tailcall;
2778 retval = expand_normal (call_expr);
2780 return retval;
2783 /* A subroutine of set_storage_via_libcall. Create the tree node
2784 for the function we use for block clears. */
2786 tree block_clear_fn;
2788 void
2789 init_block_clear_fn (const char *asmspec)
2791 if (!block_clear_fn)
2793 tree fn, args;
2795 fn = get_identifier ("memset");
2796 args = build_function_type_list (ptr_type_node, ptr_type_node,
2797 integer_type_node, sizetype,
2798 NULL_TREE);
2800 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
2801 DECL_EXTERNAL (fn) = 1;
2802 TREE_PUBLIC (fn) = 1;
2803 DECL_ARTIFICIAL (fn) = 1;
2804 TREE_NOTHROW (fn) = 1;
2805 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
2806 DECL_VISIBILITY_SPECIFIED (fn) = 1;
2808 block_clear_fn = fn;
2811 if (asmspec)
2812 set_user_assembler_name (block_clear_fn, asmspec);
2815 static tree
2816 clear_storage_libcall_fn (int for_call)
2818 static bool emitted_extern;
2820 if (!block_clear_fn)
2821 init_block_clear_fn (NULL);
2823 if (for_call && !emitted_extern)
2825 emitted_extern = true;
2826 make_decl_rtl (block_clear_fn);
2829 return block_clear_fn;
2832 /* Expand a setmem pattern; return true if successful. */
2834 bool
2835 set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
2836 unsigned int expected_align, HOST_WIDE_INT expected_size)
2838 /* Try the most limited insn first, because there's no point
2839 including more than one in the machine description unless
2840 the more limited one has some advantage. */
2842 enum machine_mode mode;
2844 if (expected_align < align)
2845 expected_align = align;
2847 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2848 mode = GET_MODE_WIDER_MODE (mode))
2850 enum insn_code code = direct_optab_handler (setmem_optab, mode);
2852 if (code != CODE_FOR_nothing
2853 /* We don't need MODE to be narrower than
2854 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2855 the mode mask, as it is returned by the macro, it will
2856 definitely be less than the actual mode mask. */
2857 && ((CONST_INT_P (size)
2858 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2859 <= (GET_MODE_MASK (mode) >> 1)))
2860 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD))
2862 struct expand_operand ops[6];
2863 unsigned int nops;
2865 nops = insn_data[(int) code].n_generator_args;
2866 gcc_assert (nops == 4 || nops == 6);
2868 create_fixed_operand (&ops[0], object);
2869 /* The check above guarantees that this size conversion is valid. */
2870 create_convert_operand_to (&ops[1], size, mode, true);
2871 create_convert_operand_from (&ops[2], val, byte_mode, true);
2872 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2873 if (nops == 6)
2875 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2876 create_integer_operand (&ops[5], expected_size);
2878 if (maybe_expand_insn (code, nops, ops))
2879 return true;
2883 return false;
2887 /* Write to one of the components of the complex value CPLX. Write VAL to
2888 the real part if IMAG_P is false, and the imaginary part if its true. */
2890 static void
2891 write_complex_part (rtx cplx, rtx val, bool imag_p)
2893 enum machine_mode cmode;
2894 enum machine_mode imode;
2895 unsigned ibitsize;
2897 if (GET_CODE (cplx) == CONCAT)
2899 emit_move_insn (XEXP (cplx, imag_p), val);
2900 return;
2903 cmode = GET_MODE (cplx);
2904 imode = GET_MODE_INNER (cmode);
2905 ibitsize = GET_MODE_BITSIZE (imode);
2907 /* For MEMs simplify_gen_subreg may generate an invalid new address
2908 because, e.g., the original address is considered mode-dependent
2909 by the target, which restricts simplify_subreg from invoking
2910 adjust_address_nv. Instead of preparing fallback support for an
2911 invalid address, we call adjust_address_nv directly. */
2912 if (MEM_P (cplx))
2914 emit_move_insn (adjust_address_nv (cplx, imode,
2915 imag_p ? GET_MODE_SIZE (imode) : 0),
2916 val);
2917 return;
2920 /* If the sub-object is at least word sized, then we know that subregging
2921 will work. This special case is important, since store_bit_field
2922 wants to operate on integer modes, and there's rarely an OImode to
2923 correspond to TCmode. */
2924 if (ibitsize >= BITS_PER_WORD
2925 /* For hard regs we have exact predicates. Assume we can split
2926 the original object if it spans an even number of hard regs.
2927 This special case is important for SCmode on 64-bit platforms
2928 where the natural size of floating-point regs is 32-bit. */
2929 || (REG_P (cplx)
2930 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2931 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2933 rtx part = simplify_gen_subreg (imode, cplx, cmode,
2934 imag_p ? GET_MODE_SIZE (imode) : 0);
2935 if (part)
2937 emit_move_insn (part, val);
2938 return;
2940 else
2941 /* simplify_gen_subreg may fail for sub-word MEMs. */
2942 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2945 store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, 0, 0, imode, val);
2948 /* Extract one of the components of the complex value CPLX. Extract the
2949 real part if IMAG_P is false, and the imaginary part if it's true. */
2951 static rtx
2952 read_complex_part (rtx cplx, bool imag_p)
2954 enum machine_mode cmode, imode;
2955 unsigned ibitsize;
2957 if (GET_CODE (cplx) == CONCAT)
2958 return XEXP (cplx, imag_p);
2960 cmode = GET_MODE (cplx);
2961 imode = GET_MODE_INNER (cmode);
2962 ibitsize = GET_MODE_BITSIZE (imode);
2964 /* Special case reads from complex constants that got spilled to memory. */
2965 if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
2967 tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
2968 if (decl && TREE_CODE (decl) == COMPLEX_CST)
2970 tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
2971 if (CONSTANT_CLASS_P (part))
2972 return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
2976 /* For MEMs simplify_gen_subreg may generate an invalid new address
2977 because, e.g., the original address is considered mode-dependent
2978 by the target, which restricts simplify_subreg from invoking
2979 adjust_address_nv. Instead of preparing fallback support for an
2980 invalid address, we call adjust_address_nv directly. */
2981 if (MEM_P (cplx))
2982 return adjust_address_nv (cplx, imode,
2983 imag_p ? GET_MODE_SIZE (imode) : 0);
2985 /* If the sub-object is at least word sized, then we know that subregging
2986 will work. This special case is important, since extract_bit_field
2987 wants to operate on integer modes, and there's rarely an OImode to
2988 correspond to TCmode. */
2989 if (ibitsize >= BITS_PER_WORD
2990 /* For hard regs we have exact predicates. Assume we can split
2991 the original object if it spans an even number of hard regs.
2992 This special case is important for SCmode on 64-bit platforms
2993 where the natural size of floating-point regs is 32-bit. */
2994 || (REG_P (cplx)
2995 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2996 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2998 rtx ret = simplify_gen_subreg (imode, cplx, cmode,
2999 imag_p ? GET_MODE_SIZE (imode) : 0);
3000 if (ret)
3001 return ret;
3002 else
3003 /* simplify_gen_subreg may fail for sub-word MEMs. */
3004 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
3007 return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
3008 true, false, NULL_RTX, imode, imode);
3011 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3012 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3013 represented in NEW_MODE. If FORCE is true, this will never happen, as
3014 we'll force-create a SUBREG if needed. */
3016 static rtx
3017 emit_move_change_mode (enum machine_mode new_mode,
3018 enum machine_mode old_mode, rtx x, bool force)
3020 rtx ret;
3022 if (push_operand (x, GET_MODE (x)))
3024 ret = gen_rtx_MEM (new_mode, XEXP (x, 0));
3025 MEM_COPY_ATTRIBUTES (ret, x);
3027 else if (MEM_P (x))
3029 /* We don't have to worry about changing the address since the
3030 size in bytes is supposed to be the same. */
3031 if (reload_in_progress)
3033 /* Copy the MEM to change the mode and move any
3034 substitutions from the old MEM to the new one. */
3035 ret = adjust_address_nv (x, new_mode, 0);
3036 copy_replacements (x, ret);
3038 else
3039 ret = adjust_address (x, new_mode, 0);
3041 else
3043 /* Note that we do want simplify_subreg's behavior of validating
3044 that the new mode is ok for a hard register. If we were to use
3045 simplify_gen_subreg, we would create the subreg, but would
3046 probably run into the target not being able to implement it. */
3047 /* Except, of course, when FORCE is true, when this is exactly what
3048 we want. Which is needed for CCmodes on some targets. */
3049 if (force)
3050 ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
3051 else
3052 ret = simplify_subreg (new_mode, x, old_mode, 0);
3055 return ret;
3058 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3059 an integer mode of the same size as MODE. Returns the instruction
3060 emitted, or NULL if such a move could not be generated. */
3062 static rtx
3063 emit_move_via_integer (enum machine_mode mode, rtx x, rtx y, bool force)
3065 enum machine_mode imode;
3066 enum insn_code code;
3068 /* There must exist a mode of the exact size we require. */
3069 imode = int_mode_for_mode (mode);
3070 if (imode == BLKmode)
3071 return NULL_RTX;
3073 /* The target must support moves in this mode. */
3074 code = optab_handler (mov_optab, imode);
3075 if (code == CODE_FOR_nothing)
3076 return NULL_RTX;
3078 x = emit_move_change_mode (imode, mode, x, force);
3079 if (x == NULL_RTX)
3080 return NULL_RTX;
3081 y = emit_move_change_mode (imode, mode, y, force);
3082 if (y == NULL_RTX)
3083 return NULL_RTX;
3084 return emit_insn (GEN_FCN (code) (x, y));
3087 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3088 Return an equivalent MEM that does not use an auto-increment. */
3090 static rtx
3091 emit_move_resolve_push (enum machine_mode mode, rtx x)
3093 enum rtx_code code = GET_CODE (XEXP (x, 0));
3094 HOST_WIDE_INT adjust;
3095 rtx temp;
3097 adjust = GET_MODE_SIZE (mode);
3098 #ifdef PUSH_ROUNDING
3099 adjust = PUSH_ROUNDING (adjust);
3100 #endif
3101 if (code == PRE_DEC || code == POST_DEC)
3102 adjust = -adjust;
3103 else if (code == PRE_MODIFY || code == POST_MODIFY)
3105 rtx expr = XEXP (XEXP (x, 0), 1);
3106 HOST_WIDE_INT val;
3108 gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
3109 gcc_assert (CONST_INT_P (XEXP (expr, 1)));
3110 val = INTVAL (XEXP (expr, 1));
3111 if (GET_CODE (expr) == MINUS)
3112 val = -val;
3113 gcc_assert (adjust == val || adjust == -val);
3114 adjust = val;
3117 /* Do not use anti_adjust_stack, since we don't want to update
3118 stack_pointer_delta. */
3119 temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
3120 GEN_INT (adjust), stack_pointer_rtx,
3121 0, OPTAB_LIB_WIDEN);
3122 if (temp != stack_pointer_rtx)
3123 emit_move_insn (stack_pointer_rtx, temp);
3125 switch (code)
3127 case PRE_INC:
3128 case PRE_DEC:
3129 case PRE_MODIFY:
3130 temp = stack_pointer_rtx;
3131 break;
3132 case POST_INC:
3133 case POST_DEC:
3134 case POST_MODIFY:
3135 temp = plus_constant (Pmode, stack_pointer_rtx, -adjust);
3136 break;
3137 default:
3138 gcc_unreachable ();
3141 return replace_equiv_address (x, temp);
3144 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3145 X is known to satisfy push_operand, and MODE is known to be complex.
3146 Returns the last instruction emitted. */
3149 emit_move_complex_push (enum machine_mode mode, rtx x, rtx y)
3151 enum machine_mode submode = GET_MODE_INNER (mode);
3152 bool imag_first;
3154 #ifdef PUSH_ROUNDING
3155 unsigned int submodesize = GET_MODE_SIZE (submode);
3157 /* In case we output to the stack, but the size is smaller than the
3158 machine can push exactly, we need to use move instructions. */
3159 if (PUSH_ROUNDING (submodesize) != submodesize)
3161 x = emit_move_resolve_push (mode, x);
3162 return emit_move_insn (x, y);
3164 #endif
3166 /* Note that the real part always precedes the imag part in memory
3167 regardless of machine's endianness. */
3168 switch (GET_CODE (XEXP (x, 0)))
3170 case PRE_DEC:
3171 case POST_DEC:
3172 imag_first = true;
3173 break;
3174 case PRE_INC:
3175 case POST_INC:
3176 imag_first = false;
3177 break;
3178 default:
3179 gcc_unreachable ();
3182 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3183 read_complex_part (y, imag_first));
3184 return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3185 read_complex_part (y, !imag_first));
3188 /* A subroutine of emit_move_complex. Perform the move from Y to X
3189 via two moves of the parts. Returns the last instruction emitted. */
3192 emit_move_complex_parts (rtx x, rtx y)
3194 /* Show the output dies here. This is necessary for SUBREGs
3195 of pseudos since we cannot track their lifetimes correctly;
3196 hard regs shouldn't appear here except as return values. */
3197 if (!reload_completed && !reload_in_progress
3198 && REG_P (x) && !reg_overlap_mentioned_p (x, y))
3199 emit_clobber (x);
3201 write_complex_part (x, read_complex_part (y, false), false);
3202 write_complex_part (x, read_complex_part (y, true), true);
3204 return get_last_insn ();
3207 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3208 MODE is known to be complex. Returns the last instruction emitted. */
3210 static rtx
3211 emit_move_complex (enum machine_mode mode, rtx x, rtx y)
3213 bool try_int;
3215 /* Need to take special care for pushes, to maintain proper ordering
3216 of the data, and possibly extra padding. */
3217 if (push_operand (x, mode))
3218 return emit_move_complex_push (mode, x, y);
3220 /* See if we can coerce the target into moving both values at once. */
3222 /* Move floating point as parts. */
3223 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3224 && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing)
3225 try_int = false;
3226 /* Not possible if the values are inherently not adjacent. */
3227 else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
3228 try_int = false;
3229 /* Is possible if both are registers (or subregs of registers). */
3230 else if (register_operand (x, mode) && register_operand (y, mode))
3231 try_int = true;
3232 /* If one of the operands is a memory, and alignment constraints
3233 are friendly enough, we may be able to do combined memory operations.
3234 We do not attempt this if Y is a constant because that combination is
3235 usually better with the by-parts thing below. */
3236 else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
3237 && (!STRICT_ALIGNMENT
3238 || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
3239 try_int = true;
3240 else
3241 try_int = false;
3243 if (try_int)
3245 rtx ret;
3247 /* For memory to memory moves, optimal behavior can be had with the
3248 existing block move logic. */
3249 if (MEM_P (x) && MEM_P (y))
3251 emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
3252 BLOCK_OP_NO_LIBCALL);
3253 return get_last_insn ();
3256 ret = emit_move_via_integer (mode, x, y, true);
3257 if (ret)
3258 return ret;
3261 return emit_move_complex_parts (x, y);
3264 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3265 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3267 static rtx
3268 emit_move_ccmode (enum machine_mode mode, rtx x, rtx y)
3270 rtx ret;
3272 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3273 if (mode != CCmode)
3275 enum insn_code code = optab_handler (mov_optab, CCmode);
3276 if (code != CODE_FOR_nothing)
3278 x = emit_move_change_mode (CCmode, mode, x, true);
3279 y = emit_move_change_mode (CCmode, mode, y, true);
3280 return emit_insn (GEN_FCN (code) (x, y));
3284 /* Otherwise, find the MODE_INT mode of the same width. */
3285 ret = emit_move_via_integer (mode, x, y, false);
3286 gcc_assert (ret != NULL);
3287 return ret;
3290 /* Return true if word I of OP lies entirely in the
3291 undefined bits of a paradoxical subreg. */
3293 static bool
3294 undefined_operand_subword_p (const_rtx op, int i)
3296 enum machine_mode innermode, innermostmode;
3297 int offset;
3298 if (GET_CODE (op) != SUBREG)
3299 return false;
3300 innermode = GET_MODE (op);
3301 innermostmode = GET_MODE (SUBREG_REG (op));
3302 offset = i * UNITS_PER_WORD + SUBREG_BYTE (op);
3303 /* The SUBREG_BYTE represents offset, as if the value were stored in
3304 memory, except for a paradoxical subreg where we define
3305 SUBREG_BYTE to be 0; undo this exception as in
3306 simplify_subreg. */
3307 if (SUBREG_BYTE (op) == 0
3308 && GET_MODE_SIZE (innermostmode) < GET_MODE_SIZE (innermode))
3310 int difference = (GET_MODE_SIZE (innermostmode) - GET_MODE_SIZE (innermode));
3311 if (WORDS_BIG_ENDIAN)
3312 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
3313 if (BYTES_BIG_ENDIAN)
3314 offset += difference % UNITS_PER_WORD;
3316 if (offset >= GET_MODE_SIZE (innermostmode)
3317 || offset <= -GET_MODE_SIZE (word_mode))
3318 return true;
3319 return false;
3322 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3323 MODE is any multi-word or full-word mode that lacks a move_insn
3324 pattern. Note that you will get better code if you define such
3325 patterns, even if they must turn into multiple assembler instructions. */
3327 static rtx
3328 emit_move_multi_word (enum machine_mode mode, rtx x, rtx y)
3330 rtx last_insn = 0;
3331 rtx seq, inner;
3332 bool need_clobber;
3333 int i;
3335 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
3337 /* If X is a push on the stack, do the push now and replace
3338 X with a reference to the stack pointer. */
3339 if (push_operand (x, mode))
3340 x = emit_move_resolve_push (mode, x);
3342 /* If we are in reload, see if either operand is a MEM whose address
3343 is scheduled for replacement. */
3344 if (reload_in_progress && MEM_P (x)
3345 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3346 x = replace_equiv_address_nv (x, inner);
3347 if (reload_in_progress && MEM_P (y)
3348 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3349 y = replace_equiv_address_nv (y, inner);
3351 start_sequence ();
3353 need_clobber = false;
3354 for (i = 0;
3355 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3356 i++)
3358 rtx xpart = operand_subword (x, i, 1, mode);
3359 rtx ypart;
3361 /* Do not generate code for a move if it would come entirely
3362 from the undefined bits of a paradoxical subreg. */
3363 if (undefined_operand_subword_p (y, i))
3364 continue;
3366 ypart = operand_subword (y, i, 1, mode);
3368 /* If we can't get a part of Y, put Y into memory if it is a
3369 constant. Otherwise, force it into a register. Then we must
3370 be able to get a part of Y. */
3371 if (ypart == 0 && CONSTANT_P (y))
3373 y = use_anchored_address (force_const_mem (mode, y));
3374 ypart = operand_subword (y, i, 1, mode);
3376 else if (ypart == 0)
3377 ypart = operand_subword_force (y, i, mode);
3379 gcc_assert (xpart && ypart);
3381 need_clobber |= (GET_CODE (xpart) == SUBREG);
3383 last_insn = emit_move_insn (xpart, ypart);
3386 seq = get_insns ();
3387 end_sequence ();
3389 /* Show the output dies here. This is necessary for SUBREGs
3390 of pseudos since we cannot track their lifetimes correctly;
3391 hard regs shouldn't appear here except as return values.
3392 We never want to emit such a clobber after reload. */
3393 if (x != y
3394 && ! (reload_in_progress || reload_completed)
3395 && need_clobber != 0)
3396 emit_clobber (x);
3398 emit_insn (seq);
3400 return last_insn;
3403 /* Low level part of emit_move_insn.
3404 Called just like emit_move_insn, but assumes X and Y
3405 are basically valid. */
3408 emit_move_insn_1 (rtx x, rtx y)
3410 enum machine_mode mode = GET_MODE (x);
3411 enum insn_code code;
3413 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
3415 code = optab_handler (mov_optab, mode);
3416 if (code != CODE_FOR_nothing)
3417 return emit_insn (GEN_FCN (code) (x, y));
3419 /* Expand complex moves by moving real part and imag part. */
3420 if (COMPLEX_MODE_P (mode))
3421 return emit_move_complex (mode, x, y);
3423 if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
3424 || ALL_FIXED_POINT_MODE_P (mode))
3426 rtx result = emit_move_via_integer (mode, x, y, true);
3428 /* If we can't find an integer mode, use multi words. */
3429 if (result)
3430 return result;
3431 else
3432 return emit_move_multi_word (mode, x, y);
3435 if (GET_MODE_CLASS (mode) == MODE_CC)
3436 return emit_move_ccmode (mode, x, y);
3438 /* Try using a move pattern for the corresponding integer mode. This is
3439 only safe when simplify_subreg can convert MODE constants into integer
3440 constants. At present, it can only do this reliably if the value
3441 fits within a HOST_WIDE_INT. */
3442 if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3444 rtx ret = emit_move_via_integer (mode, x, y, lra_in_progress);
3446 if (ret)
3448 if (! lra_in_progress || recog (PATTERN (ret), ret, 0) >= 0)
3449 return ret;
3453 return emit_move_multi_word (mode, x, y);
3456 /* Generate code to copy Y into X.
3457 Both Y and X must have the same mode, except that
3458 Y can be a constant with VOIDmode.
3459 This mode cannot be BLKmode; use emit_block_move for that.
3461 Return the last instruction emitted. */
3464 emit_move_insn (rtx x, rtx y)
3466 enum machine_mode mode = GET_MODE (x);
3467 rtx y_cst = NULL_RTX;
3468 rtx last_insn, set;
3470 gcc_assert (mode != BLKmode
3471 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
3473 if (CONSTANT_P (y))
3475 if (optimize
3476 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3477 && (last_insn = compress_float_constant (x, y)))
3478 return last_insn;
3480 y_cst = y;
3482 if (!targetm.legitimate_constant_p (mode, y))
3484 y = force_const_mem (mode, y);
3486 /* If the target's cannot_force_const_mem prevented the spill,
3487 assume that the target's move expanders will also take care
3488 of the non-legitimate constant. */
3489 if (!y)
3490 y = y_cst;
3491 else
3492 y = use_anchored_address (y);
3496 /* If X or Y are memory references, verify that their addresses are valid
3497 for the machine. */
3498 if (MEM_P (x)
3499 && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
3500 MEM_ADDR_SPACE (x))
3501 && ! push_operand (x, GET_MODE (x))))
3502 x = validize_mem (x);
3504 if (MEM_P (y)
3505 && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
3506 MEM_ADDR_SPACE (y)))
3507 y = validize_mem (y);
3509 gcc_assert (mode != BLKmode);
3511 last_insn = emit_move_insn_1 (x, y);
3513 if (y_cst && REG_P (x)
3514 && (set = single_set (last_insn)) != NULL_RTX
3515 && SET_DEST (set) == x
3516 && ! rtx_equal_p (y_cst, SET_SRC (set)))
3517 set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
3519 return last_insn;
3522 /* If Y is representable exactly in a narrower mode, and the target can
3523 perform the extension directly from constant or memory, then emit the
3524 move as an extension. */
3526 static rtx
3527 compress_float_constant (rtx x, rtx y)
3529 enum machine_mode dstmode = GET_MODE (x);
3530 enum machine_mode orig_srcmode = GET_MODE (y);
3531 enum machine_mode srcmode;
3532 REAL_VALUE_TYPE r;
3533 int oldcost, newcost;
3534 bool speed = optimize_insn_for_speed_p ();
3536 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3538 if (targetm.legitimate_constant_p (dstmode, y))
3539 oldcost = set_src_cost (y, speed);
3540 else
3541 oldcost = set_src_cost (force_const_mem (dstmode, y), speed);
3543 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3544 srcmode != orig_srcmode;
3545 srcmode = GET_MODE_WIDER_MODE (srcmode))
3547 enum insn_code ic;
3548 rtx trunc_y, last_insn;
3550 /* Skip if the target can't extend this way. */
3551 ic = can_extend_p (dstmode, srcmode, 0);
3552 if (ic == CODE_FOR_nothing)
3553 continue;
3555 /* Skip if the narrowed value isn't exact. */
3556 if (! exact_real_truncate (srcmode, &r))
3557 continue;
3559 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3561 if (targetm.legitimate_constant_p (srcmode, trunc_y))
3563 /* Skip if the target needs extra instructions to perform
3564 the extension. */
3565 if (!insn_operand_matches (ic, 1, trunc_y))
3566 continue;
3567 /* This is valid, but may not be cheaper than the original. */
3568 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3569 speed);
3570 if (oldcost < newcost)
3571 continue;
3573 else if (float_extend_from_mem[dstmode][srcmode])
3575 trunc_y = force_const_mem (srcmode, trunc_y);
3576 /* This is valid, but may not be cheaper than the original. */
3577 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3578 speed);
3579 if (oldcost < newcost)
3580 continue;
3581 trunc_y = validize_mem (trunc_y);
3583 else
3584 continue;
3586 /* For CSE's benefit, force the compressed constant pool entry
3587 into a new pseudo. This constant may be used in different modes,
3588 and if not, combine will put things back together for us. */
3589 trunc_y = force_reg (srcmode, trunc_y);
3590 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3591 last_insn = get_last_insn ();
3593 if (REG_P (x))
3594 set_unique_reg_note (last_insn, REG_EQUAL, y);
3596 return last_insn;
3599 return NULL_RTX;
3602 /* Pushing data onto the stack. */
3604 /* Push a block of length SIZE (perhaps variable)
3605 and return an rtx to address the beginning of the block.
3606 The value may be virtual_outgoing_args_rtx.
3608 EXTRA is the number of bytes of padding to push in addition to SIZE.
3609 BELOW nonzero means this padding comes at low addresses;
3610 otherwise, the padding comes at high addresses. */
3613 push_block (rtx size, int extra, int below)
3615 rtx temp;
3617 size = convert_modes (Pmode, ptr_mode, size, 1);
3618 if (CONSTANT_P (size))
3619 anti_adjust_stack (plus_constant (Pmode, size, extra));
3620 else if (REG_P (size) && extra == 0)
3621 anti_adjust_stack (size);
3622 else
3624 temp = copy_to_mode_reg (Pmode, size);
3625 if (extra != 0)
3626 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
3627 temp, 0, OPTAB_LIB_WIDEN);
3628 anti_adjust_stack (temp);
3631 #ifndef STACK_GROWS_DOWNWARD
3632 if (0)
3633 #else
3634 if (1)
3635 #endif
3637 temp = virtual_outgoing_args_rtx;
3638 if (extra != 0 && below)
3639 temp = plus_constant (Pmode, temp, extra);
3641 else
3643 if (CONST_INT_P (size))
3644 temp = plus_constant (Pmode, virtual_outgoing_args_rtx,
3645 -INTVAL (size) - (below ? 0 : extra));
3646 else if (extra != 0 && !below)
3647 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3648 negate_rtx (Pmode, plus_constant (Pmode, size,
3649 extra)));
3650 else
3651 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3652 negate_rtx (Pmode, size));
3655 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3658 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3660 static rtx
3661 mem_autoinc_base (rtx mem)
3663 if (MEM_P (mem))
3665 rtx addr = XEXP (mem, 0);
3666 if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
3667 return XEXP (addr, 0);
3669 return NULL;
3672 /* A utility routine used here, in reload, and in try_split. The insns
3673 after PREV up to and including LAST are known to adjust the stack,
3674 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3675 placing notes as appropriate. PREV may be NULL, indicating the
3676 entire insn sequence prior to LAST should be scanned.
3678 The set of allowed stack pointer modifications is small:
3679 (1) One or more auto-inc style memory references (aka pushes),
3680 (2) One or more addition/subtraction with the SP as destination,
3681 (3) A single move insn with the SP as destination,
3682 (4) A call_pop insn,
3683 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3685 Insns in the sequence that do not modify the SP are ignored,
3686 except for noreturn calls.
3688 The return value is the amount of adjustment that can be trivially
3689 verified, via immediate operand or auto-inc. If the adjustment
3690 cannot be trivially extracted, the return value is INT_MIN. */
3692 HOST_WIDE_INT
3693 find_args_size_adjust (rtx insn)
3695 rtx dest, set, pat;
3696 int i;
3698 pat = PATTERN (insn);
3699 set = NULL;
3701 /* Look for a call_pop pattern. */
3702 if (CALL_P (insn))
3704 /* We have to allow non-call_pop patterns for the case
3705 of emit_single_push_insn of a TLS address. */
3706 if (GET_CODE (pat) != PARALLEL)
3707 return 0;
3709 /* All call_pop have a stack pointer adjust in the parallel.
3710 The call itself is always first, and the stack adjust is
3711 usually last, so search from the end. */
3712 for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
3714 set = XVECEXP (pat, 0, i);
3715 if (GET_CODE (set) != SET)
3716 continue;
3717 dest = SET_DEST (set);
3718 if (dest == stack_pointer_rtx)
3719 break;
3721 /* We'd better have found the stack pointer adjust. */
3722 if (i == 0)
3723 return 0;
3724 /* Fall through to process the extracted SET and DEST
3725 as if it was a standalone insn. */
3727 else if (GET_CODE (pat) == SET)
3728 set = pat;
3729 else if ((set = single_set (insn)) != NULL)
3731 else if (GET_CODE (pat) == PARALLEL)
3733 /* ??? Some older ports use a parallel with a stack adjust
3734 and a store for a PUSH_ROUNDING pattern, rather than a
3735 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3736 /* ??? See h8300 and m68k, pushqi1. */
3737 for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
3739 set = XVECEXP (pat, 0, i);
3740 if (GET_CODE (set) != SET)
3741 continue;
3742 dest = SET_DEST (set);
3743 if (dest == stack_pointer_rtx)
3744 break;
3746 /* We do not expect an auto-inc of the sp in the parallel. */
3747 gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
3748 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3749 != stack_pointer_rtx);
3751 if (i < 0)
3752 return 0;
3754 else
3755 return 0;
3757 dest = SET_DEST (set);
3759 /* Look for direct modifications of the stack pointer. */
3760 if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
3762 /* Look for a trivial adjustment, otherwise assume nothing. */
3763 /* Note that the SPU restore_stack_block pattern refers to
3764 the stack pointer in V4SImode. Consider that non-trivial. */
3765 if (SCALAR_INT_MODE_P (GET_MODE (dest))
3766 && GET_CODE (SET_SRC (set)) == PLUS
3767 && XEXP (SET_SRC (set), 0) == stack_pointer_rtx
3768 && CONST_INT_P (XEXP (SET_SRC (set), 1)))
3769 return INTVAL (XEXP (SET_SRC (set), 1));
3770 /* ??? Reload can generate no-op moves, which will be cleaned
3771 up later. Recognize it and continue searching. */
3772 else if (rtx_equal_p (dest, SET_SRC (set)))
3773 return 0;
3774 else
3775 return HOST_WIDE_INT_MIN;
3777 else
3779 rtx mem, addr;
3781 /* Otherwise only think about autoinc patterns. */
3782 if (mem_autoinc_base (dest) == stack_pointer_rtx)
3784 mem = dest;
3785 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3786 != stack_pointer_rtx);
3788 else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
3789 mem = SET_SRC (set);
3790 else
3791 return 0;
3793 addr = XEXP (mem, 0);
3794 switch (GET_CODE (addr))
3796 case PRE_INC:
3797 case POST_INC:
3798 return GET_MODE_SIZE (GET_MODE (mem));
3799 case PRE_DEC:
3800 case POST_DEC:
3801 return -GET_MODE_SIZE (GET_MODE (mem));
3802 case PRE_MODIFY:
3803 case POST_MODIFY:
3804 addr = XEXP (addr, 1);
3805 gcc_assert (GET_CODE (addr) == PLUS);
3806 gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
3807 gcc_assert (CONST_INT_P (XEXP (addr, 1)));
3808 return INTVAL (XEXP (addr, 1));
3809 default:
3810 gcc_unreachable ();
3816 fixup_args_size_notes (rtx prev, rtx last, int end_args_size)
3818 int args_size = end_args_size;
3819 bool saw_unknown = false;
3820 rtx insn;
3822 for (insn = last; insn != prev; insn = PREV_INSN (insn))
3824 HOST_WIDE_INT this_delta;
3826 if (!NONDEBUG_INSN_P (insn))
3827 continue;
3829 this_delta = find_args_size_adjust (insn);
3830 if (this_delta == 0)
3832 if (!CALL_P (insn)
3833 || ACCUMULATE_OUTGOING_ARGS
3834 || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
3835 continue;
3838 gcc_assert (!saw_unknown);
3839 if (this_delta == HOST_WIDE_INT_MIN)
3840 saw_unknown = true;
3842 add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (args_size));
3843 #ifdef STACK_GROWS_DOWNWARD
3844 this_delta = -(unsigned HOST_WIDE_INT) this_delta;
3845 #endif
3846 args_size -= this_delta;
3849 return saw_unknown ? INT_MIN : args_size;
3852 #ifdef PUSH_ROUNDING
3853 /* Emit single push insn. */
3855 static void
3856 emit_single_push_insn_1 (enum machine_mode mode, rtx x, tree type)
3858 rtx dest_addr;
3859 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3860 rtx dest;
3861 enum insn_code icode;
3863 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3864 /* If there is push pattern, use it. Otherwise try old way of throwing
3865 MEM representing push operation to move expander. */
3866 icode = optab_handler (push_optab, mode);
3867 if (icode != CODE_FOR_nothing)
3869 struct expand_operand ops[1];
3871 create_input_operand (&ops[0], x, mode);
3872 if (maybe_expand_insn (icode, 1, ops))
3873 return;
3875 if (GET_MODE_SIZE (mode) == rounded_size)
3876 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3877 /* If we are to pad downward, adjust the stack pointer first and
3878 then store X into the stack location using an offset. This is
3879 because emit_move_insn does not know how to pad; it does not have
3880 access to type. */
3881 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3883 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3884 HOST_WIDE_INT offset;
3886 emit_move_insn (stack_pointer_rtx,
3887 expand_binop (Pmode,
3888 #ifdef STACK_GROWS_DOWNWARD
3889 sub_optab,
3890 #else
3891 add_optab,
3892 #endif
3893 stack_pointer_rtx,
3894 GEN_INT (rounded_size),
3895 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3897 offset = (HOST_WIDE_INT) padding_size;
3898 #ifdef STACK_GROWS_DOWNWARD
3899 if (STACK_PUSH_CODE == POST_DEC)
3900 /* We have already decremented the stack pointer, so get the
3901 previous value. */
3902 offset += (HOST_WIDE_INT) rounded_size;
3903 #else
3904 if (STACK_PUSH_CODE == POST_INC)
3905 /* We have already incremented the stack pointer, so get the
3906 previous value. */
3907 offset -= (HOST_WIDE_INT) rounded_size;
3908 #endif
3909 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3911 else
3913 #ifdef STACK_GROWS_DOWNWARD
3914 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3915 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3916 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3917 #else
3918 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3919 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3920 GEN_INT (rounded_size));
3921 #endif
3922 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3925 dest = gen_rtx_MEM (mode, dest_addr);
3927 if (type != 0)
3929 set_mem_attributes (dest, type, 1);
3931 if (flag_optimize_sibling_calls)
3932 /* Function incoming arguments may overlap with sibling call
3933 outgoing arguments and we cannot allow reordering of reads
3934 from function arguments with stores to outgoing arguments
3935 of sibling calls. */
3936 set_mem_alias_set (dest, 0);
3938 emit_move_insn (dest, x);
3941 /* Emit and annotate a single push insn. */
3943 static void
3944 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
3946 int delta, old_delta = stack_pointer_delta;
3947 rtx prev = get_last_insn ();
3948 rtx last;
3950 emit_single_push_insn_1 (mode, x, type);
3952 last = get_last_insn ();
3954 /* Notice the common case where we emitted exactly one insn. */
3955 if (PREV_INSN (last) == prev)
3957 add_reg_note (last, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
3958 return;
3961 delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
3962 gcc_assert (delta == INT_MIN || delta == old_delta);
3964 #endif
3966 /* Generate code to push X onto the stack, assuming it has mode MODE and
3967 type TYPE.
3968 MODE is redundant except when X is a CONST_INT (since they don't
3969 carry mode info).
3970 SIZE is an rtx for the size of data to be copied (in bytes),
3971 needed only if X is BLKmode.
3973 ALIGN (in bits) is maximum alignment we can assume.
3975 If PARTIAL and REG are both nonzero, then copy that many of the first
3976 bytes of X into registers starting with REG, and push the rest of X.
3977 The amount of space pushed is decreased by PARTIAL bytes.
3978 REG must be a hard register in this case.
3979 If REG is zero but PARTIAL is not, take any all others actions for an
3980 argument partially in registers, but do not actually load any
3981 registers.
3983 EXTRA is the amount in bytes of extra space to leave next to this arg.
3984 This is ignored if an argument block has already been allocated.
3986 On a machine that lacks real push insns, ARGS_ADDR is the address of
3987 the bottom of the argument block for this call. We use indexing off there
3988 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3989 argument block has not been preallocated.
3991 ARGS_SO_FAR is the size of args previously pushed for this call.
3993 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3994 for arguments passed in registers. If nonzero, it will be the number
3995 of bytes required. */
3997 void
3998 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
3999 unsigned int align, int partial, rtx reg, int extra,
4000 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
4001 rtx alignment_pad)
4003 rtx xinner;
4004 enum direction stack_direction
4005 #ifdef STACK_GROWS_DOWNWARD
4006 = downward;
4007 #else
4008 = upward;
4009 #endif
4011 /* Decide where to pad the argument: `downward' for below,
4012 `upward' for above, or `none' for don't pad it.
4013 Default is below for small data on big-endian machines; else above. */
4014 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
4016 /* Invert direction if stack is post-decrement.
4017 FIXME: why? */
4018 if (STACK_PUSH_CODE == POST_DEC)
4019 if (where_pad != none)
4020 where_pad = (where_pad == downward ? upward : downward);
4022 xinner = x;
4024 if (mode == BLKmode
4025 || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
4027 /* Copy a block into the stack, entirely or partially. */
4029 rtx temp;
4030 int used;
4031 int offset;
4032 int skip;
4034 offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4035 used = partial - offset;
4037 if (mode != BLKmode)
4039 /* A value is to be stored in an insufficiently aligned
4040 stack slot; copy via a suitably aligned slot if
4041 necessary. */
4042 size = GEN_INT (GET_MODE_SIZE (mode));
4043 if (!MEM_P (xinner))
4045 temp = assign_temp (type, 1, 1);
4046 emit_move_insn (temp, xinner);
4047 xinner = temp;
4051 gcc_assert (size);
4053 /* USED is now the # of bytes we need not copy to the stack
4054 because registers will take care of them. */
4056 if (partial != 0)
4057 xinner = adjust_address (xinner, BLKmode, used);
4059 /* If the partial register-part of the arg counts in its stack size,
4060 skip the part of stack space corresponding to the registers.
4061 Otherwise, start copying to the beginning of the stack space,
4062 by setting SKIP to 0. */
4063 skip = (reg_parm_stack_space == 0) ? 0 : used;
4065 #ifdef PUSH_ROUNDING
4066 /* Do it with several push insns if that doesn't take lots of insns
4067 and if there is no difficulty with push insns that skip bytes
4068 on the stack for alignment purposes. */
4069 if (args_addr == 0
4070 && PUSH_ARGS
4071 && CONST_INT_P (size)
4072 && skip == 0
4073 && MEM_ALIGN (xinner) >= align
4074 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
4075 /* Here we avoid the case of a structure whose weak alignment
4076 forces many pushes of a small amount of data,
4077 and such small pushes do rounding that causes trouble. */
4078 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
4079 || align >= BIGGEST_ALIGNMENT
4080 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
4081 == (align / BITS_PER_UNIT)))
4082 && (HOST_WIDE_INT) PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
4084 /* Push padding now if padding above and stack grows down,
4085 or if padding below and stack grows up.
4086 But if space already allocated, this has already been done. */
4087 if (extra && args_addr == 0
4088 && where_pad != none && where_pad != stack_direction)
4089 anti_adjust_stack (GEN_INT (extra));
4091 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
4093 else
4094 #endif /* PUSH_ROUNDING */
4096 rtx target;
4098 /* Otherwise make space on the stack and copy the data
4099 to the address of that space. */
4101 /* Deduct words put into registers from the size we must copy. */
4102 if (partial != 0)
4104 if (CONST_INT_P (size))
4105 size = GEN_INT (INTVAL (size) - used);
4106 else
4107 size = expand_binop (GET_MODE (size), sub_optab, size,
4108 GEN_INT (used), NULL_RTX, 0,
4109 OPTAB_LIB_WIDEN);
4112 /* Get the address of the stack space.
4113 In this case, we do not deal with EXTRA separately.
4114 A single stack adjust will do. */
4115 if (! args_addr)
4117 temp = push_block (size, extra, where_pad == downward);
4118 extra = 0;
4120 else if (CONST_INT_P (args_so_far))
4121 temp = memory_address (BLKmode,
4122 plus_constant (Pmode, args_addr,
4123 skip + INTVAL (args_so_far)));
4124 else
4125 temp = memory_address (BLKmode,
4126 plus_constant (Pmode,
4127 gen_rtx_PLUS (Pmode,
4128 args_addr,
4129 args_so_far),
4130 skip));
4132 if (!ACCUMULATE_OUTGOING_ARGS)
4134 /* If the source is referenced relative to the stack pointer,
4135 copy it to another register to stabilize it. We do not need
4136 to do this if we know that we won't be changing sp. */
4138 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
4139 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
4140 temp = copy_to_reg (temp);
4143 target = gen_rtx_MEM (BLKmode, temp);
4145 /* We do *not* set_mem_attributes here, because incoming arguments
4146 may overlap with sibling call outgoing arguments and we cannot
4147 allow reordering of reads from function arguments with stores
4148 to outgoing arguments of sibling calls. We do, however, want
4149 to record the alignment of the stack slot. */
4150 /* ALIGN may well be better aligned than TYPE, e.g. due to
4151 PARM_BOUNDARY. Assume the caller isn't lying. */
4152 set_mem_align (target, align);
4154 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
4157 else if (partial > 0)
4159 /* Scalar partly in registers. */
4161 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
4162 int i;
4163 int not_stack;
4164 /* # bytes of start of argument
4165 that we must make space for but need not store. */
4166 int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4167 int args_offset = INTVAL (args_so_far);
4168 int skip;
4170 /* Push padding now if padding above and stack grows down,
4171 or if padding below and stack grows up.
4172 But if space already allocated, this has already been done. */
4173 if (extra && args_addr == 0
4174 && where_pad != none && where_pad != stack_direction)
4175 anti_adjust_stack (GEN_INT (extra));
4177 /* If we make space by pushing it, we might as well push
4178 the real data. Otherwise, we can leave OFFSET nonzero
4179 and leave the space uninitialized. */
4180 if (args_addr == 0)
4181 offset = 0;
4183 /* Now NOT_STACK gets the number of words that we don't need to
4184 allocate on the stack. Convert OFFSET to words too. */
4185 not_stack = (partial - offset) / UNITS_PER_WORD;
4186 offset /= UNITS_PER_WORD;
4188 /* If the partial register-part of the arg counts in its stack size,
4189 skip the part of stack space corresponding to the registers.
4190 Otherwise, start copying to the beginning of the stack space,
4191 by setting SKIP to 0. */
4192 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
4194 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
4195 x = validize_mem (force_const_mem (mode, x));
4197 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4198 SUBREGs of such registers are not allowed. */
4199 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
4200 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
4201 x = copy_to_reg (x);
4203 /* Loop over all the words allocated on the stack for this arg. */
4204 /* We can do it by words, because any scalar bigger than a word
4205 has a size a multiple of a word. */
4206 #ifndef PUSH_ARGS_REVERSED
4207 for (i = not_stack; i < size; i++)
4208 #else
4209 for (i = size - 1; i >= not_stack; i--)
4210 #endif
4211 if (i >= not_stack + offset)
4212 emit_push_insn (operand_subword_force (x, i, mode),
4213 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
4214 0, args_addr,
4215 GEN_INT (args_offset + ((i - not_stack + skip)
4216 * UNITS_PER_WORD)),
4217 reg_parm_stack_space, alignment_pad);
4219 else
4221 rtx addr;
4222 rtx dest;
4224 /* Push padding now if padding above and stack grows down,
4225 or if padding below and stack grows up.
4226 But if space already allocated, this has already been done. */
4227 if (extra && args_addr == 0
4228 && where_pad != none && where_pad != stack_direction)
4229 anti_adjust_stack (GEN_INT (extra));
4231 #ifdef PUSH_ROUNDING
4232 if (args_addr == 0 && PUSH_ARGS)
4233 emit_single_push_insn (mode, x, type);
4234 else
4235 #endif
4237 if (CONST_INT_P (args_so_far))
4238 addr
4239 = memory_address (mode,
4240 plus_constant (Pmode, args_addr,
4241 INTVAL (args_so_far)));
4242 else
4243 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
4244 args_so_far));
4245 dest = gen_rtx_MEM (mode, addr);
4247 /* We do *not* set_mem_attributes here, because incoming arguments
4248 may overlap with sibling call outgoing arguments and we cannot
4249 allow reordering of reads from function arguments with stores
4250 to outgoing arguments of sibling calls. We do, however, want
4251 to record the alignment of the stack slot. */
4252 /* ALIGN may well be better aligned than TYPE, e.g. due to
4253 PARM_BOUNDARY. Assume the caller isn't lying. */
4254 set_mem_align (dest, align);
4256 emit_move_insn (dest, x);
4260 /* If part should go in registers, copy that part
4261 into the appropriate registers. Do this now, at the end,
4262 since mem-to-mem copies above may do function calls. */
4263 if (partial > 0 && reg != 0)
4265 /* Handle calls that pass values in multiple non-contiguous locations.
4266 The Irix 6 ABI has examples of this. */
4267 if (GET_CODE (reg) == PARALLEL)
4268 emit_group_load (reg, x, type, -1);
4269 else
4271 gcc_assert (partial % UNITS_PER_WORD == 0);
4272 move_block_to_reg (REGNO (reg), x, partial / UNITS_PER_WORD, mode);
4276 if (extra && args_addr == 0 && where_pad == stack_direction)
4277 anti_adjust_stack (GEN_INT (extra));
4279 if (alignment_pad && args_addr == 0)
4280 anti_adjust_stack (alignment_pad);
4283 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4284 operations. */
4286 static rtx
4287 get_subtarget (rtx x)
4289 return (optimize
4290 || x == 0
4291 /* Only registers can be subtargets. */
4292 || !REG_P (x)
4293 /* Don't use hard regs to avoid extending their life. */
4294 || REGNO (x) < FIRST_PSEUDO_REGISTER
4295 ? 0 : x);
4298 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4299 FIELD is a bitfield. Returns true if the optimization was successful,
4300 and there's nothing else to do. */
4302 static bool
4303 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize,
4304 unsigned HOST_WIDE_INT bitpos,
4305 unsigned HOST_WIDE_INT bitregion_start,
4306 unsigned HOST_WIDE_INT bitregion_end,
4307 enum machine_mode mode1, rtx str_rtx,
4308 tree to, tree src)
4310 enum machine_mode str_mode = GET_MODE (str_rtx);
4311 unsigned int str_bitsize = GET_MODE_BITSIZE (str_mode);
4312 tree op0, op1;
4313 rtx value, result;
4314 optab binop;
4315 gimple srcstmt;
4316 enum tree_code code;
4318 if (mode1 != VOIDmode
4319 || bitsize >= BITS_PER_WORD
4320 || str_bitsize > BITS_PER_WORD
4321 || TREE_SIDE_EFFECTS (to)
4322 || TREE_THIS_VOLATILE (to))
4323 return false;
4325 STRIP_NOPS (src);
4326 if (TREE_CODE (src) != SSA_NAME)
4327 return false;
4328 if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
4329 return false;
4331 srcstmt = get_gimple_for_ssa_name (src);
4332 if (!srcstmt
4333 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
4334 return false;
4336 code = gimple_assign_rhs_code (srcstmt);
4338 op0 = gimple_assign_rhs1 (srcstmt);
4340 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4341 to find its initialization. Hopefully the initialization will
4342 be from a bitfield load. */
4343 if (TREE_CODE (op0) == SSA_NAME)
4345 gimple op0stmt = get_gimple_for_ssa_name (op0);
4347 /* We want to eventually have OP0 be the same as TO, which
4348 should be a bitfield. */
4349 if (!op0stmt
4350 || !is_gimple_assign (op0stmt)
4351 || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
4352 return false;
4353 op0 = gimple_assign_rhs1 (op0stmt);
4356 op1 = gimple_assign_rhs2 (srcstmt);
4358 if (!operand_equal_p (to, op0, 0))
4359 return false;
4361 if (MEM_P (str_rtx))
4363 unsigned HOST_WIDE_INT offset1;
4365 if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
4366 str_mode = word_mode;
4367 str_mode = get_best_mode (bitsize, bitpos,
4368 bitregion_start, bitregion_end,
4369 MEM_ALIGN (str_rtx), str_mode, 0);
4370 if (str_mode == VOIDmode)
4371 return false;
4372 str_bitsize = GET_MODE_BITSIZE (str_mode);
4374 offset1 = bitpos;
4375 bitpos %= str_bitsize;
4376 offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
4377 str_rtx = adjust_address (str_rtx, str_mode, offset1);
4379 else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
4380 return false;
4382 /* If the bit field covers the whole REG/MEM, store_field
4383 will likely generate better code. */
4384 if (bitsize >= str_bitsize)
4385 return false;
4387 /* We can't handle fields split across multiple entities. */
4388 if (bitpos + bitsize > str_bitsize)
4389 return false;
4391 if (BYTES_BIG_ENDIAN)
4392 bitpos = str_bitsize - bitpos - bitsize;
4394 switch (code)
4396 case PLUS_EXPR:
4397 case MINUS_EXPR:
4398 /* For now, just optimize the case of the topmost bitfield
4399 where we don't need to do any masking and also
4400 1 bit bitfields where xor can be used.
4401 We might win by one instruction for the other bitfields
4402 too if insv/extv instructions aren't used, so that
4403 can be added later. */
4404 if (bitpos + bitsize != str_bitsize
4405 && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
4406 break;
4408 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4409 value = convert_modes (str_mode,
4410 TYPE_MODE (TREE_TYPE (op1)), value,
4411 TYPE_UNSIGNED (TREE_TYPE (op1)));
4413 /* We may be accessing data outside the field, which means
4414 we can alias adjacent data. */
4415 if (MEM_P (str_rtx))
4417 str_rtx = shallow_copy_rtx (str_rtx);
4418 set_mem_alias_set (str_rtx, 0);
4419 set_mem_expr (str_rtx, 0);
4422 binop = code == PLUS_EXPR ? add_optab : sub_optab;
4423 if (bitsize == 1 && bitpos + bitsize != str_bitsize)
4425 value = expand_and (str_mode, value, const1_rtx, NULL);
4426 binop = xor_optab;
4428 value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
4429 result = expand_binop (str_mode, binop, str_rtx,
4430 value, str_rtx, 1, OPTAB_WIDEN);
4431 if (result != str_rtx)
4432 emit_move_insn (str_rtx, result);
4433 return true;
4435 case BIT_IOR_EXPR:
4436 case BIT_XOR_EXPR:
4437 if (TREE_CODE (op1) != INTEGER_CST)
4438 break;
4439 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4440 value = convert_modes (str_mode,
4441 TYPE_MODE (TREE_TYPE (op1)), value,
4442 TYPE_UNSIGNED (TREE_TYPE (op1)));
4444 /* We may be accessing data outside the field, which means
4445 we can alias adjacent data. */
4446 if (MEM_P (str_rtx))
4448 str_rtx = shallow_copy_rtx (str_rtx);
4449 set_mem_alias_set (str_rtx, 0);
4450 set_mem_expr (str_rtx, 0);
4453 binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
4454 if (bitpos + bitsize != str_bitsize)
4456 rtx mask = GEN_INT (((unsigned HOST_WIDE_INT) 1 << bitsize) - 1);
4457 value = expand_and (str_mode, value, mask, NULL_RTX);
4459 value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
4460 result = expand_binop (str_mode, binop, str_rtx,
4461 value, str_rtx, 1, OPTAB_WIDEN);
4462 if (result != str_rtx)
4463 emit_move_insn (str_rtx, result);
4464 return true;
4466 default:
4467 break;
4470 return false;
4473 /* In the C++ memory model, consecutive bit fields in a structure are
4474 considered one memory location.
4476 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4477 returns the bit range of consecutive bits in which this COMPONENT_REF
4478 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4479 and *OFFSET may be adjusted in the process.
4481 If the access does not need to be restricted, 0 is returned in both
4482 *BITSTART and *BITEND. */
4484 static void
4485 get_bit_range (unsigned HOST_WIDE_INT *bitstart,
4486 unsigned HOST_WIDE_INT *bitend,
4487 tree exp,
4488 HOST_WIDE_INT *bitpos,
4489 tree *offset)
4491 HOST_WIDE_INT bitoffset;
4492 tree field, repr;
4494 gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
4496 field = TREE_OPERAND (exp, 1);
4497 repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
4498 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4499 need to limit the range we can access. */
4500 if (!repr)
4502 *bitstart = *bitend = 0;
4503 return;
4506 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4507 part of a larger bit field, then the representative does not serve any
4508 useful purpose. This can occur in Ada. */
4509 if (handled_component_p (TREE_OPERAND (exp, 0)))
4511 enum machine_mode rmode;
4512 HOST_WIDE_INT rbitsize, rbitpos;
4513 tree roffset;
4514 int unsignedp;
4515 int volatilep = 0;
4516 get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
4517 &roffset, &rmode, &unsignedp, &volatilep, false);
4518 if ((rbitpos % BITS_PER_UNIT) != 0)
4520 *bitstart = *bitend = 0;
4521 return;
4525 /* Compute the adjustment to bitpos from the offset of the field
4526 relative to the representative. DECL_FIELD_OFFSET of field and
4527 repr are the same by construction if they are not constants,
4528 see finish_bitfield_layout. */
4529 if (host_integerp (DECL_FIELD_OFFSET (field), 1)
4530 && host_integerp (DECL_FIELD_OFFSET (repr), 1))
4531 bitoffset = (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
4532 - tree_low_cst (DECL_FIELD_OFFSET (repr), 1)) * BITS_PER_UNIT;
4533 else
4534 bitoffset = 0;
4535 bitoffset += (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
4536 - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1));
4538 /* If the adjustment is larger than bitpos, we would have a negative bit
4539 position for the lower bound and this may wreak havoc later. This can
4540 occur only if we have a non-null offset, so adjust offset and bitpos
4541 to make the lower bound non-negative. */
4542 if (bitoffset > *bitpos)
4544 HOST_WIDE_INT adjust = bitoffset - *bitpos;
4546 gcc_assert ((adjust % BITS_PER_UNIT) == 0);
4547 gcc_assert (*offset != NULL_TREE);
4549 *bitpos += adjust;
4550 *offset
4551 = size_binop (MINUS_EXPR, *offset, size_int (adjust / BITS_PER_UNIT));
4552 *bitstart = 0;
4554 else
4555 *bitstart = *bitpos - bitoffset;
4557 *bitend = *bitstart + tree_low_cst (DECL_SIZE (repr), 1) - 1;
4560 /* Returns true if the MEM_REF REF refers to an object that does not
4561 reside in memory and has non-BLKmode. */
4563 static bool
4564 mem_ref_refers_to_non_mem_p (tree ref)
4566 tree base = TREE_OPERAND (ref, 0);
4567 if (TREE_CODE (base) != ADDR_EXPR)
4568 return false;
4569 base = TREE_OPERAND (base, 0);
4570 return (DECL_P (base)
4571 && !TREE_ADDRESSABLE (base)
4572 && DECL_MODE (base) != BLKmode
4573 && DECL_RTL_SET_P (base)
4574 && !MEM_P (DECL_RTL (base)));
4577 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4578 is true, try generating a nontemporal store. */
4580 void
4581 expand_assignment (tree to, tree from, bool nontemporal)
4583 rtx to_rtx = 0;
4584 rtx result;
4585 enum machine_mode mode;
4586 unsigned int align;
4587 enum insn_code icode;
4589 /* Don't crash if the lhs of the assignment was erroneous. */
4590 if (TREE_CODE (to) == ERROR_MARK)
4592 expand_normal (from);
4593 return;
4596 /* Optimize away no-op moves without side-effects. */
4597 if (operand_equal_p (to, from, 0))
4598 return;
4600 /* Handle misaligned stores. */
4601 mode = TYPE_MODE (TREE_TYPE (to));
4602 if ((TREE_CODE (to) == MEM_REF
4603 || TREE_CODE (to) == TARGET_MEM_REF)
4604 && mode != BLKmode
4605 && !mem_ref_refers_to_non_mem_p (to)
4606 && ((align = get_object_alignment (to))
4607 < GET_MODE_ALIGNMENT (mode))
4608 && (((icode = optab_handler (movmisalign_optab, mode))
4609 != CODE_FOR_nothing)
4610 || SLOW_UNALIGNED_ACCESS (mode, align)))
4612 rtx reg, mem;
4614 reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4615 reg = force_not_mem (reg);
4616 mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4618 if (icode != CODE_FOR_nothing)
4620 struct expand_operand ops[2];
4622 create_fixed_operand (&ops[0], mem);
4623 create_input_operand (&ops[1], reg, mode);
4624 /* The movmisalign<mode> pattern cannot fail, else the assignment
4625 would silently be omitted. */
4626 expand_insn (icode, 2, ops);
4628 else
4629 store_bit_field (mem, GET_MODE_BITSIZE (mode),
4630 0, 0, 0, mode, reg);
4631 return;
4634 /* Assignment of a structure component needs special treatment
4635 if the structure component's rtx is not simply a MEM.
4636 Assignment of an array element at a constant index, and assignment of
4637 an array element in an unaligned packed structure field, has the same
4638 problem. Same for (partially) storing into a non-memory object. */
4639 if (handled_component_p (to)
4640 || (TREE_CODE (to) == MEM_REF
4641 && mem_ref_refers_to_non_mem_p (to))
4642 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
4644 enum machine_mode mode1;
4645 HOST_WIDE_INT bitsize, bitpos;
4646 unsigned HOST_WIDE_INT bitregion_start = 0;
4647 unsigned HOST_WIDE_INT bitregion_end = 0;
4648 tree offset;
4649 int unsignedp;
4650 int volatilep = 0;
4651 tree tem;
4652 bool misalignp;
4653 rtx mem = NULL_RTX;
4655 push_temp_slots ();
4656 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
4657 &unsignedp, &volatilep, true);
4659 if (TREE_CODE (to) == COMPONENT_REF
4660 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
4661 get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
4663 /* If we are going to use store_bit_field and extract_bit_field,
4664 make sure to_rtx will be safe for multiple use. */
4665 mode = TYPE_MODE (TREE_TYPE (tem));
4666 if (TREE_CODE (tem) == MEM_REF
4667 && mode != BLKmode
4668 && ((align = get_object_alignment (tem))
4669 < GET_MODE_ALIGNMENT (mode))
4670 && ((icode = optab_handler (movmisalign_optab, mode))
4671 != CODE_FOR_nothing))
4673 struct expand_operand ops[2];
4675 misalignp = true;
4676 to_rtx = gen_reg_rtx (mode);
4677 mem = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
4679 /* If the misaligned store doesn't overwrite all bits, perform
4680 rmw cycle on MEM. */
4681 if (bitsize != GET_MODE_BITSIZE (mode))
4683 create_input_operand (&ops[0], to_rtx, mode);
4684 create_fixed_operand (&ops[1], mem);
4685 /* The movmisalign<mode> pattern cannot fail, else the assignment
4686 would silently be omitted. */
4687 expand_insn (icode, 2, ops);
4689 mem = copy_rtx (mem);
4692 else
4694 misalignp = false;
4695 to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
4698 /* If the bitfield is volatile, we want to access it in the
4699 field's mode, not the computed mode.
4700 If a MEM has VOIDmode (external with incomplete type),
4701 use BLKmode for it instead. */
4702 if (MEM_P (to_rtx))
4704 if (volatilep && flag_strict_volatile_bitfields > 0)
4705 to_rtx = adjust_address (to_rtx, mode1, 0);
4706 else if (GET_MODE (to_rtx) == VOIDmode)
4707 to_rtx = adjust_address (to_rtx, BLKmode, 0);
4710 if (offset != 0)
4712 enum machine_mode address_mode;
4713 rtx offset_rtx;
4715 if (!MEM_P (to_rtx))
4717 /* We can get constant negative offsets into arrays with broken
4718 user code. Translate this to a trap instead of ICEing. */
4719 gcc_assert (TREE_CODE (offset) == INTEGER_CST);
4720 expand_builtin_trap ();
4721 to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
4724 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
4725 address_mode = get_address_mode (to_rtx);
4726 if (GET_MODE (offset_rtx) != address_mode)
4727 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
4729 /* A constant address in TO_RTX can have VOIDmode, we must not try
4730 to call force_reg for that case. Avoid that case. */
4731 if (MEM_P (to_rtx)
4732 && GET_MODE (to_rtx) == BLKmode
4733 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
4734 && bitsize > 0
4735 && (bitpos % bitsize) == 0
4736 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
4737 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
4739 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
4740 bitpos = 0;
4743 to_rtx = offset_address (to_rtx, offset_rtx,
4744 highest_pow2_factor_for_target (to,
4745 offset));
4748 /* No action is needed if the target is not a memory and the field
4749 lies completely outside that target. This can occur if the source
4750 code contains an out-of-bounds access to a small array. */
4751 if (!MEM_P (to_rtx)
4752 && GET_MODE (to_rtx) != BLKmode
4753 && (unsigned HOST_WIDE_INT) bitpos
4754 >= GET_MODE_PRECISION (GET_MODE (to_rtx)))
4756 expand_normal (from);
4757 result = NULL;
4759 /* Handle expand_expr of a complex value returning a CONCAT. */
4760 else if (GET_CODE (to_rtx) == CONCAT)
4762 unsigned short mode_bitsize = GET_MODE_BITSIZE (GET_MODE (to_rtx));
4763 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from)))
4764 && bitpos == 0
4765 && bitsize == mode_bitsize)
4766 result = store_expr (from, to_rtx, false, nontemporal);
4767 else if (bitsize == mode_bitsize / 2
4768 && (bitpos == 0 || bitpos == mode_bitsize / 2))
4769 result = store_expr (from, XEXP (to_rtx, bitpos != 0), false,
4770 nontemporal);
4771 else if (bitpos + bitsize <= mode_bitsize / 2)
4772 result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
4773 bitregion_start, bitregion_end,
4774 mode1, from,
4775 get_alias_set (to), nontemporal);
4776 else if (bitpos >= mode_bitsize / 2)
4777 result = store_field (XEXP (to_rtx, 1), bitsize,
4778 bitpos - mode_bitsize / 2,
4779 bitregion_start, bitregion_end,
4780 mode1, from,
4781 get_alias_set (to), nontemporal);
4782 else if (bitpos == 0 && bitsize == mode_bitsize)
4784 rtx from_rtx;
4785 result = expand_normal (from);
4786 from_rtx = simplify_gen_subreg (GET_MODE (to_rtx), result,
4787 TYPE_MODE (TREE_TYPE (from)), 0);
4788 emit_move_insn (XEXP (to_rtx, 0),
4789 read_complex_part (from_rtx, false));
4790 emit_move_insn (XEXP (to_rtx, 1),
4791 read_complex_part (from_rtx, true));
4793 else
4795 rtx temp = assign_stack_temp (GET_MODE (to_rtx),
4796 GET_MODE_SIZE (GET_MODE (to_rtx)));
4797 write_complex_part (temp, XEXP (to_rtx, 0), false);
4798 write_complex_part (temp, XEXP (to_rtx, 1), true);
4799 result = store_field (temp, bitsize, bitpos,
4800 bitregion_start, bitregion_end,
4801 mode1, from,
4802 get_alias_set (to), nontemporal);
4803 emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
4804 emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
4807 else
4809 if (MEM_P (to_rtx))
4811 /* If the field is at offset zero, we could have been given the
4812 DECL_RTX of the parent struct. Don't munge it. */
4813 to_rtx = shallow_copy_rtx (to_rtx);
4815 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
4817 /* Deal with volatile and readonly fields. The former is only
4818 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4819 if (volatilep)
4820 MEM_VOLATILE_P (to_rtx) = 1;
4823 if (optimize_bitfield_assignment_op (bitsize, bitpos,
4824 bitregion_start, bitregion_end,
4825 mode1,
4826 to_rtx, to, from))
4827 result = NULL;
4828 else
4829 result = store_field (to_rtx, bitsize, bitpos,
4830 bitregion_start, bitregion_end,
4831 mode1, from,
4832 get_alias_set (to), nontemporal);
4835 if (misalignp)
4837 struct expand_operand ops[2];
4839 create_fixed_operand (&ops[0], mem);
4840 create_input_operand (&ops[1], to_rtx, mode);
4841 /* The movmisalign<mode> pattern cannot fail, else the assignment
4842 would silently be omitted. */
4843 expand_insn (icode, 2, ops);
4846 if (result)
4847 preserve_temp_slots (result);
4848 pop_temp_slots ();
4849 return;
4852 /* If the rhs is a function call and its value is not an aggregate,
4853 call the function before we start to compute the lhs.
4854 This is needed for correct code for cases such as
4855 val = setjmp (buf) on machines where reference to val
4856 requires loading up part of an address in a separate insn.
4858 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4859 since it might be a promoted variable where the zero- or sign- extension
4860 needs to be done. Handling this in the normal way is safe because no
4861 computation is done before the call. The same is true for SSA names. */
4862 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
4863 && COMPLETE_TYPE_P (TREE_TYPE (from))
4864 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
4865 && ! (((TREE_CODE (to) == VAR_DECL
4866 || TREE_CODE (to) == PARM_DECL
4867 || TREE_CODE (to) == RESULT_DECL)
4868 && REG_P (DECL_RTL (to)))
4869 || TREE_CODE (to) == SSA_NAME))
4871 rtx value;
4873 push_temp_slots ();
4874 value = expand_normal (from);
4875 if (to_rtx == 0)
4876 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4878 /* Handle calls that return values in multiple non-contiguous locations.
4879 The Irix 6 ABI has examples of this. */
4880 if (GET_CODE (to_rtx) == PARALLEL)
4882 if (GET_CODE (value) == PARALLEL)
4883 emit_group_move (to_rtx, value);
4884 else
4885 emit_group_load (to_rtx, value, TREE_TYPE (from),
4886 int_size_in_bytes (TREE_TYPE (from)));
4888 else if (GET_CODE (value) == PARALLEL)
4889 emit_group_store (to_rtx, value, TREE_TYPE (from),
4890 int_size_in_bytes (TREE_TYPE (from)));
4891 else if (GET_MODE (to_rtx) == BLKmode)
4893 /* Handle calls that return BLKmode values in registers. */
4894 if (REG_P (value))
4895 copy_blkmode_from_reg (to_rtx, value, TREE_TYPE (from));
4896 else
4897 emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
4899 else
4901 if (POINTER_TYPE_P (TREE_TYPE (to)))
4902 value = convert_memory_address_addr_space
4903 (GET_MODE (to_rtx), value,
4904 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
4906 emit_move_insn (to_rtx, value);
4908 preserve_temp_slots (to_rtx);
4909 pop_temp_slots ();
4910 return;
4913 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4914 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4916 /* Don't move directly into a return register. */
4917 if (TREE_CODE (to) == RESULT_DECL
4918 && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
4920 rtx temp;
4922 push_temp_slots ();
4923 if (REG_P (to_rtx) && TYPE_MODE (TREE_TYPE (from)) == BLKmode)
4924 temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
4925 else
4926 temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
4928 /* Handle calls that return values in multiple non-contiguous locations.
4929 The Irix 6 ABI has examples of this. */
4930 if (GET_CODE (to_rtx) == PARALLEL)
4932 if (GET_CODE (temp) == PARALLEL)
4933 emit_group_move (to_rtx, temp);
4934 else
4935 emit_group_load (to_rtx, temp, TREE_TYPE (from),
4936 int_size_in_bytes (TREE_TYPE (from)));
4938 else if (temp)
4939 emit_move_insn (to_rtx, temp);
4941 preserve_temp_slots (to_rtx);
4942 pop_temp_slots ();
4943 return;
4946 /* In case we are returning the contents of an object which overlaps
4947 the place the value is being stored, use a safe function when copying
4948 a value through a pointer into a structure value return block. */
4949 if (TREE_CODE (to) == RESULT_DECL
4950 && TREE_CODE (from) == INDIRECT_REF
4951 && ADDR_SPACE_GENERIC_P
4952 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
4953 && refs_may_alias_p (to, from)
4954 && cfun->returns_struct
4955 && !cfun->returns_pcc_struct)
4957 rtx from_rtx, size;
4959 push_temp_slots ();
4960 size = expr_size (from);
4961 from_rtx = expand_normal (from);
4963 emit_library_call (memmove_libfunc, LCT_NORMAL,
4964 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
4965 XEXP (from_rtx, 0), Pmode,
4966 convert_to_mode (TYPE_MODE (sizetype),
4967 size, TYPE_UNSIGNED (sizetype)),
4968 TYPE_MODE (sizetype));
4970 preserve_temp_slots (to_rtx);
4971 pop_temp_slots ();
4972 return;
4975 /* Compute FROM and store the value in the rtx we got. */
4977 push_temp_slots ();
4978 result = store_expr (from, to_rtx, 0, nontemporal);
4979 preserve_temp_slots (result);
4980 pop_temp_slots ();
4981 return;
4984 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
4985 succeeded, false otherwise. */
4987 bool
4988 emit_storent_insn (rtx to, rtx from)
4990 struct expand_operand ops[2];
4991 enum machine_mode mode = GET_MODE (to);
4992 enum insn_code code = optab_handler (storent_optab, mode);
4994 if (code == CODE_FOR_nothing)
4995 return false;
4997 create_fixed_operand (&ops[0], to);
4998 create_input_operand (&ops[1], from, mode);
4999 return maybe_expand_insn (code, 2, ops);
5002 /* Generate code for computing expression EXP,
5003 and storing the value into TARGET.
5005 If the mode is BLKmode then we may return TARGET itself.
5006 It turns out that in BLKmode it doesn't cause a problem.
5007 because C has no operators that could combine two different
5008 assignments into the same BLKmode object with different values
5009 with no sequence point. Will other languages need this to
5010 be more thorough?
5012 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5013 stack, and block moves may need to be treated specially.
5015 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5018 store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
5020 rtx temp;
5021 rtx alt_rtl = NULL_RTX;
5022 location_t loc = curr_insn_location ();
5024 if (VOID_TYPE_P (TREE_TYPE (exp)))
5026 /* C++ can generate ?: expressions with a throw expression in one
5027 branch and an rvalue in the other. Here, we resolve attempts to
5028 store the throw expression's nonexistent result. */
5029 gcc_assert (!call_param_p);
5030 expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
5031 return NULL_RTX;
5033 if (TREE_CODE (exp) == COMPOUND_EXPR)
5035 /* Perform first part of compound expression, then assign from second
5036 part. */
5037 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
5038 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5039 return store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
5040 nontemporal);
5042 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
5044 /* For conditional expression, get safe form of the target. Then
5045 test the condition, doing the appropriate assignment on either
5046 side. This avoids the creation of unnecessary temporaries.
5047 For non-BLKmode, it is more efficient not to do this. */
5049 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
5051 do_pending_stack_adjust ();
5052 NO_DEFER_POP;
5053 jumpifnot (TREE_OPERAND (exp, 0), lab1, -1);
5054 store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
5055 nontemporal);
5056 emit_jump_insn (gen_jump (lab2));
5057 emit_barrier ();
5058 emit_label (lab1);
5059 store_expr (TREE_OPERAND (exp, 2), target, call_param_p,
5060 nontemporal);
5061 emit_label (lab2);
5062 OK_DEFER_POP;
5064 return NULL_RTX;
5066 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
5067 /* If this is a scalar in a register that is stored in a wider mode
5068 than the declared mode, compute the result into its declared mode
5069 and then convert to the wider mode. Our value is the computed
5070 expression. */
5072 rtx inner_target = 0;
5074 /* We can do the conversion inside EXP, which will often result
5075 in some optimizations. Do the conversion in two steps: first
5076 change the signedness, if needed, then the extend. But don't
5077 do this if the type of EXP is a subtype of something else
5078 since then the conversion might involve more than just
5079 converting modes. */
5080 if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
5081 && TREE_TYPE (TREE_TYPE (exp)) == 0
5082 && GET_MODE_PRECISION (GET_MODE (target))
5083 == TYPE_PRECISION (TREE_TYPE (exp)))
5085 if (TYPE_UNSIGNED (TREE_TYPE (exp))
5086 != SUBREG_PROMOTED_UNSIGNED_P (target))
5088 /* Some types, e.g. Fortran's logical*4, won't have a signed
5089 version, so use the mode instead. */
5090 tree ntype
5091 = (signed_or_unsigned_type_for
5092 (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)));
5093 if (ntype == NULL)
5094 ntype = lang_hooks.types.type_for_mode
5095 (TYPE_MODE (TREE_TYPE (exp)),
5096 SUBREG_PROMOTED_UNSIGNED_P (target));
5098 exp = fold_convert_loc (loc, ntype, exp);
5101 exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
5102 (GET_MODE (SUBREG_REG (target)),
5103 SUBREG_PROMOTED_UNSIGNED_P (target)),
5104 exp);
5106 inner_target = SUBREG_REG (target);
5109 temp = expand_expr (exp, inner_target, VOIDmode,
5110 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5112 /* If TEMP is a VOIDmode constant, use convert_modes to make
5113 sure that we properly convert it. */
5114 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
5116 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5117 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
5118 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
5119 GET_MODE (target), temp,
5120 SUBREG_PROMOTED_UNSIGNED_P (target));
5123 convert_move (SUBREG_REG (target), temp,
5124 SUBREG_PROMOTED_UNSIGNED_P (target));
5126 return NULL_RTX;
5128 else if ((TREE_CODE (exp) == STRING_CST
5129 || (TREE_CODE (exp) == MEM_REF
5130 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
5131 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
5132 == STRING_CST
5133 && integer_zerop (TREE_OPERAND (exp, 1))))
5134 && !nontemporal && !call_param_p
5135 && MEM_P (target))
5137 /* Optimize initialization of an array with a STRING_CST. */
5138 HOST_WIDE_INT exp_len, str_copy_len;
5139 rtx dest_mem;
5140 tree str = TREE_CODE (exp) == STRING_CST
5141 ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5143 exp_len = int_expr_size (exp);
5144 if (exp_len <= 0)
5145 goto normal_expr;
5147 if (TREE_STRING_LENGTH (str) <= 0)
5148 goto normal_expr;
5150 str_copy_len = strlen (TREE_STRING_POINTER (str));
5151 if (str_copy_len < TREE_STRING_LENGTH (str) - 1)
5152 goto normal_expr;
5154 str_copy_len = TREE_STRING_LENGTH (str);
5155 if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0
5156 && TREE_STRING_POINTER (str)[TREE_STRING_LENGTH (str) - 1] == '\0')
5158 str_copy_len += STORE_MAX_PIECES - 1;
5159 str_copy_len &= ~(STORE_MAX_PIECES - 1);
5161 str_copy_len = MIN (str_copy_len, exp_len);
5162 if (!can_store_by_pieces (str_copy_len, builtin_strncpy_read_str,
5163 CONST_CAST (char *, TREE_STRING_POINTER (str)),
5164 MEM_ALIGN (target), false))
5165 goto normal_expr;
5167 dest_mem = target;
5169 dest_mem = store_by_pieces (dest_mem,
5170 str_copy_len, builtin_strncpy_read_str,
5171 CONST_CAST (char *,
5172 TREE_STRING_POINTER (str)),
5173 MEM_ALIGN (target), false,
5174 exp_len > str_copy_len ? 1 : 0);
5175 if (exp_len > str_copy_len)
5176 clear_storage (adjust_address (dest_mem, BLKmode, 0),
5177 GEN_INT (exp_len - str_copy_len),
5178 BLOCK_OP_NORMAL);
5179 return NULL_RTX;
5181 else
5183 rtx tmp_target;
5185 normal_expr:
5186 /* If we want to use a nontemporal store, force the value to
5187 register first. */
5188 tmp_target = nontemporal ? NULL_RTX : target;
5189 temp = expand_expr_real (exp, tmp_target, GET_MODE (target),
5190 (call_param_p
5191 ? EXPAND_STACK_PARM : EXPAND_NORMAL),
5192 &alt_rtl);
5195 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5196 the same as that of TARGET, adjust the constant. This is needed, for
5197 example, in case it is a CONST_DOUBLE and we want only a word-sized
5198 value. */
5199 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
5200 && TREE_CODE (exp) != ERROR_MARK
5201 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
5202 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5203 temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5205 /* If value was not generated in the target, store it there.
5206 Convert the value to TARGET's type first if necessary and emit the
5207 pending incrementations that have been queued when expanding EXP.
5208 Note that we cannot emit the whole queue blindly because this will
5209 effectively disable the POST_INC optimization later.
5211 If TEMP and TARGET compare equal according to rtx_equal_p, but
5212 one or both of them are volatile memory refs, we have to distinguish
5213 two cases:
5214 - expand_expr has used TARGET. In this case, we must not generate
5215 another copy. This can be detected by TARGET being equal according
5216 to == .
5217 - expand_expr has not used TARGET - that means that the source just
5218 happens to have the same RTX form. Since temp will have been created
5219 by expand_expr, it will compare unequal according to == .
5220 We must generate a copy in this case, to reach the correct number
5221 of volatile memory references. */
5223 if ((! rtx_equal_p (temp, target)
5224 || (temp != target && (side_effects_p (temp)
5225 || side_effects_p (target))))
5226 && TREE_CODE (exp) != ERROR_MARK
5227 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5228 but TARGET is not valid memory reference, TEMP will differ
5229 from TARGET although it is really the same location. */
5230 && !(alt_rtl
5231 && rtx_equal_p (alt_rtl, target)
5232 && !side_effects_p (alt_rtl)
5233 && !side_effects_p (target))
5234 /* If there's nothing to copy, don't bother. Don't call
5235 expr_size unless necessary, because some front-ends (C++)
5236 expr_size-hook must not be given objects that are not
5237 supposed to be bit-copied or bit-initialized. */
5238 && expr_size (exp) != const0_rtx)
5240 if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
5242 if (GET_MODE (target) == BLKmode)
5244 /* Handle calls that return BLKmode values in registers. */
5245 if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
5246 copy_blkmode_from_reg (target, temp, TREE_TYPE (exp));
5247 else
5248 store_bit_field (target,
5249 INTVAL (expr_size (exp)) * BITS_PER_UNIT,
5250 0, 0, 0, GET_MODE (temp), temp);
5252 else
5253 convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5256 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
5258 /* Handle copying a string constant into an array. The string
5259 constant may be shorter than the array. So copy just the string's
5260 actual length, and clear the rest. First get the size of the data
5261 type of the string, which is actually the size of the target. */
5262 rtx size = expr_size (exp);
5264 if (CONST_INT_P (size)
5265 && INTVAL (size) < TREE_STRING_LENGTH (exp))
5266 emit_block_move (target, temp, size,
5267 (call_param_p
5268 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5269 else
5271 enum machine_mode pointer_mode
5272 = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
5273 enum machine_mode address_mode = get_address_mode (target);
5275 /* Compute the size of the data to copy from the string. */
5276 tree copy_size
5277 = size_binop_loc (loc, MIN_EXPR,
5278 make_tree (sizetype, size),
5279 size_int (TREE_STRING_LENGTH (exp)));
5280 rtx copy_size_rtx
5281 = expand_expr (copy_size, NULL_RTX, VOIDmode,
5282 (call_param_p
5283 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
5284 rtx label = 0;
5286 /* Copy that much. */
5287 copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
5288 TYPE_UNSIGNED (sizetype));
5289 emit_block_move (target, temp, copy_size_rtx,
5290 (call_param_p
5291 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5293 /* Figure out how much is left in TARGET that we have to clear.
5294 Do all calculations in pointer_mode. */
5295 if (CONST_INT_P (copy_size_rtx))
5297 size = plus_constant (address_mode, size,
5298 -INTVAL (copy_size_rtx));
5299 target = adjust_address (target, BLKmode,
5300 INTVAL (copy_size_rtx));
5302 else
5304 size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
5305 copy_size_rtx, NULL_RTX, 0,
5306 OPTAB_LIB_WIDEN);
5308 if (GET_MODE (copy_size_rtx) != address_mode)
5309 copy_size_rtx = convert_to_mode (address_mode,
5310 copy_size_rtx,
5311 TYPE_UNSIGNED (sizetype));
5313 target = offset_address (target, copy_size_rtx,
5314 highest_pow2_factor (copy_size));
5315 label = gen_label_rtx ();
5316 emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
5317 GET_MODE (size), 0, label);
5320 if (size != const0_rtx)
5321 clear_storage (target, size, BLOCK_OP_NORMAL);
5323 if (label)
5324 emit_label (label);
5327 /* Handle calls that return values in multiple non-contiguous locations.
5328 The Irix 6 ABI has examples of this. */
5329 else if (GET_CODE (target) == PARALLEL)
5331 if (GET_CODE (temp) == PARALLEL)
5332 emit_group_move (target, temp);
5333 else
5334 emit_group_load (target, temp, TREE_TYPE (exp),
5335 int_size_in_bytes (TREE_TYPE (exp)));
5337 else if (GET_CODE (temp) == PARALLEL)
5338 emit_group_store (target, temp, TREE_TYPE (exp),
5339 int_size_in_bytes (TREE_TYPE (exp)));
5340 else if (GET_MODE (temp) == BLKmode)
5341 emit_block_move (target, temp, expr_size (exp),
5342 (call_param_p
5343 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5344 /* If we emit a nontemporal store, there is nothing else to do. */
5345 else if (nontemporal && emit_storent_insn (target, temp))
5347 else
5349 temp = force_operand (temp, target);
5350 if (temp != target)
5351 emit_move_insn (target, temp);
5355 return NULL_RTX;
5358 /* Return true if field F of structure TYPE is a flexible array. */
5360 static bool
5361 flexible_array_member_p (const_tree f, const_tree type)
5363 const_tree tf;
5365 tf = TREE_TYPE (f);
5366 return (DECL_CHAIN (f) == NULL
5367 && TREE_CODE (tf) == ARRAY_TYPE
5368 && TYPE_DOMAIN (tf)
5369 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
5370 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
5371 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
5372 && int_size_in_bytes (type) >= 0);
5375 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5376 must have in order for it to completely initialize a value of type TYPE.
5377 Return -1 if the number isn't known.
5379 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5381 static HOST_WIDE_INT
5382 count_type_elements (const_tree type, bool for_ctor_p)
5384 switch (TREE_CODE (type))
5386 case ARRAY_TYPE:
5388 tree nelts;
5390 nelts = array_type_nelts (type);
5391 if (nelts && host_integerp (nelts, 1))
5393 unsigned HOST_WIDE_INT n;
5395 n = tree_low_cst (nelts, 1) + 1;
5396 if (n == 0 || for_ctor_p)
5397 return n;
5398 else
5399 return n * count_type_elements (TREE_TYPE (type), false);
5401 return for_ctor_p ? -1 : 1;
5404 case RECORD_TYPE:
5406 unsigned HOST_WIDE_INT n;
5407 tree f;
5409 n = 0;
5410 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5411 if (TREE_CODE (f) == FIELD_DECL)
5413 if (!for_ctor_p)
5414 n += count_type_elements (TREE_TYPE (f), false);
5415 else if (!flexible_array_member_p (f, type))
5416 /* Don't count flexible arrays, which are not supposed
5417 to be initialized. */
5418 n += 1;
5421 return n;
5424 case UNION_TYPE:
5425 case QUAL_UNION_TYPE:
5427 tree f;
5428 HOST_WIDE_INT n, m;
5430 gcc_assert (!for_ctor_p);
5431 /* Estimate the number of scalars in each field and pick the
5432 maximum. Other estimates would do instead; the idea is simply
5433 to make sure that the estimate is not sensitive to the ordering
5434 of the fields. */
5435 n = 1;
5436 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5437 if (TREE_CODE (f) == FIELD_DECL)
5439 m = count_type_elements (TREE_TYPE (f), false);
5440 /* If the field doesn't span the whole union, add an extra
5441 scalar for the rest. */
5442 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
5443 TYPE_SIZE (type)) != 1)
5444 m++;
5445 if (n < m)
5446 n = m;
5448 return n;
5451 case COMPLEX_TYPE:
5452 return 2;
5454 case VECTOR_TYPE:
5455 return TYPE_VECTOR_SUBPARTS (type);
5457 case INTEGER_TYPE:
5458 case REAL_TYPE:
5459 case FIXED_POINT_TYPE:
5460 case ENUMERAL_TYPE:
5461 case BOOLEAN_TYPE:
5462 case POINTER_TYPE:
5463 case OFFSET_TYPE:
5464 case REFERENCE_TYPE:
5465 case NULLPTR_TYPE:
5466 return 1;
5468 case ERROR_MARK:
5469 return 0;
5471 case VOID_TYPE:
5472 case METHOD_TYPE:
5473 case FUNCTION_TYPE:
5474 case LANG_TYPE:
5475 default:
5476 gcc_unreachable ();
5480 /* Helper for categorize_ctor_elements. Identical interface. */
5482 static bool
5483 categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5484 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5486 unsigned HOST_WIDE_INT idx;
5487 HOST_WIDE_INT nz_elts, init_elts, num_fields;
5488 tree value, purpose, elt_type;
5490 /* Whether CTOR is a valid constant initializer, in accordance with what
5491 initializer_constant_valid_p does. If inferred from the constructor
5492 elements, true until proven otherwise. */
5493 bool const_from_elts_p = constructor_static_from_elts_p (ctor);
5494 bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
5496 nz_elts = 0;
5497 init_elts = 0;
5498 num_fields = 0;
5499 elt_type = NULL_TREE;
5501 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
5503 HOST_WIDE_INT mult = 1;
5505 if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
5507 tree lo_index = TREE_OPERAND (purpose, 0);
5508 tree hi_index = TREE_OPERAND (purpose, 1);
5510 if (host_integerp (lo_index, 1) && host_integerp (hi_index, 1))
5511 mult = (tree_low_cst (hi_index, 1)
5512 - tree_low_cst (lo_index, 1) + 1);
5514 num_fields += mult;
5515 elt_type = TREE_TYPE (value);
5517 switch (TREE_CODE (value))
5519 case CONSTRUCTOR:
5521 HOST_WIDE_INT nz = 0, ic = 0;
5523 bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &ic,
5524 p_complete);
5526 nz_elts += mult * nz;
5527 init_elts += mult * ic;
5529 if (const_from_elts_p && const_p)
5530 const_p = const_elt_p;
5532 break;
5534 case INTEGER_CST:
5535 case REAL_CST:
5536 case FIXED_CST:
5537 if (!initializer_zerop (value))
5538 nz_elts += mult;
5539 init_elts += mult;
5540 break;
5542 case STRING_CST:
5543 nz_elts += mult * TREE_STRING_LENGTH (value);
5544 init_elts += mult * TREE_STRING_LENGTH (value);
5545 break;
5547 case COMPLEX_CST:
5548 if (!initializer_zerop (TREE_REALPART (value)))
5549 nz_elts += mult;
5550 if (!initializer_zerop (TREE_IMAGPART (value)))
5551 nz_elts += mult;
5552 init_elts += mult;
5553 break;
5555 case VECTOR_CST:
5557 unsigned i;
5558 for (i = 0; i < VECTOR_CST_NELTS (value); ++i)
5560 tree v = VECTOR_CST_ELT (value, i);
5561 if (!initializer_zerop (v))
5562 nz_elts += mult;
5563 init_elts += mult;
5566 break;
5568 default:
5570 HOST_WIDE_INT tc = count_type_elements (elt_type, false);
5571 nz_elts += mult * tc;
5572 init_elts += mult * tc;
5574 if (const_from_elts_p && const_p)
5575 const_p = initializer_constant_valid_p (value, elt_type)
5576 != NULL_TREE;
5578 break;
5582 if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
5583 num_fields, elt_type))
5584 *p_complete = false;
5586 *p_nz_elts += nz_elts;
5587 *p_init_elts += init_elts;
5589 return const_p;
5592 /* Examine CTOR to discover:
5593 * how many scalar fields are set to nonzero values,
5594 and place it in *P_NZ_ELTS;
5595 * how many scalar fields in total are in CTOR,
5596 and place it in *P_ELT_COUNT.
5597 * whether the constructor is complete -- in the sense that every
5598 meaningful byte is explicitly given a value --
5599 and place it in *P_COMPLETE.
5601 Return whether or not CTOR is a valid static constant initializer, the same
5602 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5604 bool
5605 categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5606 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5608 *p_nz_elts = 0;
5609 *p_init_elts = 0;
5610 *p_complete = true;
5612 return categorize_ctor_elements_1 (ctor, p_nz_elts, p_init_elts, p_complete);
5615 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5616 of which had type LAST_TYPE. Each element was itself a complete
5617 initializer, in the sense that every meaningful byte was explicitly
5618 given a value. Return true if the same is true for the constructor
5619 as a whole. */
5621 bool
5622 complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
5623 const_tree last_type)
5625 if (TREE_CODE (type) == UNION_TYPE
5626 || TREE_CODE (type) == QUAL_UNION_TYPE)
5628 if (num_elts == 0)
5629 return false;
5631 gcc_assert (num_elts == 1 && last_type);
5633 /* ??? We could look at each element of the union, and find the
5634 largest element. Which would avoid comparing the size of the
5635 initialized element against any tail padding in the union.
5636 Doesn't seem worth the effort... */
5637 return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
5640 return count_type_elements (type, true) == num_elts;
5643 /* Return 1 if EXP contains mostly (3/4) zeros. */
5645 static int
5646 mostly_zeros_p (const_tree exp)
5648 if (TREE_CODE (exp) == CONSTRUCTOR)
5650 HOST_WIDE_INT nz_elts, init_elts;
5651 bool complete_p;
5653 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5654 return !complete_p || nz_elts < init_elts / 4;
5657 return initializer_zerop (exp);
5660 /* Return 1 if EXP contains all zeros. */
5662 static int
5663 all_zeros_p (const_tree exp)
5665 if (TREE_CODE (exp) == CONSTRUCTOR)
5667 HOST_WIDE_INT nz_elts, init_elts;
5668 bool complete_p;
5670 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5671 return nz_elts == 0;
5674 return initializer_zerop (exp);
5677 /* Helper function for store_constructor.
5678 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5679 CLEARED is as for store_constructor.
5680 ALIAS_SET is the alias set to use for any stores.
5682 This provides a recursive shortcut back to store_constructor when it isn't
5683 necessary to go through store_field. This is so that we can pass through
5684 the cleared field to let store_constructor know that we may not have to
5685 clear a substructure if the outer structure has already been cleared. */
5687 static void
5688 store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
5689 HOST_WIDE_INT bitpos, enum machine_mode mode,
5690 tree exp, int cleared, alias_set_type alias_set)
5692 if (TREE_CODE (exp) == CONSTRUCTOR
5693 /* We can only call store_constructor recursively if the size and
5694 bit position are on a byte boundary. */
5695 && bitpos % BITS_PER_UNIT == 0
5696 && (bitsize > 0 && bitsize % BITS_PER_UNIT == 0)
5697 /* If we have a nonzero bitpos for a register target, then we just
5698 let store_field do the bitfield handling. This is unlikely to
5699 generate unnecessary clear instructions anyways. */
5700 && (bitpos == 0 || MEM_P (target)))
5702 if (MEM_P (target))
5703 target
5704 = adjust_address (target,
5705 GET_MODE (target) == BLKmode
5706 || 0 != (bitpos
5707 % GET_MODE_ALIGNMENT (GET_MODE (target)))
5708 ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
5711 /* Update the alias set, if required. */
5712 if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
5713 && MEM_ALIAS_SET (target) != 0)
5715 target = copy_rtx (target);
5716 set_mem_alias_set (target, alias_set);
5719 store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
5721 else
5722 store_field (target, bitsize, bitpos, 0, 0, mode, exp, alias_set, false);
5725 /* Store the value of constructor EXP into the rtx TARGET.
5726 TARGET is either a REG or a MEM; we know it cannot conflict, since
5727 safe_from_p has been called.
5728 CLEARED is true if TARGET is known to have been zero'd.
5729 SIZE is the number of bytes of TARGET we are allowed to modify: this
5730 may not be the same as the size of EXP if we are assigning to a field
5731 which has been packed to exclude padding bits. */
5733 static void
5734 store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
5736 tree type = TREE_TYPE (exp);
5737 #ifdef WORD_REGISTER_OPERATIONS
5738 HOST_WIDE_INT exp_size = int_size_in_bytes (type);
5739 #endif
5741 switch (TREE_CODE (type))
5743 case RECORD_TYPE:
5744 case UNION_TYPE:
5745 case QUAL_UNION_TYPE:
5747 unsigned HOST_WIDE_INT idx;
5748 tree field, value;
5750 /* If size is zero or the target is already cleared, do nothing. */
5751 if (size == 0 || cleared)
5752 cleared = 1;
5753 /* We either clear the aggregate or indicate the value is dead. */
5754 else if ((TREE_CODE (type) == UNION_TYPE
5755 || TREE_CODE (type) == QUAL_UNION_TYPE)
5756 && ! CONSTRUCTOR_ELTS (exp))
5757 /* If the constructor is empty, clear the union. */
5759 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
5760 cleared = 1;
5763 /* If we are building a static constructor into a register,
5764 set the initial value as zero so we can fold the value into
5765 a constant. But if more than one register is involved,
5766 this probably loses. */
5767 else if (REG_P (target) && TREE_STATIC (exp)
5768 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
5770 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5771 cleared = 1;
5774 /* If the constructor has fewer fields than the structure or
5775 if we are initializing the structure to mostly zeros, clear
5776 the whole structure first. Don't do this if TARGET is a
5777 register whose mode size isn't equal to SIZE since
5778 clear_storage can't handle this case. */
5779 else if (size > 0
5780 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp))
5781 != fields_length (type))
5782 || mostly_zeros_p (exp))
5783 && (!REG_P (target)
5784 || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
5785 == size)))
5787 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5788 cleared = 1;
5791 if (REG_P (target) && !cleared)
5792 emit_clobber (target);
5794 /* Store each element of the constructor into the
5795 corresponding field of TARGET. */
5796 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
5798 enum machine_mode mode;
5799 HOST_WIDE_INT bitsize;
5800 HOST_WIDE_INT bitpos = 0;
5801 tree offset;
5802 rtx to_rtx = target;
5804 /* Just ignore missing fields. We cleared the whole
5805 structure, above, if any fields are missing. */
5806 if (field == 0)
5807 continue;
5809 if (cleared && initializer_zerop (value))
5810 continue;
5812 if (host_integerp (DECL_SIZE (field), 1))
5813 bitsize = tree_low_cst (DECL_SIZE (field), 1);
5814 else
5815 bitsize = -1;
5817 mode = DECL_MODE (field);
5818 if (DECL_BIT_FIELD (field))
5819 mode = VOIDmode;
5821 offset = DECL_FIELD_OFFSET (field);
5822 if (host_integerp (offset, 0)
5823 && host_integerp (bit_position (field), 0))
5825 bitpos = int_bit_position (field);
5826 offset = 0;
5828 else
5829 bitpos = tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 0);
5831 if (offset)
5833 enum machine_mode address_mode;
5834 rtx offset_rtx;
5836 offset
5837 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
5838 make_tree (TREE_TYPE (exp),
5839 target));
5841 offset_rtx = expand_normal (offset);
5842 gcc_assert (MEM_P (to_rtx));
5844 address_mode = get_address_mode (to_rtx);
5845 if (GET_MODE (offset_rtx) != address_mode)
5846 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
5848 to_rtx = offset_address (to_rtx, offset_rtx,
5849 highest_pow2_factor (offset));
5852 #ifdef WORD_REGISTER_OPERATIONS
5853 /* If this initializes a field that is smaller than a
5854 word, at the start of a word, try to widen it to a full
5855 word. This special case allows us to output C++ member
5856 function initializations in a form that the optimizers
5857 can understand. */
5858 if (REG_P (target)
5859 && bitsize < BITS_PER_WORD
5860 && bitpos % BITS_PER_WORD == 0
5861 && GET_MODE_CLASS (mode) == MODE_INT
5862 && TREE_CODE (value) == INTEGER_CST
5863 && exp_size >= 0
5864 && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
5866 tree type = TREE_TYPE (value);
5868 if (TYPE_PRECISION (type) < BITS_PER_WORD)
5870 type = lang_hooks.types.type_for_mode
5871 (word_mode, TYPE_UNSIGNED (type));
5872 value = fold_convert (type, value);
5875 if (BYTES_BIG_ENDIAN)
5876 value
5877 = fold_build2 (LSHIFT_EXPR, type, value,
5878 build_int_cst (type,
5879 BITS_PER_WORD - bitsize));
5880 bitsize = BITS_PER_WORD;
5881 mode = word_mode;
5883 #endif
5885 if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
5886 && DECL_NONADDRESSABLE_P (field))
5888 to_rtx = copy_rtx (to_rtx);
5889 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
5892 store_constructor_field (to_rtx, bitsize, bitpos, mode,
5893 value, cleared,
5894 get_alias_set (TREE_TYPE (field)));
5896 break;
5898 case ARRAY_TYPE:
5900 tree value, index;
5901 unsigned HOST_WIDE_INT i;
5902 int need_to_clear;
5903 tree domain;
5904 tree elttype = TREE_TYPE (type);
5905 int const_bounds_p;
5906 HOST_WIDE_INT minelt = 0;
5907 HOST_WIDE_INT maxelt = 0;
5909 domain = TYPE_DOMAIN (type);
5910 const_bounds_p = (TYPE_MIN_VALUE (domain)
5911 && TYPE_MAX_VALUE (domain)
5912 && host_integerp (TYPE_MIN_VALUE (domain), 0)
5913 && host_integerp (TYPE_MAX_VALUE (domain), 0));
5915 /* If we have constant bounds for the range of the type, get them. */
5916 if (const_bounds_p)
5918 minelt = tree_low_cst (TYPE_MIN_VALUE (domain), 0);
5919 maxelt = tree_low_cst (TYPE_MAX_VALUE (domain), 0);
5922 /* If the constructor has fewer elements than the array, clear
5923 the whole array first. Similarly if this is static
5924 constructor of a non-BLKmode object. */
5925 if (cleared)
5926 need_to_clear = 0;
5927 else if (REG_P (target) && TREE_STATIC (exp))
5928 need_to_clear = 1;
5929 else
5931 unsigned HOST_WIDE_INT idx;
5932 tree index, value;
5933 HOST_WIDE_INT count = 0, zero_count = 0;
5934 need_to_clear = ! const_bounds_p;
5936 /* This loop is a more accurate version of the loop in
5937 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5938 is also needed to check for missing elements. */
5939 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
5941 HOST_WIDE_INT this_node_count;
5943 if (need_to_clear)
5944 break;
5946 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5948 tree lo_index = TREE_OPERAND (index, 0);
5949 tree hi_index = TREE_OPERAND (index, 1);
5951 if (! host_integerp (lo_index, 1)
5952 || ! host_integerp (hi_index, 1))
5954 need_to_clear = 1;
5955 break;
5958 this_node_count = (tree_low_cst (hi_index, 1)
5959 - tree_low_cst (lo_index, 1) + 1);
5961 else
5962 this_node_count = 1;
5964 count += this_node_count;
5965 if (mostly_zeros_p (value))
5966 zero_count += this_node_count;
5969 /* Clear the entire array first if there are any missing
5970 elements, or if the incidence of zero elements is >=
5971 75%. */
5972 if (! need_to_clear
5973 && (count < maxelt - minelt + 1
5974 || 4 * zero_count >= 3 * count))
5975 need_to_clear = 1;
5978 if (need_to_clear && size > 0)
5980 if (REG_P (target))
5981 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5982 else
5983 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5984 cleared = 1;
5987 if (!cleared && REG_P (target))
5988 /* Inform later passes that the old value is dead. */
5989 emit_clobber (target);
5991 /* Store each element of the constructor into the
5992 corresponding element of TARGET, determined by counting the
5993 elements. */
5994 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
5996 enum machine_mode mode;
5997 HOST_WIDE_INT bitsize;
5998 HOST_WIDE_INT bitpos;
5999 rtx xtarget = target;
6001 if (cleared && initializer_zerop (value))
6002 continue;
6004 mode = TYPE_MODE (elttype);
6005 if (mode == BLKmode)
6006 bitsize = (host_integerp (TYPE_SIZE (elttype), 1)
6007 ? tree_low_cst (TYPE_SIZE (elttype), 1)
6008 : -1);
6009 else
6010 bitsize = GET_MODE_BITSIZE (mode);
6012 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
6014 tree lo_index = TREE_OPERAND (index, 0);
6015 tree hi_index = TREE_OPERAND (index, 1);
6016 rtx index_r, pos_rtx;
6017 HOST_WIDE_INT lo, hi, count;
6018 tree position;
6020 /* If the range is constant and "small", unroll the loop. */
6021 if (const_bounds_p
6022 && host_integerp (lo_index, 0)
6023 && host_integerp (hi_index, 0)
6024 && (lo = tree_low_cst (lo_index, 0),
6025 hi = tree_low_cst (hi_index, 0),
6026 count = hi - lo + 1,
6027 (!MEM_P (target)
6028 || count <= 2
6029 || (host_integerp (TYPE_SIZE (elttype), 1)
6030 && (tree_low_cst (TYPE_SIZE (elttype), 1) * count
6031 <= 40 * 8)))))
6033 lo -= minelt; hi -= minelt;
6034 for (; lo <= hi; lo++)
6036 bitpos = lo * tree_low_cst (TYPE_SIZE (elttype), 0);
6038 if (MEM_P (target)
6039 && !MEM_KEEP_ALIAS_SET_P (target)
6040 && TREE_CODE (type) == ARRAY_TYPE
6041 && TYPE_NONALIASED_COMPONENT (type))
6043 target = copy_rtx (target);
6044 MEM_KEEP_ALIAS_SET_P (target) = 1;
6047 store_constructor_field
6048 (target, bitsize, bitpos, mode, value, cleared,
6049 get_alias_set (elttype));
6052 else
6054 rtx loop_start = gen_label_rtx ();
6055 rtx loop_end = gen_label_rtx ();
6056 tree exit_cond;
6058 expand_normal (hi_index);
6060 index = build_decl (EXPR_LOCATION (exp),
6061 VAR_DECL, NULL_TREE, domain);
6062 index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
6063 SET_DECL_RTL (index, index_r);
6064 store_expr (lo_index, index_r, 0, false);
6066 /* Build the head of the loop. */
6067 do_pending_stack_adjust ();
6068 emit_label (loop_start);
6070 /* Assign value to element index. */
6071 position =
6072 fold_convert (ssizetype,
6073 fold_build2 (MINUS_EXPR,
6074 TREE_TYPE (index),
6075 index,
6076 TYPE_MIN_VALUE (domain)));
6078 position =
6079 size_binop (MULT_EXPR, position,
6080 fold_convert (ssizetype,
6081 TYPE_SIZE_UNIT (elttype)));
6083 pos_rtx = expand_normal (position);
6084 xtarget = offset_address (target, pos_rtx,
6085 highest_pow2_factor (position));
6086 xtarget = adjust_address (xtarget, mode, 0);
6087 if (TREE_CODE (value) == CONSTRUCTOR)
6088 store_constructor (value, xtarget, cleared,
6089 bitsize / BITS_PER_UNIT);
6090 else
6091 store_expr (value, xtarget, 0, false);
6093 /* Generate a conditional jump to exit the loop. */
6094 exit_cond = build2 (LT_EXPR, integer_type_node,
6095 index, hi_index);
6096 jumpif (exit_cond, loop_end, -1);
6098 /* Update the loop counter, and jump to the head of
6099 the loop. */
6100 expand_assignment (index,
6101 build2 (PLUS_EXPR, TREE_TYPE (index),
6102 index, integer_one_node),
6103 false);
6105 emit_jump (loop_start);
6107 /* Build the end of the loop. */
6108 emit_label (loop_end);
6111 else if ((index != 0 && ! host_integerp (index, 0))
6112 || ! host_integerp (TYPE_SIZE (elttype), 1))
6114 tree position;
6116 if (index == 0)
6117 index = ssize_int (1);
6119 if (minelt)
6120 index = fold_convert (ssizetype,
6121 fold_build2 (MINUS_EXPR,
6122 TREE_TYPE (index),
6123 index,
6124 TYPE_MIN_VALUE (domain)));
6126 position =
6127 size_binop (MULT_EXPR, index,
6128 fold_convert (ssizetype,
6129 TYPE_SIZE_UNIT (elttype)));
6130 xtarget = offset_address (target,
6131 expand_normal (position),
6132 highest_pow2_factor (position));
6133 xtarget = adjust_address (xtarget, mode, 0);
6134 store_expr (value, xtarget, 0, false);
6136 else
6138 if (index != 0)
6139 bitpos = ((tree_low_cst (index, 0) - minelt)
6140 * tree_low_cst (TYPE_SIZE (elttype), 1));
6141 else
6142 bitpos = (i * tree_low_cst (TYPE_SIZE (elttype), 1));
6144 if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
6145 && TREE_CODE (type) == ARRAY_TYPE
6146 && TYPE_NONALIASED_COMPONENT (type))
6148 target = copy_rtx (target);
6149 MEM_KEEP_ALIAS_SET_P (target) = 1;
6151 store_constructor_field (target, bitsize, bitpos, mode, value,
6152 cleared, get_alias_set (elttype));
6155 break;
6158 case VECTOR_TYPE:
6160 unsigned HOST_WIDE_INT idx;
6161 constructor_elt *ce;
6162 int i;
6163 int need_to_clear;
6164 int icode = CODE_FOR_nothing;
6165 tree elttype = TREE_TYPE (type);
6166 int elt_size = tree_low_cst (TYPE_SIZE (elttype), 1);
6167 enum machine_mode eltmode = TYPE_MODE (elttype);
6168 HOST_WIDE_INT bitsize;
6169 HOST_WIDE_INT bitpos;
6170 rtvec vector = NULL;
6171 unsigned n_elts;
6172 alias_set_type alias;
6174 gcc_assert (eltmode != BLKmode);
6176 n_elts = TYPE_VECTOR_SUBPARTS (type);
6177 if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
6179 enum machine_mode mode = GET_MODE (target);
6181 icode = (int) optab_handler (vec_init_optab, mode);
6182 if (icode != CODE_FOR_nothing)
6184 unsigned int i;
6186 vector = rtvec_alloc (n_elts);
6187 for (i = 0; i < n_elts; i++)
6188 RTVEC_ELT (vector, i) = CONST0_RTX (GET_MODE_INNER (mode));
6192 /* If the constructor has fewer elements than the vector,
6193 clear the whole array first. Similarly if this is static
6194 constructor of a non-BLKmode object. */
6195 if (cleared)
6196 need_to_clear = 0;
6197 else if (REG_P (target) && TREE_STATIC (exp))
6198 need_to_clear = 1;
6199 else
6201 unsigned HOST_WIDE_INT count = 0, zero_count = 0;
6202 tree value;
6204 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
6206 int n_elts_here = tree_low_cst
6207 (int_const_binop (TRUNC_DIV_EXPR,
6208 TYPE_SIZE (TREE_TYPE (value)),
6209 TYPE_SIZE (elttype)), 1);
6211 count += n_elts_here;
6212 if (mostly_zeros_p (value))
6213 zero_count += n_elts_here;
6216 /* Clear the entire vector first if there are any missing elements,
6217 or if the incidence of zero elements is >= 75%. */
6218 need_to_clear = (count < n_elts || 4 * zero_count >= 3 * count);
6221 if (need_to_clear && size > 0 && !vector)
6223 if (REG_P (target))
6224 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6225 else
6226 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6227 cleared = 1;
6230 /* Inform later passes that the old value is dead. */
6231 if (!cleared && !vector && REG_P (target))
6232 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6234 if (MEM_P (target))
6235 alias = MEM_ALIAS_SET (target);
6236 else
6237 alias = get_alias_set (elttype);
6239 /* Store each element of the constructor into the corresponding
6240 element of TARGET, determined by counting the elements. */
6241 for (idx = 0, i = 0;
6242 vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
6243 idx++, i += bitsize / elt_size)
6245 HOST_WIDE_INT eltpos;
6246 tree value = ce->value;
6248 bitsize = tree_low_cst (TYPE_SIZE (TREE_TYPE (value)), 1);
6249 if (cleared && initializer_zerop (value))
6250 continue;
6252 if (ce->index)
6253 eltpos = tree_low_cst (ce->index, 1);
6254 else
6255 eltpos = i;
6257 if (vector)
6259 /* Vector CONSTRUCTORs should only be built from smaller
6260 vectors in the case of BLKmode vectors. */
6261 gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
6262 RTVEC_ELT (vector, eltpos)
6263 = expand_normal (value);
6265 else
6267 enum machine_mode value_mode =
6268 TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
6269 ? TYPE_MODE (TREE_TYPE (value))
6270 : eltmode;
6271 bitpos = eltpos * elt_size;
6272 store_constructor_field (target, bitsize, bitpos, value_mode,
6273 value, cleared, alias);
6277 if (vector)
6278 emit_insn (GEN_FCN (icode)
6279 (target,
6280 gen_rtx_PARALLEL (GET_MODE (target), vector)));
6281 break;
6284 default:
6285 gcc_unreachable ();
6289 /* Store the value of EXP (an expression tree)
6290 into a subfield of TARGET which has mode MODE and occupies
6291 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6292 If MODE is VOIDmode, it means that we are storing into a bit-field.
6294 BITREGION_START is bitpos of the first bitfield in this region.
6295 BITREGION_END is the bitpos of the ending bitfield in this region.
6296 These two fields are 0, if the C++ memory model does not apply,
6297 or we are not interested in keeping track of bitfield regions.
6299 Always return const0_rtx unless we have something particular to
6300 return.
6302 ALIAS_SET is the alias set for the destination. This value will
6303 (in general) be different from that for TARGET, since TARGET is a
6304 reference to the containing structure.
6306 If NONTEMPORAL is true, try generating a nontemporal store. */
6308 static rtx
6309 store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
6310 unsigned HOST_WIDE_INT bitregion_start,
6311 unsigned HOST_WIDE_INT bitregion_end,
6312 enum machine_mode mode, tree exp,
6313 alias_set_type alias_set, bool nontemporal)
6315 if (TREE_CODE (exp) == ERROR_MARK)
6316 return const0_rtx;
6318 /* If we have nothing to store, do nothing unless the expression has
6319 side-effects. */
6320 if (bitsize == 0)
6321 return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
6323 if (GET_CODE (target) == CONCAT)
6325 /* We're storing into a struct containing a single __complex. */
6327 gcc_assert (!bitpos);
6328 return store_expr (exp, target, 0, nontemporal);
6331 /* If the structure is in a register or if the component
6332 is a bit field, we cannot use addressing to access it.
6333 Use bit-field techniques or SUBREG to store in it. */
6335 if (mode == VOIDmode
6336 || (mode != BLKmode && ! direct_store[(int) mode]
6337 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
6338 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
6339 || REG_P (target)
6340 || GET_CODE (target) == SUBREG
6341 /* If the field isn't aligned enough to store as an ordinary memref,
6342 store it as a bit field. */
6343 || (mode != BLKmode
6344 && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
6345 || bitpos % GET_MODE_ALIGNMENT (mode))
6346 && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
6347 || (bitpos % BITS_PER_UNIT != 0)))
6348 || (bitsize >= 0 && mode != BLKmode
6349 && GET_MODE_BITSIZE (mode) > bitsize)
6350 /* If the RHS and field are a constant size and the size of the
6351 RHS isn't the same size as the bitfield, we must use bitfield
6352 operations. */
6353 || (bitsize >= 0
6354 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
6355 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0)
6356 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6357 decl we must use bitfield operations. */
6358 || (bitsize >= 0
6359 && TREE_CODE (exp) == MEM_REF
6360 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6361 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6362 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0),0 ))
6363 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
6365 rtx temp;
6366 gimple nop_def;
6368 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6369 implies a mask operation. If the precision is the same size as
6370 the field we're storing into, that mask is redundant. This is
6371 particularly common with bit field assignments generated by the
6372 C front end. */
6373 nop_def = get_def_for_expr (exp, NOP_EXPR);
6374 if (nop_def)
6376 tree type = TREE_TYPE (exp);
6377 if (INTEGRAL_TYPE_P (type)
6378 && TYPE_PRECISION (type) < GET_MODE_BITSIZE (TYPE_MODE (type))
6379 && bitsize == TYPE_PRECISION (type))
6381 tree op = gimple_assign_rhs1 (nop_def);
6382 type = TREE_TYPE (op);
6383 if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) >= bitsize)
6384 exp = op;
6388 temp = expand_normal (exp);
6390 /* If BITSIZE is narrower than the size of the type of EXP
6391 we will be narrowing TEMP. Normally, what's wanted are the
6392 low-order bits. However, if EXP's type is a record and this is
6393 big-endian machine, we want the upper BITSIZE bits. */
6394 if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
6395 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
6396 && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
6397 temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
6398 GET_MODE_BITSIZE (GET_MODE (temp)) - bitsize,
6399 NULL_RTX, 1);
6401 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6402 if (mode != VOIDmode && mode != BLKmode
6403 && mode != TYPE_MODE (TREE_TYPE (exp)))
6404 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
6406 /* If the modes of TEMP and TARGET are both BLKmode, both
6407 must be in memory and BITPOS must be aligned on a byte
6408 boundary. If so, we simply do a block copy. Likewise
6409 for a BLKmode-like TARGET. */
6410 if (GET_MODE (temp) == BLKmode
6411 && (GET_MODE (target) == BLKmode
6412 || (MEM_P (target)
6413 && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
6414 && (bitpos % BITS_PER_UNIT) == 0
6415 && (bitsize % BITS_PER_UNIT) == 0)))
6417 gcc_assert (MEM_P (target) && MEM_P (temp)
6418 && (bitpos % BITS_PER_UNIT) == 0);
6420 target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
6421 emit_block_move (target, temp,
6422 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
6423 / BITS_PER_UNIT),
6424 BLOCK_OP_NORMAL);
6426 return const0_rtx;
6429 /* Handle calls that return values in multiple non-contiguous locations.
6430 The Irix 6 ABI has examples of this. */
6431 if (GET_CODE (temp) == PARALLEL)
6433 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
6434 rtx temp_target;
6435 if (mode == BLKmode)
6436 mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
6437 temp_target = gen_reg_rtx (mode);
6438 emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
6439 temp = temp_target;
6441 else if (mode == BLKmode)
6443 /* Handle calls that return BLKmode values in registers. */
6444 if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
6446 rtx temp_target = gen_reg_rtx (GET_MODE (temp));
6447 copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp));
6448 temp = temp_target;
6450 else
6452 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
6453 rtx temp_target;
6454 mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
6455 temp_target = gen_reg_rtx (mode);
6456 temp_target
6457 = extract_bit_field (temp, size * BITS_PER_UNIT, 0, 1,
6458 false, temp_target, mode, mode);
6459 temp = temp_target;
6463 /* Store the value in the bitfield. */
6464 store_bit_field (target, bitsize, bitpos,
6465 bitregion_start, bitregion_end,
6466 mode, temp);
6468 return const0_rtx;
6470 else
6472 /* Now build a reference to just the desired component. */
6473 rtx to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
6475 if (to_rtx == target)
6476 to_rtx = copy_rtx (to_rtx);
6478 if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
6479 set_mem_alias_set (to_rtx, alias_set);
6481 return store_expr (exp, to_rtx, 0, nontemporal);
6485 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6486 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6487 codes and find the ultimate containing object, which we return.
6489 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6490 bit position, and *PUNSIGNEDP to the signedness of the field.
6491 If the position of the field is variable, we store a tree
6492 giving the variable offset (in units) in *POFFSET.
6493 This offset is in addition to the bit position.
6494 If the position is not variable, we store 0 in *POFFSET.
6496 If any of the extraction expressions is volatile,
6497 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6499 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6500 Otherwise, it is a mode that can be used to access the field.
6502 If the field describes a variable-sized object, *PMODE is set to
6503 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6504 this case, but the address of the object can be found.
6506 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6507 look through nodes that serve as markers of a greater alignment than
6508 the one that can be deduced from the expression. These nodes make it
6509 possible for front-ends to prevent temporaries from being created by
6510 the middle-end on alignment considerations. For that purpose, the
6511 normal operating mode at high-level is to always pass FALSE so that
6512 the ultimate containing object is really returned; moreover, the
6513 associated predicate handled_component_p will always return TRUE
6514 on these nodes, thus indicating that they are essentially handled
6515 by get_inner_reference. TRUE should only be passed when the caller
6516 is scanning the expression in order to build another representation
6517 and specifically knows how to handle these nodes; as such, this is
6518 the normal operating mode in the RTL expanders. */
6520 tree
6521 get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
6522 HOST_WIDE_INT *pbitpos, tree *poffset,
6523 enum machine_mode *pmode, int *punsignedp,
6524 int *pvolatilep, bool keep_aligning)
6526 tree size_tree = 0;
6527 enum machine_mode mode = VOIDmode;
6528 bool blkmode_bitfield = false;
6529 tree offset = size_zero_node;
6530 double_int bit_offset = double_int_zero;
6532 /* First get the mode, signedness, and size. We do this from just the
6533 outermost expression. */
6534 *pbitsize = -1;
6535 if (TREE_CODE (exp) == COMPONENT_REF)
6537 tree field = TREE_OPERAND (exp, 1);
6538 size_tree = DECL_SIZE (field);
6539 if (!DECL_BIT_FIELD (field))
6540 mode = DECL_MODE (field);
6541 else if (DECL_MODE (field) == BLKmode)
6542 blkmode_bitfield = true;
6543 else if (TREE_THIS_VOLATILE (exp)
6544 && flag_strict_volatile_bitfields > 0)
6545 /* Volatile bitfields should be accessed in the mode of the
6546 field's type, not the mode computed based on the bit
6547 size. */
6548 mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
6550 *punsignedp = DECL_UNSIGNED (field);
6552 else if (TREE_CODE (exp) == BIT_FIELD_REF)
6554 size_tree = TREE_OPERAND (exp, 1);
6555 *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
6556 || TYPE_UNSIGNED (TREE_TYPE (exp)));
6558 /* For vector types, with the correct size of access, use the mode of
6559 inner type. */
6560 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
6561 && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
6562 && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
6563 mode = TYPE_MODE (TREE_TYPE (exp));
6565 else
6567 mode = TYPE_MODE (TREE_TYPE (exp));
6568 *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
6570 if (mode == BLKmode)
6571 size_tree = TYPE_SIZE (TREE_TYPE (exp));
6572 else
6573 *pbitsize = GET_MODE_BITSIZE (mode);
6576 if (size_tree != 0)
6578 if (! host_integerp (size_tree, 1))
6579 mode = BLKmode, *pbitsize = -1;
6580 else
6581 *pbitsize = tree_low_cst (size_tree, 1);
6584 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6585 and find the ultimate containing object. */
6586 while (1)
6588 switch (TREE_CODE (exp))
6590 case BIT_FIELD_REF:
6591 bit_offset += tree_to_double_int (TREE_OPERAND (exp, 2));
6592 break;
6594 case COMPONENT_REF:
6596 tree field = TREE_OPERAND (exp, 1);
6597 tree this_offset = component_ref_field_offset (exp);
6599 /* If this field hasn't been filled in yet, don't go past it.
6600 This should only happen when folding expressions made during
6601 type construction. */
6602 if (this_offset == 0)
6603 break;
6605 offset = size_binop (PLUS_EXPR, offset, this_offset);
6606 bit_offset += tree_to_double_int (DECL_FIELD_BIT_OFFSET (field));
6608 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6610 break;
6612 case ARRAY_REF:
6613 case ARRAY_RANGE_REF:
6615 tree index = TREE_OPERAND (exp, 1);
6616 tree low_bound = array_ref_low_bound (exp);
6617 tree unit_size = array_ref_element_size (exp);
6619 /* We assume all arrays have sizes that are a multiple of a byte.
6620 First subtract the lower bound, if any, in the type of the
6621 index, then convert to sizetype and multiply by the size of
6622 the array element. */
6623 if (! integer_zerop (low_bound))
6624 index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
6625 index, low_bound);
6627 offset = size_binop (PLUS_EXPR, offset,
6628 size_binop (MULT_EXPR,
6629 fold_convert (sizetype, index),
6630 unit_size));
6632 break;
6634 case REALPART_EXPR:
6635 break;
6637 case IMAGPART_EXPR:
6638 bit_offset += double_int::from_uhwi (*pbitsize);
6639 break;
6641 case VIEW_CONVERT_EXPR:
6642 if (keep_aligning && STRICT_ALIGNMENT
6643 && (TYPE_ALIGN (TREE_TYPE (exp))
6644 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
6645 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
6646 < BIGGEST_ALIGNMENT)
6647 && (TYPE_ALIGN_OK (TREE_TYPE (exp))
6648 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp, 0)))))
6649 goto done;
6650 break;
6652 case MEM_REF:
6653 /* Hand back the decl for MEM[&decl, off]. */
6654 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
6656 tree off = TREE_OPERAND (exp, 1);
6657 if (!integer_zerop (off))
6659 double_int boff, coff = mem_ref_offset (exp);
6660 boff = coff.alshift (BITS_PER_UNIT == 8
6661 ? 3 : exact_log2 (BITS_PER_UNIT),
6662 HOST_BITS_PER_DOUBLE_INT);
6663 bit_offset += boff;
6665 exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6667 goto done;
6669 default:
6670 goto done;
6673 /* If any reference in the chain is volatile, the effect is volatile. */
6674 if (TREE_THIS_VOLATILE (exp))
6675 *pvolatilep = 1;
6677 exp = TREE_OPERAND (exp, 0);
6679 done:
6681 /* If OFFSET is constant, see if we can return the whole thing as a
6682 constant bit position. Make sure to handle overflow during
6683 this conversion. */
6684 if (TREE_CODE (offset) == INTEGER_CST)
6686 double_int tem = tree_to_double_int (offset);
6687 tem = tem.sext (TYPE_PRECISION (sizetype));
6688 tem = tem.alshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT),
6689 HOST_BITS_PER_DOUBLE_INT);
6690 tem += bit_offset;
6691 if (tem.fits_shwi ())
6693 *pbitpos = tem.to_shwi ();
6694 *poffset = offset = NULL_TREE;
6698 /* Otherwise, split it up. */
6699 if (offset)
6701 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6702 if (bit_offset.is_negative ())
6704 double_int mask
6705 = double_int::mask (BITS_PER_UNIT == 8
6706 ? 3 : exact_log2 (BITS_PER_UNIT));
6707 double_int tem = bit_offset.and_not (mask);
6708 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6709 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6710 bit_offset -= tem;
6711 tem = tem.arshift (BITS_PER_UNIT == 8
6712 ? 3 : exact_log2 (BITS_PER_UNIT),
6713 HOST_BITS_PER_DOUBLE_INT);
6714 offset = size_binop (PLUS_EXPR, offset,
6715 double_int_to_tree (sizetype, tem));
6718 *pbitpos = bit_offset.to_shwi ();
6719 *poffset = offset;
6722 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6723 if (mode == VOIDmode
6724 && blkmode_bitfield
6725 && (*pbitpos % BITS_PER_UNIT) == 0
6726 && (*pbitsize % BITS_PER_UNIT) == 0)
6727 *pmode = BLKmode;
6728 else
6729 *pmode = mode;
6731 return exp;
6734 /* Return a tree of sizetype representing the size, in bytes, of the element
6735 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6737 tree
6738 array_ref_element_size (tree exp)
6740 tree aligned_size = TREE_OPERAND (exp, 3);
6741 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
6742 location_t loc = EXPR_LOCATION (exp);
6744 /* If a size was specified in the ARRAY_REF, it's the size measured
6745 in alignment units of the element type. So multiply by that value. */
6746 if (aligned_size)
6748 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6749 sizetype from another type of the same width and signedness. */
6750 if (TREE_TYPE (aligned_size) != sizetype)
6751 aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
6752 return size_binop_loc (loc, MULT_EXPR, aligned_size,
6753 size_int (TYPE_ALIGN_UNIT (elmt_type)));
6756 /* Otherwise, take the size from that of the element type. Substitute
6757 any PLACEHOLDER_EXPR that we have. */
6758 else
6759 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
6762 /* Return a tree representing the lower bound of the array mentioned in
6763 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6765 tree
6766 array_ref_low_bound (tree exp)
6768 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
6770 /* If a lower bound is specified in EXP, use it. */
6771 if (TREE_OPERAND (exp, 2))
6772 return TREE_OPERAND (exp, 2);
6774 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6775 substituting for a PLACEHOLDER_EXPR as needed. */
6776 if (domain_type && TYPE_MIN_VALUE (domain_type))
6777 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
6779 /* Otherwise, return a zero of the appropriate type. */
6780 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp, 1)), 0);
6783 /* Returns true if REF is an array reference to an array at the end of
6784 a structure. If this is the case, the array may be allocated larger
6785 than its upper bound implies. */
6787 bool
6788 array_at_struct_end_p (tree ref)
6790 if (TREE_CODE (ref) != ARRAY_REF
6791 && TREE_CODE (ref) != ARRAY_RANGE_REF)
6792 return false;
6794 while (handled_component_p (ref))
6796 /* If the reference chain contains a component reference to a
6797 non-union type and there follows another field the reference
6798 is not at the end of a structure. */
6799 if (TREE_CODE (ref) == COMPONENT_REF
6800 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
6802 tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
6803 while (nextf && TREE_CODE (nextf) != FIELD_DECL)
6804 nextf = DECL_CHAIN (nextf);
6805 if (nextf)
6806 return false;
6809 ref = TREE_OPERAND (ref, 0);
6812 /* If the reference is based on a declared entity, the size of the array
6813 is constrained by its given domain. */
6814 if (DECL_P (ref))
6815 return false;
6817 return true;
6820 /* Return a tree representing the upper bound of the array mentioned in
6821 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6823 tree
6824 array_ref_up_bound (tree exp)
6826 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
6828 /* If there is a domain type and it has an upper bound, use it, substituting
6829 for a PLACEHOLDER_EXPR as needed. */
6830 if (domain_type && TYPE_MAX_VALUE (domain_type))
6831 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
6833 /* Otherwise fail. */
6834 return NULL_TREE;
6837 /* Return a tree representing the offset, in bytes, of the field referenced
6838 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6840 tree
6841 component_ref_field_offset (tree exp)
6843 tree aligned_offset = TREE_OPERAND (exp, 2);
6844 tree field = TREE_OPERAND (exp, 1);
6845 location_t loc = EXPR_LOCATION (exp);
6847 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6848 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6849 value. */
6850 if (aligned_offset)
6852 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6853 sizetype from another type of the same width and signedness. */
6854 if (TREE_TYPE (aligned_offset) != sizetype)
6855 aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
6856 return size_binop_loc (loc, MULT_EXPR, aligned_offset,
6857 size_int (DECL_OFFSET_ALIGN (field)
6858 / BITS_PER_UNIT));
6861 /* Otherwise, take the offset from that of the field. Substitute
6862 any PLACEHOLDER_EXPR that we have. */
6863 else
6864 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
6867 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6869 static unsigned HOST_WIDE_INT
6870 target_align (const_tree target)
6872 /* We might have a chain of nested references with intermediate misaligning
6873 bitfields components, so need to recurse to find out. */
6875 unsigned HOST_WIDE_INT this_align, outer_align;
6877 switch (TREE_CODE (target))
6879 case BIT_FIELD_REF:
6880 return 1;
6882 case COMPONENT_REF:
6883 this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
6884 outer_align = target_align (TREE_OPERAND (target, 0));
6885 return MIN (this_align, outer_align);
6887 case ARRAY_REF:
6888 case ARRAY_RANGE_REF:
6889 this_align = TYPE_ALIGN (TREE_TYPE (target));
6890 outer_align = target_align (TREE_OPERAND (target, 0));
6891 return MIN (this_align, outer_align);
6893 CASE_CONVERT:
6894 case NON_LVALUE_EXPR:
6895 case VIEW_CONVERT_EXPR:
6896 this_align = TYPE_ALIGN (TREE_TYPE (target));
6897 outer_align = target_align (TREE_OPERAND (target, 0));
6898 return MAX (this_align, outer_align);
6900 default:
6901 return TYPE_ALIGN (TREE_TYPE (target));
6906 /* Given an rtx VALUE that may contain additions and multiplications, return
6907 an equivalent value that just refers to a register, memory, or constant.
6908 This is done by generating instructions to perform the arithmetic and
6909 returning a pseudo-register containing the value.
6911 The returned value may be a REG, SUBREG, MEM or constant. */
6914 force_operand (rtx value, rtx target)
6916 rtx op1, op2;
6917 /* Use subtarget as the target for operand 0 of a binary operation. */
6918 rtx subtarget = get_subtarget (target);
6919 enum rtx_code code = GET_CODE (value);
6921 /* Check for subreg applied to an expression produced by loop optimizer. */
6922 if (code == SUBREG
6923 && !REG_P (SUBREG_REG (value))
6924 && !MEM_P (SUBREG_REG (value)))
6926 value
6927 = simplify_gen_subreg (GET_MODE (value),
6928 force_reg (GET_MODE (SUBREG_REG (value)),
6929 force_operand (SUBREG_REG (value),
6930 NULL_RTX)),
6931 GET_MODE (SUBREG_REG (value)),
6932 SUBREG_BYTE (value));
6933 code = GET_CODE (value);
6936 /* Check for a PIC address load. */
6937 if ((code == PLUS || code == MINUS)
6938 && XEXP (value, 0) == pic_offset_table_rtx
6939 && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
6940 || GET_CODE (XEXP (value, 1)) == LABEL_REF
6941 || GET_CODE (XEXP (value, 1)) == CONST))
6943 if (!subtarget)
6944 subtarget = gen_reg_rtx (GET_MODE (value));
6945 emit_move_insn (subtarget, value);
6946 return subtarget;
6949 if (ARITHMETIC_P (value))
6951 op2 = XEXP (value, 1);
6952 if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
6953 subtarget = 0;
6954 if (code == MINUS && CONST_INT_P (op2))
6956 code = PLUS;
6957 op2 = negate_rtx (GET_MODE (value), op2);
6960 /* Check for an addition with OP2 a constant integer and our first
6961 operand a PLUS of a virtual register and something else. In that
6962 case, we want to emit the sum of the virtual register and the
6963 constant first and then add the other value. This allows virtual
6964 register instantiation to simply modify the constant rather than
6965 creating another one around this addition. */
6966 if (code == PLUS && CONST_INT_P (op2)
6967 && GET_CODE (XEXP (value, 0)) == PLUS
6968 && REG_P (XEXP (XEXP (value, 0), 0))
6969 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
6970 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
6972 rtx temp = expand_simple_binop (GET_MODE (value), code,
6973 XEXP (XEXP (value, 0), 0), op2,
6974 subtarget, 0, OPTAB_LIB_WIDEN);
6975 return expand_simple_binop (GET_MODE (value), code, temp,
6976 force_operand (XEXP (XEXP (value,
6977 0), 1), 0),
6978 target, 0, OPTAB_LIB_WIDEN);
6981 op1 = force_operand (XEXP (value, 0), subtarget);
6982 op2 = force_operand (op2, NULL_RTX);
6983 switch (code)
6985 case MULT:
6986 return expand_mult (GET_MODE (value), op1, op2, target, 1);
6987 case DIV:
6988 if (!INTEGRAL_MODE_P (GET_MODE (value)))
6989 return expand_simple_binop (GET_MODE (value), code, op1, op2,
6990 target, 1, OPTAB_LIB_WIDEN);
6991 else
6992 return expand_divmod (0,
6993 FLOAT_MODE_P (GET_MODE (value))
6994 ? RDIV_EXPR : TRUNC_DIV_EXPR,
6995 GET_MODE (value), op1, op2, target, 0);
6996 case MOD:
6997 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
6998 target, 0);
6999 case UDIV:
7000 return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
7001 target, 1);
7002 case UMOD:
7003 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7004 target, 1);
7005 case ASHIFTRT:
7006 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7007 target, 0, OPTAB_LIB_WIDEN);
7008 default:
7009 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7010 target, 1, OPTAB_LIB_WIDEN);
7013 if (UNARY_P (value))
7015 if (!target)
7016 target = gen_reg_rtx (GET_MODE (value));
7017 op1 = force_operand (XEXP (value, 0), NULL_RTX);
7018 switch (code)
7020 case ZERO_EXTEND:
7021 case SIGN_EXTEND:
7022 case TRUNCATE:
7023 case FLOAT_EXTEND:
7024 case FLOAT_TRUNCATE:
7025 convert_move (target, op1, code == ZERO_EXTEND);
7026 return target;
7028 case FIX:
7029 case UNSIGNED_FIX:
7030 expand_fix (target, op1, code == UNSIGNED_FIX);
7031 return target;
7033 case FLOAT:
7034 case UNSIGNED_FLOAT:
7035 expand_float (target, op1, code == UNSIGNED_FLOAT);
7036 return target;
7038 default:
7039 return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
7043 #ifdef INSN_SCHEDULING
7044 /* On machines that have insn scheduling, we want all memory reference to be
7045 explicit, so we need to deal with such paradoxical SUBREGs. */
7046 if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
7047 value
7048 = simplify_gen_subreg (GET_MODE (value),
7049 force_reg (GET_MODE (SUBREG_REG (value)),
7050 force_operand (SUBREG_REG (value),
7051 NULL_RTX)),
7052 GET_MODE (SUBREG_REG (value)),
7053 SUBREG_BYTE (value));
7054 #endif
7056 return value;
7059 /* Subroutine of expand_expr: return nonzero iff there is no way that
7060 EXP can reference X, which is being modified. TOP_P is nonzero if this
7061 call is going to be used to determine whether we need a temporary
7062 for EXP, as opposed to a recursive call to this function.
7064 It is always safe for this routine to return zero since it merely
7065 searches for optimization opportunities. */
7068 safe_from_p (const_rtx x, tree exp, int top_p)
7070 rtx exp_rtl = 0;
7071 int i, nops;
7073 if (x == 0
7074 /* If EXP has varying size, we MUST use a target since we currently
7075 have no way of allocating temporaries of variable size
7076 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7077 So we assume here that something at a higher level has prevented a
7078 clash. This is somewhat bogus, but the best we can do. Only
7079 do this when X is BLKmode and when we are at the top level. */
7080 || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
7081 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
7082 && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
7083 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
7084 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
7085 != INTEGER_CST)
7086 && GET_MODE (x) == BLKmode)
7087 /* If X is in the outgoing argument area, it is always safe. */
7088 || (MEM_P (x)
7089 && (XEXP (x, 0) == virtual_outgoing_args_rtx
7090 || (GET_CODE (XEXP (x, 0)) == PLUS
7091 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
7092 return 1;
7094 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7095 find the underlying pseudo. */
7096 if (GET_CODE (x) == SUBREG)
7098 x = SUBREG_REG (x);
7099 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7100 return 0;
7103 /* Now look at our tree code and possibly recurse. */
7104 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
7106 case tcc_declaration:
7107 exp_rtl = DECL_RTL_IF_SET (exp);
7108 break;
7110 case tcc_constant:
7111 return 1;
7113 case tcc_exceptional:
7114 if (TREE_CODE (exp) == TREE_LIST)
7116 while (1)
7118 if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
7119 return 0;
7120 exp = TREE_CHAIN (exp);
7121 if (!exp)
7122 return 1;
7123 if (TREE_CODE (exp) != TREE_LIST)
7124 return safe_from_p (x, exp, 0);
7127 else if (TREE_CODE (exp) == CONSTRUCTOR)
7129 constructor_elt *ce;
7130 unsigned HOST_WIDE_INT idx;
7132 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
7133 if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
7134 || !safe_from_p (x, ce->value, 0))
7135 return 0;
7136 return 1;
7138 else if (TREE_CODE (exp) == ERROR_MARK)
7139 return 1; /* An already-visited SAVE_EXPR? */
7140 else
7141 return 0;
7143 case tcc_statement:
7144 /* The only case we look at here is the DECL_INITIAL inside a
7145 DECL_EXPR. */
7146 return (TREE_CODE (exp) != DECL_EXPR
7147 || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
7148 || !DECL_INITIAL (DECL_EXPR_DECL (exp))
7149 || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
7151 case tcc_binary:
7152 case tcc_comparison:
7153 if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
7154 return 0;
7155 /* Fall through. */
7157 case tcc_unary:
7158 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7160 case tcc_expression:
7161 case tcc_reference:
7162 case tcc_vl_exp:
7163 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7164 the expression. If it is set, we conflict iff we are that rtx or
7165 both are in memory. Otherwise, we check all operands of the
7166 expression recursively. */
7168 switch (TREE_CODE (exp))
7170 case ADDR_EXPR:
7171 /* If the operand is static or we are static, we can't conflict.
7172 Likewise if we don't conflict with the operand at all. */
7173 if (staticp (TREE_OPERAND (exp, 0))
7174 || TREE_STATIC (exp)
7175 || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
7176 return 1;
7178 /* Otherwise, the only way this can conflict is if we are taking
7179 the address of a DECL a that address if part of X, which is
7180 very rare. */
7181 exp = TREE_OPERAND (exp, 0);
7182 if (DECL_P (exp))
7184 if (!DECL_RTL_SET_P (exp)
7185 || !MEM_P (DECL_RTL (exp)))
7186 return 0;
7187 else
7188 exp_rtl = XEXP (DECL_RTL (exp), 0);
7190 break;
7192 case MEM_REF:
7193 if (MEM_P (x)
7194 && alias_sets_conflict_p (MEM_ALIAS_SET (x),
7195 get_alias_set (exp)))
7196 return 0;
7197 break;
7199 case CALL_EXPR:
7200 /* Assume that the call will clobber all hard registers and
7201 all of memory. */
7202 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7203 || MEM_P (x))
7204 return 0;
7205 break;
7207 case WITH_CLEANUP_EXPR:
7208 case CLEANUP_POINT_EXPR:
7209 /* Lowered by gimplify.c. */
7210 gcc_unreachable ();
7212 case SAVE_EXPR:
7213 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7215 default:
7216 break;
7219 /* If we have an rtx, we do not need to scan our operands. */
7220 if (exp_rtl)
7221 break;
7223 nops = TREE_OPERAND_LENGTH (exp);
7224 for (i = 0; i < nops; i++)
7225 if (TREE_OPERAND (exp, i) != 0
7226 && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
7227 return 0;
7229 break;
7231 case tcc_type:
7232 /* Should never get a type here. */
7233 gcc_unreachable ();
7236 /* If we have an rtl, find any enclosed object. Then see if we conflict
7237 with it. */
7238 if (exp_rtl)
7240 if (GET_CODE (exp_rtl) == SUBREG)
7242 exp_rtl = SUBREG_REG (exp_rtl);
7243 if (REG_P (exp_rtl)
7244 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
7245 return 0;
7248 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7249 are memory and they conflict. */
7250 return ! (rtx_equal_p (x, exp_rtl)
7251 || (MEM_P (x) && MEM_P (exp_rtl)
7252 && true_dependence (exp_rtl, VOIDmode, x)));
7255 /* If we reach here, it is safe. */
7256 return 1;
7260 /* Return the highest power of two that EXP is known to be a multiple of.
7261 This is used in updating alignment of MEMs in array references. */
7263 unsigned HOST_WIDE_INT
7264 highest_pow2_factor (const_tree exp)
7266 unsigned HOST_WIDE_INT c0, c1;
7268 switch (TREE_CODE (exp))
7270 case INTEGER_CST:
7271 /* We can find the lowest bit that's a one. If the low
7272 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
7273 We need to handle this case since we can find it in a COND_EXPR,
7274 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
7275 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
7276 later ICE. */
7277 if (TREE_OVERFLOW (exp))
7278 return BIGGEST_ALIGNMENT;
7279 else
7281 /* Note: tree_low_cst is intentionally not used here,
7282 we don't care about the upper bits. */
7283 c0 = TREE_INT_CST_LOW (exp);
7284 c0 &= -c0;
7285 return c0 ? c0 : BIGGEST_ALIGNMENT;
7287 break;
7289 case PLUS_EXPR: case MINUS_EXPR: case MIN_EXPR: case MAX_EXPR:
7290 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7291 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7292 return MIN (c0, c1);
7294 case MULT_EXPR:
7295 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7296 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7297 return c0 * c1;
7299 case ROUND_DIV_EXPR: case TRUNC_DIV_EXPR: case FLOOR_DIV_EXPR:
7300 case CEIL_DIV_EXPR:
7301 if (integer_pow2p (TREE_OPERAND (exp, 1))
7302 && host_integerp (TREE_OPERAND (exp, 1), 1))
7304 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
7305 c1 = tree_low_cst (TREE_OPERAND (exp, 1), 1);
7306 return MAX (1, c0 / c1);
7308 break;
7310 case BIT_AND_EXPR:
7311 /* The highest power of two of a bit-and expression is the maximum of
7312 that of its operands. We typically get here for a complex LHS and
7313 a constant negative power of two on the RHS to force an explicit
7314 alignment, so don't bother looking at the LHS. */
7315 return highest_pow2_factor (TREE_OPERAND (exp, 1));
7317 CASE_CONVERT:
7318 case SAVE_EXPR:
7319 return highest_pow2_factor (TREE_OPERAND (exp, 0));
7321 case COMPOUND_EXPR:
7322 return highest_pow2_factor (TREE_OPERAND (exp, 1));
7324 case COND_EXPR:
7325 c0 = highest_pow2_factor (TREE_OPERAND (exp, 1));
7326 c1 = highest_pow2_factor (TREE_OPERAND (exp, 2));
7327 return MIN (c0, c1);
7329 default:
7330 break;
7333 return 1;
7336 /* Similar, except that the alignment requirements of TARGET are
7337 taken into account. Assume it is at least as aligned as its
7338 type, unless it is a COMPONENT_REF in which case the layout of
7339 the structure gives the alignment. */
7341 static unsigned HOST_WIDE_INT
7342 highest_pow2_factor_for_target (const_tree target, const_tree exp)
7344 unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
7345 unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
7347 return MAX (factor, talign);
7350 #ifdef HAVE_conditional_move
7351 /* Convert the tree comparison code TCODE to the rtl one where the
7352 signedness is UNSIGNEDP. */
7354 static enum rtx_code
7355 convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
7357 enum rtx_code code;
7358 switch (tcode)
7360 case EQ_EXPR:
7361 code = EQ;
7362 break;
7363 case NE_EXPR:
7364 code = NE;
7365 break;
7366 case LT_EXPR:
7367 code = unsignedp ? LTU : LT;
7368 break;
7369 case LE_EXPR:
7370 code = unsignedp ? LEU : LE;
7371 break;
7372 case GT_EXPR:
7373 code = unsignedp ? GTU : GT;
7374 break;
7375 case GE_EXPR:
7376 code = unsignedp ? GEU : GE;
7377 break;
7378 case UNORDERED_EXPR:
7379 code = UNORDERED;
7380 break;
7381 case ORDERED_EXPR:
7382 code = ORDERED;
7383 break;
7384 case UNLT_EXPR:
7385 code = UNLT;
7386 break;
7387 case UNLE_EXPR:
7388 code = UNLE;
7389 break;
7390 case UNGT_EXPR:
7391 code = UNGT;
7392 break;
7393 case UNGE_EXPR:
7394 code = UNGE;
7395 break;
7396 case UNEQ_EXPR:
7397 code = UNEQ;
7398 break;
7399 case LTGT_EXPR:
7400 code = LTGT;
7401 break;
7403 default:
7404 gcc_unreachable ();
7406 return code;
7408 #endif
7410 /* Subroutine of expand_expr. Expand the two operands of a binary
7411 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7412 The value may be stored in TARGET if TARGET is nonzero. The
7413 MODIFIER argument is as documented by expand_expr. */
7415 static void
7416 expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
7417 enum expand_modifier modifier)
7419 if (! safe_from_p (target, exp1, 1))
7420 target = 0;
7421 if (operand_equal_p (exp0, exp1, 0))
7423 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7424 *op1 = copy_rtx (*op0);
7426 else
7428 /* If we need to preserve evaluation order, copy exp0 into its own
7429 temporary variable so that it can't be clobbered by exp1. */
7430 if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
7431 exp0 = save_expr (exp0);
7432 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7433 *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
7438 /* Return a MEM that contains constant EXP. DEFER is as for
7439 output_constant_def and MODIFIER is as for expand_expr. */
7441 static rtx
7442 expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
7444 rtx mem;
7446 mem = output_constant_def (exp, defer);
7447 if (modifier != EXPAND_INITIALIZER)
7448 mem = use_anchored_address (mem);
7449 return mem;
7452 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7453 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7455 static rtx
7456 expand_expr_addr_expr_1 (tree exp, rtx target, enum machine_mode tmode,
7457 enum expand_modifier modifier, addr_space_t as)
7459 rtx result, subtarget;
7460 tree inner, offset;
7461 HOST_WIDE_INT bitsize, bitpos;
7462 int volatilep, unsignedp;
7463 enum machine_mode mode1;
7465 /* If we are taking the address of a constant and are at the top level,
7466 we have to use output_constant_def since we can't call force_const_mem
7467 at top level. */
7468 /* ??? This should be considered a front-end bug. We should not be
7469 generating ADDR_EXPR of something that isn't an LVALUE. The only
7470 exception here is STRING_CST. */
7471 if (CONSTANT_CLASS_P (exp))
7473 result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
7474 if (modifier < EXPAND_SUM)
7475 result = force_operand (result, target);
7476 return result;
7479 /* Everything must be something allowed by is_gimple_addressable. */
7480 switch (TREE_CODE (exp))
7482 case INDIRECT_REF:
7483 /* This case will happen via recursion for &a->b. */
7484 return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7486 case MEM_REF:
7488 tree tem = TREE_OPERAND (exp, 0);
7489 if (!integer_zerop (TREE_OPERAND (exp, 1)))
7490 tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
7491 return expand_expr (tem, target, tmode, modifier);
7494 case CONST_DECL:
7495 /* Expand the initializer like constants above. */
7496 result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
7497 0, modifier), 0);
7498 if (modifier < EXPAND_SUM)
7499 result = force_operand (result, target);
7500 return result;
7502 case REALPART_EXPR:
7503 /* The real part of the complex number is always first, therefore
7504 the address is the same as the address of the parent object. */
7505 offset = 0;
7506 bitpos = 0;
7507 inner = TREE_OPERAND (exp, 0);
7508 break;
7510 case IMAGPART_EXPR:
7511 /* The imaginary part of the complex number is always second.
7512 The expression is therefore always offset by the size of the
7513 scalar type. */
7514 offset = 0;
7515 bitpos = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)));
7516 inner = TREE_OPERAND (exp, 0);
7517 break;
7519 default:
7520 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7521 expand_expr, as that can have various side effects; LABEL_DECLs for
7522 example, may not have their DECL_RTL set yet. Expand the rtl of
7523 CONSTRUCTORs too, which should yield a memory reference for the
7524 constructor's contents. Assume language specific tree nodes can
7525 be expanded in some interesting way. */
7526 gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
7527 if (DECL_P (exp)
7528 || TREE_CODE (exp) == CONSTRUCTOR
7529 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
7531 result = expand_expr (exp, target, tmode,
7532 modifier == EXPAND_INITIALIZER
7533 ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
7535 /* If the DECL isn't in memory, then the DECL wasn't properly
7536 marked TREE_ADDRESSABLE, which will be either a front-end
7537 or a tree optimizer bug. */
7539 if (TREE_ADDRESSABLE (exp)
7540 && ! MEM_P (result)
7541 && ! targetm.calls.allocate_stack_slots_for_args())
7543 error ("local frame unavailable (naked function?)");
7544 return result;
7546 else
7547 gcc_assert (MEM_P (result));
7548 result = XEXP (result, 0);
7550 /* ??? Is this needed anymore? */
7551 if (DECL_P (exp))
7552 TREE_USED (exp) = 1;
7554 if (modifier != EXPAND_INITIALIZER
7555 && modifier != EXPAND_CONST_ADDRESS
7556 && modifier != EXPAND_SUM)
7557 result = force_operand (result, target);
7558 return result;
7561 /* Pass FALSE as the last argument to get_inner_reference although
7562 we are expanding to RTL. The rationale is that we know how to
7563 handle "aligning nodes" here: we can just bypass them because
7564 they won't change the final object whose address will be returned
7565 (they actually exist only for that purpose). */
7566 inner = get_inner_reference (exp, &bitsize, &bitpos, &offset,
7567 &mode1, &unsignedp, &volatilep, false);
7568 break;
7571 /* We must have made progress. */
7572 gcc_assert (inner != exp);
7574 subtarget = offset || bitpos ? NULL_RTX : target;
7575 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7576 inner alignment, force the inner to be sufficiently aligned. */
7577 if (CONSTANT_CLASS_P (inner)
7578 && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
7580 inner = copy_node (inner);
7581 TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
7582 TYPE_ALIGN (TREE_TYPE (inner)) = TYPE_ALIGN (TREE_TYPE (exp));
7583 TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
7585 result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
7587 if (offset)
7589 rtx tmp;
7591 if (modifier != EXPAND_NORMAL)
7592 result = force_operand (result, NULL);
7593 tmp = expand_expr (offset, NULL_RTX, tmode,
7594 modifier == EXPAND_INITIALIZER
7595 ? EXPAND_INITIALIZER : EXPAND_NORMAL);
7597 result = convert_memory_address_addr_space (tmode, result, as);
7598 tmp = convert_memory_address_addr_space (tmode, tmp, as);
7600 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7601 result = simplify_gen_binary (PLUS, tmode, result, tmp);
7602 else
7604 subtarget = bitpos ? NULL_RTX : target;
7605 result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
7606 1, OPTAB_LIB_WIDEN);
7610 if (bitpos)
7612 /* Someone beforehand should have rejected taking the address
7613 of such an object. */
7614 gcc_assert ((bitpos % BITS_PER_UNIT) == 0);
7616 result = convert_memory_address_addr_space (tmode, result, as);
7617 result = plus_constant (tmode, result, bitpos / BITS_PER_UNIT);
7618 if (modifier < EXPAND_SUM)
7619 result = force_operand (result, target);
7622 return result;
7625 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7626 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7628 static rtx
7629 expand_expr_addr_expr (tree exp, rtx target, enum machine_mode tmode,
7630 enum expand_modifier modifier)
7632 addr_space_t as = ADDR_SPACE_GENERIC;
7633 enum machine_mode address_mode = Pmode;
7634 enum machine_mode pointer_mode = ptr_mode;
7635 enum machine_mode rmode;
7636 rtx result;
7638 /* Target mode of VOIDmode says "whatever's natural". */
7639 if (tmode == VOIDmode)
7640 tmode = TYPE_MODE (TREE_TYPE (exp));
7642 if (POINTER_TYPE_P (TREE_TYPE (exp)))
7644 as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
7645 address_mode = targetm.addr_space.address_mode (as);
7646 pointer_mode = targetm.addr_space.pointer_mode (as);
7649 /* We can get called with some Weird Things if the user does silliness
7650 like "(short) &a". In that case, convert_memory_address won't do
7651 the right thing, so ignore the given target mode. */
7652 if (tmode != address_mode && tmode != pointer_mode)
7653 tmode = address_mode;
7655 result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
7656 tmode, modifier, as);
7658 /* Despite expand_expr claims concerning ignoring TMODE when not
7659 strictly convenient, stuff breaks if we don't honor it. Note
7660 that combined with the above, we only do this for pointer modes. */
7661 rmode = GET_MODE (result);
7662 if (rmode == VOIDmode)
7663 rmode = tmode;
7664 if (rmode != tmode)
7665 result = convert_memory_address_addr_space (tmode, result, as);
7667 return result;
7670 /* Generate code for computing CONSTRUCTOR EXP.
7671 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7672 is TRUE, instead of creating a temporary variable in memory
7673 NULL is returned and the caller needs to handle it differently. */
7675 static rtx
7676 expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
7677 bool avoid_temp_mem)
7679 tree type = TREE_TYPE (exp);
7680 enum machine_mode mode = TYPE_MODE (type);
7682 /* Try to avoid creating a temporary at all. This is possible
7683 if all of the initializer is zero.
7684 FIXME: try to handle all [0..255] initializers we can handle
7685 with memset. */
7686 if (TREE_STATIC (exp)
7687 && !TREE_ADDRESSABLE (exp)
7688 && target != 0 && mode == BLKmode
7689 && all_zeros_p (exp))
7691 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7692 return target;
7695 /* All elts simple constants => refer to a constant in memory. But
7696 if this is a non-BLKmode mode, let it store a field at a time
7697 since that should make a CONST_INT or CONST_DOUBLE when we
7698 fold. Likewise, if we have a target we can use, it is best to
7699 store directly into the target unless the type is large enough
7700 that memcpy will be used. If we are making an initializer and
7701 all operands are constant, put it in memory as well.
7703 FIXME: Avoid trying to fill vector constructors piece-meal.
7704 Output them with output_constant_def below unless we're sure
7705 they're zeros. This should go away when vector initializers
7706 are treated like VECTOR_CST instead of arrays. */
7707 if ((TREE_STATIC (exp)
7708 && ((mode == BLKmode
7709 && ! (target != 0 && safe_from_p (target, exp, 1)))
7710 || TREE_ADDRESSABLE (exp)
7711 || (host_integerp (TYPE_SIZE_UNIT (type), 1)
7712 && (! MOVE_BY_PIECES_P
7713 (tree_low_cst (TYPE_SIZE_UNIT (type), 1),
7714 TYPE_ALIGN (type)))
7715 && ! mostly_zeros_p (exp))))
7716 || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
7717 && TREE_CONSTANT (exp)))
7719 rtx constructor;
7721 if (avoid_temp_mem)
7722 return NULL_RTX;
7724 constructor = expand_expr_constant (exp, 1, modifier);
7726 if (modifier != EXPAND_CONST_ADDRESS
7727 && modifier != EXPAND_INITIALIZER
7728 && modifier != EXPAND_SUM)
7729 constructor = validize_mem (constructor);
7731 return constructor;
7734 /* Handle calls that pass values in multiple non-contiguous
7735 locations. The Irix 6 ABI has examples of this. */
7736 if (target == 0 || ! safe_from_p (target, exp, 1)
7737 || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM)
7739 if (avoid_temp_mem)
7740 return NULL_RTX;
7742 target
7743 = assign_temp (build_qualified_type (type, (TYPE_QUALS (type)
7744 | (TREE_READONLY (exp)
7745 * TYPE_QUAL_CONST))),
7746 TREE_ADDRESSABLE (exp), 1);
7749 store_constructor (exp, target, 0, int_expr_size (exp));
7750 return target;
7754 /* expand_expr: generate code for computing expression EXP.
7755 An rtx for the computed value is returned. The value is never null.
7756 In the case of a void EXP, const0_rtx is returned.
7758 The value may be stored in TARGET if TARGET is nonzero.
7759 TARGET is just a suggestion; callers must assume that
7760 the rtx returned may not be the same as TARGET.
7762 If TARGET is CONST0_RTX, it means that the value will be ignored.
7764 If TMODE is not VOIDmode, it suggests generating the
7765 result in mode TMODE. But this is done only when convenient.
7766 Otherwise, TMODE is ignored and the value generated in its natural mode.
7767 TMODE is just a suggestion; callers must assume that
7768 the rtx returned may not have mode TMODE.
7770 Note that TARGET may have neither TMODE nor MODE. In that case, it
7771 probably will not be used.
7773 If MODIFIER is EXPAND_SUM then when EXP is an addition
7774 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7775 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7776 products as above, or REG or MEM, or constant.
7777 Ordinarily in such cases we would output mul or add instructions
7778 and then return a pseudo reg containing the sum.
7780 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7781 it also marks a label as absolutely required (it can't be dead).
7782 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7783 This is used for outputting expressions used in initializers.
7785 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7786 with a constant address even if that address is not normally legitimate.
7787 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7789 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7790 a call parameter. Such targets require special care as we haven't yet
7791 marked TARGET so that it's safe from being trashed by libcalls. We
7792 don't want to use TARGET for anything but the final result;
7793 Intermediate values must go elsewhere. Additionally, calls to
7794 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7796 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7797 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7798 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7799 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7800 recursively. */
7803 expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
7804 enum expand_modifier modifier, rtx *alt_rtl)
7806 rtx ret;
7808 /* Handle ERROR_MARK before anybody tries to access its type. */
7809 if (TREE_CODE (exp) == ERROR_MARK
7810 || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
7812 ret = CONST0_RTX (tmode);
7813 return ret ? ret : const0_rtx;
7816 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
7817 return ret;
7820 /* Try to expand the conditional expression which is represented by
7821 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7822 return the rtl reg which repsents the result. Otherwise return
7823 NULL_RTL. */
7825 static rtx
7826 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
7827 tree treeop1 ATTRIBUTE_UNUSED,
7828 tree treeop2 ATTRIBUTE_UNUSED)
7830 #ifdef HAVE_conditional_move
7831 rtx insn;
7832 rtx op00, op01, op1, op2;
7833 enum rtx_code comparison_code;
7834 enum machine_mode comparison_mode;
7835 gimple srcstmt;
7836 rtx temp;
7837 tree type = TREE_TYPE (treeop1);
7838 int unsignedp = TYPE_UNSIGNED (type);
7839 enum machine_mode mode = TYPE_MODE (type);
7841 /* If we cannot do a conditional move on the mode, try doing it
7842 with the promoted mode. */
7843 if (!can_conditionally_move_p (mode))
7845 mode = promote_mode (type, mode, &unsignedp);
7846 if (!can_conditionally_move_p (mode))
7847 return NULL_RTX;
7848 temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */
7850 else
7851 temp = assign_temp (type, 0, 1);
7853 start_sequence ();
7854 expand_operands (treeop1, treeop2,
7855 temp, &op1, &op2, EXPAND_NORMAL);
7857 if (TREE_CODE (treeop0) == SSA_NAME
7858 && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison)))
7860 tree type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
7861 enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
7862 op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
7863 op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
7864 comparison_mode = TYPE_MODE (type);
7865 unsignedp = TYPE_UNSIGNED (type);
7866 comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
7868 else if (TREE_CODE_CLASS (TREE_CODE (treeop0)) == tcc_comparison)
7870 tree type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
7871 enum tree_code cmpcode = TREE_CODE (treeop0);
7872 op00 = expand_normal (TREE_OPERAND (treeop0, 0));
7873 op01 = expand_normal (TREE_OPERAND (treeop0, 1));
7874 unsignedp = TYPE_UNSIGNED (type);
7875 comparison_mode = TYPE_MODE (type);
7876 comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
7878 else
7880 op00 = expand_normal (treeop0);
7881 op01 = const0_rtx;
7882 comparison_code = NE;
7883 comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
7886 if (GET_MODE (op1) != mode)
7887 op1 = gen_lowpart (mode, op1);
7889 if (GET_MODE (op2) != mode)
7890 op2 = gen_lowpart (mode, op2);
7892 /* Try to emit the conditional move. */
7893 insn = emit_conditional_move (temp, comparison_code,
7894 op00, op01, comparison_mode,
7895 op1, op2, mode,
7896 unsignedp);
7898 /* If we could do the conditional move, emit the sequence,
7899 and return. */
7900 if (insn)
7902 rtx seq = get_insns ();
7903 end_sequence ();
7904 emit_insn (seq);
7905 return temp;
7908 /* Otherwise discard the sequence and fall back to code with
7909 branches. */
7910 end_sequence ();
7911 #endif
7912 return NULL_RTX;
7916 expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
7917 enum expand_modifier modifier)
7919 rtx op0, op1, op2, temp;
7920 tree type;
7921 int unsignedp;
7922 enum machine_mode mode;
7923 enum tree_code code = ops->code;
7924 optab this_optab;
7925 rtx subtarget, original_target;
7926 int ignore;
7927 bool reduce_bit_field;
7928 location_t loc = ops->location;
7929 tree treeop0, treeop1, treeop2;
7930 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
7931 ? reduce_to_bit_field_precision ((expr), \
7932 target, \
7933 type) \
7934 : (expr))
7936 type = ops->type;
7937 mode = TYPE_MODE (type);
7938 unsignedp = TYPE_UNSIGNED (type);
7940 treeop0 = ops->op0;
7941 treeop1 = ops->op1;
7942 treeop2 = ops->op2;
7944 /* We should be called only on simple (binary or unary) expressions,
7945 exactly those that are valid in gimple expressions that aren't
7946 GIMPLE_SINGLE_RHS (or invalid). */
7947 gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
7948 || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
7949 || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
7951 ignore = (target == const0_rtx
7952 || ((CONVERT_EXPR_CODE_P (code)
7953 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
7954 && TREE_CODE (type) == VOID_TYPE));
7956 /* We should be called only if we need the result. */
7957 gcc_assert (!ignore);
7959 /* An operation in what may be a bit-field type needs the
7960 result to be reduced to the precision of the bit-field type,
7961 which is narrower than that of the type's mode. */
7962 reduce_bit_field = (INTEGRAL_TYPE_P (type)
7963 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
7965 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
7966 target = 0;
7968 /* Use subtarget as the target for operand 0 of a binary operation. */
7969 subtarget = get_subtarget (target);
7970 original_target = target;
7972 switch (code)
7974 case NON_LVALUE_EXPR:
7975 case PAREN_EXPR:
7976 CASE_CONVERT:
7977 if (treeop0 == error_mark_node)
7978 return const0_rtx;
7980 if (TREE_CODE (type) == UNION_TYPE)
7982 tree valtype = TREE_TYPE (treeop0);
7984 /* If both input and output are BLKmode, this conversion isn't doing
7985 anything except possibly changing memory attribute. */
7986 if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
7988 rtx result = expand_expr (treeop0, target, tmode,
7989 modifier);
7991 result = copy_rtx (result);
7992 set_mem_attributes (result, type, 0);
7993 return result;
7996 if (target == 0)
7998 if (TYPE_MODE (type) != BLKmode)
7999 target = gen_reg_rtx (TYPE_MODE (type));
8000 else
8001 target = assign_temp (type, 1, 1);
8004 if (MEM_P (target))
8005 /* Store data into beginning of memory target. */
8006 store_expr (treeop0,
8007 adjust_address (target, TYPE_MODE (valtype), 0),
8008 modifier == EXPAND_STACK_PARM,
8009 false);
8011 else
8013 gcc_assert (REG_P (target));
8015 /* Store this field into a union of the proper type. */
8016 store_field (target,
8017 MIN ((int_size_in_bytes (TREE_TYPE
8018 (treeop0))
8019 * BITS_PER_UNIT),
8020 (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
8021 0, 0, 0, TYPE_MODE (valtype), treeop0, 0, false);
8024 /* Return the entire union. */
8025 return target;
8028 if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
8030 op0 = expand_expr (treeop0, target, VOIDmode,
8031 modifier);
8033 /* If the signedness of the conversion differs and OP0 is
8034 a promoted SUBREG, clear that indication since we now
8035 have to do the proper extension. */
8036 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)) != unsignedp
8037 && GET_CODE (op0) == SUBREG)
8038 SUBREG_PROMOTED_VAR_P (op0) = 0;
8040 return REDUCE_BIT_FIELD (op0);
8043 op0 = expand_expr (treeop0, NULL_RTX, mode,
8044 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
8045 if (GET_MODE (op0) == mode)
8048 /* If OP0 is a constant, just convert it into the proper mode. */
8049 else if (CONSTANT_P (op0))
8051 tree inner_type = TREE_TYPE (treeop0);
8052 enum machine_mode inner_mode = GET_MODE (op0);
8054 if (inner_mode == VOIDmode)
8055 inner_mode = TYPE_MODE (inner_type);
8057 if (modifier == EXPAND_INITIALIZER)
8058 op0 = simplify_gen_subreg (mode, op0, inner_mode,
8059 subreg_lowpart_offset (mode,
8060 inner_mode));
8061 else
8062 op0= convert_modes (mode, inner_mode, op0,
8063 TYPE_UNSIGNED (inner_type));
8066 else if (modifier == EXPAND_INITIALIZER)
8067 op0 = gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
8069 else if (target == 0)
8070 op0 = convert_to_mode (mode, op0,
8071 TYPE_UNSIGNED (TREE_TYPE
8072 (treeop0)));
8073 else
8075 convert_move (target, op0,
8076 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8077 op0 = target;
8080 return REDUCE_BIT_FIELD (op0);
8082 case ADDR_SPACE_CONVERT_EXPR:
8084 tree treeop0_type = TREE_TYPE (treeop0);
8085 addr_space_t as_to;
8086 addr_space_t as_from;
8088 gcc_assert (POINTER_TYPE_P (type));
8089 gcc_assert (POINTER_TYPE_P (treeop0_type));
8091 as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
8092 as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
8094 /* Conversions between pointers to the same address space should
8095 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8096 gcc_assert (as_to != as_from);
8098 /* Ask target code to handle conversion between pointers
8099 to overlapping address spaces. */
8100 if (targetm.addr_space.subset_p (as_to, as_from)
8101 || targetm.addr_space.subset_p (as_from, as_to))
8103 op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
8104 op0 = targetm.addr_space.convert (op0, treeop0_type, type);
8105 gcc_assert (op0);
8106 return op0;
8109 /* For disjoint address spaces, converting anything but
8110 a null pointer invokes undefined behaviour. We simply
8111 always return a null pointer here. */
8112 return CONST0_RTX (mode);
8115 case POINTER_PLUS_EXPR:
8116 /* Even though the sizetype mode and the pointer's mode can be different
8117 expand is able to handle this correctly and get the correct result out
8118 of the PLUS_EXPR code. */
8119 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8120 if sizetype precision is smaller than pointer precision. */
8121 if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
8122 treeop1 = fold_convert_loc (loc, type,
8123 fold_convert_loc (loc, ssizetype,
8124 treeop1));
8125 /* If sizetype precision is larger than pointer precision, truncate the
8126 offset to have matching modes. */
8127 else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
8128 treeop1 = fold_convert_loc (loc, type, treeop1);
8130 case PLUS_EXPR:
8131 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8132 something else, make sure we add the register to the constant and
8133 then to the other thing. This case can occur during strength
8134 reduction and doing it this way will produce better code if the
8135 frame pointer or argument pointer is eliminated.
8137 fold-const.c will ensure that the constant is always in the inner
8138 PLUS_EXPR, so the only case we need to do anything about is if
8139 sp, ap, or fp is our second argument, in which case we must swap
8140 the innermost first argument and our second argument. */
8142 if (TREE_CODE (treeop0) == PLUS_EXPR
8143 && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
8144 && TREE_CODE (treeop1) == VAR_DECL
8145 && (DECL_RTL (treeop1) == frame_pointer_rtx
8146 || DECL_RTL (treeop1) == stack_pointer_rtx
8147 || DECL_RTL (treeop1) == arg_pointer_rtx))
8149 gcc_unreachable ();
8152 /* If the result is to be ptr_mode and we are adding an integer to
8153 something, we might be forming a constant. So try to use
8154 plus_constant. If it produces a sum and we can't accept it,
8155 use force_operand. This allows P = &ARR[const] to generate
8156 efficient code on machines where a SYMBOL_REF is not a valid
8157 address.
8159 If this is an EXPAND_SUM call, always return the sum. */
8160 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
8161 || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
8163 if (modifier == EXPAND_STACK_PARM)
8164 target = 0;
8165 if (TREE_CODE (treeop0) == INTEGER_CST
8166 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8167 && TREE_CONSTANT (treeop1))
8169 rtx constant_part;
8171 op1 = expand_expr (treeop1, subtarget, VOIDmode,
8172 EXPAND_SUM);
8173 /* Use immed_double_const to ensure that the constant is
8174 truncated according to the mode of OP1, then sign extended
8175 to a HOST_WIDE_INT. Using the constant directly can result
8176 in non-canonical RTL in a 64x32 cross compile. */
8177 constant_part
8178 = immed_double_const (TREE_INT_CST_LOW (treeop0),
8179 (HOST_WIDE_INT) 0,
8180 TYPE_MODE (TREE_TYPE (treeop1)));
8181 op1 = plus_constant (mode, op1, INTVAL (constant_part));
8182 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8183 op1 = force_operand (op1, target);
8184 return REDUCE_BIT_FIELD (op1);
8187 else if (TREE_CODE (treeop1) == INTEGER_CST
8188 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8189 && TREE_CONSTANT (treeop0))
8191 rtx constant_part;
8193 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8194 (modifier == EXPAND_INITIALIZER
8195 ? EXPAND_INITIALIZER : EXPAND_SUM));
8196 if (! CONSTANT_P (op0))
8198 op1 = expand_expr (treeop1, NULL_RTX,
8199 VOIDmode, modifier);
8200 /* Return a PLUS if modifier says it's OK. */
8201 if (modifier == EXPAND_SUM
8202 || modifier == EXPAND_INITIALIZER)
8203 return simplify_gen_binary (PLUS, mode, op0, op1);
8204 goto binop2;
8206 /* Use immed_double_const to ensure that the constant is
8207 truncated according to the mode of OP1, then sign extended
8208 to a HOST_WIDE_INT. Using the constant directly can result
8209 in non-canonical RTL in a 64x32 cross compile. */
8210 constant_part
8211 = immed_double_const (TREE_INT_CST_LOW (treeop1),
8212 (HOST_WIDE_INT) 0,
8213 TYPE_MODE (TREE_TYPE (treeop0)));
8214 op0 = plus_constant (mode, op0, INTVAL (constant_part));
8215 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8216 op0 = force_operand (op0, target);
8217 return REDUCE_BIT_FIELD (op0);
8221 /* Use TER to expand pointer addition of a negated value
8222 as pointer subtraction. */
8223 if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
8224 || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
8225 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
8226 && TREE_CODE (treeop1) == SSA_NAME
8227 && TYPE_MODE (TREE_TYPE (treeop0))
8228 == TYPE_MODE (TREE_TYPE (treeop1)))
8230 gimple def = get_def_for_expr (treeop1, NEGATE_EXPR);
8231 if (def)
8233 treeop1 = gimple_assign_rhs1 (def);
8234 code = MINUS_EXPR;
8235 goto do_minus;
8239 /* No sense saving up arithmetic to be done
8240 if it's all in the wrong mode to form part of an address.
8241 And force_operand won't know whether to sign-extend or
8242 zero-extend. */
8243 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8244 || mode != ptr_mode)
8246 expand_operands (treeop0, treeop1,
8247 subtarget, &op0, &op1, EXPAND_NORMAL);
8248 if (op0 == const0_rtx)
8249 return op1;
8250 if (op1 == const0_rtx)
8251 return op0;
8252 goto binop2;
8255 expand_operands (treeop0, treeop1,
8256 subtarget, &op0, &op1, modifier);
8257 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8259 case MINUS_EXPR:
8260 do_minus:
8261 /* For initializers, we are allowed to return a MINUS of two
8262 symbolic constants. Here we handle all cases when both operands
8263 are constant. */
8264 /* Handle difference of two symbolic constants,
8265 for the sake of an initializer. */
8266 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8267 && really_constant_p (treeop0)
8268 && really_constant_p (treeop1))
8270 expand_operands (treeop0, treeop1,
8271 NULL_RTX, &op0, &op1, modifier);
8273 /* If the last operand is a CONST_INT, use plus_constant of
8274 the negated constant. Else make the MINUS. */
8275 if (CONST_INT_P (op1))
8276 return REDUCE_BIT_FIELD (plus_constant (mode, op0,
8277 -INTVAL (op1)));
8278 else
8279 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode, op0, op1));
8282 /* No sense saving up arithmetic to be done
8283 if it's all in the wrong mode to form part of an address.
8284 And force_operand won't know whether to sign-extend or
8285 zero-extend. */
8286 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8287 || mode != ptr_mode)
8288 goto binop;
8290 expand_operands (treeop0, treeop1,
8291 subtarget, &op0, &op1, modifier);
8293 /* Convert A - const to A + (-const). */
8294 if (CONST_INT_P (op1))
8296 op1 = negate_rtx (mode, op1);
8297 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8300 goto binop2;
8302 case WIDEN_MULT_PLUS_EXPR:
8303 case WIDEN_MULT_MINUS_EXPR:
8304 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8305 op2 = expand_normal (treeop2);
8306 target = expand_widen_pattern_expr (ops, op0, op1, op2,
8307 target, unsignedp);
8308 return target;
8310 case WIDEN_MULT_EXPR:
8311 /* If first operand is constant, swap them.
8312 Thus the following special case checks need only
8313 check the second operand. */
8314 if (TREE_CODE (treeop0) == INTEGER_CST)
8316 tree t1 = treeop0;
8317 treeop0 = treeop1;
8318 treeop1 = t1;
8321 /* First, check if we have a multiplication of one signed and one
8322 unsigned operand. */
8323 if (TREE_CODE (treeop1) != INTEGER_CST
8324 && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
8325 != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
8327 enum machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
8328 this_optab = usmul_widen_optab;
8329 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8330 != CODE_FOR_nothing)
8332 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8333 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8334 EXPAND_NORMAL);
8335 else
8336 expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
8337 EXPAND_NORMAL);
8338 goto binop3;
8341 /* Check for a multiplication with matching signedness. */
8342 else if ((TREE_CODE (treeop1) == INTEGER_CST
8343 && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
8344 || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
8345 == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
8347 tree op0type = TREE_TYPE (treeop0);
8348 enum machine_mode innermode = TYPE_MODE (op0type);
8349 bool zextend_p = TYPE_UNSIGNED (op0type);
8350 optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
8351 this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
8353 if (TREE_CODE (treeop0) != INTEGER_CST)
8355 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8356 != CODE_FOR_nothing)
8358 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8359 EXPAND_NORMAL);
8360 temp = expand_widening_mult (mode, op0, op1, target,
8361 unsignedp, this_optab);
8362 return REDUCE_BIT_FIELD (temp);
8364 if (find_widening_optab_handler (other_optab, mode, innermode, 0)
8365 != CODE_FOR_nothing
8366 && innermode == word_mode)
8368 rtx htem, hipart;
8369 op0 = expand_normal (treeop0);
8370 if (TREE_CODE (treeop1) == INTEGER_CST)
8371 op1 = convert_modes (innermode, mode,
8372 expand_normal (treeop1), unsignedp);
8373 else
8374 op1 = expand_normal (treeop1);
8375 temp = expand_binop (mode, other_optab, op0, op1, target,
8376 unsignedp, OPTAB_LIB_WIDEN);
8377 hipart = gen_highpart (innermode, temp);
8378 htem = expand_mult_highpart_adjust (innermode, hipart,
8379 op0, op1, hipart,
8380 zextend_p);
8381 if (htem != hipart)
8382 emit_move_insn (hipart, htem);
8383 return REDUCE_BIT_FIELD (temp);
8387 treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
8388 treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
8389 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8390 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8392 case FMA_EXPR:
8394 optab opt = fma_optab;
8395 gimple def0, def2;
8397 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8398 call. */
8399 if (optab_handler (fma_optab, mode) == CODE_FOR_nothing)
8401 tree fn = mathfn_built_in (TREE_TYPE (treeop0), BUILT_IN_FMA);
8402 tree call_expr;
8404 gcc_assert (fn != NULL_TREE);
8405 call_expr = build_call_expr (fn, 3, treeop0, treeop1, treeop2);
8406 return expand_builtin (call_expr, target, subtarget, mode, false);
8409 def0 = get_def_for_expr (treeop0, NEGATE_EXPR);
8410 def2 = get_def_for_expr (treeop2, NEGATE_EXPR);
8412 op0 = op2 = NULL;
8414 if (def0 && def2
8415 && optab_handler (fnms_optab, mode) != CODE_FOR_nothing)
8417 opt = fnms_optab;
8418 op0 = expand_normal (gimple_assign_rhs1 (def0));
8419 op2 = expand_normal (gimple_assign_rhs1 (def2));
8421 else if (def0
8422 && optab_handler (fnma_optab, mode) != CODE_FOR_nothing)
8424 opt = fnma_optab;
8425 op0 = expand_normal (gimple_assign_rhs1 (def0));
8427 else if (def2
8428 && optab_handler (fms_optab, mode) != CODE_FOR_nothing)
8430 opt = fms_optab;
8431 op2 = expand_normal (gimple_assign_rhs1 (def2));
8434 if (op0 == NULL)
8435 op0 = expand_expr (treeop0, subtarget, VOIDmode, EXPAND_NORMAL);
8436 if (op2 == NULL)
8437 op2 = expand_normal (treeop2);
8438 op1 = expand_normal (treeop1);
8440 return expand_ternary_op (TYPE_MODE (type), opt,
8441 op0, op1, op2, target, 0);
8444 case MULT_EXPR:
8445 /* If this is a fixed-point operation, then we cannot use the code
8446 below because "expand_mult" doesn't support sat/no-sat fixed-point
8447 multiplications. */
8448 if (ALL_FIXED_POINT_MODE_P (mode))
8449 goto binop;
8451 /* If first operand is constant, swap them.
8452 Thus the following special case checks need only
8453 check the second operand. */
8454 if (TREE_CODE (treeop0) == INTEGER_CST)
8456 tree t1 = treeop0;
8457 treeop0 = treeop1;
8458 treeop1 = t1;
8461 /* Attempt to return something suitable for generating an
8462 indexed address, for machines that support that. */
8464 if (modifier == EXPAND_SUM && mode == ptr_mode
8465 && host_integerp (treeop1, 0))
8467 tree exp1 = treeop1;
8469 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8470 EXPAND_SUM);
8472 if (!REG_P (op0))
8473 op0 = force_operand (op0, NULL_RTX);
8474 if (!REG_P (op0))
8475 op0 = copy_to_mode_reg (mode, op0);
8477 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0,
8478 gen_int_mode (tree_low_cst (exp1, 0),
8479 TYPE_MODE (TREE_TYPE (exp1)))));
8482 if (modifier == EXPAND_STACK_PARM)
8483 target = 0;
8485 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8486 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8488 case TRUNC_DIV_EXPR:
8489 case FLOOR_DIV_EXPR:
8490 case CEIL_DIV_EXPR:
8491 case ROUND_DIV_EXPR:
8492 case EXACT_DIV_EXPR:
8493 /* If this is a fixed-point operation, then we cannot use the code
8494 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8495 divisions. */
8496 if (ALL_FIXED_POINT_MODE_P (mode))
8497 goto binop;
8499 if (modifier == EXPAND_STACK_PARM)
8500 target = 0;
8501 /* Possible optimization: compute the dividend with EXPAND_SUM
8502 then if the divisor is constant can optimize the case
8503 where some terms of the dividend have coeffs divisible by it. */
8504 expand_operands (treeop0, treeop1,
8505 subtarget, &op0, &op1, EXPAND_NORMAL);
8506 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
8508 case RDIV_EXPR:
8509 goto binop;
8511 case MULT_HIGHPART_EXPR:
8512 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8513 temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
8514 gcc_assert (temp);
8515 return temp;
8517 case TRUNC_MOD_EXPR:
8518 case FLOOR_MOD_EXPR:
8519 case CEIL_MOD_EXPR:
8520 case ROUND_MOD_EXPR:
8521 if (modifier == EXPAND_STACK_PARM)
8522 target = 0;
8523 expand_operands (treeop0, treeop1,
8524 subtarget, &op0, &op1, EXPAND_NORMAL);
8525 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
8527 case FIXED_CONVERT_EXPR:
8528 op0 = expand_normal (treeop0);
8529 if (target == 0 || modifier == EXPAND_STACK_PARM)
8530 target = gen_reg_rtx (mode);
8532 if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
8533 && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8534 || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
8535 expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
8536 else
8537 expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
8538 return target;
8540 case FIX_TRUNC_EXPR:
8541 op0 = expand_normal (treeop0);
8542 if (target == 0 || modifier == EXPAND_STACK_PARM)
8543 target = gen_reg_rtx (mode);
8544 expand_fix (target, op0, unsignedp);
8545 return target;
8547 case FLOAT_EXPR:
8548 op0 = expand_normal (treeop0);
8549 if (target == 0 || modifier == EXPAND_STACK_PARM)
8550 target = gen_reg_rtx (mode);
8551 /* expand_float can't figure out what to do if FROM has VOIDmode.
8552 So give it the correct mode. With -O, cse will optimize this. */
8553 if (GET_MODE (op0) == VOIDmode)
8554 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
8555 op0);
8556 expand_float (target, op0,
8557 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8558 return target;
8560 case NEGATE_EXPR:
8561 op0 = expand_expr (treeop0, subtarget,
8562 VOIDmode, EXPAND_NORMAL);
8563 if (modifier == EXPAND_STACK_PARM)
8564 target = 0;
8565 temp = expand_unop (mode,
8566 optab_for_tree_code (NEGATE_EXPR, type,
8567 optab_default),
8568 op0, target, 0);
8569 gcc_assert (temp);
8570 return REDUCE_BIT_FIELD (temp);
8572 case ABS_EXPR:
8573 op0 = expand_expr (treeop0, subtarget,
8574 VOIDmode, EXPAND_NORMAL);
8575 if (modifier == EXPAND_STACK_PARM)
8576 target = 0;
8578 /* ABS_EXPR is not valid for complex arguments. */
8579 gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8580 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
8582 /* Unsigned abs is simply the operand. Testing here means we don't
8583 risk generating incorrect code below. */
8584 if (TYPE_UNSIGNED (type))
8585 return op0;
8587 return expand_abs (mode, op0, target, unsignedp,
8588 safe_from_p (target, treeop0, 1));
8590 case MAX_EXPR:
8591 case MIN_EXPR:
8592 target = original_target;
8593 if (target == 0
8594 || modifier == EXPAND_STACK_PARM
8595 || (MEM_P (target) && MEM_VOLATILE_P (target))
8596 || GET_MODE (target) != mode
8597 || (REG_P (target)
8598 && REGNO (target) < FIRST_PSEUDO_REGISTER))
8599 target = gen_reg_rtx (mode);
8600 expand_operands (treeop0, treeop1,
8601 target, &op0, &op1, EXPAND_NORMAL);
8603 /* First try to do it with a special MIN or MAX instruction.
8604 If that does not win, use a conditional jump to select the proper
8605 value. */
8606 this_optab = optab_for_tree_code (code, type, optab_default);
8607 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8608 OPTAB_WIDEN);
8609 if (temp != 0)
8610 return temp;
8612 /* At this point, a MEM target is no longer useful; we will get better
8613 code without it. */
8615 if (! REG_P (target))
8616 target = gen_reg_rtx (mode);
8618 /* If op1 was placed in target, swap op0 and op1. */
8619 if (target != op0 && target == op1)
8621 temp = op0;
8622 op0 = op1;
8623 op1 = temp;
8626 /* We generate better code and avoid problems with op1 mentioning
8627 target by forcing op1 into a pseudo if it isn't a constant. */
8628 if (! CONSTANT_P (op1))
8629 op1 = force_reg (mode, op1);
8632 enum rtx_code comparison_code;
8633 rtx cmpop1 = op1;
8635 if (code == MAX_EXPR)
8636 comparison_code = unsignedp ? GEU : GE;
8637 else
8638 comparison_code = unsignedp ? LEU : LE;
8640 /* Canonicalize to comparisons against 0. */
8641 if (op1 == const1_rtx)
8643 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8644 or (a != 0 ? a : 1) for unsigned.
8645 For MIN we are safe converting (a <= 1 ? a : 1)
8646 into (a <= 0 ? a : 1) */
8647 cmpop1 = const0_rtx;
8648 if (code == MAX_EXPR)
8649 comparison_code = unsignedp ? NE : GT;
8651 if (op1 == constm1_rtx && !unsignedp)
8653 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8654 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8655 cmpop1 = const0_rtx;
8656 if (code == MIN_EXPR)
8657 comparison_code = LT;
8659 #ifdef HAVE_conditional_move
8660 /* Use a conditional move if possible. */
8661 if (can_conditionally_move_p (mode))
8663 rtx insn;
8665 /* ??? Same problem as in expmed.c: emit_conditional_move
8666 forces a stack adjustment via compare_from_rtx, and we
8667 lose the stack adjustment if the sequence we are about
8668 to create is discarded. */
8669 do_pending_stack_adjust ();
8671 start_sequence ();
8673 /* Try to emit the conditional move. */
8674 insn = emit_conditional_move (target, comparison_code,
8675 op0, cmpop1, mode,
8676 op0, op1, mode,
8677 unsignedp);
8679 /* If we could do the conditional move, emit the sequence,
8680 and return. */
8681 if (insn)
8683 rtx seq = get_insns ();
8684 end_sequence ();
8685 emit_insn (seq);
8686 return target;
8689 /* Otherwise discard the sequence and fall back to code with
8690 branches. */
8691 end_sequence ();
8693 #endif
8694 if (target != op0)
8695 emit_move_insn (target, op0);
8697 temp = gen_label_rtx ();
8698 do_compare_rtx_and_jump (target, cmpop1, comparison_code,
8699 unsignedp, mode, NULL_RTX, NULL_RTX, temp,
8700 -1);
8702 emit_move_insn (target, op1);
8703 emit_label (temp);
8704 return target;
8706 case BIT_NOT_EXPR:
8707 op0 = expand_expr (treeop0, subtarget,
8708 VOIDmode, EXPAND_NORMAL);
8709 if (modifier == EXPAND_STACK_PARM)
8710 target = 0;
8711 /* In case we have to reduce the result to bitfield precision
8712 for unsigned bitfield expand this as XOR with a proper constant
8713 instead. */
8714 if (reduce_bit_field && TYPE_UNSIGNED (type))
8715 temp = expand_binop (mode, xor_optab, op0,
8716 immed_double_int_const
8717 (double_int::mask (TYPE_PRECISION (type)), mode),
8718 target, 1, OPTAB_LIB_WIDEN);
8719 else
8720 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
8721 gcc_assert (temp);
8722 return temp;
8724 /* ??? Can optimize bitwise operations with one arg constant.
8725 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8726 and (a bitwise1 b) bitwise2 b (etc)
8727 but that is probably not worth while. */
8729 case BIT_AND_EXPR:
8730 case BIT_IOR_EXPR:
8731 case BIT_XOR_EXPR:
8732 goto binop;
8734 case LROTATE_EXPR:
8735 case RROTATE_EXPR:
8736 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
8737 || (GET_MODE_PRECISION (TYPE_MODE (type))
8738 == TYPE_PRECISION (type)));
8739 /* fall through */
8741 case LSHIFT_EXPR:
8742 case RSHIFT_EXPR:
8743 /* If this is a fixed-point operation, then we cannot use the code
8744 below because "expand_shift" doesn't support sat/no-sat fixed-point
8745 shifts. */
8746 if (ALL_FIXED_POINT_MODE_P (mode))
8747 goto binop;
8749 if (! safe_from_p (subtarget, treeop1, 1))
8750 subtarget = 0;
8751 if (modifier == EXPAND_STACK_PARM)
8752 target = 0;
8753 op0 = expand_expr (treeop0, subtarget,
8754 VOIDmode, EXPAND_NORMAL);
8755 temp = expand_variable_shift (code, mode, op0, treeop1, target,
8756 unsignedp);
8757 if (code == LSHIFT_EXPR)
8758 temp = REDUCE_BIT_FIELD (temp);
8759 return temp;
8761 /* Could determine the answer when only additive constants differ. Also,
8762 the addition of one can be handled by changing the condition. */
8763 case LT_EXPR:
8764 case LE_EXPR:
8765 case GT_EXPR:
8766 case GE_EXPR:
8767 case EQ_EXPR:
8768 case NE_EXPR:
8769 case UNORDERED_EXPR:
8770 case ORDERED_EXPR:
8771 case UNLT_EXPR:
8772 case UNLE_EXPR:
8773 case UNGT_EXPR:
8774 case UNGE_EXPR:
8775 case UNEQ_EXPR:
8776 case LTGT_EXPR:
8777 temp = do_store_flag (ops,
8778 modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
8779 tmode != VOIDmode ? tmode : mode);
8780 if (temp)
8781 return temp;
8783 /* Use a compare and a jump for BLKmode comparisons, or for function
8784 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8786 if ((target == 0
8787 || modifier == EXPAND_STACK_PARM
8788 || ! safe_from_p (target, treeop0, 1)
8789 || ! safe_from_p (target, treeop1, 1)
8790 /* Make sure we don't have a hard reg (such as function's return
8791 value) live across basic blocks, if not optimizing. */
8792 || (!optimize && REG_P (target)
8793 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
8794 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
8796 emit_move_insn (target, const0_rtx);
8798 op1 = gen_label_rtx ();
8799 jumpifnot_1 (code, treeop0, treeop1, op1, -1);
8801 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
8802 emit_move_insn (target, constm1_rtx);
8803 else
8804 emit_move_insn (target, const1_rtx);
8806 emit_label (op1);
8807 return target;
8809 case COMPLEX_EXPR:
8810 /* Get the rtx code of the operands. */
8811 op0 = expand_normal (treeop0);
8812 op1 = expand_normal (treeop1);
8814 if (!target)
8815 target = gen_reg_rtx (TYPE_MODE (type));
8817 /* Move the real (op0) and imaginary (op1) parts to their location. */
8818 write_complex_part (target, op0, false);
8819 write_complex_part (target, op1, true);
8821 return target;
8823 case WIDEN_SUM_EXPR:
8825 tree oprnd0 = treeop0;
8826 tree oprnd1 = treeop1;
8828 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8829 target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
8830 target, unsignedp);
8831 return target;
8834 case REDUC_MAX_EXPR:
8835 case REDUC_MIN_EXPR:
8836 case REDUC_PLUS_EXPR:
8838 op0 = expand_normal (treeop0);
8839 this_optab = optab_for_tree_code (code, type, optab_default);
8840 temp = expand_unop (mode, this_optab, op0, target, unsignedp);
8841 gcc_assert (temp);
8842 return temp;
8845 case VEC_LSHIFT_EXPR:
8846 case VEC_RSHIFT_EXPR:
8848 target = expand_vec_shift_expr (ops, target);
8849 return target;
8852 case VEC_UNPACK_HI_EXPR:
8853 case VEC_UNPACK_LO_EXPR:
8855 op0 = expand_normal (treeop0);
8856 temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
8857 target, unsignedp);
8858 gcc_assert (temp);
8859 return temp;
8862 case VEC_UNPACK_FLOAT_HI_EXPR:
8863 case VEC_UNPACK_FLOAT_LO_EXPR:
8865 op0 = expand_normal (treeop0);
8866 /* The signedness is determined from input operand. */
8867 temp = expand_widen_pattern_expr
8868 (ops, op0, NULL_RTX, NULL_RTX,
8869 target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8871 gcc_assert (temp);
8872 return temp;
8875 case VEC_WIDEN_MULT_HI_EXPR:
8876 case VEC_WIDEN_MULT_LO_EXPR:
8877 case VEC_WIDEN_MULT_EVEN_EXPR:
8878 case VEC_WIDEN_MULT_ODD_EXPR:
8879 case VEC_WIDEN_LSHIFT_HI_EXPR:
8880 case VEC_WIDEN_LSHIFT_LO_EXPR:
8881 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8882 target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
8883 target, unsignedp);
8884 gcc_assert (target);
8885 return target;
8887 case VEC_PACK_TRUNC_EXPR:
8888 case VEC_PACK_SAT_EXPR:
8889 case VEC_PACK_FIX_TRUNC_EXPR:
8890 mode = TYPE_MODE (TREE_TYPE (treeop0));
8891 goto binop;
8893 case VEC_PERM_EXPR:
8894 expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
8895 op2 = expand_normal (treeop2);
8897 /* Careful here: if the target doesn't support integral vector modes,
8898 a constant selection vector could wind up smooshed into a normal
8899 integral constant. */
8900 if (CONSTANT_P (op2) && GET_CODE (op2) != CONST_VECTOR)
8902 tree sel_type = TREE_TYPE (treeop2);
8903 enum machine_mode vmode
8904 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type)),
8905 TYPE_VECTOR_SUBPARTS (sel_type));
8906 gcc_assert (GET_MODE_CLASS (vmode) == MODE_VECTOR_INT);
8907 op2 = simplify_subreg (vmode, op2, TYPE_MODE (sel_type), 0);
8908 gcc_assert (op2 && GET_CODE (op2) == CONST_VECTOR);
8910 else
8911 gcc_assert (GET_MODE_CLASS (GET_MODE (op2)) == MODE_VECTOR_INT);
8913 temp = expand_vec_perm (mode, op0, op1, op2, target);
8914 gcc_assert (temp);
8915 return temp;
8917 case DOT_PROD_EXPR:
8919 tree oprnd0 = treeop0;
8920 tree oprnd1 = treeop1;
8921 tree oprnd2 = treeop2;
8922 rtx op2;
8924 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8925 op2 = expand_normal (oprnd2);
8926 target = expand_widen_pattern_expr (ops, op0, op1, op2,
8927 target, unsignedp);
8928 return target;
8931 case REALIGN_LOAD_EXPR:
8933 tree oprnd0 = treeop0;
8934 tree oprnd1 = treeop1;
8935 tree oprnd2 = treeop2;
8936 rtx op2;
8938 this_optab = optab_for_tree_code (code, type, optab_default);
8939 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8940 op2 = expand_normal (oprnd2);
8941 temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
8942 target, unsignedp);
8943 gcc_assert (temp);
8944 return temp;
8947 case COND_EXPR:
8948 /* A COND_EXPR with its type being VOID_TYPE represents a
8949 conditional jump and is handled in
8950 expand_gimple_cond_expr. */
8951 gcc_assert (!VOID_TYPE_P (type));
8953 /* Note that COND_EXPRs whose type is a structure or union
8954 are required to be constructed to contain assignments of
8955 a temporary variable, so that we can evaluate them here
8956 for side effect only. If type is void, we must do likewise. */
8958 gcc_assert (!TREE_ADDRESSABLE (type)
8959 && !ignore
8960 && TREE_TYPE (treeop1) != void_type_node
8961 && TREE_TYPE (treeop2) != void_type_node);
8963 temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
8964 if (temp)
8965 return temp;
8967 /* If we are not to produce a result, we have no target. Otherwise,
8968 if a target was specified use it; it will not be used as an
8969 intermediate target unless it is safe. If no target, use a
8970 temporary. */
8972 if (modifier != EXPAND_STACK_PARM
8973 && original_target
8974 && safe_from_p (original_target, treeop0, 1)
8975 && GET_MODE (original_target) == mode
8976 && !MEM_P (original_target))
8977 temp = original_target;
8978 else
8979 temp = assign_temp (type, 0, 1);
8981 do_pending_stack_adjust ();
8982 NO_DEFER_POP;
8983 op0 = gen_label_rtx ();
8984 op1 = gen_label_rtx ();
8985 jumpifnot (treeop0, op0, -1);
8986 store_expr (treeop1, temp,
8987 modifier == EXPAND_STACK_PARM,
8988 false);
8990 emit_jump_insn (gen_jump (op1));
8991 emit_barrier ();
8992 emit_label (op0);
8993 store_expr (treeop2, temp,
8994 modifier == EXPAND_STACK_PARM,
8995 false);
8997 emit_label (op1);
8998 OK_DEFER_POP;
8999 return temp;
9001 case VEC_COND_EXPR:
9002 target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target);
9003 return target;
9005 default:
9006 gcc_unreachable ();
9009 /* Here to do an ordinary binary operator. */
9010 binop:
9011 expand_operands (treeop0, treeop1,
9012 subtarget, &op0, &op1, EXPAND_NORMAL);
9013 binop2:
9014 this_optab = optab_for_tree_code (code, type, optab_default);
9015 binop3:
9016 if (modifier == EXPAND_STACK_PARM)
9017 target = 0;
9018 temp = expand_binop (mode, this_optab, op0, op1, target,
9019 unsignedp, OPTAB_LIB_WIDEN);
9020 gcc_assert (temp);
9021 /* Bitwise operations do not need bitfield reduction as we expect their
9022 operands being properly truncated. */
9023 if (code == BIT_XOR_EXPR
9024 || code == BIT_AND_EXPR
9025 || code == BIT_IOR_EXPR)
9026 return temp;
9027 return REDUCE_BIT_FIELD (temp);
9029 #undef REDUCE_BIT_FIELD
9032 expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
9033 enum expand_modifier modifier, rtx *alt_rtl)
9035 rtx op0, op1, temp, decl_rtl;
9036 tree type;
9037 int unsignedp;
9038 enum machine_mode mode;
9039 enum tree_code code = TREE_CODE (exp);
9040 rtx subtarget, original_target;
9041 int ignore;
9042 tree context;
9043 bool reduce_bit_field;
9044 location_t loc = EXPR_LOCATION (exp);
9045 struct separate_ops ops;
9046 tree treeop0, treeop1, treeop2;
9047 tree ssa_name = NULL_TREE;
9048 gimple g;
9050 type = TREE_TYPE (exp);
9051 mode = TYPE_MODE (type);
9052 unsignedp = TYPE_UNSIGNED (type);
9054 treeop0 = treeop1 = treeop2 = NULL_TREE;
9055 if (!VL_EXP_CLASS_P (exp))
9056 switch (TREE_CODE_LENGTH (code))
9058 default:
9059 case 3: treeop2 = TREE_OPERAND (exp, 2);
9060 case 2: treeop1 = TREE_OPERAND (exp, 1);
9061 case 1: treeop0 = TREE_OPERAND (exp, 0);
9062 case 0: break;
9064 ops.code = code;
9065 ops.type = type;
9066 ops.op0 = treeop0;
9067 ops.op1 = treeop1;
9068 ops.op2 = treeop2;
9069 ops.location = loc;
9071 ignore = (target == const0_rtx
9072 || ((CONVERT_EXPR_CODE_P (code)
9073 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
9074 && TREE_CODE (type) == VOID_TYPE));
9076 /* An operation in what may be a bit-field type needs the
9077 result to be reduced to the precision of the bit-field type,
9078 which is narrower than that of the type's mode. */
9079 reduce_bit_field = (!ignore
9080 && INTEGRAL_TYPE_P (type)
9081 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
9083 /* If we are going to ignore this result, we need only do something
9084 if there is a side-effect somewhere in the expression. If there
9085 is, short-circuit the most common cases here. Note that we must
9086 not call expand_expr with anything but const0_rtx in case this
9087 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9089 if (ignore)
9091 if (! TREE_SIDE_EFFECTS (exp))
9092 return const0_rtx;
9094 /* Ensure we reference a volatile object even if value is ignored, but
9095 don't do this if all we are doing is taking its address. */
9096 if (TREE_THIS_VOLATILE (exp)
9097 && TREE_CODE (exp) != FUNCTION_DECL
9098 && mode != VOIDmode && mode != BLKmode
9099 && modifier != EXPAND_CONST_ADDRESS)
9101 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
9102 if (MEM_P (temp))
9103 copy_to_reg (temp);
9104 return const0_rtx;
9107 if (TREE_CODE_CLASS (code) == tcc_unary
9108 || code == BIT_FIELD_REF
9109 || code == COMPONENT_REF
9110 || code == INDIRECT_REF)
9111 return expand_expr (treeop0, const0_rtx, VOIDmode,
9112 modifier);
9114 else if (TREE_CODE_CLASS (code) == tcc_binary
9115 || TREE_CODE_CLASS (code) == tcc_comparison
9116 || code == ARRAY_REF || code == ARRAY_RANGE_REF)
9118 expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
9119 expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
9120 return const0_rtx;
9123 target = 0;
9126 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
9127 target = 0;
9129 /* Use subtarget as the target for operand 0 of a binary operation. */
9130 subtarget = get_subtarget (target);
9131 original_target = target;
9133 switch (code)
9135 case LABEL_DECL:
9137 tree function = decl_function_context (exp);
9139 temp = label_rtx (exp);
9140 temp = gen_rtx_LABEL_REF (Pmode, temp);
9142 if (function != current_function_decl
9143 && function != 0)
9144 LABEL_REF_NONLOCAL_P (temp) = 1;
9146 temp = gen_rtx_MEM (FUNCTION_MODE, temp);
9147 return temp;
9150 case SSA_NAME:
9151 /* ??? ivopts calls expander, without any preparation from
9152 out-of-ssa. So fake instructions as if this was an access to the
9153 base variable. This unnecessarily allocates a pseudo, see how we can
9154 reuse it, if partition base vars have it set already. */
9155 if (!currently_expanding_to_rtl)
9157 tree var = SSA_NAME_VAR (exp);
9158 if (var && DECL_RTL_SET_P (var))
9159 return DECL_RTL (var);
9160 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
9161 LAST_VIRTUAL_REGISTER + 1);
9164 g = get_gimple_for_ssa_name (exp);
9165 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9166 if (g == NULL
9167 && modifier == EXPAND_INITIALIZER
9168 && !SSA_NAME_IS_DEFAULT_DEF (exp)
9169 && (optimize || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
9170 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
9171 g = SSA_NAME_DEF_STMT (exp);
9172 if (g)
9174 rtx r;
9175 location_t saved_loc = curr_insn_location ();
9177 set_curr_insn_location (gimple_location (g));
9178 r = expand_expr_real (gimple_assign_rhs_to_tree (g), target,
9179 tmode, modifier, NULL);
9180 set_curr_insn_location (saved_loc);
9181 if (REG_P (r) && !REG_EXPR (r))
9182 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp), r);
9183 return r;
9186 ssa_name = exp;
9187 decl_rtl = get_rtx_for_ssa_name (ssa_name);
9188 exp = SSA_NAME_VAR (ssa_name);
9189 goto expand_decl_rtl;
9191 case PARM_DECL:
9192 case VAR_DECL:
9193 /* If a static var's type was incomplete when the decl was written,
9194 but the type is complete now, lay out the decl now. */
9195 if (DECL_SIZE (exp) == 0
9196 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
9197 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
9198 layout_decl (exp, 0);
9200 /* ... fall through ... */
9202 case FUNCTION_DECL:
9203 case RESULT_DECL:
9204 decl_rtl = DECL_RTL (exp);
9205 expand_decl_rtl:
9206 gcc_assert (decl_rtl);
9207 decl_rtl = copy_rtx (decl_rtl);
9208 /* Record writes to register variables. */
9209 if (modifier == EXPAND_WRITE
9210 && REG_P (decl_rtl)
9211 && HARD_REGISTER_P (decl_rtl))
9212 add_to_hard_reg_set (&crtl->asm_clobbers,
9213 GET_MODE (decl_rtl), REGNO (decl_rtl));
9215 /* Ensure variable marked as used even if it doesn't go through
9216 a parser. If it hasn't be used yet, write out an external
9217 definition. */
9218 TREE_USED (exp) = 1;
9220 /* Show we haven't gotten RTL for this yet. */
9221 temp = 0;
9223 /* Variables inherited from containing functions should have
9224 been lowered by this point. */
9225 context = decl_function_context (exp);
9226 gcc_assert (!context
9227 || context == current_function_decl
9228 || TREE_STATIC (exp)
9229 || DECL_EXTERNAL (exp)
9230 /* ??? C++ creates functions that are not TREE_STATIC. */
9231 || TREE_CODE (exp) == FUNCTION_DECL);
9233 /* This is the case of an array whose size is to be determined
9234 from its initializer, while the initializer is still being parsed.
9235 ??? We aren't parsing while expanding anymore. */
9237 if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
9238 temp = validize_mem (decl_rtl);
9240 /* If DECL_RTL is memory, we are in the normal case and the
9241 address is not valid, get the address into a register. */
9243 else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
9245 if (alt_rtl)
9246 *alt_rtl = decl_rtl;
9247 decl_rtl = use_anchored_address (decl_rtl);
9248 if (modifier != EXPAND_CONST_ADDRESS
9249 && modifier != EXPAND_SUM
9250 && !memory_address_addr_space_p (DECL_MODE (exp),
9251 XEXP (decl_rtl, 0),
9252 MEM_ADDR_SPACE (decl_rtl)))
9253 temp = replace_equiv_address (decl_rtl,
9254 copy_rtx (XEXP (decl_rtl, 0)));
9257 /* If we got something, return it. But first, set the alignment
9258 if the address is a register. */
9259 if (temp != 0)
9261 if (MEM_P (temp) && REG_P (XEXP (temp, 0)))
9262 mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
9264 return temp;
9267 /* If the mode of DECL_RTL does not match that of the decl,
9268 there are two cases: we are dealing with a BLKmode value
9269 that is returned in a register, or we are dealing with
9270 a promoted value. In the latter case, return a SUBREG
9271 of the wanted mode, but mark it so that we know that it
9272 was already extended. */
9273 if (REG_P (decl_rtl)
9274 && DECL_MODE (exp) != BLKmode
9275 && GET_MODE (decl_rtl) != DECL_MODE (exp))
9277 enum machine_mode pmode;
9279 /* Get the signedness to be used for this variable. Ensure we get
9280 the same mode we got when the variable was declared. */
9281 if (code == SSA_NAME
9282 && (g = SSA_NAME_DEF_STMT (ssa_name))
9283 && gimple_code (g) == GIMPLE_CALL)
9285 gcc_assert (!gimple_call_internal_p (g));
9286 pmode = promote_function_mode (type, mode, &unsignedp,
9287 gimple_call_fntype (g),
9290 else
9291 pmode = promote_decl_mode (exp, &unsignedp);
9292 gcc_assert (GET_MODE (decl_rtl) == pmode);
9294 temp = gen_lowpart_SUBREG (mode, decl_rtl);
9295 SUBREG_PROMOTED_VAR_P (temp) = 1;
9296 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
9297 return temp;
9300 return decl_rtl;
9302 case INTEGER_CST:
9303 temp = immed_double_const (TREE_INT_CST_LOW (exp),
9304 TREE_INT_CST_HIGH (exp), mode);
9306 return temp;
9308 case VECTOR_CST:
9310 tree tmp = NULL_TREE;
9311 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
9312 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
9313 || GET_MODE_CLASS (mode) == MODE_VECTOR_FRACT
9314 || GET_MODE_CLASS (mode) == MODE_VECTOR_UFRACT
9315 || GET_MODE_CLASS (mode) == MODE_VECTOR_ACCUM
9316 || GET_MODE_CLASS (mode) == MODE_VECTOR_UACCUM)
9317 return const_vector_from_tree (exp);
9318 if (GET_MODE_CLASS (mode) == MODE_INT)
9320 tree type_for_mode = lang_hooks.types.type_for_mode (mode, 1);
9321 if (type_for_mode)
9322 tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR, type_for_mode, exp);
9324 if (!tmp)
9326 vec<constructor_elt, va_gc> *v;
9327 unsigned i;
9328 vec_alloc (v, VECTOR_CST_NELTS (exp));
9329 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
9330 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
9331 tmp = build_constructor (type, v);
9333 return expand_expr (tmp, ignore ? const0_rtx : target,
9334 tmode, modifier);
9337 case CONST_DECL:
9338 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
9340 case REAL_CST:
9341 /* If optimized, generate immediate CONST_DOUBLE
9342 which will be turned into memory by reload if necessary.
9344 We used to force a register so that loop.c could see it. But
9345 this does not allow gen_* patterns to perform optimizations with
9346 the constants. It also produces two insns in cases like "x = 1.0;".
9347 On most machines, floating-point constants are not permitted in
9348 many insns, so we'd end up copying it to a register in any case.
9350 Now, we do the copying in expand_binop, if appropriate. */
9351 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
9352 TYPE_MODE (TREE_TYPE (exp)));
9354 case FIXED_CST:
9355 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
9356 TYPE_MODE (TREE_TYPE (exp)));
9358 case COMPLEX_CST:
9359 /* Handle evaluating a complex constant in a CONCAT target. */
9360 if (original_target && GET_CODE (original_target) == CONCAT)
9362 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
9363 rtx rtarg, itarg;
9365 rtarg = XEXP (original_target, 0);
9366 itarg = XEXP (original_target, 1);
9368 /* Move the real and imaginary parts separately. */
9369 op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
9370 op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
9372 if (op0 != rtarg)
9373 emit_move_insn (rtarg, op0);
9374 if (op1 != itarg)
9375 emit_move_insn (itarg, op1);
9377 return original_target;
9380 /* ... fall through ... */
9382 case STRING_CST:
9383 temp = expand_expr_constant (exp, 1, modifier);
9385 /* temp contains a constant address.
9386 On RISC machines where a constant address isn't valid,
9387 make some insns to get that address into a register. */
9388 if (modifier != EXPAND_CONST_ADDRESS
9389 && modifier != EXPAND_INITIALIZER
9390 && modifier != EXPAND_SUM
9391 && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
9392 MEM_ADDR_SPACE (temp)))
9393 return replace_equiv_address (temp,
9394 copy_rtx (XEXP (temp, 0)));
9395 return temp;
9397 case SAVE_EXPR:
9399 tree val = treeop0;
9400 rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl);
9402 if (!SAVE_EXPR_RESOLVED_P (exp))
9404 /* We can indeed still hit this case, typically via builtin
9405 expanders calling save_expr immediately before expanding
9406 something. Assume this means that we only have to deal
9407 with non-BLKmode values. */
9408 gcc_assert (GET_MODE (ret) != BLKmode);
9410 val = build_decl (curr_insn_location (),
9411 VAR_DECL, NULL, TREE_TYPE (exp));
9412 DECL_ARTIFICIAL (val) = 1;
9413 DECL_IGNORED_P (val) = 1;
9414 treeop0 = val;
9415 TREE_OPERAND (exp, 0) = treeop0;
9416 SAVE_EXPR_RESOLVED_P (exp) = 1;
9418 if (!CONSTANT_P (ret))
9419 ret = copy_to_reg (ret);
9420 SET_DECL_RTL (val, ret);
9423 return ret;
9427 case CONSTRUCTOR:
9428 /* If we don't need the result, just ensure we evaluate any
9429 subexpressions. */
9430 if (ignore)
9432 unsigned HOST_WIDE_INT idx;
9433 tree value;
9435 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
9436 expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
9438 return const0_rtx;
9441 return expand_constructor (exp, target, modifier, false);
9443 case TARGET_MEM_REF:
9445 addr_space_t as
9446 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9447 struct mem_address addr;
9448 enum insn_code icode;
9449 unsigned int align;
9451 get_address_description (exp, &addr);
9452 op0 = addr_for_mem_ref (&addr, as, true);
9453 op0 = memory_address_addr_space (mode, op0, as);
9454 temp = gen_rtx_MEM (mode, op0);
9455 set_mem_attributes (temp, exp, 0);
9456 set_mem_addr_space (temp, as);
9457 align = get_object_alignment (exp);
9458 if (modifier != EXPAND_WRITE
9459 && mode != BLKmode
9460 && align < GET_MODE_ALIGNMENT (mode)
9461 /* If the target does not have special handling for unaligned
9462 loads of mode then it can use regular moves for them. */
9463 && ((icode = optab_handler (movmisalign_optab, mode))
9464 != CODE_FOR_nothing))
9466 struct expand_operand ops[2];
9468 /* We've already validated the memory, and we're creating a
9469 new pseudo destination. The predicates really can't fail,
9470 nor can the generator. */
9471 create_output_operand (&ops[0], NULL_RTX, mode);
9472 create_fixed_operand (&ops[1], temp);
9473 expand_insn (icode, 2, ops);
9474 return ops[0].value;
9476 return temp;
9479 case MEM_REF:
9481 addr_space_t as
9482 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9483 enum machine_mode address_mode;
9484 tree base = TREE_OPERAND (exp, 0);
9485 gimple def_stmt;
9486 enum insn_code icode;
9487 unsigned align;
9488 /* Handle expansion of non-aliased memory with non-BLKmode. That
9489 might end up in a register. */
9490 if (mem_ref_refers_to_non_mem_p (exp))
9492 HOST_WIDE_INT offset = mem_ref_offset (exp).low;
9493 tree bit_offset;
9494 tree bftype;
9495 base = TREE_OPERAND (base, 0);
9496 if (offset == 0
9497 && host_integerp (TYPE_SIZE (TREE_TYPE (exp)), 1)
9498 && (GET_MODE_BITSIZE (DECL_MODE (base))
9499 == TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp)))))
9500 return expand_expr (build1 (VIEW_CONVERT_EXPR,
9501 TREE_TYPE (exp), base),
9502 target, tmode, modifier);
9503 bit_offset = bitsize_int (offset * BITS_PER_UNIT);
9504 bftype = TREE_TYPE (base);
9505 if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
9506 bftype = TREE_TYPE (exp);
9507 else
9509 temp = assign_stack_temp (DECL_MODE (base),
9510 GET_MODE_SIZE (DECL_MODE (base)));
9511 store_expr (base, temp, 0, false);
9512 temp = adjust_address (temp, BLKmode, offset);
9513 set_mem_size (temp, int_size_in_bytes (TREE_TYPE (exp)));
9514 return temp;
9516 return expand_expr (build3 (BIT_FIELD_REF, bftype,
9517 base,
9518 TYPE_SIZE (TREE_TYPE (exp)),
9519 bit_offset),
9520 target, tmode, modifier);
9522 address_mode = targetm.addr_space.address_mode (as);
9523 base = TREE_OPERAND (exp, 0);
9524 if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
9526 tree mask = gimple_assign_rhs2 (def_stmt);
9527 base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
9528 gimple_assign_rhs1 (def_stmt), mask);
9529 TREE_OPERAND (exp, 0) = base;
9531 align = get_object_alignment (exp);
9532 op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
9533 op0 = memory_address_addr_space (address_mode, op0, as);
9534 if (!integer_zerop (TREE_OPERAND (exp, 1)))
9536 rtx off
9537 = immed_double_int_const (mem_ref_offset (exp), address_mode);
9538 op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
9540 op0 = memory_address_addr_space (mode, op0, as);
9541 temp = gen_rtx_MEM (mode, op0);
9542 set_mem_attributes (temp, exp, 0);
9543 set_mem_addr_space (temp, as);
9544 if (TREE_THIS_VOLATILE (exp))
9545 MEM_VOLATILE_P (temp) = 1;
9546 if (modifier != EXPAND_WRITE
9547 && mode != BLKmode
9548 && align < GET_MODE_ALIGNMENT (mode))
9550 if ((icode = optab_handler (movmisalign_optab, mode))
9551 != CODE_FOR_nothing)
9553 struct expand_operand ops[2];
9555 /* We've already validated the memory, and we're creating a
9556 new pseudo destination. The predicates really can't fail,
9557 nor can the generator. */
9558 create_output_operand (&ops[0], NULL_RTX, mode);
9559 create_fixed_operand (&ops[1], temp);
9560 expand_insn (icode, 2, ops);
9561 return ops[0].value;
9563 else if (SLOW_UNALIGNED_ACCESS (mode, align))
9564 temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode),
9565 0, TYPE_UNSIGNED (TREE_TYPE (exp)),
9566 true, (modifier == EXPAND_STACK_PARM
9567 ? NULL_RTX : target),
9568 mode, mode);
9570 return temp;
9573 case ARRAY_REF:
9576 tree array = treeop0;
9577 tree index = treeop1;
9579 /* Fold an expression like: "foo"[2].
9580 This is not done in fold so it won't happen inside &.
9581 Don't fold if this is for wide characters since it's too
9582 difficult to do correctly and this is a very rare case. */
9584 if (modifier != EXPAND_CONST_ADDRESS
9585 && modifier != EXPAND_INITIALIZER
9586 && modifier != EXPAND_MEMORY)
9588 tree t = fold_read_from_constant_string (exp);
9590 if (t)
9591 return expand_expr (t, target, tmode, modifier);
9594 /* If this is a constant index into a constant array,
9595 just get the value from the array. Handle both the cases when
9596 we have an explicit constructor and when our operand is a variable
9597 that was declared const. */
9599 if (modifier != EXPAND_CONST_ADDRESS
9600 && modifier != EXPAND_INITIALIZER
9601 && modifier != EXPAND_MEMORY
9602 && TREE_CODE (array) == CONSTRUCTOR
9603 && ! TREE_SIDE_EFFECTS (array)
9604 && TREE_CODE (index) == INTEGER_CST)
9606 unsigned HOST_WIDE_INT ix;
9607 tree field, value;
9609 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
9610 field, value)
9611 if (tree_int_cst_equal (field, index))
9613 if (!TREE_SIDE_EFFECTS (value))
9614 return expand_expr (fold (value), target, tmode, modifier);
9615 break;
9619 else if (optimize >= 1
9620 && modifier != EXPAND_CONST_ADDRESS
9621 && modifier != EXPAND_INITIALIZER
9622 && modifier != EXPAND_MEMORY
9623 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
9624 && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
9625 && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK
9626 && const_value_known_p (array))
9628 if (TREE_CODE (index) == INTEGER_CST)
9630 tree init = DECL_INITIAL (array);
9632 if (TREE_CODE (init) == CONSTRUCTOR)
9634 unsigned HOST_WIDE_INT ix;
9635 tree field, value;
9637 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
9638 field, value)
9639 if (tree_int_cst_equal (field, index))
9641 if (TREE_SIDE_EFFECTS (value))
9642 break;
9644 if (TREE_CODE (value) == CONSTRUCTOR)
9646 /* If VALUE is a CONSTRUCTOR, this
9647 optimization is only useful if
9648 this doesn't store the CONSTRUCTOR
9649 into memory. If it does, it is more
9650 efficient to just load the data from
9651 the array directly. */
9652 rtx ret = expand_constructor (value, target,
9653 modifier, true);
9654 if (ret == NULL_RTX)
9655 break;
9658 return expand_expr (fold (value), target, tmode,
9659 modifier);
9662 else if(TREE_CODE (init) == STRING_CST)
9664 tree index1 = index;
9665 tree low_bound = array_ref_low_bound (exp);
9666 index1 = fold_convert_loc (loc, sizetype,
9667 treeop1);
9669 /* Optimize the special-case of a zero lower bound.
9671 We convert the low_bound to sizetype to avoid some problems
9672 with constant folding. (E.g. suppose the lower bound is 1,
9673 and its mode is QI. Without the conversion,l (ARRAY
9674 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
9675 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
9677 if (! integer_zerop (low_bound))
9678 index1 = size_diffop_loc (loc, index1,
9679 fold_convert_loc (loc, sizetype,
9680 low_bound));
9682 if (0 > compare_tree_int (index1,
9683 TREE_STRING_LENGTH (init)))
9685 tree type = TREE_TYPE (TREE_TYPE (init));
9686 enum machine_mode mode = TYPE_MODE (type);
9688 if (GET_MODE_CLASS (mode) == MODE_INT
9689 && GET_MODE_SIZE (mode) == 1)
9690 return gen_int_mode (TREE_STRING_POINTER (init)
9691 [TREE_INT_CST_LOW (index1)],
9692 mode);
9698 goto normal_inner_ref;
9700 case COMPONENT_REF:
9701 /* If the operand is a CONSTRUCTOR, we can just extract the
9702 appropriate field if it is present. */
9703 if (TREE_CODE (treeop0) == CONSTRUCTOR)
9705 unsigned HOST_WIDE_INT idx;
9706 tree field, value;
9708 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0),
9709 idx, field, value)
9710 if (field == treeop1
9711 /* We can normally use the value of the field in the
9712 CONSTRUCTOR. However, if this is a bitfield in
9713 an integral mode that we can fit in a HOST_WIDE_INT,
9714 we must mask only the number of bits in the bitfield,
9715 since this is done implicitly by the constructor. If
9716 the bitfield does not meet either of those conditions,
9717 we can't do this optimization. */
9718 && (! DECL_BIT_FIELD (field)
9719 || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
9720 && (GET_MODE_PRECISION (DECL_MODE (field))
9721 <= HOST_BITS_PER_WIDE_INT))))
9723 if (DECL_BIT_FIELD (field)
9724 && modifier == EXPAND_STACK_PARM)
9725 target = 0;
9726 op0 = expand_expr (value, target, tmode, modifier);
9727 if (DECL_BIT_FIELD (field))
9729 HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
9730 enum machine_mode imode = TYPE_MODE (TREE_TYPE (field));
9732 if (TYPE_UNSIGNED (TREE_TYPE (field)))
9734 op1 = GEN_INT (((HOST_WIDE_INT) 1 << bitsize) - 1);
9735 op0 = expand_and (imode, op0, op1, target);
9737 else
9739 int count = GET_MODE_PRECISION (imode) - bitsize;
9741 op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
9742 target, 0);
9743 op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
9744 target, 0);
9748 return op0;
9751 goto normal_inner_ref;
9753 case BIT_FIELD_REF:
9754 case ARRAY_RANGE_REF:
9755 normal_inner_ref:
9757 enum machine_mode mode1, mode2;
9758 HOST_WIDE_INT bitsize, bitpos;
9759 tree offset;
9760 int volatilep = 0, must_force_mem;
9761 bool packedp = false;
9762 tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
9763 &mode1, &unsignedp, &volatilep, true);
9764 rtx orig_op0, memloc;
9765 bool mem_attrs_from_type = false;
9767 /* If we got back the original object, something is wrong. Perhaps
9768 we are evaluating an expression too early. In any event, don't
9769 infinitely recurse. */
9770 gcc_assert (tem != exp);
9772 if (TYPE_PACKED (TREE_TYPE (TREE_OPERAND (exp, 0)))
9773 || (TREE_CODE (TREE_OPERAND (exp, 1)) == FIELD_DECL
9774 && DECL_PACKED (TREE_OPERAND (exp, 1))))
9775 packedp = true;
9777 /* If TEM's type is a union of variable size, pass TARGET to the inner
9778 computation, since it will need a temporary and TARGET is known
9779 to have to do. This occurs in unchecked conversion in Ada. */
9780 orig_op0 = op0
9781 = expand_expr (tem,
9782 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
9783 && COMPLETE_TYPE_P (TREE_TYPE (tem))
9784 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
9785 != INTEGER_CST)
9786 && modifier != EXPAND_STACK_PARM
9787 ? target : NULL_RTX),
9788 VOIDmode,
9789 (modifier == EXPAND_INITIALIZER
9790 || modifier == EXPAND_CONST_ADDRESS
9791 || modifier == EXPAND_STACK_PARM)
9792 ? modifier : EXPAND_NORMAL);
9795 /* If the bitfield is volatile, we want to access it in the
9796 field's mode, not the computed mode.
9797 If a MEM has VOIDmode (external with incomplete type),
9798 use BLKmode for it instead. */
9799 if (MEM_P (op0))
9801 if (volatilep && flag_strict_volatile_bitfields > 0)
9802 op0 = adjust_address (op0, mode1, 0);
9803 else if (GET_MODE (op0) == VOIDmode)
9804 op0 = adjust_address (op0, BLKmode, 0);
9807 mode2
9808 = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
9810 /* If we have either an offset, a BLKmode result, or a reference
9811 outside the underlying object, we must force it to memory.
9812 Such a case can occur in Ada if we have unchecked conversion
9813 of an expression from a scalar type to an aggregate type or
9814 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9815 passed a partially uninitialized object or a view-conversion
9816 to a larger size. */
9817 must_force_mem = (offset
9818 || mode1 == BLKmode
9819 || bitpos + bitsize > GET_MODE_BITSIZE (mode2));
9821 /* Handle CONCAT first. */
9822 if (GET_CODE (op0) == CONCAT && !must_force_mem)
9824 if (bitpos == 0
9825 && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)))
9826 return op0;
9827 if (bitpos == 0
9828 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
9829 && bitsize)
9831 op0 = XEXP (op0, 0);
9832 mode2 = GET_MODE (op0);
9834 else if (bitpos == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
9835 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1)))
9836 && bitpos
9837 && bitsize)
9839 op0 = XEXP (op0, 1);
9840 bitpos = 0;
9841 mode2 = GET_MODE (op0);
9843 else
9844 /* Otherwise force into memory. */
9845 must_force_mem = 1;
9848 /* If this is a constant, put it in a register if it is a legitimate
9849 constant and we don't need a memory reference. */
9850 if (CONSTANT_P (op0)
9851 && mode2 != BLKmode
9852 && targetm.legitimate_constant_p (mode2, op0)
9853 && !must_force_mem)
9854 op0 = force_reg (mode2, op0);
9856 /* Otherwise, if this is a constant, try to force it to the constant
9857 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9858 is a legitimate constant. */
9859 else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
9860 op0 = validize_mem (memloc);
9862 /* Otherwise, if this is a constant or the object is not in memory
9863 and need be, put it there. */
9864 else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
9866 tree nt = build_qualified_type (TREE_TYPE (tem),
9867 (TYPE_QUALS (TREE_TYPE (tem))
9868 | TYPE_QUAL_CONST));
9869 memloc = assign_temp (nt, 1, 1);
9870 emit_move_insn (memloc, op0);
9871 op0 = memloc;
9872 mem_attrs_from_type = true;
9875 if (offset)
9877 enum machine_mode address_mode;
9878 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
9879 EXPAND_SUM);
9881 gcc_assert (MEM_P (op0));
9883 address_mode = get_address_mode (op0);
9884 if (GET_MODE (offset_rtx) != address_mode)
9885 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
9887 if (GET_MODE (op0) == BLKmode
9888 /* A constant address in OP0 can have VOIDmode, we must
9889 not try to call force_reg in that case. */
9890 && GET_MODE (XEXP (op0, 0)) != VOIDmode
9891 && bitsize != 0
9892 && (bitpos % bitsize) == 0
9893 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
9894 && MEM_ALIGN (op0) == GET_MODE_ALIGNMENT (mode1))
9896 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
9897 bitpos = 0;
9900 op0 = offset_address (op0, offset_rtx,
9901 highest_pow2_factor (offset));
9904 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
9905 record its alignment as BIGGEST_ALIGNMENT. */
9906 if (MEM_P (op0) && bitpos == 0 && offset != 0
9907 && is_aligning_offset (offset, tem))
9908 set_mem_align (op0, BIGGEST_ALIGNMENT);
9910 /* Don't forget about volatility even if this is a bitfield. */
9911 if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
9913 if (op0 == orig_op0)
9914 op0 = copy_rtx (op0);
9916 MEM_VOLATILE_P (op0) = 1;
9919 /* In cases where an aligned union has an unaligned object
9920 as a field, we might be extracting a BLKmode value from
9921 an integer-mode (e.g., SImode) object. Handle this case
9922 by doing the extract into an object as wide as the field
9923 (which we know to be the width of a basic mode), then
9924 storing into memory, and changing the mode to BLKmode. */
9925 if (mode1 == VOIDmode
9926 || REG_P (op0) || GET_CODE (op0) == SUBREG
9927 || (mode1 != BLKmode && ! direct_load[(int) mode1]
9928 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
9929 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
9930 && modifier != EXPAND_CONST_ADDRESS
9931 && modifier != EXPAND_INITIALIZER)
9932 /* If the field is volatile, we always want an aligned
9933 access. Do this in following two situations:
9934 1. the access is not already naturally
9935 aligned, otherwise "normal" (non-bitfield) volatile fields
9936 become non-addressable.
9937 2. the bitsize is narrower than the access size. Need
9938 to extract bitfields from the access. */
9939 || (volatilep && flag_strict_volatile_bitfields > 0
9940 && (bitpos % GET_MODE_ALIGNMENT (mode) != 0
9941 || (mode1 != BLKmode
9942 && bitsize < GET_MODE_SIZE (mode1) * BITS_PER_UNIT)))
9943 /* If the field isn't aligned enough to fetch as a memref,
9944 fetch it as a bit field. */
9945 || (mode1 != BLKmode
9946 && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
9947 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
9948 || (MEM_P (op0)
9949 && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
9950 || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
9951 && ((modifier == EXPAND_CONST_ADDRESS
9952 || modifier == EXPAND_INITIALIZER)
9953 ? STRICT_ALIGNMENT
9954 : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
9955 || (bitpos % BITS_PER_UNIT != 0)))
9956 /* If the type and the field are a constant size and the
9957 size of the type isn't the same size as the bitfield,
9958 we must use bitfield operations. */
9959 || (bitsize >= 0
9960 && TYPE_SIZE (TREE_TYPE (exp))
9961 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
9962 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
9963 bitsize)))
9965 enum machine_mode ext_mode = mode;
9967 if (ext_mode == BLKmode
9968 && ! (target != 0 && MEM_P (op0)
9969 && MEM_P (target)
9970 && bitpos % BITS_PER_UNIT == 0))
9971 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
9973 if (ext_mode == BLKmode)
9975 if (target == 0)
9976 target = assign_temp (type, 1, 1);
9978 if (bitsize == 0)
9979 return target;
9981 /* In this case, BITPOS must start at a byte boundary and
9982 TARGET, if specified, must be a MEM. */
9983 gcc_assert (MEM_P (op0)
9984 && (!target || MEM_P (target))
9985 && !(bitpos % BITS_PER_UNIT));
9987 emit_block_move (target,
9988 adjust_address (op0, VOIDmode,
9989 bitpos / BITS_PER_UNIT),
9990 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
9991 / BITS_PER_UNIT),
9992 (modifier == EXPAND_STACK_PARM
9993 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
9995 return target;
9998 op0 = validize_mem (op0);
10000 if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
10001 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10003 op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp, packedp,
10004 (modifier == EXPAND_STACK_PARM
10005 ? NULL_RTX : target),
10006 ext_mode, ext_mode);
10008 /* If the result is a record type and BITSIZE is narrower than
10009 the mode of OP0, an integral mode, and this is a big endian
10010 machine, we must put the field into the high-order bits. */
10011 if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
10012 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
10013 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
10014 op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
10015 GET_MODE_BITSIZE (GET_MODE (op0))
10016 - bitsize, op0, 1);
10018 /* If the result type is BLKmode, store the data into a temporary
10019 of the appropriate type, but with the mode corresponding to the
10020 mode for the data we have (op0's mode). It's tempting to make
10021 this a constant type, since we know it's only being stored once,
10022 but that can cause problems if we are taking the address of this
10023 COMPONENT_REF because the MEM of any reference via that address
10024 will have flags corresponding to the type, which will not
10025 necessarily be constant. */
10026 if (mode == BLKmode)
10028 rtx new_rtx;
10030 new_rtx = assign_stack_temp_for_type (ext_mode,
10031 GET_MODE_BITSIZE (ext_mode),
10032 type);
10033 emit_move_insn (new_rtx, op0);
10034 op0 = copy_rtx (new_rtx);
10035 PUT_MODE (op0, BLKmode);
10038 return op0;
10041 /* If the result is BLKmode, use that to access the object
10042 now as well. */
10043 if (mode == BLKmode)
10044 mode1 = BLKmode;
10046 /* Get a reference to just this component. */
10047 if (modifier == EXPAND_CONST_ADDRESS
10048 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
10049 op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
10050 else
10051 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
10053 if (op0 == orig_op0)
10054 op0 = copy_rtx (op0);
10056 /* If op0 is a temporary because of forcing to memory, pass only the
10057 type to set_mem_attributes so that the original expression is never
10058 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10059 if (mem_attrs_from_type)
10060 set_mem_attributes (op0, type, 0);
10061 else
10062 set_mem_attributes (op0, exp, 0);
10064 if (REG_P (XEXP (op0, 0)))
10065 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10067 MEM_VOLATILE_P (op0) |= volatilep;
10068 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
10069 || modifier == EXPAND_CONST_ADDRESS
10070 || modifier == EXPAND_INITIALIZER)
10071 return op0;
10072 else if (target == 0)
10073 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
10075 convert_move (target, op0, unsignedp);
10076 return target;
10079 case OBJ_TYPE_REF:
10080 return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
10082 case CALL_EXPR:
10083 /* All valid uses of __builtin_va_arg_pack () are removed during
10084 inlining. */
10085 if (CALL_EXPR_VA_ARG_PACK (exp))
10086 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
10088 tree fndecl = get_callee_fndecl (exp), attr;
10090 if (fndecl
10091 && (attr = lookup_attribute ("error",
10092 DECL_ATTRIBUTES (fndecl))) != NULL)
10093 error ("%Kcall to %qs declared with attribute error: %s",
10094 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
10095 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
10096 if (fndecl
10097 && (attr = lookup_attribute ("warning",
10098 DECL_ATTRIBUTES (fndecl))) != NULL)
10099 warning_at (tree_nonartificial_location (exp),
10100 0, "%Kcall to %qs declared with attribute warning: %s",
10101 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
10102 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
10104 /* Check for a built-in function. */
10105 if (fndecl && DECL_BUILT_IN (fndecl))
10107 gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
10108 return expand_builtin (exp, target, subtarget, tmode, ignore);
10111 return expand_call (exp, target, ignore);
10113 case VIEW_CONVERT_EXPR:
10114 op0 = NULL_RTX;
10116 /* If we are converting to BLKmode, try to avoid an intermediate
10117 temporary by fetching an inner memory reference. */
10118 if (mode == BLKmode
10119 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
10120 && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
10121 && handled_component_p (treeop0))
10123 enum machine_mode mode1;
10124 HOST_WIDE_INT bitsize, bitpos;
10125 tree offset;
10126 int unsignedp;
10127 int volatilep = 0;
10128 tree tem
10129 = get_inner_reference (treeop0, &bitsize, &bitpos,
10130 &offset, &mode1, &unsignedp, &volatilep,
10131 true);
10132 rtx orig_op0;
10134 /* ??? We should work harder and deal with non-zero offsets. */
10135 if (!offset
10136 && (bitpos % BITS_PER_UNIT) == 0
10137 && bitsize >= 0
10138 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) == 0)
10140 /* See the normal_inner_ref case for the rationale. */
10141 orig_op0
10142 = expand_expr (tem,
10143 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
10144 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
10145 != INTEGER_CST)
10146 && modifier != EXPAND_STACK_PARM
10147 ? target : NULL_RTX),
10148 VOIDmode,
10149 (modifier == EXPAND_INITIALIZER
10150 || modifier == EXPAND_CONST_ADDRESS
10151 || modifier == EXPAND_STACK_PARM)
10152 ? modifier : EXPAND_NORMAL);
10154 if (MEM_P (orig_op0))
10156 op0 = orig_op0;
10158 /* Get a reference to just this component. */
10159 if (modifier == EXPAND_CONST_ADDRESS
10160 || modifier == EXPAND_SUM
10161 || modifier == EXPAND_INITIALIZER)
10162 op0 = adjust_address_nv (op0, mode, bitpos / BITS_PER_UNIT);
10163 else
10164 op0 = adjust_address (op0, mode, bitpos / BITS_PER_UNIT);
10166 if (op0 == orig_op0)
10167 op0 = copy_rtx (op0);
10169 set_mem_attributes (op0, treeop0, 0);
10170 if (REG_P (XEXP (op0, 0)))
10171 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10173 MEM_VOLATILE_P (op0) |= volatilep;
10178 if (!op0)
10179 op0 = expand_expr (treeop0,
10180 NULL_RTX, VOIDmode, modifier);
10182 /* If the input and output modes are both the same, we are done. */
10183 if (mode == GET_MODE (op0))
10185 /* If neither mode is BLKmode, and both modes are the same size
10186 then we can use gen_lowpart. */
10187 else if (mode != BLKmode && GET_MODE (op0) != BLKmode
10188 && (GET_MODE_PRECISION (mode)
10189 == GET_MODE_PRECISION (GET_MODE (op0)))
10190 && !COMPLEX_MODE_P (GET_MODE (op0)))
10192 if (GET_CODE (op0) == SUBREG)
10193 op0 = force_reg (GET_MODE (op0), op0);
10194 temp = gen_lowpart_common (mode, op0);
10195 if (temp)
10196 op0 = temp;
10197 else
10199 if (!REG_P (op0) && !MEM_P (op0))
10200 op0 = force_reg (GET_MODE (op0), op0);
10201 op0 = gen_lowpart (mode, op0);
10204 /* If both types are integral, convert from one mode to the other. */
10205 else if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0)))
10206 op0 = convert_modes (mode, GET_MODE (op0), op0,
10207 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10208 /* As a last resort, spill op0 to memory, and reload it in a
10209 different mode. */
10210 else if (!MEM_P (op0))
10212 /* If the operand is not a MEM, force it into memory. Since we
10213 are going to be changing the mode of the MEM, don't call
10214 force_const_mem for constants because we don't allow pool
10215 constants to change mode. */
10216 tree inner_type = TREE_TYPE (treeop0);
10218 gcc_assert (!TREE_ADDRESSABLE (exp));
10220 if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
10221 target
10222 = assign_stack_temp_for_type
10223 (TYPE_MODE (inner_type),
10224 GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
10226 emit_move_insn (target, op0);
10227 op0 = target;
10230 /* At this point, OP0 is in the correct mode. If the output type is
10231 such that the operand is known to be aligned, indicate that it is.
10232 Otherwise, we need only be concerned about alignment for non-BLKmode
10233 results. */
10234 if (MEM_P (op0))
10236 enum insn_code icode;
10238 if (TYPE_ALIGN_OK (type))
10240 /* ??? Copying the MEM without substantially changing it might
10241 run afoul of the code handling volatile memory references in
10242 store_expr, which assumes that TARGET is returned unmodified
10243 if it has been used. */
10244 op0 = copy_rtx (op0);
10245 set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
10247 else if (mode != BLKmode
10248 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode)
10249 /* If the target does have special handling for unaligned
10250 loads of mode then use them. */
10251 && ((icode = optab_handler (movmisalign_optab, mode))
10252 != CODE_FOR_nothing))
10254 rtx reg, insn;
10256 op0 = adjust_address (op0, mode, 0);
10257 /* We've already validated the memory, and we're creating a
10258 new pseudo destination. The predicates really can't
10259 fail. */
10260 reg = gen_reg_rtx (mode);
10262 /* Nor can the insn generator. */
10263 insn = GEN_FCN (icode) (reg, op0);
10264 emit_insn (insn);
10265 return reg;
10267 else if (STRICT_ALIGNMENT
10268 && mode != BLKmode
10269 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
10271 tree inner_type = TREE_TYPE (treeop0);
10272 HOST_WIDE_INT temp_size
10273 = MAX (int_size_in_bytes (inner_type),
10274 (HOST_WIDE_INT) GET_MODE_SIZE (mode));
10275 rtx new_rtx
10276 = assign_stack_temp_for_type (mode, temp_size, type);
10277 rtx new_with_op0_mode
10278 = adjust_address (new_rtx, GET_MODE (op0), 0);
10280 gcc_assert (!TREE_ADDRESSABLE (exp));
10282 if (GET_MODE (op0) == BLKmode)
10283 emit_block_move (new_with_op0_mode, op0,
10284 GEN_INT (GET_MODE_SIZE (mode)),
10285 (modifier == EXPAND_STACK_PARM
10286 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
10287 else
10288 emit_move_insn (new_with_op0_mode, op0);
10290 op0 = new_rtx;
10293 op0 = adjust_address (op0, mode, 0);
10296 return op0;
10298 case MODIFY_EXPR:
10300 tree lhs = treeop0;
10301 tree rhs = treeop1;
10302 gcc_assert (ignore);
10304 /* Check for |= or &= of a bitfield of size one into another bitfield
10305 of size 1. In this case, (unless we need the result of the
10306 assignment) we can do this more efficiently with a
10307 test followed by an assignment, if necessary.
10309 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10310 things change so we do, this code should be enhanced to
10311 support it. */
10312 if (TREE_CODE (lhs) == COMPONENT_REF
10313 && (TREE_CODE (rhs) == BIT_IOR_EXPR
10314 || TREE_CODE (rhs) == BIT_AND_EXPR)
10315 && TREE_OPERAND (rhs, 0) == lhs
10316 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
10317 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
10318 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
10320 rtx label = gen_label_rtx ();
10321 int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
10322 do_jump (TREE_OPERAND (rhs, 1),
10323 value ? label : 0,
10324 value ? 0 : label, -1);
10325 expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
10326 false);
10327 do_pending_stack_adjust ();
10328 emit_label (label);
10329 return const0_rtx;
10332 expand_assignment (lhs, rhs, false);
10333 return const0_rtx;
10336 case ADDR_EXPR:
10337 return expand_expr_addr_expr (exp, target, tmode, modifier);
10339 case REALPART_EXPR:
10340 op0 = expand_normal (treeop0);
10341 return read_complex_part (op0, false);
10343 case IMAGPART_EXPR:
10344 op0 = expand_normal (treeop0);
10345 return read_complex_part (op0, true);
10347 case RETURN_EXPR:
10348 case LABEL_EXPR:
10349 case GOTO_EXPR:
10350 case SWITCH_EXPR:
10351 case ASM_EXPR:
10352 /* Expanded in cfgexpand.c. */
10353 gcc_unreachable ();
10355 case TRY_CATCH_EXPR:
10356 case CATCH_EXPR:
10357 case EH_FILTER_EXPR:
10358 case TRY_FINALLY_EXPR:
10359 /* Lowered by tree-eh.c. */
10360 gcc_unreachable ();
10362 case WITH_CLEANUP_EXPR:
10363 case CLEANUP_POINT_EXPR:
10364 case TARGET_EXPR:
10365 case CASE_LABEL_EXPR:
10366 case VA_ARG_EXPR:
10367 case BIND_EXPR:
10368 case INIT_EXPR:
10369 case CONJ_EXPR:
10370 case COMPOUND_EXPR:
10371 case PREINCREMENT_EXPR:
10372 case PREDECREMENT_EXPR:
10373 case POSTINCREMENT_EXPR:
10374 case POSTDECREMENT_EXPR:
10375 case LOOP_EXPR:
10376 case EXIT_EXPR:
10377 case COMPOUND_LITERAL_EXPR:
10378 /* Lowered by gimplify.c. */
10379 gcc_unreachable ();
10381 case FDESC_EXPR:
10382 /* Function descriptors are not valid except for as
10383 initialization constants, and should not be expanded. */
10384 gcc_unreachable ();
10386 case WITH_SIZE_EXPR:
10387 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10388 have pulled out the size to use in whatever context it needed. */
10389 return expand_expr_real (treeop0, original_target, tmode,
10390 modifier, alt_rtl);
10392 default:
10393 return expand_expr_real_2 (&ops, target, tmode, modifier);
10397 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10398 signedness of TYPE), possibly returning the result in TARGET. */
10399 static rtx
10400 reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
10402 HOST_WIDE_INT prec = TYPE_PRECISION (type);
10403 if (target && GET_MODE (target) != GET_MODE (exp))
10404 target = 0;
10405 /* For constant values, reduce using build_int_cst_type. */
10406 if (CONST_INT_P (exp))
10408 HOST_WIDE_INT value = INTVAL (exp);
10409 tree t = build_int_cst_type (type, value);
10410 return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
10412 else if (TYPE_UNSIGNED (type))
10414 rtx mask = immed_double_int_const (double_int::mask (prec),
10415 GET_MODE (exp));
10416 return expand_and (GET_MODE (exp), exp, mask, target);
10418 else
10420 int count = GET_MODE_PRECISION (GET_MODE (exp)) - prec;
10421 exp = expand_shift (LSHIFT_EXPR, GET_MODE (exp),
10422 exp, count, target, 0);
10423 return expand_shift (RSHIFT_EXPR, GET_MODE (exp),
10424 exp, count, target, 0);
10428 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10429 when applied to the address of EXP produces an address known to be
10430 aligned more than BIGGEST_ALIGNMENT. */
10432 static int
10433 is_aligning_offset (const_tree offset, const_tree exp)
10435 /* Strip off any conversions. */
10436 while (CONVERT_EXPR_P (offset))
10437 offset = TREE_OPERAND (offset, 0);
10439 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10440 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10441 if (TREE_CODE (offset) != BIT_AND_EXPR
10442 || !host_integerp (TREE_OPERAND (offset, 1), 1)
10443 || compare_tree_int (TREE_OPERAND (offset, 1),
10444 BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
10445 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
10446 return 0;
10448 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10449 It must be NEGATE_EXPR. Then strip any more conversions. */
10450 offset = TREE_OPERAND (offset, 0);
10451 while (CONVERT_EXPR_P (offset))
10452 offset = TREE_OPERAND (offset, 0);
10454 if (TREE_CODE (offset) != NEGATE_EXPR)
10455 return 0;
10457 offset = TREE_OPERAND (offset, 0);
10458 while (CONVERT_EXPR_P (offset))
10459 offset = TREE_OPERAND (offset, 0);
10461 /* This must now be the address of EXP. */
10462 return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
10465 /* Return the tree node if an ARG corresponds to a string constant or zero
10466 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10467 in bytes within the string that ARG is accessing. The type of the
10468 offset will be `sizetype'. */
10470 tree
10471 string_constant (tree arg, tree *ptr_offset)
10473 tree array, offset, lower_bound;
10474 STRIP_NOPS (arg);
10476 if (TREE_CODE (arg) == ADDR_EXPR)
10478 if (TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
10480 *ptr_offset = size_zero_node;
10481 return TREE_OPERAND (arg, 0);
10483 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL)
10485 array = TREE_OPERAND (arg, 0);
10486 offset = size_zero_node;
10488 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF)
10490 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10491 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10492 if (TREE_CODE (array) != STRING_CST
10493 && TREE_CODE (array) != VAR_DECL)
10494 return 0;
10496 /* Check if the array has a nonzero lower bound. */
10497 lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
10498 if (!integer_zerop (lower_bound))
10500 /* If the offset and base aren't both constants, return 0. */
10501 if (TREE_CODE (lower_bound) != INTEGER_CST)
10502 return 0;
10503 if (TREE_CODE (offset) != INTEGER_CST)
10504 return 0;
10505 /* Adjust offset by the lower bound. */
10506 offset = size_diffop (fold_convert (sizetype, offset),
10507 fold_convert (sizetype, lower_bound));
10510 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == MEM_REF)
10512 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10513 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10514 if (TREE_CODE (array) != ADDR_EXPR)
10515 return 0;
10516 array = TREE_OPERAND (array, 0);
10517 if (TREE_CODE (array) != STRING_CST
10518 && TREE_CODE (array) != VAR_DECL)
10519 return 0;
10521 else
10522 return 0;
10524 else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
10526 tree arg0 = TREE_OPERAND (arg, 0);
10527 tree arg1 = TREE_OPERAND (arg, 1);
10529 STRIP_NOPS (arg0);
10530 STRIP_NOPS (arg1);
10532 if (TREE_CODE (arg0) == ADDR_EXPR
10533 && (TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST
10534 || TREE_CODE (TREE_OPERAND (arg0, 0)) == VAR_DECL))
10536 array = TREE_OPERAND (arg0, 0);
10537 offset = arg1;
10539 else if (TREE_CODE (arg1) == ADDR_EXPR
10540 && (TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST
10541 || TREE_CODE (TREE_OPERAND (arg1, 0)) == VAR_DECL))
10543 array = TREE_OPERAND (arg1, 0);
10544 offset = arg0;
10546 else
10547 return 0;
10549 else
10550 return 0;
10552 if (TREE_CODE (array) == STRING_CST)
10554 *ptr_offset = fold_convert (sizetype, offset);
10555 return array;
10557 else if (TREE_CODE (array) == VAR_DECL
10558 || TREE_CODE (array) == CONST_DECL)
10560 int length;
10562 /* Variables initialized to string literals can be handled too. */
10563 if (!const_value_known_p (array)
10564 || !DECL_INITIAL (array)
10565 || TREE_CODE (DECL_INITIAL (array)) != STRING_CST)
10566 return 0;
10568 /* Avoid const char foo[4] = "abcde"; */
10569 if (DECL_SIZE_UNIT (array) == NULL_TREE
10570 || TREE_CODE (DECL_SIZE_UNIT (array)) != INTEGER_CST
10571 || (length = TREE_STRING_LENGTH (DECL_INITIAL (array))) <= 0
10572 || compare_tree_int (DECL_SIZE_UNIT (array), length) < 0)
10573 return 0;
10575 /* If variable is bigger than the string literal, OFFSET must be constant
10576 and inside of the bounds of the string literal. */
10577 offset = fold_convert (sizetype, offset);
10578 if (compare_tree_int (DECL_SIZE_UNIT (array), length) > 0
10579 && (! host_integerp (offset, 1)
10580 || compare_tree_int (offset, length) >= 0))
10581 return 0;
10583 *ptr_offset = offset;
10584 return DECL_INITIAL (array);
10587 return 0;
10590 /* Generate code to calculate OPS, and exploded expression
10591 using a store-flag instruction and return an rtx for the result.
10592 OPS reflects a comparison.
10594 If TARGET is nonzero, store the result there if convenient.
10596 Return zero if there is no suitable set-flag instruction
10597 available on this machine.
10599 Once expand_expr has been called on the arguments of the comparison,
10600 we are committed to doing the store flag, since it is not safe to
10601 re-evaluate the expression. We emit the store-flag insn by calling
10602 emit_store_flag, but only expand the arguments if we have a reason
10603 to believe that emit_store_flag will be successful. If we think that
10604 it will, but it isn't, we have to simulate the store-flag with a
10605 set/jump/set sequence. */
10607 static rtx
10608 do_store_flag (sepops ops, rtx target, enum machine_mode mode)
10610 enum rtx_code code;
10611 tree arg0, arg1, type;
10612 tree tem;
10613 enum machine_mode operand_mode;
10614 int unsignedp;
10615 rtx op0, op1;
10616 rtx subtarget = target;
10617 location_t loc = ops->location;
10619 arg0 = ops->op0;
10620 arg1 = ops->op1;
10622 /* Don't crash if the comparison was erroneous. */
10623 if (arg0 == error_mark_node || arg1 == error_mark_node)
10624 return const0_rtx;
10626 type = TREE_TYPE (arg0);
10627 operand_mode = TYPE_MODE (type);
10628 unsignedp = TYPE_UNSIGNED (type);
10630 /* We won't bother with BLKmode store-flag operations because it would mean
10631 passing a lot of information to emit_store_flag. */
10632 if (operand_mode == BLKmode)
10633 return 0;
10635 /* We won't bother with store-flag operations involving function pointers
10636 when function pointers must be canonicalized before comparisons. */
10637 #ifdef HAVE_canonicalize_funcptr_for_compare
10638 if (HAVE_canonicalize_funcptr_for_compare
10639 && ((TREE_CODE (TREE_TYPE (arg0)) == POINTER_TYPE
10640 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0)))
10641 == FUNCTION_TYPE))
10642 || (TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE
10643 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1)))
10644 == FUNCTION_TYPE))))
10645 return 0;
10646 #endif
10648 STRIP_NOPS (arg0);
10649 STRIP_NOPS (arg1);
10651 /* For vector typed comparisons emit code to generate the desired
10652 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10653 expander for this. */
10654 if (TREE_CODE (ops->type) == VECTOR_TYPE)
10656 tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
10657 tree if_true = constant_boolean_node (true, ops->type);
10658 tree if_false = constant_boolean_node (false, ops->type);
10659 return expand_vec_cond_expr (ops->type, ifexp, if_true, if_false, target);
10662 /* Get the rtx comparison code to use. We know that EXP is a comparison
10663 operation of some type. Some comparisons against 1 and -1 can be
10664 converted to comparisons with zero. Do so here so that the tests
10665 below will be aware that we have a comparison with zero. These
10666 tests will not catch constants in the first operand, but constants
10667 are rarely passed as the first operand. */
10669 switch (ops->code)
10671 case EQ_EXPR:
10672 code = EQ;
10673 break;
10674 case NE_EXPR:
10675 code = NE;
10676 break;
10677 case LT_EXPR:
10678 if (integer_onep (arg1))
10679 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
10680 else
10681 code = unsignedp ? LTU : LT;
10682 break;
10683 case LE_EXPR:
10684 if (! unsignedp && integer_all_onesp (arg1))
10685 arg1 = integer_zero_node, code = LT;
10686 else
10687 code = unsignedp ? LEU : LE;
10688 break;
10689 case GT_EXPR:
10690 if (! unsignedp && integer_all_onesp (arg1))
10691 arg1 = integer_zero_node, code = GE;
10692 else
10693 code = unsignedp ? GTU : GT;
10694 break;
10695 case GE_EXPR:
10696 if (integer_onep (arg1))
10697 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
10698 else
10699 code = unsignedp ? GEU : GE;
10700 break;
10702 case UNORDERED_EXPR:
10703 code = UNORDERED;
10704 break;
10705 case ORDERED_EXPR:
10706 code = ORDERED;
10707 break;
10708 case UNLT_EXPR:
10709 code = UNLT;
10710 break;
10711 case UNLE_EXPR:
10712 code = UNLE;
10713 break;
10714 case UNGT_EXPR:
10715 code = UNGT;
10716 break;
10717 case UNGE_EXPR:
10718 code = UNGE;
10719 break;
10720 case UNEQ_EXPR:
10721 code = UNEQ;
10722 break;
10723 case LTGT_EXPR:
10724 code = LTGT;
10725 break;
10727 default:
10728 gcc_unreachable ();
10731 /* Put a constant second. */
10732 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
10733 || TREE_CODE (arg0) == FIXED_CST)
10735 tem = arg0; arg0 = arg1; arg1 = tem;
10736 code = swap_condition (code);
10739 /* If this is an equality or inequality test of a single bit, we can
10740 do this by shifting the bit being tested to the low-order bit and
10741 masking the result with the constant 1. If the condition was EQ,
10742 we xor it with 1. This does not require an scc insn and is faster
10743 than an scc insn even if we have it.
10745 The code to make this transformation was moved into fold_single_bit_test,
10746 so we just call into the folder and expand its result. */
10748 if ((code == NE || code == EQ)
10749 && integer_zerop (arg1)
10750 && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
10752 gimple srcstmt = get_def_for_expr (arg0, BIT_AND_EXPR);
10753 if (srcstmt
10754 && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
10756 enum tree_code tcode = code == NE ? NE_EXPR : EQ_EXPR;
10757 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
10758 tree temp = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg1),
10759 gimple_assign_rhs1 (srcstmt),
10760 gimple_assign_rhs2 (srcstmt));
10761 temp = fold_single_bit_test (loc, tcode, temp, arg1, type);
10762 if (temp)
10763 return expand_expr (temp, target, VOIDmode, EXPAND_NORMAL);
10767 if (! get_subtarget (target)
10768 || GET_MODE (subtarget) != operand_mode)
10769 subtarget = 0;
10771 expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
10773 if (target == 0)
10774 target = gen_reg_rtx (mode);
10776 /* Try a cstore if possible. */
10777 return emit_store_flag_force (target, code, op0, op1,
10778 operand_mode, unsignedp,
10779 (TYPE_PRECISION (ops->type) == 1
10780 && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
10784 /* Stubs in case we haven't got a casesi insn. */
10785 #ifndef HAVE_casesi
10786 # define HAVE_casesi 0
10787 # define gen_casesi(a, b, c, d, e) (0)
10788 # define CODE_FOR_casesi CODE_FOR_nothing
10789 #endif
10791 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10792 0 otherwise (i.e. if there is no casesi instruction).
10794 DEFAULT_PROBABILITY is the probability of jumping to the default
10795 label. */
10797 try_casesi (tree index_type, tree index_expr, tree minval, tree range,
10798 rtx table_label, rtx default_label, rtx fallback_label,
10799 int default_probability)
10801 struct expand_operand ops[5];
10802 enum machine_mode index_mode = SImode;
10803 rtx op1, op2, index;
10805 if (! HAVE_casesi)
10806 return 0;
10808 /* Convert the index to SImode. */
10809 if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
10811 enum machine_mode omode = TYPE_MODE (index_type);
10812 rtx rangertx = expand_normal (range);
10814 /* We must handle the endpoints in the original mode. */
10815 index_expr = build2 (MINUS_EXPR, index_type,
10816 index_expr, minval);
10817 minval = integer_zero_node;
10818 index = expand_normal (index_expr);
10819 if (default_label)
10820 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
10821 omode, 1, default_label,
10822 default_probability);
10823 /* Now we can safely truncate. */
10824 index = convert_to_mode (index_mode, index, 0);
10826 else
10828 if (TYPE_MODE (index_type) != index_mode)
10830 index_type = lang_hooks.types.type_for_mode (index_mode, 0);
10831 index_expr = fold_convert (index_type, index_expr);
10834 index = expand_normal (index_expr);
10837 do_pending_stack_adjust ();
10839 op1 = expand_normal (minval);
10840 op2 = expand_normal (range);
10842 create_input_operand (&ops[0], index, index_mode);
10843 create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
10844 create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
10845 create_fixed_operand (&ops[3], table_label);
10846 create_fixed_operand (&ops[4], (default_label
10847 ? default_label
10848 : fallback_label));
10849 expand_jump_insn (CODE_FOR_casesi, 5, ops);
10850 return 1;
10853 /* Attempt to generate a tablejump instruction; same concept. */
10854 #ifndef HAVE_tablejump
10855 #define HAVE_tablejump 0
10856 #define gen_tablejump(x, y) (0)
10857 #endif
10859 /* Subroutine of the next function.
10861 INDEX is the value being switched on, with the lowest value
10862 in the table already subtracted.
10863 MODE is its expected mode (needed if INDEX is constant).
10864 RANGE is the length of the jump table.
10865 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10867 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10868 index value is out of range.
10869 DEFAULT_PROBABILITY is the probability of jumping to
10870 the default label. */
10872 static void
10873 do_tablejump (rtx index, enum machine_mode mode, rtx range, rtx table_label,
10874 rtx default_label, int default_probability)
10876 rtx temp, vector;
10878 if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
10879 cfun->cfg->max_jumptable_ents = INTVAL (range);
10881 /* Do an unsigned comparison (in the proper mode) between the index
10882 expression and the value which represents the length of the range.
10883 Since we just finished subtracting the lower bound of the range
10884 from the index expression, this comparison allows us to simultaneously
10885 check that the original index expression value is both greater than
10886 or equal to the minimum value of the range and less than or equal to
10887 the maximum value of the range. */
10889 if (default_label)
10890 emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
10891 default_label, default_probability);
10894 /* If index is in range, it must fit in Pmode.
10895 Convert to Pmode so we can index with it. */
10896 if (mode != Pmode)
10897 index = convert_to_mode (Pmode, index, 1);
10899 /* Don't let a MEM slip through, because then INDEX that comes
10900 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
10901 and break_out_memory_refs will go to work on it and mess it up. */
10902 #ifdef PIC_CASE_VECTOR_ADDRESS
10903 if (flag_pic && !REG_P (index))
10904 index = copy_to_mode_reg (Pmode, index);
10905 #endif
10907 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
10908 GET_MODE_SIZE, because this indicates how large insns are. The other
10909 uses should all be Pmode, because they are addresses. This code
10910 could fail if addresses and insns are not the same size. */
10911 index = gen_rtx_PLUS (Pmode,
10912 gen_rtx_MULT (Pmode, index,
10913 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))),
10914 gen_rtx_LABEL_REF (Pmode, table_label));
10915 #ifdef PIC_CASE_VECTOR_ADDRESS
10916 if (flag_pic)
10917 index = PIC_CASE_VECTOR_ADDRESS (index);
10918 else
10919 #endif
10920 index = memory_address (CASE_VECTOR_MODE, index);
10921 temp = gen_reg_rtx (CASE_VECTOR_MODE);
10922 vector = gen_const_mem (CASE_VECTOR_MODE, index);
10923 convert_move (temp, vector, 0);
10925 emit_jump_insn (gen_tablejump (temp, table_label));
10927 /* If we are generating PIC code or if the table is PC-relative, the
10928 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
10929 if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
10930 emit_barrier ();
10934 try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
10935 rtx table_label, rtx default_label, int default_probability)
10937 rtx index;
10939 if (! HAVE_tablejump)
10940 return 0;
10942 index_expr = fold_build2 (MINUS_EXPR, index_type,
10943 fold_convert (index_type, index_expr),
10944 fold_convert (index_type, minval));
10945 index = expand_normal (index_expr);
10946 do_pending_stack_adjust ();
10948 do_tablejump (index, TYPE_MODE (index_type),
10949 convert_modes (TYPE_MODE (index_type),
10950 TYPE_MODE (TREE_TYPE (range)),
10951 expand_normal (range),
10952 TYPE_UNSIGNED (TREE_TYPE (range))),
10953 table_label, default_label, default_probability);
10954 return 1;
10957 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
10958 static rtx
10959 const_vector_from_tree (tree exp)
10961 rtvec v;
10962 unsigned i;
10963 int units;
10964 tree elt;
10965 enum machine_mode inner, mode;
10967 mode = TYPE_MODE (TREE_TYPE (exp));
10969 if (initializer_zerop (exp))
10970 return CONST0_RTX (mode);
10972 units = GET_MODE_NUNITS (mode);
10973 inner = GET_MODE_INNER (mode);
10975 v = rtvec_alloc (units);
10977 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
10979 elt = VECTOR_CST_ELT (exp, i);
10981 if (TREE_CODE (elt) == REAL_CST)
10982 RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
10983 inner);
10984 else if (TREE_CODE (elt) == FIXED_CST)
10985 RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
10986 inner);
10987 else
10988 RTVEC_ELT (v, i) = immed_double_int_const (tree_to_double_int (elt),
10989 inner);
10992 return gen_rtx_CONST_VECTOR (mode, v);
10995 /* Build a decl for a personality function given a language prefix. */
10997 tree
10998 build_personality_function (const char *lang)
11000 const char *unwind_and_version;
11001 tree decl, type;
11002 char *name;
11004 switch (targetm_common.except_unwind_info (&global_options))
11006 case UI_NONE:
11007 return NULL;
11008 case UI_SJLJ:
11009 unwind_and_version = "_sj0";
11010 break;
11011 case UI_DWARF2:
11012 case UI_TARGET:
11013 unwind_and_version = "_v0";
11014 break;
11015 case UI_SEH:
11016 unwind_and_version = "_seh0";
11017 break;
11018 default:
11019 gcc_unreachable ();
11022 name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
11024 type = build_function_type_list (integer_type_node, integer_type_node,
11025 long_long_unsigned_type_node,
11026 ptr_type_node, ptr_type_node, NULL_TREE);
11027 decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
11028 get_identifier (name), type);
11029 DECL_ARTIFICIAL (decl) = 1;
11030 DECL_EXTERNAL (decl) = 1;
11031 TREE_PUBLIC (decl) = 1;
11033 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11034 are the flags assigned by targetm.encode_section_info. */
11035 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
11037 return decl;
11040 /* Extracts the personality function of DECL and returns the corresponding
11041 libfunc. */
11044 get_personality_function (tree decl)
11046 tree personality = DECL_FUNCTION_PERSONALITY (decl);
11047 enum eh_personality_kind pk;
11049 pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
11050 if (pk == eh_personality_none)
11051 return NULL;
11053 if (!personality
11054 && pk == eh_personality_any)
11055 personality = lang_hooks.eh_personality ();
11057 if (pk == eh_personality_lang)
11058 gcc_assert (personality != NULL_TREE);
11060 return XEXP (DECL_RTL (personality), 0);
11063 #include "gt-expr.h"