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