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