2007-05-01 H.J. Lu <hongjiu.lu@intel.com>
[official-gcc.git] / gcc / expr.c
blob5a618c983986ab2f4d75e4f9fc5ec6e5ecba7b61
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
4 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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "machmode.h"
28 #include "real.h"
29 #include "rtl.h"
30 #include "tree.h"
31 #include "flags.h"
32 #include "regs.h"
33 #include "hard-reg-set.h"
34 #include "except.h"
35 #include "function.h"
36 #include "insn-config.h"
37 #include "insn-attr.h"
38 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
39 #include "expr.h"
40 #include "optabs.h"
41 #include "libfuncs.h"
42 #include "recog.h"
43 #include "reload.h"
44 #include "output.h"
45 #include "typeclass.h"
46 #include "toplev.h"
47 #include "ggc.h"
48 #include "langhooks.h"
49 #include "intl.h"
50 #include "tm_p.h"
51 #include "tree-iterator.h"
52 #include "tree-pass.h"
53 #include "tree-flow.h"
54 #include "target.h"
55 #include "timevar.h"
57 /* Decide whether a function's arguments should be processed
58 from first to last or from last to first.
60 They should if the stack and args grow in opposite directions, but
61 only if we have push insns. */
63 #ifdef PUSH_ROUNDING
65 #ifndef PUSH_ARGS_REVERSED
66 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
67 #define PUSH_ARGS_REVERSED /* If it's last to first. */
68 #endif
69 #endif
71 #endif
73 #ifndef STACK_PUSH_CODE
74 #ifdef STACK_GROWS_DOWNWARD
75 #define STACK_PUSH_CODE PRE_DEC
76 #else
77 #define STACK_PUSH_CODE PRE_INC
78 #endif
79 #endif
82 /* If this is nonzero, we do not bother generating VOLATILE
83 around volatile memory references, and we are willing to
84 output indirect addresses. If cse is to follow, we reject
85 indirect addresses so a useful potential cse is generated;
86 if it is used only once, instruction combination will produce
87 the same indirect address eventually. */
88 int cse_not_expected;
90 /* This structure is used by move_by_pieces to describe the move to
91 be performed. */
92 struct move_by_pieces
94 rtx to;
95 rtx to_addr;
96 int autinc_to;
97 int explicit_inc_to;
98 rtx from;
99 rtx from_addr;
100 int autinc_from;
101 int explicit_inc_from;
102 unsigned HOST_WIDE_INT len;
103 HOST_WIDE_INT offset;
104 int reverse;
107 /* This structure is used by store_by_pieces to describe the clear to
108 be performed. */
110 struct store_by_pieces
112 rtx to;
113 rtx to_addr;
114 int autinc_to;
115 int explicit_inc_to;
116 unsigned HOST_WIDE_INT len;
117 HOST_WIDE_INT offset;
118 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
119 void *constfundata;
120 int reverse;
123 static unsigned HOST_WIDE_INT move_by_pieces_ninsns (unsigned HOST_WIDE_INT,
124 unsigned int,
125 unsigned int);
126 static void move_by_pieces_1 (rtx (*) (rtx, ...), enum machine_mode,
127 struct move_by_pieces *);
128 static bool block_move_libcall_safe_for_call_parm (void);
129 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned, unsigned, HOST_WIDE_INT);
130 static tree emit_block_move_libcall_fn (int);
131 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
132 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
133 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
134 static void store_by_pieces_1 (struct store_by_pieces *, unsigned int);
135 static void store_by_pieces_2 (rtx (*) (rtx, ...), enum machine_mode,
136 struct store_by_pieces *);
137 static tree clear_storage_libcall_fn (int);
138 static rtx compress_float_constant (rtx, rtx);
139 static rtx get_subtarget (rtx);
140 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
141 HOST_WIDE_INT, enum machine_mode,
142 tree, tree, int, int);
143 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
144 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT, enum machine_mode,
145 tree, tree, int);
147 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (tree, tree);
149 static int is_aligning_offset (tree, tree);
150 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
151 enum expand_modifier);
152 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
153 static rtx do_store_flag (tree, rtx, enum machine_mode, int);
154 #ifdef PUSH_ROUNDING
155 static void emit_single_push_insn (enum machine_mode, rtx, tree);
156 #endif
157 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx);
158 static rtx const_vector_from_tree (tree);
159 static void write_complex_part (rtx, rtx, bool);
161 /* Record for each mode whether we can move a register directly to or
162 from an object of that mode in memory. If we can't, we won't try
163 to use that mode directly when accessing a field of that mode. */
165 static char direct_load[NUM_MACHINE_MODES];
166 static char direct_store[NUM_MACHINE_MODES];
168 /* Record for each mode whether we can float-extend from memory. */
170 static bool float_extend_from_mem[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
172 /* This macro is used to determine whether move_by_pieces should be called
173 to perform a structure copy. */
174 #ifndef MOVE_BY_PIECES_P
175 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
176 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
177 < (unsigned int) MOVE_RATIO)
178 #endif
180 /* This macro is used to determine whether clear_by_pieces should be
181 called to clear storage. */
182 #ifndef CLEAR_BY_PIECES_P
183 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
184 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
185 < (unsigned int) CLEAR_RATIO)
186 #endif
188 /* This macro is used to determine whether store_by_pieces should be
189 called to "memset" storage with byte values other than zero, or
190 to "memcpy" storage when the source is a constant string. */
191 #ifndef STORE_BY_PIECES_P
192 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
193 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
194 < (unsigned int) MOVE_RATIO)
195 #endif
197 /* This array records the insn_code of insns to perform block moves. */
198 enum insn_code movmem_optab[NUM_MACHINE_MODES];
200 /* This array records the insn_code of insns to perform block sets. */
201 enum insn_code setmem_optab[NUM_MACHINE_MODES];
203 /* These arrays record the insn_code of three different kinds of insns
204 to perform block compares. */
205 enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
206 enum insn_code cmpstrn_optab[NUM_MACHINE_MODES];
207 enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
209 /* Synchronization primitives. */
210 enum insn_code sync_add_optab[NUM_MACHINE_MODES];
211 enum insn_code sync_sub_optab[NUM_MACHINE_MODES];
212 enum insn_code sync_ior_optab[NUM_MACHINE_MODES];
213 enum insn_code sync_and_optab[NUM_MACHINE_MODES];
214 enum insn_code sync_xor_optab[NUM_MACHINE_MODES];
215 enum insn_code sync_nand_optab[NUM_MACHINE_MODES];
216 enum insn_code sync_old_add_optab[NUM_MACHINE_MODES];
217 enum insn_code sync_old_sub_optab[NUM_MACHINE_MODES];
218 enum insn_code sync_old_ior_optab[NUM_MACHINE_MODES];
219 enum insn_code sync_old_and_optab[NUM_MACHINE_MODES];
220 enum insn_code sync_old_xor_optab[NUM_MACHINE_MODES];
221 enum insn_code sync_old_nand_optab[NUM_MACHINE_MODES];
222 enum insn_code sync_new_add_optab[NUM_MACHINE_MODES];
223 enum insn_code sync_new_sub_optab[NUM_MACHINE_MODES];
224 enum insn_code sync_new_ior_optab[NUM_MACHINE_MODES];
225 enum insn_code sync_new_and_optab[NUM_MACHINE_MODES];
226 enum insn_code sync_new_xor_optab[NUM_MACHINE_MODES];
227 enum insn_code sync_new_nand_optab[NUM_MACHINE_MODES];
228 enum insn_code sync_compare_and_swap[NUM_MACHINE_MODES];
229 enum insn_code sync_compare_and_swap_cc[NUM_MACHINE_MODES];
230 enum insn_code sync_lock_test_and_set[NUM_MACHINE_MODES];
231 enum insn_code sync_lock_release[NUM_MACHINE_MODES];
233 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
235 #ifndef SLOW_UNALIGNED_ACCESS
236 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
237 #endif
239 /* This is run once per compilation to set up which modes can be used
240 directly in memory and to initialize the block move optab. */
242 void
243 init_expr_once (void)
245 rtx insn, pat;
246 enum machine_mode mode;
247 int num_clobbers;
248 rtx mem, mem1;
249 rtx reg;
251 /* Try indexing by frame ptr and try by stack ptr.
252 It is known that on the Convex the stack ptr isn't a valid index.
253 With luck, one or the other is valid on any machine. */
254 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
255 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
257 /* A scratch register we can modify in-place below to avoid
258 useless RTL allocations. */
259 reg = gen_rtx_REG (VOIDmode, -1);
261 insn = rtx_alloc (INSN);
262 pat = gen_rtx_SET (0, NULL_RTX, NULL_RTX);
263 PATTERN (insn) = pat;
265 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
266 mode = (enum machine_mode) ((int) mode + 1))
268 int regno;
270 direct_load[(int) mode] = direct_store[(int) mode] = 0;
271 PUT_MODE (mem, mode);
272 PUT_MODE (mem1, mode);
273 PUT_MODE (reg, mode);
275 /* See if there is some register that can be used in this mode and
276 directly loaded or stored from memory. */
278 if (mode != VOIDmode && mode != BLKmode)
279 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
280 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
281 regno++)
283 if (! HARD_REGNO_MODE_OK (regno, mode))
284 continue;
286 REGNO (reg) = regno;
288 SET_SRC (pat) = mem;
289 SET_DEST (pat) = reg;
290 if (recog (pat, insn, &num_clobbers) >= 0)
291 direct_load[(int) mode] = 1;
293 SET_SRC (pat) = mem1;
294 SET_DEST (pat) = reg;
295 if (recog (pat, insn, &num_clobbers) >= 0)
296 direct_load[(int) mode] = 1;
298 SET_SRC (pat) = reg;
299 SET_DEST (pat) = mem;
300 if (recog (pat, insn, &num_clobbers) >= 0)
301 direct_store[(int) mode] = 1;
303 SET_SRC (pat) = reg;
304 SET_DEST (pat) = mem1;
305 if (recog (pat, insn, &num_clobbers) >= 0)
306 direct_store[(int) mode] = 1;
310 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
312 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
313 mode = GET_MODE_WIDER_MODE (mode))
315 enum machine_mode srcmode;
316 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
317 srcmode = GET_MODE_WIDER_MODE (srcmode))
319 enum insn_code ic;
321 ic = can_extend_p (mode, srcmode, 0);
322 if (ic == CODE_FOR_nothing)
323 continue;
325 PUT_MODE (mem, srcmode);
327 if ((*insn_data[ic].operand[1].predicate) (mem, srcmode))
328 float_extend_from_mem[mode][srcmode] = true;
333 /* This is run at the start of compiling a function. */
335 void
336 init_expr (void)
338 cfun->expr = ggc_alloc_cleared (sizeof (struct expr_status));
341 /* Copy data from FROM to TO, where the machine modes are not the same.
342 Both modes may be integer, or both may be floating.
343 UNSIGNEDP should be nonzero if FROM is an unsigned type.
344 This causes zero-extension instead of sign-extension. */
346 void
347 convert_move (rtx to, rtx from, int unsignedp)
349 enum machine_mode to_mode = GET_MODE (to);
350 enum machine_mode from_mode = GET_MODE (from);
351 int to_real = SCALAR_FLOAT_MODE_P (to_mode);
352 int from_real = SCALAR_FLOAT_MODE_P (from_mode);
353 enum insn_code code;
354 rtx libcall;
356 /* rtx code for making an equivalent value. */
357 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
358 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
361 gcc_assert (to_real == from_real);
363 /* If the source and destination are already the same, then there's
364 nothing to do. */
365 if (to == from)
366 return;
368 /* If FROM is a SUBREG that indicates that we have already done at least
369 the required extension, strip it. We don't handle such SUBREGs as
370 TO here. */
372 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
373 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
374 >= GET_MODE_SIZE (to_mode))
375 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
376 from = gen_lowpart (to_mode, from), from_mode = to_mode;
378 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
380 if (to_mode == from_mode
381 || (from_mode == VOIDmode && CONSTANT_P (from)))
383 emit_move_insn (to, from);
384 return;
387 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
389 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
391 if (VECTOR_MODE_P (to_mode))
392 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
393 else
394 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
396 emit_move_insn (to, from);
397 return;
400 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
402 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
403 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
404 return;
407 if (to_real)
409 rtx value, insns;
410 convert_optab tab;
412 gcc_assert ((GET_MODE_PRECISION (from_mode)
413 != GET_MODE_PRECISION (to_mode))
414 || (DECIMAL_FLOAT_MODE_P (from_mode)
415 != DECIMAL_FLOAT_MODE_P (to_mode)));
417 if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
418 /* Conversion between decimal float and binary float, same size. */
419 tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
420 else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
421 tab = sext_optab;
422 else
423 tab = trunc_optab;
425 /* Try converting directly if the insn is supported. */
427 code = tab->handlers[to_mode][from_mode].insn_code;
428 if (code != CODE_FOR_nothing)
430 emit_unop_insn (code, to, from,
431 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
432 return;
435 /* Otherwise use a libcall. */
436 libcall = tab->handlers[to_mode][from_mode].libfunc;
438 /* Is this conversion implemented yet? */
439 gcc_assert (libcall);
441 start_sequence ();
442 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
443 1, from, from_mode);
444 insns = get_insns ();
445 end_sequence ();
446 emit_libcall_block (insns, to, value,
447 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
448 from)
449 : gen_rtx_FLOAT_EXTEND (to_mode, from));
450 return;
453 /* Handle pointer conversion. */ /* SPEE 900220. */
454 /* Targets are expected to provide conversion insns between PxImode and
455 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
456 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
458 enum machine_mode full_mode
459 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
461 gcc_assert (trunc_optab->handlers[to_mode][full_mode].insn_code
462 != CODE_FOR_nothing);
464 if (full_mode != from_mode)
465 from = convert_to_mode (full_mode, from, unsignedp);
466 emit_unop_insn (trunc_optab->handlers[to_mode][full_mode].insn_code,
467 to, from, UNKNOWN);
468 return;
470 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
472 rtx new_from;
473 enum machine_mode full_mode
474 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
476 gcc_assert (sext_optab->handlers[full_mode][from_mode].insn_code
477 != CODE_FOR_nothing);
479 if (to_mode == full_mode)
481 emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
482 to, from, UNKNOWN);
483 return;
486 new_from = gen_reg_rtx (full_mode);
487 emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
488 new_from, from, UNKNOWN);
490 /* else proceed to integer conversions below. */
491 from_mode = full_mode;
492 from = new_from;
495 /* Now both modes are integers. */
497 /* Handle expanding beyond a word. */
498 if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
499 && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
501 rtx insns;
502 rtx lowpart;
503 rtx fill_value;
504 rtx lowfrom;
505 int i;
506 enum machine_mode lowpart_mode;
507 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
509 /* Try converting directly if the insn is supported. */
510 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
511 != CODE_FOR_nothing)
513 /* If FROM is a SUBREG, put it into a register. Do this
514 so that we always generate the same set of insns for
515 better cse'ing; if an intermediate assignment occurred,
516 we won't be doing the operation directly on the SUBREG. */
517 if (optimize > 0 && GET_CODE (from) == SUBREG)
518 from = force_reg (from_mode, from);
519 emit_unop_insn (code, to, from, equiv_code);
520 return;
522 /* Next, try converting via full word. */
523 else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
524 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
525 != CODE_FOR_nothing))
527 if (REG_P (to))
529 if (reg_overlap_mentioned_p (to, from))
530 from = force_reg (from_mode, from);
531 emit_insn (gen_rtx_CLOBBER (VOIDmode, to));
533 convert_move (gen_lowpart (word_mode, to), from, unsignedp);
534 emit_unop_insn (code, to,
535 gen_lowpart (word_mode, to), equiv_code);
536 return;
539 /* No special multiword conversion insn; do it by hand. */
540 start_sequence ();
542 /* Since we will turn this into a no conflict block, we must ensure
543 that the source does not overlap the target. */
545 if (reg_overlap_mentioned_p (to, from))
546 from = force_reg (from_mode, from);
548 /* Get a copy of FROM widened to a word, if necessary. */
549 if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
550 lowpart_mode = word_mode;
551 else
552 lowpart_mode = from_mode;
554 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
556 lowpart = gen_lowpart (lowpart_mode, to);
557 emit_move_insn (lowpart, lowfrom);
559 /* Compute the value to put in each remaining word. */
560 if (unsignedp)
561 fill_value = const0_rtx;
562 else
564 #ifdef HAVE_slt
565 if (HAVE_slt
566 && insn_data[(int) CODE_FOR_slt].operand[0].mode == word_mode
567 && STORE_FLAG_VALUE == -1)
569 emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
570 lowpart_mode, 0);
571 fill_value = gen_reg_rtx (word_mode);
572 emit_insn (gen_slt (fill_value));
574 else
575 #endif
577 fill_value
578 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
579 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
580 NULL_RTX, 0);
581 fill_value = convert_to_mode (word_mode, fill_value, 1);
585 /* Fill the remaining words. */
586 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
588 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
589 rtx subword = operand_subword (to, index, 1, to_mode);
591 gcc_assert (subword);
593 if (fill_value != subword)
594 emit_move_insn (subword, fill_value);
597 insns = get_insns ();
598 end_sequence ();
600 emit_no_conflict_block (insns, to, from, NULL_RTX,
601 gen_rtx_fmt_e (equiv_code, to_mode, copy_rtx (from)));
602 return;
605 /* Truncating multi-word to a word or less. */
606 if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
607 && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
609 if (!((MEM_P (from)
610 && ! MEM_VOLATILE_P (from)
611 && direct_load[(int) to_mode]
612 && ! mode_dependent_address_p (XEXP (from, 0)))
613 || REG_P (from)
614 || GET_CODE (from) == SUBREG))
615 from = force_reg (from_mode, from);
616 convert_move (to, gen_lowpart (word_mode, from), 0);
617 return;
620 /* Now follow all the conversions between integers
621 no more than a word long. */
623 /* For truncation, usually we can just refer to FROM in a narrower mode. */
624 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
625 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
626 GET_MODE_BITSIZE (from_mode)))
628 if (!((MEM_P (from)
629 && ! MEM_VOLATILE_P (from)
630 && direct_load[(int) to_mode]
631 && ! mode_dependent_address_p (XEXP (from, 0)))
632 || REG_P (from)
633 || GET_CODE (from) == SUBREG))
634 from = force_reg (from_mode, from);
635 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
636 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
637 from = copy_to_reg (from);
638 emit_move_insn (to, gen_lowpart (to_mode, from));
639 return;
642 /* Handle extension. */
643 if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
645 /* Convert directly if that works. */
646 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
647 != CODE_FOR_nothing)
649 emit_unop_insn (code, to, from, equiv_code);
650 return;
652 else
654 enum machine_mode intermediate;
655 rtx tmp;
656 tree shift_amount;
658 /* Search for a mode to convert via. */
659 for (intermediate = from_mode; intermediate != VOIDmode;
660 intermediate = GET_MODE_WIDER_MODE (intermediate))
661 if (((can_extend_p (to_mode, intermediate, unsignedp)
662 != CODE_FOR_nothing)
663 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
664 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
665 GET_MODE_BITSIZE (intermediate))))
666 && (can_extend_p (intermediate, from_mode, unsignedp)
667 != CODE_FOR_nothing))
669 convert_move (to, convert_to_mode (intermediate, from,
670 unsignedp), unsignedp);
671 return;
674 /* No suitable intermediate mode.
675 Generate what we need with shifts. */
676 shift_amount = build_int_cst (NULL_TREE,
677 GET_MODE_BITSIZE (to_mode)
678 - GET_MODE_BITSIZE (from_mode));
679 from = gen_lowpart (to_mode, force_reg (from_mode, from));
680 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
681 to, unsignedp);
682 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
683 to, unsignedp);
684 if (tmp != to)
685 emit_move_insn (to, tmp);
686 return;
690 /* Support special truncate insns for certain modes. */
691 if (trunc_optab->handlers[to_mode][from_mode].insn_code != CODE_FOR_nothing)
693 emit_unop_insn (trunc_optab->handlers[to_mode][from_mode].insn_code,
694 to, from, UNKNOWN);
695 return;
698 /* Handle truncation of volatile memrefs, and so on;
699 the things that couldn't be truncated directly,
700 and for which there was no special instruction.
702 ??? Code above formerly short-circuited this, for most integer
703 mode pairs, with a force_reg in from_mode followed by a recursive
704 call to this routine. Appears always to have been wrong. */
705 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
707 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
708 emit_move_insn (to, temp);
709 return;
712 /* Mode combination is not recognized. */
713 gcc_unreachable ();
716 /* Return an rtx for a value that would result
717 from converting X to mode MODE.
718 Both X and MODE may be floating, or both integer.
719 UNSIGNEDP is nonzero if X is an unsigned value.
720 This can be done by referring to a part of X in place
721 or by copying to a new temporary with conversion. */
724 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
726 return convert_modes (mode, VOIDmode, x, unsignedp);
729 /* Return an rtx for a value that would result
730 from converting X from mode OLDMODE to mode MODE.
731 Both modes may be floating, or both integer.
732 UNSIGNEDP is nonzero if X is an unsigned value.
734 This can be done by referring to a part of X in place
735 or by copying to a new temporary with conversion.
737 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
740 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
742 rtx temp;
744 /* If FROM is a SUBREG that indicates that we have already done at least
745 the required extension, strip it. */
747 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
748 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
749 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
750 x = gen_lowpart (mode, x);
752 if (GET_MODE (x) != VOIDmode)
753 oldmode = GET_MODE (x);
755 if (mode == oldmode)
756 return x;
758 /* There is one case that we must handle specially: If we are converting
759 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
760 we are to interpret the constant as unsigned, gen_lowpart will do
761 the wrong if the constant appears negative. What we want to do is
762 make the high-order word of the constant zero, not all ones. */
764 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
765 && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
766 && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
768 HOST_WIDE_INT val = INTVAL (x);
770 if (oldmode != VOIDmode
771 && HOST_BITS_PER_WIDE_INT > GET_MODE_BITSIZE (oldmode))
773 int width = GET_MODE_BITSIZE (oldmode);
775 /* We need to zero extend VAL. */
776 val &= ((HOST_WIDE_INT) 1 << width) - 1;
779 return immed_double_const (val, (HOST_WIDE_INT) 0, mode);
782 /* We can do this with a gen_lowpart if both desired and current modes
783 are integer, and this is either a constant integer, a register, or a
784 non-volatile MEM. Except for the constant case where MODE is no
785 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
787 if ((GET_CODE (x) == CONST_INT
788 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
789 || (GET_MODE_CLASS (mode) == MODE_INT
790 && GET_MODE_CLASS (oldmode) == MODE_INT
791 && (GET_CODE (x) == CONST_DOUBLE
792 || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
793 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
794 && direct_load[(int) mode])
795 || (REG_P (x)
796 && (! HARD_REGISTER_P (x)
797 || HARD_REGNO_MODE_OK (REGNO (x), mode))
798 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
799 GET_MODE_BITSIZE (GET_MODE (x)))))))))
801 /* ?? If we don't know OLDMODE, we have to assume here that
802 X does not need sign- or zero-extension. This may not be
803 the case, but it's the best we can do. */
804 if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
805 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
807 HOST_WIDE_INT val = INTVAL (x);
808 int width = GET_MODE_BITSIZE (oldmode);
810 /* We must sign or zero-extend in this case. Start by
811 zero-extending, then sign extend if we need to. */
812 val &= ((HOST_WIDE_INT) 1 << width) - 1;
813 if (! unsignedp
814 && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
815 val |= (HOST_WIDE_INT) (-1) << width;
817 return gen_int_mode (val, mode);
820 return gen_lowpart (mode, x);
823 /* Converting from integer constant into mode is always equivalent to an
824 subreg operation. */
825 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
827 gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
828 return simplify_gen_subreg (mode, x, oldmode, 0);
831 temp = gen_reg_rtx (mode);
832 convert_move (temp, x, unsignedp);
833 return temp;
836 /* STORE_MAX_PIECES is the number of bytes at a time that we can
837 store efficiently. Due to internal GCC limitations, this is
838 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
839 for an immediate constant. */
841 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
843 /* Determine whether the LEN bytes can be moved by using several move
844 instructions. Return nonzero if a call to move_by_pieces should
845 succeed. */
848 can_move_by_pieces (unsigned HOST_WIDE_INT len,
849 unsigned int align ATTRIBUTE_UNUSED)
851 return MOVE_BY_PIECES_P (len, align);
854 /* Generate several move instructions to copy LEN bytes from block FROM to
855 block TO. (These are MEM rtx's with BLKmode).
857 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
858 used to push FROM to the stack.
860 ALIGN is maximum stack alignment we can assume.
862 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
863 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
864 stpcpy. */
867 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
868 unsigned int align, int endp)
870 struct move_by_pieces data;
871 rtx to_addr, from_addr = XEXP (from, 0);
872 unsigned int max_size = MOVE_MAX_PIECES + 1;
873 enum machine_mode mode = VOIDmode, tmode;
874 enum insn_code icode;
876 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
878 data.offset = 0;
879 data.from_addr = from_addr;
880 if (to)
882 to_addr = XEXP (to, 0);
883 data.to = to;
884 data.autinc_to
885 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
886 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
887 data.reverse
888 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
890 else
892 to_addr = NULL_RTX;
893 data.to = NULL_RTX;
894 data.autinc_to = 1;
895 #ifdef STACK_GROWS_DOWNWARD
896 data.reverse = 1;
897 #else
898 data.reverse = 0;
899 #endif
901 data.to_addr = to_addr;
902 data.from = from;
903 data.autinc_from
904 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
905 || GET_CODE (from_addr) == POST_INC
906 || GET_CODE (from_addr) == POST_DEC);
908 data.explicit_inc_from = 0;
909 data.explicit_inc_to = 0;
910 if (data.reverse) data.offset = len;
911 data.len = len;
913 /* If copying requires more than two move insns,
914 copy addresses to registers (to make displacements shorter)
915 and use post-increment if available. */
916 if (!(data.autinc_from && data.autinc_to)
917 && move_by_pieces_ninsns (len, align, max_size) > 2)
919 /* Find the mode of the largest move... */
920 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
921 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
922 if (GET_MODE_SIZE (tmode) < max_size)
923 mode = tmode;
925 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
927 data.from_addr = copy_addr_to_reg (plus_constant (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_addr_to_reg (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_addr_to_reg (from_addr);
939 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
941 data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
942 data.autinc_to = 1;
943 data.explicit_inc_to = -1;
945 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
947 data.to_addr = copy_addr_to_reg (to_addr);
948 data.autinc_to = 1;
949 data.explicit_inc_to = 1;
951 if (!data.autinc_to && CONSTANT_P (to_addr))
952 data.to_addr = copy_addr_to_reg (to_addr);
955 tmode = mode_for_size (MOVE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
956 if (align >= GET_MODE_ALIGNMENT (tmode))
957 align = GET_MODE_ALIGNMENT (tmode);
958 else
960 enum machine_mode xmode;
962 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
963 tmode != VOIDmode;
964 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
965 if (GET_MODE_SIZE (tmode) > MOVE_MAX_PIECES
966 || SLOW_UNALIGNED_ACCESS (tmode, align))
967 break;
969 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
972 /* First move what we can in the largest integer mode, then go to
973 successively smaller modes. */
975 while (max_size > 1)
977 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
978 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
979 if (GET_MODE_SIZE (tmode) < max_size)
980 mode = tmode;
982 if (mode == VOIDmode)
983 break;
985 icode = mov_optab->handlers[(int) mode].insn_code;
986 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
987 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
989 max_size = GET_MODE_SIZE (mode);
992 /* The code above should have handled everything. */
993 gcc_assert (!data.len);
995 if (endp)
997 rtx to1;
999 gcc_assert (!data.reverse);
1000 if (data.autinc_to)
1002 if (endp == 2)
1004 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
1005 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
1006 else
1007 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
1008 -1));
1010 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
1011 data.offset);
1013 else
1015 if (endp == 2)
1016 --data.offset;
1017 to1 = adjust_address (data.to, QImode, data.offset);
1019 return to1;
1021 else
1022 return data.to;
1025 /* Return number of insns required to move L bytes by pieces.
1026 ALIGN (in bits) is maximum alignment we can assume. */
1028 static unsigned HOST_WIDE_INT
1029 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1030 unsigned int max_size)
1032 unsigned HOST_WIDE_INT n_insns = 0;
1033 enum machine_mode tmode;
1035 tmode = mode_for_size (MOVE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
1036 if (align >= GET_MODE_ALIGNMENT (tmode))
1037 align = GET_MODE_ALIGNMENT (tmode);
1038 else
1040 enum machine_mode tmode, xmode;
1042 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
1043 tmode != VOIDmode;
1044 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
1045 if (GET_MODE_SIZE (tmode) > MOVE_MAX_PIECES
1046 || SLOW_UNALIGNED_ACCESS (tmode, align))
1047 break;
1049 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
1052 while (max_size > 1)
1054 enum machine_mode mode = VOIDmode;
1055 enum insn_code icode;
1057 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1058 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1059 if (GET_MODE_SIZE (tmode) < max_size)
1060 mode = tmode;
1062 if (mode == VOIDmode)
1063 break;
1065 icode = mov_optab->handlers[(int) mode].insn_code;
1066 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1067 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1069 max_size = GET_MODE_SIZE (mode);
1072 gcc_assert (!l);
1073 return n_insns;
1076 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1077 with move instructions for mode MODE. GENFUN is the gen_... function
1078 to make a move insn for that mode. DATA has all the other info. */
1080 static void
1081 move_by_pieces_1 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
1082 struct move_by_pieces *data)
1084 unsigned int size = GET_MODE_SIZE (mode);
1085 rtx to1 = NULL_RTX, from1;
1087 while (data->len >= size)
1089 if (data->reverse)
1090 data->offset -= size;
1092 if (data->to)
1094 if (data->autinc_to)
1095 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1096 data->offset);
1097 else
1098 to1 = adjust_address (data->to, mode, data->offset);
1101 if (data->autinc_from)
1102 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1103 data->offset);
1104 else
1105 from1 = adjust_address (data->from, mode, data->offset);
1107 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1108 emit_insn (gen_add2_insn (data->to_addr,
1109 GEN_INT (-(HOST_WIDE_INT)size)));
1110 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1111 emit_insn (gen_add2_insn (data->from_addr,
1112 GEN_INT (-(HOST_WIDE_INT)size)));
1114 if (data->to)
1115 emit_insn ((*genfun) (to1, from1));
1116 else
1118 #ifdef PUSH_ROUNDING
1119 emit_single_push_insn (mode, from1, NULL);
1120 #else
1121 gcc_unreachable ();
1122 #endif
1125 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1126 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1127 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1128 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1130 if (! data->reverse)
1131 data->offset += size;
1133 data->len -= size;
1137 /* Emit code to move a block Y to a block X. This may be done with
1138 string-move instructions, with multiple scalar move instructions,
1139 or with a library call.
1141 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1142 SIZE is an rtx that says how long they are.
1143 ALIGN is the maximum alignment we can assume they have.
1144 METHOD describes what kind of copy this is, and what mechanisms may be used.
1146 Return the address of the new block, if memcpy is called and returns it,
1147 0 otherwise. */
1150 emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
1151 unsigned int expected_align, HOST_WIDE_INT expected_size)
1153 bool may_use_call;
1154 rtx retval = 0;
1155 unsigned int align;
1157 switch (method)
1159 case BLOCK_OP_NORMAL:
1160 case BLOCK_OP_TAILCALL:
1161 may_use_call = true;
1162 break;
1164 case BLOCK_OP_CALL_PARM:
1165 may_use_call = block_move_libcall_safe_for_call_parm ();
1167 /* Make inhibit_defer_pop nonzero around the library call
1168 to force it to pop the arguments right away. */
1169 NO_DEFER_POP;
1170 break;
1172 case BLOCK_OP_NO_LIBCALL:
1173 may_use_call = false;
1174 break;
1176 default:
1177 gcc_unreachable ();
1180 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1182 gcc_assert (MEM_P (x));
1183 gcc_assert (MEM_P (y));
1184 gcc_assert (size);
1186 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1187 block copy is more efficient for other large modes, e.g. DCmode. */
1188 x = adjust_address (x, BLKmode, 0);
1189 y = adjust_address (y, BLKmode, 0);
1191 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1192 can be incorrect is coming from __builtin_memcpy. */
1193 if (GET_CODE (size) == CONST_INT)
1195 if (INTVAL (size) == 0)
1196 return 0;
1198 x = shallow_copy_rtx (x);
1199 y = shallow_copy_rtx (y);
1200 set_mem_size (x, size);
1201 set_mem_size (y, size);
1204 if (GET_CODE (size) == CONST_INT && MOVE_BY_PIECES_P (INTVAL (size), align))
1205 move_by_pieces (x, y, INTVAL (size), align, 0);
1206 else if (emit_block_move_via_movmem (x, y, size, align,
1207 expected_align, expected_size))
1209 else if (may_use_call)
1210 retval = emit_block_move_via_libcall (x, y, size,
1211 method == BLOCK_OP_TAILCALL);
1212 else
1213 emit_block_move_via_loop (x, y, size, align);
1215 if (method == BLOCK_OP_CALL_PARM)
1216 OK_DEFER_POP;
1218 return retval;
1222 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1224 return emit_block_move_hints (x, y, size, method, 0, -1);
1227 /* A subroutine of emit_block_move. Returns true if calling the
1228 block move libcall will not clobber any parameters which may have
1229 already been placed on the stack. */
1231 static bool
1232 block_move_libcall_safe_for_call_parm (void)
1234 /* If arguments are pushed on the stack, then they're safe. */
1235 if (PUSH_ARGS)
1236 return true;
1238 /* If registers go on the stack anyway, any argument is sure to clobber
1239 an outgoing argument. */
1240 #if defined (REG_PARM_STACK_SPACE)
1241 if (OUTGOING_REG_PARM_STACK_SPACE)
1243 tree fn;
1244 fn = emit_block_move_libcall_fn (false);
1245 if (REG_PARM_STACK_SPACE (fn) != 0)
1246 return false;
1248 #endif
1250 /* If any argument goes in memory, then it might clobber an outgoing
1251 argument. */
1253 CUMULATIVE_ARGS args_so_far;
1254 tree fn, arg;
1256 fn = emit_block_move_libcall_fn (false);
1257 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fn), NULL_RTX, 0, 3);
1259 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1260 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1262 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1263 rtx tmp = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
1264 if (!tmp || !REG_P (tmp))
1265 return false;
1266 if (targetm.calls.arg_partial_bytes (&args_so_far, mode, NULL, 1))
1267 return false;
1268 FUNCTION_ARG_ADVANCE (args_so_far, mode, NULL_TREE, 1);
1271 return true;
1274 /* A subroutine of emit_block_move. Expand a movmem pattern;
1275 return true if successful. */
1277 static bool
1278 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
1279 unsigned int expected_align, HOST_WIDE_INT expected_size)
1281 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
1282 int save_volatile_ok = volatile_ok;
1283 enum machine_mode mode;
1285 if (expected_align < align)
1286 expected_align = align;
1288 /* Since this is a move insn, we don't care about volatility. */
1289 volatile_ok = 1;
1291 /* Try the most limited insn first, because there's no point
1292 including more than one in the machine description unless
1293 the more limited one has some advantage. */
1295 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1296 mode = GET_MODE_WIDER_MODE (mode))
1298 enum insn_code code = movmem_optab[(int) mode];
1299 insn_operand_predicate_fn pred;
1301 if (code != CODE_FOR_nothing
1302 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1303 here because if SIZE is less than the mode mask, as it is
1304 returned by the macro, it will definitely be less than the
1305 actual mode mask. */
1306 && ((GET_CODE (size) == CONST_INT
1307 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1308 <= (GET_MODE_MASK (mode) >> 1)))
1309 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1310 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
1311 || (*pred) (x, BLKmode))
1312 && ((pred = insn_data[(int) code].operand[1].predicate) == 0
1313 || (*pred) (y, BLKmode))
1314 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
1315 || (*pred) (opalign, VOIDmode)))
1317 rtx op2;
1318 rtx last = get_last_insn ();
1319 rtx pat;
1321 op2 = convert_to_mode (mode, size, 1);
1322 pred = insn_data[(int) code].operand[2].predicate;
1323 if (pred != 0 && ! (*pred) (op2, mode))
1324 op2 = copy_to_mode_reg (mode, op2);
1326 /* ??? When called via emit_block_move_for_call, it'd be
1327 nice if there were some way to inform the backend, so
1328 that it doesn't fail the expansion because it thinks
1329 emitting the libcall would be more efficient. */
1331 if (insn_data[(int) code].n_operands == 4)
1332 pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1333 else
1334 pat = GEN_FCN ((int) code) (x, y, op2, opalign,
1335 GEN_INT (expected_align),
1336 GEN_INT (expected_size));
1337 if (pat)
1339 emit_insn (pat);
1340 volatile_ok = save_volatile_ok;
1341 return true;
1343 else
1344 delete_insns_since (last);
1348 volatile_ok = save_volatile_ok;
1349 return false;
1352 /* A subroutine of emit_block_move. Expand a call to memcpy.
1353 Return the return value from memcpy, 0 otherwise. */
1356 emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
1358 rtx dst_addr, src_addr;
1359 tree call_expr, fn, src_tree, dst_tree, size_tree;
1360 enum machine_mode size_mode;
1361 rtx retval;
1363 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1364 pseudos. We can then place those new pseudos into a VAR_DECL and
1365 use them later. */
1367 dst_addr = copy_to_mode_reg (Pmode, XEXP (dst, 0));
1368 src_addr = copy_to_mode_reg (Pmode, XEXP (src, 0));
1370 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1371 src_addr = convert_memory_address (ptr_mode, src_addr);
1373 dst_tree = make_tree (ptr_type_node, dst_addr);
1374 src_tree = make_tree (ptr_type_node, src_addr);
1376 size_mode = TYPE_MODE (sizetype);
1378 size = convert_to_mode (size_mode, size, 1);
1379 size = copy_to_mode_reg (size_mode, size);
1381 /* It is incorrect to use the libcall calling conventions to call
1382 memcpy in this context. This could be a user call to memcpy and
1383 the user may wish to examine the return value from memcpy. For
1384 targets where libcalls and normal calls have different conventions
1385 for returning pointers, we could end up generating incorrect code. */
1387 size_tree = make_tree (sizetype, size);
1389 fn = emit_block_move_libcall_fn (true);
1390 call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
1391 CALL_EXPR_TAILCALL (call_expr) = tailcall;
1393 retval = expand_normal (call_expr);
1395 return retval;
1398 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1399 for the function we use for block copies. The first time FOR_CALL
1400 is true, we call assemble_external. */
1402 static GTY(()) tree block_move_fn;
1404 void
1405 init_block_move_fn (const char *asmspec)
1407 if (!block_move_fn)
1409 tree args, fn;
1411 fn = get_identifier ("memcpy");
1412 args = build_function_type_list (ptr_type_node, ptr_type_node,
1413 const_ptr_type_node, sizetype,
1414 NULL_TREE);
1416 fn = build_decl (FUNCTION_DECL, fn, args);
1417 DECL_EXTERNAL (fn) = 1;
1418 TREE_PUBLIC (fn) = 1;
1419 DECL_ARTIFICIAL (fn) = 1;
1420 TREE_NOTHROW (fn) = 1;
1421 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
1422 DECL_VISIBILITY_SPECIFIED (fn) = 1;
1424 block_move_fn = fn;
1427 if (asmspec)
1428 set_user_assembler_name (block_move_fn, asmspec);
1431 static tree
1432 emit_block_move_libcall_fn (int for_call)
1434 static bool emitted_extern;
1436 if (!block_move_fn)
1437 init_block_move_fn (NULL);
1439 if (for_call && !emitted_extern)
1441 emitted_extern = true;
1442 make_decl_rtl (block_move_fn);
1443 assemble_external (block_move_fn);
1446 return block_move_fn;
1449 /* A subroutine of emit_block_move. Copy the data via an explicit
1450 loop. This is used only when libcalls are forbidden. */
1451 /* ??? It'd be nice to copy in hunks larger than QImode. */
1453 static void
1454 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1455 unsigned int align ATTRIBUTE_UNUSED)
1457 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1458 enum machine_mode iter_mode;
1460 iter_mode = GET_MODE (size);
1461 if (iter_mode == VOIDmode)
1462 iter_mode = word_mode;
1464 top_label = gen_label_rtx ();
1465 cmp_label = gen_label_rtx ();
1466 iter = gen_reg_rtx (iter_mode);
1468 emit_move_insn (iter, const0_rtx);
1470 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1471 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1472 do_pending_stack_adjust ();
1474 emit_jump (cmp_label);
1475 emit_label (top_label);
1477 tmp = convert_modes (Pmode, iter_mode, iter, true);
1478 x_addr = gen_rtx_PLUS (Pmode, x_addr, tmp);
1479 y_addr = gen_rtx_PLUS (Pmode, y_addr, tmp);
1480 x = change_address (x, QImode, x_addr);
1481 y = change_address (y, QImode, y_addr);
1483 emit_move_insn (x, y);
1485 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1486 true, OPTAB_LIB_WIDEN);
1487 if (tmp != iter)
1488 emit_move_insn (iter, tmp);
1490 emit_label (cmp_label);
1492 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1493 true, top_label);
1496 /* Copy all or part of a value X into registers starting at REGNO.
1497 The number of registers to be filled is NREGS. */
1499 void
1500 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1502 int i;
1503 #ifdef HAVE_load_multiple
1504 rtx pat;
1505 rtx last;
1506 #endif
1508 if (nregs == 0)
1509 return;
1511 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
1512 x = validize_mem (force_const_mem (mode, x));
1514 /* See if the machine can do this with a load multiple insn. */
1515 #ifdef HAVE_load_multiple
1516 if (HAVE_load_multiple)
1518 last = get_last_insn ();
1519 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1520 GEN_INT (nregs));
1521 if (pat)
1523 emit_insn (pat);
1524 return;
1526 else
1527 delete_insns_since (last);
1529 #endif
1531 for (i = 0; i < nregs; i++)
1532 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1533 operand_subword_force (x, i, mode));
1536 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1537 The number of registers to be filled is NREGS. */
1539 void
1540 move_block_from_reg (int regno, rtx x, int nregs)
1542 int i;
1544 if (nregs == 0)
1545 return;
1547 /* See if the machine can do this with a store multiple insn. */
1548 #ifdef HAVE_store_multiple
1549 if (HAVE_store_multiple)
1551 rtx last = get_last_insn ();
1552 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1553 GEN_INT (nregs));
1554 if (pat)
1556 emit_insn (pat);
1557 return;
1559 else
1560 delete_insns_since (last);
1562 #endif
1564 for (i = 0; i < nregs; i++)
1566 rtx tem = operand_subword (x, i, 1, BLKmode);
1568 gcc_assert (tem);
1570 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1574 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1575 ORIG, where ORIG is a non-consecutive group of registers represented by
1576 a PARALLEL. The clone is identical to the original except in that the
1577 original set of registers is replaced by a new set of pseudo registers.
1578 The new set has the same modes as the original set. */
1581 gen_group_rtx (rtx orig)
1583 int i, length;
1584 rtx *tmps;
1586 gcc_assert (GET_CODE (orig) == PARALLEL);
1588 length = XVECLEN (orig, 0);
1589 tmps = alloca (sizeof (rtx) * length);
1591 /* Skip a NULL entry in first slot. */
1592 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1594 if (i)
1595 tmps[0] = 0;
1597 for (; i < length; i++)
1599 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1600 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1602 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1605 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1608 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1609 except that values are placed in TMPS[i], and must later be moved
1610 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1612 static void
1613 emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
1615 rtx src;
1616 int start, i;
1617 enum machine_mode m = GET_MODE (orig_src);
1619 gcc_assert (GET_CODE (dst) == PARALLEL);
1621 if (m != VOIDmode
1622 && !SCALAR_INT_MODE_P (m)
1623 && !MEM_P (orig_src)
1624 && GET_CODE (orig_src) != CONCAT)
1626 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
1627 if (imode == BLKmode)
1628 src = assign_stack_temp (GET_MODE (orig_src), ssize, 0);
1629 else
1630 src = gen_reg_rtx (imode);
1631 if (imode != BLKmode)
1632 src = gen_lowpart (GET_MODE (orig_src), src);
1633 emit_move_insn (src, orig_src);
1634 /* ...and back again. */
1635 if (imode != BLKmode)
1636 src = gen_lowpart (imode, src);
1637 emit_group_load_1 (tmps, dst, src, type, ssize);
1638 return;
1641 /* Check for a NULL entry, used to indicate that the parameter goes
1642 both on the stack and in registers. */
1643 if (XEXP (XVECEXP (dst, 0, 0), 0))
1644 start = 0;
1645 else
1646 start = 1;
1648 /* Process the pieces. */
1649 for (i = start; i < XVECLEN (dst, 0); i++)
1651 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1652 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1653 unsigned int bytelen = GET_MODE_SIZE (mode);
1654 int shift = 0;
1656 /* Handle trailing fragments that run over the size of the struct. */
1657 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1659 /* Arrange to shift the fragment to where it belongs.
1660 extract_bit_field loads to the lsb of the reg. */
1661 if (
1662 #ifdef BLOCK_REG_PADDING
1663 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1664 == (BYTES_BIG_ENDIAN ? upward : downward)
1665 #else
1666 BYTES_BIG_ENDIAN
1667 #endif
1669 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1670 bytelen = ssize - bytepos;
1671 gcc_assert (bytelen > 0);
1674 /* If we won't be loading directly from memory, protect the real source
1675 from strange tricks we might play; but make sure that the source can
1676 be loaded directly into the destination. */
1677 src = orig_src;
1678 if (!MEM_P (orig_src)
1679 && (!CONSTANT_P (orig_src)
1680 || (GET_MODE (orig_src) != mode
1681 && GET_MODE (orig_src) != VOIDmode)))
1683 if (GET_MODE (orig_src) == VOIDmode)
1684 src = gen_reg_rtx (mode);
1685 else
1686 src = gen_reg_rtx (GET_MODE (orig_src));
1688 emit_move_insn (src, orig_src);
1691 /* Optimize the access just a bit. */
1692 if (MEM_P (src)
1693 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1694 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1695 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1696 && bytelen == GET_MODE_SIZE (mode))
1698 tmps[i] = gen_reg_rtx (mode);
1699 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1701 else if (COMPLEX_MODE_P (mode)
1702 && GET_MODE (src) == mode
1703 && bytelen == GET_MODE_SIZE (mode))
1704 /* Let emit_move_complex do the bulk of the work. */
1705 tmps[i] = src;
1706 else if (GET_CODE (src) == CONCAT)
1708 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1709 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1711 if ((bytepos == 0 && bytelen == slen0)
1712 || (bytepos != 0 && bytepos + bytelen <= slen))
1714 /* The following assumes that the concatenated objects all
1715 have the same size. In this case, a simple calculation
1716 can be used to determine the object and the bit field
1717 to be extracted. */
1718 tmps[i] = XEXP (src, bytepos / slen0);
1719 if (! CONSTANT_P (tmps[i])
1720 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1721 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1722 (bytepos % slen0) * BITS_PER_UNIT,
1723 1, NULL_RTX, mode, mode);
1725 else
1727 rtx mem;
1729 gcc_assert (!bytepos);
1730 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1731 emit_move_insn (mem, src);
1732 tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
1733 0, 1, NULL_RTX, mode, mode);
1736 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1737 SIMD register, which is currently broken. While we get GCC
1738 to emit proper RTL for these cases, let's dump to memory. */
1739 else if (VECTOR_MODE_P (GET_MODE (dst))
1740 && REG_P (src))
1742 int slen = GET_MODE_SIZE (GET_MODE (src));
1743 rtx mem;
1745 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1746 emit_move_insn (mem, src);
1747 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1749 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1750 && XVECLEN (dst, 0) > 1)
1751 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE(dst), bytepos);
1752 else if (CONSTANT_P (src)
1753 || (REG_P (src) && GET_MODE (src) == mode))
1754 tmps[i] = src;
1755 else
1756 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1757 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1758 mode, mode);
1760 if (shift)
1761 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1762 build_int_cst (NULL_TREE, shift), tmps[i], 0);
1766 /* Emit code to move a block SRC of type TYPE to a block DST,
1767 where DST is non-consecutive registers represented by a PARALLEL.
1768 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1769 if not known. */
1771 void
1772 emit_group_load (rtx dst, rtx src, tree type, int ssize)
1774 rtx *tmps;
1775 int i;
1777 tmps = alloca (sizeof (rtx) * XVECLEN (dst, 0));
1778 emit_group_load_1 (tmps, dst, src, type, ssize);
1780 /* Copy the extracted pieces into the proper (probable) hard regs. */
1781 for (i = 0; i < XVECLEN (dst, 0); i++)
1783 rtx d = XEXP (XVECEXP (dst, 0, i), 0);
1784 if (d == NULL)
1785 continue;
1786 emit_move_insn (d, tmps[i]);
1790 /* Similar, but load SRC into new pseudos in a format that looks like
1791 PARALLEL. This can later be fed to emit_group_move to get things
1792 in the right place. */
1795 emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
1797 rtvec vec;
1798 int i;
1800 vec = rtvec_alloc (XVECLEN (parallel, 0));
1801 emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
1803 /* Convert the vector to look just like the original PARALLEL, except
1804 with the computed values. */
1805 for (i = 0; i < XVECLEN (parallel, 0); i++)
1807 rtx e = XVECEXP (parallel, 0, i);
1808 rtx d = XEXP (e, 0);
1810 if (d)
1812 d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
1813 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
1815 RTVEC_ELT (vec, i) = e;
1818 return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
1821 /* Emit code to move a block SRC to block DST, where SRC and DST are
1822 non-consecutive groups of registers, each represented by a PARALLEL. */
1824 void
1825 emit_group_move (rtx dst, rtx src)
1827 int i;
1829 gcc_assert (GET_CODE (src) == PARALLEL
1830 && GET_CODE (dst) == PARALLEL
1831 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1833 /* Skip first entry if NULL. */
1834 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1835 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1836 XEXP (XVECEXP (src, 0, i), 0));
1839 /* Move a group of registers represented by a PARALLEL into pseudos. */
1842 emit_group_move_into_temps (rtx src)
1844 rtvec vec = rtvec_alloc (XVECLEN (src, 0));
1845 int i;
1847 for (i = 0; i < XVECLEN (src, 0); i++)
1849 rtx e = XVECEXP (src, 0, i);
1850 rtx d = XEXP (e, 0);
1852 if (d)
1853 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
1854 RTVEC_ELT (vec, i) = e;
1857 return gen_rtx_PARALLEL (GET_MODE (src), vec);
1860 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1861 where SRC is non-consecutive registers represented by a PARALLEL.
1862 SSIZE represents the total size of block ORIG_DST, or -1 if not
1863 known. */
1865 void
1866 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1868 rtx *tmps, dst;
1869 int start, finish, i;
1870 enum machine_mode m = GET_MODE (orig_dst);
1872 gcc_assert (GET_CODE (src) == PARALLEL);
1874 if (!SCALAR_INT_MODE_P (m)
1875 && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
1877 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
1878 if (imode == BLKmode)
1879 dst = assign_stack_temp (GET_MODE (orig_dst), ssize, 0);
1880 else
1881 dst = gen_reg_rtx (imode);
1882 emit_group_store (dst, src, type, ssize);
1883 if (imode != BLKmode)
1884 dst = gen_lowpart (GET_MODE (orig_dst), dst);
1885 emit_move_insn (orig_dst, dst);
1886 return;
1889 /* Check for a NULL entry, used to indicate that the parameter goes
1890 both on the stack and in registers. */
1891 if (XEXP (XVECEXP (src, 0, 0), 0))
1892 start = 0;
1893 else
1894 start = 1;
1895 finish = XVECLEN (src, 0);
1897 tmps = alloca (sizeof (rtx) * finish);
1899 /* Copy the (probable) hard regs into pseudos. */
1900 for (i = start; i < finish; i++)
1902 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1903 if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
1905 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1906 emit_move_insn (tmps[i], reg);
1908 else
1909 tmps[i] = reg;
1912 /* If we won't be storing directly into memory, protect the real destination
1913 from strange tricks we might play. */
1914 dst = orig_dst;
1915 if (GET_CODE (dst) == PARALLEL)
1917 rtx temp;
1919 /* We can get a PARALLEL dst if there is a conditional expression in
1920 a return statement. In that case, the dst and src are the same,
1921 so no action is necessary. */
1922 if (rtx_equal_p (dst, src))
1923 return;
1925 /* It is unclear if we can ever reach here, but we may as well handle
1926 it. Allocate a temporary, and split this into a store/load to/from
1927 the temporary. */
1929 temp = assign_stack_temp (GET_MODE (dst), ssize, 0);
1930 emit_group_store (temp, src, type, ssize);
1931 emit_group_load (dst, temp, type, ssize);
1932 return;
1934 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1936 enum machine_mode outer = GET_MODE (dst);
1937 enum machine_mode inner;
1938 HOST_WIDE_INT bytepos;
1939 bool done = false;
1940 rtx temp;
1942 if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
1943 dst = gen_reg_rtx (outer);
1945 /* Make life a bit easier for combine. */
1946 /* If the first element of the vector is the low part
1947 of the destination mode, use a paradoxical subreg to
1948 initialize the destination. */
1949 if (start < finish)
1951 inner = GET_MODE (tmps[start]);
1952 bytepos = subreg_lowpart_offset (inner, outer);
1953 if (INTVAL (XEXP (XVECEXP (src, 0, start), 1)) == bytepos)
1955 temp = simplify_gen_subreg (outer, tmps[start],
1956 inner, 0);
1957 if (temp)
1959 emit_move_insn (dst, temp);
1960 done = true;
1961 start++;
1966 /* If the first element wasn't the low part, try the last. */
1967 if (!done
1968 && start < finish - 1)
1970 inner = GET_MODE (tmps[finish - 1]);
1971 bytepos = subreg_lowpart_offset (inner, outer);
1972 if (INTVAL (XEXP (XVECEXP (src, 0, finish - 1), 1)) == bytepos)
1974 temp = simplify_gen_subreg (outer, tmps[finish - 1],
1975 inner, 0);
1976 if (temp)
1978 emit_move_insn (dst, temp);
1979 done = true;
1980 finish--;
1985 /* Otherwise, simply initialize the result to zero. */
1986 if (!done)
1987 emit_move_insn (dst, CONST0_RTX (outer));
1990 /* Process the pieces. */
1991 for (i = start; i < finish; i++)
1993 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
1994 enum machine_mode mode = GET_MODE (tmps[i]);
1995 unsigned int bytelen = GET_MODE_SIZE (mode);
1996 rtx dest = dst;
1998 /* Handle trailing fragments that run over the size of the struct. */
1999 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2001 /* store_bit_field always takes its value from the lsb.
2002 Move the fragment to the lsb if it's not already there. */
2003 if (
2004 #ifdef BLOCK_REG_PADDING
2005 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
2006 == (BYTES_BIG_ENDIAN ? upward : downward)
2007 #else
2008 BYTES_BIG_ENDIAN
2009 #endif
2012 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2013 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
2014 build_int_cst (NULL_TREE, shift),
2015 tmps[i], 0);
2017 bytelen = ssize - bytepos;
2020 if (GET_CODE (dst) == CONCAT)
2022 if (bytepos + bytelen <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2023 dest = XEXP (dst, 0);
2024 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2026 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
2027 dest = XEXP (dst, 1);
2029 else
2031 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
2032 dest = assign_stack_temp (GET_MODE (dest),
2033 GET_MODE_SIZE (GET_MODE (dest)), 0);
2034 emit_move_insn (adjust_address (dest, GET_MODE (tmps[i]), bytepos),
2035 tmps[i]);
2036 dst = dest;
2037 break;
2041 /* Optimize the access just a bit. */
2042 if (MEM_P (dest)
2043 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
2044 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
2045 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2046 && bytelen == GET_MODE_SIZE (mode))
2047 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2048 else
2049 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2050 mode, tmps[i]);
2053 /* Copy from the pseudo into the (probable) hard reg. */
2054 if (orig_dst != dst)
2055 emit_move_insn (orig_dst, dst);
2058 /* Generate code to copy a BLKmode object of TYPE out of a
2059 set of registers starting with SRCREG into TGTBLK. If TGTBLK
2060 is null, a stack temporary is created. TGTBLK is returned.
2062 The purpose of this routine is to handle functions that return
2063 BLKmode structures in registers. Some machines (the PA for example)
2064 want to return all small structures in registers regardless of the
2065 structure's alignment. */
2068 copy_blkmode_from_reg (rtx tgtblk, rtx srcreg, tree type)
2070 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2071 rtx src = NULL, dst = NULL;
2072 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2073 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2075 if (tgtblk == 0)
2077 tgtblk = assign_temp (build_qualified_type (type,
2078 (TYPE_QUALS (type)
2079 | TYPE_QUAL_CONST)),
2080 0, 1, 1);
2081 preserve_temp_slots (tgtblk);
2084 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2085 into a new pseudo which is a full word. */
2087 if (GET_MODE (srcreg) != BLKmode
2088 && GET_MODE_SIZE (GET_MODE (srcreg)) < UNITS_PER_WORD)
2089 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
2091 /* If the structure doesn't take up a whole number of words, see whether
2092 SRCREG is padded on the left or on the right. If it's on the left,
2093 set PADDING_CORRECTION to the number of bits to skip.
2095 In most ABIs, the structure will be returned at the least end of
2096 the register, which translates to right padding on little-endian
2097 targets and left padding on big-endian targets. The opposite
2098 holds if the structure is returned at the most significant
2099 end of the register. */
2100 if (bytes % UNITS_PER_WORD != 0
2101 && (targetm.calls.return_in_msb (type)
2102 ? !BYTES_BIG_ENDIAN
2103 : BYTES_BIG_ENDIAN))
2104 padding_correction
2105 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2107 /* Copy the structure BITSIZE bites at a time.
2109 We could probably emit more efficient code for machines which do not use
2110 strict alignment, but it doesn't seem worth the effort at the current
2111 time. */
2112 for (bitpos = 0, xbitpos = padding_correction;
2113 bitpos < bytes * BITS_PER_UNIT;
2114 bitpos += bitsize, xbitpos += bitsize)
2116 /* We need a new source operand each time xbitpos is on a
2117 word boundary and when xbitpos == padding_correction
2118 (the first time through). */
2119 if (xbitpos % BITS_PER_WORD == 0
2120 || xbitpos == padding_correction)
2121 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD,
2122 GET_MODE (srcreg));
2124 /* We need a new destination operand each time bitpos is on
2125 a word boundary. */
2126 if (bitpos % BITS_PER_WORD == 0)
2127 dst = operand_subword (tgtblk, bitpos / BITS_PER_WORD, 1, BLKmode);
2129 /* Use xbitpos for the source extraction (right justified) and
2130 xbitpos for the destination store (left justified). */
2131 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
2132 extract_bit_field (src, bitsize,
2133 xbitpos % BITS_PER_WORD, 1,
2134 NULL_RTX, word_mode, word_mode));
2137 return tgtblk;
2140 /* Add a USE expression for REG to the (possibly empty) list pointed
2141 to by CALL_FUSAGE. REG must denote a hard register. */
2143 void
2144 use_reg (rtx *call_fusage, rtx reg)
2146 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
2148 *call_fusage
2149 = gen_rtx_EXPR_LIST (VOIDmode,
2150 gen_rtx_USE (VOIDmode, reg), *call_fusage);
2153 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2154 starting at REGNO. All of these registers must be hard registers. */
2156 void
2157 use_regs (rtx *call_fusage, int regno, int nregs)
2159 int i;
2161 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
2163 for (i = 0; i < nregs; i++)
2164 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2167 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2168 PARALLEL REGS. This is for calls that pass values in multiple
2169 non-contiguous locations. The Irix 6 ABI has examples of this. */
2171 void
2172 use_group_regs (rtx *call_fusage, rtx regs)
2174 int i;
2176 for (i = 0; i < XVECLEN (regs, 0); i++)
2178 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2180 /* A NULL entry means the parameter goes both on the stack and in
2181 registers. This can also be a MEM for targets that pass values
2182 partially on the stack and partially in registers. */
2183 if (reg != 0 && REG_P (reg))
2184 use_reg (call_fusage, reg);
2189 /* Determine whether the LEN bytes generated by CONSTFUN can be
2190 stored to memory using several move instructions. CONSTFUNDATA is
2191 a pointer which will be passed as argument in every CONSTFUN call.
2192 ALIGN is maximum alignment we can assume. Return nonzero if a
2193 call to store_by_pieces should succeed. */
2196 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2197 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2198 void *constfundata, unsigned int align)
2200 unsigned HOST_WIDE_INT l;
2201 unsigned int max_size;
2202 HOST_WIDE_INT offset = 0;
2203 enum machine_mode mode, tmode;
2204 enum insn_code icode;
2205 int reverse;
2206 rtx cst;
2208 if (len == 0)
2209 return 1;
2211 if (! STORE_BY_PIECES_P (len, align))
2212 return 0;
2214 tmode = mode_for_size (STORE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
2215 if (align >= GET_MODE_ALIGNMENT (tmode))
2216 align = GET_MODE_ALIGNMENT (tmode);
2217 else
2219 enum machine_mode xmode;
2221 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
2222 tmode != VOIDmode;
2223 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
2224 if (GET_MODE_SIZE (tmode) > STORE_MAX_PIECES
2225 || SLOW_UNALIGNED_ACCESS (tmode, align))
2226 break;
2228 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
2231 /* We would first store what we can in the largest integer mode, then go to
2232 successively smaller modes. */
2234 for (reverse = 0;
2235 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2236 reverse++)
2238 l = len;
2239 mode = VOIDmode;
2240 max_size = STORE_MAX_PIECES + 1;
2241 while (max_size > 1)
2243 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2244 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2245 if (GET_MODE_SIZE (tmode) < max_size)
2246 mode = tmode;
2248 if (mode == VOIDmode)
2249 break;
2251 icode = mov_optab->handlers[(int) mode].insn_code;
2252 if (icode != CODE_FOR_nothing
2253 && align >= GET_MODE_ALIGNMENT (mode))
2255 unsigned int size = GET_MODE_SIZE (mode);
2257 while (l >= size)
2259 if (reverse)
2260 offset -= size;
2262 cst = (*constfun) (constfundata, offset, mode);
2263 if (!LEGITIMATE_CONSTANT_P (cst))
2264 return 0;
2266 if (!reverse)
2267 offset += size;
2269 l -= size;
2273 max_size = GET_MODE_SIZE (mode);
2276 /* The code above should have handled everything. */
2277 gcc_assert (!l);
2280 return 1;
2283 /* Generate several move instructions to store LEN bytes generated by
2284 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2285 pointer which will be passed as argument in every CONSTFUN call.
2286 ALIGN is maximum alignment we can assume.
2287 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2288 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2289 stpcpy. */
2292 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2293 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2294 void *constfundata, unsigned int align, int endp)
2296 struct store_by_pieces data;
2298 if (len == 0)
2300 gcc_assert (endp != 2);
2301 return to;
2304 gcc_assert (STORE_BY_PIECES_P (len, align));
2305 data.constfun = constfun;
2306 data.constfundata = constfundata;
2307 data.len = len;
2308 data.to = to;
2309 store_by_pieces_1 (&data, align);
2310 if (endp)
2312 rtx to1;
2314 gcc_assert (!data.reverse);
2315 if (data.autinc_to)
2317 if (endp == 2)
2319 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2320 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2321 else
2322 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
2323 -1));
2325 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2326 data.offset);
2328 else
2330 if (endp == 2)
2331 --data.offset;
2332 to1 = adjust_address (data.to, QImode, data.offset);
2334 return to1;
2336 else
2337 return data.to;
2340 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2341 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2343 static void
2344 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2346 struct store_by_pieces data;
2348 if (len == 0)
2349 return;
2351 data.constfun = clear_by_pieces_1;
2352 data.constfundata = NULL;
2353 data.len = len;
2354 data.to = to;
2355 store_by_pieces_1 (&data, align);
2358 /* Callback routine for clear_by_pieces.
2359 Return const0_rtx unconditionally. */
2361 static rtx
2362 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2363 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2364 enum machine_mode mode ATTRIBUTE_UNUSED)
2366 return const0_rtx;
2369 /* Subroutine of clear_by_pieces and store_by_pieces.
2370 Generate several move instructions to store LEN bytes of block TO. (A MEM
2371 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2373 static void
2374 store_by_pieces_1 (struct store_by_pieces *data ATTRIBUTE_UNUSED,
2375 unsigned int align ATTRIBUTE_UNUSED)
2377 rtx to_addr = XEXP (data->to, 0);
2378 unsigned int max_size = STORE_MAX_PIECES + 1;
2379 enum machine_mode mode = VOIDmode, tmode;
2380 enum insn_code icode;
2382 data->offset = 0;
2383 data->to_addr = to_addr;
2384 data->autinc_to
2385 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2386 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2388 data->explicit_inc_to = 0;
2389 data->reverse
2390 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2391 if (data->reverse)
2392 data->offset = data->len;
2394 /* If storing requires more than two move insns,
2395 copy addresses to registers (to make displacements shorter)
2396 and use post-increment if available. */
2397 if (!data->autinc_to
2398 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2400 /* Determine the main mode we'll be using. */
2401 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2402 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2403 if (GET_MODE_SIZE (tmode) < max_size)
2404 mode = tmode;
2406 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2408 data->to_addr = copy_addr_to_reg (plus_constant (to_addr, data->len));
2409 data->autinc_to = 1;
2410 data->explicit_inc_to = -1;
2413 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2414 && ! data->autinc_to)
2416 data->to_addr = copy_addr_to_reg (to_addr);
2417 data->autinc_to = 1;
2418 data->explicit_inc_to = 1;
2421 if ( !data->autinc_to && CONSTANT_P (to_addr))
2422 data->to_addr = copy_addr_to_reg (to_addr);
2425 tmode = mode_for_size (STORE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
2426 if (align >= GET_MODE_ALIGNMENT (tmode))
2427 align = GET_MODE_ALIGNMENT (tmode);
2428 else
2430 enum machine_mode xmode;
2432 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
2433 tmode != VOIDmode;
2434 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
2435 if (GET_MODE_SIZE (tmode) > STORE_MAX_PIECES
2436 || SLOW_UNALIGNED_ACCESS (tmode, align))
2437 break;
2439 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
2442 /* First store what we can in the largest integer mode, then go to
2443 successively smaller modes. */
2445 while (max_size > 1)
2447 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2448 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2449 if (GET_MODE_SIZE (tmode) < max_size)
2450 mode = tmode;
2452 if (mode == VOIDmode)
2453 break;
2455 icode = mov_optab->handlers[(int) mode].insn_code;
2456 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2457 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2459 max_size = GET_MODE_SIZE (mode);
2462 /* The code above should have handled everything. */
2463 gcc_assert (!data->len);
2466 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2467 with move instructions for mode MODE. GENFUN is the gen_... function
2468 to make a move insn for that mode. DATA has all the other info. */
2470 static void
2471 store_by_pieces_2 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
2472 struct store_by_pieces *data)
2474 unsigned int size = GET_MODE_SIZE (mode);
2475 rtx to1, cst;
2477 while (data->len >= size)
2479 if (data->reverse)
2480 data->offset -= size;
2482 if (data->autinc_to)
2483 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2484 data->offset);
2485 else
2486 to1 = adjust_address (data->to, mode, data->offset);
2488 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2489 emit_insn (gen_add2_insn (data->to_addr,
2490 GEN_INT (-(HOST_WIDE_INT) size)));
2492 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2493 emit_insn ((*genfun) (to1, cst));
2495 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2496 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2498 if (! data->reverse)
2499 data->offset += size;
2501 data->len -= size;
2505 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2506 its length in bytes. */
2509 clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
2510 unsigned int expected_align, HOST_WIDE_INT expected_size)
2512 enum machine_mode mode = GET_MODE (object);
2513 unsigned int align;
2515 gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
2517 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2518 just move a zero. Otherwise, do this a piece at a time. */
2519 if (mode != BLKmode
2520 && GET_CODE (size) == CONST_INT
2521 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
2523 rtx zero = CONST0_RTX (mode);
2524 if (zero != NULL)
2526 emit_move_insn (object, zero);
2527 return NULL;
2530 if (COMPLEX_MODE_P (mode))
2532 zero = CONST0_RTX (GET_MODE_INNER (mode));
2533 if (zero != NULL)
2535 write_complex_part (object, zero, 0);
2536 write_complex_part (object, zero, 1);
2537 return NULL;
2542 if (size == const0_rtx)
2543 return NULL;
2545 align = MEM_ALIGN (object);
2547 if (GET_CODE (size) == CONST_INT
2548 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2549 clear_by_pieces (object, INTVAL (size), align);
2550 else if (set_storage_via_setmem (object, size, const0_rtx, align,
2551 expected_align, expected_size))
2553 else
2554 return set_storage_via_libcall (object, size, const0_rtx,
2555 method == BLOCK_OP_TAILCALL);
2557 return NULL;
2561 clear_storage (rtx object, rtx size, enum block_op_methods method)
2563 return clear_storage_hints (object, size, method, 0, -1);
2567 /* A subroutine of clear_storage. Expand a call to memset.
2568 Return the return value of memset, 0 otherwise. */
2571 set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
2573 tree call_expr, fn, object_tree, size_tree, val_tree;
2574 enum machine_mode size_mode;
2575 rtx retval;
2577 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2578 place those into new pseudos into a VAR_DECL and use them later. */
2580 object = copy_to_mode_reg (Pmode, XEXP (object, 0));
2582 size_mode = TYPE_MODE (sizetype);
2583 size = convert_to_mode (size_mode, size, 1);
2584 size = copy_to_mode_reg (size_mode, size);
2586 /* It is incorrect to use the libcall calling conventions to call
2587 memset in this context. This could be a user call to memset and
2588 the user may wish to examine the return value from memset. For
2589 targets where libcalls and normal calls have different conventions
2590 for returning pointers, we could end up generating incorrect code. */
2592 object_tree = make_tree (ptr_type_node, object);
2593 if (GET_CODE (val) != CONST_INT)
2594 val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
2595 size_tree = make_tree (sizetype, size);
2596 val_tree = make_tree (integer_type_node, val);
2598 fn = clear_storage_libcall_fn (true);
2599 call_expr = build_call_expr (fn, 3,
2600 object_tree, integer_zero_node, size_tree);
2601 CALL_EXPR_TAILCALL (call_expr) = tailcall;
2603 retval = expand_normal (call_expr);
2605 return retval;
2608 /* A subroutine of set_storage_via_libcall. Create the tree node
2609 for the function we use for block clears. The first time FOR_CALL
2610 is true, we call assemble_external. */
2612 static GTY(()) tree block_clear_fn;
2614 void
2615 init_block_clear_fn (const char *asmspec)
2617 if (!block_clear_fn)
2619 tree fn, args;
2621 fn = get_identifier ("memset");
2622 args = build_function_type_list (ptr_type_node, ptr_type_node,
2623 integer_type_node, sizetype,
2624 NULL_TREE);
2626 fn = build_decl (FUNCTION_DECL, fn, args);
2627 DECL_EXTERNAL (fn) = 1;
2628 TREE_PUBLIC (fn) = 1;
2629 DECL_ARTIFICIAL (fn) = 1;
2630 TREE_NOTHROW (fn) = 1;
2631 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
2632 DECL_VISIBILITY_SPECIFIED (fn) = 1;
2634 block_clear_fn = fn;
2637 if (asmspec)
2638 set_user_assembler_name (block_clear_fn, asmspec);
2641 static tree
2642 clear_storage_libcall_fn (int for_call)
2644 static bool emitted_extern;
2646 if (!block_clear_fn)
2647 init_block_clear_fn (NULL);
2649 if (for_call && !emitted_extern)
2651 emitted_extern = true;
2652 make_decl_rtl (block_clear_fn);
2653 assemble_external (block_clear_fn);
2656 return block_clear_fn;
2659 /* Expand a setmem pattern; return true if successful. */
2661 bool
2662 set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
2663 unsigned int expected_align, HOST_WIDE_INT expected_size)
2665 /* Try the most limited insn first, because there's no point
2666 including more than one in the machine description unless
2667 the more limited one has some advantage. */
2669 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
2670 enum machine_mode mode;
2672 if (expected_align < align)
2673 expected_align = align;
2675 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2676 mode = GET_MODE_WIDER_MODE (mode))
2678 enum insn_code code = setmem_optab[(int) mode];
2679 insn_operand_predicate_fn pred;
2681 if (code != CODE_FOR_nothing
2682 /* We don't need MODE to be narrower than
2683 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2684 the mode mask, as it is returned by the macro, it will
2685 definitely be less than the actual mode mask. */
2686 && ((GET_CODE (size) == CONST_INT
2687 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2688 <= (GET_MODE_MASK (mode) >> 1)))
2689 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2690 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
2691 || (*pred) (object, BLKmode))
2692 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
2693 || (*pred) (opalign, VOIDmode)))
2695 rtx opsize, opchar;
2696 enum machine_mode char_mode;
2697 rtx last = get_last_insn ();
2698 rtx pat;
2700 opsize = convert_to_mode (mode, size, 1);
2701 pred = insn_data[(int) code].operand[1].predicate;
2702 if (pred != 0 && ! (*pred) (opsize, mode))
2703 opsize = copy_to_mode_reg (mode, opsize);
2705 opchar = val;
2706 char_mode = insn_data[(int) code].operand[2].mode;
2707 if (char_mode != VOIDmode)
2709 opchar = convert_to_mode (char_mode, opchar, 1);
2710 pred = insn_data[(int) code].operand[2].predicate;
2711 if (pred != 0 && ! (*pred) (opchar, char_mode))
2712 opchar = copy_to_mode_reg (char_mode, opchar);
2715 if (insn_data[(int) code].n_operands == 4)
2716 pat = GEN_FCN ((int) code) (object, opsize, opchar, opalign);
2717 else
2718 pat = GEN_FCN ((int) code) (object, opsize, opchar, opalign,
2719 GEN_INT (expected_align),
2720 GEN_INT (expected_size));
2721 if (pat)
2723 emit_insn (pat);
2724 return true;
2726 else
2727 delete_insns_since (last);
2731 return false;
2735 /* Write to one of the components of the complex value CPLX. Write VAL to
2736 the real part if IMAG_P is false, and the imaginary part if its true. */
2738 static void
2739 write_complex_part (rtx cplx, rtx val, bool imag_p)
2741 enum machine_mode cmode;
2742 enum machine_mode imode;
2743 unsigned ibitsize;
2745 if (GET_CODE (cplx) == CONCAT)
2747 emit_move_insn (XEXP (cplx, imag_p), val);
2748 return;
2751 cmode = GET_MODE (cplx);
2752 imode = GET_MODE_INNER (cmode);
2753 ibitsize = GET_MODE_BITSIZE (imode);
2755 /* For MEMs simplify_gen_subreg may generate an invalid new address
2756 because, e.g., the original address is considered mode-dependent
2757 by the target, which restricts simplify_subreg from invoking
2758 adjust_address_nv. Instead of preparing fallback support for an
2759 invalid address, we call adjust_address_nv directly. */
2760 if (MEM_P (cplx))
2762 emit_move_insn (adjust_address_nv (cplx, imode,
2763 imag_p ? GET_MODE_SIZE (imode) : 0),
2764 val);
2765 return;
2768 /* If the sub-object is at least word sized, then we know that subregging
2769 will work. This special case is important, since store_bit_field
2770 wants to operate on integer modes, and there's rarely an OImode to
2771 correspond to TCmode. */
2772 if (ibitsize >= BITS_PER_WORD
2773 /* For hard regs we have exact predicates. Assume we can split
2774 the original object if it spans an even number of hard regs.
2775 This special case is important for SCmode on 64-bit platforms
2776 where the natural size of floating-point regs is 32-bit. */
2777 || (REG_P (cplx)
2778 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2779 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2781 rtx part = simplify_gen_subreg (imode, cplx, cmode,
2782 imag_p ? GET_MODE_SIZE (imode) : 0);
2783 if (part)
2785 emit_move_insn (part, val);
2786 return;
2788 else
2789 /* simplify_gen_subreg may fail for sub-word MEMs. */
2790 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2793 store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, imode, val);
2796 /* Extract one of the components of the complex value CPLX. Extract the
2797 real part if IMAG_P is false, and the imaginary part if it's true. */
2799 static rtx
2800 read_complex_part (rtx cplx, bool imag_p)
2802 enum machine_mode cmode, imode;
2803 unsigned ibitsize;
2805 if (GET_CODE (cplx) == CONCAT)
2806 return XEXP (cplx, imag_p);
2808 cmode = GET_MODE (cplx);
2809 imode = GET_MODE_INNER (cmode);
2810 ibitsize = GET_MODE_BITSIZE (imode);
2812 /* Special case reads from complex constants that got spilled to memory. */
2813 if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
2815 tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
2816 if (decl && TREE_CODE (decl) == COMPLEX_CST)
2818 tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
2819 if (CONSTANT_CLASS_P (part))
2820 return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
2824 /* For MEMs simplify_gen_subreg may generate an invalid new address
2825 because, e.g., the original address is considered mode-dependent
2826 by the target, which restricts simplify_subreg from invoking
2827 adjust_address_nv. Instead of preparing fallback support for an
2828 invalid address, we call adjust_address_nv directly. */
2829 if (MEM_P (cplx))
2830 return adjust_address_nv (cplx, imode,
2831 imag_p ? GET_MODE_SIZE (imode) : 0);
2833 /* If the sub-object is at least word sized, then we know that subregging
2834 will work. This special case is important, since extract_bit_field
2835 wants to operate on integer modes, and there's rarely an OImode to
2836 correspond to TCmode. */
2837 if (ibitsize >= BITS_PER_WORD
2838 /* For hard regs we have exact predicates. Assume we can split
2839 the original object if it spans an even number of hard regs.
2840 This special case is important for SCmode on 64-bit platforms
2841 where the natural size of floating-point regs is 32-bit. */
2842 || (REG_P (cplx)
2843 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2844 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2846 rtx ret = simplify_gen_subreg (imode, cplx, cmode,
2847 imag_p ? GET_MODE_SIZE (imode) : 0);
2848 if (ret)
2849 return ret;
2850 else
2851 /* simplify_gen_subreg may fail for sub-word MEMs. */
2852 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2855 return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
2856 true, NULL_RTX, imode, imode);
2859 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
2860 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
2861 represented in NEW_MODE. If FORCE is true, this will never happen, as
2862 we'll force-create a SUBREG if needed. */
2864 static rtx
2865 emit_move_change_mode (enum machine_mode new_mode,
2866 enum machine_mode old_mode, rtx x, bool force)
2868 rtx ret;
2870 if (MEM_P (x))
2872 /* We don't have to worry about changing the address since the
2873 size in bytes is supposed to be the same. */
2874 if (reload_in_progress)
2876 /* Copy the MEM to change the mode and move any
2877 substitutions from the old MEM to the new one. */
2878 ret = adjust_address_nv (x, new_mode, 0);
2879 copy_replacements (x, ret);
2881 else
2882 ret = adjust_address (x, new_mode, 0);
2884 else
2886 /* Note that we do want simplify_subreg's behavior of validating
2887 that the new mode is ok for a hard register. If we were to use
2888 simplify_gen_subreg, we would create the subreg, but would
2889 probably run into the target not being able to implement it. */
2890 /* Except, of course, when FORCE is true, when this is exactly what
2891 we want. Which is needed for CCmodes on some targets. */
2892 if (force)
2893 ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
2894 else
2895 ret = simplify_subreg (new_mode, x, old_mode, 0);
2898 return ret;
2901 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
2902 an integer mode of the same size as MODE. Returns the instruction
2903 emitted, or NULL if such a move could not be generated. */
2905 static rtx
2906 emit_move_via_integer (enum machine_mode mode, rtx x, rtx y, bool force)
2908 enum machine_mode imode;
2909 enum insn_code code;
2911 /* There must exist a mode of the exact size we require. */
2912 imode = int_mode_for_mode (mode);
2913 if (imode == BLKmode)
2914 return NULL_RTX;
2916 /* The target must support moves in this mode. */
2917 code = mov_optab->handlers[imode].insn_code;
2918 if (code == CODE_FOR_nothing)
2919 return NULL_RTX;
2921 x = emit_move_change_mode (imode, mode, x, force);
2922 if (x == NULL_RTX)
2923 return NULL_RTX;
2924 y = emit_move_change_mode (imode, mode, y, force);
2925 if (y == NULL_RTX)
2926 return NULL_RTX;
2927 return emit_insn (GEN_FCN (code) (x, y));
2930 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
2931 Return an equivalent MEM that does not use an auto-increment. */
2933 static rtx
2934 emit_move_resolve_push (enum machine_mode mode, rtx x)
2936 enum rtx_code code = GET_CODE (XEXP (x, 0));
2937 HOST_WIDE_INT adjust;
2938 rtx temp;
2940 adjust = GET_MODE_SIZE (mode);
2941 #ifdef PUSH_ROUNDING
2942 adjust = PUSH_ROUNDING (adjust);
2943 #endif
2944 if (code == PRE_DEC || code == POST_DEC)
2945 adjust = -adjust;
2946 else if (code == PRE_MODIFY || code == POST_MODIFY)
2948 rtx expr = XEXP (XEXP (x, 0), 1);
2949 HOST_WIDE_INT val;
2951 gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
2952 gcc_assert (GET_CODE (XEXP (expr, 1)) == CONST_INT);
2953 val = INTVAL (XEXP (expr, 1));
2954 if (GET_CODE (expr) == MINUS)
2955 val = -val;
2956 gcc_assert (adjust == val || adjust == -val);
2957 adjust = val;
2960 /* Do not use anti_adjust_stack, since we don't want to update
2961 stack_pointer_delta. */
2962 temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
2963 GEN_INT (adjust), stack_pointer_rtx,
2964 0, OPTAB_LIB_WIDEN);
2965 if (temp != stack_pointer_rtx)
2966 emit_move_insn (stack_pointer_rtx, temp);
2968 switch (code)
2970 case PRE_INC:
2971 case PRE_DEC:
2972 case PRE_MODIFY:
2973 temp = stack_pointer_rtx;
2974 break;
2975 case POST_INC:
2976 case POST_DEC:
2977 case POST_MODIFY:
2978 temp = plus_constant (stack_pointer_rtx, -adjust);
2979 break;
2980 default:
2981 gcc_unreachable ();
2984 return replace_equiv_address (x, temp);
2987 /* A subroutine of emit_move_complex. Generate a move from Y into X.
2988 X is known to satisfy push_operand, and MODE is known to be complex.
2989 Returns the last instruction emitted. */
2992 emit_move_complex_push (enum machine_mode mode, rtx x, rtx y)
2994 enum machine_mode submode = GET_MODE_INNER (mode);
2995 bool imag_first;
2997 #ifdef PUSH_ROUNDING
2998 unsigned int submodesize = GET_MODE_SIZE (submode);
3000 /* In case we output to the stack, but the size is smaller than the
3001 machine can push exactly, we need to use move instructions. */
3002 if (PUSH_ROUNDING (submodesize) != submodesize)
3004 x = emit_move_resolve_push (mode, x);
3005 return emit_move_insn (x, y);
3007 #endif
3009 /* Note that the real part always precedes the imag part in memory
3010 regardless of machine's endianness. */
3011 switch (GET_CODE (XEXP (x, 0)))
3013 case PRE_DEC:
3014 case POST_DEC:
3015 imag_first = true;
3016 break;
3017 case PRE_INC:
3018 case POST_INC:
3019 imag_first = false;
3020 break;
3021 default:
3022 gcc_unreachable ();
3025 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3026 read_complex_part (y, imag_first));
3027 return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3028 read_complex_part (y, !imag_first));
3031 /* A subroutine of emit_move_complex. Perform the move from Y to X
3032 via two moves of the parts. Returns the last instruction emitted. */
3035 emit_move_complex_parts (rtx x, rtx y)
3037 /* Show the output dies here. This is necessary for SUBREGs
3038 of pseudos since we cannot track their lifetimes correctly;
3039 hard regs shouldn't appear here except as return values. */
3040 if (!reload_completed && !reload_in_progress
3041 && REG_P (x) && !reg_overlap_mentioned_p (x, y))
3042 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3044 write_complex_part (x, read_complex_part (y, false), false);
3045 write_complex_part (x, read_complex_part (y, true), true);
3047 return get_last_insn ();
3050 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3051 MODE is known to be complex. Returns the last instruction emitted. */
3053 static rtx
3054 emit_move_complex (enum machine_mode mode, rtx x, rtx y)
3056 bool try_int;
3058 /* Need to take special care for pushes, to maintain proper ordering
3059 of the data, and possibly extra padding. */
3060 if (push_operand (x, mode))
3061 return emit_move_complex_push (mode, x, y);
3063 /* See if we can coerce the target into moving both values at once. */
3065 /* Move floating point as parts. */
3066 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3067 && mov_optab->handlers[GET_MODE_INNER (mode)].insn_code != CODE_FOR_nothing)
3068 try_int = false;
3069 /* Not possible if the values are inherently not adjacent. */
3070 else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
3071 try_int = false;
3072 /* Is possible if both are registers (or subregs of registers). */
3073 else if (register_operand (x, mode) && register_operand (y, mode))
3074 try_int = true;
3075 /* If one of the operands is a memory, and alignment constraints
3076 are friendly enough, we may be able to do combined memory operations.
3077 We do not attempt this if Y is a constant because that combination is
3078 usually better with the by-parts thing below. */
3079 else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
3080 && (!STRICT_ALIGNMENT
3081 || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
3082 try_int = true;
3083 else
3084 try_int = false;
3086 if (try_int)
3088 rtx ret;
3090 /* For memory to memory moves, optimal behavior can be had with the
3091 existing block move logic. */
3092 if (MEM_P (x) && MEM_P (y))
3094 emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
3095 BLOCK_OP_NO_LIBCALL);
3096 return get_last_insn ();
3099 ret = emit_move_via_integer (mode, x, y, true);
3100 if (ret)
3101 return ret;
3104 return emit_move_complex_parts (x, y);
3107 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3108 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3110 static rtx
3111 emit_move_ccmode (enum machine_mode mode, rtx x, rtx y)
3113 rtx ret;
3115 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3116 if (mode != CCmode)
3118 enum insn_code code = mov_optab->handlers[CCmode].insn_code;
3119 if (code != CODE_FOR_nothing)
3121 x = emit_move_change_mode (CCmode, mode, x, true);
3122 y = emit_move_change_mode (CCmode, mode, y, true);
3123 return emit_insn (GEN_FCN (code) (x, y));
3127 /* Otherwise, find the MODE_INT mode of the same width. */
3128 ret = emit_move_via_integer (mode, x, y, false);
3129 gcc_assert (ret != NULL);
3130 return ret;
3133 /* Return true if word I of OP lies entirely in the
3134 undefined bits of a paradoxical subreg. */
3136 static bool
3137 undefined_operand_subword_p (rtx op, int i)
3139 enum machine_mode innermode, innermostmode;
3140 int offset;
3141 if (GET_CODE (op) != SUBREG)
3142 return false;
3143 innermode = GET_MODE (op);
3144 innermostmode = GET_MODE (SUBREG_REG (op));
3145 offset = i * UNITS_PER_WORD + SUBREG_BYTE (op);
3146 /* The SUBREG_BYTE represents offset, as if the value were stored in
3147 memory, except for a paradoxical subreg where we define
3148 SUBREG_BYTE to be 0; undo this exception as in
3149 simplify_subreg. */
3150 if (SUBREG_BYTE (op) == 0
3151 && GET_MODE_SIZE (innermostmode) < GET_MODE_SIZE (innermode))
3153 int difference = (GET_MODE_SIZE (innermostmode) - GET_MODE_SIZE (innermode));
3154 if (WORDS_BIG_ENDIAN)
3155 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
3156 if (BYTES_BIG_ENDIAN)
3157 offset += difference % UNITS_PER_WORD;
3159 if (offset >= GET_MODE_SIZE (innermostmode)
3160 || offset <= -GET_MODE_SIZE (word_mode))
3161 return true;
3162 return false;
3165 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3166 MODE is any multi-word or full-word mode that lacks a move_insn
3167 pattern. Note that you will get better code if you define such
3168 patterns, even if they must turn into multiple assembler instructions. */
3170 static rtx
3171 emit_move_multi_word (enum machine_mode mode, rtx x, rtx y)
3173 rtx last_insn = 0;
3174 rtx seq, inner;
3175 bool need_clobber;
3176 int i;
3178 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
3180 /* If X is a push on the stack, do the push now and replace
3181 X with a reference to the stack pointer. */
3182 if (push_operand (x, mode))
3183 x = emit_move_resolve_push (mode, x);
3185 /* If we are in reload, see if either operand is a MEM whose address
3186 is scheduled for replacement. */
3187 if (reload_in_progress && MEM_P (x)
3188 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3189 x = replace_equiv_address_nv (x, inner);
3190 if (reload_in_progress && MEM_P (y)
3191 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3192 y = replace_equiv_address_nv (y, inner);
3194 start_sequence ();
3196 need_clobber = false;
3197 for (i = 0;
3198 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3199 i++)
3201 rtx xpart = operand_subword (x, i, 1, mode);
3202 rtx ypart;
3204 /* Do not generate code for a move if it would come entirely
3205 from the undefined bits of a paradoxical subreg. */
3206 if (undefined_operand_subword_p (y, i))
3207 continue;
3209 ypart = operand_subword (y, i, 1, mode);
3211 /* If we can't get a part of Y, put Y into memory if it is a
3212 constant. Otherwise, force it into a register. Then we must
3213 be able to get a part of Y. */
3214 if (ypart == 0 && CONSTANT_P (y))
3216 y = use_anchored_address (force_const_mem (mode, y));
3217 ypart = operand_subword (y, i, 1, mode);
3219 else if (ypart == 0)
3220 ypart = operand_subword_force (y, i, mode);
3222 gcc_assert (xpart && ypart);
3224 need_clobber |= (GET_CODE (xpart) == SUBREG);
3226 last_insn = emit_move_insn (xpart, ypart);
3229 seq = get_insns ();
3230 end_sequence ();
3232 /* Show the output dies here. This is necessary for SUBREGs
3233 of pseudos since we cannot track their lifetimes correctly;
3234 hard regs shouldn't appear here except as return values.
3235 We never want to emit such a clobber after reload. */
3236 if (x != y
3237 && ! (reload_in_progress || reload_completed)
3238 && need_clobber != 0)
3239 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3241 emit_insn (seq);
3243 return last_insn;
3246 /* Low level part of emit_move_insn.
3247 Called just like emit_move_insn, but assumes X and Y
3248 are basically valid. */
3251 emit_move_insn_1 (rtx x, rtx y)
3253 enum machine_mode mode = GET_MODE (x);
3254 enum insn_code code;
3256 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
3258 code = mov_optab->handlers[mode].insn_code;
3259 if (code != CODE_FOR_nothing)
3260 return emit_insn (GEN_FCN (code) (x, y));
3262 /* Expand complex moves by moving real part and imag part. */
3263 if (COMPLEX_MODE_P (mode))
3264 return emit_move_complex (mode, x, y);
3266 if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT)
3268 rtx result = emit_move_via_integer (mode, x, y, true);
3270 /* If we can't find an integer mode, use multi words. */
3271 if (result)
3272 return result;
3273 else
3274 return emit_move_multi_word (mode, x, y);
3277 if (GET_MODE_CLASS (mode) == MODE_CC)
3278 return emit_move_ccmode (mode, x, y);
3280 /* Try using a move pattern for the corresponding integer mode. This is
3281 only safe when simplify_subreg can convert MODE constants into integer
3282 constants. At present, it can only do this reliably if the value
3283 fits within a HOST_WIDE_INT. */
3284 if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3286 rtx ret = emit_move_via_integer (mode, x, y, false);
3287 if (ret)
3288 return ret;
3291 return emit_move_multi_word (mode, x, y);
3294 /* Generate code to copy Y into X.
3295 Both Y and X must have the same mode, except that
3296 Y can be a constant with VOIDmode.
3297 This mode cannot be BLKmode; use emit_block_move for that.
3299 Return the last instruction emitted. */
3302 emit_move_insn (rtx x, rtx y)
3304 enum machine_mode mode = GET_MODE (x);
3305 rtx y_cst = NULL_RTX;
3306 rtx last_insn, set;
3308 gcc_assert (mode != BLKmode
3309 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
3311 if (CONSTANT_P (y))
3313 if (optimize
3314 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3315 && (last_insn = compress_float_constant (x, y)))
3316 return last_insn;
3318 y_cst = y;
3320 if (!LEGITIMATE_CONSTANT_P (y))
3322 y = force_const_mem (mode, y);
3324 /* If the target's cannot_force_const_mem prevented the spill,
3325 assume that the target's move expanders will also take care
3326 of the non-legitimate constant. */
3327 if (!y)
3328 y = y_cst;
3329 else
3330 y = use_anchored_address (y);
3334 /* If X or Y are memory references, verify that their addresses are valid
3335 for the machine. */
3336 if (MEM_P (x)
3337 && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
3338 && ! push_operand (x, GET_MODE (x)))
3339 || (flag_force_addr
3340 && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
3341 x = validize_mem (x);
3343 if (MEM_P (y)
3344 && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
3345 || (flag_force_addr
3346 && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
3347 y = validize_mem (y);
3349 gcc_assert (mode != BLKmode);
3351 last_insn = emit_move_insn_1 (x, y);
3353 if (y_cst && REG_P (x)
3354 && (set = single_set (last_insn)) != NULL_RTX
3355 && SET_DEST (set) == x
3356 && ! rtx_equal_p (y_cst, SET_SRC (set)))
3357 set_unique_reg_note (last_insn, REG_EQUAL, y_cst);
3359 return last_insn;
3362 /* If Y is representable exactly in a narrower mode, and the target can
3363 perform the extension directly from constant or memory, then emit the
3364 move as an extension. */
3366 static rtx
3367 compress_float_constant (rtx x, rtx y)
3369 enum machine_mode dstmode = GET_MODE (x);
3370 enum machine_mode orig_srcmode = GET_MODE (y);
3371 enum machine_mode srcmode;
3372 REAL_VALUE_TYPE r;
3373 int oldcost, newcost;
3375 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3377 if (LEGITIMATE_CONSTANT_P (y))
3378 oldcost = rtx_cost (y, SET);
3379 else
3380 oldcost = rtx_cost (force_const_mem (dstmode, y), SET);
3382 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3383 srcmode != orig_srcmode;
3384 srcmode = GET_MODE_WIDER_MODE (srcmode))
3386 enum insn_code ic;
3387 rtx trunc_y, last_insn;
3389 /* Skip if the target can't extend this way. */
3390 ic = can_extend_p (dstmode, srcmode, 0);
3391 if (ic == CODE_FOR_nothing)
3392 continue;
3394 /* Skip if the narrowed value isn't exact. */
3395 if (! exact_real_truncate (srcmode, &r))
3396 continue;
3398 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3400 if (LEGITIMATE_CONSTANT_P (trunc_y))
3402 /* Skip if the target needs extra instructions to perform
3403 the extension. */
3404 if (! (*insn_data[ic].operand[1].predicate) (trunc_y, srcmode))
3405 continue;
3406 /* This is valid, but may not be cheaper than the original. */
3407 newcost = rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y), SET);
3408 if (oldcost < newcost)
3409 continue;
3411 else if (float_extend_from_mem[dstmode][srcmode])
3413 trunc_y = force_const_mem (srcmode, trunc_y);
3414 /* This is valid, but may not be cheaper than the original. */
3415 newcost = rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y), SET);
3416 if (oldcost < newcost)
3417 continue;
3418 trunc_y = validize_mem (trunc_y);
3420 else
3421 continue;
3423 /* For CSE's benefit, force the compressed constant pool entry
3424 into a new pseudo. This constant may be used in different modes,
3425 and if not, combine will put things back together for us. */
3426 trunc_y = force_reg (srcmode, trunc_y);
3427 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3428 last_insn = get_last_insn ();
3430 if (REG_P (x))
3431 set_unique_reg_note (last_insn, REG_EQUAL, y);
3433 return last_insn;
3436 return NULL_RTX;
3439 /* Pushing data onto the stack. */
3441 /* Push a block of length SIZE (perhaps variable)
3442 and return an rtx to address the beginning of the block.
3443 The value may be virtual_outgoing_args_rtx.
3445 EXTRA is the number of bytes of padding to push in addition to SIZE.
3446 BELOW nonzero means this padding comes at low addresses;
3447 otherwise, the padding comes at high addresses. */
3450 push_block (rtx size, int extra, int below)
3452 rtx temp;
3454 size = convert_modes (Pmode, ptr_mode, size, 1);
3455 if (CONSTANT_P (size))
3456 anti_adjust_stack (plus_constant (size, extra));
3457 else if (REG_P (size) && extra == 0)
3458 anti_adjust_stack (size);
3459 else
3461 temp = copy_to_mode_reg (Pmode, size);
3462 if (extra != 0)
3463 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
3464 temp, 0, OPTAB_LIB_WIDEN);
3465 anti_adjust_stack (temp);
3468 #ifndef STACK_GROWS_DOWNWARD
3469 if (0)
3470 #else
3471 if (1)
3472 #endif
3474 temp = virtual_outgoing_args_rtx;
3475 if (extra != 0 && below)
3476 temp = plus_constant (temp, extra);
3478 else
3480 if (GET_CODE (size) == CONST_INT)
3481 temp = plus_constant (virtual_outgoing_args_rtx,
3482 -INTVAL (size) - (below ? 0 : extra));
3483 else if (extra != 0 && !below)
3484 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3485 negate_rtx (Pmode, plus_constant (size, extra)));
3486 else
3487 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3488 negate_rtx (Pmode, size));
3491 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3494 #ifdef PUSH_ROUNDING
3496 /* Emit single push insn. */
3498 static void
3499 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
3501 rtx dest_addr;
3502 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3503 rtx dest;
3504 enum insn_code icode;
3505 insn_operand_predicate_fn pred;
3507 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3508 /* If there is push pattern, use it. Otherwise try old way of throwing
3509 MEM representing push operation to move expander. */
3510 icode = push_optab->handlers[(int) mode].insn_code;
3511 if (icode != CODE_FOR_nothing)
3513 if (((pred = insn_data[(int) icode].operand[0].predicate)
3514 && !((*pred) (x, mode))))
3515 x = force_reg (mode, x);
3516 emit_insn (GEN_FCN (icode) (x));
3517 return;
3519 if (GET_MODE_SIZE (mode) == rounded_size)
3520 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3521 /* If we are to pad downward, adjust the stack pointer first and
3522 then store X into the stack location using an offset. This is
3523 because emit_move_insn does not know how to pad; it does not have
3524 access to type. */
3525 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3527 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3528 HOST_WIDE_INT offset;
3530 emit_move_insn (stack_pointer_rtx,
3531 expand_binop (Pmode,
3532 #ifdef STACK_GROWS_DOWNWARD
3533 sub_optab,
3534 #else
3535 add_optab,
3536 #endif
3537 stack_pointer_rtx,
3538 GEN_INT (rounded_size),
3539 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3541 offset = (HOST_WIDE_INT) padding_size;
3542 #ifdef STACK_GROWS_DOWNWARD
3543 if (STACK_PUSH_CODE == POST_DEC)
3544 /* We have already decremented the stack pointer, so get the
3545 previous value. */
3546 offset += (HOST_WIDE_INT) rounded_size;
3547 #else
3548 if (STACK_PUSH_CODE == POST_INC)
3549 /* We have already incremented the stack pointer, so get the
3550 previous value. */
3551 offset -= (HOST_WIDE_INT) rounded_size;
3552 #endif
3553 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3555 else
3557 #ifdef STACK_GROWS_DOWNWARD
3558 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3559 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3560 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3561 #else
3562 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3563 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3564 GEN_INT (rounded_size));
3565 #endif
3566 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3569 dest = gen_rtx_MEM (mode, dest_addr);
3571 if (type != 0)
3573 set_mem_attributes (dest, type, 1);
3575 if (flag_optimize_sibling_calls)
3576 /* Function incoming arguments may overlap with sibling call
3577 outgoing arguments and we cannot allow reordering of reads
3578 from function arguments with stores to outgoing arguments
3579 of sibling calls. */
3580 set_mem_alias_set (dest, 0);
3582 emit_move_insn (dest, x);
3584 #endif
3586 /* Generate code to push X onto the stack, assuming it has mode MODE and
3587 type TYPE.
3588 MODE is redundant except when X is a CONST_INT (since they don't
3589 carry mode info).
3590 SIZE is an rtx for the size of data to be copied (in bytes),
3591 needed only if X is BLKmode.
3593 ALIGN (in bits) is maximum alignment we can assume.
3595 If PARTIAL and REG are both nonzero, then copy that many of the first
3596 bytes of X into registers starting with REG, and push the rest of X.
3597 The amount of space pushed is decreased by PARTIAL bytes.
3598 REG must be a hard register in this case.
3599 If REG is zero but PARTIAL is not, take any all others actions for an
3600 argument partially in registers, but do not actually load any
3601 registers.
3603 EXTRA is the amount in bytes of extra space to leave next to this arg.
3604 This is ignored if an argument block has already been allocated.
3606 On a machine that lacks real push insns, ARGS_ADDR is the address of
3607 the bottom of the argument block for this call. We use indexing off there
3608 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3609 argument block has not been preallocated.
3611 ARGS_SO_FAR is the size of args previously pushed for this call.
3613 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3614 for arguments passed in registers. If nonzero, it will be the number
3615 of bytes required. */
3617 void
3618 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
3619 unsigned int align, int partial, rtx reg, int extra,
3620 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
3621 rtx alignment_pad)
3623 rtx xinner;
3624 enum direction stack_direction
3625 #ifdef STACK_GROWS_DOWNWARD
3626 = downward;
3627 #else
3628 = upward;
3629 #endif
3631 /* Decide where to pad the argument: `downward' for below,
3632 `upward' for above, or `none' for don't pad it.
3633 Default is below for small data on big-endian machines; else above. */
3634 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
3636 /* Invert direction if stack is post-decrement.
3637 FIXME: why? */
3638 if (STACK_PUSH_CODE == POST_DEC)
3639 if (where_pad != none)
3640 where_pad = (where_pad == downward ? upward : downward);
3642 xinner = x;
3644 if (mode == BLKmode
3645 || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
3647 /* Copy a block into the stack, entirely or partially. */
3649 rtx temp;
3650 int used;
3651 int offset;
3652 int skip;
3654 offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
3655 used = partial - offset;
3657 if (mode != BLKmode)
3659 /* A value is to be stored in an insufficiently aligned
3660 stack slot; copy via a suitably aligned slot if
3661 necessary. */
3662 size = GEN_INT (GET_MODE_SIZE (mode));
3663 if (!MEM_P (xinner))
3665 temp = assign_temp (type, 0, 1, 1);
3666 emit_move_insn (temp, xinner);
3667 xinner = temp;
3671 gcc_assert (size);
3673 /* USED is now the # of bytes we need not copy to the stack
3674 because registers will take care of them. */
3676 if (partial != 0)
3677 xinner = adjust_address (xinner, BLKmode, used);
3679 /* If the partial register-part of the arg counts in its stack size,
3680 skip the part of stack space corresponding to the registers.
3681 Otherwise, start copying to the beginning of the stack space,
3682 by setting SKIP to 0. */
3683 skip = (reg_parm_stack_space == 0) ? 0 : used;
3685 #ifdef PUSH_ROUNDING
3686 /* Do it with several push insns if that doesn't take lots of insns
3687 and if there is no difficulty with push insns that skip bytes
3688 on the stack for alignment purposes. */
3689 if (args_addr == 0
3690 && PUSH_ARGS
3691 && GET_CODE (size) == CONST_INT
3692 && skip == 0
3693 && MEM_ALIGN (xinner) >= align
3694 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
3695 /* Here we avoid the case of a structure whose weak alignment
3696 forces many pushes of a small amount of data,
3697 and such small pushes do rounding that causes trouble. */
3698 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
3699 || align >= BIGGEST_ALIGNMENT
3700 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
3701 == (align / BITS_PER_UNIT)))
3702 && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
3704 /* Push padding now if padding above and stack grows down,
3705 or if padding below and stack grows up.
3706 But if space already allocated, this has already been done. */
3707 if (extra && args_addr == 0
3708 && where_pad != none && where_pad != stack_direction)
3709 anti_adjust_stack (GEN_INT (extra));
3711 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
3713 else
3714 #endif /* PUSH_ROUNDING */
3716 rtx target;
3718 /* Otherwise make space on the stack and copy the data
3719 to the address of that space. */
3721 /* Deduct words put into registers from the size we must copy. */
3722 if (partial != 0)
3724 if (GET_CODE (size) == CONST_INT)
3725 size = GEN_INT (INTVAL (size) - used);
3726 else
3727 size = expand_binop (GET_MODE (size), sub_optab, size,
3728 GEN_INT (used), NULL_RTX, 0,
3729 OPTAB_LIB_WIDEN);
3732 /* Get the address of the stack space.
3733 In this case, we do not deal with EXTRA separately.
3734 A single stack adjust will do. */
3735 if (! args_addr)
3737 temp = push_block (size, extra, where_pad == downward);
3738 extra = 0;
3740 else if (GET_CODE (args_so_far) == CONST_INT)
3741 temp = memory_address (BLKmode,
3742 plus_constant (args_addr,
3743 skip + INTVAL (args_so_far)));
3744 else
3745 temp = memory_address (BLKmode,
3746 plus_constant (gen_rtx_PLUS (Pmode,
3747 args_addr,
3748 args_so_far),
3749 skip));
3751 if (!ACCUMULATE_OUTGOING_ARGS)
3753 /* If the source is referenced relative to the stack pointer,
3754 copy it to another register to stabilize it. We do not need
3755 to do this if we know that we won't be changing sp. */
3757 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
3758 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
3759 temp = copy_to_reg (temp);
3762 target = gen_rtx_MEM (BLKmode, temp);
3764 /* We do *not* set_mem_attributes here, because incoming arguments
3765 may overlap with sibling call outgoing arguments and we cannot
3766 allow reordering of reads from function arguments with stores
3767 to outgoing arguments of sibling calls. We do, however, want
3768 to record the alignment of the stack slot. */
3769 /* ALIGN may well be better aligned than TYPE, e.g. due to
3770 PARM_BOUNDARY. Assume the caller isn't lying. */
3771 set_mem_align (target, align);
3773 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
3776 else if (partial > 0)
3778 /* Scalar partly in registers. */
3780 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
3781 int i;
3782 int not_stack;
3783 /* # bytes of start of argument
3784 that we must make space for but need not store. */
3785 int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
3786 int args_offset = INTVAL (args_so_far);
3787 int skip;
3789 /* Push padding now if padding above and stack grows down,
3790 or if padding below and stack grows up.
3791 But if space already allocated, this has already been done. */
3792 if (extra && args_addr == 0
3793 && where_pad != none && where_pad != stack_direction)
3794 anti_adjust_stack (GEN_INT (extra));
3796 /* If we make space by pushing it, we might as well push
3797 the real data. Otherwise, we can leave OFFSET nonzero
3798 and leave the space uninitialized. */
3799 if (args_addr == 0)
3800 offset = 0;
3802 /* Now NOT_STACK gets the number of words that we don't need to
3803 allocate on the stack. Convert OFFSET to words too. */
3804 not_stack = (partial - offset) / UNITS_PER_WORD;
3805 offset /= UNITS_PER_WORD;
3807 /* If the partial register-part of the arg counts in its stack size,
3808 skip the part of stack space corresponding to the registers.
3809 Otherwise, start copying to the beginning of the stack space,
3810 by setting SKIP to 0. */
3811 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
3813 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
3814 x = validize_mem (force_const_mem (mode, x));
3816 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
3817 SUBREGs of such registers are not allowed. */
3818 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
3819 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
3820 x = copy_to_reg (x);
3822 /* Loop over all the words allocated on the stack for this arg. */
3823 /* We can do it by words, because any scalar bigger than a word
3824 has a size a multiple of a word. */
3825 #ifndef PUSH_ARGS_REVERSED
3826 for (i = not_stack; i < size; i++)
3827 #else
3828 for (i = size - 1; i >= not_stack; i--)
3829 #endif
3830 if (i >= not_stack + offset)
3831 emit_push_insn (operand_subword_force (x, i, mode),
3832 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
3833 0, args_addr,
3834 GEN_INT (args_offset + ((i - not_stack + skip)
3835 * UNITS_PER_WORD)),
3836 reg_parm_stack_space, alignment_pad);
3838 else
3840 rtx addr;
3841 rtx dest;
3843 /* Push padding now if padding above and stack grows down,
3844 or if padding below and stack grows up.
3845 But if space already allocated, this has already been done. */
3846 if (extra && args_addr == 0
3847 && where_pad != none && where_pad != stack_direction)
3848 anti_adjust_stack (GEN_INT (extra));
3850 #ifdef PUSH_ROUNDING
3851 if (args_addr == 0 && PUSH_ARGS)
3852 emit_single_push_insn (mode, x, type);
3853 else
3854 #endif
3856 if (GET_CODE (args_so_far) == CONST_INT)
3857 addr
3858 = memory_address (mode,
3859 plus_constant (args_addr,
3860 INTVAL (args_so_far)));
3861 else
3862 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
3863 args_so_far));
3864 dest = gen_rtx_MEM (mode, addr);
3866 /* We do *not* set_mem_attributes here, because incoming arguments
3867 may overlap with sibling call outgoing arguments and we cannot
3868 allow reordering of reads from function arguments with stores
3869 to outgoing arguments of sibling calls. We do, however, want
3870 to record the alignment of the stack slot. */
3871 /* ALIGN may well be better aligned than TYPE, e.g. due to
3872 PARM_BOUNDARY. Assume the caller isn't lying. */
3873 set_mem_align (dest, align);
3875 emit_move_insn (dest, x);
3879 /* If part should go in registers, copy that part
3880 into the appropriate registers. Do this now, at the end,
3881 since mem-to-mem copies above may do function calls. */
3882 if (partial > 0 && reg != 0)
3884 /* Handle calls that pass values in multiple non-contiguous locations.
3885 The Irix 6 ABI has examples of this. */
3886 if (GET_CODE (reg) == PARALLEL)
3887 emit_group_load (reg, x, type, -1);
3888 else
3890 gcc_assert (partial % UNITS_PER_WORD == 0);
3891 move_block_to_reg (REGNO (reg), x, partial / UNITS_PER_WORD, mode);
3895 if (extra && args_addr == 0 && where_pad == stack_direction)
3896 anti_adjust_stack (GEN_INT (extra));
3898 if (alignment_pad && args_addr == 0)
3899 anti_adjust_stack (alignment_pad);
3902 /* Return X if X can be used as a subtarget in a sequence of arithmetic
3903 operations. */
3905 static rtx
3906 get_subtarget (rtx x)
3908 return (optimize
3909 || x == 0
3910 /* Only registers can be subtargets. */
3911 || !REG_P (x)
3912 /* Don't use hard regs to avoid extending their life. */
3913 || REGNO (x) < FIRST_PSEUDO_REGISTER
3914 ? 0 : x);
3917 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
3918 FIELD is a bitfield. Returns true if the optimization was successful,
3919 and there's nothing else to do. */
3921 static bool
3922 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize,
3923 unsigned HOST_WIDE_INT bitpos,
3924 enum machine_mode mode1, rtx str_rtx,
3925 tree to, tree src)
3927 enum machine_mode str_mode = GET_MODE (str_rtx);
3928 unsigned int str_bitsize = GET_MODE_BITSIZE (str_mode);
3929 tree op0, op1;
3930 rtx value, result;
3931 optab binop;
3933 if (mode1 != VOIDmode
3934 || bitsize >= BITS_PER_WORD
3935 || str_bitsize > BITS_PER_WORD
3936 || TREE_SIDE_EFFECTS (to)
3937 || TREE_THIS_VOLATILE (to))
3938 return false;
3940 STRIP_NOPS (src);
3941 if (!BINARY_CLASS_P (src)
3942 || TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
3943 return false;
3945 op0 = TREE_OPERAND (src, 0);
3946 op1 = TREE_OPERAND (src, 1);
3947 STRIP_NOPS (op0);
3949 if (!operand_equal_p (to, op0, 0))
3950 return false;
3952 if (MEM_P (str_rtx))
3954 unsigned HOST_WIDE_INT offset1;
3956 if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
3957 str_mode = word_mode;
3958 str_mode = get_best_mode (bitsize, bitpos,
3959 MEM_ALIGN (str_rtx), str_mode, 0);
3960 if (str_mode == VOIDmode)
3961 return false;
3962 str_bitsize = GET_MODE_BITSIZE (str_mode);
3964 offset1 = bitpos;
3965 bitpos %= str_bitsize;
3966 offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
3967 str_rtx = adjust_address (str_rtx, str_mode, offset1);
3969 else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
3970 return false;
3972 /* If the bit field covers the whole REG/MEM, store_field
3973 will likely generate better code. */
3974 if (bitsize >= str_bitsize)
3975 return false;
3977 /* We can't handle fields split across multiple entities. */
3978 if (bitpos + bitsize > str_bitsize)
3979 return false;
3981 if (BYTES_BIG_ENDIAN)
3982 bitpos = str_bitsize - bitpos - bitsize;
3984 switch (TREE_CODE (src))
3986 case PLUS_EXPR:
3987 case MINUS_EXPR:
3988 /* For now, just optimize the case of the topmost bitfield
3989 where we don't need to do any masking and also
3990 1 bit bitfields where xor can be used.
3991 We might win by one instruction for the other bitfields
3992 too if insv/extv instructions aren't used, so that
3993 can be added later. */
3994 if (bitpos + bitsize != str_bitsize
3995 && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
3996 break;
3998 value = expand_expr (op1, NULL_RTX, str_mode, 0);
3999 value = convert_modes (str_mode,
4000 TYPE_MODE (TREE_TYPE (op1)), value,
4001 TYPE_UNSIGNED (TREE_TYPE (op1)));
4003 /* We may be accessing data outside the field, which means
4004 we can alias adjacent data. */
4005 if (MEM_P (str_rtx))
4007 str_rtx = shallow_copy_rtx (str_rtx);
4008 set_mem_alias_set (str_rtx, 0);
4009 set_mem_expr (str_rtx, 0);
4012 binop = TREE_CODE (src) == PLUS_EXPR ? add_optab : sub_optab;
4013 if (bitsize == 1 && bitpos + bitsize != str_bitsize)
4015 value = expand_and (str_mode, value, const1_rtx, NULL);
4016 binop = xor_optab;
4018 value = expand_shift (LSHIFT_EXPR, str_mode, value,
4019 build_int_cst (NULL_TREE, bitpos),
4020 NULL_RTX, 1);
4021 result = expand_binop (str_mode, binop, str_rtx,
4022 value, str_rtx, 1, OPTAB_WIDEN);
4023 if (result != str_rtx)
4024 emit_move_insn (str_rtx, result);
4025 return true;
4027 case BIT_IOR_EXPR:
4028 case BIT_XOR_EXPR:
4029 if (TREE_CODE (op1) != INTEGER_CST)
4030 break;
4031 value = expand_expr (op1, NULL_RTX, GET_MODE (str_rtx), 0);
4032 value = convert_modes (GET_MODE (str_rtx),
4033 TYPE_MODE (TREE_TYPE (op1)), value,
4034 TYPE_UNSIGNED (TREE_TYPE (op1)));
4036 /* We may be accessing data outside the field, which means
4037 we can alias adjacent data. */
4038 if (MEM_P (str_rtx))
4040 str_rtx = shallow_copy_rtx (str_rtx);
4041 set_mem_alias_set (str_rtx, 0);
4042 set_mem_expr (str_rtx, 0);
4045 binop = TREE_CODE (src) == BIT_IOR_EXPR ? ior_optab : xor_optab;
4046 if (bitpos + bitsize != GET_MODE_BITSIZE (GET_MODE (str_rtx)))
4048 rtx mask = GEN_INT (((unsigned HOST_WIDE_INT) 1 << bitsize)
4049 - 1);
4050 value = expand_and (GET_MODE (str_rtx), value, mask,
4051 NULL_RTX);
4053 value = expand_shift (LSHIFT_EXPR, GET_MODE (str_rtx), value,
4054 build_int_cst (NULL_TREE, bitpos),
4055 NULL_RTX, 1);
4056 result = expand_binop (GET_MODE (str_rtx), binop, str_rtx,
4057 value, str_rtx, 1, OPTAB_WIDEN);
4058 if (result != str_rtx)
4059 emit_move_insn (str_rtx, result);
4060 return true;
4062 default:
4063 break;
4066 return false;
4070 /* Expand an assignment that stores the value of FROM into TO. */
4072 void
4073 expand_assignment (tree to, tree from)
4075 rtx to_rtx = 0;
4076 rtx result;
4078 /* Don't crash if the lhs of the assignment was erroneous. */
4079 if (TREE_CODE (to) == ERROR_MARK)
4081 result = expand_normal (from);
4082 return;
4085 /* Optimize away no-op moves without side-effects. */
4086 if (operand_equal_p (to, from, 0))
4087 return;
4089 /* Assignment of a structure component needs special treatment
4090 if the structure component's rtx is not simply a MEM.
4091 Assignment of an array element at a constant index, and assignment of
4092 an array element in an unaligned packed structure field, has the same
4093 problem. */
4094 if (handled_component_p (to)
4095 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
4097 enum machine_mode mode1;
4098 HOST_WIDE_INT bitsize, bitpos;
4099 tree offset;
4100 int unsignedp;
4101 int volatilep = 0;
4102 tree tem;
4104 push_temp_slots ();
4105 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
4106 &unsignedp, &volatilep, true);
4108 /* If we are going to use store_bit_field and extract_bit_field,
4109 make sure to_rtx will be safe for multiple use. */
4111 to_rtx = expand_normal (tem);
4113 if (offset != 0)
4115 rtx offset_rtx;
4117 if (!MEM_P (to_rtx))
4119 /* We can get constant negative offsets into arrays with broken
4120 user code. Translate this to a trap instead of ICEing. */
4121 gcc_assert (TREE_CODE (offset) == INTEGER_CST);
4122 expand_builtin_trap ();
4123 to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
4126 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
4127 #ifdef POINTERS_EXTEND_UNSIGNED
4128 if (GET_MODE (offset_rtx) != Pmode)
4129 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
4130 #else
4131 if (GET_MODE (offset_rtx) != ptr_mode)
4132 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
4133 #endif
4135 /* A constant address in TO_RTX can have VOIDmode, we must not try
4136 to call force_reg for that case. Avoid that case. */
4137 if (MEM_P (to_rtx)
4138 && GET_MODE (to_rtx) == BLKmode
4139 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
4140 && bitsize > 0
4141 && (bitpos % bitsize) == 0
4142 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
4143 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
4145 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
4146 bitpos = 0;
4149 to_rtx = offset_address (to_rtx, offset_rtx,
4150 highest_pow2_factor_for_target (to,
4151 offset));
4154 /* Handle expand_expr of a complex value returning a CONCAT. */
4155 if (GET_CODE (to_rtx) == CONCAT)
4157 if (TREE_CODE (TREE_TYPE (from)) == COMPLEX_TYPE)
4159 gcc_assert (bitpos == 0);
4160 result = store_expr (from, to_rtx, false);
4162 else
4164 gcc_assert (bitpos == 0 || bitpos == GET_MODE_BITSIZE (mode1));
4165 result = store_expr (from, XEXP (to_rtx, bitpos != 0), false);
4168 else
4170 if (MEM_P (to_rtx))
4172 /* If the field is at offset zero, we could have been given the
4173 DECL_RTX of the parent struct. Don't munge it. */
4174 to_rtx = shallow_copy_rtx (to_rtx);
4176 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
4178 /* Deal with volatile and readonly fields. The former is only
4179 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4180 if (volatilep)
4181 MEM_VOLATILE_P (to_rtx) = 1;
4182 if (component_uses_parent_alias_set (to))
4183 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
4186 if (optimize_bitfield_assignment_op (bitsize, bitpos, mode1,
4187 to_rtx, to, from))
4188 result = NULL;
4189 else
4190 result = store_field (to_rtx, bitsize, bitpos, mode1, from,
4191 TREE_TYPE (tem), get_alias_set (to));
4194 if (result)
4195 preserve_temp_slots (result);
4196 free_temp_slots ();
4197 pop_temp_slots ();
4198 return;
4201 /* If the rhs is a function call and its value is not an aggregate,
4202 call the function before we start to compute the lhs.
4203 This is needed for correct code for cases such as
4204 val = setjmp (buf) on machines where reference to val
4205 requires loading up part of an address in a separate insn.
4207 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4208 since it might be a promoted variable where the zero- or sign- extension
4209 needs to be done. Handling this in the normal way is safe because no
4210 computation is done before the call. */
4211 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
4212 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
4213 && ! ((TREE_CODE (to) == VAR_DECL || TREE_CODE (to) == PARM_DECL)
4214 && REG_P (DECL_RTL (to))))
4216 rtx value;
4218 push_temp_slots ();
4219 value = expand_normal (from);
4220 if (to_rtx == 0)
4221 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4223 /* Handle calls that return values in multiple non-contiguous locations.
4224 The Irix 6 ABI has examples of this. */
4225 if (GET_CODE (to_rtx) == PARALLEL)
4226 emit_group_load (to_rtx, value, TREE_TYPE (from),
4227 int_size_in_bytes (TREE_TYPE (from)));
4228 else if (GET_MODE (to_rtx) == BLKmode)
4229 emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
4230 else
4232 if (POINTER_TYPE_P (TREE_TYPE (to)))
4233 value = convert_memory_address (GET_MODE (to_rtx), value);
4234 emit_move_insn (to_rtx, value);
4236 preserve_temp_slots (to_rtx);
4237 free_temp_slots ();
4238 pop_temp_slots ();
4239 return;
4242 /* Ordinary treatment. Expand TO to get a REG or MEM rtx.
4243 Don't re-expand if it was expanded already (in COMPONENT_REF case). */
4245 if (to_rtx == 0)
4246 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4248 /* Don't move directly into a return register. */
4249 if (TREE_CODE (to) == RESULT_DECL
4250 && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
4252 rtx temp;
4254 push_temp_slots ();
4255 temp = expand_expr (from, 0, GET_MODE (to_rtx), 0);
4257 if (GET_CODE (to_rtx) == PARALLEL)
4258 emit_group_load (to_rtx, temp, TREE_TYPE (from),
4259 int_size_in_bytes (TREE_TYPE (from)));
4260 else
4261 emit_move_insn (to_rtx, temp);
4263 preserve_temp_slots (to_rtx);
4264 free_temp_slots ();
4265 pop_temp_slots ();
4266 return;
4269 /* In case we are returning the contents of an object which overlaps
4270 the place the value is being stored, use a safe function when copying
4271 a value through a pointer into a structure value return block. */
4272 if (TREE_CODE (to) == RESULT_DECL && TREE_CODE (from) == INDIRECT_REF
4273 && current_function_returns_struct
4274 && !current_function_returns_pcc_struct)
4276 rtx from_rtx, size;
4278 push_temp_slots ();
4279 size = expr_size (from);
4280 from_rtx = expand_normal (from);
4282 emit_library_call (memmove_libfunc, LCT_NORMAL,
4283 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
4284 XEXP (from_rtx, 0), Pmode,
4285 convert_to_mode (TYPE_MODE (sizetype),
4286 size, TYPE_UNSIGNED (sizetype)),
4287 TYPE_MODE (sizetype));
4289 preserve_temp_slots (to_rtx);
4290 free_temp_slots ();
4291 pop_temp_slots ();
4292 return;
4295 /* Compute FROM and store the value in the rtx we got. */
4297 push_temp_slots ();
4298 result = store_expr (from, to_rtx, 0);
4299 preserve_temp_slots (result);
4300 free_temp_slots ();
4301 pop_temp_slots ();
4302 return;
4305 /* Generate code for computing expression EXP,
4306 and storing the value into TARGET.
4308 If the mode is BLKmode then we may return TARGET itself.
4309 It turns out that in BLKmode it doesn't cause a problem.
4310 because C has no operators that could combine two different
4311 assignments into the same BLKmode object with different values
4312 with no sequence point. Will other languages need this to
4313 be more thorough?
4315 If CALL_PARAM_P is nonzero, this is a store into a call param on the
4316 stack, and block moves may need to be treated specially. */
4319 store_expr (tree exp, rtx target, int call_param_p)
4321 rtx temp;
4322 rtx alt_rtl = NULL_RTX;
4323 int dont_return_target = 0;
4325 if (VOID_TYPE_P (TREE_TYPE (exp)))
4327 /* C++ can generate ?: expressions with a throw expression in one
4328 branch and an rvalue in the other. Here, we resolve attempts to
4329 store the throw expression's nonexistent result. */
4330 gcc_assert (!call_param_p);
4331 expand_expr (exp, const0_rtx, VOIDmode, 0);
4332 return NULL_RTX;
4334 if (TREE_CODE (exp) == COMPOUND_EXPR)
4336 /* Perform first part of compound expression, then assign from second
4337 part. */
4338 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
4339 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4340 return store_expr (TREE_OPERAND (exp, 1), target, call_param_p);
4342 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
4344 /* For conditional expression, get safe form of the target. Then
4345 test the condition, doing the appropriate assignment on either
4346 side. This avoids the creation of unnecessary temporaries.
4347 For non-BLKmode, it is more efficient not to do this. */
4349 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
4351 do_pending_stack_adjust ();
4352 NO_DEFER_POP;
4353 jumpifnot (TREE_OPERAND (exp, 0), lab1);
4354 store_expr (TREE_OPERAND (exp, 1), target, call_param_p);
4355 emit_jump_insn (gen_jump (lab2));
4356 emit_barrier ();
4357 emit_label (lab1);
4358 store_expr (TREE_OPERAND (exp, 2), target, call_param_p);
4359 emit_label (lab2);
4360 OK_DEFER_POP;
4362 return NULL_RTX;
4364 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
4365 /* If this is a scalar in a register that is stored in a wider mode
4366 than the declared mode, compute the result into its declared mode
4367 and then convert to the wider mode. Our value is the computed
4368 expression. */
4370 rtx inner_target = 0;
4372 /* We can do the conversion inside EXP, which will often result
4373 in some optimizations. Do the conversion in two steps: first
4374 change the signedness, if needed, then the extend. But don't
4375 do this if the type of EXP is a subtype of something else
4376 since then the conversion might involve more than just
4377 converting modes. */
4378 if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
4379 && TREE_TYPE (TREE_TYPE (exp)) == 0
4380 && (!lang_hooks.reduce_bit_field_operations
4381 || (GET_MODE_PRECISION (GET_MODE (target))
4382 == TYPE_PRECISION (TREE_TYPE (exp)))))
4384 if (TYPE_UNSIGNED (TREE_TYPE (exp))
4385 != SUBREG_PROMOTED_UNSIGNED_P (target))
4387 /* Some types, e.g. Fortran's logical*4, won't have a signed
4388 version, so use the mode instead. */
4389 tree ntype
4390 = (get_signed_or_unsigned_type
4391 (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)));
4392 if (ntype == NULL)
4393 ntype = lang_hooks.types.type_for_mode
4394 (TYPE_MODE (TREE_TYPE (exp)),
4395 SUBREG_PROMOTED_UNSIGNED_P (target));
4397 exp = fold_convert (ntype, exp);
4400 exp = fold_convert (lang_hooks.types.type_for_mode
4401 (GET_MODE (SUBREG_REG (target)),
4402 SUBREG_PROMOTED_UNSIGNED_P (target)),
4403 exp);
4405 inner_target = SUBREG_REG (target);
4408 temp = expand_expr (exp, inner_target, VOIDmode,
4409 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4411 /* If TEMP is a VOIDmode constant, use convert_modes to make
4412 sure that we properly convert it. */
4413 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
4415 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
4416 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
4417 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
4418 GET_MODE (target), temp,
4419 SUBREG_PROMOTED_UNSIGNED_P (target));
4422 convert_move (SUBREG_REG (target), temp,
4423 SUBREG_PROMOTED_UNSIGNED_P (target));
4425 return NULL_RTX;
4427 else
4429 temp = expand_expr_real (exp, target, GET_MODE (target),
4430 (call_param_p
4431 ? EXPAND_STACK_PARM : EXPAND_NORMAL),
4432 &alt_rtl);
4433 /* Return TARGET if it's a specified hardware register.
4434 If TARGET is a volatile mem ref, either return TARGET
4435 or return a reg copied *from* TARGET; ANSI requires this.
4437 Otherwise, if TEMP is not TARGET, return TEMP
4438 if it is constant (for efficiency),
4439 or if we really want the correct value. */
4440 if (!(target && REG_P (target)
4441 && REGNO (target) < FIRST_PSEUDO_REGISTER)
4442 && !(MEM_P (target) && MEM_VOLATILE_P (target))
4443 && ! rtx_equal_p (temp, target)
4444 && CONSTANT_P (temp))
4445 dont_return_target = 1;
4448 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
4449 the same as that of TARGET, adjust the constant. This is needed, for
4450 example, in case it is a CONST_DOUBLE and we want only a word-sized
4451 value. */
4452 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
4453 && TREE_CODE (exp) != ERROR_MARK
4454 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
4455 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
4456 temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
4458 /* If value was not generated in the target, store it there.
4459 Convert the value to TARGET's type first if necessary and emit the
4460 pending incrementations that have been queued when expanding EXP.
4461 Note that we cannot emit the whole queue blindly because this will
4462 effectively disable the POST_INC optimization later.
4464 If TEMP and TARGET compare equal according to rtx_equal_p, but
4465 one or both of them are volatile memory refs, we have to distinguish
4466 two cases:
4467 - expand_expr has used TARGET. In this case, we must not generate
4468 another copy. This can be detected by TARGET being equal according
4469 to == .
4470 - expand_expr has not used TARGET - that means that the source just
4471 happens to have the same RTX form. Since temp will have been created
4472 by expand_expr, it will compare unequal according to == .
4473 We must generate a copy in this case, to reach the correct number
4474 of volatile memory references. */
4476 if ((! rtx_equal_p (temp, target)
4477 || (temp != target && (side_effects_p (temp)
4478 || side_effects_p (target))))
4479 && TREE_CODE (exp) != ERROR_MARK
4480 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
4481 but TARGET is not valid memory reference, TEMP will differ
4482 from TARGET although it is really the same location. */
4483 && !(alt_rtl && rtx_equal_p (alt_rtl, target))
4484 /* If there's nothing to copy, don't bother. Don't call
4485 expr_size unless necessary, because some front-ends (C++)
4486 expr_size-hook must not be given objects that are not
4487 supposed to be bit-copied or bit-initialized. */
4488 && expr_size (exp) != const0_rtx)
4490 if (GET_MODE (temp) != GET_MODE (target)
4491 && GET_MODE (temp) != VOIDmode)
4493 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
4494 if (dont_return_target)
4496 /* In this case, we will return TEMP,
4497 so make sure it has the proper mode.
4498 But don't forget to store the value into TARGET. */
4499 temp = convert_to_mode (GET_MODE (target), temp, unsignedp);
4500 emit_move_insn (target, temp);
4502 else
4503 convert_move (target, temp, unsignedp);
4506 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
4508 /* Handle copying a string constant into an array. The string
4509 constant may be shorter than the array. So copy just the string's
4510 actual length, and clear the rest. First get the size of the data
4511 type of the string, which is actually the size of the target. */
4512 rtx size = expr_size (exp);
4514 if (GET_CODE (size) == CONST_INT
4515 && INTVAL (size) < TREE_STRING_LENGTH (exp))
4516 emit_block_move (target, temp, size,
4517 (call_param_p
4518 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4519 else
4521 /* Compute the size of the data to copy from the string. */
4522 tree copy_size
4523 = size_binop (MIN_EXPR,
4524 make_tree (sizetype, size),
4525 size_int (TREE_STRING_LENGTH (exp)));
4526 rtx copy_size_rtx
4527 = expand_expr (copy_size, NULL_RTX, VOIDmode,
4528 (call_param_p
4529 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
4530 rtx label = 0;
4532 /* Copy that much. */
4533 copy_size_rtx = convert_to_mode (ptr_mode, copy_size_rtx,
4534 TYPE_UNSIGNED (sizetype));
4535 emit_block_move (target, temp, copy_size_rtx,
4536 (call_param_p
4537 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4539 /* Figure out how much is left in TARGET that we have to clear.
4540 Do all calculations in ptr_mode. */
4541 if (GET_CODE (copy_size_rtx) == CONST_INT)
4543 size = plus_constant (size, -INTVAL (copy_size_rtx));
4544 target = adjust_address (target, BLKmode,
4545 INTVAL (copy_size_rtx));
4547 else
4549 size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
4550 copy_size_rtx, NULL_RTX, 0,
4551 OPTAB_LIB_WIDEN);
4553 #ifdef POINTERS_EXTEND_UNSIGNED
4554 if (GET_MODE (copy_size_rtx) != Pmode)
4555 copy_size_rtx = convert_to_mode (Pmode, copy_size_rtx,
4556 TYPE_UNSIGNED (sizetype));
4557 #endif
4559 target = offset_address (target, copy_size_rtx,
4560 highest_pow2_factor (copy_size));
4561 label = gen_label_rtx ();
4562 emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
4563 GET_MODE (size), 0, label);
4566 if (size != const0_rtx)
4567 clear_storage (target, size, BLOCK_OP_NORMAL);
4569 if (label)
4570 emit_label (label);
4573 /* Handle calls that return values in multiple non-contiguous locations.
4574 The Irix 6 ABI has examples of this. */
4575 else if (GET_CODE (target) == PARALLEL)
4576 emit_group_load (target, temp, TREE_TYPE (exp),
4577 int_size_in_bytes (TREE_TYPE (exp)));
4578 else if (GET_MODE (temp) == BLKmode)
4579 emit_block_move (target, temp, expr_size (exp),
4580 (call_param_p
4581 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4582 else
4584 temp = force_operand (temp, target);
4585 if (temp != target)
4586 emit_move_insn (target, temp);
4590 return NULL_RTX;
4593 /* Helper for categorize_ctor_elements. Identical interface. */
4595 static bool
4596 categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts,
4597 HOST_WIDE_INT *p_elt_count,
4598 bool *p_must_clear)
4600 unsigned HOST_WIDE_INT idx;
4601 HOST_WIDE_INT nz_elts, elt_count;
4602 tree value, purpose;
4604 /* Whether CTOR is a valid constant initializer, in accordance with what
4605 initializer_constant_valid_p does. If inferred from the constructor
4606 elements, true until proven otherwise. */
4607 bool const_from_elts_p = constructor_static_from_elts_p (ctor);
4608 bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
4610 nz_elts = 0;
4611 elt_count = 0;
4613 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
4615 HOST_WIDE_INT mult;
4617 mult = 1;
4618 if (TREE_CODE (purpose) == RANGE_EXPR)
4620 tree lo_index = TREE_OPERAND (purpose, 0);
4621 tree hi_index = TREE_OPERAND (purpose, 1);
4623 if (host_integerp (lo_index, 1) && host_integerp (hi_index, 1))
4624 mult = (tree_low_cst (hi_index, 1)
4625 - tree_low_cst (lo_index, 1) + 1);
4628 switch (TREE_CODE (value))
4630 case CONSTRUCTOR:
4632 HOST_WIDE_INT nz = 0, ic = 0;
4634 bool const_elt_p
4635 = categorize_ctor_elements_1 (value, &nz, &ic, p_must_clear);
4637 nz_elts += mult * nz;
4638 elt_count += mult * ic;
4640 if (const_from_elts_p && const_p)
4641 const_p = const_elt_p;
4643 break;
4645 case INTEGER_CST:
4646 case REAL_CST:
4647 if (!initializer_zerop (value))
4648 nz_elts += mult;
4649 elt_count += mult;
4650 break;
4652 case STRING_CST:
4653 nz_elts += mult * TREE_STRING_LENGTH (value);
4654 elt_count += mult * TREE_STRING_LENGTH (value);
4655 break;
4657 case COMPLEX_CST:
4658 if (!initializer_zerop (TREE_REALPART (value)))
4659 nz_elts += mult;
4660 if (!initializer_zerop (TREE_IMAGPART (value)))
4661 nz_elts += mult;
4662 elt_count += mult;
4663 break;
4665 case VECTOR_CST:
4667 tree v;
4668 for (v = TREE_VECTOR_CST_ELTS (value); v; v = TREE_CHAIN (v))
4670 if (!initializer_zerop (TREE_VALUE (v)))
4671 nz_elts += mult;
4672 elt_count += mult;
4675 break;
4677 default:
4678 nz_elts += mult;
4679 elt_count += mult;
4681 if (const_from_elts_p && const_p)
4682 const_p = initializer_constant_valid_p (value, TREE_TYPE (value))
4683 != NULL_TREE;
4684 break;
4688 if (!*p_must_clear
4689 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4690 || TREE_CODE (TREE_TYPE (ctor)) == QUAL_UNION_TYPE))
4692 tree init_sub_type;
4693 bool clear_this = true;
4695 if (!VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)))
4697 /* We don't expect more than one element of the union to be
4698 initialized. Not sure what we should do otherwise... */
4699 gcc_assert (VEC_length (constructor_elt, CONSTRUCTOR_ELTS (ctor))
4700 == 1);
4702 init_sub_type = TREE_TYPE (VEC_index (constructor_elt,
4703 CONSTRUCTOR_ELTS (ctor),
4704 0)->value);
4706 /* ??? We could look at each element of the union, and find the
4707 largest element. Which would avoid comparing the size of the
4708 initialized element against any tail padding in the union.
4709 Doesn't seem worth the effort... */
4710 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor)),
4711 TYPE_SIZE (init_sub_type)) == 1)
4713 /* And now we have to find out if the element itself is fully
4714 constructed. E.g. for union { struct { int a, b; } s; } u
4715 = { .s = { .a = 1 } }. */
4716 if (elt_count == count_type_elements (init_sub_type, false))
4717 clear_this = false;
4721 *p_must_clear = clear_this;
4724 *p_nz_elts += nz_elts;
4725 *p_elt_count += elt_count;
4727 return const_p;
4730 /* Examine CTOR to discover:
4731 * how many scalar fields are set to nonzero values,
4732 and place it in *P_NZ_ELTS;
4733 * how many scalar fields in total are in CTOR,
4734 and place it in *P_ELT_COUNT.
4735 * if a type is a union, and the initializer from the constructor
4736 is not the largest element in the union, then set *p_must_clear.
4738 Return whether or not CTOR is a valid static constant initializer, the same
4739 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
4741 bool
4742 categorize_ctor_elements (tree ctor, HOST_WIDE_INT *p_nz_elts,
4743 HOST_WIDE_INT *p_elt_count,
4744 bool *p_must_clear)
4746 *p_nz_elts = 0;
4747 *p_elt_count = 0;
4748 *p_must_clear = false;
4750 return
4751 categorize_ctor_elements_1 (ctor, p_nz_elts, p_elt_count, p_must_clear);
4754 /* Count the number of scalars in TYPE. Return -1 on overflow or
4755 variable-sized. If ALLOW_FLEXARR is true, don't count flexible
4756 array member at the end of the structure. */
4758 HOST_WIDE_INT
4759 count_type_elements (tree type, bool allow_flexarr)
4761 const HOST_WIDE_INT max = ~((HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT-1));
4762 switch (TREE_CODE (type))
4764 case ARRAY_TYPE:
4766 tree telts = array_type_nelts (type);
4767 if (telts && host_integerp (telts, 1))
4769 HOST_WIDE_INT n = tree_low_cst (telts, 1) + 1;
4770 HOST_WIDE_INT m = count_type_elements (TREE_TYPE (type), false);
4771 if (n == 0)
4772 return 0;
4773 else if (max / n > m)
4774 return n * m;
4776 return -1;
4779 case RECORD_TYPE:
4781 HOST_WIDE_INT n = 0, t;
4782 tree f;
4784 for (f = TYPE_FIELDS (type); f ; f = TREE_CHAIN (f))
4785 if (TREE_CODE (f) == FIELD_DECL)
4787 t = count_type_elements (TREE_TYPE (f), false);
4788 if (t < 0)
4790 /* Check for structures with flexible array member. */
4791 tree tf = TREE_TYPE (f);
4792 if (allow_flexarr
4793 && TREE_CHAIN (f) == NULL
4794 && TREE_CODE (tf) == ARRAY_TYPE
4795 && TYPE_DOMAIN (tf)
4796 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
4797 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
4798 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
4799 && int_size_in_bytes (type) >= 0)
4800 break;
4802 return -1;
4804 n += t;
4807 return n;
4810 case UNION_TYPE:
4811 case QUAL_UNION_TYPE:
4813 /* Ho hum. How in the world do we guess here? Clearly it isn't
4814 right to count the fields. Guess based on the number of words. */
4815 HOST_WIDE_INT n = int_size_in_bytes (type);
4816 if (n < 0)
4817 return -1;
4818 return n / UNITS_PER_WORD;
4821 case COMPLEX_TYPE:
4822 return 2;
4824 case VECTOR_TYPE:
4825 return TYPE_VECTOR_SUBPARTS (type);
4827 case INTEGER_TYPE:
4828 case REAL_TYPE:
4829 case ENUMERAL_TYPE:
4830 case BOOLEAN_TYPE:
4831 case POINTER_TYPE:
4832 case OFFSET_TYPE:
4833 case REFERENCE_TYPE:
4834 return 1;
4836 case VOID_TYPE:
4837 case METHOD_TYPE:
4838 case FUNCTION_TYPE:
4839 case LANG_TYPE:
4840 default:
4841 gcc_unreachable ();
4845 /* Return 1 if EXP contains mostly (3/4) zeros. */
4847 static int
4848 mostly_zeros_p (tree exp)
4850 if (TREE_CODE (exp) == CONSTRUCTOR)
4853 HOST_WIDE_INT nz_elts, count, elts;
4854 bool must_clear;
4856 categorize_ctor_elements (exp, &nz_elts, &count, &must_clear);
4857 if (must_clear)
4858 return 1;
4860 elts = count_type_elements (TREE_TYPE (exp), false);
4862 return nz_elts < elts / 4;
4865 return initializer_zerop (exp);
4868 /* Return 1 if EXP contains all zeros. */
4870 static int
4871 all_zeros_p (tree exp)
4873 if (TREE_CODE (exp) == CONSTRUCTOR)
4876 HOST_WIDE_INT nz_elts, count;
4877 bool must_clear;
4879 categorize_ctor_elements (exp, &nz_elts, &count, &must_clear);
4880 return nz_elts == 0;
4883 return initializer_zerop (exp);
4886 /* Helper function for store_constructor.
4887 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
4888 TYPE is the type of the CONSTRUCTOR, not the element type.
4889 CLEARED is as for store_constructor.
4890 ALIAS_SET is the alias set to use for any stores.
4892 This provides a recursive shortcut back to store_constructor when it isn't
4893 necessary to go through store_field. This is so that we can pass through
4894 the cleared field to let store_constructor know that we may not have to
4895 clear a substructure if the outer structure has already been cleared. */
4897 static void
4898 store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
4899 HOST_WIDE_INT bitpos, enum machine_mode mode,
4900 tree exp, tree type, int cleared, int alias_set)
4902 if (TREE_CODE (exp) == CONSTRUCTOR
4903 /* We can only call store_constructor recursively if the size and
4904 bit position are on a byte boundary. */
4905 && bitpos % BITS_PER_UNIT == 0
4906 && (bitsize > 0 && bitsize % BITS_PER_UNIT == 0)
4907 /* If we have a nonzero bitpos for a register target, then we just
4908 let store_field do the bitfield handling. This is unlikely to
4909 generate unnecessary clear instructions anyways. */
4910 && (bitpos == 0 || MEM_P (target)))
4912 if (MEM_P (target))
4913 target
4914 = adjust_address (target,
4915 GET_MODE (target) == BLKmode
4916 || 0 != (bitpos
4917 % GET_MODE_ALIGNMENT (GET_MODE (target)))
4918 ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
4921 /* Update the alias set, if required. */
4922 if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
4923 && MEM_ALIAS_SET (target) != 0)
4925 target = copy_rtx (target);
4926 set_mem_alias_set (target, alias_set);
4929 store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
4931 else
4932 store_field (target, bitsize, bitpos, mode, exp, type, alias_set);
4935 /* Store the value of constructor EXP into the rtx TARGET.
4936 TARGET is either a REG or a MEM; we know it cannot conflict, since
4937 safe_from_p has been called.
4938 CLEARED is true if TARGET is known to have been zero'd.
4939 SIZE is the number of bytes of TARGET we are allowed to modify: this
4940 may not be the same as the size of EXP if we are assigning to a field
4941 which has been packed to exclude padding bits. */
4943 static void
4944 store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
4946 tree type = TREE_TYPE (exp);
4947 #ifdef WORD_REGISTER_OPERATIONS
4948 HOST_WIDE_INT exp_size = int_size_in_bytes (type);
4949 #endif
4951 switch (TREE_CODE (type))
4953 case RECORD_TYPE:
4954 case UNION_TYPE:
4955 case QUAL_UNION_TYPE:
4957 unsigned HOST_WIDE_INT idx;
4958 tree field, value;
4960 /* If size is zero or the target is already cleared, do nothing. */
4961 if (size == 0 || cleared)
4962 cleared = 1;
4963 /* We either clear the aggregate or indicate the value is dead. */
4964 else if ((TREE_CODE (type) == UNION_TYPE
4965 || TREE_CODE (type) == QUAL_UNION_TYPE)
4966 && ! CONSTRUCTOR_ELTS (exp))
4967 /* If the constructor is empty, clear the union. */
4969 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
4970 cleared = 1;
4973 /* If we are building a static constructor into a register,
4974 set the initial value as zero so we can fold the value into
4975 a constant. But if more than one register is involved,
4976 this probably loses. */
4977 else if (REG_P (target) && TREE_STATIC (exp)
4978 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
4980 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
4981 cleared = 1;
4984 /* If the constructor has fewer fields than the structure or
4985 if we are initializing the structure to mostly zeros, clear
4986 the whole structure first. Don't do this if TARGET is a
4987 register whose mode size isn't equal to SIZE since
4988 clear_storage can't handle this case. */
4989 else if (size > 0
4990 && (((int)VEC_length (constructor_elt, CONSTRUCTOR_ELTS (exp))
4991 != fields_length (type))
4992 || mostly_zeros_p (exp))
4993 && (!REG_P (target)
4994 || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
4995 == size)))
4997 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
4998 cleared = 1;
5001 if (! cleared)
5002 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
5004 /* Store each element of the constructor into the
5005 corresponding field of TARGET. */
5006 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
5008 enum machine_mode mode;
5009 HOST_WIDE_INT bitsize;
5010 HOST_WIDE_INT bitpos = 0;
5011 tree offset;
5012 rtx to_rtx = target;
5014 /* Just ignore missing fields. We cleared the whole
5015 structure, above, if any fields are missing. */
5016 if (field == 0)
5017 continue;
5019 if (cleared && initializer_zerop (value))
5020 continue;
5022 if (host_integerp (DECL_SIZE (field), 1))
5023 bitsize = tree_low_cst (DECL_SIZE (field), 1);
5024 else
5025 bitsize = -1;
5027 mode = DECL_MODE (field);
5028 if (DECL_BIT_FIELD (field))
5029 mode = VOIDmode;
5031 offset = DECL_FIELD_OFFSET (field);
5032 if (host_integerp (offset, 0)
5033 && host_integerp (bit_position (field), 0))
5035 bitpos = int_bit_position (field);
5036 offset = 0;
5038 else
5039 bitpos = tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 0);
5041 if (offset)
5043 rtx offset_rtx;
5045 offset
5046 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
5047 make_tree (TREE_TYPE (exp),
5048 target));
5050 offset_rtx = expand_normal (offset);
5051 gcc_assert (MEM_P (to_rtx));
5053 #ifdef POINTERS_EXTEND_UNSIGNED
5054 if (GET_MODE (offset_rtx) != Pmode)
5055 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
5056 #else
5057 if (GET_MODE (offset_rtx) != ptr_mode)
5058 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
5059 #endif
5061 to_rtx = offset_address (to_rtx, offset_rtx,
5062 highest_pow2_factor (offset));
5065 #ifdef WORD_REGISTER_OPERATIONS
5066 /* If this initializes a field that is smaller than a
5067 word, at the start of a word, try to widen it to a full
5068 word. This special case allows us to output C++ member
5069 function initializations in a form that the optimizers
5070 can understand. */
5071 if (REG_P (target)
5072 && bitsize < BITS_PER_WORD
5073 && bitpos % BITS_PER_WORD == 0
5074 && GET_MODE_CLASS (mode) == MODE_INT
5075 && TREE_CODE (value) == INTEGER_CST
5076 && exp_size >= 0
5077 && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
5079 tree type = TREE_TYPE (value);
5081 if (TYPE_PRECISION (type) < BITS_PER_WORD)
5083 type = lang_hooks.types.type_for_size
5084 (BITS_PER_WORD, TYPE_UNSIGNED (type));
5085 value = fold_convert (type, value);
5088 if (BYTES_BIG_ENDIAN)
5089 value
5090 = fold_build2 (LSHIFT_EXPR, type, value,
5091 build_int_cst (type,
5092 BITS_PER_WORD - bitsize));
5093 bitsize = BITS_PER_WORD;
5094 mode = word_mode;
5096 #endif
5098 if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
5099 && DECL_NONADDRESSABLE_P (field))
5101 to_rtx = copy_rtx (to_rtx);
5102 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
5105 store_constructor_field (to_rtx, bitsize, bitpos, mode,
5106 value, type, cleared,
5107 get_alias_set (TREE_TYPE (field)));
5109 break;
5111 case ARRAY_TYPE:
5113 tree value, index;
5114 unsigned HOST_WIDE_INT i;
5115 int need_to_clear;
5116 tree domain;
5117 tree elttype = TREE_TYPE (type);
5118 int const_bounds_p;
5119 HOST_WIDE_INT minelt = 0;
5120 HOST_WIDE_INT maxelt = 0;
5122 domain = TYPE_DOMAIN (type);
5123 const_bounds_p = (TYPE_MIN_VALUE (domain)
5124 && TYPE_MAX_VALUE (domain)
5125 && host_integerp (TYPE_MIN_VALUE (domain), 0)
5126 && host_integerp (TYPE_MAX_VALUE (domain), 0));
5128 /* If we have constant bounds for the range of the type, get them. */
5129 if (const_bounds_p)
5131 minelt = tree_low_cst (TYPE_MIN_VALUE (domain), 0);
5132 maxelt = tree_low_cst (TYPE_MAX_VALUE (domain), 0);
5135 /* If the constructor has fewer elements than the array, clear
5136 the whole array first. Similarly if this is static
5137 constructor of a non-BLKmode object. */
5138 if (cleared)
5139 need_to_clear = 0;
5140 else if (REG_P (target) && TREE_STATIC (exp))
5141 need_to_clear = 1;
5142 else
5144 unsigned HOST_WIDE_INT idx;
5145 tree index, value;
5146 HOST_WIDE_INT count = 0, zero_count = 0;
5147 need_to_clear = ! const_bounds_p;
5149 /* This loop is a more accurate version of the loop in
5150 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5151 is also needed to check for missing elements. */
5152 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
5154 HOST_WIDE_INT this_node_count;
5156 if (need_to_clear)
5157 break;
5159 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5161 tree lo_index = TREE_OPERAND (index, 0);
5162 tree hi_index = TREE_OPERAND (index, 1);
5164 if (! host_integerp (lo_index, 1)
5165 || ! host_integerp (hi_index, 1))
5167 need_to_clear = 1;
5168 break;
5171 this_node_count = (tree_low_cst (hi_index, 1)
5172 - tree_low_cst (lo_index, 1) + 1);
5174 else
5175 this_node_count = 1;
5177 count += this_node_count;
5178 if (mostly_zeros_p (value))
5179 zero_count += this_node_count;
5182 /* Clear the entire array first if there are any missing
5183 elements, or if the incidence of zero elements is >=
5184 75%. */
5185 if (! need_to_clear
5186 && (count < maxelt - minelt + 1
5187 || 4 * zero_count >= 3 * count))
5188 need_to_clear = 1;
5191 if (need_to_clear && size > 0)
5193 if (REG_P (target))
5194 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5195 else
5196 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5197 cleared = 1;
5200 if (!cleared && REG_P (target))
5201 /* Inform later passes that the old value is dead. */
5202 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
5204 /* Store each element of the constructor into the
5205 corresponding element of TARGET, determined by counting the
5206 elements. */
5207 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
5209 enum machine_mode mode;
5210 HOST_WIDE_INT bitsize;
5211 HOST_WIDE_INT bitpos;
5212 int unsignedp;
5213 rtx xtarget = target;
5215 if (cleared && initializer_zerop (value))
5216 continue;
5218 unsignedp = TYPE_UNSIGNED (elttype);
5219 mode = TYPE_MODE (elttype);
5220 if (mode == BLKmode)
5221 bitsize = (host_integerp (TYPE_SIZE (elttype), 1)
5222 ? tree_low_cst (TYPE_SIZE (elttype), 1)
5223 : -1);
5224 else
5225 bitsize = GET_MODE_BITSIZE (mode);
5227 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5229 tree lo_index = TREE_OPERAND (index, 0);
5230 tree hi_index = TREE_OPERAND (index, 1);
5231 rtx index_r, pos_rtx;
5232 HOST_WIDE_INT lo, hi, count;
5233 tree position;
5235 /* If the range is constant and "small", unroll the loop. */
5236 if (const_bounds_p
5237 && host_integerp (lo_index, 0)
5238 && host_integerp (hi_index, 0)
5239 && (lo = tree_low_cst (lo_index, 0),
5240 hi = tree_low_cst (hi_index, 0),
5241 count = hi - lo + 1,
5242 (!MEM_P (target)
5243 || count <= 2
5244 || (host_integerp (TYPE_SIZE (elttype), 1)
5245 && (tree_low_cst (TYPE_SIZE (elttype), 1) * count
5246 <= 40 * 8)))))
5248 lo -= minelt; hi -= minelt;
5249 for (; lo <= hi; lo++)
5251 bitpos = lo * tree_low_cst (TYPE_SIZE (elttype), 0);
5253 if (MEM_P (target)
5254 && !MEM_KEEP_ALIAS_SET_P (target)
5255 && TREE_CODE (type) == ARRAY_TYPE
5256 && TYPE_NONALIASED_COMPONENT (type))
5258 target = copy_rtx (target);
5259 MEM_KEEP_ALIAS_SET_P (target) = 1;
5262 store_constructor_field
5263 (target, bitsize, bitpos, mode, value, type, cleared,
5264 get_alias_set (elttype));
5267 else
5269 rtx loop_start = gen_label_rtx ();
5270 rtx loop_end = gen_label_rtx ();
5271 tree exit_cond;
5273 expand_normal (hi_index);
5274 unsignedp = TYPE_UNSIGNED (domain);
5276 index = build_decl (VAR_DECL, NULL_TREE, domain);
5278 index_r
5279 = gen_reg_rtx (promote_mode (domain, DECL_MODE (index),
5280 &unsignedp, 0));
5281 SET_DECL_RTL (index, index_r);
5282 store_expr (lo_index, index_r, 0);
5284 /* Build the head of the loop. */
5285 do_pending_stack_adjust ();
5286 emit_label (loop_start);
5288 /* Assign value to element index. */
5289 position =
5290 fold_convert (ssizetype,
5291 fold_build2 (MINUS_EXPR,
5292 TREE_TYPE (index),
5293 index,
5294 TYPE_MIN_VALUE (domain)));
5296 position =
5297 size_binop (MULT_EXPR, position,
5298 fold_convert (ssizetype,
5299 TYPE_SIZE_UNIT (elttype)));
5301 pos_rtx = expand_normal (position);
5302 xtarget = offset_address (target, pos_rtx,
5303 highest_pow2_factor (position));
5304 xtarget = adjust_address (xtarget, mode, 0);
5305 if (TREE_CODE (value) == CONSTRUCTOR)
5306 store_constructor (value, xtarget, cleared,
5307 bitsize / BITS_PER_UNIT);
5308 else
5309 store_expr (value, xtarget, 0);
5311 /* Generate a conditional jump to exit the loop. */
5312 exit_cond = build2 (LT_EXPR, integer_type_node,
5313 index, hi_index);
5314 jumpif (exit_cond, loop_end);
5316 /* Update the loop counter, and jump to the head of
5317 the loop. */
5318 expand_assignment (index,
5319 build2 (PLUS_EXPR, TREE_TYPE (index),
5320 index, integer_one_node));
5322 emit_jump (loop_start);
5324 /* Build the end of the loop. */
5325 emit_label (loop_end);
5328 else if ((index != 0 && ! host_integerp (index, 0))
5329 || ! host_integerp (TYPE_SIZE (elttype), 1))
5331 tree position;
5333 if (index == 0)
5334 index = ssize_int (1);
5336 if (minelt)
5337 index = fold_convert (ssizetype,
5338 fold_build2 (MINUS_EXPR,
5339 TREE_TYPE (index),
5340 index,
5341 TYPE_MIN_VALUE (domain)));
5343 position =
5344 size_binop (MULT_EXPR, index,
5345 fold_convert (ssizetype,
5346 TYPE_SIZE_UNIT (elttype)));
5347 xtarget = offset_address (target,
5348 expand_normal (position),
5349 highest_pow2_factor (position));
5350 xtarget = adjust_address (xtarget, mode, 0);
5351 store_expr (value, xtarget, 0);
5353 else
5355 if (index != 0)
5356 bitpos = ((tree_low_cst (index, 0) - minelt)
5357 * tree_low_cst (TYPE_SIZE (elttype), 1));
5358 else
5359 bitpos = (i * tree_low_cst (TYPE_SIZE (elttype), 1));
5361 if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
5362 && TREE_CODE (type) == ARRAY_TYPE
5363 && TYPE_NONALIASED_COMPONENT (type))
5365 target = copy_rtx (target);
5366 MEM_KEEP_ALIAS_SET_P (target) = 1;
5368 store_constructor_field (target, bitsize, bitpos, mode, value,
5369 type, cleared, get_alias_set (elttype));
5372 break;
5375 case VECTOR_TYPE:
5377 unsigned HOST_WIDE_INT idx;
5378 constructor_elt *ce;
5379 int i;
5380 int need_to_clear;
5381 int icode = 0;
5382 tree elttype = TREE_TYPE (type);
5383 int elt_size = tree_low_cst (TYPE_SIZE (elttype), 1);
5384 enum machine_mode eltmode = TYPE_MODE (elttype);
5385 HOST_WIDE_INT bitsize;
5386 HOST_WIDE_INT bitpos;
5387 rtvec vector = NULL;
5388 unsigned n_elts;
5390 gcc_assert (eltmode != BLKmode);
5392 n_elts = TYPE_VECTOR_SUBPARTS (type);
5393 if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
5395 enum machine_mode mode = GET_MODE (target);
5397 icode = (int) vec_init_optab->handlers[mode].insn_code;
5398 if (icode != CODE_FOR_nothing)
5400 unsigned int i;
5402 vector = rtvec_alloc (n_elts);
5403 for (i = 0; i < n_elts; i++)
5404 RTVEC_ELT (vector, i) = CONST0_RTX (GET_MODE_INNER (mode));
5408 /* If the constructor has fewer elements than the vector,
5409 clear the whole array first. Similarly if this is static
5410 constructor of a non-BLKmode object. */
5411 if (cleared)
5412 need_to_clear = 0;
5413 else if (REG_P (target) && TREE_STATIC (exp))
5414 need_to_clear = 1;
5415 else
5417 unsigned HOST_WIDE_INT count = 0, zero_count = 0;
5418 tree value;
5420 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
5422 int n_elts_here = tree_low_cst
5423 (int_const_binop (TRUNC_DIV_EXPR,
5424 TYPE_SIZE (TREE_TYPE (value)),
5425 TYPE_SIZE (elttype), 0), 1);
5427 count += n_elts_here;
5428 if (mostly_zeros_p (value))
5429 zero_count += n_elts_here;
5432 /* Clear the entire vector first if there are any missing elements,
5433 or if the incidence of zero elements is >= 75%. */
5434 need_to_clear = (count < n_elts || 4 * zero_count >= 3 * count);
5437 if (need_to_clear && size > 0 && !vector)
5439 if (REG_P (target))
5440 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5441 else
5442 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5443 cleared = 1;
5446 /* Inform later passes that the old value is dead. */
5447 if (!cleared && !vector && REG_P (target))
5448 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5450 /* Store each element of the constructor into the corresponding
5451 element of TARGET, determined by counting the elements. */
5452 for (idx = 0, i = 0;
5453 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), idx, ce);
5454 idx++, i += bitsize / elt_size)
5456 HOST_WIDE_INT eltpos;
5457 tree value = ce->value;
5459 bitsize = tree_low_cst (TYPE_SIZE (TREE_TYPE (value)), 1);
5460 if (cleared && initializer_zerop (value))
5461 continue;
5463 if (ce->index)
5464 eltpos = tree_low_cst (ce->index, 1);
5465 else
5466 eltpos = i;
5468 if (vector)
5470 /* Vector CONSTRUCTORs should only be built from smaller
5471 vectors in the case of BLKmode vectors. */
5472 gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
5473 RTVEC_ELT (vector, eltpos)
5474 = expand_normal (value);
5476 else
5478 enum machine_mode value_mode =
5479 TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
5480 ? TYPE_MODE (TREE_TYPE (value))
5481 : eltmode;
5482 bitpos = eltpos * elt_size;
5483 store_constructor_field (target, bitsize, bitpos,
5484 value_mode, value, type,
5485 cleared, get_alias_set (elttype));
5489 if (vector)
5490 emit_insn (GEN_FCN (icode)
5491 (target,
5492 gen_rtx_PARALLEL (GET_MODE (target), vector)));
5493 break;
5496 default:
5497 gcc_unreachable ();
5501 /* Store the value of EXP (an expression tree)
5502 into a subfield of TARGET which has mode MODE and occupies
5503 BITSIZE bits, starting BITPOS bits from the start of TARGET.
5504 If MODE is VOIDmode, it means that we are storing into a bit-field.
5506 Always return const0_rtx unless we have something particular to
5507 return.
5509 TYPE is the type of the underlying object,
5511 ALIAS_SET is the alias set for the destination. This value will
5512 (in general) be different from that for TARGET, since TARGET is a
5513 reference to the containing structure. */
5515 static rtx
5516 store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
5517 enum machine_mode mode, tree exp, tree type, int alias_set)
5519 HOST_WIDE_INT width_mask = 0;
5521 if (TREE_CODE (exp) == ERROR_MARK)
5522 return const0_rtx;
5524 /* If we have nothing to store, do nothing unless the expression has
5525 side-effects. */
5526 if (bitsize == 0)
5527 return expand_expr (exp, const0_rtx, VOIDmode, 0);
5528 else if (bitsize >= 0 && bitsize < HOST_BITS_PER_WIDE_INT)
5529 width_mask = ((HOST_WIDE_INT) 1 << bitsize) - 1;
5531 /* If we are storing into an unaligned field of an aligned union that is
5532 in a register, we may have the mode of TARGET being an integer mode but
5533 MODE == BLKmode. In that case, get an aligned object whose size and
5534 alignment are the same as TARGET and store TARGET into it (we can avoid
5535 the store if the field being stored is the entire width of TARGET). Then
5536 call ourselves recursively to store the field into a BLKmode version of
5537 that object. Finally, load from the object into TARGET. This is not
5538 very efficient in general, but should only be slightly more expensive
5539 than the otherwise-required unaligned accesses. Perhaps this can be
5540 cleaned up later. It's tempting to make OBJECT readonly, but it's set
5541 twice, once with emit_move_insn and once via store_field. */
5543 if (mode == BLKmode
5544 && (REG_P (target) || GET_CODE (target) == SUBREG))
5546 rtx object = assign_temp (type, 0, 1, 1);
5547 rtx blk_object = adjust_address (object, BLKmode, 0);
5549 if (bitsize != (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (target)))
5550 emit_move_insn (object, target);
5552 store_field (blk_object, bitsize, bitpos, mode, exp, type, alias_set);
5554 emit_move_insn (target, object);
5556 /* We want to return the BLKmode version of the data. */
5557 return blk_object;
5560 if (GET_CODE (target) == CONCAT)
5562 /* We're storing into a struct containing a single __complex. */
5564 gcc_assert (!bitpos);
5565 return store_expr (exp, target, 0);
5568 /* If the structure is in a register or if the component
5569 is a bit field, we cannot use addressing to access it.
5570 Use bit-field techniques or SUBREG to store in it. */
5572 if (mode == VOIDmode
5573 || (mode != BLKmode && ! direct_store[(int) mode]
5574 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
5575 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
5576 || REG_P (target)
5577 || GET_CODE (target) == SUBREG
5578 /* If the field isn't aligned enough to store as an ordinary memref,
5579 store it as a bit field. */
5580 || (mode != BLKmode
5581 && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
5582 || bitpos % GET_MODE_ALIGNMENT (mode))
5583 && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
5584 || (bitpos % BITS_PER_UNIT != 0)))
5585 /* If the RHS and field are a constant size and the size of the
5586 RHS isn't the same size as the bitfield, we must use bitfield
5587 operations. */
5588 || (bitsize >= 0
5589 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
5590 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0))
5592 rtx temp;
5594 /* If EXP is a NOP_EXPR of precision less than its mode, then that
5595 implies a mask operation. If the precision is the same size as
5596 the field we're storing into, that mask is redundant. This is
5597 particularly common with bit field assignments generated by the
5598 C front end. */
5599 if (TREE_CODE (exp) == NOP_EXPR)
5601 tree type = TREE_TYPE (exp);
5602 if (INTEGRAL_TYPE_P (type)
5603 && TYPE_PRECISION (type) < GET_MODE_BITSIZE (TYPE_MODE (type))
5604 && bitsize == TYPE_PRECISION (type))
5606 type = TREE_TYPE (TREE_OPERAND (exp, 0));
5607 if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) >= bitsize)
5608 exp = TREE_OPERAND (exp, 0);
5612 temp = expand_normal (exp);
5614 /* If BITSIZE is narrower than the size of the type of EXP
5615 we will be narrowing TEMP. Normally, what's wanted are the
5616 low-order bits. However, if EXP's type is a record and this is
5617 big-endian machine, we want the upper BITSIZE bits. */
5618 if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
5619 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
5620 && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
5621 temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
5622 size_int (GET_MODE_BITSIZE (GET_MODE (temp))
5623 - bitsize),
5624 NULL_RTX, 1);
5626 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to
5627 MODE. */
5628 if (mode != VOIDmode && mode != BLKmode
5629 && mode != TYPE_MODE (TREE_TYPE (exp)))
5630 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
5632 /* If the modes of TARGET and TEMP are both BLKmode, both
5633 must be in memory and BITPOS must be aligned on a byte
5634 boundary. If so, we simply do a block copy. */
5635 if (GET_MODE (target) == BLKmode && GET_MODE (temp) == BLKmode)
5637 gcc_assert (MEM_P (target) && MEM_P (temp)
5638 && !(bitpos % BITS_PER_UNIT));
5640 target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
5641 emit_block_move (target, temp,
5642 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
5643 / BITS_PER_UNIT),
5644 BLOCK_OP_NORMAL);
5646 return const0_rtx;
5649 /* Store the value in the bitfield. */
5650 store_bit_field (target, bitsize, bitpos, mode, temp);
5652 return const0_rtx;
5654 else
5656 /* Now build a reference to just the desired component. */
5657 rtx to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
5659 if (to_rtx == target)
5660 to_rtx = copy_rtx (to_rtx);
5662 MEM_SET_IN_STRUCT_P (to_rtx, 1);
5663 if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
5664 set_mem_alias_set (to_rtx, alias_set);
5666 return store_expr (exp, to_rtx, 0);
5670 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
5671 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
5672 codes and find the ultimate containing object, which we return.
5674 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
5675 bit position, and *PUNSIGNEDP to the signedness of the field.
5676 If the position of the field is variable, we store a tree
5677 giving the variable offset (in units) in *POFFSET.
5678 This offset is in addition to the bit position.
5679 If the position is not variable, we store 0 in *POFFSET.
5681 If any of the extraction expressions is volatile,
5682 we store 1 in *PVOLATILEP. Otherwise we don't change that.
5684 If the field is a bit-field, *PMODE is set to VOIDmode. Otherwise, it
5685 is a mode that can be used to access the field. In that case, *PBITSIZE
5686 is redundant.
5688 If the field describes a variable-sized object, *PMODE is set to
5689 VOIDmode and *PBITSIZE is set to -1. An access cannot be made in
5690 this case, but the address of the object can be found.
5692 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
5693 look through nodes that serve as markers of a greater alignment than
5694 the one that can be deduced from the expression. These nodes make it
5695 possible for front-ends to prevent temporaries from being created by
5696 the middle-end on alignment considerations. For that purpose, the
5697 normal operating mode at high-level is to always pass FALSE so that
5698 the ultimate containing object is really returned; moreover, the
5699 associated predicate handled_component_p will always return TRUE
5700 on these nodes, thus indicating that they are essentially handled
5701 by get_inner_reference. TRUE should only be passed when the caller
5702 is scanning the expression in order to build another representation
5703 and specifically knows how to handle these nodes; as such, this is
5704 the normal operating mode in the RTL expanders. */
5706 tree
5707 get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
5708 HOST_WIDE_INT *pbitpos, tree *poffset,
5709 enum machine_mode *pmode, int *punsignedp,
5710 int *pvolatilep, bool keep_aligning)
5712 tree size_tree = 0;
5713 enum machine_mode mode = VOIDmode;
5714 tree offset = size_zero_node;
5715 tree bit_offset = bitsize_zero_node;
5716 tree tem;
5718 /* First get the mode, signedness, and size. We do this from just the
5719 outermost expression. */
5720 if (TREE_CODE (exp) == COMPONENT_REF)
5722 size_tree = DECL_SIZE (TREE_OPERAND (exp, 1));
5723 if (! DECL_BIT_FIELD (TREE_OPERAND (exp, 1)))
5724 mode = DECL_MODE (TREE_OPERAND (exp, 1));
5726 *punsignedp = DECL_UNSIGNED (TREE_OPERAND (exp, 1));
5728 else if (TREE_CODE (exp) == BIT_FIELD_REF)
5730 size_tree = TREE_OPERAND (exp, 1);
5731 *punsignedp = BIT_FIELD_REF_UNSIGNED (exp);
5733 /* For vector types, with the correct size of access, use the mode of
5734 inner type. */
5735 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
5736 && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
5737 && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
5738 mode = TYPE_MODE (TREE_TYPE (exp));
5740 else
5742 mode = TYPE_MODE (TREE_TYPE (exp));
5743 *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
5745 if (mode == BLKmode)
5746 size_tree = TYPE_SIZE (TREE_TYPE (exp));
5747 else
5748 *pbitsize = GET_MODE_BITSIZE (mode);
5751 if (size_tree != 0)
5753 if (! host_integerp (size_tree, 1))
5754 mode = BLKmode, *pbitsize = -1;
5755 else
5756 *pbitsize = tree_low_cst (size_tree, 1);
5759 /* Compute cumulative bit-offset for nested component-refs and array-refs,
5760 and find the ultimate containing object. */
5761 while (1)
5763 switch (TREE_CODE (exp))
5765 case BIT_FIELD_REF:
5766 bit_offset = size_binop (PLUS_EXPR, bit_offset,
5767 TREE_OPERAND (exp, 2));
5768 break;
5770 case COMPONENT_REF:
5772 tree field = TREE_OPERAND (exp, 1);
5773 tree this_offset = component_ref_field_offset (exp);
5775 /* If this field hasn't been filled in yet, don't go past it.
5776 This should only happen when folding expressions made during
5777 type construction. */
5778 if (this_offset == 0)
5779 break;
5781 offset = size_binop (PLUS_EXPR, offset, this_offset);
5782 bit_offset = size_binop (PLUS_EXPR, bit_offset,
5783 DECL_FIELD_BIT_OFFSET (field));
5785 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
5787 break;
5789 case ARRAY_REF:
5790 case ARRAY_RANGE_REF:
5792 tree index = TREE_OPERAND (exp, 1);
5793 tree low_bound = array_ref_low_bound (exp);
5794 tree unit_size = array_ref_element_size (exp);
5796 /* We assume all arrays have sizes that are a multiple of a byte.
5797 First subtract the lower bound, if any, in the type of the
5798 index, then convert to sizetype and multiply by the size of
5799 the array element. */
5800 if (! integer_zerop (low_bound))
5801 index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
5802 index, low_bound);
5804 offset = size_binop (PLUS_EXPR, offset,
5805 size_binop (MULT_EXPR,
5806 fold_convert (sizetype, index),
5807 unit_size));
5809 break;
5811 case REALPART_EXPR:
5812 break;
5814 case IMAGPART_EXPR:
5815 bit_offset = size_binop (PLUS_EXPR, bit_offset,
5816 bitsize_int (*pbitsize));
5817 break;
5819 case VIEW_CONVERT_EXPR:
5820 if (keep_aligning && STRICT_ALIGNMENT
5821 && (TYPE_ALIGN (TREE_TYPE (exp))
5822 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
5823 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
5824 < BIGGEST_ALIGNMENT)
5825 && (TYPE_ALIGN_OK (TREE_TYPE (exp))
5826 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp, 0)))))
5827 goto done;
5828 break;
5830 default:
5831 goto done;
5834 /* If any reference in the chain is volatile, the effect is volatile. */
5835 if (TREE_THIS_VOLATILE (exp))
5836 *pvolatilep = 1;
5838 exp = TREE_OPERAND (exp, 0);
5840 done:
5842 /* If OFFSET is constant, see if we can return the whole thing as a
5843 constant bit position. Otherwise, split it up. */
5844 if (host_integerp (offset, 0)
5845 && 0 != (tem = size_binop (MULT_EXPR,
5846 fold_convert (bitsizetype, offset),
5847 bitsize_unit_node))
5848 && 0 != (tem = size_binop (PLUS_EXPR, tem, bit_offset))
5849 && host_integerp (tem, 0))
5850 *pbitpos = tree_low_cst (tem, 0), *poffset = 0;
5851 else
5852 *pbitpos = tree_low_cst (bit_offset, 0), *poffset = offset;
5854 *pmode = mode;
5855 return exp;
5858 /* Return a tree of sizetype representing the size, in bytes, of the element
5859 of EXP, an ARRAY_REF. */
5861 tree
5862 array_ref_element_size (tree exp)
5864 tree aligned_size = TREE_OPERAND (exp, 3);
5865 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
5867 /* If a size was specified in the ARRAY_REF, it's the size measured
5868 in alignment units of the element type. So multiply by that value. */
5869 if (aligned_size)
5871 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
5872 sizetype from another type of the same width and signedness. */
5873 if (TREE_TYPE (aligned_size) != sizetype)
5874 aligned_size = fold_convert (sizetype, aligned_size);
5875 return size_binop (MULT_EXPR, aligned_size,
5876 size_int (TYPE_ALIGN_UNIT (elmt_type)));
5879 /* Otherwise, take the size from that of the element type. Substitute
5880 any PLACEHOLDER_EXPR that we have. */
5881 else
5882 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
5885 /* Return a tree representing the lower bound of the array mentioned in
5886 EXP, an ARRAY_REF. */
5888 tree
5889 array_ref_low_bound (tree exp)
5891 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
5893 /* If a lower bound is specified in EXP, use it. */
5894 if (TREE_OPERAND (exp, 2))
5895 return TREE_OPERAND (exp, 2);
5897 /* Otherwise, if there is a domain type and it has a lower bound, use it,
5898 substituting for a PLACEHOLDER_EXPR as needed. */
5899 if (domain_type && TYPE_MIN_VALUE (domain_type))
5900 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
5902 /* Otherwise, return a zero of the appropriate type. */
5903 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp, 1)), 0);
5906 /* Return a tree representing the upper bound of the array mentioned in
5907 EXP, an ARRAY_REF. */
5909 tree
5910 array_ref_up_bound (tree exp)
5912 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
5914 /* If there is a domain type and it has an upper bound, use it, substituting
5915 for a PLACEHOLDER_EXPR as needed. */
5916 if (domain_type && TYPE_MAX_VALUE (domain_type))
5917 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
5919 /* Otherwise fail. */
5920 return NULL_TREE;
5923 /* Return a tree representing the offset, in bytes, of the field referenced
5924 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
5926 tree
5927 component_ref_field_offset (tree exp)
5929 tree aligned_offset = TREE_OPERAND (exp, 2);
5930 tree field = TREE_OPERAND (exp, 1);
5932 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
5933 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
5934 value. */
5935 if (aligned_offset)
5937 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
5938 sizetype from another type of the same width and signedness. */
5939 if (TREE_TYPE (aligned_offset) != sizetype)
5940 aligned_offset = fold_convert (sizetype, aligned_offset);
5941 return size_binop (MULT_EXPR, aligned_offset,
5942 size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT));
5945 /* Otherwise, take the offset from that of the field. Substitute
5946 any PLACEHOLDER_EXPR that we have. */
5947 else
5948 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
5951 /* Return 1 if T is an expression that get_inner_reference handles. */
5954 handled_component_p (tree t)
5956 switch (TREE_CODE (t))
5958 case BIT_FIELD_REF:
5959 case COMPONENT_REF:
5960 case ARRAY_REF:
5961 case ARRAY_RANGE_REF:
5962 case VIEW_CONVERT_EXPR:
5963 case REALPART_EXPR:
5964 case IMAGPART_EXPR:
5965 return 1;
5967 default:
5968 return 0;
5972 /* Given an rtx VALUE that may contain additions and multiplications, return
5973 an equivalent value that just refers to a register, memory, or constant.
5974 This is done by generating instructions to perform the arithmetic and
5975 returning a pseudo-register containing the value.
5977 The returned value may be a REG, SUBREG, MEM or constant. */
5980 force_operand (rtx value, rtx target)
5982 rtx op1, op2;
5983 /* Use subtarget as the target for operand 0 of a binary operation. */
5984 rtx subtarget = get_subtarget (target);
5985 enum rtx_code code = GET_CODE (value);
5987 /* Check for subreg applied to an expression produced by loop optimizer. */
5988 if (code == SUBREG
5989 && !REG_P (SUBREG_REG (value))
5990 && !MEM_P (SUBREG_REG (value)))
5992 value = simplify_gen_subreg (GET_MODE (value),
5993 force_reg (GET_MODE (SUBREG_REG (value)),
5994 force_operand (SUBREG_REG (value),
5995 NULL_RTX)),
5996 GET_MODE (SUBREG_REG (value)),
5997 SUBREG_BYTE (value));
5998 code = GET_CODE (value);
6001 /* Check for a PIC address load. */
6002 if ((code == PLUS || code == MINUS)
6003 && XEXP (value, 0) == pic_offset_table_rtx
6004 && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
6005 || GET_CODE (XEXP (value, 1)) == LABEL_REF
6006 || GET_CODE (XEXP (value, 1)) == CONST))
6008 if (!subtarget)
6009 subtarget = gen_reg_rtx (GET_MODE (value));
6010 emit_move_insn (subtarget, value);
6011 return subtarget;
6014 if (ARITHMETIC_P (value))
6016 op2 = XEXP (value, 1);
6017 if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
6018 subtarget = 0;
6019 if (code == MINUS && GET_CODE (op2) == CONST_INT)
6021 code = PLUS;
6022 op2 = negate_rtx (GET_MODE (value), op2);
6025 /* Check for an addition with OP2 a constant integer and our first
6026 operand a PLUS of a virtual register and something else. In that
6027 case, we want to emit the sum of the virtual register and the
6028 constant first and then add the other value. This allows virtual
6029 register instantiation to simply modify the constant rather than
6030 creating another one around this addition. */
6031 if (code == PLUS && GET_CODE (op2) == CONST_INT
6032 && GET_CODE (XEXP (value, 0)) == PLUS
6033 && REG_P (XEXP (XEXP (value, 0), 0))
6034 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
6035 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
6037 rtx temp = expand_simple_binop (GET_MODE (value), code,
6038 XEXP (XEXP (value, 0), 0), op2,
6039 subtarget, 0, OPTAB_LIB_WIDEN);
6040 return expand_simple_binop (GET_MODE (value), code, temp,
6041 force_operand (XEXP (XEXP (value,
6042 0), 1), 0),
6043 target, 0, OPTAB_LIB_WIDEN);
6046 op1 = force_operand (XEXP (value, 0), subtarget);
6047 op2 = force_operand (op2, NULL_RTX);
6048 switch (code)
6050 case MULT:
6051 return expand_mult (GET_MODE (value), op1, op2, target, 1);
6052 case DIV:
6053 if (!INTEGRAL_MODE_P (GET_MODE (value)))
6054 return expand_simple_binop (GET_MODE (value), code, op1, op2,
6055 target, 1, OPTAB_LIB_WIDEN);
6056 else
6057 return expand_divmod (0,
6058 FLOAT_MODE_P (GET_MODE (value))
6059 ? RDIV_EXPR : TRUNC_DIV_EXPR,
6060 GET_MODE (value), op1, op2, target, 0);
6061 break;
6062 case MOD:
6063 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
6064 target, 0);
6065 break;
6066 case UDIV:
6067 return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
6068 target, 1);
6069 break;
6070 case UMOD:
6071 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
6072 target, 1);
6073 break;
6074 case ASHIFTRT:
6075 return expand_simple_binop (GET_MODE (value), code, op1, op2,
6076 target, 0, OPTAB_LIB_WIDEN);
6077 break;
6078 default:
6079 return expand_simple_binop (GET_MODE (value), code, op1, op2,
6080 target, 1, OPTAB_LIB_WIDEN);
6083 if (UNARY_P (value))
6085 if (!target)
6086 target = gen_reg_rtx (GET_MODE (value));
6087 op1 = force_operand (XEXP (value, 0), NULL_RTX);
6088 switch (code)
6090 case ZERO_EXTEND:
6091 case SIGN_EXTEND:
6092 case TRUNCATE:
6093 case FLOAT_EXTEND:
6094 case FLOAT_TRUNCATE:
6095 convert_move (target, op1, code == ZERO_EXTEND);
6096 return target;
6098 case FIX:
6099 case UNSIGNED_FIX:
6100 expand_fix (target, op1, code == UNSIGNED_FIX);
6101 return target;
6103 case FLOAT:
6104 case UNSIGNED_FLOAT:
6105 expand_float (target, op1, code == UNSIGNED_FLOAT);
6106 return target;
6108 default:
6109 return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
6113 #ifdef INSN_SCHEDULING
6114 /* On machines that have insn scheduling, we want all memory reference to be
6115 explicit, so we need to deal with such paradoxical SUBREGs. */
6116 if (GET_CODE (value) == SUBREG && MEM_P (SUBREG_REG (value))
6117 && (GET_MODE_SIZE (GET_MODE (value))
6118 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (value)))))
6119 value
6120 = simplify_gen_subreg (GET_MODE (value),
6121 force_reg (GET_MODE (SUBREG_REG (value)),
6122 force_operand (SUBREG_REG (value),
6123 NULL_RTX)),
6124 GET_MODE (SUBREG_REG (value)),
6125 SUBREG_BYTE (value));
6126 #endif
6128 return value;
6131 /* Subroutine of expand_expr: return nonzero iff there is no way that
6132 EXP can reference X, which is being modified. TOP_P is nonzero if this
6133 call is going to be used to determine whether we need a temporary
6134 for EXP, as opposed to a recursive call to this function.
6136 It is always safe for this routine to return zero since it merely
6137 searches for optimization opportunities. */
6140 safe_from_p (rtx x, tree exp, int top_p)
6142 rtx exp_rtl = 0;
6143 int i, nops;
6145 if (x == 0
6146 /* If EXP has varying size, we MUST use a target since we currently
6147 have no way of allocating temporaries of variable size
6148 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
6149 So we assume here that something at a higher level has prevented a
6150 clash. This is somewhat bogus, but the best we can do. Only
6151 do this when X is BLKmode and when we are at the top level. */
6152 || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
6153 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
6154 && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
6155 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
6156 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
6157 != INTEGER_CST)
6158 && GET_MODE (x) == BLKmode)
6159 /* If X is in the outgoing argument area, it is always safe. */
6160 || (MEM_P (x)
6161 && (XEXP (x, 0) == virtual_outgoing_args_rtx
6162 || (GET_CODE (XEXP (x, 0)) == PLUS
6163 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
6164 return 1;
6166 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
6167 find the underlying pseudo. */
6168 if (GET_CODE (x) == SUBREG)
6170 x = SUBREG_REG (x);
6171 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
6172 return 0;
6175 /* Now look at our tree code and possibly recurse. */
6176 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
6178 case tcc_declaration:
6179 exp_rtl = DECL_RTL_IF_SET (exp);
6180 break;
6182 case tcc_constant:
6183 return 1;
6185 case tcc_exceptional:
6186 if (TREE_CODE (exp) == TREE_LIST)
6188 while (1)
6190 if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
6191 return 0;
6192 exp = TREE_CHAIN (exp);
6193 if (!exp)
6194 return 1;
6195 if (TREE_CODE (exp) != TREE_LIST)
6196 return safe_from_p (x, exp, 0);
6199 else if (TREE_CODE (exp) == CONSTRUCTOR)
6201 constructor_elt *ce;
6202 unsigned HOST_WIDE_INT idx;
6204 for (idx = 0;
6205 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), idx, ce);
6206 idx++)
6207 if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
6208 || !safe_from_p (x, ce->value, 0))
6209 return 0;
6210 return 1;
6212 else if (TREE_CODE (exp) == ERROR_MARK)
6213 return 1; /* An already-visited SAVE_EXPR? */
6214 else
6215 return 0;
6217 case tcc_statement:
6218 /* The only case we look at here is the DECL_INITIAL inside a
6219 DECL_EXPR. */
6220 return (TREE_CODE (exp) != DECL_EXPR
6221 || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
6222 || !DECL_INITIAL (DECL_EXPR_DECL (exp))
6223 || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
6225 case tcc_binary:
6226 case tcc_comparison:
6227 if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
6228 return 0;
6229 /* Fall through. */
6231 case tcc_unary:
6232 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
6234 case tcc_expression:
6235 case tcc_reference:
6236 case tcc_vl_exp:
6237 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
6238 the expression. If it is set, we conflict iff we are that rtx or
6239 both are in memory. Otherwise, we check all operands of the
6240 expression recursively. */
6242 switch (TREE_CODE (exp))
6244 case ADDR_EXPR:
6245 /* If the operand is static or we are static, we can't conflict.
6246 Likewise if we don't conflict with the operand at all. */
6247 if (staticp (TREE_OPERAND (exp, 0))
6248 || TREE_STATIC (exp)
6249 || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
6250 return 1;
6252 /* Otherwise, the only way this can conflict is if we are taking
6253 the address of a DECL a that address if part of X, which is
6254 very rare. */
6255 exp = TREE_OPERAND (exp, 0);
6256 if (DECL_P (exp))
6258 if (!DECL_RTL_SET_P (exp)
6259 || !MEM_P (DECL_RTL (exp)))
6260 return 0;
6261 else
6262 exp_rtl = XEXP (DECL_RTL (exp), 0);
6264 break;
6266 case MISALIGNED_INDIRECT_REF:
6267 case ALIGN_INDIRECT_REF:
6268 case INDIRECT_REF:
6269 if (MEM_P (x)
6270 && alias_sets_conflict_p (MEM_ALIAS_SET (x),
6271 get_alias_set (exp)))
6272 return 0;
6273 break;
6275 case CALL_EXPR:
6276 /* Assume that the call will clobber all hard registers and
6277 all of memory. */
6278 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
6279 || MEM_P (x))
6280 return 0;
6281 break;
6283 case WITH_CLEANUP_EXPR:
6284 case CLEANUP_POINT_EXPR:
6285 /* Lowered by gimplify.c. */
6286 gcc_unreachable ();
6288 case SAVE_EXPR:
6289 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
6291 default:
6292 break;
6295 /* If we have an rtx, we do not need to scan our operands. */
6296 if (exp_rtl)
6297 break;
6299 nops = TREE_OPERAND_LENGTH (exp);
6300 for (i = 0; i < nops; i++)
6301 if (TREE_OPERAND (exp, i) != 0
6302 && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
6303 return 0;
6305 break;
6307 case tcc_type:
6308 /* Should never get a type here. */
6309 gcc_unreachable ();
6311 case tcc_gimple_stmt:
6312 gcc_unreachable ();
6315 /* If we have an rtl, find any enclosed object. Then see if we conflict
6316 with it. */
6317 if (exp_rtl)
6319 if (GET_CODE (exp_rtl) == SUBREG)
6321 exp_rtl = SUBREG_REG (exp_rtl);
6322 if (REG_P (exp_rtl)
6323 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
6324 return 0;
6327 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
6328 are memory and they conflict. */
6329 return ! (rtx_equal_p (x, exp_rtl)
6330 || (MEM_P (x) && MEM_P (exp_rtl)
6331 && true_dependence (exp_rtl, VOIDmode, x,
6332 rtx_addr_varies_p)));
6335 /* If we reach here, it is safe. */
6336 return 1;
6340 /* Return the highest power of two that EXP is known to be a multiple of.
6341 This is used in updating alignment of MEMs in array references. */
6343 unsigned HOST_WIDE_INT
6344 highest_pow2_factor (tree exp)
6346 unsigned HOST_WIDE_INT c0, c1;
6348 switch (TREE_CODE (exp))
6350 case INTEGER_CST:
6351 /* We can find the lowest bit that's a one. If the low
6352 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
6353 We need to handle this case since we can find it in a COND_EXPR,
6354 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
6355 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
6356 later ICE. */
6357 if (TREE_OVERFLOW (exp))
6358 return BIGGEST_ALIGNMENT;
6359 else
6361 /* Note: tree_low_cst is intentionally not used here,
6362 we don't care about the upper bits. */
6363 c0 = TREE_INT_CST_LOW (exp);
6364 c0 &= -c0;
6365 return c0 ? c0 : BIGGEST_ALIGNMENT;
6367 break;
6369 case PLUS_EXPR: case MINUS_EXPR: case MIN_EXPR: case MAX_EXPR:
6370 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6371 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6372 return MIN (c0, c1);
6374 case MULT_EXPR:
6375 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6376 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6377 return c0 * c1;
6379 case ROUND_DIV_EXPR: case TRUNC_DIV_EXPR: case FLOOR_DIV_EXPR:
6380 case CEIL_DIV_EXPR:
6381 if (integer_pow2p (TREE_OPERAND (exp, 1))
6382 && host_integerp (TREE_OPERAND (exp, 1), 1))
6384 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6385 c1 = tree_low_cst (TREE_OPERAND (exp, 1), 1);
6386 return MAX (1, c0 / c1);
6388 break;
6390 case NON_LVALUE_EXPR: case NOP_EXPR: case CONVERT_EXPR:
6391 case SAVE_EXPR:
6392 return highest_pow2_factor (TREE_OPERAND (exp, 0));
6394 case COMPOUND_EXPR:
6395 return highest_pow2_factor (TREE_OPERAND (exp, 1));
6397 case COND_EXPR:
6398 c0 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6399 c1 = highest_pow2_factor (TREE_OPERAND (exp, 2));
6400 return MIN (c0, c1);
6402 default:
6403 break;
6406 return 1;
6409 /* Similar, except that the alignment requirements of TARGET are
6410 taken into account. Assume it is at least as aligned as its
6411 type, unless it is a COMPONENT_REF in which case the layout of
6412 the structure gives the alignment. */
6414 static unsigned HOST_WIDE_INT
6415 highest_pow2_factor_for_target (tree target, tree exp)
6417 unsigned HOST_WIDE_INT target_align, factor;
6419 factor = highest_pow2_factor (exp);
6420 if (TREE_CODE (target) == COMPONENT_REF)
6421 target_align = DECL_ALIGN_UNIT (TREE_OPERAND (target, 1));
6422 else
6423 target_align = TYPE_ALIGN_UNIT (TREE_TYPE (target));
6424 return MAX (factor, target_align);
6427 /* Return &VAR expression for emulated thread local VAR. */
6429 static tree
6430 emutls_var_address (tree var)
6432 tree emuvar = emutls_decl (var);
6433 tree fn = built_in_decls [BUILT_IN_EMUTLS_GET_ADDRESS];
6434 tree arg = build_fold_addr_expr_with_type (emuvar, ptr_type_node);
6435 tree arglist = build_tree_list (NULL_TREE, arg);
6436 tree call = build_function_call_expr (fn, arglist);
6437 return fold_convert (build_pointer_type (TREE_TYPE (var)), call);
6440 /* Expands variable VAR. */
6442 void
6443 expand_var (tree var)
6445 if (DECL_EXTERNAL (var))
6446 return;
6448 if (TREE_STATIC (var))
6449 /* If this is an inlined copy of a static local variable,
6450 look up the original decl. */
6451 var = DECL_ORIGIN (var);
6453 if (TREE_STATIC (var)
6454 ? !TREE_ASM_WRITTEN (var)
6455 : !DECL_RTL_SET_P (var))
6457 if (TREE_CODE (var) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (var))
6458 /* Should be ignored. */;
6459 else if (lang_hooks.expand_decl (var))
6460 /* OK. */;
6461 else if (TREE_CODE (var) == VAR_DECL && !TREE_STATIC (var))
6462 expand_decl (var);
6463 else if (TREE_CODE (var) == VAR_DECL && TREE_STATIC (var))
6464 rest_of_decl_compilation (var, 0, 0);
6465 else
6466 /* No expansion needed. */
6467 gcc_assert (TREE_CODE (var) == TYPE_DECL
6468 || TREE_CODE (var) == CONST_DECL
6469 || TREE_CODE (var) == FUNCTION_DECL
6470 || TREE_CODE (var) == LABEL_DECL);
6474 /* Subroutine of expand_expr. Expand the two operands of a binary
6475 expression EXP0 and EXP1 placing the results in OP0 and OP1.
6476 The value may be stored in TARGET if TARGET is nonzero. The
6477 MODIFIER argument is as documented by expand_expr. */
6479 static void
6480 expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
6481 enum expand_modifier modifier)
6483 if (! safe_from_p (target, exp1, 1))
6484 target = 0;
6485 if (operand_equal_p (exp0, exp1, 0))
6487 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
6488 *op1 = copy_rtx (*op0);
6490 else
6492 /* If we need to preserve evaluation order, copy exp0 into its own
6493 temporary variable so that it can't be clobbered by exp1. */
6494 if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
6495 exp0 = save_expr (exp0);
6496 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
6497 *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
6502 /* Return a MEM that contains constant EXP. DEFER is as for
6503 output_constant_def and MODIFIER is as for expand_expr. */
6505 static rtx
6506 expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
6508 rtx mem;
6510 mem = output_constant_def (exp, defer);
6511 if (modifier != EXPAND_INITIALIZER)
6512 mem = use_anchored_address (mem);
6513 return mem;
6516 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
6517 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
6519 static rtx
6520 expand_expr_addr_expr_1 (tree exp, rtx target, enum machine_mode tmode,
6521 enum expand_modifier modifier)
6523 rtx result, subtarget;
6524 tree inner, offset;
6525 HOST_WIDE_INT bitsize, bitpos;
6526 int volatilep, unsignedp;
6527 enum machine_mode mode1;
6529 /* If we are taking the address of a constant and are at the top level,
6530 we have to use output_constant_def since we can't call force_const_mem
6531 at top level. */
6532 /* ??? This should be considered a front-end bug. We should not be
6533 generating ADDR_EXPR of something that isn't an LVALUE. The only
6534 exception here is STRING_CST. */
6535 if (TREE_CODE (exp) == CONSTRUCTOR
6536 || CONSTANT_CLASS_P (exp))
6537 return XEXP (expand_expr_constant (exp, 0, modifier), 0);
6539 /* Everything must be something allowed by is_gimple_addressable. */
6540 switch (TREE_CODE (exp))
6542 case INDIRECT_REF:
6543 /* This case will happen via recursion for &a->b. */
6544 return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
6546 case CONST_DECL:
6547 /* Recurse and make the output_constant_def clause above handle this. */
6548 return expand_expr_addr_expr_1 (DECL_INITIAL (exp), target,
6549 tmode, modifier);
6551 case REALPART_EXPR:
6552 /* The real part of the complex number is always first, therefore
6553 the address is the same as the address of the parent object. */
6554 offset = 0;
6555 bitpos = 0;
6556 inner = TREE_OPERAND (exp, 0);
6557 break;
6559 case IMAGPART_EXPR:
6560 /* The imaginary part of the complex number is always second.
6561 The expression is therefore always offset by the size of the
6562 scalar type. */
6563 offset = 0;
6564 bitpos = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)));
6565 inner = TREE_OPERAND (exp, 0);
6566 break;
6568 case VAR_DECL:
6569 /* TLS emulation hook - replace __thread VAR's &VAR with
6570 __emutls_get_address (&_emutls.VAR). */
6571 if (! targetm.have_tls
6572 && TREE_CODE (exp) == VAR_DECL
6573 && DECL_THREAD_LOCAL_P (exp))
6575 exp = emutls_var_address (exp);
6576 return expand_expr (exp, target, tmode, modifier);
6578 /* Fall through. */
6580 default:
6581 /* If the object is a DECL, then expand it for its rtl. Don't bypass
6582 expand_expr, as that can have various side effects; LABEL_DECLs for
6583 example, may not have their DECL_RTL set yet. Assume language
6584 specific tree nodes can be expanded in some interesting way. */
6585 if (DECL_P (exp)
6586 || TREE_CODE (exp) >= LAST_AND_UNUSED_TREE_CODE)
6588 result = expand_expr (exp, target, tmode,
6589 modifier == EXPAND_INITIALIZER
6590 ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
6592 /* If the DECL isn't in memory, then the DECL wasn't properly
6593 marked TREE_ADDRESSABLE, which will be either a front-end
6594 or a tree optimizer bug. */
6595 gcc_assert (MEM_P (result));
6596 result = XEXP (result, 0);
6598 /* ??? Is this needed anymore? */
6599 if (DECL_P (exp) && !TREE_USED (exp) == 0)
6601 assemble_external (exp);
6602 TREE_USED (exp) = 1;
6605 if (modifier != EXPAND_INITIALIZER
6606 && modifier != EXPAND_CONST_ADDRESS)
6607 result = force_operand (result, target);
6608 return result;
6611 /* Pass FALSE as the last argument to get_inner_reference although
6612 we are expanding to RTL. The rationale is that we know how to
6613 handle "aligning nodes" here: we can just bypass them because
6614 they won't change the final object whose address will be returned
6615 (they actually exist only for that purpose). */
6616 inner = get_inner_reference (exp, &bitsize, &bitpos, &offset,
6617 &mode1, &unsignedp, &volatilep, false);
6618 break;
6621 /* We must have made progress. */
6622 gcc_assert (inner != exp);
6624 subtarget = offset || bitpos ? NULL_RTX : target;
6625 result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier);
6627 if (offset)
6629 rtx tmp;
6631 if (modifier != EXPAND_NORMAL)
6632 result = force_operand (result, NULL);
6633 tmp = expand_expr (offset, NULL, tmode, EXPAND_NORMAL);
6635 result = convert_memory_address (tmode, result);
6636 tmp = convert_memory_address (tmode, tmp);
6638 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
6639 result = gen_rtx_PLUS (tmode, result, tmp);
6640 else
6642 subtarget = bitpos ? NULL_RTX : target;
6643 result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
6644 1, OPTAB_LIB_WIDEN);
6648 if (bitpos)
6650 /* Someone beforehand should have rejected taking the address
6651 of such an object. */
6652 gcc_assert ((bitpos % BITS_PER_UNIT) == 0);
6654 result = plus_constant (result, bitpos / BITS_PER_UNIT);
6655 if (modifier < EXPAND_SUM)
6656 result = force_operand (result, target);
6659 return result;
6662 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
6663 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
6665 static rtx
6666 expand_expr_addr_expr (tree exp, rtx target, enum machine_mode tmode,
6667 enum expand_modifier modifier)
6669 enum machine_mode rmode;
6670 rtx result;
6672 /* Target mode of VOIDmode says "whatever's natural". */
6673 if (tmode == VOIDmode)
6674 tmode = TYPE_MODE (TREE_TYPE (exp));
6676 /* We can get called with some Weird Things if the user does silliness
6677 like "(short) &a". In that case, convert_memory_address won't do
6678 the right thing, so ignore the given target mode. */
6679 if (tmode != Pmode && tmode != ptr_mode)
6680 tmode = Pmode;
6682 result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
6683 tmode, modifier);
6685 /* Despite expand_expr claims concerning ignoring TMODE when not
6686 strictly convenient, stuff breaks if we don't honor it. Note
6687 that combined with the above, we only do this for pointer modes. */
6688 rmode = GET_MODE (result);
6689 if (rmode == VOIDmode)
6690 rmode = tmode;
6691 if (rmode != tmode)
6692 result = convert_memory_address (tmode, result);
6694 return result;
6698 /* expand_expr: generate code for computing expression EXP.
6699 An rtx for the computed value is returned. The value is never null.
6700 In the case of a void EXP, const0_rtx is returned.
6702 The value may be stored in TARGET if TARGET is nonzero.
6703 TARGET is just a suggestion; callers must assume that
6704 the rtx returned may not be the same as TARGET.
6706 If TARGET is CONST0_RTX, it means that the value will be ignored.
6708 If TMODE is not VOIDmode, it suggests generating the
6709 result in mode TMODE. But this is done only when convenient.
6710 Otherwise, TMODE is ignored and the value generated in its natural mode.
6711 TMODE is just a suggestion; callers must assume that
6712 the rtx returned may not have mode TMODE.
6714 Note that TARGET may have neither TMODE nor MODE. In that case, it
6715 probably will not be used.
6717 If MODIFIER is EXPAND_SUM then when EXP is an addition
6718 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
6719 or a nest of (PLUS ...) and (MINUS ...) where the terms are
6720 products as above, or REG or MEM, or constant.
6721 Ordinarily in such cases we would output mul or add instructions
6722 and then return a pseudo reg containing the sum.
6724 EXPAND_INITIALIZER is much like EXPAND_SUM except that
6725 it also marks a label as absolutely required (it can't be dead).
6726 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
6727 This is used for outputting expressions used in initializers.
6729 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
6730 with a constant address even if that address is not normally legitimate.
6731 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
6733 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
6734 a call parameter. Such targets require special care as we haven't yet
6735 marked TARGET so that it's safe from being trashed by libcalls. We
6736 don't want to use TARGET for anything but the final result;
6737 Intermediate values must go elsewhere. Additionally, calls to
6738 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
6740 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
6741 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
6742 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
6743 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
6744 recursively. */
6746 static rtx expand_expr_real_1 (tree, rtx, enum machine_mode,
6747 enum expand_modifier, rtx *);
6750 expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
6751 enum expand_modifier modifier, rtx *alt_rtl)
6753 int rn = -1;
6754 rtx ret, last = NULL;
6756 /* Handle ERROR_MARK before anybody tries to access its type. */
6757 if (TREE_CODE (exp) == ERROR_MARK
6758 || (!GIMPLE_TUPLE_P (exp) && TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
6760 ret = CONST0_RTX (tmode);
6761 return ret ? ret : const0_rtx;
6764 if (flag_non_call_exceptions)
6766 rn = lookup_stmt_eh_region (exp);
6767 /* If rn < 0, then either (1) tree-ssa not used or (2) doesn't throw. */
6768 if (rn >= 0)
6769 last = get_last_insn ();
6772 /* If this is an expression of some kind and it has an associated line
6773 number, then emit the line number before expanding the expression.
6775 We need to save and restore the file and line information so that
6776 errors discovered during expansion are emitted with the right
6777 information. It would be better of the diagnostic routines
6778 used the file/line information embedded in the tree nodes rather
6779 than globals. */
6780 if (cfun && EXPR_HAS_LOCATION (exp))
6782 location_t saved_location = input_location;
6783 input_location = EXPR_LOCATION (exp);
6784 set_curr_insn_source_location (input_location);
6786 /* Record where the insns produced belong. */
6787 set_curr_insn_block (TREE_BLOCK (exp));
6789 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
6791 input_location = saved_location;
6793 else
6795 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
6798 /* If using non-call exceptions, mark all insns that may trap.
6799 expand_call() will mark CALL_INSNs before we get to this code,
6800 but it doesn't handle libcalls, and these may trap. */
6801 if (rn >= 0)
6803 rtx insn;
6804 for (insn = next_real_insn (last); insn;
6805 insn = next_real_insn (insn))
6807 if (! find_reg_note (insn, REG_EH_REGION, NULL_RTX)
6808 /* If we want exceptions for non-call insns, any
6809 may_trap_p instruction may throw. */
6810 && GET_CODE (PATTERN (insn)) != CLOBBER
6811 && GET_CODE (PATTERN (insn)) != USE
6812 && (CALL_P (insn) || may_trap_p (PATTERN (insn))))
6814 REG_NOTES (insn) = alloc_EXPR_LIST (REG_EH_REGION, GEN_INT (rn),
6815 REG_NOTES (insn));
6820 return ret;
6823 static rtx
6824 expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
6825 enum expand_modifier modifier, rtx *alt_rtl)
6827 rtx op0, op1, op2, temp, decl_rtl;
6828 tree type;
6829 int unsignedp;
6830 enum machine_mode mode;
6831 enum tree_code code = TREE_CODE (exp);
6832 optab this_optab;
6833 rtx subtarget, original_target;
6834 int ignore;
6835 tree context, subexp0, subexp1;
6836 bool reduce_bit_field = false;
6837 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field && !ignore \
6838 ? reduce_to_bit_field_precision ((expr), \
6839 target, \
6840 type) \
6841 : (expr))
6843 if (GIMPLE_STMT_P (exp))
6845 type = void_type_node;
6846 mode = VOIDmode;
6847 unsignedp = 0;
6849 else
6851 type = TREE_TYPE (exp);
6852 mode = TYPE_MODE (type);
6853 unsignedp = TYPE_UNSIGNED (type);
6855 if (lang_hooks.reduce_bit_field_operations
6856 && TREE_CODE (type) == INTEGER_TYPE
6857 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type))
6859 /* An operation in what may be a bit-field type needs the
6860 result to be reduced to the precision of the bit-field type,
6861 which is narrower than that of the type's mode. */
6862 reduce_bit_field = true;
6863 if (modifier == EXPAND_STACK_PARM)
6864 target = 0;
6867 /* Use subtarget as the target for operand 0 of a binary operation. */
6868 subtarget = get_subtarget (target);
6869 original_target = target;
6870 ignore = (target == const0_rtx
6871 || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
6872 || code == CONVERT_EXPR || code == COND_EXPR
6873 || code == VIEW_CONVERT_EXPR)
6874 && TREE_CODE (type) == VOID_TYPE));
6876 /* If we are going to ignore this result, we need only do something
6877 if there is a side-effect somewhere in the expression. If there
6878 is, short-circuit the most common cases here. Note that we must
6879 not call expand_expr with anything but const0_rtx in case this
6880 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
6882 if (ignore)
6884 if (! TREE_SIDE_EFFECTS (exp))
6885 return const0_rtx;
6887 /* Ensure we reference a volatile object even if value is ignored, but
6888 don't do this if all we are doing is taking its address. */
6889 if (TREE_THIS_VOLATILE (exp)
6890 && TREE_CODE (exp) != FUNCTION_DECL
6891 && mode != VOIDmode && mode != BLKmode
6892 && modifier != EXPAND_CONST_ADDRESS)
6894 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
6895 if (MEM_P (temp))
6896 temp = copy_to_reg (temp);
6897 return const0_rtx;
6900 if (TREE_CODE_CLASS (code) == tcc_unary
6901 || code == COMPONENT_REF || code == INDIRECT_REF)
6902 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6903 modifier);
6905 else if (TREE_CODE_CLASS (code) == tcc_binary
6906 || TREE_CODE_CLASS (code) == tcc_comparison
6907 || code == ARRAY_REF || code == ARRAY_RANGE_REF)
6909 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
6910 expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
6911 return const0_rtx;
6913 else if (code == BIT_FIELD_REF)
6915 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
6916 expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
6917 expand_expr (TREE_OPERAND (exp, 2), const0_rtx, VOIDmode, modifier);
6918 return const0_rtx;
6921 target = 0;
6925 switch (code)
6927 case LABEL_DECL:
6929 tree function = decl_function_context (exp);
6931 temp = label_rtx (exp);
6932 temp = gen_rtx_LABEL_REF (Pmode, temp);
6934 if (function != current_function_decl
6935 && function != 0)
6936 LABEL_REF_NONLOCAL_P (temp) = 1;
6938 temp = gen_rtx_MEM (FUNCTION_MODE, temp);
6939 return temp;
6942 case SSA_NAME:
6943 return expand_expr_real_1 (SSA_NAME_VAR (exp), target, tmode, modifier,
6944 NULL);
6946 case PARM_DECL:
6947 case VAR_DECL:
6948 /* If a static var's type was incomplete when the decl was written,
6949 but the type is complete now, lay out the decl now. */
6950 if (DECL_SIZE (exp) == 0
6951 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
6952 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
6953 layout_decl (exp, 0);
6955 /* TLS emulation hook - replace __thread vars with
6956 *__emutls_get_address (&_emutls.var). */
6957 if (! targetm.have_tls
6958 && TREE_CODE (exp) == VAR_DECL
6959 && DECL_THREAD_LOCAL_P (exp))
6961 exp = build_fold_indirect_ref (emutls_var_address (exp));
6962 return expand_expr_real_1 (exp, target, tmode, modifier, NULL);
6965 /* ... fall through ... */
6967 case FUNCTION_DECL:
6968 case RESULT_DECL:
6969 decl_rtl = DECL_RTL (exp);
6970 gcc_assert (decl_rtl);
6971 decl_rtl = copy_rtx (decl_rtl);
6973 /* Ensure variable marked as used even if it doesn't go through
6974 a parser. If it hasn't be used yet, write out an external
6975 definition. */
6976 if (! TREE_USED (exp))
6978 assemble_external (exp);
6979 TREE_USED (exp) = 1;
6982 /* Show we haven't gotten RTL for this yet. */
6983 temp = 0;
6985 /* Variables inherited from containing functions should have
6986 been lowered by this point. */
6987 context = decl_function_context (exp);
6988 gcc_assert (!context
6989 || context == current_function_decl
6990 || TREE_STATIC (exp)
6991 /* ??? C++ creates functions that are not TREE_STATIC. */
6992 || TREE_CODE (exp) == FUNCTION_DECL);
6994 /* This is the case of an array whose size is to be determined
6995 from its initializer, while the initializer is still being parsed.
6996 See expand_decl. */
6998 if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
6999 temp = validize_mem (decl_rtl);
7001 /* If DECL_RTL is memory, we are in the normal case and either
7002 the address is not valid or it is not a register and -fforce-addr
7003 is specified, get the address into a register. */
7005 else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
7007 if (alt_rtl)
7008 *alt_rtl = decl_rtl;
7009 decl_rtl = use_anchored_address (decl_rtl);
7010 if (modifier != EXPAND_CONST_ADDRESS
7011 && modifier != EXPAND_SUM
7012 && (!memory_address_p (DECL_MODE (exp), XEXP (decl_rtl, 0))
7013 || (flag_force_addr && !REG_P (XEXP (decl_rtl, 0)))))
7014 temp = replace_equiv_address (decl_rtl,
7015 copy_rtx (XEXP (decl_rtl, 0)));
7018 /* If we got something, return it. But first, set the alignment
7019 if the address is a register. */
7020 if (temp != 0)
7022 if (MEM_P (temp) && REG_P (XEXP (temp, 0)))
7023 mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
7025 return temp;
7028 /* If the mode of DECL_RTL does not match that of the decl, it
7029 must be a promoted value. We return a SUBREG of the wanted mode,
7030 but mark it so that we know that it was already extended. */
7032 if (REG_P (decl_rtl)
7033 && GET_MODE (decl_rtl) != DECL_MODE (exp))
7035 enum machine_mode pmode;
7037 /* Get the signedness used for this variable. Ensure we get the
7038 same mode we got when the variable was declared. */
7039 pmode = promote_mode (type, DECL_MODE (exp), &unsignedp,
7040 (TREE_CODE (exp) == RESULT_DECL
7041 || TREE_CODE (exp) == PARM_DECL) ? 1 : 0);
7042 gcc_assert (GET_MODE (decl_rtl) == pmode);
7044 temp = gen_lowpart_SUBREG (mode, decl_rtl);
7045 SUBREG_PROMOTED_VAR_P (temp) = 1;
7046 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
7047 return temp;
7050 return decl_rtl;
7052 case INTEGER_CST:
7053 temp = immed_double_const (TREE_INT_CST_LOW (exp),
7054 TREE_INT_CST_HIGH (exp), mode);
7056 /* ??? If overflow is set, fold will have done an incomplete job,
7057 which can result in (plus xx (const_int 0)), which can get
7058 simplified by validate_replace_rtx during virtual register
7059 instantiation, which can result in unrecognizable insns.
7060 Avoid this by forcing all overflows into registers. */
7061 if (TREE_OVERFLOW (exp)
7062 && modifier != EXPAND_INITIALIZER)
7063 temp = force_reg (mode, temp);
7065 return temp;
7067 case VECTOR_CST:
7069 tree tmp = NULL_TREE;
7070 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
7071 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
7072 return const_vector_from_tree (exp);
7073 if (GET_MODE_CLASS (mode) == MODE_INT)
7075 tree type_for_mode = lang_hooks.types.type_for_mode (mode, 1);
7076 if (type_for_mode)
7077 tmp = fold_unary (VIEW_CONVERT_EXPR, type_for_mode, exp);
7079 if (!tmp)
7080 tmp = build_constructor_from_list (type,
7081 TREE_VECTOR_CST_ELTS (exp));
7082 return expand_expr (tmp, ignore ? const0_rtx : target,
7083 tmode, modifier);
7086 case CONST_DECL:
7087 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
7089 case REAL_CST:
7090 /* If optimized, generate immediate CONST_DOUBLE
7091 which will be turned into memory by reload if necessary.
7093 We used to force a register so that loop.c could see it. But
7094 this does not allow gen_* patterns to perform optimizations with
7095 the constants. It also produces two insns in cases like "x = 1.0;".
7096 On most machines, floating-point constants are not permitted in
7097 many insns, so we'd end up copying it to a register in any case.
7099 Now, we do the copying in expand_binop, if appropriate. */
7100 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
7101 TYPE_MODE (TREE_TYPE (exp)));
7103 case COMPLEX_CST:
7104 /* Handle evaluating a complex constant in a CONCAT target. */
7105 if (original_target && GET_CODE (original_target) == CONCAT)
7107 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
7108 rtx rtarg, itarg;
7110 rtarg = XEXP (original_target, 0);
7111 itarg = XEXP (original_target, 1);
7113 /* Move the real and imaginary parts separately. */
7114 op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, 0);
7115 op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, 0);
7117 if (op0 != rtarg)
7118 emit_move_insn (rtarg, op0);
7119 if (op1 != itarg)
7120 emit_move_insn (itarg, op1);
7122 return original_target;
7125 /* ... fall through ... */
7127 case STRING_CST:
7128 temp = expand_expr_constant (exp, 1, modifier);
7130 /* temp contains a constant address.
7131 On RISC machines where a constant address isn't valid,
7132 make some insns to get that address into a register. */
7133 if (modifier != EXPAND_CONST_ADDRESS
7134 && modifier != EXPAND_INITIALIZER
7135 && modifier != EXPAND_SUM
7136 && (! memory_address_p (mode, XEXP (temp, 0))
7137 || flag_force_addr))
7138 return replace_equiv_address (temp,
7139 copy_rtx (XEXP (temp, 0)));
7140 return temp;
7142 case SAVE_EXPR:
7144 tree val = TREE_OPERAND (exp, 0);
7145 rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl);
7147 if (!SAVE_EXPR_RESOLVED_P (exp))
7149 /* We can indeed still hit this case, typically via builtin
7150 expanders calling save_expr immediately before expanding
7151 something. Assume this means that we only have to deal
7152 with non-BLKmode values. */
7153 gcc_assert (GET_MODE (ret) != BLKmode);
7155 val = build_decl (VAR_DECL, NULL, TREE_TYPE (exp));
7156 DECL_ARTIFICIAL (val) = 1;
7157 DECL_IGNORED_P (val) = 1;
7158 TREE_OPERAND (exp, 0) = val;
7159 SAVE_EXPR_RESOLVED_P (exp) = 1;
7161 if (!CONSTANT_P (ret))
7162 ret = copy_to_reg (ret);
7163 SET_DECL_RTL (val, ret);
7166 return ret;
7169 case GOTO_EXPR:
7170 if (TREE_CODE (TREE_OPERAND (exp, 0)) == LABEL_DECL)
7171 expand_goto (TREE_OPERAND (exp, 0));
7172 else
7173 expand_computed_goto (TREE_OPERAND (exp, 0));
7174 return const0_rtx;
7176 case CONSTRUCTOR:
7177 /* If we don't need the result, just ensure we evaluate any
7178 subexpressions. */
7179 if (ignore)
7181 unsigned HOST_WIDE_INT idx;
7182 tree value;
7184 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
7185 expand_expr (value, const0_rtx, VOIDmode, 0);
7187 return const0_rtx;
7190 /* Try to avoid creating a temporary at all. This is possible
7191 if all of the initializer is zero.
7192 FIXME: try to handle all [0..255] initializers we can handle
7193 with memset. */
7194 else if (TREE_STATIC (exp)
7195 && !TREE_ADDRESSABLE (exp)
7196 && target != 0 && mode == BLKmode
7197 && all_zeros_p (exp))
7199 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7200 return target;
7203 /* All elts simple constants => refer to a constant in memory. But
7204 if this is a non-BLKmode mode, let it store a field at a time
7205 since that should make a CONST_INT or CONST_DOUBLE when we
7206 fold. Likewise, if we have a target we can use, it is best to
7207 store directly into the target unless the type is large enough
7208 that memcpy will be used. If we are making an initializer and
7209 all operands are constant, put it in memory as well.
7211 FIXME: Avoid trying to fill vector constructors piece-meal.
7212 Output them with output_constant_def below unless we're sure
7213 they're zeros. This should go away when vector initializers
7214 are treated like VECTOR_CST instead of arrays.
7216 else if ((TREE_STATIC (exp)
7217 && ((mode == BLKmode
7218 && ! (target != 0 && safe_from_p (target, exp, 1)))
7219 || TREE_ADDRESSABLE (exp)
7220 || (host_integerp (TYPE_SIZE_UNIT (type), 1)
7221 && (! MOVE_BY_PIECES_P
7222 (tree_low_cst (TYPE_SIZE_UNIT (type), 1),
7223 TYPE_ALIGN (type)))
7224 && ! mostly_zeros_p (exp))))
7225 || ((modifier == EXPAND_INITIALIZER
7226 || modifier == EXPAND_CONST_ADDRESS)
7227 && TREE_CONSTANT (exp)))
7229 rtx constructor = expand_expr_constant (exp, 1, modifier);
7231 if (modifier != EXPAND_CONST_ADDRESS
7232 && modifier != EXPAND_INITIALIZER
7233 && modifier != EXPAND_SUM)
7234 constructor = validize_mem (constructor);
7236 return constructor;
7238 else
7240 /* Handle calls that pass values in multiple non-contiguous
7241 locations. The Irix 6 ABI has examples of this. */
7242 if (target == 0 || ! safe_from_p (target, exp, 1)
7243 || GET_CODE (target) == PARALLEL
7244 || modifier == EXPAND_STACK_PARM)
7245 target
7246 = assign_temp (build_qualified_type (type,
7247 (TYPE_QUALS (type)
7248 | (TREE_READONLY (exp)
7249 * TYPE_QUAL_CONST))),
7250 0, TREE_ADDRESSABLE (exp), 1);
7252 store_constructor (exp, target, 0, int_expr_size (exp));
7253 return target;
7256 case MISALIGNED_INDIRECT_REF:
7257 case ALIGN_INDIRECT_REF:
7258 case INDIRECT_REF:
7260 tree exp1 = TREE_OPERAND (exp, 0);
7262 if (modifier != EXPAND_WRITE)
7264 tree t;
7266 t = fold_read_from_constant_string (exp);
7267 if (t)
7268 return expand_expr (t, target, tmode, modifier);
7271 op0 = expand_expr (exp1, NULL_RTX, VOIDmode, EXPAND_SUM);
7272 op0 = memory_address (mode, op0);
7274 if (code == ALIGN_INDIRECT_REF)
7276 int align = TYPE_ALIGN_UNIT (type);
7277 op0 = gen_rtx_AND (Pmode, op0, GEN_INT (-align));
7278 op0 = memory_address (mode, op0);
7281 temp = gen_rtx_MEM (mode, op0);
7283 set_mem_attributes (temp, exp, 0);
7285 /* Resolve the misalignment now, so that we don't have to remember
7286 to resolve it later. Of course, this only works for reads. */
7287 /* ??? When we get around to supporting writes, we'll have to handle
7288 this in store_expr directly. The vectorizer isn't generating
7289 those yet, however. */
7290 if (code == MISALIGNED_INDIRECT_REF)
7292 int icode;
7293 rtx reg, insn;
7295 gcc_assert (modifier == EXPAND_NORMAL
7296 || modifier == EXPAND_STACK_PARM);
7298 /* The vectorizer should have already checked the mode. */
7299 icode = movmisalign_optab->handlers[mode].insn_code;
7300 gcc_assert (icode != CODE_FOR_nothing);
7302 /* We've already validated the memory, and we're creating a
7303 new pseudo destination. The predicates really can't fail. */
7304 reg = gen_reg_rtx (mode);
7306 /* Nor can the insn generator. */
7307 insn = GEN_FCN (icode) (reg, temp);
7308 emit_insn (insn);
7310 return reg;
7313 return temp;
7316 case TARGET_MEM_REF:
7318 struct mem_address addr;
7320 get_address_description (exp, &addr);
7321 op0 = addr_for_mem_ref (&addr, true);
7322 op0 = memory_address (mode, op0);
7323 temp = gen_rtx_MEM (mode, op0);
7324 set_mem_attributes (temp, TMR_ORIGINAL (exp), 0);
7326 return temp;
7328 case ARRAY_REF:
7331 tree array = TREE_OPERAND (exp, 0);
7332 tree index = TREE_OPERAND (exp, 1);
7334 /* Fold an expression like: "foo"[2].
7335 This is not done in fold so it won't happen inside &.
7336 Don't fold if this is for wide characters since it's too
7337 difficult to do correctly and this is a very rare case. */
7339 if (modifier != EXPAND_CONST_ADDRESS
7340 && modifier != EXPAND_INITIALIZER
7341 && modifier != EXPAND_MEMORY)
7343 tree t = fold_read_from_constant_string (exp);
7345 if (t)
7346 return expand_expr (t, target, tmode, modifier);
7349 /* If this is a constant index into a constant array,
7350 just get the value from the array. Handle both the cases when
7351 we have an explicit constructor and when our operand is a variable
7352 that was declared const. */
7354 if (modifier != EXPAND_CONST_ADDRESS
7355 && modifier != EXPAND_INITIALIZER
7356 && modifier != EXPAND_MEMORY
7357 && TREE_CODE (array) == CONSTRUCTOR
7358 && ! TREE_SIDE_EFFECTS (array)
7359 && TREE_CODE (index) == INTEGER_CST)
7361 unsigned HOST_WIDE_INT ix;
7362 tree field, value;
7364 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
7365 field, value)
7366 if (tree_int_cst_equal (field, index))
7368 if (!TREE_SIDE_EFFECTS (value))
7369 return expand_expr (fold (value), target, tmode, modifier);
7370 break;
7374 else if (optimize >= 1
7375 && modifier != EXPAND_CONST_ADDRESS
7376 && modifier != EXPAND_INITIALIZER
7377 && modifier != EXPAND_MEMORY
7378 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
7379 && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
7380 && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK
7381 && targetm.binds_local_p (array))
7383 if (TREE_CODE (index) == INTEGER_CST)
7385 tree init = DECL_INITIAL (array);
7387 if (TREE_CODE (init) == CONSTRUCTOR)
7389 unsigned HOST_WIDE_INT ix;
7390 tree field, value;
7392 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
7393 field, value)
7394 if (tree_int_cst_equal (field, index))
7396 if (!TREE_SIDE_EFFECTS (value))
7397 return expand_expr (fold (value), target, tmode,
7398 modifier);
7399 break;
7402 else if(TREE_CODE (init) == STRING_CST)
7404 tree index1 = index;
7405 tree low_bound = array_ref_low_bound (exp);
7406 index1 = fold_convert (sizetype, TREE_OPERAND (exp, 1));
7408 /* Optimize the special-case of a zero lower bound.
7410 We convert the low_bound to sizetype to avoid some problems
7411 with constant folding. (E.g. suppose the lower bound is 1,
7412 and its mode is QI. Without the conversion,l (ARRAY
7413 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
7414 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
7416 if (! integer_zerop (low_bound))
7417 index1 = size_diffop (index1, fold_convert (sizetype,
7418 low_bound));
7420 if (0 > compare_tree_int (index1,
7421 TREE_STRING_LENGTH (init)))
7423 tree type = TREE_TYPE (TREE_TYPE (init));
7424 enum machine_mode mode = TYPE_MODE (type);
7426 if (GET_MODE_CLASS (mode) == MODE_INT
7427 && GET_MODE_SIZE (mode) == 1)
7428 return gen_int_mode (TREE_STRING_POINTER (init)
7429 [TREE_INT_CST_LOW (index1)],
7430 mode);
7436 goto normal_inner_ref;
7438 case COMPONENT_REF:
7439 /* If the operand is a CONSTRUCTOR, we can just extract the
7440 appropriate field if it is present. */
7441 if (TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR)
7443 unsigned HOST_WIDE_INT idx;
7444 tree field, value;
7446 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)),
7447 idx, field, value)
7448 if (field == TREE_OPERAND (exp, 1)
7449 /* We can normally use the value of the field in the
7450 CONSTRUCTOR. However, if this is a bitfield in
7451 an integral mode that we can fit in a HOST_WIDE_INT,
7452 we must mask only the number of bits in the bitfield,
7453 since this is done implicitly by the constructor. If
7454 the bitfield does not meet either of those conditions,
7455 we can't do this optimization. */
7456 && (! DECL_BIT_FIELD (field)
7457 || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
7458 && (GET_MODE_BITSIZE (DECL_MODE (field))
7459 <= HOST_BITS_PER_WIDE_INT))))
7461 if (DECL_BIT_FIELD (field)
7462 && modifier == EXPAND_STACK_PARM)
7463 target = 0;
7464 op0 = expand_expr (value, target, tmode, modifier);
7465 if (DECL_BIT_FIELD (field))
7467 HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
7468 enum machine_mode imode = TYPE_MODE (TREE_TYPE (field));
7470 if (TYPE_UNSIGNED (TREE_TYPE (field)))
7472 op1 = GEN_INT (((HOST_WIDE_INT) 1 << bitsize) - 1);
7473 op0 = expand_and (imode, op0, op1, target);
7475 else
7477 tree count
7478 = build_int_cst (NULL_TREE,
7479 GET_MODE_BITSIZE (imode) - bitsize);
7481 op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
7482 target, 0);
7483 op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
7484 target, 0);
7488 return op0;
7491 goto normal_inner_ref;
7493 case BIT_FIELD_REF:
7494 case ARRAY_RANGE_REF:
7495 normal_inner_ref:
7497 enum machine_mode mode1;
7498 HOST_WIDE_INT bitsize, bitpos;
7499 tree offset;
7500 int volatilep = 0;
7501 tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
7502 &mode1, &unsignedp, &volatilep, true);
7503 rtx orig_op0;
7505 /* If we got back the original object, something is wrong. Perhaps
7506 we are evaluating an expression too early. In any event, don't
7507 infinitely recurse. */
7508 gcc_assert (tem != exp);
7510 /* If TEM's type is a union of variable size, pass TARGET to the inner
7511 computation, since it will need a temporary and TARGET is known
7512 to have to do. This occurs in unchecked conversion in Ada. */
7514 orig_op0 = op0
7515 = expand_expr (tem,
7516 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
7517 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
7518 != INTEGER_CST)
7519 && modifier != EXPAND_STACK_PARM
7520 ? target : NULL_RTX),
7521 VOIDmode,
7522 (modifier == EXPAND_INITIALIZER
7523 || modifier == EXPAND_CONST_ADDRESS
7524 || modifier == EXPAND_STACK_PARM)
7525 ? modifier : EXPAND_NORMAL);
7527 /* If this is a constant, put it into a register if it is a legitimate
7528 constant, OFFSET is 0, and we won't try to extract outside the
7529 register (in case we were passed a partially uninitialized object
7530 or a view_conversion to a larger size). Force the constant to
7531 memory otherwise. */
7532 if (CONSTANT_P (op0))
7534 enum machine_mode mode = TYPE_MODE (TREE_TYPE (tem));
7535 if (mode != BLKmode && LEGITIMATE_CONSTANT_P (op0)
7536 && offset == 0
7537 && bitpos + bitsize <= GET_MODE_BITSIZE (mode))
7538 op0 = force_reg (mode, op0);
7539 else
7540 op0 = validize_mem (force_const_mem (mode, op0));
7543 /* Otherwise, if this object not in memory and we either have an
7544 offset, a BLKmode result, or a reference outside the object, put it
7545 there. Such cases can occur in Ada if we have unchecked conversion
7546 of an expression from a scalar type to an array or record type or
7547 for an ARRAY_RANGE_REF whose type is BLKmode. */
7548 else if (!MEM_P (op0)
7549 && (offset != 0
7550 || (bitpos + bitsize > GET_MODE_BITSIZE (GET_MODE (op0)))
7551 || (code == ARRAY_RANGE_REF && mode == BLKmode)))
7553 tree nt = build_qualified_type (TREE_TYPE (tem),
7554 (TYPE_QUALS (TREE_TYPE (tem))
7555 | TYPE_QUAL_CONST));
7556 rtx memloc = assign_temp (nt, 1, 1, 1);
7558 emit_move_insn (memloc, op0);
7559 op0 = memloc;
7562 if (offset != 0)
7564 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
7565 EXPAND_SUM);
7567 gcc_assert (MEM_P (op0));
7569 #ifdef POINTERS_EXTEND_UNSIGNED
7570 if (GET_MODE (offset_rtx) != Pmode)
7571 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
7572 #else
7573 if (GET_MODE (offset_rtx) != ptr_mode)
7574 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
7575 #endif
7577 if (GET_MODE (op0) == BLKmode
7578 /* A constant address in OP0 can have VOIDmode, we must
7579 not try to call force_reg in that case. */
7580 && GET_MODE (XEXP (op0, 0)) != VOIDmode
7581 && bitsize != 0
7582 && (bitpos % bitsize) == 0
7583 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
7584 && MEM_ALIGN (op0) == GET_MODE_ALIGNMENT (mode1))
7586 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
7587 bitpos = 0;
7590 op0 = offset_address (op0, offset_rtx,
7591 highest_pow2_factor (offset));
7594 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
7595 record its alignment as BIGGEST_ALIGNMENT. */
7596 if (MEM_P (op0) && bitpos == 0 && offset != 0
7597 && is_aligning_offset (offset, tem))
7598 set_mem_align (op0, BIGGEST_ALIGNMENT);
7600 /* Don't forget about volatility even if this is a bitfield. */
7601 if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
7603 if (op0 == orig_op0)
7604 op0 = copy_rtx (op0);
7606 MEM_VOLATILE_P (op0) = 1;
7609 /* The following code doesn't handle CONCAT.
7610 Assume only bitpos == 0 can be used for CONCAT, due to
7611 one element arrays having the same mode as its element. */
7612 if (GET_CODE (op0) == CONCAT)
7614 gcc_assert (bitpos == 0
7615 && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)));
7616 return op0;
7619 /* In cases where an aligned union has an unaligned object
7620 as a field, we might be extracting a BLKmode value from
7621 an integer-mode (e.g., SImode) object. Handle this case
7622 by doing the extract into an object as wide as the field
7623 (which we know to be the width of a basic mode), then
7624 storing into memory, and changing the mode to BLKmode. */
7625 if (mode1 == VOIDmode
7626 || REG_P (op0) || GET_CODE (op0) == SUBREG
7627 || (mode1 != BLKmode && ! direct_load[(int) mode1]
7628 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
7629 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
7630 && modifier != EXPAND_CONST_ADDRESS
7631 && modifier != EXPAND_INITIALIZER)
7632 /* If the field isn't aligned enough to fetch as a memref,
7633 fetch it as a bit field. */
7634 || (mode1 != BLKmode
7635 && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
7636 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
7637 || (MEM_P (op0)
7638 && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
7639 || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
7640 && ((modifier == EXPAND_CONST_ADDRESS
7641 || modifier == EXPAND_INITIALIZER)
7642 ? STRICT_ALIGNMENT
7643 : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
7644 || (bitpos % BITS_PER_UNIT != 0)))
7645 /* If the type and the field are a constant size and the
7646 size of the type isn't the same size as the bitfield,
7647 we must use bitfield operations. */
7648 || (bitsize >= 0
7649 && TYPE_SIZE (TREE_TYPE (exp))
7650 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
7651 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
7652 bitsize)))
7654 enum machine_mode ext_mode = mode;
7656 if (ext_mode == BLKmode
7657 && ! (target != 0 && MEM_P (op0)
7658 && MEM_P (target)
7659 && bitpos % BITS_PER_UNIT == 0))
7660 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
7662 if (ext_mode == BLKmode)
7664 if (target == 0)
7665 target = assign_temp (type, 0, 1, 1);
7667 if (bitsize == 0)
7668 return target;
7670 /* In this case, BITPOS must start at a byte boundary and
7671 TARGET, if specified, must be a MEM. */
7672 gcc_assert (MEM_P (op0)
7673 && (!target || MEM_P (target))
7674 && !(bitpos % BITS_PER_UNIT));
7676 emit_block_move (target,
7677 adjust_address (op0, VOIDmode,
7678 bitpos / BITS_PER_UNIT),
7679 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
7680 / BITS_PER_UNIT),
7681 (modifier == EXPAND_STACK_PARM
7682 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
7684 return target;
7687 op0 = validize_mem (op0);
7689 if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
7690 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
7692 op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
7693 (modifier == EXPAND_STACK_PARM
7694 ? NULL_RTX : target),
7695 ext_mode, ext_mode);
7697 /* If the result is a record type and BITSIZE is narrower than
7698 the mode of OP0, an integral mode, and this is a big endian
7699 machine, we must put the field into the high-order bits. */
7700 if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
7701 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
7702 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
7703 op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
7704 size_int (GET_MODE_BITSIZE (GET_MODE (op0))
7705 - bitsize),
7706 op0, 1);
7708 /* If the result type is BLKmode, store the data into a temporary
7709 of the appropriate type, but with the mode corresponding to the
7710 mode for the data we have (op0's mode). It's tempting to make
7711 this a constant type, since we know it's only being stored once,
7712 but that can cause problems if we are taking the address of this
7713 COMPONENT_REF because the MEM of any reference via that address
7714 will have flags corresponding to the type, which will not
7715 necessarily be constant. */
7716 if (mode == BLKmode)
7718 HOST_WIDE_INT size = GET_MODE_BITSIZE (ext_mode);
7719 rtx new;
7721 /* If the reference doesn't use the alias set of its type,
7722 we cannot create the temporary using that type. */
7723 if (component_uses_parent_alias_set (exp))
7725 new = assign_stack_local (ext_mode, size, 0);
7726 set_mem_alias_set (new, get_alias_set (exp));
7728 else
7729 new = assign_stack_temp_for_type (ext_mode, size, 0, type);
7731 emit_move_insn (new, op0);
7732 op0 = copy_rtx (new);
7733 PUT_MODE (op0, BLKmode);
7734 set_mem_attributes (op0, exp, 1);
7737 return op0;
7740 /* If the result is BLKmode, use that to access the object
7741 now as well. */
7742 if (mode == BLKmode)
7743 mode1 = BLKmode;
7745 /* Get a reference to just this component. */
7746 if (modifier == EXPAND_CONST_ADDRESS
7747 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7748 op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
7749 else
7750 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
7752 if (op0 == orig_op0)
7753 op0 = copy_rtx (op0);
7755 set_mem_attributes (op0, exp, 0);
7756 if (REG_P (XEXP (op0, 0)))
7757 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
7759 MEM_VOLATILE_P (op0) |= volatilep;
7760 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
7761 || modifier == EXPAND_CONST_ADDRESS
7762 || modifier == EXPAND_INITIALIZER)
7763 return op0;
7764 else if (target == 0)
7765 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
7767 convert_move (target, op0, unsignedp);
7768 return target;
7771 case OBJ_TYPE_REF:
7772 return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
7774 case CALL_EXPR:
7775 /* Check for a built-in function. */
7776 if (TREE_CODE (CALL_EXPR_FN (exp)) == ADDR_EXPR
7777 && (TREE_CODE (TREE_OPERAND (CALL_EXPR_FN (exp), 0))
7778 == FUNCTION_DECL)
7779 && DECL_BUILT_IN (TREE_OPERAND (CALL_EXPR_FN (exp), 0)))
7781 if (DECL_BUILT_IN_CLASS (TREE_OPERAND (CALL_EXPR_FN (exp), 0))
7782 == BUILT_IN_FRONTEND)
7783 return lang_hooks.expand_expr (exp, original_target,
7784 tmode, modifier,
7785 alt_rtl);
7786 else
7787 return expand_builtin (exp, target, subtarget, tmode, ignore);
7790 return expand_call (exp, target, ignore);
7792 case NON_LVALUE_EXPR:
7793 case NOP_EXPR:
7794 case CONVERT_EXPR:
7795 if (TREE_OPERAND (exp, 0) == error_mark_node)
7796 return const0_rtx;
7798 if (TREE_CODE (type) == UNION_TYPE)
7800 tree valtype = TREE_TYPE (TREE_OPERAND (exp, 0));
7802 /* If both input and output are BLKmode, this conversion isn't doing
7803 anything except possibly changing memory attribute. */
7804 if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
7806 rtx result = expand_expr (TREE_OPERAND (exp, 0), target, tmode,
7807 modifier);
7809 result = copy_rtx (result);
7810 set_mem_attributes (result, exp, 0);
7811 return result;
7814 if (target == 0)
7816 if (TYPE_MODE (type) != BLKmode)
7817 target = gen_reg_rtx (TYPE_MODE (type));
7818 else
7819 target = assign_temp (type, 0, 1, 1);
7822 if (MEM_P (target))
7823 /* Store data into beginning of memory target. */
7824 store_expr (TREE_OPERAND (exp, 0),
7825 adjust_address (target, TYPE_MODE (valtype), 0),
7826 modifier == EXPAND_STACK_PARM);
7828 else
7830 gcc_assert (REG_P (target));
7832 /* Store this field into a union of the proper type. */
7833 store_field (target,
7834 MIN ((int_size_in_bytes (TREE_TYPE
7835 (TREE_OPERAND (exp, 0)))
7836 * BITS_PER_UNIT),
7837 (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
7838 0, TYPE_MODE (valtype), TREE_OPERAND (exp, 0),
7839 type, 0);
7842 /* Return the entire union. */
7843 return target;
7846 if (mode == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
7848 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode,
7849 modifier);
7851 /* If the signedness of the conversion differs and OP0 is
7852 a promoted SUBREG, clear that indication since we now
7853 have to do the proper extension. */
7854 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))) != unsignedp
7855 && GET_CODE (op0) == SUBREG)
7856 SUBREG_PROMOTED_VAR_P (op0) = 0;
7858 return REDUCE_BIT_FIELD (op0);
7861 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode,
7862 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
7863 if (GET_MODE (op0) == mode)
7866 /* If OP0 is a constant, just convert it into the proper mode. */
7867 else if (CONSTANT_P (op0))
7869 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7870 enum machine_mode inner_mode = TYPE_MODE (inner_type);
7872 if (modifier == EXPAND_INITIALIZER)
7873 op0 = simplify_gen_subreg (mode, op0, inner_mode,
7874 subreg_lowpart_offset (mode,
7875 inner_mode));
7876 else
7877 op0= convert_modes (mode, inner_mode, op0,
7878 TYPE_UNSIGNED (inner_type));
7881 else if (modifier == EXPAND_INITIALIZER)
7882 op0 = gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
7884 else if (target == 0)
7885 op0 = convert_to_mode (mode, op0,
7886 TYPE_UNSIGNED (TREE_TYPE
7887 (TREE_OPERAND (exp, 0))));
7888 else
7890 convert_move (target, op0,
7891 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7892 op0 = target;
7895 return REDUCE_BIT_FIELD (op0);
7897 case VIEW_CONVERT_EXPR:
7898 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode, modifier);
7900 /* If the input and output modes are both the same, we are done. */
7901 if (TYPE_MODE (type) == GET_MODE (op0))
7903 /* If neither mode is BLKmode, and both modes are the same size
7904 then we can use gen_lowpart. */
7905 else if (TYPE_MODE (type) != BLKmode && GET_MODE (op0) != BLKmode
7906 && GET_MODE_SIZE (TYPE_MODE (type))
7907 == GET_MODE_SIZE (GET_MODE (op0)))
7909 if (GET_CODE (op0) == SUBREG)
7910 op0 = force_reg (GET_MODE (op0), op0);
7911 op0 = gen_lowpart (TYPE_MODE (type), op0);
7913 /* If both modes are integral, then we can convert from one to the
7914 other. */
7915 else if (SCALAR_INT_MODE_P (GET_MODE (op0))
7916 && SCALAR_INT_MODE_P (TYPE_MODE (type)))
7917 op0 = convert_modes (TYPE_MODE (type), GET_MODE (op0), op0,
7918 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7919 /* As a last resort, spill op0 to memory, and reload it in a
7920 different mode. */
7921 else if (!MEM_P (op0))
7923 /* If the operand is not a MEM, force it into memory. Since we
7924 are going to be changing the mode of the MEM, don't call
7925 force_const_mem for constants because we don't allow pool
7926 constants to change mode. */
7927 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7929 gcc_assert (!TREE_ADDRESSABLE (exp));
7931 if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
7932 target
7933 = assign_stack_temp_for_type
7934 (TYPE_MODE (inner_type),
7935 GET_MODE_SIZE (TYPE_MODE (inner_type)), 0, inner_type);
7937 emit_move_insn (target, op0);
7938 op0 = target;
7941 /* At this point, OP0 is in the correct mode. If the output type is such
7942 that the operand is known to be aligned, indicate that it is.
7943 Otherwise, we need only be concerned about alignment for non-BLKmode
7944 results. */
7945 if (MEM_P (op0))
7947 op0 = copy_rtx (op0);
7949 if (TYPE_ALIGN_OK (type))
7950 set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
7951 else if (TYPE_MODE (type) != BLKmode && STRICT_ALIGNMENT
7952 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
7954 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7955 HOST_WIDE_INT temp_size
7956 = MAX (int_size_in_bytes (inner_type),
7957 (HOST_WIDE_INT) GET_MODE_SIZE (TYPE_MODE (type)));
7958 rtx new = assign_stack_temp_for_type (TYPE_MODE (type),
7959 temp_size, 0, type);
7960 rtx new_with_op0_mode = adjust_address (new, GET_MODE (op0), 0);
7962 gcc_assert (!TREE_ADDRESSABLE (exp));
7964 if (GET_MODE (op0) == BLKmode)
7965 emit_block_move (new_with_op0_mode, op0,
7966 GEN_INT (GET_MODE_SIZE (TYPE_MODE (type))),
7967 (modifier == EXPAND_STACK_PARM
7968 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
7969 else
7970 emit_move_insn (new_with_op0_mode, op0);
7972 op0 = new;
7975 op0 = adjust_address (op0, TYPE_MODE (type), 0);
7978 return op0;
7980 case PLUS_EXPR:
7981 /* Check if this is a case for multiplication and addition. */
7982 if (TREE_CODE (type) == INTEGER_TYPE
7983 && TREE_CODE (TREE_OPERAND (exp, 0)) == MULT_EXPR)
7985 tree subsubexp0, subsubexp1;
7986 enum tree_code code0, code1;
7988 subexp0 = TREE_OPERAND (exp, 0);
7989 subsubexp0 = TREE_OPERAND (subexp0, 0);
7990 subsubexp1 = TREE_OPERAND (subexp0, 1);
7991 code0 = TREE_CODE (subsubexp0);
7992 code1 = TREE_CODE (subsubexp1);
7993 if (code0 == NOP_EXPR && code1 == NOP_EXPR
7994 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subsubexp0, 0)))
7995 < TYPE_PRECISION (TREE_TYPE (subsubexp0)))
7996 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subsubexp0, 0)))
7997 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subsubexp1, 0))))
7998 && (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (subsubexp0, 0)))
7999 == TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (subsubexp1, 0)))))
8001 tree op0type = TREE_TYPE (TREE_OPERAND (subsubexp0, 0));
8002 enum machine_mode innermode = TYPE_MODE (op0type);
8003 bool zextend_p = TYPE_UNSIGNED (op0type);
8004 this_optab = zextend_p ? umadd_widen_optab : smadd_widen_optab;
8005 if (mode == GET_MODE_2XWIDER_MODE (innermode)
8006 && (this_optab->handlers[(int) mode].insn_code
8007 != CODE_FOR_nothing))
8009 expand_operands (TREE_OPERAND (subsubexp0, 0),
8010 TREE_OPERAND (subsubexp1, 0),
8011 NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8012 op2 = expand_expr (TREE_OPERAND (exp, 1), subtarget,
8013 VOIDmode, 0);
8014 temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
8015 target, unsignedp);
8016 gcc_assert (temp);
8017 return REDUCE_BIT_FIELD (temp);
8022 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8023 something else, make sure we add the register to the constant and
8024 then to the other thing. This case can occur during strength
8025 reduction and doing it this way will produce better code if the
8026 frame pointer or argument pointer is eliminated.
8028 fold-const.c will ensure that the constant is always in the inner
8029 PLUS_EXPR, so the only case we need to do anything about is if
8030 sp, ap, or fp is our second argument, in which case we must swap
8031 the innermost first argument and our second argument. */
8033 if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
8034 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 1)) == INTEGER_CST
8035 && TREE_CODE (TREE_OPERAND (exp, 1)) == VAR_DECL
8036 && (DECL_RTL (TREE_OPERAND (exp, 1)) == frame_pointer_rtx
8037 || DECL_RTL (TREE_OPERAND (exp, 1)) == stack_pointer_rtx
8038 || DECL_RTL (TREE_OPERAND (exp, 1)) == arg_pointer_rtx))
8040 tree t = TREE_OPERAND (exp, 1);
8042 TREE_OPERAND (exp, 1) = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
8043 TREE_OPERAND (TREE_OPERAND (exp, 0), 0) = t;
8046 /* If the result is to be ptr_mode and we are adding an integer to
8047 something, we might be forming a constant. So try to use
8048 plus_constant. If it produces a sum and we can't accept it,
8049 use force_operand. This allows P = &ARR[const] to generate
8050 efficient code on machines where a SYMBOL_REF is not a valid
8051 address.
8053 If this is an EXPAND_SUM call, always return the sum. */
8054 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
8055 || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
8057 if (modifier == EXPAND_STACK_PARM)
8058 target = 0;
8059 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
8060 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
8061 && TREE_CONSTANT (TREE_OPERAND (exp, 1)))
8063 rtx constant_part;
8065 op1 = expand_expr (TREE_OPERAND (exp, 1), subtarget, VOIDmode,
8066 EXPAND_SUM);
8067 /* Use immed_double_const to ensure that the constant is
8068 truncated according to the mode of OP1, then sign extended
8069 to a HOST_WIDE_INT. Using the constant directly can result
8070 in non-canonical RTL in a 64x32 cross compile. */
8071 constant_part
8072 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp, 0)),
8073 (HOST_WIDE_INT) 0,
8074 TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))));
8075 op1 = plus_constant (op1, INTVAL (constant_part));
8076 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8077 op1 = force_operand (op1, target);
8078 return REDUCE_BIT_FIELD (op1);
8081 else if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
8082 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
8083 && TREE_CONSTANT (TREE_OPERAND (exp, 0)))
8085 rtx constant_part;
8087 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
8088 (modifier == EXPAND_INITIALIZER
8089 ? EXPAND_INITIALIZER : EXPAND_SUM));
8090 if (! CONSTANT_P (op0))
8092 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
8093 VOIDmode, modifier);
8094 /* Return a PLUS if modifier says it's OK. */
8095 if (modifier == EXPAND_SUM
8096 || modifier == EXPAND_INITIALIZER)
8097 return simplify_gen_binary (PLUS, mode, op0, op1);
8098 goto binop2;
8100 /* Use immed_double_const to ensure that the constant is
8101 truncated according to the mode of OP1, then sign extended
8102 to a HOST_WIDE_INT. Using the constant directly can result
8103 in non-canonical RTL in a 64x32 cross compile. */
8104 constant_part
8105 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)),
8106 (HOST_WIDE_INT) 0,
8107 TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))));
8108 op0 = plus_constant (op0, INTVAL (constant_part));
8109 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8110 op0 = force_operand (op0, target);
8111 return REDUCE_BIT_FIELD (op0);
8115 /* No sense saving up arithmetic to be done
8116 if it's all in the wrong mode to form part of an address.
8117 And force_operand won't know whether to sign-extend or
8118 zero-extend. */
8119 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8120 || mode != ptr_mode)
8122 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8123 subtarget, &op0, &op1, 0);
8124 if (op0 == const0_rtx)
8125 return op1;
8126 if (op1 == const0_rtx)
8127 return op0;
8128 goto binop2;
8131 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8132 subtarget, &op0, &op1, modifier);
8133 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8135 case MINUS_EXPR:
8136 /* For initializers, we are allowed to return a MINUS of two
8137 symbolic constants. Here we handle all cases when both operands
8138 are constant. */
8139 /* Handle difference of two symbolic constants,
8140 for the sake of an initializer. */
8141 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8142 && really_constant_p (TREE_OPERAND (exp, 0))
8143 && really_constant_p (TREE_OPERAND (exp, 1)))
8145 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8146 NULL_RTX, &op0, &op1, modifier);
8148 /* If the last operand is a CONST_INT, use plus_constant of
8149 the negated constant. Else make the MINUS. */
8150 if (GET_CODE (op1) == CONST_INT)
8151 return REDUCE_BIT_FIELD (plus_constant (op0, - INTVAL (op1)));
8152 else
8153 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode, op0, op1));
8156 /* No sense saving up arithmetic to be done
8157 if it's all in the wrong mode to form part of an address.
8158 And force_operand won't know whether to sign-extend or
8159 zero-extend. */
8160 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8161 || mode != ptr_mode)
8162 goto binop;
8164 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8165 subtarget, &op0, &op1, modifier);
8167 /* Convert A - const to A + (-const). */
8168 if (GET_CODE (op1) == CONST_INT)
8170 op1 = negate_rtx (mode, op1);
8171 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8174 goto binop2;
8176 case MULT_EXPR:
8177 /* If first operand is constant, swap them.
8178 Thus the following special case checks need only
8179 check the second operand. */
8180 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
8182 tree t1 = TREE_OPERAND (exp, 0);
8183 TREE_OPERAND (exp, 0) = TREE_OPERAND (exp, 1);
8184 TREE_OPERAND (exp, 1) = t1;
8187 /* Attempt to return something suitable for generating an
8188 indexed address, for machines that support that. */
8190 if (modifier == EXPAND_SUM && mode == ptr_mode
8191 && host_integerp (TREE_OPERAND (exp, 1), 0))
8193 tree exp1 = TREE_OPERAND (exp, 1);
8195 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
8196 EXPAND_SUM);
8198 if (!REG_P (op0))
8199 op0 = force_operand (op0, NULL_RTX);
8200 if (!REG_P (op0))
8201 op0 = copy_to_mode_reg (mode, op0);
8203 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0,
8204 gen_int_mode (tree_low_cst (exp1, 0),
8205 TYPE_MODE (TREE_TYPE (exp1)))));
8208 if (modifier == EXPAND_STACK_PARM)
8209 target = 0;
8211 /* Check for multiplying things that have been extended
8212 from a narrower type. If this machine supports multiplying
8213 in that narrower type with a result in the desired type,
8214 do it that way, and avoid the explicit type-conversion. */
8216 subexp0 = TREE_OPERAND (exp, 0);
8217 subexp1 = TREE_OPERAND (exp, 1);
8218 /* First, check if we have a multiplication of one signed and one
8219 unsigned operand. */
8220 if (TREE_CODE (subexp0) == NOP_EXPR
8221 && TREE_CODE (subexp1) == NOP_EXPR
8222 && TREE_CODE (type) == INTEGER_TYPE
8223 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subexp0, 0)))
8224 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
8225 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subexp0, 0)))
8226 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subexp1, 0))))
8227 && (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (subexp0, 0)))
8228 != TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (subexp1, 0)))))
8230 enum machine_mode innermode
8231 = TYPE_MODE (TREE_TYPE (TREE_OPERAND (subexp0, 0)));
8232 this_optab = usmul_widen_optab;
8233 if (mode == GET_MODE_WIDER_MODE (innermode))
8235 if (this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
8237 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (subexp0, 0))))
8238 expand_operands (TREE_OPERAND (subexp0, 0),
8239 TREE_OPERAND (subexp1, 0),
8240 NULL_RTX, &op0, &op1, 0);
8241 else
8242 expand_operands (TREE_OPERAND (subexp0, 0),
8243 TREE_OPERAND (subexp1, 0),
8244 NULL_RTX, &op1, &op0, 0);
8246 goto binop3;
8250 /* Check for a multiplication with matching signedness. */
8251 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR
8252 && TREE_CODE (type) == INTEGER_TYPE
8253 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
8254 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
8255 && ((TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
8256 && int_fits_type_p (TREE_OPERAND (exp, 1),
8257 TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
8258 /* Don't use a widening multiply if a shift will do. */
8259 && ((GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))))
8260 > HOST_BITS_PER_WIDE_INT)
8261 || exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))) < 0))
8263 (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
8264 && (TYPE_PRECISION (TREE_TYPE
8265 (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
8266 == TYPE_PRECISION (TREE_TYPE
8267 (TREE_OPERAND
8268 (TREE_OPERAND (exp, 0), 0))))
8269 /* If both operands are extended, they must either both
8270 be zero-extended or both be sign-extended. */
8271 && (TYPE_UNSIGNED (TREE_TYPE
8272 (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
8273 == TYPE_UNSIGNED (TREE_TYPE
8274 (TREE_OPERAND
8275 (TREE_OPERAND (exp, 0), 0)))))))
8277 tree op0type = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0));
8278 enum machine_mode innermode = TYPE_MODE (op0type);
8279 bool zextend_p = TYPE_UNSIGNED (op0type);
8280 optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
8281 this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
8283 if (mode == GET_MODE_2XWIDER_MODE (innermode))
8285 if (this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
8287 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
8288 expand_operands (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8289 TREE_OPERAND (exp, 1),
8290 NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8291 else
8292 expand_operands (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8293 TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
8294 NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8295 goto binop3;
8297 else if (other_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
8298 && innermode == word_mode)
8300 rtx htem, hipart;
8301 op0 = expand_normal (TREE_OPERAND (TREE_OPERAND (exp, 0), 0));
8302 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
8303 op1 = convert_modes (innermode, mode,
8304 expand_normal (TREE_OPERAND (exp, 1)),
8305 unsignedp);
8306 else
8307 op1 = expand_normal (TREE_OPERAND (TREE_OPERAND (exp, 1), 0));
8308 temp = expand_binop (mode, other_optab, op0, op1, target,
8309 unsignedp, OPTAB_LIB_WIDEN);
8310 hipart = gen_highpart (innermode, temp);
8311 htem = expand_mult_highpart_adjust (innermode, hipart,
8312 op0, op1, hipart,
8313 zextend_p);
8314 if (htem != hipart)
8315 emit_move_insn (hipart, htem);
8316 return REDUCE_BIT_FIELD (temp);
8320 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8321 subtarget, &op0, &op1, 0);
8322 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8324 case TRUNC_DIV_EXPR:
8325 case FLOOR_DIV_EXPR:
8326 case CEIL_DIV_EXPR:
8327 case ROUND_DIV_EXPR:
8328 case EXACT_DIV_EXPR:
8329 if (modifier == EXPAND_STACK_PARM)
8330 target = 0;
8331 /* Possible optimization: compute the dividend with EXPAND_SUM
8332 then if the divisor is constant can optimize the case
8333 where some terms of the dividend have coeffs divisible by it. */
8334 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8335 subtarget, &op0, &op1, 0);
8336 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
8338 case RDIV_EXPR:
8339 goto binop;
8341 case TRUNC_MOD_EXPR:
8342 case FLOOR_MOD_EXPR:
8343 case CEIL_MOD_EXPR:
8344 case ROUND_MOD_EXPR:
8345 if (modifier == EXPAND_STACK_PARM)
8346 target = 0;
8347 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8348 subtarget, &op0, &op1, 0);
8349 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
8351 case FIX_TRUNC_EXPR:
8352 op0 = expand_normal (TREE_OPERAND (exp, 0));
8353 if (target == 0 || modifier == EXPAND_STACK_PARM)
8354 target = gen_reg_rtx (mode);
8355 expand_fix (target, op0, unsignedp);
8356 return target;
8358 case FLOAT_EXPR:
8359 op0 = expand_normal (TREE_OPERAND (exp, 0));
8360 if (target == 0 || modifier == EXPAND_STACK_PARM)
8361 target = gen_reg_rtx (mode);
8362 /* expand_float can't figure out what to do if FROM has VOIDmode.
8363 So give it the correct mode. With -O, cse will optimize this. */
8364 if (GET_MODE (op0) == VOIDmode)
8365 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
8366 op0);
8367 expand_float (target, op0,
8368 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
8369 return target;
8371 case NEGATE_EXPR:
8372 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8373 if (modifier == EXPAND_STACK_PARM)
8374 target = 0;
8375 temp = expand_unop (mode,
8376 optab_for_tree_code (NEGATE_EXPR, type),
8377 op0, target, 0);
8378 gcc_assert (temp);
8379 return REDUCE_BIT_FIELD (temp);
8381 case ABS_EXPR:
8382 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8383 if (modifier == EXPAND_STACK_PARM)
8384 target = 0;
8386 /* ABS_EXPR is not valid for complex arguments. */
8387 gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8388 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
8390 /* Unsigned abs is simply the operand. Testing here means we don't
8391 risk generating incorrect code below. */
8392 if (TYPE_UNSIGNED (type))
8393 return op0;
8395 return expand_abs (mode, op0, target, unsignedp,
8396 safe_from_p (target, TREE_OPERAND (exp, 0), 1));
8398 case MAX_EXPR:
8399 case MIN_EXPR:
8400 target = original_target;
8401 if (target == 0
8402 || modifier == EXPAND_STACK_PARM
8403 || (MEM_P (target) && MEM_VOLATILE_P (target))
8404 || GET_MODE (target) != mode
8405 || (REG_P (target)
8406 && REGNO (target) < FIRST_PSEUDO_REGISTER))
8407 target = gen_reg_rtx (mode);
8408 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8409 target, &op0, &op1, 0);
8411 /* First try to do it with a special MIN or MAX instruction.
8412 If that does not win, use a conditional jump to select the proper
8413 value. */
8414 this_optab = optab_for_tree_code (code, type);
8415 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8416 OPTAB_WIDEN);
8417 if (temp != 0)
8418 return temp;
8420 /* At this point, a MEM target is no longer useful; we will get better
8421 code without it. */
8423 if (! REG_P (target))
8424 target = gen_reg_rtx (mode);
8426 /* If op1 was placed in target, swap op0 and op1. */
8427 if (target != op0 && target == op1)
8429 temp = op0;
8430 op0 = op1;
8431 op1 = temp;
8434 /* We generate better code and avoid problems with op1 mentioning
8435 target by forcing op1 into a pseudo if it isn't a constant. */
8436 if (! CONSTANT_P (op1))
8437 op1 = force_reg (mode, op1);
8440 enum rtx_code comparison_code;
8441 rtx cmpop1 = op1;
8443 if (code == MAX_EXPR)
8444 comparison_code = unsignedp ? GEU : GE;
8445 else
8446 comparison_code = unsignedp ? LEU : LE;
8448 /* Canonicalize to comparisons against 0. */
8449 if (op1 == const1_rtx)
8451 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8452 or (a != 0 ? a : 1) for unsigned.
8453 For MIN we are safe converting (a <= 1 ? a : 1)
8454 into (a <= 0 ? a : 1) */
8455 cmpop1 = const0_rtx;
8456 if (code == MAX_EXPR)
8457 comparison_code = unsignedp ? NE : GT;
8459 if (op1 == constm1_rtx && !unsignedp)
8461 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8462 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8463 cmpop1 = const0_rtx;
8464 if (code == MIN_EXPR)
8465 comparison_code = LT;
8467 #ifdef HAVE_conditional_move
8468 /* Use a conditional move if possible. */
8469 if (can_conditionally_move_p (mode))
8471 rtx insn;
8473 /* ??? Same problem as in expmed.c: emit_conditional_move
8474 forces a stack adjustment via compare_from_rtx, and we
8475 lose the stack adjustment if the sequence we are about
8476 to create is discarded. */
8477 do_pending_stack_adjust ();
8479 start_sequence ();
8481 /* Try to emit the conditional move. */
8482 insn = emit_conditional_move (target, comparison_code,
8483 op0, cmpop1, mode,
8484 op0, op1, mode,
8485 unsignedp);
8487 /* If we could do the conditional move, emit the sequence,
8488 and return. */
8489 if (insn)
8491 rtx seq = get_insns ();
8492 end_sequence ();
8493 emit_insn (seq);
8494 return target;
8497 /* Otherwise discard the sequence and fall back to code with
8498 branches. */
8499 end_sequence ();
8501 #endif
8502 if (target != op0)
8503 emit_move_insn (target, op0);
8505 temp = gen_label_rtx ();
8506 do_compare_rtx_and_jump (target, cmpop1, comparison_code,
8507 unsignedp, mode, NULL_RTX, NULL_RTX, temp);
8509 emit_move_insn (target, op1);
8510 emit_label (temp);
8511 return target;
8513 case BIT_NOT_EXPR:
8514 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8515 if (modifier == EXPAND_STACK_PARM)
8516 target = 0;
8517 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
8518 gcc_assert (temp);
8519 return temp;
8521 /* ??? Can optimize bitwise operations with one arg constant.
8522 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8523 and (a bitwise1 b) bitwise2 b (etc)
8524 but that is probably not worth while. */
8526 /* BIT_AND_EXPR is for bitwise anding. TRUTH_AND_EXPR is for anding two
8527 boolean values when we want in all cases to compute both of them. In
8528 general it is fastest to do TRUTH_AND_EXPR by computing both operands
8529 as actual zero-or-1 values and then bitwise anding. In cases where
8530 there cannot be any side effects, better code would be made by
8531 treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR; but the question is
8532 how to recognize those cases. */
8534 case TRUTH_AND_EXPR:
8535 code = BIT_AND_EXPR;
8536 case BIT_AND_EXPR:
8537 goto binop;
8539 case TRUTH_OR_EXPR:
8540 code = BIT_IOR_EXPR;
8541 case BIT_IOR_EXPR:
8542 goto binop;
8544 case TRUTH_XOR_EXPR:
8545 code = BIT_XOR_EXPR;
8546 case BIT_XOR_EXPR:
8547 goto binop;
8549 case LSHIFT_EXPR:
8550 case RSHIFT_EXPR:
8551 case LROTATE_EXPR:
8552 case RROTATE_EXPR:
8553 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8554 subtarget = 0;
8555 if (modifier == EXPAND_STACK_PARM)
8556 target = 0;
8557 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8558 return expand_shift (code, mode, op0, TREE_OPERAND (exp, 1), target,
8559 unsignedp);
8561 /* Could determine the answer when only additive constants differ. Also,
8562 the addition of one can be handled by changing the condition. */
8563 case LT_EXPR:
8564 case LE_EXPR:
8565 case GT_EXPR:
8566 case GE_EXPR:
8567 case EQ_EXPR:
8568 case NE_EXPR:
8569 case UNORDERED_EXPR:
8570 case ORDERED_EXPR:
8571 case UNLT_EXPR:
8572 case UNLE_EXPR:
8573 case UNGT_EXPR:
8574 case UNGE_EXPR:
8575 case UNEQ_EXPR:
8576 case LTGT_EXPR:
8577 temp = do_store_flag (exp,
8578 modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
8579 tmode != VOIDmode ? tmode : mode, 0);
8580 if (temp != 0)
8581 return temp;
8583 /* For foo != 0, load foo, and if it is nonzero load 1 instead. */
8584 if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
8585 && original_target
8586 && REG_P (original_target)
8587 && (GET_MODE (original_target)
8588 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
8590 temp = expand_expr (TREE_OPERAND (exp, 0), original_target,
8591 VOIDmode, 0);
8593 /* If temp is constant, we can just compute the result. */
8594 if (GET_CODE (temp) == CONST_INT)
8596 if (INTVAL (temp) != 0)
8597 emit_move_insn (target, const1_rtx);
8598 else
8599 emit_move_insn (target, const0_rtx);
8601 return target;
8604 if (temp != original_target)
8606 enum machine_mode mode1 = GET_MODE (temp);
8607 if (mode1 == VOIDmode)
8608 mode1 = tmode != VOIDmode ? tmode : mode;
8610 temp = copy_to_mode_reg (mode1, temp);
8613 op1 = gen_label_rtx ();
8614 emit_cmp_and_jump_insns (temp, const0_rtx, EQ, NULL_RTX,
8615 GET_MODE (temp), unsignedp, op1);
8616 emit_move_insn (temp, const1_rtx);
8617 emit_label (op1);
8618 return temp;
8621 /* If no set-flag instruction, must generate a conditional store
8622 into a temporary variable. Drop through and handle this
8623 like && and ||. */
8625 if (! ignore
8626 && (target == 0
8627 || modifier == EXPAND_STACK_PARM
8628 || ! safe_from_p (target, exp, 1)
8629 /* Make sure we don't have a hard reg (such as function's return
8630 value) live across basic blocks, if not optimizing. */
8631 || (!optimize && REG_P (target)
8632 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
8633 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
8635 if (target)
8636 emit_move_insn (target, const0_rtx);
8638 op1 = gen_label_rtx ();
8639 jumpifnot (exp, op1);
8641 if (target)
8642 emit_move_insn (target, const1_rtx);
8644 emit_label (op1);
8645 return ignore ? const0_rtx : target;
8647 case TRUTH_NOT_EXPR:
8648 if (modifier == EXPAND_STACK_PARM)
8649 target = 0;
8650 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
8651 /* The parser is careful to generate TRUTH_NOT_EXPR
8652 only with operands that are always zero or one. */
8653 temp = expand_binop (mode, xor_optab, op0, const1_rtx,
8654 target, 1, OPTAB_LIB_WIDEN);
8655 gcc_assert (temp);
8656 return temp;
8658 case STATEMENT_LIST:
8660 tree_stmt_iterator iter;
8662 gcc_assert (ignore);
8664 for (iter = tsi_start (exp); !tsi_end_p (iter); tsi_next (&iter))
8665 expand_expr (tsi_stmt (iter), const0_rtx, VOIDmode, modifier);
8667 return const0_rtx;
8669 case COND_EXPR:
8670 /* A COND_EXPR with its type being VOID_TYPE represents a
8671 conditional jump and is handled in
8672 expand_gimple_cond_expr. */
8673 gcc_assert (!VOID_TYPE_P (TREE_TYPE (exp)));
8675 /* Note that COND_EXPRs whose type is a structure or union
8676 are required to be constructed to contain assignments of
8677 a temporary variable, so that we can evaluate them here
8678 for side effect only. If type is void, we must do likewise. */
8680 gcc_assert (!TREE_ADDRESSABLE (type)
8681 && !ignore
8682 && TREE_TYPE (TREE_OPERAND (exp, 1)) != void_type_node
8683 && TREE_TYPE (TREE_OPERAND (exp, 2)) != void_type_node);
8685 /* If we are not to produce a result, we have no target. Otherwise,
8686 if a target was specified use it; it will not be used as an
8687 intermediate target unless it is safe. If no target, use a
8688 temporary. */
8690 if (modifier != EXPAND_STACK_PARM
8691 && original_target
8692 && safe_from_p (original_target, TREE_OPERAND (exp, 0), 1)
8693 && GET_MODE (original_target) == mode
8694 #ifdef HAVE_conditional_move
8695 && (! can_conditionally_move_p (mode)
8696 || REG_P (original_target))
8697 #endif
8698 && !MEM_P (original_target))
8699 temp = original_target;
8700 else
8701 temp = assign_temp (type, 0, 0, 1);
8703 do_pending_stack_adjust ();
8704 NO_DEFER_POP;
8705 op0 = gen_label_rtx ();
8706 op1 = gen_label_rtx ();
8707 jumpifnot (TREE_OPERAND (exp, 0), op0);
8708 store_expr (TREE_OPERAND (exp, 1), temp,
8709 modifier == EXPAND_STACK_PARM);
8711 emit_jump_insn (gen_jump (op1));
8712 emit_barrier ();
8713 emit_label (op0);
8714 store_expr (TREE_OPERAND (exp, 2), temp,
8715 modifier == EXPAND_STACK_PARM);
8717 emit_label (op1);
8718 OK_DEFER_POP;
8719 return temp;
8721 case VEC_COND_EXPR:
8722 target = expand_vec_cond_expr (exp, target);
8723 return target;
8725 case MODIFY_EXPR:
8727 tree lhs = TREE_OPERAND (exp, 0);
8728 tree rhs = TREE_OPERAND (exp, 1);
8729 gcc_assert (ignore);
8730 expand_assignment (lhs, rhs);
8731 return const0_rtx;
8734 case GIMPLE_MODIFY_STMT:
8736 tree lhs = GIMPLE_STMT_OPERAND (exp, 0);
8737 tree rhs = GIMPLE_STMT_OPERAND (exp, 1);
8739 gcc_assert (ignore);
8741 /* Check for |= or &= of a bitfield of size one into another bitfield
8742 of size 1. In this case, (unless we need the result of the
8743 assignment) we can do this more efficiently with a
8744 test followed by an assignment, if necessary.
8746 ??? At this point, we can't get a BIT_FIELD_REF here. But if
8747 things change so we do, this code should be enhanced to
8748 support it. */
8749 if (TREE_CODE (lhs) == COMPONENT_REF
8750 && (TREE_CODE (rhs) == BIT_IOR_EXPR
8751 || TREE_CODE (rhs) == BIT_AND_EXPR)
8752 && TREE_OPERAND (rhs, 0) == lhs
8753 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
8754 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
8755 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
8757 rtx label = gen_label_rtx ();
8758 int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
8759 do_jump (TREE_OPERAND (rhs, 1),
8760 value ? label : 0,
8761 value ? 0 : label);
8762 expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value));
8763 do_pending_stack_adjust ();
8764 emit_label (label);
8765 return const0_rtx;
8768 expand_assignment (lhs, rhs);
8769 return const0_rtx;
8772 case RETURN_EXPR:
8773 if (!TREE_OPERAND (exp, 0))
8774 expand_null_return ();
8775 else
8776 expand_return (TREE_OPERAND (exp, 0));
8777 return const0_rtx;
8779 case ADDR_EXPR:
8780 return expand_expr_addr_expr (exp, target, tmode, modifier);
8782 case COMPLEX_EXPR:
8783 /* Get the rtx code of the operands. */
8784 op0 = expand_normal (TREE_OPERAND (exp, 0));
8785 op1 = expand_normal (TREE_OPERAND (exp, 1));
8787 if (!target)
8788 target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
8790 /* Move the real (op0) and imaginary (op1) parts to their location. */
8791 write_complex_part (target, op0, false);
8792 write_complex_part (target, op1, true);
8794 return target;
8796 case REALPART_EXPR:
8797 op0 = expand_normal (TREE_OPERAND (exp, 0));
8798 return read_complex_part (op0, false);
8800 case IMAGPART_EXPR:
8801 op0 = expand_normal (TREE_OPERAND (exp, 0));
8802 return read_complex_part (op0, true);
8804 case RESX_EXPR:
8805 expand_resx_expr (exp);
8806 return const0_rtx;
8808 case TRY_CATCH_EXPR:
8809 case CATCH_EXPR:
8810 case EH_FILTER_EXPR:
8811 case TRY_FINALLY_EXPR:
8812 /* Lowered by tree-eh.c. */
8813 gcc_unreachable ();
8815 case WITH_CLEANUP_EXPR:
8816 case CLEANUP_POINT_EXPR:
8817 case TARGET_EXPR:
8818 case CASE_LABEL_EXPR:
8819 case VA_ARG_EXPR:
8820 case BIND_EXPR:
8821 case INIT_EXPR:
8822 case CONJ_EXPR:
8823 case COMPOUND_EXPR:
8824 case PREINCREMENT_EXPR:
8825 case PREDECREMENT_EXPR:
8826 case POSTINCREMENT_EXPR:
8827 case POSTDECREMENT_EXPR:
8828 case LOOP_EXPR:
8829 case EXIT_EXPR:
8830 case TRUTH_ANDIF_EXPR:
8831 case TRUTH_ORIF_EXPR:
8832 /* Lowered by gimplify.c. */
8833 gcc_unreachable ();
8835 case EXC_PTR_EXPR:
8836 return get_exception_pointer (cfun);
8838 case FILTER_EXPR:
8839 return get_exception_filter (cfun);
8841 case FDESC_EXPR:
8842 /* Function descriptors are not valid except for as
8843 initialization constants, and should not be expanded. */
8844 gcc_unreachable ();
8846 case SWITCH_EXPR:
8847 expand_case (exp);
8848 return const0_rtx;
8850 case LABEL_EXPR:
8851 expand_label (TREE_OPERAND (exp, 0));
8852 return const0_rtx;
8854 case ASM_EXPR:
8855 expand_asm_expr (exp);
8856 return const0_rtx;
8858 case WITH_SIZE_EXPR:
8859 /* WITH_SIZE_EXPR expands to its first argument. The caller should
8860 have pulled out the size to use in whatever context it needed. */
8861 return expand_expr_real (TREE_OPERAND (exp, 0), original_target, tmode,
8862 modifier, alt_rtl);
8864 case REALIGN_LOAD_EXPR:
8866 tree oprnd0 = TREE_OPERAND (exp, 0);
8867 tree oprnd1 = TREE_OPERAND (exp, 1);
8868 tree oprnd2 = TREE_OPERAND (exp, 2);
8869 rtx op2;
8871 this_optab = optab_for_tree_code (code, type);
8872 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8873 op2 = expand_normal (oprnd2);
8874 temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
8875 target, unsignedp);
8876 gcc_assert (temp);
8877 return temp;
8880 case DOT_PROD_EXPR:
8882 tree oprnd0 = TREE_OPERAND (exp, 0);
8883 tree oprnd1 = TREE_OPERAND (exp, 1);
8884 tree oprnd2 = TREE_OPERAND (exp, 2);
8885 rtx op2;
8887 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8888 op2 = expand_normal (oprnd2);
8889 target = expand_widen_pattern_expr (exp, op0, op1, op2,
8890 target, unsignedp);
8891 return target;
8894 case WIDEN_SUM_EXPR:
8896 tree oprnd0 = TREE_OPERAND (exp, 0);
8897 tree oprnd1 = TREE_OPERAND (exp, 1);
8899 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, 0);
8900 target = expand_widen_pattern_expr (exp, op0, NULL_RTX, op1,
8901 target, unsignedp);
8902 return target;
8905 case REDUC_MAX_EXPR:
8906 case REDUC_MIN_EXPR:
8907 case REDUC_PLUS_EXPR:
8909 op0 = expand_normal (TREE_OPERAND (exp, 0));
8910 this_optab = optab_for_tree_code (code, type);
8911 temp = expand_unop (mode, this_optab, op0, target, unsignedp);
8912 gcc_assert (temp);
8913 return temp;
8916 case VEC_EXTRACT_EVEN_EXPR:
8917 case VEC_EXTRACT_ODD_EXPR:
8919 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8920 NULL_RTX, &op0, &op1, 0);
8921 this_optab = optab_for_tree_code (code, type);
8922 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8923 OPTAB_WIDEN);
8924 gcc_assert (temp);
8925 return temp;
8928 case VEC_INTERLEAVE_HIGH_EXPR:
8929 case VEC_INTERLEAVE_LOW_EXPR:
8931 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8932 NULL_RTX, &op0, &op1, 0);
8933 this_optab = optab_for_tree_code (code, type);
8934 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8935 OPTAB_WIDEN);
8936 gcc_assert (temp);
8937 return temp;
8940 case VEC_LSHIFT_EXPR:
8941 case VEC_RSHIFT_EXPR:
8943 target = expand_vec_shift_expr (exp, target);
8944 return target;
8947 case VEC_UNPACK_HI_EXPR:
8948 case VEC_UNPACK_LO_EXPR:
8950 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
8951 this_optab = optab_for_tree_code (code, type);
8952 temp = expand_widen_pattern_expr (exp, op0, NULL_RTX, NULL_RTX,
8953 target, unsignedp);
8954 gcc_assert (temp);
8955 return temp;
8958 case VEC_WIDEN_MULT_HI_EXPR:
8959 case VEC_WIDEN_MULT_LO_EXPR:
8961 tree oprnd0 = TREE_OPERAND (exp, 0);
8962 tree oprnd1 = TREE_OPERAND (exp, 1);
8964 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, 0);
8965 target = expand_widen_pattern_expr (exp, op0, op1, NULL_RTX,
8966 target, unsignedp);
8967 gcc_assert (target);
8968 return target;
8971 case VEC_PACK_TRUNC_EXPR:
8972 case VEC_PACK_SAT_EXPR:
8974 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
8975 goto binop;
8978 default:
8979 return lang_hooks.expand_expr (exp, original_target, tmode,
8980 modifier, alt_rtl);
8983 /* Here to do an ordinary binary operator. */
8984 binop:
8985 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8986 subtarget, &op0, &op1, 0);
8987 binop2:
8988 this_optab = optab_for_tree_code (code, type);
8989 binop3:
8990 if (modifier == EXPAND_STACK_PARM)
8991 target = 0;
8992 temp = expand_binop (mode, this_optab, op0, op1, target,
8993 unsignedp, OPTAB_LIB_WIDEN);
8994 gcc_assert (temp);
8995 return REDUCE_BIT_FIELD (temp);
8997 #undef REDUCE_BIT_FIELD
8999 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
9000 signedness of TYPE), possibly returning the result in TARGET. */
9001 static rtx
9002 reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
9004 HOST_WIDE_INT prec = TYPE_PRECISION (type);
9005 if (target && GET_MODE (target) != GET_MODE (exp))
9006 target = 0;
9007 /* For constant values, reduce using build_int_cst_type. */
9008 if (GET_CODE (exp) == CONST_INT)
9010 HOST_WIDE_INT value = INTVAL (exp);
9011 tree t = build_int_cst_type (type, value);
9012 return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
9014 else if (TYPE_UNSIGNED (type))
9016 rtx mask;
9017 if (prec < HOST_BITS_PER_WIDE_INT)
9018 mask = immed_double_const (((unsigned HOST_WIDE_INT) 1 << prec) - 1, 0,
9019 GET_MODE (exp));
9020 else
9021 mask = immed_double_const ((unsigned HOST_WIDE_INT) -1,
9022 ((unsigned HOST_WIDE_INT) 1
9023 << (prec - HOST_BITS_PER_WIDE_INT)) - 1,
9024 GET_MODE (exp));
9025 return expand_and (GET_MODE (exp), exp, mask, target);
9027 else
9029 tree count = build_int_cst (NULL_TREE,
9030 GET_MODE_BITSIZE (GET_MODE (exp)) - prec);
9031 exp = expand_shift (LSHIFT_EXPR, GET_MODE (exp), exp, count, target, 0);
9032 return expand_shift (RSHIFT_EXPR, GET_MODE (exp), exp, count, target, 0);
9036 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
9037 when applied to the address of EXP produces an address known to be
9038 aligned more than BIGGEST_ALIGNMENT. */
9040 static int
9041 is_aligning_offset (tree offset, tree exp)
9043 /* Strip off any conversions. */
9044 while (TREE_CODE (offset) == NON_LVALUE_EXPR
9045 || TREE_CODE (offset) == NOP_EXPR
9046 || TREE_CODE (offset) == CONVERT_EXPR)
9047 offset = TREE_OPERAND (offset, 0);
9049 /* We must now have a BIT_AND_EXPR with a constant that is one less than
9050 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
9051 if (TREE_CODE (offset) != BIT_AND_EXPR
9052 || !host_integerp (TREE_OPERAND (offset, 1), 1)
9053 || compare_tree_int (TREE_OPERAND (offset, 1),
9054 BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
9055 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
9056 return 0;
9058 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
9059 It must be NEGATE_EXPR. Then strip any more conversions. */
9060 offset = TREE_OPERAND (offset, 0);
9061 while (TREE_CODE (offset) == NON_LVALUE_EXPR
9062 || TREE_CODE (offset) == NOP_EXPR
9063 || TREE_CODE (offset) == CONVERT_EXPR)
9064 offset = TREE_OPERAND (offset, 0);
9066 if (TREE_CODE (offset) != NEGATE_EXPR)
9067 return 0;
9069 offset = TREE_OPERAND (offset, 0);
9070 while (TREE_CODE (offset) == NON_LVALUE_EXPR
9071 || TREE_CODE (offset) == NOP_EXPR
9072 || TREE_CODE (offset) == CONVERT_EXPR)
9073 offset = TREE_OPERAND (offset, 0);
9075 /* This must now be the address of EXP. */
9076 return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
9079 /* Return the tree node if an ARG corresponds to a string constant or zero
9080 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
9081 in bytes within the string that ARG is accessing. The type of the
9082 offset will be `sizetype'. */
9084 tree
9085 string_constant (tree arg, tree *ptr_offset)
9087 tree array, offset, lower_bound;
9088 STRIP_NOPS (arg);
9090 if (TREE_CODE (arg) == ADDR_EXPR)
9092 if (TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
9094 *ptr_offset = size_zero_node;
9095 return TREE_OPERAND (arg, 0);
9097 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL)
9099 array = TREE_OPERAND (arg, 0);
9100 offset = size_zero_node;
9102 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF)
9104 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
9105 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
9106 if (TREE_CODE (array) != STRING_CST
9107 && TREE_CODE (array) != VAR_DECL)
9108 return 0;
9110 /* Check if the array has a nonzero lower bound. */
9111 lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
9112 if (!integer_zerop (lower_bound))
9114 /* If the offset and base aren't both constants, return 0. */
9115 if (TREE_CODE (lower_bound) != INTEGER_CST)
9116 return 0;
9117 if (TREE_CODE (offset) != INTEGER_CST)
9118 return 0;
9119 /* Adjust offset by the lower bound. */
9120 offset = size_diffop (fold_convert (sizetype, offset),
9121 fold_convert (sizetype, lower_bound));
9124 else
9125 return 0;
9127 else if (TREE_CODE (arg) == PLUS_EXPR)
9129 tree arg0 = TREE_OPERAND (arg, 0);
9130 tree arg1 = TREE_OPERAND (arg, 1);
9132 STRIP_NOPS (arg0);
9133 STRIP_NOPS (arg1);
9135 if (TREE_CODE (arg0) == ADDR_EXPR
9136 && (TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST
9137 || TREE_CODE (TREE_OPERAND (arg0, 0)) == VAR_DECL))
9139 array = TREE_OPERAND (arg0, 0);
9140 offset = arg1;
9142 else if (TREE_CODE (arg1) == ADDR_EXPR
9143 && (TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST
9144 || TREE_CODE (TREE_OPERAND (arg1, 0)) == VAR_DECL))
9146 array = TREE_OPERAND (arg1, 0);
9147 offset = arg0;
9149 else
9150 return 0;
9152 else
9153 return 0;
9155 if (TREE_CODE (array) == STRING_CST)
9157 *ptr_offset = fold_convert (sizetype, offset);
9158 return array;
9160 else if (TREE_CODE (array) == VAR_DECL)
9162 int length;
9164 /* Variables initialized to string literals can be handled too. */
9165 if (DECL_INITIAL (array) == NULL_TREE
9166 || TREE_CODE (DECL_INITIAL (array)) != STRING_CST)
9167 return 0;
9169 /* If they are read-only, non-volatile and bind locally. */
9170 if (! TREE_READONLY (array)
9171 || TREE_SIDE_EFFECTS (array)
9172 || ! targetm.binds_local_p (array))
9173 return 0;
9175 /* Avoid const char foo[4] = "abcde"; */
9176 if (DECL_SIZE_UNIT (array) == NULL_TREE
9177 || TREE_CODE (DECL_SIZE_UNIT (array)) != INTEGER_CST
9178 || (length = TREE_STRING_LENGTH (DECL_INITIAL (array))) <= 0
9179 || compare_tree_int (DECL_SIZE_UNIT (array), length) < 0)
9180 return 0;
9182 /* If variable is bigger than the string literal, OFFSET must be constant
9183 and inside of the bounds of the string literal. */
9184 offset = fold_convert (sizetype, offset);
9185 if (compare_tree_int (DECL_SIZE_UNIT (array), length) > 0
9186 && (! host_integerp (offset, 1)
9187 || compare_tree_int (offset, length) >= 0))
9188 return 0;
9190 *ptr_offset = offset;
9191 return DECL_INITIAL (array);
9194 return 0;
9197 /* Generate code to calculate EXP using a store-flag instruction
9198 and return an rtx for the result. EXP is either a comparison
9199 or a TRUTH_NOT_EXPR whose operand is a comparison.
9201 If TARGET is nonzero, store the result there if convenient.
9203 If ONLY_CHEAP is nonzero, only do this if it is likely to be very
9204 cheap.
9206 Return zero if there is no suitable set-flag instruction
9207 available on this machine.
9209 Once expand_expr has been called on the arguments of the comparison,
9210 we are committed to doing the store flag, since it is not safe to
9211 re-evaluate the expression. We emit the store-flag insn by calling
9212 emit_store_flag, but only expand the arguments if we have a reason
9213 to believe that emit_store_flag will be successful. If we think that
9214 it will, but it isn't, we have to simulate the store-flag with a
9215 set/jump/set sequence. */
9217 static rtx
9218 do_store_flag (tree exp, rtx target, enum machine_mode mode, int only_cheap)
9220 enum rtx_code code;
9221 tree arg0, arg1, type;
9222 tree tem;
9223 enum machine_mode operand_mode;
9224 int invert = 0;
9225 int unsignedp;
9226 rtx op0, op1;
9227 enum insn_code icode;
9228 rtx subtarget = target;
9229 rtx result, label;
9231 /* If this is a TRUTH_NOT_EXPR, set a flag indicating we must invert the
9232 result at the end. We can't simply invert the test since it would
9233 have already been inverted if it were valid. This case occurs for
9234 some floating-point comparisons. */
9236 if (TREE_CODE (exp) == TRUTH_NOT_EXPR)
9237 invert = 1, exp = TREE_OPERAND (exp, 0);
9239 arg0 = TREE_OPERAND (exp, 0);
9240 arg1 = TREE_OPERAND (exp, 1);
9242 /* Don't crash if the comparison was erroneous. */
9243 if (arg0 == error_mark_node || arg1 == error_mark_node)
9244 return const0_rtx;
9246 type = TREE_TYPE (arg0);
9247 operand_mode = TYPE_MODE (type);
9248 unsignedp = TYPE_UNSIGNED (type);
9250 /* We won't bother with BLKmode store-flag operations because it would mean
9251 passing a lot of information to emit_store_flag. */
9252 if (operand_mode == BLKmode)
9253 return 0;
9255 /* We won't bother with store-flag operations involving function pointers
9256 when function pointers must be canonicalized before comparisons. */
9257 #ifdef HAVE_canonicalize_funcptr_for_compare
9258 if (HAVE_canonicalize_funcptr_for_compare
9259 && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
9260 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
9261 == FUNCTION_TYPE))
9262 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
9263 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
9264 == FUNCTION_TYPE))))
9265 return 0;
9266 #endif
9268 STRIP_NOPS (arg0);
9269 STRIP_NOPS (arg1);
9271 /* Get the rtx comparison code to use. We know that EXP is a comparison
9272 operation of some type. Some comparisons against 1 and -1 can be
9273 converted to comparisons with zero. Do so here so that the tests
9274 below will be aware that we have a comparison with zero. These
9275 tests will not catch constants in the first operand, but constants
9276 are rarely passed as the first operand. */
9278 switch (TREE_CODE (exp))
9280 case EQ_EXPR:
9281 code = EQ;
9282 break;
9283 case NE_EXPR:
9284 code = NE;
9285 break;
9286 case LT_EXPR:
9287 if (integer_onep (arg1))
9288 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
9289 else
9290 code = unsignedp ? LTU : LT;
9291 break;
9292 case LE_EXPR:
9293 if (! unsignedp && integer_all_onesp (arg1))
9294 arg1 = integer_zero_node, code = LT;
9295 else
9296 code = unsignedp ? LEU : LE;
9297 break;
9298 case GT_EXPR:
9299 if (! unsignedp && integer_all_onesp (arg1))
9300 arg1 = integer_zero_node, code = GE;
9301 else
9302 code = unsignedp ? GTU : GT;
9303 break;
9304 case GE_EXPR:
9305 if (integer_onep (arg1))
9306 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
9307 else
9308 code = unsignedp ? GEU : GE;
9309 break;
9311 case UNORDERED_EXPR:
9312 code = UNORDERED;
9313 break;
9314 case ORDERED_EXPR:
9315 code = ORDERED;
9316 break;
9317 case UNLT_EXPR:
9318 code = UNLT;
9319 break;
9320 case UNLE_EXPR:
9321 code = UNLE;
9322 break;
9323 case UNGT_EXPR:
9324 code = UNGT;
9325 break;
9326 case UNGE_EXPR:
9327 code = UNGE;
9328 break;
9329 case UNEQ_EXPR:
9330 code = UNEQ;
9331 break;
9332 case LTGT_EXPR:
9333 code = LTGT;
9334 break;
9336 default:
9337 gcc_unreachable ();
9340 /* Put a constant second. */
9341 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST)
9343 tem = arg0; arg0 = arg1; arg1 = tem;
9344 code = swap_condition (code);
9347 /* If this is an equality or inequality test of a single bit, we can
9348 do this by shifting the bit being tested to the low-order bit and
9349 masking the result with the constant 1. If the condition was EQ,
9350 we xor it with 1. This does not require an scc insn and is faster
9351 than an scc insn even if we have it.
9353 The code to make this transformation was moved into fold_single_bit_test,
9354 so we just call into the folder and expand its result. */
9356 if ((code == NE || code == EQ)
9357 && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
9358 && integer_pow2p (TREE_OPERAND (arg0, 1)))
9360 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
9361 return expand_expr (fold_single_bit_test (code == NE ? NE_EXPR : EQ_EXPR,
9362 arg0, arg1, type),
9363 target, VOIDmode, EXPAND_NORMAL);
9366 /* Now see if we are likely to be able to do this. Return if not. */
9367 if (! can_compare_p (code, operand_mode, ccp_store_flag))
9368 return 0;
9370 icode = setcc_gen_code[(int) code];
9372 if (icode == CODE_FOR_nothing)
9374 enum machine_mode wmode;
9376 for (wmode = operand_mode;
9377 icode == CODE_FOR_nothing && wmode != VOIDmode;
9378 wmode = GET_MODE_WIDER_MODE (wmode))
9379 icode = cstore_optab->handlers[(int) wmode].insn_code;
9382 if (icode == CODE_FOR_nothing
9383 || (only_cheap && insn_data[(int) icode].operand[0].mode != mode))
9385 /* We can only do this if it is one of the special cases that
9386 can be handled without an scc insn. */
9387 if ((code == LT && integer_zerop (arg1))
9388 || (! only_cheap && code == GE && integer_zerop (arg1)))
9390 else if (! only_cheap && (code == NE || code == EQ)
9391 && TREE_CODE (type) != REAL_TYPE
9392 && ((abs_optab->handlers[(int) operand_mode].insn_code
9393 != CODE_FOR_nothing)
9394 || (ffs_optab->handlers[(int) operand_mode].insn_code
9395 != CODE_FOR_nothing)))
9397 else
9398 return 0;
9401 if (! get_subtarget (target)
9402 || GET_MODE (subtarget) != operand_mode)
9403 subtarget = 0;
9405 expand_operands (arg0, arg1, subtarget, &op0, &op1, 0);
9407 if (target == 0)
9408 target = gen_reg_rtx (mode);
9410 result = emit_store_flag (target, code, op0, op1,
9411 operand_mode, unsignedp, 1);
9413 if (result)
9415 if (invert)
9416 result = expand_binop (mode, xor_optab, result, const1_rtx,
9417 result, 0, OPTAB_LIB_WIDEN);
9418 return result;
9421 /* If this failed, we have to do this with set/compare/jump/set code. */
9422 if (!REG_P (target)
9423 || reg_mentioned_p (target, op0) || reg_mentioned_p (target, op1))
9424 target = gen_reg_rtx (GET_MODE (target));
9426 emit_move_insn (target, invert ? const0_rtx : const1_rtx);
9427 label = gen_label_rtx ();
9428 do_compare_rtx_and_jump (op0, op1, code, unsignedp, operand_mode, NULL_RTX,
9429 NULL_RTX, label);
9431 emit_move_insn (target, invert ? const1_rtx : const0_rtx);
9432 emit_label (label);
9434 return target;
9438 /* Stubs in case we haven't got a casesi insn. */
9439 #ifndef HAVE_casesi
9440 # define HAVE_casesi 0
9441 # define gen_casesi(a, b, c, d, e) (0)
9442 # define CODE_FOR_casesi CODE_FOR_nothing
9443 #endif
9445 /* If the machine does not have a case insn that compares the bounds,
9446 this means extra overhead for dispatch tables, which raises the
9447 threshold for using them. */
9448 #ifndef CASE_VALUES_THRESHOLD
9449 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
9450 #endif /* CASE_VALUES_THRESHOLD */
9452 unsigned int
9453 case_values_threshold (void)
9455 return CASE_VALUES_THRESHOLD;
9458 /* Attempt to generate a casesi instruction. Returns 1 if successful,
9459 0 otherwise (i.e. if there is no casesi instruction). */
9461 try_casesi (tree index_type, tree index_expr, tree minval, tree range,
9462 rtx table_label ATTRIBUTE_UNUSED, rtx default_label)
9464 enum machine_mode index_mode = SImode;
9465 int index_bits = GET_MODE_BITSIZE (index_mode);
9466 rtx op1, op2, index;
9467 enum machine_mode op_mode;
9469 if (! HAVE_casesi)
9470 return 0;
9472 /* Convert the index to SImode. */
9473 if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
9475 enum machine_mode omode = TYPE_MODE (index_type);
9476 rtx rangertx = expand_normal (range);
9478 /* We must handle the endpoints in the original mode. */
9479 index_expr = build2 (MINUS_EXPR, index_type,
9480 index_expr, minval);
9481 minval = integer_zero_node;
9482 index = expand_normal (index_expr);
9483 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
9484 omode, 1, default_label);
9485 /* Now we can safely truncate. */
9486 index = convert_to_mode (index_mode, index, 0);
9488 else
9490 if (TYPE_MODE (index_type) != index_mode)
9492 index_type = lang_hooks.types.type_for_size (index_bits, 0);
9493 index_expr = fold_convert (index_type, index_expr);
9496 index = expand_normal (index_expr);
9499 do_pending_stack_adjust ();
9501 op_mode = insn_data[(int) CODE_FOR_casesi].operand[0].mode;
9502 if (! (*insn_data[(int) CODE_FOR_casesi].operand[0].predicate)
9503 (index, op_mode))
9504 index = copy_to_mode_reg (op_mode, index);
9506 op1 = expand_normal (minval);
9508 op_mode = insn_data[(int) CODE_FOR_casesi].operand[1].mode;
9509 op1 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (minval)),
9510 op1, TYPE_UNSIGNED (TREE_TYPE (minval)));
9511 if (! (*insn_data[(int) CODE_FOR_casesi].operand[1].predicate)
9512 (op1, op_mode))
9513 op1 = copy_to_mode_reg (op_mode, op1);
9515 op2 = expand_normal (range);
9517 op_mode = insn_data[(int) CODE_FOR_casesi].operand[2].mode;
9518 op2 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (range)),
9519 op2, TYPE_UNSIGNED (TREE_TYPE (range)));
9520 if (! (*insn_data[(int) CODE_FOR_casesi].operand[2].predicate)
9521 (op2, op_mode))
9522 op2 = copy_to_mode_reg (op_mode, op2);
9524 emit_jump_insn (gen_casesi (index, op1, op2,
9525 table_label, default_label));
9526 return 1;
9529 /* Attempt to generate a tablejump instruction; same concept. */
9530 #ifndef HAVE_tablejump
9531 #define HAVE_tablejump 0
9532 #define gen_tablejump(x, y) (0)
9533 #endif
9535 /* Subroutine of the next function.
9537 INDEX is the value being switched on, with the lowest value
9538 in the table already subtracted.
9539 MODE is its expected mode (needed if INDEX is constant).
9540 RANGE is the length of the jump table.
9541 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
9543 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
9544 index value is out of range. */
9546 static void
9547 do_tablejump (rtx index, enum machine_mode mode, rtx range, rtx table_label,
9548 rtx default_label)
9550 rtx temp, vector;
9552 if (INTVAL (range) > cfun->max_jumptable_ents)
9553 cfun->max_jumptable_ents = INTVAL (range);
9555 /* Do an unsigned comparison (in the proper mode) between the index
9556 expression and the value which represents the length of the range.
9557 Since we just finished subtracting the lower bound of the range
9558 from the index expression, this comparison allows us to simultaneously
9559 check that the original index expression value is both greater than
9560 or equal to the minimum value of the range and less than or equal to
9561 the maximum value of the range. */
9563 emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
9564 default_label);
9566 /* If index is in range, it must fit in Pmode.
9567 Convert to Pmode so we can index with it. */
9568 if (mode != Pmode)
9569 index = convert_to_mode (Pmode, index, 1);
9571 /* Don't let a MEM slip through, because then INDEX that comes
9572 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
9573 and break_out_memory_refs will go to work on it and mess it up. */
9574 #ifdef PIC_CASE_VECTOR_ADDRESS
9575 if (flag_pic && !REG_P (index))
9576 index = copy_to_mode_reg (Pmode, index);
9577 #endif
9579 /* If flag_force_addr were to affect this address
9580 it could interfere with the tricky assumptions made
9581 about addresses that contain label-refs,
9582 which may be valid only very near the tablejump itself. */
9583 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
9584 GET_MODE_SIZE, because this indicates how large insns are. The other
9585 uses should all be Pmode, because they are addresses. This code
9586 could fail if addresses and insns are not the same size. */
9587 index = gen_rtx_PLUS (Pmode,
9588 gen_rtx_MULT (Pmode, index,
9589 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))),
9590 gen_rtx_LABEL_REF (Pmode, table_label));
9591 #ifdef PIC_CASE_VECTOR_ADDRESS
9592 if (flag_pic)
9593 index = PIC_CASE_VECTOR_ADDRESS (index);
9594 else
9595 #endif
9596 index = memory_address_noforce (CASE_VECTOR_MODE, index);
9597 temp = gen_reg_rtx (CASE_VECTOR_MODE);
9598 vector = gen_const_mem (CASE_VECTOR_MODE, index);
9599 convert_move (temp, vector, 0);
9601 emit_jump_insn (gen_tablejump (temp, table_label));
9603 /* If we are generating PIC code or if the table is PC-relative, the
9604 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
9605 if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
9606 emit_barrier ();
9610 try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
9611 rtx table_label, rtx default_label)
9613 rtx index;
9615 if (! HAVE_tablejump)
9616 return 0;
9618 index_expr = fold_build2 (MINUS_EXPR, index_type,
9619 fold_convert (index_type, index_expr),
9620 fold_convert (index_type, minval));
9621 index = expand_normal (index_expr);
9622 do_pending_stack_adjust ();
9624 do_tablejump (index, TYPE_MODE (index_type),
9625 convert_modes (TYPE_MODE (index_type),
9626 TYPE_MODE (TREE_TYPE (range)),
9627 expand_normal (range),
9628 TYPE_UNSIGNED (TREE_TYPE (range))),
9629 table_label, default_label);
9630 return 1;
9633 /* Nonzero if the mode is a valid vector mode for this architecture.
9634 This returns nonzero even if there is no hardware support for the
9635 vector mode, but we can emulate with narrower modes. */
9638 vector_mode_valid_p (enum machine_mode mode)
9640 enum mode_class class = GET_MODE_CLASS (mode);
9641 enum machine_mode innermode;
9643 /* Doh! What's going on? */
9644 if (class != MODE_VECTOR_INT
9645 && class != MODE_VECTOR_FLOAT)
9646 return 0;
9648 /* Hardware support. Woo hoo! */
9649 if (targetm.vector_mode_supported_p (mode))
9650 return 1;
9652 innermode = GET_MODE_INNER (mode);
9654 /* We should probably return 1 if requesting V4DI and we have no DI,
9655 but we have V2DI, but this is probably very unlikely. */
9657 /* If we have support for the inner mode, we can safely emulate it.
9658 We may not have V2DI, but me can emulate with a pair of DIs. */
9659 return targetm.scalar_mode_supported_p (innermode);
9662 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
9663 static rtx
9664 const_vector_from_tree (tree exp)
9666 rtvec v;
9667 int units, i;
9668 tree link, elt;
9669 enum machine_mode inner, mode;
9671 mode = TYPE_MODE (TREE_TYPE (exp));
9673 if (initializer_zerop (exp))
9674 return CONST0_RTX (mode);
9676 units = GET_MODE_NUNITS (mode);
9677 inner = GET_MODE_INNER (mode);
9679 v = rtvec_alloc (units);
9681 link = TREE_VECTOR_CST_ELTS (exp);
9682 for (i = 0; link; link = TREE_CHAIN (link), ++i)
9684 elt = TREE_VALUE (link);
9686 if (TREE_CODE (elt) == REAL_CST)
9687 RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
9688 inner);
9689 else
9690 RTVEC_ELT (v, i) = immed_double_const (TREE_INT_CST_LOW (elt),
9691 TREE_INT_CST_HIGH (elt),
9692 inner);
9695 /* Initialize remaining elements to 0. */
9696 for (; i < units; ++i)
9697 RTVEC_ELT (v, i) = CONST0_RTX (inner);
9699 return gen_rtx_CONST_VECTOR (mode, v);
9701 #include "gt-expr.h"