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