1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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/>. */
22 #include "coretypes.h"
38 #include "diagnostic.h"
40 #include "fold-const.h"
41 #include "stor-layout.h"
45 #include "insn-attr.h"
50 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
52 #include "optabs-tree.h"
55 #include "langhooks.h"
56 #include "common/common-target.h"
57 #include "tree-ssa-live.h"
58 #include "tree-outof-ssa.h"
59 #include "tree-ssa-address.h"
61 #include "tree-chkp.h"
66 /* If this is nonzero, we do not bother generating VOLATILE
67 around volatile memory references, and we are willing to
68 output indirect addresses. If cse is to follow, we reject
69 indirect addresses so a useful potential cse is generated;
70 if it is used only once, instruction combination will produce
71 the same indirect address eventually. */
74 static bool block_move_libcall_safe_for_call_parm (void);
75 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
76 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
77 unsigned HOST_WIDE_INT
);
78 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
79 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
80 static rtx_insn
*compress_float_constant (rtx
, rtx
);
81 static rtx
get_subtarget (rtx
);
82 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
83 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
84 unsigned HOST_WIDE_INT
, machine_mode
,
85 tree
, int, alias_set_type
, bool);
86 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
, bool);
87 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
88 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
89 machine_mode
, tree
, alias_set_type
, bool, bool);
91 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
93 static int is_aligning_offset (const_tree
, const_tree
);
94 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
95 static rtx
do_store_flag (sepops
, rtx
, machine_mode
);
97 static void emit_single_push_insn (machine_mode
, rtx
, tree
);
99 static void do_tablejump (rtx
, machine_mode
, rtx
, rtx
, rtx
, int);
100 static rtx
const_vector_from_tree (tree
);
101 static rtx
const_scalar_mask_from_tree (tree
);
102 static tree
tree_expr_size (const_tree
);
103 static HOST_WIDE_INT
int_expr_size (tree
);
106 /* This is run to set up which modes can be used
107 directly in memory and to initialize the block move optab. It is run
108 at the beginning of compilation and when the target is reinitialized. */
111 init_expr_target (void)
119 /* Try indexing by frame ptr and try by stack ptr.
120 It is known that on the Convex the stack ptr isn't a valid index.
121 With luck, one or the other is valid on any machine. */
122 mem
= gen_rtx_MEM (word_mode
, stack_pointer_rtx
);
123 mem1
= gen_rtx_MEM (word_mode
, frame_pointer_rtx
);
125 /* A scratch register we can modify in-place below to avoid
126 useless RTL allocations. */
127 reg
= gen_rtx_REG (word_mode
, LAST_VIRTUAL_REGISTER
+ 1);
129 rtx_insn
*insn
= as_a
<rtx_insn
*> (rtx_alloc (INSN
));
130 pat
= gen_rtx_SET (NULL_RTX
, NULL_RTX
);
131 PATTERN (insn
) = pat
;
133 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
134 mode
= (machine_mode
) ((int) mode
+ 1))
138 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
139 PUT_MODE (mem
, mode
);
140 PUT_MODE (mem1
, mode
);
142 /* See if there is some register that can be used in this mode and
143 directly loaded or stored from memory. */
145 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
146 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
147 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
150 if (! HARD_REGNO_MODE_OK (regno
, mode
))
153 set_mode_and_regno (reg
, mode
, regno
);
156 SET_DEST (pat
) = reg
;
157 if (recog (pat
, insn
, &num_clobbers
) >= 0)
158 direct_load
[(int) mode
] = 1;
160 SET_SRC (pat
) = mem1
;
161 SET_DEST (pat
) = reg
;
162 if (recog (pat
, insn
, &num_clobbers
) >= 0)
163 direct_load
[(int) mode
] = 1;
166 SET_DEST (pat
) = mem
;
167 if (recog (pat
, insn
, &num_clobbers
) >= 0)
168 direct_store
[(int) mode
] = 1;
171 SET_DEST (pat
) = mem1
;
172 if (recog (pat
, insn
, &num_clobbers
) >= 0)
173 direct_store
[(int) mode
] = 1;
177 mem
= gen_rtx_MEM (VOIDmode
, gen_raw_REG (Pmode
, LAST_VIRTUAL_REGISTER
+ 1));
179 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
180 mode
= GET_MODE_WIDER_MODE (mode
))
182 machine_mode srcmode
;
183 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
184 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
188 ic
= can_extend_p (mode
, srcmode
, 0);
189 if (ic
== CODE_FOR_nothing
)
192 PUT_MODE (mem
, srcmode
);
194 if (insn_operand_matches (ic
, 1, mem
))
195 float_extend_from_mem
[mode
][srcmode
] = true;
200 /* This is run at the start of compiling a function. */
205 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
208 /* Copy data from FROM to TO, where the machine modes are not the same.
209 Both modes may be integer, or both may be floating, or both may be
211 UNSIGNEDP should be nonzero if FROM is an unsigned type.
212 This causes zero-extension instead of sign-extension. */
215 convert_move (rtx to
, rtx from
, int unsignedp
)
217 machine_mode to_mode
= GET_MODE (to
);
218 machine_mode from_mode
= GET_MODE (from
);
219 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
220 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
224 /* rtx code for making an equivalent value. */
225 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
226 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
229 gcc_assert (to_real
== from_real
);
230 gcc_assert (to_mode
!= BLKmode
);
231 gcc_assert (from_mode
!= BLKmode
);
233 /* If the source and destination are already the same, then there's
238 /* If FROM is a SUBREG that indicates that we have already done at least
239 the required extension, strip it. We don't handle such SUBREGs as
242 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
243 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
244 >= GET_MODE_PRECISION (to_mode
))
245 && SUBREG_CHECK_PROMOTED_SIGN (from
, unsignedp
))
246 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
248 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
250 if (to_mode
== from_mode
251 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
253 emit_move_insn (to
, from
);
257 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
259 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
261 if (VECTOR_MODE_P (to_mode
))
262 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
264 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
266 emit_move_insn (to
, from
);
270 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
272 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
273 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
283 gcc_assert ((GET_MODE_PRECISION (from_mode
)
284 != GET_MODE_PRECISION (to_mode
))
285 || (DECIMAL_FLOAT_MODE_P (from_mode
)
286 != DECIMAL_FLOAT_MODE_P (to_mode
)));
288 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
289 /* Conversion between decimal float and binary float, same size. */
290 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
291 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
296 /* Try converting directly if the insn is supported. */
298 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
299 if (code
!= CODE_FOR_nothing
)
301 emit_unop_insn (code
, to
, from
,
302 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
306 /* Otherwise use a libcall. */
307 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
309 /* Is this conversion implemented yet? */
310 gcc_assert (libcall
);
313 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
315 insns
= get_insns ();
317 emit_libcall_block (insns
, to
, value
,
318 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
320 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
324 /* Handle pointer conversion. */ /* SPEE 900220. */
325 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
329 if (GET_MODE_PRECISION (from_mode
) > GET_MODE_PRECISION (to_mode
))
336 if (convert_optab_handler (ctab
, to_mode
, from_mode
)
339 emit_unop_insn (convert_optab_handler (ctab
, to_mode
, from_mode
),
345 /* Targets are expected to provide conversion insns between PxImode and
346 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
347 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
349 machine_mode full_mode
350 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
352 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
353 != CODE_FOR_nothing
);
355 if (full_mode
!= from_mode
)
356 from
= convert_to_mode (full_mode
, from
, unsignedp
);
357 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
361 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
364 machine_mode full_mode
365 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
366 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
367 enum insn_code icode
;
369 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
370 gcc_assert (icode
!= CODE_FOR_nothing
);
372 if (to_mode
== full_mode
)
374 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
378 new_from
= gen_reg_rtx (full_mode
);
379 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
381 /* else proceed to integer conversions below. */
382 from_mode
= full_mode
;
386 /* Make sure both are fixed-point modes or both are not. */
387 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
388 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
389 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
391 /* If we widen from_mode to to_mode and they are in the same class,
392 we won't saturate the result.
393 Otherwise, always saturate the result to play safe. */
394 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
395 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
396 expand_fixed_convert (to
, from
, 0, 0);
398 expand_fixed_convert (to
, from
, 0, 1);
402 /* Now both modes are integers. */
404 /* Handle expanding beyond a word. */
405 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
406 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
413 machine_mode lowpart_mode
;
414 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
416 /* Try converting directly if the insn is supported. */
417 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
420 /* If FROM is a SUBREG, put it into a register. Do this
421 so that we always generate the same set of insns for
422 better cse'ing; if an intermediate assignment occurred,
423 we won't be doing the operation directly on the SUBREG. */
424 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
425 from
= force_reg (from_mode
, from
);
426 emit_unop_insn (code
, to
, from
, equiv_code
);
429 /* Next, try converting via full word. */
430 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
431 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
432 != CODE_FOR_nothing
))
434 rtx word_to
= gen_reg_rtx (word_mode
);
437 if (reg_overlap_mentioned_p (to
, from
))
438 from
= force_reg (from_mode
, from
);
441 convert_move (word_to
, from
, unsignedp
);
442 emit_unop_insn (code
, to
, word_to
, equiv_code
);
446 /* No special multiword conversion insn; do it by hand. */
449 /* Since we will turn this into a no conflict block, we must ensure
450 the source does not overlap the target so force it into an isolated
451 register when maybe so. Likewise for any MEM input, since the
452 conversion sequence might require several references to it and we
453 must ensure we're getting the same value every time. */
455 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
456 from
= force_reg (from_mode
, from
);
458 /* Get a copy of FROM widened to a word, if necessary. */
459 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
460 lowpart_mode
= word_mode
;
462 lowpart_mode
= from_mode
;
464 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
466 lowpart
= gen_lowpart (lowpart_mode
, to
);
467 emit_move_insn (lowpart
, lowfrom
);
469 /* Compute the value to put in each remaining word. */
471 fill_value
= const0_rtx
;
473 fill_value
= emit_store_flag_force (gen_reg_rtx (word_mode
),
474 LT
, lowfrom
, const0_rtx
,
475 lowpart_mode
, 0, -1);
477 /* Fill the remaining words. */
478 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
480 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
481 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
483 gcc_assert (subword
);
485 if (fill_value
!= subword
)
486 emit_move_insn (subword
, fill_value
);
489 insns
= get_insns ();
496 /* Truncating multi-word to a word or less. */
497 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
498 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
501 && ! MEM_VOLATILE_P (from
)
502 && direct_load
[(int) to_mode
]
503 && ! mode_dependent_address_p (XEXP (from
, 0),
504 MEM_ADDR_SPACE (from
)))
506 || GET_CODE (from
) == SUBREG
))
507 from
= force_reg (from_mode
, from
);
508 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
512 /* Now follow all the conversions between integers
513 no more than a word long. */
515 /* For truncation, usually we can just refer to FROM in a narrower mode. */
516 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
517 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
520 && ! MEM_VOLATILE_P (from
)
521 && direct_load
[(int) to_mode
]
522 && ! mode_dependent_address_p (XEXP (from
, 0),
523 MEM_ADDR_SPACE (from
)))
525 || GET_CODE (from
) == SUBREG
))
526 from
= force_reg (from_mode
, from
);
527 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
528 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
529 from
= copy_to_reg (from
);
530 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
534 /* Handle extension. */
535 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
537 /* Convert directly if that works. */
538 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
541 emit_unop_insn (code
, to
, from
, equiv_code
);
546 machine_mode intermediate
;
550 /* Search for a mode to convert via. */
551 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
552 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
553 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
555 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
556 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
557 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
558 != CODE_FOR_nothing
))
560 convert_move (to
, convert_to_mode (intermediate
, from
,
561 unsignedp
), unsignedp
);
565 /* No suitable intermediate mode.
566 Generate what we need with shifts. */
567 shift_amount
= (GET_MODE_PRECISION (to_mode
)
568 - GET_MODE_PRECISION (from_mode
));
569 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
570 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
572 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
575 emit_move_insn (to
, tmp
);
580 /* Support special truncate insns for certain modes. */
581 if (convert_optab_handler (trunc_optab
, to_mode
,
582 from_mode
) != CODE_FOR_nothing
)
584 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
589 /* Handle truncation of volatile memrefs, and so on;
590 the things that couldn't be truncated directly,
591 and for which there was no special instruction.
593 ??? Code above formerly short-circuited this, for most integer
594 mode pairs, with a force_reg in from_mode followed by a recursive
595 call to this routine. Appears always to have been wrong. */
596 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
598 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
599 emit_move_insn (to
, temp
);
603 /* Mode combination is not recognized. */
607 /* Return an rtx for a value that would result
608 from converting X to mode MODE.
609 Both X and MODE may be floating, or both integer.
610 UNSIGNEDP is nonzero if X is an unsigned value.
611 This can be done by referring to a part of X in place
612 or by copying to a new temporary with conversion. */
615 convert_to_mode (machine_mode mode
, rtx x
, int unsignedp
)
617 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
620 /* Return an rtx for a value that would result
621 from converting X from mode OLDMODE to mode MODE.
622 Both modes may be floating, or both integer.
623 UNSIGNEDP is nonzero if X is an unsigned value.
625 This can be done by referring to a part of X in place
626 or by copying to a new temporary with conversion.
628 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
631 convert_modes (machine_mode mode
, machine_mode oldmode
, rtx x
, int unsignedp
)
635 /* If FROM is a SUBREG that indicates that we have already done at least
636 the required extension, strip it. */
638 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
639 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
640 && SUBREG_CHECK_PROMOTED_SIGN (x
, unsignedp
))
641 x
= gen_lowpart (mode
, SUBREG_REG (x
));
643 if (GET_MODE (x
) != VOIDmode
)
644 oldmode
= GET_MODE (x
);
649 if (CONST_SCALAR_INT_P (x
) && GET_MODE_CLASS (mode
) == MODE_INT
)
651 /* If the caller did not tell us the old mode, then there is not
652 much to do with respect to canonicalization. We have to
653 assume that all the bits are significant. */
654 if (GET_MODE_CLASS (oldmode
) != MODE_INT
)
655 oldmode
= MAX_MODE_INT
;
656 wide_int w
= wide_int::from (rtx_mode_t (x
, oldmode
),
657 GET_MODE_PRECISION (mode
),
658 unsignedp
? UNSIGNED
: SIGNED
);
659 return immed_wide_int_const (w
, mode
);
662 /* We can do this with a gen_lowpart if both desired and current modes
663 are integer, and this is either a constant integer, a register, or a
665 if (GET_MODE_CLASS (mode
) == MODE_INT
666 && GET_MODE_CLASS (oldmode
) == MODE_INT
667 && GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
668 && ((MEM_P (x
) && !MEM_VOLATILE_P (x
) && direct_load
[(int) mode
])
670 && (!HARD_REGISTER_P (x
)
671 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
672 && TRULY_NOOP_TRUNCATION_MODES_P (mode
, GET_MODE (x
)))))
674 return gen_lowpart (mode
, x
);
676 /* Converting from integer constant into mode is always equivalent to an
678 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
680 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
681 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
684 temp
= gen_reg_rtx (mode
);
685 convert_move (temp
, x
, unsignedp
);
689 /* Return the largest alignment we can use for doing a move (or store)
690 of MAX_PIECES. ALIGN is the largest alignment we could use. */
693 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
697 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
698 if (align
>= GET_MODE_ALIGNMENT (tmode
))
699 align
= GET_MODE_ALIGNMENT (tmode
);
702 machine_mode tmode
, xmode
;
704 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
706 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
707 if (GET_MODE_SIZE (tmode
) > max_pieces
708 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
711 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
717 /* Return the widest integer mode no wider than SIZE. If no such mode
718 can be found, return VOIDmode. */
721 widest_int_mode_for_size (unsigned int size
)
723 machine_mode tmode
, mode
= VOIDmode
;
725 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
726 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
727 if (GET_MODE_SIZE (tmode
) < size
)
733 /* Determine whether an operation OP on LEN bytes with alignment ALIGN can
734 and should be performed piecewise. */
737 can_do_by_pieces (unsigned HOST_WIDE_INT len
, unsigned int align
,
738 enum by_pieces_operation op
)
740 return targetm
.use_by_pieces_infrastructure_p (len
, align
, op
,
741 optimize_insn_for_speed_p ());
744 /* Determine whether the LEN bytes can be moved by using several move
745 instructions. Return nonzero if a call to move_by_pieces should
749 can_move_by_pieces (unsigned HOST_WIDE_INT len
, unsigned int align
)
751 return can_do_by_pieces (len
, align
, MOVE_BY_PIECES
);
754 /* Return number of insns required to perform operation OP by pieces
755 for L bytes. ALIGN (in bits) is maximum alignment we can assume. */
757 unsigned HOST_WIDE_INT
758 by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
759 unsigned int max_size
, by_pieces_operation op
)
761 unsigned HOST_WIDE_INT n_insns
= 0;
763 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
765 while (max_size
> 1 && l
> 0)
768 enum insn_code icode
;
770 mode
= widest_int_mode_for_size (max_size
);
772 if (mode
== VOIDmode
)
774 unsigned int modesize
= GET_MODE_SIZE (mode
);
776 icode
= optab_handler (mov_optab
, mode
);
777 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
779 unsigned HOST_WIDE_INT n_pieces
= l
/ modesize
;
787 case COMPARE_BY_PIECES
:
788 int batch
= targetm
.compare_by_pieces_branch_ratio (mode
);
789 int batch_ops
= 4 * batch
- 1;
790 unsigned HOST_WIDE_INT full
= n_pieces
/ batch
;
791 n_insns
+= full
* batch_ops
;
792 if (n_pieces
% batch
!= 0)
805 /* Used when performing piecewise block operations, holds information
806 about one of the memory objects involved. The member functions
807 can be used to generate code for loading from the object and
808 updating the address when iterating. */
812 /* The object being referenced, a MEM. Can be NULL_RTX to indicate
815 /* The address of the object. Can differ from that seen in the
816 MEM rtx if we copied the address to a register. */
818 /* Nonzero if the address on the object has an autoincrement already,
819 signifies whether that was an increment or decrement. */
820 signed char m_addr_inc
;
821 /* Nonzero if we intend to use autoinc without the address already
822 having autoinc form. We will insert add insns around each memory
823 reference, expecting later passes to form autoinc addressing modes.
824 The only supported options are predecrement and postincrement. */
825 signed char m_explicit_inc
;
826 /* True if we have either of the two possible cases of using
829 /* True if this is an address to be used for load operations rather
833 /* Optionally, a function to obtain constants for any given offset into
834 the objects, and data associated with it. */
835 by_pieces_constfn m_constfn
;
838 pieces_addr (rtx
, bool, by_pieces_constfn
, void *);
839 rtx
adjust (machine_mode
, HOST_WIDE_INT
);
840 void increment_address (HOST_WIDE_INT
);
841 void maybe_predec (HOST_WIDE_INT
);
842 void maybe_postinc (HOST_WIDE_INT
);
843 void decide_autoinc (machine_mode
, bool, HOST_WIDE_INT
);
850 /* Initialize a pieces_addr structure from an object OBJ. IS_LOAD is
851 true if the operation to be performed on this object is a load
852 rather than a store. For stores, OBJ can be NULL, in which case we
853 assume the operation is a stack push. For loads, the optional
854 CONSTFN and its associated CFNDATA can be used in place of the
857 pieces_addr::pieces_addr (rtx obj
, bool is_load
, by_pieces_constfn constfn
,
859 : m_obj (obj
), m_is_load (is_load
), m_constfn (constfn
), m_cfndata (cfndata
)
865 rtx addr
= XEXP (obj
, 0);
866 rtx_code code
= GET_CODE (addr
);
868 bool dec
= code
== PRE_DEC
|| code
== POST_DEC
;
869 bool inc
= code
== PRE_INC
|| code
== POST_INC
;
872 m_addr_inc
= dec
? -1 : 1;
874 /* While we have always looked for these codes here, the code
875 implementing the memory operation has never handled them.
876 Support could be added later if necessary or beneficial. */
877 gcc_assert (code
!= PRE_INC
&& code
!= POST_DEC
);
885 if (STACK_GROWS_DOWNWARD
)
891 gcc_assert (constfn
!= NULL
);
895 gcc_assert (is_load
);
898 /* Decide whether to use autoinc for an address involved in a memory op.
899 MODE is the mode of the accesses, REVERSE is true if we've decided to
900 perform the operation starting from the end, and LEN is the length of
901 the operation. Don't override an earlier decision to set m_auto. */
904 pieces_addr::decide_autoinc (machine_mode
ARG_UNUSED (mode
), bool reverse
,
907 if (m_auto
|| m_obj
== NULL_RTX
)
910 bool use_predec
= (m_is_load
911 ? USE_LOAD_PRE_DECREMENT (mode
)
912 : USE_STORE_PRE_DECREMENT (mode
));
913 bool use_postinc
= (m_is_load
914 ? USE_LOAD_POST_INCREMENT (mode
)
915 : USE_STORE_POST_INCREMENT (mode
));
916 machine_mode addr_mode
= get_address_mode (m_obj
);
918 if (use_predec
&& reverse
)
920 m_addr
= copy_to_mode_reg (addr_mode
,
921 plus_constant (addr_mode
,
926 else if (use_postinc
&& !reverse
)
928 m_addr
= copy_to_mode_reg (addr_mode
, m_addr
);
932 else if (CONSTANT_P (m_addr
))
933 m_addr
= copy_to_mode_reg (addr_mode
, m_addr
);
936 /* Adjust the address to refer to the data at OFFSET in MODE. If we
937 are using autoincrement for this address, we don't add the offset,
938 but we still modify the MEM's properties. */
941 pieces_addr::adjust (machine_mode mode
, HOST_WIDE_INT offset
)
944 return m_constfn (m_cfndata
, offset
, mode
);
945 if (m_obj
== NULL_RTX
)
948 return adjust_automodify_address (m_obj
, mode
, m_addr
, offset
);
950 return adjust_address (m_obj
, mode
, offset
);
953 /* Emit an add instruction to increment the address by SIZE. */
956 pieces_addr::increment_address (HOST_WIDE_INT size
)
958 rtx amount
= gen_int_mode (size
, GET_MODE (m_addr
));
959 emit_insn (gen_add2_insn (m_addr
, amount
));
962 /* If we are supposed to decrement the address after each access, emit code
963 to do so now. Increment by SIZE (which has should have the correct sign
967 pieces_addr::maybe_predec (HOST_WIDE_INT size
)
969 if (m_explicit_inc
>= 0)
971 gcc_assert (HAVE_PRE_DECREMENT
);
972 increment_address (size
);
975 /* If we are supposed to decrement the address after each access, emit code
976 to do so now. Increment by SIZE. */
979 pieces_addr::maybe_postinc (HOST_WIDE_INT size
)
981 if (m_explicit_inc
<= 0)
983 gcc_assert (HAVE_POST_INCREMENT
);
984 increment_address (size
);
987 /* This structure is used by do_op_by_pieces to describe the operation
993 pieces_addr m_to
, m_from
;
994 unsigned HOST_WIDE_INT m_len
;
995 HOST_WIDE_INT m_offset
;
996 unsigned int m_align
;
997 unsigned int m_max_size
;
1000 /* Virtual functions, overriden by derived classes for the specific
1002 virtual void generate (rtx
, rtx
, machine_mode
) = 0;
1003 virtual bool prepare_mode (machine_mode
, unsigned int) = 0;
1004 virtual void finish_mode (machine_mode
)
1009 op_by_pieces_d (rtx
, bool, rtx
, bool, by_pieces_constfn
, void *,
1010 unsigned HOST_WIDE_INT
, unsigned int);
1014 /* The constructor for an op_by_pieces_d structure. We require two
1015 objects named TO and FROM, which are identified as loads or stores
1016 by TO_LOAD and FROM_LOAD. If FROM is a load, the optional FROM_CFN
1017 and its associated FROM_CFN_DATA can be used to replace loads with
1018 constant values. LEN describes the length of the operation. */
1020 op_by_pieces_d::op_by_pieces_d (rtx to
, bool to_load
,
1021 rtx from
, bool from_load
,
1022 by_pieces_constfn from_cfn
,
1023 void *from_cfn_data
,
1024 unsigned HOST_WIDE_INT len
,
1026 : m_to (to
, to_load
, NULL
, NULL
),
1027 m_from (from
, from_load
, from_cfn
, from_cfn_data
),
1028 m_len (len
), m_max_size (MOVE_MAX_PIECES
+ 1)
1030 int toi
= m_to
.get_addr_inc ();
1031 int fromi
= m_from
.get_addr_inc ();
1032 if (toi
>= 0 && fromi
>= 0)
1034 else if (toi
<= 0 && fromi
<= 0)
1039 m_offset
= m_reverse
? len
: 0;
1040 align
= MIN (to
? MEM_ALIGN (to
) : align
,
1041 from
? MEM_ALIGN (from
) : align
);
1043 /* If copying requires more than two move insns,
1044 copy addresses to registers (to make displacements shorter)
1045 and use post-increment if available. */
1046 if (by_pieces_ninsns (len
, align
, m_max_size
, MOVE_BY_PIECES
) > 2)
1048 /* Find the mode of the largest comparison. */
1049 machine_mode mode
= widest_int_mode_for_size (m_max_size
);
1051 m_from
.decide_autoinc (mode
, m_reverse
, len
);
1052 m_to
.decide_autoinc (mode
, m_reverse
, len
);
1055 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1059 /* This function contains the main loop used for expanding a block
1060 operation. First move what we can in the largest integer mode,
1061 then go to successively smaller modes. For every access, call
1062 GENFUN with the two operands and the EXTRA_DATA. */
1065 op_by_pieces_d::run ()
1067 while (m_max_size
> 1 && m_len
> 0)
1069 machine_mode mode
= widest_int_mode_for_size (m_max_size
);
1071 if (mode
== VOIDmode
)
1074 if (prepare_mode (mode
, m_align
))
1076 unsigned int size
= GET_MODE_SIZE (mode
);
1077 rtx to1
= NULL_RTX
, from1
;
1079 while (m_len
>= size
)
1084 to1
= m_to
.adjust (mode
, m_offset
);
1085 from1
= m_from
.adjust (mode
, m_offset
);
1087 m_to
.maybe_predec (-(HOST_WIDE_INT
)size
);
1088 m_from
.maybe_predec (-(HOST_WIDE_INT
)size
);
1090 generate (to1
, from1
, mode
);
1092 m_to
.maybe_postinc (size
);
1093 m_from
.maybe_postinc (size
);
1104 m_max_size
= GET_MODE_SIZE (mode
);
1107 /* The code above should have handled everything. */
1108 gcc_assert (!m_len
);
1111 /* Derived class from op_by_pieces_d, providing support for block move
1114 class move_by_pieces_d
: public op_by_pieces_d
1116 insn_gen_fn m_gen_fun
;
1117 void generate (rtx
, rtx
, machine_mode
);
1118 bool prepare_mode (machine_mode
, unsigned int);
1121 move_by_pieces_d (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
1123 : op_by_pieces_d (to
, false, from
, true, NULL
, NULL
, len
, align
)
1126 rtx
finish_endp (int);
1129 /* Return true if MODE can be used for a set of copies, given an
1130 alignment ALIGN. Prepare whatever data is necessary for later
1131 calls to generate. */
1134 move_by_pieces_d::prepare_mode (machine_mode mode
, unsigned int align
)
1136 insn_code icode
= optab_handler (mov_optab
, mode
);
1137 m_gen_fun
= GEN_FCN (icode
);
1138 return icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
);
1141 /* A callback used when iterating for a compare_by_pieces_operation.
1142 OP0 and OP1 are the values that have been loaded and should be
1143 compared in MODE. If OP0 is NULL, this means we should generate a
1144 push; otherwise EXTRA_DATA holds a pointer to a pointer to the insn
1145 gen function that should be used to generate the mode. */
1148 move_by_pieces_d::generate (rtx op0
, rtx op1
,
1149 machine_mode mode ATTRIBUTE_UNUSED
)
1151 #ifdef PUSH_ROUNDING
1152 if (op0
== NULL_RTX
)
1154 emit_single_push_insn (mode
, op1
, NULL
);
1158 emit_insn (m_gen_fun (op0
, op1
));
1161 /* Perform the final adjustment at the end of a string to obtain the
1162 correct return value for the block operation. If ENDP is 1 return
1163 memory at the end ala mempcpy, and if ENDP is 2 return memory the
1164 end minus one byte ala stpcpy. */
1167 move_by_pieces_d::finish_endp (int endp
)
1169 gcc_assert (!m_reverse
);
1172 m_to
.maybe_postinc (-1);
1175 return m_to
.adjust (QImode
, m_offset
);
1178 /* Generate several move instructions to copy LEN bytes from block FROM to
1179 block TO. (These are MEM rtx's with BLKmode).
1181 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1182 used to push FROM to the stack.
1184 ALIGN is maximum stack alignment we can assume.
1186 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
1187 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
1191 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
1192 unsigned int align
, int endp
)
1194 #ifndef PUSH_ROUNDING
1199 move_by_pieces_d
data (to
, from
, len
, align
);
1204 return data
.finish_endp (endp
);
1209 /* Derived class from op_by_pieces_d, providing support for block move
1212 class store_by_pieces_d
: public op_by_pieces_d
1214 insn_gen_fn m_gen_fun
;
1215 void generate (rtx
, rtx
, machine_mode
);
1216 bool prepare_mode (machine_mode
, unsigned int);
1219 store_by_pieces_d (rtx to
, by_pieces_constfn cfn
, void *cfn_data
,
1220 unsigned HOST_WIDE_INT len
, unsigned int align
)
1221 : op_by_pieces_d (to
, false, NULL_RTX
, true, cfn
, cfn_data
, len
, align
)
1224 rtx
finish_endp (int);
1227 /* Return true if MODE can be used for a set of stores, given an
1228 alignment ALIGN. Prepare whatever data is necessary for later
1229 calls to generate. */
1232 store_by_pieces_d::prepare_mode (machine_mode mode
, unsigned int align
)
1234 insn_code icode
= optab_handler (mov_optab
, mode
);
1235 m_gen_fun
= GEN_FCN (icode
);
1236 return icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
);
1239 /* A callback used when iterating for a store_by_pieces_operation.
1240 OP0 and OP1 are the values that have been loaded and should be
1241 compared in MODE. If OP0 is NULL, this means we should generate a
1242 push; otherwise EXTRA_DATA holds a pointer to a pointer to the insn
1243 gen function that should be used to generate the mode. */
1246 store_by_pieces_d::generate (rtx op0
, rtx op1
, machine_mode
)
1248 emit_insn (m_gen_fun (op0
, op1
));
1251 /* Perform the final adjustment at the end of a string to obtain the
1252 correct return value for the block operation. If ENDP is 1 return
1253 memory at the end ala mempcpy, and if ENDP is 2 return memory the
1254 end minus one byte ala stpcpy. */
1257 store_by_pieces_d::finish_endp (int endp
)
1259 gcc_assert (!m_reverse
);
1262 m_to
.maybe_postinc (-1);
1265 return m_to
.adjust (QImode
, m_offset
);
1268 /* Determine whether the LEN bytes generated by CONSTFUN can be
1269 stored to memory using several move instructions. CONSTFUNDATA is
1270 a pointer which will be passed as argument in every CONSTFUN call.
1271 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
1272 a memset operation and false if it's a copy of a constant string.
1273 Return nonzero if a call to store_by_pieces should succeed. */
1276 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
1277 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
1278 void *constfundata
, unsigned int align
, bool memsetp
)
1280 unsigned HOST_WIDE_INT l
;
1281 unsigned int max_size
;
1282 HOST_WIDE_INT offset
= 0;
1284 enum insn_code icode
;
1286 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
1287 rtx cst ATTRIBUTE_UNUSED
;
1292 if (!targetm
.use_by_pieces_infrastructure_p (len
, align
,
1296 optimize_insn_for_speed_p ()))
1299 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
1301 /* We would first store what we can in the largest integer mode, then go to
1302 successively smaller modes. */
1305 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
1309 max_size
= STORE_MAX_PIECES
+ 1;
1310 while (max_size
> 1 && l
> 0)
1312 mode
= widest_int_mode_for_size (max_size
);
1314 if (mode
== VOIDmode
)
1317 icode
= optab_handler (mov_optab
, mode
);
1318 if (icode
!= CODE_FOR_nothing
1319 && align
>= GET_MODE_ALIGNMENT (mode
))
1321 unsigned int size
= GET_MODE_SIZE (mode
);
1328 cst
= (*constfun
) (constfundata
, offset
, mode
);
1329 if (!targetm
.legitimate_constant_p (mode
, cst
))
1339 max_size
= GET_MODE_SIZE (mode
);
1342 /* The code above should have handled everything. */
1349 /* Generate several move instructions to store LEN bytes generated by
1350 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
1351 pointer which will be passed as argument in every CONSTFUN call.
1352 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
1353 a memset operation and false if it's a copy of a constant string.
1354 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
1355 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
1359 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
1360 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
1361 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
1365 gcc_assert (endp
!= 2);
1369 gcc_assert (targetm
.use_by_pieces_infrastructure_p
1371 memsetp
? SET_BY_PIECES
: STORE_BY_PIECES
,
1372 optimize_insn_for_speed_p ()));
1374 store_by_pieces_d
data (to
, constfun
, constfundata
, len
, align
);
1378 return data
.finish_endp (endp
);
1383 /* Callback routine for clear_by_pieces.
1384 Return const0_rtx unconditionally. */
1387 clear_by_pieces_1 (void *, HOST_WIDE_INT
, machine_mode
)
1392 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
1393 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
1396 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
1401 store_by_pieces_d
data (to
, clear_by_pieces_1
, NULL
, len
, align
);
1405 /* Context used by compare_by_pieces_genfn. It stores the fail label
1406 to jump to in case of miscomparison, and for branch ratios greater than 1,
1407 it stores an accumulator and the current and maximum counts before
1408 emitting another branch. */
1410 class compare_by_pieces_d
: public op_by_pieces_d
1412 rtx_code_label
*m_fail_label
;
1414 int m_count
, m_batch
;
1416 void generate (rtx
, rtx
, machine_mode
);
1417 bool prepare_mode (machine_mode
, unsigned int);
1418 void finish_mode (machine_mode
);
1420 compare_by_pieces_d (rtx op0
, rtx op1
, by_pieces_constfn op1_cfn
,
1421 void *op1_cfn_data
, HOST_WIDE_INT len
, int align
,
1422 rtx_code_label
*fail_label
)
1423 : op_by_pieces_d (op0
, true, op1
, true, op1_cfn
, op1_cfn_data
, len
, align
)
1425 m_fail_label
= fail_label
;
1429 /* A callback used when iterating for a compare_by_pieces_operation.
1430 OP0 and OP1 are the values that have been loaded and should be
1431 compared in MODE. DATA holds a pointer to the compare_by_pieces_data
1432 context structure. */
1435 compare_by_pieces_d::generate (rtx op0
, rtx op1
, machine_mode mode
)
1439 rtx temp
= expand_binop (mode
, sub_optab
, op0
, op1
, NULL_RTX
,
1440 true, OPTAB_LIB_WIDEN
);
1442 temp
= expand_binop (mode
, ior_optab
, m_accumulator
, temp
, temp
,
1443 true, OPTAB_LIB_WIDEN
);
1444 m_accumulator
= temp
;
1446 if (++m_count
< m_batch
)
1450 op0
= m_accumulator
;
1452 m_accumulator
= NULL_RTX
;
1454 do_compare_rtx_and_jump (op0
, op1
, NE
, true, mode
, NULL_RTX
, NULL
,
1458 /* Return true if MODE can be used for a set of moves and comparisons,
1459 given an alignment ALIGN. Prepare whatever data is necessary for
1460 later calls to generate. */
1463 compare_by_pieces_d::prepare_mode (machine_mode mode
, unsigned int align
)
1465 insn_code icode
= optab_handler (mov_optab
, mode
);
1466 if (icode
== CODE_FOR_nothing
1467 || align
< GET_MODE_ALIGNMENT (mode
)
1468 || !can_compare_p (EQ
, mode
, ccp_jump
))
1470 m_batch
= targetm
.compare_by_pieces_branch_ratio (mode
);
1473 m_accumulator
= NULL_RTX
;
1478 /* Called after expanding a series of comparisons in MODE. If we have
1479 accumulated results for which we haven't emitted a branch yet, do
1483 compare_by_pieces_d::finish_mode (machine_mode mode
)
1485 if (m_accumulator
!= NULL_RTX
)
1486 do_compare_rtx_and_jump (m_accumulator
, const0_rtx
, NE
, true, mode
,
1487 NULL_RTX
, NULL
, m_fail_label
, -1);
1490 /* Generate several move instructions to compare LEN bytes from blocks
1491 ARG0 and ARG1. (These are MEM rtx's with BLKmode).
1493 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1494 used to push FROM to the stack.
1496 ALIGN is maximum stack alignment we can assume.
1498 Optionally, the caller can pass a constfn and associated data in A1_CFN
1499 and A1_CFN_DATA. describing that the second operand being compared is a
1500 known constant and how to obtain its data. */
1503 compare_by_pieces (rtx arg0
, rtx arg1
, unsigned HOST_WIDE_INT len
,
1504 rtx target
, unsigned int align
,
1505 by_pieces_constfn a1_cfn
, void *a1_cfn_data
)
1507 rtx_code_label
*fail_label
= gen_label_rtx ();
1508 rtx_code_label
*end_label
= gen_label_rtx ();
1510 if (target
== NULL_RTX
1511 || !REG_P (target
) || REGNO (target
) < FIRST_PSEUDO_REGISTER
)
1512 target
= gen_reg_rtx (TYPE_MODE (integer_type_node
));
1514 compare_by_pieces_d
data (arg0
, arg1
, a1_cfn
, a1_cfn_data
, len
, align
,
1519 emit_move_insn (target
, const0_rtx
);
1520 emit_jump (end_label
);
1522 emit_label (fail_label
);
1523 emit_move_insn (target
, const1_rtx
);
1524 emit_label (end_label
);
1529 /* Emit code to move a block Y to a block X. This may be done with
1530 string-move instructions, with multiple scalar move instructions,
1531 or with a library call.
1533 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1534 SIZE is an rtx that says how long they are.
1535 ALIGN is the maximum alignment we can assume they have.
1536 METHOD describes what kind of copy this is, and what mechanisms may be used.
1537 MIN_SIZE is the minimal size of block to move
1538 MAX_SIZE is the maximal size of block to move, if it can not be represented
1539 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1541 Return the address of the new block, if memcpy is called and returns it,
1545 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1546 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1547 unsigned HOST_WIDE_INT min_size
,
1548 unsigned HOST_WIDE_INT max_size
,
1549 unsigned HOST_WIDE_INT probable_max_size
)
1556 if (CONST_INT_P (size
) && INTVAL (size
) == 0)
1561 case BLOCK_OP_NORMAL
:
1562 case BLOCK_OP_TAILCALL
:
1563 may_use_call
= true;
1566 case BLOCK_OP_CALL_PARM
:
1567 may_use_call
= block_move_libcall_safe_for_call_parm ();
1569 /* Make inhibit_defer_pop nonzero around the library call
1570 to force it to pop the arguments right away. */
1574 case BLOCK_OP_NO_LIBCALL
:
1575 may_use_call
= false;
1582 gcc_assert (MEM_P (x
) && MEM_P (y
));
1583 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1584 gcc_assert (align
>= BITS_PER_UNIT
);
1586 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1587 block copy is more efficient for other large modes, e.g. DCmode. */
1588 x
= adjust_address (x
, BLKmode
, 0);
1589 y
= adjust_address (y
, BLKmode
, 0);
1591 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1592 can be incorrect is coming from __builtin_memcpy. */
1593 if (CONST_INT_P (size
))
1595 x
= shallow_copy_rtx (x
);
1596 y
= shallow_copy_rtx (y
);
1597 set_mem_size (x
, INTVAL (size
));
1598 set_mem_size (y
, INTVAL (size
));
1601 if (CONST_INT_P (size
) && can_move_by_pieces (INTVAL (size
), align
))
1602 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1603 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1604 expected_align
, expected_size
,
1605 min_size
, max_size
, probable_max_size
))
1607 else if (may_use_call
1608 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1609 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1611 /* Since x and y are passed to a libcall, mark the corresponding
1612 tree EXPR as addressable. */
1613 tree y_expr
= MEM_EXPR (y
);
1614 tree x_expr
= MEM_EXPR (x
);
1616 mark_addressable (y_expr
);
1618 mark_addressable (x_expr
);
1619 retval
= emit_block_copy_via_libcall (x
, y
, size
,
1620 method
== BLOCK_OP_TAILCALL
);
1624 emit_block_move_via_loop (x
, y
, size
, align
);
1626 if (method
== BLOCK_OP_CALL_PARM
)
1633 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1635 unsigned HOST_WIDE_INT max
, min
= 0;
1636 if (GET_CODE (size
) == CONST_INT
)
1637 min
= max
= UINTVAL (size
);
1639 max
= GET_MODE_MASK (GET_MODE (size
));
1640 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1644 /* A subroutine of emit_block_move. Returns true if calling the
1645 block move libcall will not clobber any parameters which may have
1646 already been placed on the stack. */
1649 block_move_libcall_safe_for_call_parm (void)
1651 #if defined (REG_PARM_STACK_SPACE)
1655 /* If arguments are pushed on the stack, then they're safe. */
1659 /* If registers go on the stack anyway, any argument is sure to clobber
1660 an outgoing argument. */
1661 #if defined (REG_PARM_STACK_SPACE)
1662 fn
= builtin_decl_implicit (BUILT_IN_MEMCPY
);
1663 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1664 depend on its argument. */
1666 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1667 && REG_PARM_STACK_SPACE (fn
) != 0)
1671 /* If any argument goes in memory, then it might clobber an outgoing
1674 CUMULATIVE_ARGS args_so_far_v
;
1675 cumulative_args_t args_so_far
;
1678 fn
= builtin_decl_implicit (BUILT_IN_MEMCPY
);
1679 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1680 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1682 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1683 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1685 machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1686 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1688 if (!tmp
|| !REG_P (tmp
))
1690 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1692 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1699 /* A subroutine of emit_block_move. Expand a movmem pattern;
1700 return true if successful. */
1703 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1704 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1705 unsigned HOST_WIDE_INT min_size
,
1706 unsigned HOST_WIDE_INT max_size
,
1707 unsigned HOST_WIDE_INT probable_max_size
)
1709 int save_volatile_ok
= volatile_ok
;
1712 if (expected_align
< align
)
1713 expected_align
= align
;
1714 if (expected_size
!= -1)
1716 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1717 expected_size
= probable_max_size
;
1718 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1719 expected_size
= min_size
;
1722 /* Since this is a move insn, we don't care about volatility. */
1725 /* Try the most limited insn first, because there's no point
1726 including more than one in the machine description unless
1727 the more limited one has some advantage. */
1729 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1730 mode
= GET_MODE_WIDER_MODE (mode
))
1732 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1734 if (code
!= CODE_FOR_nothing
1735 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1736 here because if SIZE is less than the mode mask, as it is
1737 returned by the macro, it will definitely be less than the
1738 actual mode mask. Since SIZE is within the Pmode address
1739 space, we limit MODE to Pmode. */
1740 && ((CONST_INT_P (size
)
1741 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1742 <= (GET_MODE_MASK (mode
) >> 1)))
1743 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1744 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1746 struct expand_operand ops
[9];
1749 /* ??? When called via emit_block_move_for_call, it'd be
1750 nice if there were some way to inform the backend, so
1751 that it doesn't fail the expansion because it thinks
1752 emitting the libcall would be more efficient. */
1753 nops
= insn_data
[(int) code
].n_generator_args
;
1754 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1756 create_fixed_operand (&ops
[0], x
);
1757 create_fixed_operand (&ops
[1], y
);
1758 /* The check above guarantees that this size conversion is valid. */
1759 create_convert_operand_to (&ops
[2], size
, mode
, true);
1760 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1763 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1764 create_integer_operand (&ops
[5], expected_size
);
1768 create_integer_operand (&ops
[6], min_size
);
1769 /* If we can not represent the maximal size,
1770 make parameter NULL. */
1771 if ((HOST_WIDE_INT
) max_size
!= -1)
1772 create_integer_operand (&ops
[7], max_size
);
1774 create_fixed_operand (&ops
[7], NULL
);
1778 /* If we can not represent the maximal size,
1779 make parameter NULL. */
1780 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1781 create_integer_operand (&ops
[8], probable_max_size
);
1783 create_fixed_operand (&ops
[8], NULL
);
1785 if (maybe_expand_insn (code
, nops
, ops
))
1787 volatile_ok
= save_volatile_ok
;
1793 volatile_ok
= save_volatile_ok
;
1797 /* A subroutine of emit_block_move. Copy the data via an explicit
1798 loop. This is used only when libcalls are forbidden. */
1799 /* ??? It'd be nice to copy in hunks larger than QImode. */
1802 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1803 unsigned int align ATTRIBUTE_UNUSED
)
1805 rtx_code_label
*cmp_label
, *top_label
;
1806 rtx iter
, x_addr
, y_addr
, tmp
;
1807 machine_mode x_addr_mode
= get_address_mode (x
);
1808 machine_mode y_addr_mode
= get_address_mode (y
);
1809 machine_mode iter_mode
;
1811 iter_mode
= GET_MODE (size
);
1812 if (iter_mode
== VOIDmode
)
1813 iter_mode
= word_mode
;
1815 top_label
= gen_label_rtx ();
1816 cmp_label
= gen_label_rtx ();
1817 iter
= gen_reg_rtx (iter_mode
);
1819 emit_move_insn (iter
, const0_rtx
);
1821 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1822 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1823 do_pending_stack_adjust ();
1825 emit_jump (cmp_label
);
1826 emit_label (top_label
);
1828 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1829 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1831 if (x_addr_mode
!= y_addr_mode
)
1832 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1833 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1835 x
= change_address (x
, QImode
, x_addr
);
1836 y
= change_address (y
, QImode
, y_addr
);
1838 emit_move_insn (x
, y
);
1840 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1841 true, OPTAB_LIB_WIDEN
);
1843 emit_move_insn (iter
, tmp
);
1845 emit_label (cmp_label
);
1847 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1848 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1851 /* Expand a call to memcpy or memmove or memcmp, and return the result.
1852 TAILCALL is true if this is a tail call. */
1855 emit_block_op_via_libcall (enum built_in_function fncode
, rtx dst
, rtx src
,
1856 rtx size
, bool tailcall
)
1858 rtx dst_addr
, src_addr
;
1859 tree call_expr
, dst_tree
, src_tree
, size_tree
;
1860 machine_mode size_mode
;
1862 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1863 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1864 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1866 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1867 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1868 src_tree
= make_tree (ptr_type_node
, src_addr
);
1870 size_mode
= TYPE_MODE (sizetype
);
1871 size
= convert_to_mode (size_mode
, size
, 1);
1872 size
= copy_to_mode_reg (size_mode
, size
);
1873 size_tree
= make_tree (sizetype
, size
);
1875 /* It is incorrect to use the libcall calling conventions for calls to
1876 memcpy/memmove/memcmp because they can be provided by the user. */
1877 tree fn
= builtin_decl_implicit (fncode
);
1878 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1879 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1881 return expand_call (call_expr
, NULL_RTX
, false);
1884 /* Try to expand cmpstrn or cmpmem operation ICODE with the given operands.
1885 ARG3_TYPE is the type of ARG3_RTX. Return the result rtx on success,
1886 otherwise return null. */
1889 expand_cmpstrn_or_cmpmem (insn_code icode
, rtx target
, rtx arg1_rtx
,
1890 rtx arg2_rtx
, tree arg3_type
, rtx arg3_rtx
,
1891 HOST_WIDE_INT align
)
1893 machine_mode insn_mode
= insn_data
[icode
].operand
[0].mode
;
1895 if (target
&& (!REG_P (target
) || HARD_REGISTER_P (target
)))
1898 struct expand_operand ops
[5];
1899 create_output_operand (&ops
[0], target
, insn_mode
);
1900 create_fixed_operand (&ops
[1], arg1_rtx
);
1901 create_fixed_operand (&ops
[2], arg2_rtx
);
1902 create_convert_operand_from (&ops
[3], arg3_rtx
, TYPE_MODE (arg3_type
),
1903 TYPE_UNSIGNED (arg3_type
));
1904 create_integer_operand (&ops
[4], align
);
1905 if (maybe_expand_insn (icode
, 5, ops
))
1906 return ops
[0].value
;
1910 /* Expand a block compare between X and Y with length LEN using the
1911 cmpmem optab, placing the result in TARGET. LEN_TYPE is the type
1912 of the expression that was used to calculate the length. ALIGN
1913 gives the known minimum common alignment. */
1916 emit_block_cmp_via_cmpmem (rtx x
, rtx y
, rtx len
, tree len_type
, rtx target
,
1919 /* Note: The cmpstrnsi pattern, if it exists, is not suitable for
1920 implementing memcmp because it will stop if it encounters two
1922 insn_code icode
= direct_optab_handler (cmpmem_optab
, SImode
);
1924 if (icode
== CODE_FOR_nothing
)
1927 return expand_cmpstrn_or_cmpmem (icode
, target
, x
, y
, len_type
, len
, align
);
1930 /* Emit code to compare a block Y to a block X. This may be done with
1931 string-compare instructions, with multiple scalar instructions,
1932 or with a library call.
1934 Both X and Y must be MEM rtx's. LEN is an rtx that says how long
1935 they are. LEN_TYPE is the type of the expression that was used to
1938 If EQUALITY_ONLY is true, it means we don't have to return the tri-state
1939 value of a normal memcmp call, instead we can just compare for equality.
1940 If FORCE_LIBCALL is true, we should emit a call to memcmp rather than
1943 Optionally, the caller can pass a constfn and associated data in Y_CFN
1944 and Y_CFN_DATA. describing that the second operand being compared is a
1945 known constant and how to obtain its data.
1946 Return the result of the comparison, or NULL_RTX if we failed to
1947 perform the operation. */
1950 emit_block_cmp_hints (rtx x
, rtx y
, rtx len
, tree len_type
, rtx target
,
1951 bool equality_only
, by_pieces_constfn y_cfn
,
1956 if (CONST_INT_P (len
) && INTVAL (len
) == 0)
1959 gcc_assert (MEM_P (x
) && MEM_P (y
));
1960 unsigned int align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1961 gcc_assert (align
>= BITS_PER_UNIT
);
1963 x
= adjust_address (x
, BLKmode
, 0);
1964 y
= adjust_address (y
, BLKmode
, 0);
1967 && CONST_INT_P (len
)
1968 && can_do_by_pieces (INTVAL (len
), align
, COMPARE_BY_PIECES
))
1969 result
= compare_by_pieces (x
, y
, INTVAL (len
), target
, align
,
1972 result
= emit_block_cmp_via_cmpmem (x
, y
, len
, len_type
, target
, align
);
1977 /* Copy all or part of a value X into registers starting at REGNO.
1978 The number of registers to be filled is NREGS. */
1981 move_block_to_reg (int regno
, rtx x
, int nregs
, machine_mode mode
)
1986 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1987 x
= validize_mem (force_const_mem (mode
, x
));
1989 /* See if the machine can do this with a load multiple insn. */
1990 if (targetm
.have_load_multiple ())
1992 rtx_insn
*last
= get_last_insn ();
1993 rtx first
= gen_rtx_REG (word_mode
, regno
);
1994 if (rtx_insn
*pat
= targetm
.gen_load_multiple (first
, x
,
2001 delete_insns_since (last
);
2004 for (int i
= 0; i
< nregs
; i
++)
2005 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
2006 operand_subword_force (x
, i
, mode
));
2009 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
2010 The number of registers to be filled is NREGS. */
2013 move_block_from_reg (int regno
, rtx x
, int nregs
)
2018 /* See if the machine can do this with a store multiple insn. */
2019 if (targetm
.have_store_multiple ())
2021 rtx_insn
*last
= get_last_insn ();
2022 rtx first
= gen_rtx_REG (word_mode
, regno
);
2023 if (rtx_insn
*pat
= targetm
.gen_store_multiple (x
, first
,
2030 delete_insns_since (last
);
2033 for (int i
= 0; i
< nregs
; i
++)
2035 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
2039 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
2043 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
2044 ORIG, where ORIG is a non-consecutive group of registers represented by
2045 a PARALLEL. The clone is identical to the original except in that the
2046 original set of registers is replaced by a new set of pseudo registers.
2047 The new set has the same modes as the original set. */
2050 gen_group_rtx (rtx orig
)
2055 gcc_assert (GET_CODE (orig
) == PARALLEL
);
2057 length
= XVECLEN (orig
, 0);
2058 tmps
= XALLOCAVEC (rtx
, length
);
2060 /* Skip a NULL entry in first slot. */
2061 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
2066 for (; i
< length
; i
++)
2068 machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
2069 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
2071 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
2074 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
2077 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
2078 except that values are placed in TMPS[i], and must later be moved
2079 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
2082 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
2086 machine_mode m
= GET_MODE (orig_src
);
2088 gcc_assert (GET_CODE (dst
) == PARALLEL
);
2091 && !SCALAR_INT_MODE_P (m
)
2092 && !MEM_P (orig_src
)
2093 && GET_CODE (orig_src
) != CONCAT
)
2095 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
2096 if (imode
== BLKmode
)
2097 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
2099 src
= gen_reg_rtx (imode
);
2100 if (imode
!= BLKmode
)
2101 src
= gen_lowpart (GET_MODE (orig_src
), src
);
2102 emit_move_insn (src
, orig_src
);
2103 /* ...and back again. */
2104 if (imode
!= BLKmode
)
2105 src
= gen_lowpart (imode
, src
);
2106 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
2110 /* Check for a NULL entry, used to indicate that the parameter goes
2111 both on the stack and in registers. */
2112 if (XEXP (XVECEXP (dst
, 0, 0), 0))
2117 /* Process the pieces. */
2118 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
2120 machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
2121 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
2122 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2125 /* Handle trailing fragments that run over the size of the struct. */
2126 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2128 /* Arrange to shift the fragment to where it belongs.
2129 extract_bit_field loads to the lsb of the reg. */
2131 #ifdef BLOCK_REG_PADDING
2132 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
2133 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2138 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2139 bytelen
= ssize
- bytepos
;
2140 gcc_assert (bytelen
> 0);
2143 /* If we won't be loading directly from memory, protect the real source
2144 from strange tricks we might play; but make sure that the source can
2145 be loaded directly into the destination. */
2147 if (!MEM_P (orig_src
)
2148 && (!CONSTANT_P (orig_src
)
2149 || (GET_MODE (orig_src
) != mode
2150 && GET_MODE (orig_src
) != VOIDmode
)))
2152 if (GET_MODE (orig_src
) == VOIDmode
)
2153 src
= gen_reg_rtx (mode
);
2155 src
= gen_reg_rtx (GET_MODE (orig_src
));
2157 emit_move_insn (src
, orig_src
);
2160 /* Optimize the access just a bit. */
2162 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
2163 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
2164 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2165 && bytelen
== GET_MODE_SIZE (mode
))
2167 tmps
[i
] = gen_reg_rtx (mode
);
2168 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
2170 else if (COMPLEX_MODE_P (mode
)
2171 && GET_MODE (src
) == mode
2172 && bytelen
== GET_MODE_SIZE (mode
))
2173 /* Let emit_move_complex do the bulk of the work. */
2175 else if (GET_CODE (src
) == CONCAT
)
2177 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
2178 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
2179 unsigned int elt
= bytepos
/ slen0
;
2180 unsigned int subpos
= bytepos
% slen0
;
2182 if (subpos
+ bytelen
<= slen0
)
2184 /* The following assumes that the concatenated objects all
2185 have the same size. In this case, a simple calculation
2186 can be used to determine the object and the bit field
2188 tmps
[i
] = XEXP (src
, elt
);
2190 || subpos
+ bytelen
!= slen0
2191 || (!CONSTANT_P (tmps
[i
])
2192 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
)))
2193 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
2194 subpos
* BITS_PER_UNIT
,
2195 1, NULL_RTX
, mode
, mode
, false);
2201 gcc_assert (!bytepos
);
2202 mem
= assign_stack_temp (GET_MODE (src
), slen
);
2203 emit_move_insn (mem
, src
);
2204 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
2205 0, 1, NULL_RTX
, mode
, mode
, false);
2208 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
2209 SIMD register, which is currently broken. While we get GCC
2210 to emit proper RTL for these cases, let's dump to memory. */
2211 else if (VECTOR_MODE_P (GET_MODE (dst
))
2214 int slen
= GET_MODE_SIZE (GET_MODE (src
));
2217 mem
= assign_stack_temp (GET_MODE (src
), slen
);
2218 emit_move_insn (mem
, src
);
2219 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
2221 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
2222 && XVECLEN (dst
, 0) > 1)
2223 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
2224 else if (CONSTANT_P (src
))
2226 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
2234 /* TODO: const_wide_int can have sizes other than this... */
2235 gcc_assert (2 * len
== ssize
);
2236 split_double (src
, &first
, &second
);
2243 else if (REG_P (src
) && GET_MODE (src
) == mode
)
2246 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
2247 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
2251 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
2256 /* Emit code to move a block SRC of type TYPE to a block DST,
2257 where DST is non-consecutive registers represented by a PARALLEL.
2258 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
2262 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
2267 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
2268 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
2270 /* Copy the extracted pieces into the proper (probable) hard regs. */
2271 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
2273 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
2276 emit_move_insn (d
, tmps
[i
]);
2280 /* Similar, but load SRC into new pseudos in a format that looks like
2281 PARALLEL. This can later be fed to emit_group_move to get things
2282 in the right place. */
2285 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
2290 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
2291 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
2293 /* Convert the vector to look just like the original PARALLEL, except
2294 with the computed values. */
2295 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
2297 rtx e
= XVECEXP (parallel
, 0, i
);
2298 rtx d
= XEXP (e
, 0);
2302 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
2303 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
2305 RTVEC_ELT (vec
, i
) = e
;
2308 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
2311 /* Emit code to move a block SRC to block DST, where SRC and DST are
2312 non-consecutive groups of registers, each represented by a PARALLEL. */
2315 emit_group_move (rtx dst
, rtx src
)
2319 gcc_assert (GET_CODE (src
) == PARALLEL
2320 && GET_CODE (dst
) == PARALLEL
2321 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
2323 /* Skip first entry if NULL. */
2324 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
2325 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
2326 XEXP (XVECEXP (src
, 0, i
), 0));
2329 /* Move a group of registers represented by a PARALLEL into pseudos. */
2332 emit_group_move_into_temps (rtx src
)
2334 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
2337 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
2339 rtx e
= XVECEXP (src
, 0, i
);
2340 rtx d
= XEXP (e
, 0);
2343 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
2344 RTVEC_ELT (vec
, i
) = e
;
2347 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
2350 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
2351 where SRC is non-consecutive registers represented by a PARALLEL.
2352 SSIZE represents the total size of block ORIG_DST, or -1 if not
2356 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
2359 int start
, finish
, i
;
2360 machine_mode m
= GET_MODE (orig_dst
);
2362 gcc_assert (GET_CODE (src
) == PARALLEL
);
2364 if (!SCALAR_INT_MODE_P (m
)
2365 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
2367 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
2368 if (imode
== BLKmode
)
2369 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
2371 dst
= gen_reg_rtx (imode
);
2372 emit_group_store (dst
, src
, type
, ssize
);
2373 if (imode
!= BLKmode
)
2374 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
2375 emit_move_insn (orig_dst
, dst
);
2379 /* Check for a NULL entry, used to indicate that the parameter goes
2380 both on the stack and in registers. */
2381 if (XEXP (XVECEXP (src
, 0, 0), 0))
2385 finish
= XVECLEN (src
, 0);
2387 tmps
= XALLOCAVEC (rtx
, finish
);
2389 /* Copy the (probable) hard regs into pseudos. */
2390 for (i
= start
; i
< finish
; i
++)
2392 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
2393 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
2395 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
2396 emit_move_insn (tmps
[i
], reg
);
2402 /* If we won't be storing directly into memory, protect the real destination
2403 from strange tricks we might play. */
2405 if (GET_CODE (dst
) == PARALLEL
)
2409 /* We can get a PARALLEL dst if there is a conditional expression in
2410 a return statement. In that case, the dst and src are the same,
2411 so no action is necessary. */
2412 if (rtx_equal_p (dst
, src
))
2415 /* It is unclear if we can ever reach here, but we may as well handle
2416 it. Allocate a temporary, and split this into a store/load to/from
2418 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
2419 emit_group_store (temp
, src
, type
, ssize
);
2420 emit_group_load (dst
, temp
, type
, ssize
);
2423 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
2425 machine_mode outer
= GET_MODE (dst
);
2427 HOST_WIDE_INT bytepos
;
2431 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
2432 dst
= gen_reg_rtx (outer
);
2434 /* Make life a bit easier for combine. */
2435 /* If the first element of the vector is the low part
2436 of the destination mode, use a paradoxical subreg to
2437 initialize the destination. */
2440 inner
= GET_MODE (tmps
[start
]);
2441 bytepos
= subreg_lowpart_offset (inner
, outer
);
2442 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
2444 temp
= simplify_gen_subreg (outer
, tmps
[start
],
2448 emit_move_insn (dst
, temp
);
2455 /* If the first element wasn't the low part, try the last. */
2457 && start
< finish
- 1)
2459 inner
= GET_MODE (tmps
[finish
- 1]);
2460 bytepos
= subreg_lowpart_offset (inner
, outer
);
2461 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
2463 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
2467 emit_move_insn (dst
, temp
);
2474 /* Otherwise, simply initialize the result to zero. */
2476 emit_move_insn (dst
, CONST0_RTX (outer
));
2479 /* Process the pieces. */
2480 for (i
= start
; i
< finish
; i
++)
2482 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
2483 machine_mode mode
= GET_MODE (tmps
[i
]);
2484 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2485 unsigned int adj_bytelen
;
2488 /* Handle trailing fragments that run over the size of the struct. */
2489 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2490 adj_bytelen
= ssize
- bytepos
;
2492 adj_bytelen
= bytelen
;
2494 if (GET_CODE (dst
) == CONCAT
)
2496 if (bytepos
+ adj_bytelen
2497 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2498 dest
= XEXP (dst
, 0);
2499 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2501 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2502 dest
= XEXP (dst
, 1);
2506 machine_mode dest_mode
= GET_MODE (dest
);
2507 machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2509 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2511 if (GET_MODE_ALIGNMENT (dest_mode
)
2512 >= GET_MODE_ALIGNMENT (tmp_mode
))
2514 dest
= assign_stack_temp (dest_mode
,
2515 GET_MODE_SIZE (dest_mode
));
2516 emit_move_insn (adjust_address (dest
,
2524 dest
= assign_stack_temp (tmp_mode
,
2525 GET_MODE_SIZE (tmp_mode
));
2526 emit_move_insn (dest
, tmps
[i
]);
2527 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2533 /* Handle trailing fragments that run over the size of the struct. */
2534 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2536 /* store_bit_field always takes its value from the lsb.
2537 Move the fragment to the lsb if it's not already there. */
2539 #ifdef BLOCK_REG_PADDING
2540 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2541 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2547 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2548 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2552 /* Make sure not to write past the end of the struct. */
2553 store_bit_field (dest
,
2554 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2555 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
- 1,
2556 VOIDmode
, tmps
[i
], false);
2559 /* Optimize the access just a bit. */
2560 else if (MEM_P (dest
)
2561 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2562 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2563 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2564 && bytelen
== GET_MODE_SIZE (mode
))
2565 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2568 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2569 0, 0, mode
, tmps
[i
], false);
2572 /* Copy from the pseudo into the (probable) hard reg. */
2573 if (orig_dst
!= dst
)
2574 emit_move_insn (orig_dst
, dst
);
2577 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2578 of the value stored in X. */
2581 maybe_emit_group_store (rtx x
, tree type
)
2583 machine_mode mode
= TYPE_MODE (type
);
2584 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2585 if (GET_CODE (x
) == PARALLEL
)
2587 rtx result
= gen_reg_rtx (mode
);
2588 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2594 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2596 This is used on targets that return BLKmode values in registers. */
2599 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2601 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2602 rtx src
= NULL
, dst
= NULL
;
2603 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2604 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2605 machine_mode mode
= GET_MODE (srcreg
);
2606 machine_mode tmode
= GET_MODE (target
);
2607 machine_mode copy_mode
;
2609 /* BLKmode registers created in the back-end shouldn't have survived. */
2610 gcc_assert (mode
!= BLKmode
);
2612 /* If the structure doesn't take up a whole number of words, see whether
2613 SRCREG is padded on the left or on the right. If it's on the left,
2614 set PADDING_CORRECTION to the number of bits to skip.
2616 In most ABIs, the structure will be returned at the least end of
2617 the register, which translates to right padding on little-endian
2618 targets and left padding on big-endian targets. The opposite
2619 holds if the structure is returned at the most significant
2620 end of the register. */
2621 if (bytes
% UNITS_PER_WORD
!= 0
2622 && (targetm
.calls
.return_in_msb (type
)
2624 : BYTES_BIG_ENDIAN
))
2626 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2628 /* We can use a single move if we have an exact mode for the size. */
2629 else if (MEM_P (target
)
2630 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2631 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2632 && bytes
== GET_MODE_SIZE (mode
))
2634 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2638 /* And if we additionally have the same mode for a register. */
2639 else if (REG_P (target
)
2640 && GET_MODE (target
) == mode
2641 && bytes
== GET_MODE_SIZE (mode
))
2643 emit_move_insn (target
, srcreg
);
2647 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2648 into a new pseudo which is a full word. */
2649 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2651 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2655 /* Copy the structure BITSIZE bits at a time. If the target lives in
2656 memory, take care of not reading/writing past its end by selecting
2657 a copy mode suited to BITSIZE. This should always be possible given
2660 If the target lives in register, make sure not to select a copy mode
2661 larger than the mode of the register.
2663 We could probably emit more efficient code for machines which do not use
2664 strict alignment, but it doesn't seem worth the effort at the current
2667 copy_mode
= word_mode
;
2670 machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2671 if (mem_mode
!= BLKmode
)
2672 copy_mode
= mem_mode
;
2674 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2677 for (bitpos
= 0, xbitpos
= padding_correction
;
2678 bitpos
< bytes
* BITS_PER_UNIT
;
2679 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2681 /* We need a new source operand each time xbitpos is on a
2682 word boundary and when xbitpos == padding_correction
2683 (the first time through). */
2684 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2685 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2687 /* We need a new destination operand each time bitpos is on
2689 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2691 else if (bitpos
% BITS_PER_WORD
== 0)
2692 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2694 /* Use xbitpos for the source extraction (right justified) and
2695 bitpos for the destination store (left justified). */
2696 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2697 extract_bit_field (src
, bitsize
,
2698 xbitpos
% BITS_PER_WORD
, 1,
2699 NULL_RTX
, copy_mode
, copy_mode
,
2705 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2706 register if it contains any data, otherwise return null.
2708 This is used on targets that return BLKmode values in registers. */
2711 copy_blkmode_to_reg (machine_mode mode
, tree src
)
2714 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2715 unsigned int bitsize
;
2716 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2717 machine_mode dst_mode
;
2719 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2721 x
= expand_normal (src
);
2723 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2727 /* If the structure doesn't take up a whole number of words, see
2728 whether the register value should be padded on the left or on
2729 the right. Set PADDING_CORRECTION to the number of padding
2730 bits needed on the left side.
2732 In most ABIs, the structure will be returned at the least end of
2733 the register, which translates to right padding on little-endian
2734 targets and left padding on big-endian targets. The opposite
2735 holds if the structure is returned at the most significant
2736 end of the register. */
2737 if (bytes
% UNITS_PER_WORD
!= 0
2738 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2740 : BYTES_BIG_ENDIAN
))
2741 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2744 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2745 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2746 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2748 /* Copy the structure BITSIZE bits at a time. */
2749 for (bitpos
= 0, xbitpos
= padding_correction
;
2750 bitpos
< bytes
* BITS_PER_UNIT
;
2751 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2753 /* We need a new destination pseudo each time xbitpos is
2754 on a word boundary and when xbitpos == padding_correction
2755 (the first time through). */
2756 if (xbitpos
% BITS_PER_WORD
== 0
2757 || xbitpos
== padding_correction
)
2759 /* Generate an appropriate register. */
2760 dst_word
= gen_reg_rtx (word_mode
);
2761 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2763 /* Clear the destination before we move anything into it. */
2764 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2767 /* We need a new source operand each time bitpos is on a word
2769 if (bitpos
% BITS_PER_WORD
== 0)
2770 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2772 /* Use bitpos for the source extraction (left justified) and
2773 xbitpos for the destination store (right justified). */
2774 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2776 extract_bit_field (src_word
, bitsize
,
2777 bitpos
% BITS_PER_WORD
, 1,
2778 NULL_RTX
, word_mode
, word_mode
,
2783 if (mode
== BLKmode
)
2785 /* Find the smallest integer mode large enough to hold the
2786 entire structure. */
2787 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2789 mode
= GET_MODE_WIDER_MODE (mode
))
2790 /* Have we found a large enough mode? */
2791 if (GET_MODE_SIZE (mode
) >= bytes
)
2794 /* A suitable mode should have been found. */
2795 gcc_assert (mode
!= VOIDmode
);
2798 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2799 dst_mode
= word_mode
;
2802 dst
= gen_reg_rtx (dst_mode
);
2804 for (i
= 0; i
< n_regs
; i
++)
2805 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2807 if (mode
!= dst_mode
)
2808 dst
= gen_lowpart (mode
, dst
);
2813 /* Add a USE expression for REG to the (possibly empty) list pointed
2814 to by CALL_FUSAGE. REG must denote a hard register. */
2817 use_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2819 gcc_assert (REG_P (reg
));
2821 if (!HARD_REGISTER_P (reg
))
2825 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2828 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
2829 to by CALL_FUSAGE. REG must denote a hard register. */
2832 clobber_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2834 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2837 = gen_rtx_EXPR_LIST (mode
, gen_rtx_CLOBBER (VOIDmode
, reg
), *call_fusage
);
2840 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2841 starting at REGNO. All of these registers must be hard registers. */
2844 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2848 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2850 for (i
= 0; i
< nregs
; i
++)
2851 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2854 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2855 PARALLEL REGS. This is for calls that pass values in multiple
2856 non-contiguous locations. The Irix 6 ABI has examples of this. */
2859 use_group_regs (rtx
*call_fusage
, rtx regs
)
2863 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2865 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2867 /* A NULL entry means the parameter goes both on the stack and in
2868 registers. This can also be a MEM for targets that pass values
2869 partially on the stack and partially in registers. */
2870 if (reg
!= 0 && REG_P (reg
))
2871 use_reg (call_fusage
, reg
);
2875 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2876 assigment and the code of the expresion on the RHS is CODE. Return
2880 get_def_for_expr (tree name
, enum tree_code code
)
2884 if (TREE_CODE (name
) != SSA_NAME
)
2887 def_stmt
= get_gimple_for_ssa_name (name
);
2889 || gimple_assign_rhs_code (def_stmt
) != code
)
2895 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2896 assigment and the class of the expresion on the RHS is CLASS. Return
2900 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2904 if (TREE_CODE (name
) != SSA_NAME
)
2907 def_stmt
= get_gimple_for_ssa_name (name
);
2909 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2915 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2916 its length in bytes. */
2919 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2920 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2921 unsigned HOST_WIDE_INT min_size
,
2922 unsigned HOST_WIDE_INT max_size
,
2923 unsigned HOST_WIDE_INT probable_max_size
)
2925 machine_mode mode
= GET_MODE (object
);
2928 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2930 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2931 just move a zero. Otherwise, do this a piece at a time. */
2933 && CONST_INT_P (size
)
2934 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2936 rtx zero
= CONST0_RTX (mode
);
2939 emit_move_insn (object
, zero
);
2943 if (COMPLEX_MODE_P (mode
))
2945 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2948 write_complex_part (object
, zero
, 0);
2949 write_complex_part (object
, zero
, 1);
2955 if (size
== const0_rtx
)
2958 align
= MEM_ALIGN (object
);
2960 if (CONST_INT_P (size
)
2961 && targetm
.use_by_pieces_infrastructure_p (INTVAL (size
), align
,
2963 optimize_insn_for_speed_p ()))
2964 clear_by_pieces (object
, INTVAL (size
), align
);
2965 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2966 expected_align
, expected_size
,
2967 min_size
, max_size
, probable_max_size
))
2969 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2970 return set_storage_via_libcall (object
, size
, const0_rtx
,
2971 method
== BLOCK_OP_TAILCALL
);
2979 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2981 unsigned HOST_WIDE_INT max
, min
= 0;
2982 if (GET_CODE (size
) == CONST_INT
)
2983 min
= max
= UINTVAL (size
);
2985 max
= GET_MODE_MASK (GET_MODE (size
));
2986 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2990 /* A subroutine of clear_storage. Expand a call to memset.
2991 Return the return value of memset, 0 otherwise. */
2994 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2996 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2997 machine_mode size_mode
;
2999 object
= copy_addr_to_reg (XEXP (object
, 0));
3000 object_tree
= make_tree (ptr_type_node
, object
);
3002 if (!CONST_INT_P (val
))
3003 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
3004 val_tree
= make_tree (integer_type_node
, val
);
3006 size_mode
= TYPE_MODE (sizetype
);
3007 size
= convert_to_mode (size_mode
, size
, 1);
3008 size
= copy_to_mode_reg (size_mode
, size
);
3009 size_tree
= make_tree (sizetype
, size
);
3011 /* It is incorrect to use the libcall calling conventions for calls to
3012 memset because it can be provided by the user. */
3013 fn
= builtin_decl_implicit (BUILT_IN_MEMSET
);
3014 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
3015 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
3017 return expand_call (call_expr
, NULL_RTX
, false);
3020 /* Expand a setmem pattern; return true if successful. */
3023 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
3024 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
3025 unsigned HOST_WIDE_INT min_size
,
3026 unsigned HOST_WIDE_INT max_size
,
3027 unsigned HOST_WIDE_INT probable_max_size
)
3029 /* Try the most limited insn first, because there's no point
3030 including more than one in the machine description unless
3031 the more limited one has some advantage. */
3035 if (expected_align
< align
)
3036 expected_align
= align
;
3037 if (expected_size
!= -1)
3039 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
3040 expected_size
= max_size
;
3041 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
3042 expected_size
= min_size
;
3045 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
3046 mode
= GET_MODE_WIDER_MODE (mode
))
3048 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
3050 if (code
!= CODE_FOR_nothing
3051 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
3052 here because if SIZE is less than the mode mask, as it is
3053 returned by the macro, it will definitely be less than the
3054 actual mode mask. Since SIZE is within the Pmode address
3055 space, we limit MODE to Pmode. */
3056 && ((CONST_INT_P (size
)
3057 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
3058 <= (GET_MODE_MASK (mode
) >> 1)))
3059 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
3060 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
3062 struct expand_operand ops
[9];
3065 nops
= insn_data
[(int) code
].n_generator_args
;
3066 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
3068 create_fixed_operand (&ops
[0], object
);
3069 /* The check above guarantees that this size conversion is valid. */
3070 create_convert_operand_to (&ops
[1], size
, mode
, true);
3071 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
3072 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
3075 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
3076 create_integer_operand (&ops
[5], expected_size
);
3080 create_integer_operand (&ops
[6], min_size
);
3081 /* If we can not represent the maximal size,
3082 make parameter NULL. */
3083 if ((HOST_WIDE_INT
) max_size
!= -1)
3084 create_integer_operand (&ops
[7], max_size
);
3086 create_fixed_operand (&ops
[7], NULL
);
3090 /* If we can not represent the maximal size,
3091 make parameter NULL. */
3092 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
3093 create_integer_operand (&ops
[8], probable_max_size
);
3095 create_fixed_operand (&ops
[8], NULL
);
3097 if (maybe_expand_insn (code
, nops
, ops
))
3106 /* Write to one of the components of the complex value CPLX. Write VAL to
3107 the real part if IMAG_P is false, and the imaginary part if its true. */
3110 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
3116 if (GET_CODE (cplx
) == CONCAT
)
3118 emit_move_insn (XEXP (cplx
, imag_p
), val
);
3122 cmode
= GET_MODE (cplx
);
3123 imode
= GET_MODE_INNER (cmode
);
3124 ibitsize
= GET_MODE_BITSIZE (imode
);
3126 /* For MEMs simplify_gen_subreg may generate an invalid new address
3127 because, e.g., the original address is considered mode-dependent
3128 by the target, which restricts simplify_subreg from invoking
3129 adjust_address_nv. Instead of preparing fallback support for an
3130 invalid address, we call adjust_address_nv directly. */
3133 emit_move_insn (adjust_address_nv (cplx
, imode
,
3134 imag_p
? GET_MODE_SIZE (imode
) : 0),
3139 /* If the sub-object is at least word sized, then we know that subregging
3140 will work. This special case is important, since store_bit_field
3141 wants to operate on integer modes, and there's rarely an OImode to
3142 correspond to TCmode. */
3143 if (ibitsize
>= BITS_PER_WORD
3144 /* For hard regs we have exact predicates. Assume we can split
3145 the original object if it spans an even number of hard regs.
3146 This special case is important for SCmode on 64-bit platforms
3147 where the natural size of floating-point regs is 32-bit. */
3149 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3150 && REG_NREGS (cplx
) % 2 == 0))
3152 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3153 imag_p
? GET_MODE_SIZE (imode
) : 0);
3156 emit_move_insn (part
, val
);
3160 /* simplify_gen_subreg may fail for sub-word MEMs. */
3161 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3164 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
,
3168 /* Extract one of the components of the complex value CPLX. Extract the
3169 real part if IMAG_P is false, and the imaginary part if it's true. */
3172 read_complex_part (rtx cplx
, bool imag_p
)
3174 machine_mode cmode
, imode
;
3177 if (GET_CODE (cplx
) == CONCAT
)
3178 return XEXP (cplx
, imag_p
);
3180 cmode
= GET_MODE (cplx
);
3181 imode
= GET_MODE_INNER (cmode
);
3182 ibitsize
= GET_MODE_BITSIZE (imode
);
3184 /* Special case reads from complex constants that got spilled to memory. */
3185 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3187 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3188 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3190 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3191 if (CONSTANT_CLASS_P (part
))
3192 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3196 /* For MEMs simplify_gen_subreg may generate an invalid new address
3197 because, e.g., the original address is considered mode-dependent
3198 by the target, which restricts simplify_subreg from invoking
3199 adjust_address_nv. Instead of preparing fallback support for an
3200 invalid address, we call adjust_address_nv directly. */
3202 return adjust_address_nv (cplx
, imode
,
3203 imag_p
? GET_MODE_SIZE (imode
) : 0);
3205 /* If the sub-object is at least word sized, then we know that subregging
3206 will work. This special case is important, since extract_bit_field
3207 wants to operate on integer modes, and there's rarely an OImode to
3208 correspond to TCmode. */
3209 if (ibitsize
>= BITS_PER_WORD
3210 /* For hard regs we have exact predicates. Assume we can split
3211 the original object if it spans an even number of hard regs.
3212 This special case is important for SCmode on 64-bit platforms
3213 where the natural size of floating-point regs is 32-bit. */
3215 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3216 && REG_NREGS (cplx
) % 2 == 0))
3218 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3219 imag_p
? GET_MODE_SIZE (imode
) : 0);
3223 /* simplify_gen_subreg may fail for sub-word MEMs. */
3224 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3227 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3228 true, NULL_RTX
, imode
, imode
, false);
3231 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3232 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3233 represented in NEW_MODE. If FORCE is true, this will never happen, as
3234 we'll force-create a SUBREG if needed. */
3237 emit_move_change_mode (machine_mode new_mode
,
3238 machine_mode old_mode
, rtx x
, bool force
)
3242 if (push_operand (x
, GET_MODE (x
)))
3244 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3245 MEM_COPY_ATTRIBUTES (ret
, x
);
3249 /* We don't have to worry about changing the address since the
3250 size in bytes is supposed to be the same. */
3251 if (reload_in_progress
)
3253 /* Copy the MEM to change the mode and move any
3254 substitutions from the old MEM to the new one. */
3255 ret
= adjust_address_nv (x
, new_mode
, 0);
3256 copy_replacements (x
, ret
);
3259 ret
= adjust_address (x
, new_mode
, 0);
3263 /* Note that we do want simplify_subreg's behavior of validating
3264 that the new mode is ok for a hard register. If we were to use
3265 simplify_gen_subreg, we would create the subreg, but would
3266 probably run into the target not being able to implement it. */
3267 /* Except, of course, when FORCE is true, when this is exactly what
3268 we want. Which is needed for CCmodes on some targets. */
3270 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3272 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3278 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3279 an integer mode of the same size as MODE. Returns the instruction
3280 emitted, or NULL if such a move could not be generated. */
3283 emit_move_via_integer (machine_mode mode
, rtx x
, rtx y
, bool force
)
3286 enum insn_code code
;
3288 /* There must exist a mode of the exact size we require. */
3289 imode
= int_mode_for_mode (mode
);
3290 if (imode
== BLKmode
)
3293 /* The target must support moves in this mode. */
3294 code
= optab_handler (mov_optab
, imode
);
3295 if (code
== CODE_FOR_nothing
)
3298 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3301 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3304 return emit_insn (GEN_FCN (code
) (x
, y
));
3307 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3308 Return an equivalent MEM that does not use an auto-increment. */
3311 emit_move_resolve_push (machine_mode mode
, rtx x
)
3313 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3314 HOST_WIDE_INT adjust
;
3317 adjust
= GET_MODE_SIZE (mode
);
3318 #ifdef PUSH_ROUNDING
3319 adjust
= PUSH_ROUNDING (adjust
);
3321 if (code
== PRE_DEC
|| code
== POST_DEC
)
3323 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3325 rtx expr
= XEXP (XEXP (x
, 0), 1);
3328 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3329 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3330 val
= INTVAL (XEXP (expr
, 1));
3331 if (GET_CODE (expr
) == MINUS
)
3333 gcc_assert (adjust
== val
|| adjust
== -val
);
3337 /* Do not use anti_adjust_stack, since we don't want to update
3338 stack_pointer_delta. */
3339 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3340 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3341 0, OPTAB_LIB_WIDEN
);
3342 if (temp
!= stack_pointer_rtx
)
3343 emit_move_insn (stack_pointer_rtx
, temp
);
3350 temp
= stack_pointer_rtx
;
3355 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3361 return replace_equiv_address (x
, temp
);
3364 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3365 X is known to satisfy push_operand, and MODE is known to be complex.
3366 Returns the last instruction emitted. */
3369 emit_move_complex_push (machine_mode mode
, rtx x
, rtx y
)
3371 machine_mode submode
= GET_MODE_INNER (mode
);
3374 #ifdef PUSH_ROUNDING
3375 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3377 /* In case we output to the stack, but the size is smaller than the
3378 machine can push exactly, we need to use move instructions. */
3379 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3381 x
= emit_move_resolve_push (mode
, x
);
3382 return emit_move_insn (x
, y
);
3386 /* Note that the real part always precedes the imag part in memory
3387 regardless of machine's endianness. */
3388 switch (GET_CODE (XEXP (x
, 0)))
3402 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3403 read_complex_part (y
, imag_first
));
3404 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3405 read_complex_part (y
, !imag_first
));
3408 /* A subroutine of emit_move_complex. Perform the move from Y to X
3409 via two moves of the parts. Returns the last instruction emitted. */
3412 emit_move_complex_parts (rtx x
, rtx y
)
3414 /* Show the output dies here. This is necessary for SUBREGs
3415 of pseudos since we cannot track their lifetimes correctly;
3416 hard regs shouldn't appear here except as return values. */
3417 if (!reload_completed
&& !reload_in_progress
3418 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3421 write_complex_part (x
, read_complex_part (y
, false), false);
3422 write_complex_part (x
, read_complex_part (y
, true), true);
3424 return get_last_insn ();
3427 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3428 MODE is known to be complex. Returns the last instruction emitted. */
3431 emit_move_complex (machine_mode mode
, rtx x
, rtx y
)
3435 /* Need to take special care for pushes, to maintain proper ordering
3436 of the data, and possibly extra padding. */
3437 if (push_operand (x
, mode
))
3438 return emit_move_complex_push (mode
, x
, y
);
3440 /* See if we can coerce the target into moving both values at once, except
3441 for floating point where we favor moving as parts if this is easy. */
3442 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3443 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3445 && HARD_REGISTER_P (x
)
3446 && REG_NREGS (x
) == 1)
3448 && HARD_REGISTER_P (y
)
3449 && REG_NREGS (y
) == 1))
3451 /* Not possible if the values are inherently not adjacent. */
3452 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3454 /* Is possible if both are registers (or subregs of registers). */
3455 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3457 /* If one of the operands is a memory, and alignment constraints
3458 are friendly enough, we may be able to do combined memory operations.
3459 We do not attempt this if Y is a constant because that combination is
3460 usually better with the by-parts thing below. */
3461 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3462 && (!STRICT_ALIGNMENT
3463 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3472 /* For memory to memory moves, optimal behavior can be had with the
3473 existing block move logic. */
3474 if (MEM_P (x
) && MEM_P (y
))
3476 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3477 BLOCK_OP_NO_LIBCALL
);
3478 return get_last_insn ();
3481 ret
= emit_move_via_integer (mode
, x
, y
, true);
3486 return emit_move_complex_parts (x
, y
);
3489 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3490 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3493 emit_move_ccmode (machine_mode mode
, rtx x
, rtx y
)
3497 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3500 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3501 if (code
!= CODE_FOR_nothing
)
3503 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3504 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3505 return emit_insn (GEN_FCN (code
) (x
, y
));
3509 /* Otherwise, find the MODE_INT mode of the same width. */
3510 ret
= emit_move_via_integer (mode
, x
, y
, false);
3511 gcc_assert (ret
!= NULL
);
3515 /* Return true if word I of OP lies entirely in the
3516 undefined bits of a paradoxical subreg. */
3519 undefined_operand_subword_p (const_rtx op
, int i
)
3521 machine_mode innermode
, innermostmode
;
3523 if (GET_CODE (op
) != SUBREG
)
3525 innermode
= GET_MODE (op
);
3526 innermostmode
= GET_MODE (SUBREG_REG (op
));
3527 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3528 /* The SUBREG_BYTE represents offset, as if the value were stored in
3529 memory, except for a paradoxical subreg where we define
3530 SUBREG_BYTE to be 0; undo this exception as in
3532 if (SUBREG_BYTE (op
) == 0
3533 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3535 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3536 if (WORDS_BIG_ENDIAN
)
3537 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3538 if (BYTES_BIG_ENDIAN
)
3539 offset
+= difference
% UNITS_PER_WORD
;
3541 if (offset
>= GET_MODE_SIZE (innermostmode
)
3542 || offset
<= -GET_MODE_SIZE (word_mode
))
3547 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3548 MODE is any multi-word or full-word mode that lacks a move_insn
3549 pattern. Note that you will get better code if you define such
3550 patterns, even if they must turn into multiple assembler instructions. */
3553 emit_move_multi_word (machine_mode mode
, rtx x
, rtx y
)
3555 rtx_insn
*last_insn
= 0;
3561 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3563 /* If X is a push on the stack, do the push now and replace
3564 X with a reference to the stack pointer. */
3565 if (push_operand (x
, mode
))
3566 x
= emit_move_resolve_push (mode
, x
);
3568 /* If we are in reload, see if either operand is a MEM whose address
3569 is scheduled for replacement. */
3570 if (reload_in_progress
&& MEM_P (x
)
3571 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3572 x
= replace_equiv_address_nv (x
, inner
);
3573 if (reload_in_progress
&& MEM_P (y
)
3574 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3575 y
= replace_equiv_address_nv (y
, inner
);
3579 need_clobber
= false;
3581 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3584 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3587 /* Do not generate code for a move if it would come entirely
3588 from the undefined bits of a paradoxical subreg. */
3589 if (undefined_operand_subword_p (y
, i
))
3592 ypart
= operand_subword (y
, i
, 1, mode
);
3594 /* If we can't get a part of Y, put Y into memory if it is a
3595 constant. Otherwise, force it into a register. Then we must
3596 be able to get a part of Y. */
3597 if (ypart
== 0 && CONSTANT_P (y
))
3599 y
= use_anchored_address (force_const_mem (mode
, y
));
3600 ypart
= operand_subword (y
, i
, 1, mode
);
3602 else if (ypart
== 0)
3603 ypart
= operand_subword_force (y
, i
, mode
);
3605 gcc_assert (xpart
&& ypart
);
3607 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3609 last_insn
= emit_move_insn (xpart
, ypart
);
3615 /* Show the output dies here. This is necessary for SUBREGs
3616 of pseudos since we cannot track their lifetimes correctly;
3617 hard regs shouldn't appear here except as return values.
3618 We never want to emit such a clobber after reload. */
3620 && ! (reload_in_progress
|| reload_completed
)
3621 && need_clobber
!= 0)
3629 /* Low level part of emit_move_insn.
3630 Called just like emit_move_insn, but assumes X and Y
3631 are basically valid. */
3634 emit_move_insn_1 (rtx x
, rtx y
)
3636 machine_mode mode
= GET_MODE (x
);
3637 enum insn_code code
;
3639 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3641 code
= optab_handler (mov_optab
, mode
);
3642 if (code
!= CODE_FOR_nothing
)
3643 return emit_insn (GEN_FCN (code
) (x
, y
));
3645 /* Expand complex moves by moving real part and imag part. */
3646 if (COMPLEX_MODE_P (mode
))
3647 return emit_move_complex (mode
, x
, y
);
3649 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3650 || ALL_FIXED_POINT_MODE_P (mode
))
3652 rtx_insn
*result
= emit_move_via_integer (mode
, x
, y
, true);
3654 /* If we can't find an integer mode, use multi words. */
3658 return emit_move_multi_word (mode
, x
, y
);
3661 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3662 return emit_move_ccmode (mode
, x
, y
);
3664 /* Try using a move pattern for the corresponding integer mode. This is
3665 only safe when simplify_subreg can convert MODE constants into integer
3666 constants. At present, it can only do this reliably if the value
3667 fits within a HOST_WIDE_INT. */
3668 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3670 rtx_insn
*ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3674 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3679 return emit_move_multi_word (mode
, x
, y
);
3682 /* Generate code to copy Y into X.
3683 Both Y and X must have the same mode, except that
3684 Y can be a constant with VOIDmode.
3685 This mode cannot be BLKmode; use emit_block_move for that.
3687 Return the last instruction emitted. */
3690 emit_move_insn (rtx x
, rtx y
)
3692 machine_mode mode
= GET_MODE (x
);
3693 rtx y_cst
= NULL_RTX
;
3694 rtx_insn
*last_insn
;
3697 gcc_assert (mode
!= BLKmode
3698 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3703 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3704 && (last_insn
= compress_float_constant (x
, y
)))
3709 if (!targetm
.legitimate_constant_p (mode
, y
))
3711 y
= force_const_mem (mode
, y
);
3713 /* If the target's cannot_force_const_mem prevented the spill,
3714 assume that the target's move expanders will also take care
3715 of the non-legitimate constant. */
3719 y
= use_anchored_address (y
);
3723 /* If X or Y are memory references, verify that their addresses are valid
3726 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3728 && ! push_operand (x
, GET_MODE (x
))))
3729 x
= validize_mem (x
);
3732 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3733 MEM_ADDR_SPACE (y
)))
3734 y
= validize_mem (y
);
3736 gcc_assert (mode
!= BLKmode
);
3738 last_insn
= emit_move_insn_1 (x
, y
);
3740 if (y_cst
&& REG_P (x
)
3741 && (set
= single_set (last_insn
)) != NULL_RTX
3742 && SET_DEST (set
) == x
3743 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3744 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3749 /* Generate the body of an instruction to copy Y into X.
3750 It may be a list of insns, if one insn isn't enough. */
3753 gen_move_insn (rtx x
, rtx y
)
3758 emit_move_insn_1 (x
, y
);
3764 /* If Y is representable exactly in a narrower mode, and the target can
3765 perform the extension directly from constant or memory, then emit the
3766 move as an extension. */
3769 compress_float_constant (rtx x
, rtx y
)
3771 machine_mode dstmode
= GET_MODE (x
);
3772 machine_mode orig_srcmode
= GET_MODE (y
);
3773 machine_mode srcmode
;
3774 const REAL_VALUE_TYPE
*r
;
3775 int oldcost
, newcost
;
3776 bool speed
= optimize_insn_for_speed_p ();
3778 r
= CONST_DOUBLE_REAL_VALUE (y
);
3780 if (targetm
.legitimate_constant_p (dstmode
, y
))
3781 oldcost
= set_src_cost (y
, orig_srcmode
, speed
);
3783 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), dstmode
, speed
);
3785 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3786 srcmode
!= orig_srcmode
;
3787 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3791 rtx_insn
*last_insn
;
3793 /* Skip if the target can't extend this way. */
3794 ic
= can_extend_p (dstmode
, srcmode
, 0);
3795 if (ic
== CODE_FOR_nothing
)
3798 /* Skip if the narrowed value isn't exact. */
3799 if (! exact_real_truncate (srcmode
, r
))
3802 trunc_y
= const_double_from_real_value (*r
, srcmode
);
3804 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3806 /* Skip if the target needs extra instructions to perform
3808 if (!insn_operand_matches (ic
, 1, trunc_y
))
3810 /* This is valid, but may not be cheaper than the original. */
3811 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3813 if (oldcost
< newcost
)
3816 else if (float_extend_from_mem
[dstmode
][srcmode
])
3818 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3819 /* This is valid, but may not be cheaper than the original. */
3820 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3822 if (oldcost
< newcost
)
3824 trunc_y
= validize_mem (trunc_y
);
3829 /* For CSE's benefit, force the compressed constant pool entry
3830 into a new pseudo. This constant may be used in different modes,
3831 and if not, combine will put things back together for us. */
3832 trunc_y
= force_reg (srcmode
, trunc_y
);
3834 /* If x is a hard register, perform the extension into a pseudo,
3835 so that e.g. stack realignment code is aware of it. */
3837 if (REG_P (x
) && HARD_REGISTER_P (x
))
3838 target
= gen_reg_rtx (dstmode
);
3840 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
3841 last_insn
= get_last_insn ();
3844 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3847 return emit_move_insn (x
, target
);
3854 /* Pushing data onto the stack. */
3856 /* Push a block of length SIZE (perhaps variable)
3857 and return an rtx to address the beginning of the block.
3858 The value may be virtual_outgoing_args_rtx.
3860 EXTRA is the number of bytes of padding to push in addition to SIZE.
3861 BELOW nonzero means this padding comes at low addresses;
3862 otherwise, the padding comes at high addresses. */
3865 push_block (rtx size
, int extra
, int below
)
3869 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3870 if (CONSTANT_P (size
))
3871 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3872 else if (REG_P (size
) && extra
== 0)
3873 anti_adjust_stack (size
);
3876 temp
= copy_to_mode_reg (Pmode
, size
);
3878 temp
= expand_binop (Pmode
, add_optab
, temp
,
3879 gen_int_mode (extra
, Pmode
),
3880 temp
, 0, OPTAB_LIB_WIDEN
);
3881 anti_adjust_stack (temp
);
3884 if (STACK_GROWS_DOWNWARD
)
3886 temp
= virtual_outgoing_args_rtx
;
3887 if (extra
!= 0 && below
)
3888 temp
= plus_constant (Pmode
, temp
, extra
);
3892 if (CONST_INT_P (size
))
3893 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3894 -INTVAL (size
) - (below
? 0 : extra
));
3895 else if (extra
!= 0 && !below
)
3896 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3897 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3900 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3901 negate_rtx (Pmode
, size
));
3904 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3907 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3910 mem_autoinc_base (rtx mem
)
3914 rtx addr
= XEXP (mem
, 0);
3915 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3916 return XEXP (addr
, 0);
3921 /* A utility routine used here, in reload, and in try_split. The insns
3922 after PREV up to and including LAST are known to adjust the stack,
3923 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3924 placing notes as appropriate. PREV may be NULL, indicating the
3925 entire insn sequence prior to LAST should be scanned.
3927 The set of allowed stack pointer modifications is small:
3928 (1) One or more auto-inc style memory references (aka pushes),
3929 (2) One or more addition/subtraction with the SP as destination,
3930 (3) A single move insn with the SP as destination,
3931 (4) A call_pop insn,
3932 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3934 Insns in the sequence that do not modify the SP are ignored,
3935 except for noreturn calls.
3937 The return value is the amount of adjustment that can be trivially
3938 verified, via immediate operand or auto-inc. If the adjustment
3939 cannot be trivially extracted, the return value is INT_MIN. */
3942 find_args_size_adjust (rtx_insn
*insn
)
3947 pat
= PATTERN (insn
);
3950 /* Look for a call_pop pattern. */
3953 /* We have to allow non-call_pop patterns for the case
3954 of emit_single_push_insn of a TLS address. */
3955 if (GET_CODE (pat
) != PARALLEL
)
3958 /* All call_pop have a stack pointer adjust in the parallel.
3959 The call itself is always first, and the stack adjust is
3960 usually last, so search from the end. */
3961 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3963 set
= XVECEXP (pat
, 0, i
);
3964 if (GET_CODE (set
) != SET
)
3966 dest
= SET_DEST (set
);
3967 if (dest
== stack_pointer_rtx
)
3970 /* We'd better have found the stack pointer adjust. */
3973 /* Fall through to process the extracted SET and DEST
3974 as if it was a standalone insn. */
3976 else if (GET_CODE (pat
) == SET
)
3978 else if ((set
= single_set (insn
)) != NULL
)
3980 else if (GET_CODE (pat
) == PARALLEL
)
3982 /* ??? Some older ports use a parallel with a stack adjust
3983 and a store for a PUSH_ROUNDING pattern, rather than a
3984 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3985 /* ??? See h8300 and m68k, pushqi1. */
3986 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3988 set
= XVECEXP (pat
, 0, i
);
3989 if (GET_CODE (set
) != SET
)
3991 dest
= SET_DEST (set
);
3992 if (dest
== stack_pointer_rtx
)
3995 /* We do not expect an auto-inc of the sp in the parallel. */
3996 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3997 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3998 != stack_pointer_rtx
);
4006 dest
= SET_DEST (set
);
4008 /* Look for direct modifications of the stack pointer. */
4009 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
4011 /* Look for a trivial adjustment, otherwise assume nothing. */
4012 /* Note that the SPU restore_stack_block pattern refers to
4013 the stack pointer in V4SImode. Consider that non-trivial. */
4014 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
4015 && GET_CODE (SET_SRC (set
)) == PLUS
4016 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
4017 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
4018 return INTVAL (XEXP (SET_SRC (set
), 1));
4019 /* ??? Reload can generate no-op moves, which will be cleaned
4020 up later. Recognize it and continue searching. */
4021 else if (rtx_equal_p (dest
, SET_SRC (set
)))
4024 return HOST_WIDE_INT_MIN
;
4030 /* Otherwise only think about autoinc patterns. */
4031 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
4034 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
4035 != stack_pointer_rtx
);
4037 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
4038 mem
= SET_SRC (set
);
4042 addr
= XEXP (mem
, 0);
4043 switch (GET_CODE (addr
))
4047 return GET_MODE_SIZE (GET_MODE (mem
));
4050 return -GET_MODE_SIZE (GET_MODE (mem
));
4053 addr
= XEXP (addr
, 1);
4054 gcc_assert (GET_CODE (addr
) == PLUS
);
4055 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
4056 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
4057 return INTVAL (XEXP (addr
, 1));
4065 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
, int end_args_size
)
4067 int args_size
= end_args_size
;
4068 bool saw_unknown
= false;
4071 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
4073 HOST_WIDE_INT this_delta
;
4075 if (!NONDEBUG_INSN_P (insn
))
4078 this_delta
= find_args_size_adjust (insn
);
4079 if (this_delta
== 0)
4082 || ACCUMULATE_OUTGOING_ARGS
4083 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
4087 gcc_assert (!saw_unknown
);
4088 if (this_delta
== HOST_WIDE_INT_MIN
)
4091 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
4092 if (STACK_GROWS_DOWNWARD
)
4093 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
4095 args_size
-= this_delta
;
4098 return saw_unknown
? INT_MIN
: args_size
;
4101 #ifdef PUSH_ROUNDING
4102 /* Emit single push insn. */
4105 emit_single_push_insn_1 (machine_mode mode
, rtx x
, tree type
)
4108 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
4110 enum insn_code icode
;
4112 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
4113 /* If there is push pattern, use it. Otherwise try old way of throwing
4114 MEM representing push operation to move expander. */
4115 icode
= optab_handler (push_optab
, mode
);
4116 if (icode
!= CODE_FOR_nothing
)
4118 struct expand_operand ops
[1];
4120 create_input_operand (&ops
[0], x
, mode
);
4121 if (maybe_expand_insn (icode
, 1, ops
))
4124 if (GET_MODE_SIZE (mode
) == rounded_size
)
4125 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
4126 /* If we are to pad downward, adjust the stack pointer first and
4127 then store X into the stack location using an offset. This is
4128 because emit_move_insn does not know how to pad; it does not have
4130 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
4132 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
4133 HOST_WIDE_INT offset
;
4135 emit_move_insn (stack_pointer_rtx
,
4136 expand_binop (Pmode
,
4137 STACK_GROWS_DOWNWARD
? sub_optab
4140 gen_int_mode (rounded_size
, Pmode
),
4141 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
4143 offset
= (HOST_WIDE_INT
) padding_size
;
4144 if (STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_DEC
)
4145 /* We have already decremented the stack pointer, so get the
4147 offset
+= (HOST_WIDE_INT
) rounded_size
;
4149 if (!STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_INC
)
4150 /* We have already incremented the stack pointer, so get the
4152 offset
-= (HOST_WIDE_INT
) rounded_size
;
4154 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4155 gen_int_mode (offset
, Pmode
));
4159 if (STACK_GROWS_DOWNWARD
)
4160 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4161 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4162 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4165 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4166 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4167 gen_int_mode (rounded_size
, Pmode
));
4169 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4172 dest
= gen_rtx_MEM (mode
, dest_addr
);
4176 set_mem_attributes (dest
, type
, 1);
4178 if (cfun
->tail_call_marked
)
4179 /* Function incoming arguments may overlap with sibling call
4180 outgoing arguments and we cannot allow reordering of reads
4181 from function arguments with stores to outgoing arguments
4182 of sibling calls. */
4183 set_mem_alias_set (dest
, 0);
4185 emit_move_insn (dest
, x
);
4188 /* Emit and annotate a single push insn. */
4191 emit_single_push_insn (machine_mode mode
, rtx x
, tree type
)
4193 int delta
, old_delta
= stack_pointer_delta
;
4194 rtx_insn
*prev
= get_last_insn ();
4197 emit_single_push_insn_1 (mode
, x
, type
);
4199 last
= get_last_insn ();
4201 /* Notice the common case where we emitted exactly one insn. */
4202 if (PREV_INSN (last
) == prev
)
4204 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4208 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4209 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4213 /* If reading SIZE bytes from X will end up reading from
4214 Y return the number of bytes that overlap. Return -1
4215 if there is no overlap or -2 if we can't determine
4216 (for example when X and Y have different base registers). */
4219 memory_load_overlap (rtx x
, rtx y
, HOST_WIDE_INT size
)
4221 rtx tmp
= plus_constant (Pmode
, x
, size
);
4222 rtx sub
= simplify_gen_binary (MINUS
, Pmode
, tmp
, y
);
4224 if (!CONST_INT_P (sub
))
4227 HOST_WIDE_INT val
= INTVAL (sub
);
4229 return IN_RANGE (val
, 1, size
) ? val
: -1;
4232 /* Generate code to push X onto the stack, assuming it has mode MODE and
4234 MODE is redundant except when X is a CONST_INT (since they don't
4236 SIZE is an rtx for the size of data to be copied (in bytes),
4237 needed only if X is BLKmode.
4238 Return true if successful. May return false if asked to push a
4239 partial argument during a sibcall optimization (as specified by
4240 SIBCALL_P) and the incoming and outgoing pointers cannot be shown
4243 ALIGN (in bits) is maximum alignment we can assume.
4245 If PARTIAL and REG are both nonzero, then copy that many of the first
4246 bytes of X into registers starting with REG, and push the rest of X.
4247 The amount of space pushed is decreased by PARTIAL bytes.
4248 REG must be a hard register in this case.
4249 If REG is zero but PARTIAL is not, take any all others actions for an
4250 argument partially in registers, but do not actually load any
4253 EXTRA is the amount in bytes of extra space to leave next to this arg.
4254 This is ignored if an argument block has already been allocated.
4256 On a machine that lacks real push insns, ARGS_ADDR is the address of
4257 the bottom of the argument block for this call. We use indexing off there
4258 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4259 argument block has not been preallocated.
4261 ARGS_SO_FAR is the size of args previously pushed for this call.
4263 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4264 for arguments passed in registers. If nonzero, it will be the number
4265 of bytes required. */
4268 emit_push_insn (rtx x
, machine_mode mode
, tree type
, rtx size
,
4269 unsigned int align
, int partial
, rtx reg
, int extra
,
4270 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4271 rtx alignment_pad
, bool sibcall_p
)
4274 enum direction stack_direction
= STACK_GROWS_DOWNWARD
? downward
: upward
;
4276 /* Decide where to pad the argument: `downward' for below,
4277 `upward' for above, or `none' for don't pad it.
4278 Default is below for small data on big-endian machines; else above. */
4279 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4281 /* Invert direction if stack is post-decrement.
4283 if (STACK_PUSH_CODE
== POST_DEC
)
4284 if (where_pad
!= none
)
4285 where_pad
= (where_pad
== downward
? upward
: downward
);
4289 int nregs
= partial
/ UNITS_PER_WORD
;
4290 rtx
*tmp_regs
= NULL
;
4291 int overlapping
= 0;
4294 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4296 /* Copy a block into the stack, entirely or partially. */
4303 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4304 used
= partial
- offset
;
4306 if (mode
!= BLKmode
)
4308 /* A value is to be stored in an insufficiently aligned
4309 stack slot; copy via a suitably aligned slot if
4311 size
= GEN_INT (GET_MODE_SIZE (mode
));
4312 if (!MEM_P (xinner
))
4314 temp
= assign_temp (type
, 1, 1);
4315 emit_move_insn (temp
, xinner
);
4322 /* USED is now the # of bytes we need not copy to the stack
4323 because registers will take care of them. */
4326 xinner
= adjust_address (xinner
, BLKmode
, used
);
4328 /* If the partial register-part of the arg counts in its stack size,
4329 skip the part of stack space corresponding to the registers.
4330 Otherwise, start copying to the beginning of the stack space,
4331 by setting SKIP to 0. */
4332 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4334 #ifdef PUSH_ROUNDING
4335 /* Do it with several push insns if that doesn't take lots of insns
4336 and if there is no difficulty with push insns that skip bytes
4337 on the stack for alignment purposes. */
4340 && CONST_INT_P (size
)
4342 && MEM_ALIGN (xinner
) >= align
4343 && can_move_by_pieces ((unsigned) INTVAL (size
) - used
, align
)
4344 /* Here we avoid the case of a structure whose weak alignment
4345 forces many pushes of a small amount of data,
4346 and such small pushes do rounding that causes trouble. */
4347 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4348 || align
>= BIGGEST_ALIGNMENT
4349 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4350 == (align
/ BITS_PER_UNIT
)))
4351 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4353 /* Push padding now if padding above and stack grows down,
4354 or if padding below and stack grows up.
4355 But if space already allocated, this has already been done. */
4356 if (extra
&& args_addr
== 0
4357 && where_pad
!= none
&& where_pad
!= stack_direction
)
4358 anti_adjust_stack (GEN_INT (extra
));
4360 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4363 #endif /* PUSH_ROUNDING */
4367 /* Otherwise make space on the stack and copy the data
4368 to the address of that space. */
4370 /* Deduct words put into registers from the size we must copy. */
4373 if (CONST_INT_P (size
))
4374 size
= GEN_INT (INTVAL (size
) - used
);
4376 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4377 gen_int_mode (used
, GET_MODE (size
)),
4378 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4381 /* Get the address of the stack space.
4382 In this case, we do not deal with EXTRA separately.
4383 A single stack adjust will do. */
4386 temp
= push_block (size
, extra
, where_pad
== downward
);
4389 else if (CONST_INT_P (args_so_far
))
4390 temp
= memory_address (BLKmode
,
4391 plus_constant (Pmode
, args_addr
,
4392 skip
+ INTVAL (args_so_far
)));
4394 temp
= memory_address (BLKmode
,
4395 plus_constant (Pmode
,
4396 gen_rtx_PLUS (Pmode
,
4401 if (!ACCUMULATE_OUTGOING_ARGS
)
4403 /* If the source is referenced relative to the stack pointer,
4404 copy it to another register to stabilize it. We do not need
4405 to do this if we know that we won't be changing sp. */
4407 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4408 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4409 temp
= copy_to_reg (temp
);
4412 target
= gen_rtx_MEM (BLKmode
, temp
);
4414 /* We do *not* set_mem_attributes here, because incoming arguments
4415 may overlap with sibling call outgoing arguments and we cannot
4416 allow reordering of reads from function arguments with stores
4417 to outgoing arguments of sibling calls. We do, however, want
4418 to record the alignment of the stack slot. */
4419 /* ALIGN may well be better aligned than TYPE, e.g. due to
4420 PARM_BOUNDARY. Assume the caller isn't lying. */
4421 set_mem_align (target
, align
);
4423 /* If part should go in registers and pushing to that part would
4424 overwrite some of the values that need to go into regs, load the
4425 overlapping values into temporary pseudos to be moved into the hard
4426 regs at the end after the stack pushing has completed.
4427 We cannot load them directly into the hard regs here because
4428 they can be clobbered by the block move expansions.
4431 if (partial
> 0 && reg
!= 0 && mode
== BLKmode
4432 && GET_CODE (reg
) != PARALLEL
)
4434 overlapping
= memory_load_overlap (XEXP (x
, 0), temp
, partial
);
4435 if (overlapping
> 0)
4437 gcc_assert (overlapping
% UNITS_PER_WORD
== 0);
4438 overlapping
/= UNITS_PER_WORD
;
4440 tmp_regs
= XALLOCAVEC (rtx
, overlapping
);
4442 for (int i
= 0; i
< overlapping
; i
++)
4443 tmp_regs
[i
] = gen_reg_rtx (word_mode
);
4445 for (int i
= 0; i
< overlapping
; i
++)
4446 emit_move_insn (tmp_regs
[i
],
4447 operand_subword_force (target
, i
, mode
));
4449 else if (overlapping
== -1)
4451 /* Could not determine whether there is overlap.
4452 Fail the sibcall. */
4460 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4463 else if (partial
> 0)
4465 /* Scalar partly in registers. */
4467 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4470 /* # bytes of start of argument
4471 that we must make space for but need not store. */
4472 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4473 int args_offset
= INTVAL (args_so_far
);
4476 /* Push padding now if padding above and stack grows down,
4477 or if padding below and stack grows up.
4478 But if space already allocated, this has already been done. */
4479 if (extra
&& args_addr
== 0
4480 && where_pad
!= none
&& where_pad
!= stack_direction
)
4481 anti_adjust_stack (GEN_INT (extra
));
4483 /* If we make space by pushing it, we might as well push
4484 the real data. Otherwise, we can leave OFFSET nonzero
4485 and leave the space uninitialized. */
4489 /* Now NOT_STACK gets the number of words that we don't need to
4490 allocate on the stack. Convert OFFSET to words too. */
4491 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4492 offset
/= UNITS_PER_WORD
;
4494 /* If the partial register-part of the arg counts in its stack size,
4495 skip the part of stack space corresponding to the registers.
4496 Otherwise, start copying to the beginning of the stack space,
4497 by setting SKIP to 0. */
4498 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4500 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4501 x
= validize_mem (force_const_mem (mode
, x
));
4503 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4504 SUBREGs of such registers are not allowed. */
4505 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4506 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4507 x
= copy_to_reg (x
);
4509 /* Loop over all the words allocated on the stack for this arg. */
4510 /* We can do it by words, because any scalar bigger than a word
4511 has a size a multiple of a word. */
4512 for (i
= size
- 1; i
>= not_stack
; i
--)
4513 if (i
>= not_stack
+ offset
)
4514 if (!emit_push_insn (operand_subword_force (x
, i
, mode
),
4515 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4517 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4519 reg_parm_stack_space
, alignment_pad
, sibcall_p
))
4527 /* Push padding now if padding above and stack grows down,
4528 or if padding below and stack grows up.
4529 But if space already allocated, this has already been done. */
4530 if (extra
&& args_addr
== 0
4531 && where_pad
!= none
&& where_pad
!= stack_direction
)
4532 anti_adjust_stack (GEN_INT (extra
));
4534 #ifdef PUSH_ROUNDING
4535 if (args_addr
== 0 && PUSH_ARGS
)
4536 emit_single_push_insn (mode
, x
, type
);
4540 if (CONST_INT_P (args_so_far
))
4542 = memory_address (mode
,
4543 plus_constant (Pmode
, args_addr
,
4544 INTVAL (args_so_far
)));
4546 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4548 dest
= gen_rtx_MEM (mode
, addr
);
4550 /* We do *not* set_mem_attributes here, because incoming arguments
4551 may overlap with sibling call outgoing arguments and we cannot
4552 allow reordering of reads from function arguments with stores
4553 to outgoing arguments of sibling calls. We do, however, want
4554 to record the alignment of the stack slot. */
4555 /* ALIGN may well be better aligned than TYPE, e.g. due to
4556 PARM_BOUNDARY. Assume the caller isn't lying. */
4557 set_mem_align (dest
, align
);
4559 emit_move_insn (dest
, x
);
4563 /* Move the partial arguments into the registers and any overlapping
4564 values that we moved into the pseudos in tmp_regs. */
4565 if (partial
> 0 && reg
!= 0)
4567 /* Handle calls that pass values in multiple non-contiguous locations.
4568 The Irix 6 ABI has examples of this. */
4569 if (GET_CODE (reg
) == PARALLEL
)
4570 emit_group_load (reg
, x
, type
, -1);
4573 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4574 move_block_to_reg (REGNO (reg
), x
, nregs
- overlapping
, mode
);
4576 for (int i
= 0; i
< overlapping
; i
++)
4577 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
)
4578 + nregs
- overlapping
+ i
),
4584 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4585 anti_adjust_stack (GEN_INT (extra
));
4587 if (alignment_pad
&& args_addr
== 0)
4588 anti_adjust_stack (alignment_pad
);
4593 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4597 get_subtarget (rtx x
)
4601 /* Only registers can be subtargets. */
4603 /* Don't use hard regs to avoid extending their life. */
4604 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4608 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4609 FIELD is a bitfield. Returns true if the optimization was successful,
4610 and there's nothing else to do. */
4613 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4614 unsigned HOST_WIDE_INT bitpos
,
4615 unsigned HOST_WIDE_INT bitregion_start
,
4616 unsigned HOST_WIDE_INT bitregion_end
,
4617 machine_mode mode1
, rtx str_rtx
,
4618 tree to
, tree src
, bool reverse
)
4620 machine_mode str_mode
= GET_MODE (str_rtx
);
4621 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4626 enum tree_code code
;
4628 if (mode1
!= VOIDmode
4629 || bitsize
>= BITS_PER_WORD
4630 || str_bitsize
> BITS_PER_WORD
4631 || TREE_SIDE_EFFECTS (to
)
4632 || TREE_THIS_VOLATILE (to
))
4636 if (TREE_CODE (src
) != SSA_NAME
)
4638 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4641 srcstmt
= get_gimple_for_ssa_name (src
);
4643 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4646 code
= gimple_assign_rhs_code (srcstmt
);
4648 op0
= gimple_assign_rhs1 (srcstmt
);
4650 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4651 to find its initialization. Hopefully the initialization will
4652 be from a bitfield load. */
4653 if (TREE_CODE (op0
) == SSA_NAME
)
4655 gimple
*op0stmt
= get_gimple_for_ssa_name (op0
);
4657 /* We want to eventually have OP0 be the same as TO, which
4658 should be a bitfield. */
4660 || !is_gimple_assign (op0stmt
)
4661 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4663 op0
= gimple_assign_rhs1 (op0stmt
);
4666 op1
= gimple_assign_rhs2 (srcstmt
);
4668 if (!operand_equal_p (to
, op0
, 0))
4671 if (MEM_P (str_rtx
))
4673 unsigned HOST_WIDE_INT offset1
;
4675 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4676 str_mode
= word_mode
;
4677 str_mode
= get_best_mode (bitsize
, bitpos
,
4678 bitregion_start
, bitregion_end
,
4679 MEM_ALIGN (str_rtx
), str_mode
, 0);
4680 if (str_mode
== VOIDmode
)
4682 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4685 bitpos
%= str_bitsize
;
4686 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4687 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4689 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4692 gcc_assert (!reverse
);
4694 /* If the bit field covers the whole REG/MEM, store_field
4695 will likely generate better code. */
4696 if (bitsize
>= str_bitsize
)
4699 /* We can't handle fields split across multiple entities. */
4700 if (bitpos
+ bitsize
> str_bitsize
)
4703 if (reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
4704 bitpos
= str_bitsize
- bitpos
- bitsize
;
4710 /* For now, just optimize the case of the topmost bitfield
4711 where we don't need to do any masking and also
4712 1 bit bitfields where xor can be used.
4713 We might win by one instruction for the other bitfields
4714 too if insv/extv instructions aren't used, so that
4715 can be added later. */
4716 if ((reverse
|| bitpos
+ bitsize
!= str_bitsize
)
4717 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4720 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4721 value
= convert_modes (str_mode
,
4722 TYPE_MODE (TREE_TYPE (op1
)), value
,
4723 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4725 /* We may be accessing data outside the field, which means
4726 we can alias adjacent data. */
4727 if (MEM_P (str_rtx
))
4729 str_rtx
= shallow_copy_rtx (str_rtx
);
4730 set_mem_alias_set (str_rtx
, 0);
4731 set_mem_expr (str_rtx
, 0);
4734 if (bitsize
== 1 && (reverse
|| bitpos
+ bitsize
!= str_bitsize
))
4736 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4740 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4742 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4744 value
= flip_storage_order (str_mode
, value
);
4745 result
= expand_binop (str_mode
, binop
, str_rtx
,
4746 value
, str_rtx
, 1, OPTAB_WIDEN
);
4747 if (result
!= str_rtx
)
4748 emit_move_insn (str_rtx
, result
);
4753 if (TREE_CODE (op1
) != INTEGER_CST
)
4755 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4756 value
= convert_modes (str_mode
,
4757 TYPE_MODE (TREE_TYPE (op1
)), value
,
4758 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4760 /* We may be accessing data outside the field, which means
4761 we can alias adjacent data. */
4762 if (MEM_P (str_rtx
))
4764 str_rtx
= shallow_copy_rtx (str_rtx
);
4765 set_mem_alias_set (str_rtx
, 0);
4766 set_mem_expr (str_rtx
, 0);
4769 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4770 if (bitpos
+ bitsize
!= str_bitsize
)
4772 rtx mask
= gen_int_mode ((HOST_WIDE_INT_1U
<< bitsize
) - 1,
4774 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4776 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4778 value
= flip_storage_order (str_mode
, value
);
4779 result
= expand_binop (str_mode
, binop
, str_rtx
,
4780 value
, str_rtx
, 1, OPTAB_WIDEN
);
4781 if (result
!= str_rtx
)
4782 emit_move_insn (str_rtx
, result
);
4792 /* In the C++ memory model, consecutive bit fields in a structure are
4793 considered one memory location.
4795 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4796 returns the bit range of consecutive bits in which this COMPONENT_REF
4797 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4798 and *OFFSET may be adjusted in the process.
4800 If the access does not need to be restricted, 0 is returned in both
4801 *BITSTART and *BITEND. */
4804 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4805 unsigned HOST_WIDE_INT
*bitend
,
4807 HOST_WIDE_INT
*bitpos
,
4810 HOST_WIDE_INT bitoffset
;
4813 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4815 field
= TREE_OPERAND (exp
, 1);
4816 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4817 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4818 need to limit the range we can access. */
4821 *bitstart
= *bitend
= 0;
4825 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4826 part of a larger bit field, then the representative does not serve any
4827 useful purpose. This can occur in Ada. */
4828 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4831 HOST_WIDE_INT rbitsize
, rbitpos
;
4833 int unsignedp
, reversep
, volatilep
= 0;
4834 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4835 &roffset
, &rmode
, &unsignedp
, &reversep
,
4837 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4839 *bitstart
= *bitend
= 0;
4844 /* Compute the adjustment to bitpos from the offset of the field
4845 relative to the representative. DECL_FIELD_OFFSET of field and
4846 repr are the same by construction if they are not constants,
4847 see finish_bitfield_layout. */
4848 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4849 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4850 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4851 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4854 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4855 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4857 /* If the adjustment is larger than bitpos, we would have a negative bit
4858 position for the lower bound and this may wreak havoc later. Adjust
4859 offset and bitpos to make the lower bound non-negative in that case. */
4860 if (bitoffset
> *bitpos
)
4862 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4863 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4866 if (*offset
== NULL_TREE
)
4867 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4870 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4874 *bitstart
= *bitpos
- bitoffset
;
4876 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4879 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4880 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4881 DECL_RTL was not set yet, return NORTL. */
4884 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4886 if (TREE_CODE (addr
) != ADDR_EXPR
)
4889 tree base
= TREE_OPERAND (addr
, 0);
4892 || TREE_ADDRESSABLE (base
)
4893 || DECL_MODE (base
) == BLKmode
)
4896 if (!DECL_RTL_SET_P (base
))
4899 return (!MEM_P (DECL_RTL (base
)));
4902 /* Returns true if the MEM_REF REF refers to an object that does not
4903 reside in memory and has non-BLKmode. */
4906 mem_ref_refers_to_non_mem_p (tree ref
)
4908 tree base
= TREE_OPERAND (ref
, 0);
4909 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4912 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4913 is true, try generating a nontemporal store. */
4916 expand_assignment (tree to
, tree from
, bool nontemporal
)
4922 enum insn_code icode
;
4924 /* Don't crash if the lhs of the assignment was erroneous. */
4925 if (TREE_CODE (to
) == ERROR_MARK
)
4927 expand_normal (from
);
4931 /* Optimize away no-op moves without side-effects. */
4932 if (operand_equal_p (to
, from
, 0))
4935 /* Handle misaligned stores. */
4936 mode
= TYPE_MODE (TREE_TYPE (to
));
4937 if ((TREE_CODE (to
) == MEM_REF
4938 || TREE_CODE (to
) == TARGET_MEM_REF
)
4940 && !mem_ref_refers_to_non_mem_p (to
)
4941 && ((align
= get_object_alignment (to
))
4942 < GET_MODE_ALIGNMENT (mode
))
4943 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4944 != CODE_FOR_nothing
)
4945 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4949 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4950 reg
= force_not_mem (reg
);
4951 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4952 if (TREE_CODE (to
) == MEM_REF
&& REF_REVERSE_STORAGE_ORDER (to
))
4953 reg
= flip_storage_order (mode
, reg
);
4955 if (icode
!= CODE_FOR_nothing
)
4957 struct expand_operand ops
[2];
4959 create_fixed_operand (&ops
[0], mem
);
4960 create_input_operand (&ops
[1], reg
, mode
);
4961 /* The movmisalign<mode> pattern cannot fail, else the assignment
4962 would silently be omitted. */
4963 expand_insn (icode
, 2, ops
);
4966 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
,
4971 /* Assignment of a structure component needs special treatment
4972 if the structure component's rtx is not simply a MEM.
4973 Assignment of an array element at a constant index, and assignment of
4974 an array element in an unaligned packed structure field, has the same
4975 problem. Same for (partially) storing into a non-memory object. */
4976 if (handled_component_p (to
)
4977 || (TREE_CODE (to
) == MEM_REF
4978 && (REF_REVERSE_STORAGE_ORDER (to
)
4979 || mem_ref_refers_to_non_mem_p (to
)))
4980 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4983 HOST_WIDE_INT bitsize
, bitpos
;
4984 unsigned HOST_WIDE_INT bitregion_start
= 0;
4985 unsigned HOST_WIDE_INT bitregion_end
= 0;
4987 int unsignedp
, reversep
, volatilep
= 0;
4991 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4992 &unsignedp
, &reversep
, &volatilep
);
4994 /* Make sure bitpos is not negative, it can wreak havoc later. */
4997 gcc_assert (offset
== NULL_TREE
);
4998 offset
= size_int (bitpos
>> LOG2_BITS_PER_UNIT
);
4999 bitpos
&= BITS_PER_UNIT
- 1;
5002 if (TREE_CODE (to
) == COMPONENT_REF
5003 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
5004 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
5005 /* The C++ memory model naturally applies to byte-aligned fields.
5006 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
5007 BITSIZE are not byte-aligned, there is no need to limit the range
5008 we can access. This can occur with packed structures in Ada. */
5009 else if (bitsize
> 0
5010 && bitsize
% BITS_PER_UNIT
== 0
5011 && bitpos
% BITS_PER_UNIT
== 0)
5013 bitregion_start
= bitpos
;
5014 bitregion_end
= bitpos
+ bitsize
- 1;
5017 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5019 /* If the field has a mode, we want to access it in the
5020 field's mode, not the computed mode.
5021 If a MEM has VOIDmode (external with incomplete type),
5022 use BLKmode for it instead. */
5025 if (mode1
!= VOIDmode
)
5026 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
5027 else if (GET_MODE (to_rtx
) == VOIDmode
)
5028 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
5033 machine_mode address_mode
;
5036 if (!MEM_P (to_rtx
))
5038 /* We can get constant negative offsets into arrays with broken
5039 user code. Translate this to a trap instead of ICEing. */
5040 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
5041 expand_builtin_trap ();
5042 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
5045 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
5046 address_mode
= get_address_mode (to_rtx
);
5047 if (GET_MODE (offset_rtx
) != address_mode
)
5049 /* We cannot be sure that the RTL in offset_rtx is valid outside
5050 of a memory address context, so force it into a register
5051 before attempting to convert it to the desired mode. */
5052 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
5053 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5056 /* If we have an expression in OFFSET_RTX and a non-zero
5057 byte offset in BITPOS, adding the byte offset before the
5058 OFFSET_RTX results in better intermediate code, which makes
5059 later rtl optimization passes perform better.
5061 We prefer intermediate code like this:
5063 r124:DI=r123:DI+0x18
5068 r124:DI=r123:DI+0x10
5069 [r124:DI+0x8]=r121:DI
5071 This is only done for aligned data values, as these can
5072 be expected to result in single move instructions. */
5073 if (mode1
!= VOIDmode
5076 && (bitpos
% bitsize
) == 0
5077 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
5078 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
5080 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
5081 bitregion_start
= 0;
5082 if (bitregion_end
>= (unsigned HOST_WIDE_INT
) bitpos
)
5083 bitregion_end
-= bitpos
;
5087 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5088 highest_pow2_factor_for_target (to
,
5092 /* No action is needed if the target is not a memory and the field
5093 lies completely outside that target. This can occur if the source
5094 code contains an out-of-bounds access to a small array. */
5096 && GET_MODE (to_rtx
) != BLKmode
5097 && (unsigned HOST_WIDE_INT
) bitpos
5098 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
5100 expand_normal (from
);
5103 /* Handle expand_expr of a complex value returning a CONCAT. */
5104 else if (GET_CODE (to_rtx
) == CONCAT
)
5106 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
5107 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
5109 && bitsize
== mode_bitsize
)
5110 result
= store_expr (from
, to_rtx
, false, nontemporal
, reversep
);
5111 else if (bitsize
== mode_bitsize
/ 2
5112 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
5113 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
5114 nontemporal
, reversep
);
5115 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
5116 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
5117 bitregion_start
, bitregion_end
,
5118 mode1
, from
, get_alias_set (to
),
5119 nontemporal
, reversep
);
5120 else if (bitpos
>= mode_bitsize
/ 2)
5121 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
5122 bitpos
- mode_bitsize
/ 2,
5123 bitregion_start
, bitregion_end
,
5124 mode1
, from
, get_alias_set (to
),
5125 nontemporal
, reversep
);
5126 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
5129 result
= expand_normal (from
);
5130 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
5131 TYPE_MODE (TREE_TYPE (from
)), 0);
5132 emit_move_insn (XEXP (to_rtx
, 0),
5133 read_complex_part (from_rtx
, false));
5134 emit_move_insn (XEXP (to_rtx
, 1),
5135 read_complex_part (from_rtx
, true));
5139 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
5140 GET_MODE_SIZE (GET_MODE (to_rtx
)));
5141 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
5142 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
5143 result
= store_field (temp
, bitsize
, bitpos
,
5144 bitregion_start
, bitregion_end
,
5145 mode1
, from
, get_alias_set (to
),
5146 nontemporal
, reversep
);
5147 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
5148 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
5155 /* If the field is at offset zero, we could have been given the
5156 DECL_RTX of the parent struct. Don't munge it. */
5157 to_rtx
= shallow_copy_rtx (to_rtx
);
5158 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
5160 MEM_VOLATILE_P (to_rtx
) = 1;
5163 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
5164 bitregion_start
, bitregion_end
,
5165 mode1
, to_rtx
, to
, from
,
5169 result
= store_field (to_rtx
, bitsize
, bitpos
,
5170 bitregion_start
, bitregion_end
,
5171 mode1
, from
, get_alias_set (to
),
5172 nontemporal
, reversep
);
5176 preserve_temp_slots (result
);
5181 /* If the rhs is a function call and its value is not an aggregate,
5182 call the function before we start to compute the lhs.
5183 This is needed for correct code for cases such as
5184 val = setjmp (buf) on machines where reference to val
5185 requires loading up part of an address in a separate insn.
5187 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
5188 since it might be a promoted variable where the zero- or sign- extension
5189 needs to be done. Handling this in the normal way is safe because no
5190 computation is done before the call. The same is true for SSA names. */
5191 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
5192 && COMPLETE_TYPE_P (TREE_TYPE (from
))
5193 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
5195 || TREE_CODE (to
) == PARM_DECL
5196 || TREE_CODE (to
) == RESULT_DECL
)
5197 && REG_P (DECL_RTL (to
)))
5198 || TREE_CODE (to
) == SSA_NAME
))
5204 value
= expand_normal (from
);
5206 /* Split value and bounds to store them separately. */
5207 chkp_split_slot (value
, &value
, &bounds
);
5210 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5212 /* Handle calls that return values in multiple non-contiguous locations.
5213 The Irix 6 ABI has examples of this. */
5214 if (GET_CODE (to_rtx
) == PARALLEL
)
5216 if (GET_CODE (value
) == PARALLEL
)
5217 emit_group_move (to_rtx
, value
);
5219 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5220 int_size_in_bytes (TREE_TYPE (from
)));
5222 else if (GET_CODE (value
) == PARALLEL
)
5223 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5224 int_size_in_bytes (TREE_TYPE (from
)));
5225 else if (GET_MODE (to_rtx
) == BLKmode
)
5227 /* Handle calls that return BLKmode values in registers. */
5229 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5231 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5235 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5236 value
= convert_memory_address_addr_space
5237 (GET_MODE (to_rtx
), value
,
5238 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5240 emit_move_insn (to_rtx
, value
);
5243 /* Store bounds if required. */
5245 && (BOUNDED_P (to
) || chkp_type_has_pointer (TREE_TYPE (to
))))
5247 gcc_assert (MEM_P (to_rtx
));
5248 chkp_emit_bounds_store (bounds
, value
, to_rtx
);
5251 preserve_temp_slots (to_rtx
);
5256 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5257 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5259 /* Don't move directly into a return register. */
5260 if (TREE_CODE (to
) == RESULT_DECL
5261 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5267 /* If the source is itself a return value, it still is in a pseudo at
5268 this point so we can move it back to the return register directly. */
5270 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5271 && TREE_CODE (from
) != CALL_EXPR
)
5272 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5274 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5276 /* Handle calls that return values in multiple non-contiguous locations.
5277 The Irix 6 ABI has examples of this. */
5278 if (GET_CODE (to_rtx
) == PARALLEL
)
5280 if (GET_CODE (temp
) == PARALLEL
)
5281 emit_group_move (to_rtx
, temp
);
5283 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5284 int_size_in_bytes (TREE_TYPE (from
)));
5287 emit_move_insn (to_rtx
, temp
);
5289 preserve_temp_slots (to_rtx
);
5294 /* In case we are returning the contents of an object which overlaps
5295 the place the value is being stored, use a safe function when copying
5296 a value through a pointer into a structure value return block. */
5297 if (TREE_CODE (to
) == RESULT_DECL
5298 && TREE_CODE (from
) == INDIRECT_REF
5299 && ADDR_SPACE_GENERIC_P
5300 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5301 && refs_may_alias_p (to
, from
)
5302 && cfun
->returns_struct
5303 && !cfun
->returns_pcc_struct
)
5308 size
= expr_size (from
);
5309 from_rtx
= expand_normal (from
);
5311 emit_block_move_via_libcall (XEXP (to_rtx
, 0), XEXP (from_rtx
, 0), size
);
5313 preserve_temp_slots (to_rtx
);
5318 /* Compute FROM and store the value in the rtx we got. */
5321 result
= store_expr_with_bounds (from
, to_rtx
, 0, nontemporal
, false, to
);
5322 preserve_temp_slots (result
);
5327 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5328 succeeded, false otherwise. */
5331 emit_storent_insn (rtx to
, rtx from
)
5333 struct expand_operand ops
[2];
5334 machine_mode mode
= GET_MODE (to
);
5335 enum insn_code code
= optab_handler (storent_optab
, mode
);
5337 if (code
== CODE_FOR_nothing
)
5340 create_fixed_operand (&ops
[0], to
);
5341 create_input_operand (&ops
[1], from
, mode
);
5342 return maybe_expand_insn (code
, 2, ops
);
5345 /* Generate code for computing expression EXP,
5346 and storing the value into TARGET.
5348 If the mode is BLKmode then we may return TARGET itself.
5349 It turns out that in BLKmode it doesn't cause a problem.
5350 because C has no operators that could combine two different
5351 assignments into the same BLKmode object with different values
5352 with no sequence point. Will other languages need this to
5355 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5356 stack, and block moves may need to be treated specially.
5358 If NONTEMPORAL is true, try using a nontemporal store instruction.
5360 If REVERSE is true, the store is to be done in reverse order.
5362 If BTARGET is not NULL then computed bounds of EXP are
5363 associated with BTARGET. */
5366 store_expr_with_bounds (tree exp
, rtx target
, int call_param_p
,
5367 bool nontemporal
, bool reverse
, tree btarget
)
5370 rtx alt_rtl
= NULL_RTX
;
5371 location_t loc
= curr_insn_location ();
5373 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5375 /* C++ can generate ?: expressions with a throw expression in one
5376 branch and an rvalue in the other. Here, we resolve attempts to
5377 store the throw expression's nonexistent result. */
5378 gcc_assert (!call_param_p
);
5379 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5382 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5384 /* Perform first part of compound expression, then assign from second
5386 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5387 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5388 return store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
,
5389 call_param_p
, nontemporal
, reverse
,
5392 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5394 /* For conditional expression, get safe form of the target. Then
5395 test the condition, doing the appropriate assignment on either
5396 side. This avoids the creation of unnecessary temporaries.
5397 For non-BLKmode, it is more efficient not to do this. */
5399 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
5401 do_pending_stack_adjust ();
5403 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5404 store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5405 nontemporal
, reverse
, btarget
);
5406 emit_jump_insn (targetm
.gen_jump (lab2
));
5409 store_expr_with_bounds (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5410 nontemporal
, reverse
, btarget
);
5416 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5417 /* If this is a scalar in a register that is stored in a wider mode
5418 than the declared mode, compute the result into its declared mode
5419 and then convert to the wider mode. Our value is the computed
5422 rtx inner_target
= 0;
5424 /* We can do the conversion inside EXP, which will often result
5425 in some optimizations. Do the conversion in two steps: first
5426 change the signedness, if needed, then the extend. But don't
5427 do this if the type of EXP is a subtype of something else
5428 since then the conversion might involve more than just
5429 converting modes. */
5430 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5431 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5432 && GET_MODE_PRECISION (GET_MODE (target
))
5433 == TYPE_PRECISION (TREE_TYPE (exp
)))
5435 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
5436 TYPE_UNSIGNED (TREE_TYPE (exp
))))
5438 /* Some types, e.g. Fortran's logical*4, won't have a signed
5439 version, so use the mode instead. */
5441 = (signed_or_unsigned_type_for
5442 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
5444 ntype
= lang_hooks
.types
.type_for_mode
5445 (TYPE_MODE (TREE_TYPE (exp
)),
5446 SUBREG_PROMOTED_SIGN (target
));
5448 exp
= fold_convert_loc (loc
, ntype
, exp
);
5451 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5452 (GET_MODE (SUBREG_REG (target
)),
5453 SUBREG_PROMOTED_SIGN (target
)),
5456 inner_target
= SUBREG_REG (target
);
5459 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5460 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5462 /* Handle bounds returned by call. */
5463 if (TREE_CODE (exp
) == CALL_EXPR
)
5466 chkp_split_slot (temp
, &temp
, &bounds
);
5467 if (bounds
&& btarget
)
5469 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5470 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5471 chkp_set_rtl_bounds (btarget
, tmp
);
5475 /* If TEMP is a VOIDmode constant, use convert_modes to make
5476 sure that we properly convert it. */
5477 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5479 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5480 temp
, SUBREG_PROMOTED_SIGN (target
));
5481 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5482 GET_MODE (target
), temp
,
5483 SUBREG_PROMOTED_SIGN (target
));
5486 convert_move (SUBREG_REG (target
), temp
,
5487 SUBREG_PROMOTED_SIGN (target
));
5491 else if ((TREE_CODE (exp
) == STRING_CST
5492 || (TREE_CODE (exp
) == MEM_REF
5493 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5494 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5496 && integer_zerop (TREE_OPERAND (exp
, 1))))
5497 && !nontemporal
&& !call_param_p
5500 /* Optimize initialization of an array with a STRING_CST. */
5501 HOST_WIDE_INT exp_len
, str_copy_len
;
5503 tree str
= TREE_CODE (exp
) == STRING_CST
5504 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5506 exp_len
= int_expr_size (exp
);
5510 if (TREE_STRING_LENGTH (str
) <= 0)
5513 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5514 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5517 str_copy_len
= TREE_STRING_LENGTH (str
);
5518 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5519 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5521 str_copy_len
+= STORE_MAX_PIECES
- 1;
5522 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5524 str_copy_len
= MIN (str_copy_len
, exp_len
);
5525 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5526 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5527 MEM_ALIGN (target
), false))
5532 dest_mem
= store_by_pieces (dest_mem
,
5533 str_copy_len
, builtin_strncpy_read_str
,
5535 TREE_STRING_POINTER (str
)),
5536 MEM_ALIGN (target
), false,
5537 exp_len
> str_copy_len
? 1 : 0);
5538 if (exp_len
> str_copy_len
)
5539 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5540 GEN_INT (exp_len
- str_copy_len
),
5549 /* If we want to use a nontemporal or a reverse order store, force the
5550 value into a register first. */
5551 tmp_target
= nontemporal
|| reverse
? NULL_RTX
: target
;
5552 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5554 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5557 /* Handle bounds returned by call. */
5558 if (TREE_CODE (exp
) == CALL_EXPR
)
5561 chkp_split_slot (temp
, &temp
, &bounds
);
5562 if (bounds
&& btarget
)
5564 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5565 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5566 chkp_set_rtl_bounds (btarget
, tmp
);
5571 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5572 the same as that of TARGET, adjust the constant. This is needed, for
5573 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5574 only a word-sized value. */
5575 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5576 && TREE_CODE (exp
) != ERROR_MARK
5577 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5578 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5579 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5581 /* If value was not generated in the target, store it there.
5582 Convert the value to TARGET's type first if necessary and emit the
5583 pending incrementations that have been queued when expanding EXP.
5584 Note that we cannot emit the whole queue blindly because this will
5585 effectively disable the POST_INC optimization later.
5587 If TEMP and TARGET compare equal according to rtx_equal_p, but
5588 one or both of them are volatile memory refs, we have to distinguish
5590 - expand_expr has used TARGET. In this case, we must not generate
5591 another copy. This can be detected by TARGET being equal according
5593 - expand_expr has not used TARGET - that means that the source just
5594 happens to have the same RTX form. Since temp will have been created
5595 by expand_expr, it will compare unequal according to == .
5596 We must generate a copy in this case, to reach the correct number
5597 of volatile memory references. */
5599 if ((! rtx_equal_p (temp
, target
)
5600 || (temp
!= target
&& (side_effects_p (temp
)
5601 || side_effects_p (target
))))
5602 && TREE_CODE (exp
) != ERROR_MARK
5603 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5604 but TARGET is not valid memory reference, TEMP will differ
5605 from TARGET although it is really the same location. */
5607 && rtx_equal_p (alt_rtl
, target
)
5608 && !side_effects_p (alt_rtl
)
5609 && !side_effects_p (target
))
5610 /* If there's nothing to copy, don't bother. Don't call
5611 expr_size unless necessary, because some front-ends (C++)
5612 expr_size-hook must not be given objects that are not
5613 supposed to be bit-copied or bit-initialized. */
5614 && expr_size (exp
) != const0_rtx
)
5616 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5618 if (GET_MODE (target
) == BLKmode
)
5620 /* Handle calls that return BLKmode values in registers. */
5621 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5622 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5624 store_bit_field (target
,
5625 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5626 0, 0, 0, GET_MODE (temp
), temp
, reverse
);
5629 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5632 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5634 /* Handle copying a string constant into an array. The string
5635 constant may be shorter than the array. So copy just the string's
5636 actual length, and clear the rest. First get the size of the data
5637 type of the string, which is actually the size of the target. */
5638 rtx size
= expr_size (exp
);
5640 if (CONST_INT_P (size
)
5641 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5642 emit_block_move (target
, temp
, size
,
5644 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5647 machine_mode pointer_mode
5648 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5649 machine_mode address_mode
= get_address_mode (target
);
5651 /* Compute the size of the data to copy from the string. */
5653 = size_binop_loc (loc
, MIN_EXPR
,
5654 make_tree (sizetype
, size
),
5655 size_int (TREE_STRING_LENGTH (exp
)));
5657 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5659 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5660 rtx_code_label
*label
= 0;
5662 /* Copy that much. */
5663 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5664 TYPE_UNSIGNED (sizetype
));
5665 emit_block_move (target
, temp
, copy_size_rtx
,
5667 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5669 /* Figure out how much is left in TARGET that we have to clear.
5670 Do all calculations in pointer_mode. */
5671 if (CONST_INT_P (copy_size_rtx
))
5673 size
= plus_constant (address_mode
, size
,
5674 -INTVAL (copy_size_rtx
));
5675 target
= adjust_address (target
, BLKmode
,
5676 INTVAL (copy_size_rtx
));
5680 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5681 copy_size_rtx
, NULL_RTX
, 0,
5684 if (GET_MODE (copy_size_rtx
) != address_mode
)
5685 copy_size_rtx
= convert_to_mode (address_mode
,
5687 TYPE_UNSIGNED (sizetype
));
5689 target
= offset_address (target
, copy_size_rtx
,
5690 highest_pow2_factor (copy_size
));
5691 label
= gen_label_rtx ();
5692 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5693 GET_MODE (size
), 0, label
);
5696 if (size
!= const0_rtx
)
5697 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5703 /* Handle calls that return values in multiple non-contiguous locations.
5704 The Irix 6 ABI has examples of this. */
5705 else if (GET_CODE (target
) == PARALLEL
)
5707 if (GET_CODE (temp
) == PARALLEL
)
5708 emit_group_move (target
, temp
);
5710 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5711 int_size_in_bytes (TREE_TYPE (exp
)));
5713 else if (GET_CODE (temp
) == PARALLEL
)
5714 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5715 int_size_in_bytes (TREE_TYPE (exp
)));
5716 else if (GET_MODE (temp
) == BLKmode
)
5717 emit_block_move (target
, temp
, expr_size (exp
),
5719 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5720 /* If we emit a nontemporal store, there is nothing else to do. */
5721 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5726 temp
= flip_storage_order (GET_MODE (target
), temp
);
5727 temp
= force_operand (temp
, target
);
5729 emit_move_insn (target
, temp
);
5736 /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
5738 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
,
5741 return store_expr_with_bounds (exp
, target
, call_param_p
, nontemporal
,
5745 /* Return true if field F of structure TYPE is a flexible array. */
5748 flexible_array_member_p (const_tree f
, const_tree type
)
5753 return (DECL_CHAIN (f
) == NULL
5754 && TREE_CODE (tf
) == ARRAY_TYPE
5756 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5757 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5758 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5759 && int_size_in_bytes (type
) >= 0);
5762 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5763 must have in order for it to completely initialize a value of type TYPE.
5764 Return -1 if the number isn't known.
5766 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5768 static HOST_WIDE_INT
5769 count_type_elements (const_tree type
, bool for_ctor_p
)
5771 switch (TREE_CODE (type
))
5777 nelts
= array_type_nelts (type
);
5778 if (nelts
&& tree_fits_uhwi_p (nelts
))
5780 unsigned HOST_WIDE_INT n
;
5782 n
= tree_to_uhwi (nelts
) + 1;
5783 if (n
== 0 || for_ctor_p
)
5786 return n
* count_type_elements (TREE_TYPE (type
), false);
5788 return for_ctor_p
? -1 : 1;
5793 unsigned HOST_WIDE_INT n
;
5797 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5798 if (TREE_CODE (f
) == FIELD_DECL
)
5801 n
+= count_type_elements (TREE_TYPE (f
), false);
5802 else if (!flexible_array_member_p (f
, type
))
5803 /* Don't count flexible arrays, which are not supposed
5804 to be initialized. */
5812 case QUAL_UNION_TYPE
:
5817 gcc_assert (!for_ctor_p
);
5818 /* Estimate the number of scalars in each field and pick the
5819 maximum. Other estimates would do instead; the idea is simply
5820 to make sure that the estimate is not sensitive to the ordering
5823 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5824 if (TREE_CODE (f
) == FIELD_DECL
)
5826 m
= count_type_elements (TREE_TYPE (f
), false);
5827 /* If the field doesn't span the whole union, add an extra
5828 scalar for the rest. */
5829 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5830 TYPE_SIZE (type
)) != 1)
5842 return TYPE_VECTOR_SUBPARTS (type
);
5846 case FIXED_POINT_TYPE
:
5851 case REFERENCE_TYPE
:
5867 /* Helper for categorize_ctor_elements. Identical interface. */
5870 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5871 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5873 unsigned HOST_WIDE_INT idx
;
5874 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5875 tree value
, purpose
, elt_type
;
5877 /* Whether CTOR is a valid constant initializer, in accordance with what
5878 initializer_constant_valid_p does. If inferred from the constructor
5879 elements, true until proven otherwise. */
5880 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5881 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5886 elt_type
= NULL_TREE
;
5888 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5890 HOST_WIDE_INT mult
= 1;
5892 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5894 tree lo_index
= TREE_OPERAND (purpose
, 0);
5895 tree hi_index
= TREE_OPERAND (purpose
, 1);
5897 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5898 mult
= (tree_to_uhwi (hi_index
)
5899 - tree_to_uhwi (lo_index
) + 1);
5902 elt_type
= TREE_TYPE (value
);
5904 switch (TREE_CODE (value
))
5908 HOST_WIDE_INT nz
= 0, ic
= 0;
5910 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5913 nz_elts
+= mult
* nz
;
5914 init_elts
+= mult
* ic
;
5916 if (const_from_elts_p
&& const_p
)
5917 const_p
= const_elt_p
;
5924 if (!initializer_zerop (value
))
5930 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5931 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5935 if (!initializer_zerop (TREE_REALPART (value
)))
5937 if (!initializer_zerop (TREE_IMAGPART (value
)))
5945 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5947 tree v
= VECTOR_CST_ELT (value
, i
);
5948 if (!initializer_zerop (v
))
5957 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5958 nz_elts
+= mult
* tc
;
5959 init_elts
+= mult
* tc
;
5961 if (const_from_elts_p
&& const_p
)
5963 = initializer_constant_valid_p (value
,
5965 TYPE_REVERSE_STORAGE_ORDER
5973 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5974 num_fields
, elt_type
))
5975 *p_complete
= false;
5977 *p_nz_elts
+= nz_elts
;
5978 *p_init_elts
+= init_elts
;
5983 /* Examine CTOR to discover:
5984 * how many scalar fields are set to nonzero values,
5985 and place it in *P_NZ_ELTS;
5986 * how many scalar fields in total are in CTOR,
5987 and place it in *P_ELT_COUNT.
5988 * whether the constructor is complete -- in the sense that every
5989 meaningful byte is explicitly given a value --
5990 and place it in *P_COMPLETE.
5992 Return whether or not CTOR is a valid static constant initializer, the same
5993 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5996 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5997 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
6003 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
6006 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
6007 of which had type LAST_TYPE. Each element was itself a complete
6008 initializer, in the sense that every meaningful byte was explicitly
6009 given a value. Return true if the same is true for the constructor
6013 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
6014 const_tree last_type
)
6016 if (TREE_CODE (type
) == UNION_TYPE
6017 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
6022 gcc_assert (num_elts
== 1 && last_type
);
6024 /* ??? We could look at each element of the union, and find the
6025 largest element. Which would avoid comparing the size of the
6026 initialized element against any tail padding in the union.
6027 Doesn't seem worth the effort... */
6028 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
6031 return count_type_elements (type
, true) == num_elts
;
6034 /* Return 1 if EXP contains mostly (3/4) zeros. */
6037 mostly_zeros_p (const_tree exp
)
6039 if (TREE_CODE (exp
) == CONSTRUCTOR
)
6041 HOST_WIDE_INT nz_elts
, init_elts
;
6044 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
6045 return !complete_p
|| nz_elts
< init_elts
/ 4;
6048 return initializer_zerop (exp
);
6051 /* Return 1 if EXP contains all zeros. */
6054 all_zeros_p (const_tree exp
)
6056 if (TREE_CODE (exp
) == CONSTRUCTOR
)
6058 HOST_WIDE_INT nz_elts
, init_elts
;
6061 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
6062 return nz_elts
== 0;
6065 return initializer_zerop (exp
);
6068 /* Helper function for store_constructor.
6069 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
6070 CLEARED is as for store_constructor.
6071 ALIAS_SET is the alias set to use for any stores.
6072 If REVERSE is true, the store is to be done in reverse order.
6074 This provides a recursive shortcut back to store_constructor when it isn't
6075 necessary to go through store_field. This is so that we can pass through
6076 the cleared field to let store_constructor know that we may not have to
6077 clear a substructure if the outer structure has already been cleared. */
6080 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
6081 HOST_WIDE_INT bitpos
,
6082 unsigned HOST_WIDE_INT bitregion_start
,
6083 unsigned HOST_WIDE_INT bitregion_end
,
6085 tree exp
, int cleared
,
6086 alias_set_type alias_set
, bool reverse
)
6088 if (TREE_CODE (exp
) == CONSTRUCTOR
6089 /* We can only call store_constructor recursively if the size and
6090 bit position are on a byte boundary. */
6091 && bitpos
% BITS_PER_UNIT
== 0
6092 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
6093 /* If we have a nonzero bitpos for a register target, then we just
6094 let store_field do the bitfield handling. This is unlikely to
6095 generate unnecessary clear instructions anyways. */
6096 && (bitpos
== 0 || MEM_P (target
)))
6100 = adjust_address (target
,
6101 GET_MODE (target
) == BLKmode
6103 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
6104 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6107 /* Update the alias set, if required. */
6108 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
6109 && MEM_ALIAS_SET (target
) != 0)
6111 target
= copy_rtx (target
);
6112 set_mem_alias_set (target
, alias_set
);
6115 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
,
6119 store_field (target
, bitsize
, bitpos
, bitregion_start
, bitregion_end
, mode
,
6120 exp
, alias_set
, false, reverse
);
6124 /* Returns the number of FIELD_DECLs in TYPE. */
6127 fields_length (const_tree type
)
6129 tree t
= TYPE_FIELDS (type
);
6132 for (; t
; t
= DECL_CHAIN (t
))
6133 if (TREE_CODE (t
) == FIELD_DECL
)
6140 /* Store the value of constructor EXP into the rtx TARGET.
6141 TARGET is either a REG or a MEM; we know it cannot conflict, since
6142 safe_from_p has been called.
6143 CLEARED is true if TARGET is known to have been zero'd.
6144 SIZE is the number of bytes of TARGET we are allowed to modify: this
6145 may not be the same as the size of EXP if we are assigning to a field
6146 which has been packed to exclude padding bits.
6147 If REVERSE is true, the store is to be done in reverse order. */
6150 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
,
6153 tree type
= TREE_TYPE (exp
);
6154 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
6155 HOST_WIDE_INT bitregion_end
= size
> 0 ? size
* BITS_PER_UNIT
- 1 : 0;
6157 switch (TREE_CODE (type
))
6161 case QUAL_UNION_TYPE
:
6163 unsigned HOST_WIDE_INT idx
;
6166 /* The storage order is specified for every aggregate type. */
6167 reverse
= TYPE_REVERSE_STORAGE_ORDER (type
);
6169 /* If size is zero or the target is already cleared, do nothing. */
6170 if (size
== 0 || cleared
)
6172 /* We either clear the aggregate or indicate the value is dead. */
6173 else if ((TREE_CODE (type
) == UNION_TYPE
6174 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
6175 && ! CONSTRUCTOR_ELTS (exp
))
6176 /* If the constructor is empty, clear the union. */
6178 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
6182 /* If we are building a static constructor into a register,
6183 set the initial value as zero so we can fold the value into
6184 a constant. But if more than one register is involved,
6185 this probably loses. */
6186 else if (REG_P (target
) && TREE_STATIC (exp
)
6187 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
6189 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6193 /* If the constructor has fewer fields than the structure or
6194 if we are initializing the structure to mostly zeros, clear
6195 the whole structure first. Don't do this if TARGET is a
6196 register whose mode size isn't equal to SIZE since
6197 clear_storage can't handle this case. */
6199 && (((int) CONSTRUCTOR_NELTS (exp
) != fields_length (type
))
6200 || mostly_zeros_p (exp
))
6202 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
6205 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6209 if (REG_P (target
) && !cleared
)
6210 emit_clobber (target
);
6212 /* Store each element of the constructor into the
6213 corresponding field of TARGET. */
6214 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
6217 HOST_WIDE_INT bitsize
;
6218 HOST_WIDE_INT bitpos
= 0;
6220 rtx to_rtx
= target
;
6222 /* Just ignore missing fields. We cleared the whole
6223 structure, above, if any fields are missing. */
6227 if (cleared
&& initializer_zerop (value
))
6230 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
6231 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
6235 mode
= DECL_MODE (field
);
6236 if (DECL_BIT_FIELD (field
))
6239 offset
= DECL_FIELD_OFFSET (field
);
6240 if (tree_fits_shwi_p (offset
)
6241 && tree_fits_shwi_p (bit_position (field
)))
6243 bitpos
= int_bit_position (field
);
6249 /* If this initializes a field that is smaller than a
6250 word, at the start of a word, try to widen it to a full
6251 word. This special case allows us to output C++ member
6252 function initializations in a form that the optimizers
6254 if (WORD_REGISTER_OPERATIONS
6256 && bitsize
< BITS_PER_WORD
6257 && bitpos
% BITS_PER_WORD
== 0
6258 && GET_MODE_CLASS (mode
) == MODE_INT
6259 && TREE_CODE (value
) == INTEGER_CST
6261 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6263 tree type
= TREE_TYPE (value
);
6265 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6267 type
= lang_hooks
.types
.type_for_mode
6268 (word_mode
, TYPE_UNSIGNED (type
));
6269 value
= fold_convert (type
, value
);
6270 /* Make sure the bits beyond the original bitsize are zero
6271 so that we can correctly avoid extra zeroing stores in
6272 later constructor elements. */
6274 = wide_int_to_tree (type
, wi::mask (bitsize
, false,
6276 value
= fold_build2 (BIT_AND_EXPR
, type
, value
, bitsize_mask
);
6279 if (BYTES_BIG_ENDIAN
)
6281 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6282 build_int_cst (type
,
6283 BITS_PER_WORD
- bitsize
));
6284 bitsize
= BITS_PER_WORD
;
6288 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6289 && DECL_NONADDRESSABLE_P (field
))
6291 to_rtx
= copy_rtx (to_rtx
);
6292 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6295 store_constructor_field (to_rtx
, bitsize
, bitpos
,
6296 0, bitregion_end
, mode
,
6298 get_alias_set (TREE_TYPE (field
)),
6306 unsigned HOST_WIDE_INT i
;
6309 tree elttype
= TREE_TYPE (type
);
6311 HOST_WIDE_INT minelt
= 0;
6312 HOST_WIDE_INT maxelt
= 0;
6314 /* The storage order is specified for every aggregate type. */
6315 reverse
= TYPE_REVERSE_STORAGE_ORDER (type
);
6317 domain
= TYPE_DOMAIN (type
);
6318 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6319 && TYPE_MAX_VALUE (domain
)
6320 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6321 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6323 /* If we have constant bounds for the range of the type, get them. */
6326 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6327 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6330 /* If the constructor has fewer elements than the array, clear
6331 the whole array first. Similarly if this is static
6332 constructor of a non-BLKmode object. */
6335 else if (REG_P (target
) && TREE_STATIC (exp
))
6339 unsigned HOST_WIDE_INT idx
;
6341 HOST_WIDE_INT count
= 0, zero_count
= 0;
6342 need_to_clear
= ! const_bounds_p
;
6344 /* This loop is a more accurate version of the loop in
6345 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6346 is also needed to check for missing elements. */
6347 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6349 HOST_WIDE_INT this_node_count
;
6354 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6356 tree lo_index
= TREE_OPERAND (index
, 0);
6357 tree hi_index
= TREE_OPERAND (index
, 1);
6359 if (! tree_fits_uhwi_p (lo_index
)
6360 || ! tree_fits_uhwi_p (hi_index
))
6366 this_node_count
= (tree_to_uhwi (hi_index
)
6367 - tree_to_uhwi (lo_index
) + 1);
6370 this_node_count
= 1;
6372 count
+= this_node_count
;
6373 if (mostly_zeros_p (value
))
6374 zero_count
+= this_node_count
;
6377 /* Clear the entire array first if there are any missing
6378 elements, or if the incidence of zero elements is >=
6381 && (count
< maxelt
- minelt
+ 1
6382 || 4 * zero_count
>= 3 * count
))
6386 if (need_to_clear
&& size
> 0)
6389 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6391 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6395 if (!cleared
&& REG_P (target
))
6396 /* Inform later passes that the old value is dead. */
6397 emit_clobber (target
);
6399 /* Store each element of the constructor into the
6400 corresponding element of TARGET, determined by counting the
6402 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6405 HOST_WIDE_INT bitsize
;
6406 HOST_WIDE_INT bitpos
;
6407 rtx xtarget
= target
;
6409 if (cleared
&& initializer_zerop (value
))
6412 mode
= TYPE_MODE (elttype
);
6413 if (mode
== BLKmode
)
6414 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6415 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6418 bitsize
= GET_MODE_BITSIZE (mode
);
6420 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6422 tree lo_index
= TREE_OPERAND (index
, 0);
6423 tree hi_index
= TREE_OPERAND (index
, 1);
6424 rtx index_r
, pos_rtx
;
6425 HOST_WIDE_INT lo
, hi
, count
;
6428 /* If the range is constant and "small", unroll the loop. */
6430 && tree_fits_shwi_p (lo_index
)
6431 && tree_fits_shwi_p (hi_index
)
6432 && (lo
= tree_to_shwi (lo_index
),
6433 hi
= tree_to_shwi (hi_index
),
6434 count
= hi
- lo
+ 1,
6437 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6438 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6441 lo
-= minelt
; hi
-= minelt
;
6442 for (; lo
<= hi
; lo
++)
6444 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6447 && !MEM_KEEP_ALIAS_SET_P (target
)
6448 && TREE_CODE (type
) == ARRAY_TYPE
6449 && TYPE_NONALIASED_COMPONENT (type
))
6451 target
= copy_rtx (target
);
6452 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6455 store_constructor_field
6456 (target
, bitsize
, bitpos
, 0, bitregion_end
,
6457 mode
, value
, cleared
,
6458 get_alias_set (elttype
), reverse
);
6463 rtx_code_label
*loop_start
= gen_label_rtx ();
6464 rtx_code_label
*loop_end
= gen_label_rtx ();
6467 expand_normal (hi_index
);
6469 index
= build_decl (EXPR_LOCATION (exp
),
6470 VAR_DECL
, NULL_TREE
, domain
);
6471 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6472 SET_DECL_RTL (index
, index_r
);
6473 store_expr (lo_index
, index_r
, 0, false, reverse
);
6475 /* Build the head of the loop. */
6476 do_pending_stack_adjust ();
6477 emit_label (loop_start
);
6479 /* Assign value to element index. */
6481 fold_convert (ssizetype
,
6482 fold_build2 (MINUS_EXPR
,
6485 TYPE_MIN_VALUE (domain
)));
6488 size_binop (MULT_EXPR
, position
,
6489 fold_convert (ssizetype
,
6490 TYPE_SIZE_UNIT (elttype
)));
6492 pos_rtx
= expand_normal (position
);
6493 xtarget
= offset_address (target
, pos_rtx
,
6494 highest_pow2_factor (position
));
6495 xtarget
= adjust_address (xtarget
, mode
, 0);
6496 if (TREE_CODE (value
) == CONSTRUCTOR
)
6497 store_constructor (value
, xtarget
, cleared
,
6498 bitsize
/ BITS_PER_UNIT
, reverse
);
6500 store_expr (value
, xtarget
, 0, false, reverse
);
6502 /* Generate a conditional jump to exit the loop. */
6503 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6505 jumpif (exit_cond
, loop_end
, -1);
6507 /* Update the loop counter, and jump to the head of
6509 expand_assignment (index
,
6510 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6511 index
, integer_one_node
),
6514 emit_jump (loop_start
);
6516 /* Build the end of the loop. */
6517 emit_label (loop_end
);
6520 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6521 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6526 index
= ssize_int (1);
6529 index
= fold_convert (ssizetype
,
6530 fold_build2 (MINUS_EXPR
,
6533 TYPE_MIN_VALUE (domain
)));
6536 size_binop (MULT_EXPR
, index
,
6537 fold_convert (ssizetype
,
6538 TYPE_SIZE_UNIT (elttype
)));
6539 xtarget
= offset_address (target
,
6540 expand_normal (position
),
6541 highest_pow2_factor (position
));
6542 xtarget
= adjust_address (xtarget
, mode
, 0);
6543 store_expr (value
, xtarget
, 0, false, reverse
);
6548 bitpos
= ((tree_to_shwi (index
) - minelt
)
6549 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6551 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6553 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6554 && TREE_CODE (type
) == ARRAY_TYPE
6555 && TYPE_NONALIASED_COMPONENT (type
))
6557 target
= copy_rtx (target
);
6558 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6560 store_constructor_field (target
, bitsize
, bitpos
, 0,
6561 bitregion_end
, mode
, value
,
6562 cleared
, get_alias_set (elttype
),
6571 unsigned HOST_WIDE_INT idx
;
6572 constructor_elt
*ce
;
6575 int icode
= CODE_FOR_nothing
;
6576 tree elttype
= TREE_TYPE (type
);
6577 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6578 machine_mode eltmode
= TYPE_MODE (elttype
);
6579 HOST_WIDE_INT bitsize
;
6580 HOST_WIDE_INT bitpos
;
6581 rtvec vector
= NULL
;
6583 alias_set_type alias
;
6585 gcc_assert (eltmode
!= BLKmode
);
6587 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6588 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6590 machine_mode mode
= GET_MODE (target
);
6592 icode
= (int) optab_handler (vec_init_optab
, mode
);
6593 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6594 if (icode
!= CODE_FOR_nothing
)
6598 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6599 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6601 icode
= CODE_FOR_nothing
;
6605 if (icode
!= CODE_FOR_nothing
)
6609 vector
= rtvec_alloc (n_elts
);
6610 for (i
= 0; i
< n_elts
; i
++)
6611 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6615 /* If the constructor has fewer elements than the vector,
6616 clear the whole array first. Similarly if this is static
6617 constructor of a non-BLKmode object. */
6620 else if (REG_P (target
) && TREE_STATIC (exp
))
6624 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6627 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6629 int n_elts_here
= tree_to_uhwi
6630 (int_const_binop (TRUNC_DIV_EXPR
,
6631 TYPE_SIZE (TREE_TYPE (value
)),
6632 TYPE_SIZE (elttype
)));
6634 count
+= n_elts_here
;
6635 if (mostly_zeros_p (value
))
6636 zero_count
+= n_elts_here
;
6639 /* Clear the entire vector first if there are any missing elements,
6640 or if the incidence of zero elements is >= 75%. */
6641 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6644 if (need_to_clear
&& size
> 0 && !vector
)
6647 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6649 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6653 /* Inform later passes that the old value is dead. */
6654 if (!cleared
&& !vector
&& REG_P (target
))
6655 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6658 alias
= MEM_ALIAS_SET (target
);
6660 alias
= get_alias_set (elttype
);
6662 /* Store each element of the constructor into the corresponding
6663 element of TARGET, determined by counting the elements. */
6664 for (idx
= 0, i
= 0;
6665 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6666 idx
++, i
+= bitsize
/ elt_size
)
6668 HOST_WIDE_INT eltpos
;
6669 tree value
= ce
->value
;
6671 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6672 if (cleared
&& initializer_zerop (value
))
6676 eltpos
= tree_to_uhwi (ce
->index
);
6682 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6684 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6685 RTVEC_ELT (vector
, eltpos
)
6686 = expand_normal (value
);
6690 machine_mode value_mode
=
6691 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6692 ? TYPE_MODE (TREE_TYPE (value
))
6694 bitpos
= eltpos
* elt_size
;
6695 store_constructor_field (target
, bitsize
, bitpos
, 0,
6696 bitregion_end
, value_mode
,
6697 value
, cleared
, alias
, reverse
);
6702 emit_insn (GEN_FCN (icode
)
6704 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6713 /* Store the value of EXP (an expression tree)
6714 into a subfield of TARGET which has mode MODE and occupies
6715 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6716 If MODE is VOIDmode, it means that we are storing into a bit-field.
6718 BITREGION_START is bitpos of the first bitfield in this region.
6719 BITREGION_END is the bitpos of the ending bitfield in this region.
6720 These two fields are 0, if the C++ memory model does not apply,
6721 or we are not interested in keeping track of bitfield regions.
6723 Always return const0_rtx unless we have something particular to
6726 ALIAS_SET is the alias set for the destination. This value will
6727 (in general) be different from that for TARGET, since TARGET is a
6728 reference to the containing structure.
6730 If NONTEMPORAL is true, try generating a nontemporal store.
6732 If REVERSE is true, the store is to be done in reverse order. */
6735 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6736 unsigned HOST_WIDE_INT bitregion_start
,
6737 unsigned HOST_WIDE_INT bitregion_end
,
6738 machine_mode mode
, tree exp
,
6739 alias_set_type alias_set
, bool nontemporal
, bool reverse
)
6741 if (TREE_CODE (exp
) == ERROR_MARK
)
6744 /* If we have nothing to store, do nothing unless the expression has
6747 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6749 if (GET_CODE (target
) == CONCAT
)
6751 /* We're storing into a struct containing a single __complex. */
6753 gcc_assert (!bitpos
);
6754 return store_expr (exp
, target
, 0, nontemporal
, reverse
);
6757 /* If the structure is in a register or if the component
6758 is a bit field, we cannot use addressing to access it.
6759 Use bit-field techniques or SUBREG to store in it. */
6761 if (mode
== VOIDmode
6762 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6763 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6764 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6766 || GET_CODE (target
) == SUBREG
6767 /* If the field isn't aligned enough to store as an ordinary memref,
6768 store it as a bit field. */
6770 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6771 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6772 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6773 || (bitpos
% BITS_PER_UNIT
!= 0)))
6774 || (bitsize
>= 0 && mode
!= BLKmode
6775 && GET_MODE_BITSIZE (mode
) > bitsize
)
6776 /* If the RHS and field are a constant size and the size of the
6777 RHS isn't the same size as the bitfield, we must use bitfield
6780 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6781 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0
6782 /* Except for initialization of full bytes from a CONSTRUCTOR, which
6783 we will handle specially below. */
6784 && !(TREE_CODE (exp
) == CONSTRUCTOR
6785 && bitsize
% BITS_PER_UNIT
== 0)
6786 /* And except for bitwise copying of TREE_ADDRESSABLE types,
6787 where the FIELD_DECL has the right bitsize, but TREE_TYPE (exp)
6788 includes some extra padding. store_expr / expand_expr will in
6789 that case call get_inner_reference that will have the bitsize
6790 we check here and thus the block move will not clobber the
6791 padding that shouldn't be clobbered. In the future we could
6792 replace the TREE_ADDRESSABLE check with a check that
6793 get_base_address needs to live in memory. */
6794 && (!TREE_ADDRESSABLE (TREE_TYPE (exp
))
6795 || TREE_CODE (exp
) != COMPONENT_REF
6796 || TREE_CODE (DECL_SIZE (TREE_OPERAND (exp
, 1))) != INTEGER_CST
6797 || (bitsize
% BITS_PER_UNIT
!= 0)
6798 || (bitpos
% BITS_PER_UNIT
!= 0)
6799 || (compare_tree_int (DECL_SIZE (TREE_OPERAND (exp
, 1)), bitsize
)
6801 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6802 decl we must use bitfield operations. */
6804 && TREE_CODE (exp
) == MEM_REF
6805 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6806 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6807 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6808 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6813 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6814 implies a mask operation. If the precision is the same size as
6815 the field we're storing into, that mask is redundant. This is
6816 particularly common with bit field assignments generated by the
6818 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6821 tree type
= TREE_TYPE (exp
);
6822 if (INTEGRAL_TYPE_P (type
)
6823 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6824 && bitsize
== TYPE_PRECISION (type
))
6826 tree op
= gimple_assign_rhs1 (nop_def
);
6827 type
= TREE_TYPE (op
);
6828 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6833 temp
= expand_normal (exp
);
6835 /* Handle calls that return values in multiple non-contiguous locations.
6836 The Irix 6 ABI has examples of this. */
6837 if (GET_CODE (temp
) == PARALLEL
)
6839 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6840 machine_mode temp_mode
6841 = smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6842 rtx temp_target
= gen_reg_rtx (temp_mode
);
6843 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6847 /* Handle calls that return BLKmode values in registers. */
6848 else if (mode
== BLKmode
&& REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6850 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6851 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6855 /* If the value has aggregate type and an integral mode then, if BITSIZE
6856 is narrower than this mode and this is for big-endian data, we first
6857 need to put the value into the low-order bits for store_bit_field,
6858 except when MODE is BLKmode and BITSIZE larger than the word size
6859 (see the handling of fields larger than a word in store_bit_field).
6860 Moreover, the field may be not aligned on a byte boundary; in this
6861 case, if it has reverse storage order, it needs to be accessed as a
6862 scalar field with reverse storage order and we must first put the
6863 value into target order. */
6864 if (AGGREGATE_TYPE_P (TREE_TYPE (exp
))
6865 && GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
)
6867 HOST_WIDE_INT size
= GET_MODE_BITSIZE (GET_MODE (temp
));
6869 reverse
= TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (exp
));
6872 temp
= flip_storage_order (GET_MODE (temp
), temp
);
6875 && reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
6876 && !(mode
== BLKmode
&& bitsize
> BITS_PER_WORD
))
6877 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6878 size
- bitsize
, NULL_RTX
, 1);
6881 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6882 if (mode
!= VOIDmode
&& mode
!= BLKmode
6883 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6884 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6886 /* If the mode of TEMP and TARGET is BLKmode, both must be in memory
6887 and BITPOS must be aligned on a byte boundary. If so, we simply do
6888 a block copy. Likewise for a BLKmode-like TARGET. */
6889 if (GET_MODE (temp
) == BLKmode
6890 && (GET_MODE (target
) == BLKmode
6892 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6893 && (bitpos
% BITS_PER_UNIT
) == 0
6894 && (bitsize
% BITS_PER_UNIT
) == 0)))
6896 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6897 && (bitpos
% BITS_PER_UNIT
) == 0);
6899 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6900 emit_block_move (target
, temp
,
6901 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6908 /* If the mode of TEMP is still BLKmode and BITSIZE not larger than the
6909 word size, we need to load the value (see again store_bit_field). */
6910 if (GET_MODE (temp
) == BLKmode
&& bitsize
<= BITS_PER_WORD
)
6912 machine_mode temp_mode
= smallest_mode_for_size (bitsize
, MODE_INT
);
6913 temp
= extract_bit_field (temp
, bitsize
, 0, 1, NULL_RTX
, temp_mode
,
6917 /* Store the value in the bitfield. */
6918 store_bit_field (target
, bitsize
, bitpos
,
6919 bitregion_start
, bitregion_end
,
6920 mode
, temp
, reverse
);
6926 /* Now build a reference to just the desired component. */
6927 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6929 if (to_rtx
== target
)
6930 to_rtx
= copy_rtx (to_rtx
);
6932 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6933 set_mem_alias_set (to_rtx
, alias_set
);
6935 /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
6936 into a target smaller than its type; handle that case now. */
6937 if (TREE_CODE (exp
) == CONSTRUCTOR
&& bitsize
>= 0)
6939 gcc_assert (bitsize
% BITS_PER_UNIT
== 0);
6940 store_constructor (exp
, to_rtx
, 0, bitsize
/ BITS_PER_UNIT
, reverse
);
6944 return store_expr (exp
, to_rtx
, 0, nontemporal
, reverse
);
6948 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6949 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6950 codes and find the ultimate containing object, which we return.
6952 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6953 bit position, *PUNSIGNEDP to the signedness and *PREVERSEP to the
6954 storage order of the field.
6955 If the position of the field is variable, we store a tree
6956 giving the variable offset (in units) in *POFFSET.
6957 This offset is in addition to the bit position.
6958 If the position is not variable, we store 0 in *POFFSET.
6960 If any of the extraction expressions is volatile,
6961 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6963 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6964 Otherwise, it is a mode that can be used to access the field.
6966 If the field describes a variable-sized object, *PMODE is set to
6967 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6968 this case, but the address of the object can be found. */
6971 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6972 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6973 machine_mode
*pmode
, int *punsignedp
,
6974 int *preversep
, int *pvolatilep
)
6977 machine_mode mode
= VOIDmode
;
6978 bool blkmode_bitfield
= false;
6979 tree offset
= size_zero_node
;
6980 offset_int bit_offset
= 0;
6982 /* First get the mode, signedness, storage order and size. We do this from
6983 just the outermost expression. */
6985 if (TREE_CODE (exp
) == COMPONENT_REF
)
6987 tree field
= TREE_OPERAND (exp
, 1);
6988 size_tree
= DECL_SIZE (field
);
6989 if (flag_strict_volatile_bitfields
> 0
6990 && TREE_THIS_VOLATILE (exp
)
6991 && DECL_BIT_FIELD_TYPE (field
)
6992 && DECL_MODE (field
) != BLKmode
)
6993 /* Volatile bitfields should be accessed in the mode of the
6994 field's type, not the mode computed based on the bit
6996 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6997 else if (!DECL_BIT_FIELD (field
))
6998 mode
= DECL_MODE (field
);
6999 else if (DECL_MODE (field
) == BLKmode
)
7000 blkmode_bitfield
= true;
7002 *punsignedp
= DECL_UNSIGNED (field
);
7004 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
7006 size_tree
= TREE_OPERAND (exp
, 1);
7007 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
7008 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
7010 /* For vector types, with the correct size of access, use the mode of
7012 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
7013 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
7014 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
7015 mode
= TYPE_MODE (TREE_TYPE (exp
));
7019 mode
= TYPE_MODE (TREE_TYPE (exp
));
7020 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
7022 if (mode
== BLKmode
)
7023 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
7025 *pbitsize
= GET_MODE_BITSIZE (mode
);
7030 if (! tree_fits_uhwi_p (size_tree
))
7031 mode
= BLKmode
, *pbitsize
= -1;
7033 *pbitsize
= tree_to_uhwi (size_tree
);
7036 *preversep
= reverse_storage_order_for_component_p (exp
);
7038 /* Compute cumulative bit-offset for nested component-refs and array-refs,
7039 and find the ultimate containing object. */
7042 switch (TREE_CODE (exp
))
7045 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
7050 tree field
= TREE_OPERAND (exp
, 1);
7051 tree this_offset
= component_ref_field_offset (exp
);
7053 /* If this field hasn't been filled in yet, don't go past it.
7054 This should only happen when folding expressions made during
7055 type construction. */
7056 if (this_offset
== 0)
7059 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
7060 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
7062 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
7067 case ARRAY_RANGE_REF
:
7069 tree index
= TREE_OPERAND (exp
, 1);
7070 tree low_bound
= array_ref_low_bound (exp
);
7071 tree unit_size
= array_ref_element_size (exp
);
7073 /* We assume all arrays have sizes that are a multiple of a byte.
7074 First subtract the lower bound, if any, in the type of the
7075 index, then convert to sizetype and multiply by the size of
7076 the array element. */
7077 if (! integer_zerop (low_bound
))
7078 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
7081 offset
= size_binop (PLUS_EXPR
, offset
,
7082 size_binop (MULT_EXPR
,
7083 fold_convert (sizetype
, index
),
7092 bit_offset
+= *pbitsize
;
7095 case VIEW_CONVERT_EXPR
:
7099 /* Hand back the decl for MEM[&decl, off]. */
7100 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
7102 tree off
= TREE_OPERAND (exp
, 1);
7103 if (!integer_zerop (off
))
7105 offset_int boff
, coff
= mem_ref_offset (exp
);
7106 boff
= coff
<< LOG2_BITS_PER_UNIT
;
7109 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
7117 /* If any reference in the chain is volatile, the effect is volatile. */
7118 if (TREE_THIS_VOLATILE (exp
))
7121 exp
= TREE_OPERAND (exp
, 0);
7125 /* If OFFSET is constant, see if we can return the whole thing as a
7126 constant bit position. Make sure to handle overflow during
7128 if (TREE_CODE (offset
) == INTEGER_CST
)
7130 offset_int tem
= wi::sext (wi::to_offset (offset
),
7131 TYPE_PRECISION (sizetype
));
7132 tem
<<= LOG2_BITS_PER_UNIT
;
7134 if (wi::fits_shwi_p (tem
))
7136 *pbitpos
= tem
.to_shwi ();
7137 *poffset
= offset
= NULL_TREE
;
7141 /* Otherwise, split it up. */
7144 /* Avoid returning a negative bitpos as this may wreak havoc later. */
7145 if (wi::neg_p (bit_offset
) || !wi::fits_shwi_p (bit_offset
))
7147 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
7148 offset_int tem
= bit_offset
.and_not (mask
);
7149 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
7150 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
7152 tem
>>= LOG2_BITS_PER_UNIT
;
7153 offset
= size_binop (PLUS_EXPR
, offset
,
7154 wide_int_to_tree (sizetype
, tem
));
7157 *pbitpos
= bit_offset
.to_shwi ();
7161 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
7162 if (mode
== VOIDmode
7164 && (*pbitpos
% BITS_PER_UNIT
) == 0
7165 && (*pbitsize
% BITS_PER_UNIT
) == 0)
7173 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7175 static unsigned HOST_WIDE_INT
7176 target_align (const_tree target
)
7178 /* We might have a chain of nested references with intermediate misaligning
7179 bitfields components, so need to recurse to find out. */
7181 unsigned HOST_WIDE_INT this_align
, outer_align
;
7183 switch (TREE_CODE (target
))
7189 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7190 outer_align
= target_align (TREE_OPERAND (target
, 0));
7191 return MIN (this_align
, outer_align
);
7194 case ARRAY_RANGE_REF
:
7195 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7196 outer_align
= target_align (TREE_OPERAND (target
, 0));
7197 return MIN (this_align
, outer_align
);
7200 case NON_LVALUE_EXPR
:
7201 case VIEW_CONVERT_EXPR
:
7202 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7203 outer_align
= target_align (TREE_OPERAND (target
, 0));
7204 return MAX (this_align
, outer_align
);
7207 return TYPE_ALIGN (TREE_TYPE (target
));
7212 /* Given an rtx VALUE that may contain additions and multiplications, return
7213 an equivalent value that just refers to a register, memory, or constant.
7214 This is done by generating instructions to perform the arithmetic and
7215 returning a pseudo-register containing the value.
7217 The returned value may be a REG, SUBREG, MEM or constant. */
7220 force_operand (rtx value
, rtx target
)
7223 /* Use subtarget as the target for operand 0 of a binary operation. */
7224 rtx subtarget
= get_subtarget (target
);
7225 enum rtx_code code
= GET_CODE (value
);
7227 /* Check for subreg applied to an expression produced by loop optimizer. */
7229 && !REG_P (SUBREG_REG (value
))
7230 && !MEM_P (SUBREG_REG (value
)))
7233 = simplify_gen_subreg (GET_MODE (value
),
7234 force_reg (GET_MODE (SUBREG_REG (value
)),
7235 force_operand (SUBREG_REG (value
),
7237 GET_MODE (SUBREG_REG (value
)),
7238 SUBREG_BYTE (value
));
7239 code
= GET_CODE (value
);
7242 /* Check for a PIC address load. */
7243 if ((code
== PLUS
|| code
== MINUS
)
7244 && XEXP (value
, 0) == pic_offset_table_rtx
7245 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7246 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7247 || GET_CODE (XEXP (value
, 1)) == CONST
))
7250 subtarget
= gen_reg_rtx (GET_MODE (value
));
7251 emit_move_insn (subtarget
, value
);
7255 if (ARITHMETIC_P (value
))
7257 op2
= XEXP (value
, 1);
7258 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7260 if (code
== MINUS
&& CONST_INT_P (op2
))
7263 op2
= negate_rtx (GET_MODE (value
), op2
);
7266 /* Check for an addition with OP2 a constant integer and our first
7267 operand a PLUS of a virtual register and something else. In that
7268 case, we want to emit the sum of the virtual register and the
7269 constant first and then add the other value. This allows virtual
7270 register instantiation to simply modify the constant rather than
7271 creating another one around this addition. */
7272 if (code
== PLUS
&& CONST_INT_P (op2
)
7273 && GET_CODE (XEXP (value
, 0)) == PLUS
7274 && REG_P (XEXP (XEXP (value
, 0), 0))
7275 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7276 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7278 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7279 XEXP (XEXP (value
, 0), 0), op2
,
7280 subtarget
, 0, OPTAB_LIB_WIDEN
);
7281 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7282 force_operand (XEXP (XEXP (value
,
7284 target
, 0, OPTAB_LIB_WIDEN
);
7287 op1
= force_operand (XEXP (value
, 0), subtarget
);
7288 op2
= force_operand (op2
, NULL_RTX
);
7292 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7294 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7295 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7296 target
, 1, OPTAB_LIB_WIDEN
);
7298 return expand_divmod (0,
7299 FLOAT_MODE_P (GET_MODE (value
))
7300 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7301 GET_MODE (value
), op1
, op2
, target
, 0);
7303 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7306 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7309 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7312 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7313 target
, 0, OPTAB_LIB_WIDEN
);
7315 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7316 target
, 1, OPTAB_LIB_WIDEN
);
7319 if (UNARY_P (value
))
7322 target
= gen_reg_rtx (GET_MODE (value
));
7323 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7330 case FLOAT_TRUNCATE
:
7331 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7336 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7340 case UNSIGNED_FLOAT
:
7341 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7345 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7349 #ifdef INSN_SCHEDULING
7350 /* On machines that have insn scheduling, we want all memory reference to be
7351 explicit, so we need to deal with such paradoxical SUBREGs. */
7352 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7354 = simplify_gen_subreg (GET_MODE (value
),
7355 force_reg (GET_MODE (SUBREG_REG (value
)),
7356 force_operand (SUBREG_REG (value
),
7358 GET_MODE (SUBREG_REG (value
)),
7359 SUBREG_BYTE (value
));
7365 /* Subroutine of expand_expr: return nonzero iff there is no way that
7366 EXP can reference X, which is being modified. TOP_P is nonzero if this
7367 call is going to be used to determine whether we need a temporary
7368 for EXP, as opposed to a recursive call to this function.
7370 It is always safe for this routine to return zero since it merely
7371 searches for optimization opportunities. */
7374 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7380 /* If EXP has varying size, we MUST use a target since we currently
7381 have no way of allocating temporaries of variable size
7382 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7383 So we assume here that something at a higher level has prevented a
7384 clash. This is somewhat bogus, but the best we can do. Only
7385 do this when X is BLKmode and when we are at the top level. */
7386 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7387 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7388 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7389 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7390 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7392 && GET_MODE (x
) == BLKmode
)
7393 /* If X is in the outgoing argument area, it is always safe. */
7395 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7396 || (GET_CODE (XEXP (x
, 0)) == PLUS
7397 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7400 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7401 find the underlying pseudo. */
7402 if (GET_CODE (x
) == SUBREG
)
7405 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7409 /* Now look at our tree code and possibly recurse. */
7410 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7412 case tcc_declaration
:
7413 exp_rtl
= DECL_RTL_IF_SET (exp
);
7419 case tcc_exceptional
:
7420 if (TREE_CODE (exp
) == TREE_LIST
)
7424 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7426 exp
= TREE_CHAIN (exp
);
7429 if (TREE_CODE (exp
) != TREE_LIST
)
7430 return safe_from_p (x
, exp
, 0);
7433 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7435 constructor_elt
*ce
;
7436 unsigned HOST_WIDE_INT idx
;
7438 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7439 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7440 || !safe_from_p (x
, ce
->value
, 0))
7444 else if (TREE_CODE (exp
) == ERROR_MARK
)
7445 return 1; /* An already-visited SAVE_EXPR? */
7450 /* The only case we look at here is the DECL_INITIAL inside a
7452 return (TREE_CODE (exp
) != DECL_EXPR
7453 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7454 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7455 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7458 case tcc_comparison
:
7459 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7464 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7466 case tcc_expression
:
7469 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7470 the expression. If it is set, we conflict iff we are that rtx or
7471 both are in memory. Otherwise, we check all operands of the
7472 expression recursively. */
7474 switch (TREE_CODE (exp
))
7477 /* If the operand is static or we are static, we can't conflict.
7478 Likewise if we don't conflict with the operand at all. */
7479 if (staticp (TREE_OPERAND (exp
, 0))
7480 || TREE_STATIC (exp
)
7481 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7484 /* Otherwise, the only way this can conflict is if we are taking
7485 the address of a DECL a that address if part of X, which is
7487 exp
= TREE_OPERAND (exp
, 0);
7490 if (!DECL_RTL_SET_P (exp
)
7491 || !MEM_P (DECL_RTL (exp
)))
7494 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7500 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7501 get_alias_set (exp
)))
7506 /* Assume that the call will clobber all hard registers and
7508 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7513 case WITH_CLEANUP_EXPR
:
7514 case CLEANUP_POINT_EXPR
:
7515 /* Lowered by gimplify.c. */
7519 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7525 /* If we have an rtx, we do not need to scan our operands. */
7529 nops
= TREE_OPERAND_LENGTH (exp
);
7530 for (i
= 0; i
< nops
; i
++)
7531 if (TREE_OPERAND (exp
, i
) != 0
7532 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7538 /* Should never get a type here. */
7542 /* If we have an rtl, find any enclosed object. Then see if we conflict
7546 if (GET_CODE (exp_rtl
) == SUBREG
)
7548 exp_rtl
= SUBREG_REG (exp_rtl
);
7550 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7554 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7555 are memory and they conflict. */
7556 return ! (rtx_equal_p (x
, exp_rtl
)
7557 || (MEM_P (x
) && MEM_P (exp_rtl
)
7558 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7561 /* If we reach here, it is safe. */
7566 /* Return the highest power of two that EXP is known to be a multiple of.
7567 This is used in updating alignment of MEMs in array references. */
7569 unsigned HOST_WIDE_INT
7570 highest_pow2_factor (const_tree exp
)
7572 unsigned HOST_WIDE_INT ret
;
7573 int trailing_zeros
= tree_ctz (exp
);
7574 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7575 return BIGGEST_ALIGNMENT
;
7576 ret
= HOST_WIDE_INT_1U
<< trailing_zeros
;
7577 if (ret
> BIGGEST_ALIGNMENT
)
7578 return BIGGEST_ALIGNMENT
;
7582 /* Similar, except that the alignment requirements of TARGET are
7583 taken into account. Assume it is at least as aligned as its
7584 type, unless it is a COMPONENT_REF in which case the layout of
7585 the structure gives the alignment. */
7587 static unsigned HOST_WIDE_INT
7588 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7590 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7591 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7593 return MAX (factor
, talign
);
7596 /* Convert the tree comparison code TCODE to the rtl one where the
7597 signedness is UNSIGNEDP. */
7599 static enum rtx_code
7600 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7612 code
= unsignedp
? LTU
: LT
;
7615 code
= unsignedp
? LEU
: LE
;
7618 code
= unsignedp
? GTU
: GT
;
7621 code
= unsignedp
? GEU
: GE
;
7623 case UNORDERED_EXPR
:
7654 /* Subroutine of expand_expr. Expand the two operands of a binary
7655 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7656 The value may be stored in TARGET if TARGET is nonzero. The
7657 MODIFIER argument is as documented by expand_expr. */
7660 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7661 enum expand_modifier modifier
)
7663 if (! safe_from_p (target
, exp1
, 1))
7665 if (operand_equal_p (exp0
, exp1
, 0))
7667 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7668 *op1
= copy_rtx (*op0
);
7672 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7673 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7678 /* Return a MEM that contains constant EXP. DEFER is as for
7679 output_constant_def and MODIFIER is as for expand_expr. */
7682 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7686 mem
= output_constant_def (exp
, defer
);
7687 if (modifier
!= EXPAND_INITIALIZER
)
7688 mem
= use_anchored_address (mem
);
7692 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7693 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7696 expand_expr_addr_expr_1 (tree exp
, rtx target
, machine_mode tmode
,
7697 enum expand_modifier modifier
, addr_space_t as
)
7699 rtx result
, subtarget
;
7701 HOST_WIDE_INT bitsize
, bitpos
;
7702 int unsignedp
, reversep
, volatilep
= 0;
7705 /* If we are taking the address of a constant and are at the top level,
7706 we have to use output_constant_def since we can't call force_const_mem
7708 /* ??? This should be considered a front-end bug. We should not be
7709 generating ADDR_EXPR of something that isn't an LVALUE. The only
7710 exception here is STRING_CST. */
7711 if (CONSTANT_CLASS_P (exp
))
7713 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7714 if (modifier
< EXPAND_SUM
)
7715 result
= force_operand (result
, target
);
7719 /* Everything must be something allowed by is_gimple_addressable. */
7720 switch (TREE_CODE (exp
))
7723 /* This case will happen via recursion for &a->b. */
7724 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7728 tree tem
= TREE_OPERAND (exp
, 0);
7729 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7730 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7731 return expand_expr (tem
, target
, tmode
, modifier
);
7735 /* Expand the initializer like constants above. */
7736 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7738 if (modifier
< EXPAND_SUM
)
7739 result
= force_operand (result
, target
);
7743 /* The real part of the complex number is always first, therefore
7744 the address is the same as the address of the parent object. */
7747 inner
= TREE_OPERAND (exp
, 0);
7751 /* The imaginary part of the complex number is always second.
7752 The expression is therefore always offset by the size of the
7755 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7756 inner
= TREE_OPERAND (exp
, 0);
7759 case COMPOUND_LITERAL_EXPR
:
7760 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
7761 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
7762 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
7763 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
7764 the initializers aren't gimplified. */
7765 if (COMPOUND_LITERAL_EXPR_DECL (exp
)
7766 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp
)))
7767 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7768 target
, tmode
, modifier
, as
);
7771 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7772 expand_expr, as that can have various side effects; LABEL_DECLs for
7773 example, may not have their DECL_RTL set yet. Expand the rtl of
7774 CONSTRUCTORs too, which should yield a memory reference for the
7775 constructor's contents. Assume language specific tree nodes can
7776 be expanded in some interesting way. */
7777 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7779 || TREE_CODE (exp
) == CONSTRUCTOR
7780 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7782 result
= expand_expr (exp
, target
, tmode
,
7783 modifier
== EXPAND_INITIALIZER
7784 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7786 /* If the DECL isn't in memory, then the DECL wasn't properly
7787 marked TREE_ADDRESSABLE, which will be either a front-end
7788 or a tree optimizer bug. */
7790 gcc_assert (MEM_P (result
));
7791 result
= XEXP (result
, 0);
7793 /* ??? Is this needed anymore? */
7795 TREE_USED (exp
) = 1;
7797 if (modifier
!= EXPAND_INITIALIZER
7798 && modifier
!= EXPAND_CONST_ADDRESS
7799 && modifier
!= EXPAND_SUM
)
7800 result
= force_operand (result
, target
);
7804 /* Pass FALSE as the last argument to get_inner_reference although
7805 we are expanding to RTL. The rationale is that we know how to
7806 handle "aligning nodes" here: we can just bypass them because
7807 they won't change the final object whose address will be returned
7808 (they actually exist only for that purpose). */
7809 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode1
,
7810 &unsignedp
, &reversep
, &volatilep
);
7814 /* We must have made progress. */
7815 gcc_assert (inner
!= exp
);
7817 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7818 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7819 inner alignment, force the inner to be sufficiently aligned. */
7820 if (CONSTANT_CLASS_P (inner
)
7821 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7823 inner
= copy_node (inner
);
7824 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7825 SET_TYPE_ALIGN (TREE_TYPE (inner
), TYPE_ALIGN (TREE_TYPE (exp
)));
7826 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7828 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7834 if (modifier
!= EXPAND_NORMAL
)
7835 result
= force_operand (result
, NULL
);
7836 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7837 modifier
== EXPAND_INITIALIZER
7838 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7840 /* expand_expr is allowed to return an object in a mode other
7841 than TMODE. If it did, we need to convert. */
7842 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7843 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7844 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7845 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7846 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7848 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7849 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7852 subtarget
= bitpos
? NULL_RTX
: target
;
7853 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7854 1, OPTAB_LIB_WIDEN
);
7860 /* Someone beforehand should have rejected taking the address
7861 of such an object. */
7862 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7864 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7865 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7866 if (modifier
< EXPAND_SUM
)
7867 result
= force_operand (result
, target
);
7873 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7874 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7877 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
7878 enum expand_modifier modifier
)
7880 addr_space_t as
= ADDR_SPACE_GENERIC
;
7881 machine_mode address_mode
= Pmode
;
7882 machine_mode pointer_mode
= ptr_mode
;
7886 /* Target mode of VOIDmode says "whatever's natural". */
7887 if (tmode
== VOIDmode
)
7888 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7890 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7892 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7893 address_mode
= targetm
.addr_space
.address_mode (as
);
7894 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7897 /* We can get called with some Weird Things if the user does silliness
7898 like "(short) &a". In that case, convert_memory_address won't do
7899 the right thing, so ignore the given target mode. */
7900 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7901 tmode
= address_mode
;
7903 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7904 tmode
, modifier
, as
);
7906 /* Despite expand_expr claims concerning ignoring TMODE when not
7907 strictly convenient, stuff breaks if we don't honor it. Note
7908 that combined with the above, we only do this for pointer modes. */
7909 rmode
= GET_MODE (result
);
7910 if (rmode
== VOIDmode
)
7913 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7918 /* Generate code for computing CONSTRUCTOR EXP.
7919 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7920 is TRUE, instead of creating a temporary variable in memory
7921 NULL is returned and the caller needs to handle it differently. */
7924 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7925 bool avoid_temp_mem
)
7927 tree type
= TREE_TYPE (exp
);
7928 machine_mode mode
= TYPE_MODE (type
);
7930 /* Try to avoid creating a temporary at all. This is possible
7931 if all of the initializer is zero.
7932 FIXME: try to handle all [0..255] initializers we can handle
7934 if (TREE_STATIC (exp
)
7935 && !TREE_ADDRESSABLE (exp
)
7936 && target
!= 0 && mode
== BLKmode
7937 && all_zeros_p (exp
))
7939 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7943 /* All elts simple constants => refer to a constant in memory. But
7944 if this is a non-BLKmode mode, let it store a field at a time
7945 since that should make a CONST_INT, CONST_WIDE_INT or
7946 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7947 use, it is best to store directly into the target unless the type
7948 is large enough that memcpy will be used. If we are making an
7949 initializer and all operands are constant, put it in memory as
7952 FIXME: Avoid trying to fill vector constructors piece-meal.
7953 Output them with output_constant_def below unless we're sure
7954 they're zeros. This should go away when vector initializers
7955 are treated like VECTOR_CST instead of arrays. */
7956 if ((TREE_STATIC (exp
)
7957 && ((mode
== BLKmode
7958 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7959 || TREE_ADDRESSABLE (exp
)
7960 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7961 && (! can_move_by_pieces
7962 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7964 && ! mostly_zeros_p (exp
))))
7965 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7966 && TREE_CONSTANT (exp
)))
7973 constructor
= expand_expr_constant (exp
, 1, modifier
);
7975 if (modifier
!= EXPAND_CONST_ADDRESS
7976 && modifier
!= EXPAND_INITIALIZER
7977 && modifier
!= EXPAND_SUM
)
7978 constructor
= validize_mem (constructor
);
7983 /* Handle calls that pass values in multiple non-contiguous
7984 locations. The Irix 6 ABI has examples of this. */
7985 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7986 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7991 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7994 store_constructor (exp
, target
, 0, int_expr_size (exp
), false);
7999 /* expand_expr: generate code for computing expression EXP.
8000 An rtx for the computed value is returned. The value is never null.
8001 In the case of a void EXP, const0_rtx is returned.
8003 The value may be stored in TARGET if TARGET is nonzero.
8004 TARGET is just a suggestion; callers must assume that
8005 the rtx returned may not be the same as TARGET.
8007 If TARGET is CONST0_RTX, it means that the value will be ignored.
8009 If TMODE is not VOIDmode, it suggests generating the
8010 result in mode TMODE. But this is done only when convenient.
8011 Otherwise, TMODE is ignored and the value generated in its natural mode.
8012 TMODE is just a suggestion; callers must assume that
8013 the rtx returned may not have mode TMODE.
8015 Note that TARGET may have neither TMODE nor MODE. In that case, it
8016 probably will not be used.
8018 If MODIFIER is EXPAND_SUM then when EXP is an addition
8019 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
8020 or a nest of (PLUS ...) and (MINUS ...) where the terms are
8021 products as above, or REG or MEM, or constant.
8022 Ordinarily in such cases we would output mul or add instructions
8023 and then return a pseudo reg containing the sum.
8025 EXPAND_INITIALIZER is much like EXPAND_SUM except that
8026 it also marks a label as absolutely required (it can't be dead).
8027 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
8028 This is used for outputting expressions used in initializers.
8030 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
8031 with a constant address even if that address is not normally legitimate.
8032 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
8034 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
8035 a call parameter. Such targets require special care as we haven't yet
8036 marked TARGET so that it's safe from being trashed by libcalls. We
8037 don't want to use TARGET for anything but the final result;
8038 Intermediate values must go elsewhere. Additionally, calls to
8039 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
8041 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
8042 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
8043 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
8044 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
8047 If INNER_REFERENCE_P is true, we are expanding an inner reference.
8048 In this case, we don't adjust a returned MEM rtx that wouldn't be
8049 sufficiently aligned for its mode; instead, it's up to the caller
8050 to deal with it afterwards. This is used to make sure that unaligned
8051 base objects for which out-of-bounds accesses are supported, for
8052 example record types with trailing arrays, aren't realigned behind
8053 the back of the caller.
8054 The normal operating mode is to pass FALSE for this parameter. */
8057 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
8058 enum expand_modifier modifier
, rtx
*alt_rtl
,
8059 bool inner_reference_p
)
8063 /* Handle ERROR_MARK before anybody tries to access its type. */
8064 if (TREE_CODE (exp
) == ERROR_MARK
8065 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
8067 ret
= CONST0_RTX (tmode
);
8068 return ret
? ret
: const0_rtx
;
8071 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
8076 /* Try to expand the conditional expression which is represented by
8077 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
8078 return the rtl reg which represents the result. Otherwise return
8082 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
8083 tree treeop1 ATTRIBUTE_UNUSED
,
8084 tree treeop2 ATTRIBUTE_UNUSED
)
8087 rtx op00
, op01
, op1
, op2
;
8088 enum rtx_code comparison_code
;
8089 machine_mode comparison_mode
;
8092 tree type
= TREE_TYPE (treeop1
);
8093 int unsignedp
= TYPE_UNSIGNED (type
);
8094 machine_mode mode
= TYPE_MODE (type
);
8095 machine_mode orig_mode
= mode
;
8096 static bool expanding_cond_expr_using_cmove
= false;
8098 /* Conditional move expansion can end up TERing two operands which,
8099 when recursively hitting conditional expressions can result in
8100 exponential behavior if the cmove expansion ultimatively fails.
8101 It's hardly profitable to TER a cmove into a cmove so avoid doing
8102 that by failing early if we end up recursing. */
8103 if (expanding_cond_expr_using_cmove
)
8106 /* If we cannot do a conditional move on the mode, try doing it
8107 with the promoted mode. */
8108 if (!can_conditionally_move_p (mode
))
8110 mode
= promote_mode (type
, mode
, &unsignedp
);
8111 if (!can_conditionally_move_p (mode
))
8113 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
8116 temp
= assign_temp (type
, 0, 1);
8118 expanding_cond_expr_using_cmove
= true;
8120 expand_operands (treeop1
, treeop2
,
8121 temp
, &op1
, &op2
, EXPAND_NORMAL
);
8123 if (TREE_CODE (treeop0
) == SSA_NAME
8124 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
8126 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
8127 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
8128 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
8129 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
8130 comparison_mode
= TYPE_MODE (type
);
8131 unsignedp
= TYPE_UNSIGNED (type
);
8132 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
8134 else if (COMPARISON_CLASS_P (treeop0
))
8136 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
8137 enum tree_code cmpcode
= TREE_CODE (treeop0
);
8138 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
8139 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
8140 unsignedp
= TYPE_UNSIGNED (type
);
8141 comparison_mode
= TYPE_MODE (type
);
8142 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
8146 op00
= expand_normal (treeop0
);
8148 comparison_code
= NE
;
8149 comparison_mode
= GET_MODE (op00
);
8150 if (comparison_mode
== VOIDmode
)
8151 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8153 expanding_cond_expr_using_cmove
= false;
8155 if (GET_MODE (op1
) != mode
)
8156 op1
= gen_lowpart (mode
, op1
);
8158 if (GET_MODE (op2
) != mode
)
8159 op2
= gen_lowpart (mode
, op2
);
8161 /* Try to emit the conditional move. */
8162 insn
= emit_conditional_move (temp
, comparison_code
,
8163 op00
, op01
, comparison_mode
,
8167 /* If we could do the conditional move, emit the sequence,
8171 rtx_insn
*seq
= get_insns ();
8174 return convert_modes (orig_mode
, mode
, temp
, 0);
8177 /* Otherwise discard the sequence and fall back to code with
8184 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
8185 enum expand_modifier modifier
)
8187 rtx op0
, op1
, op2
, temp
;
8188 rtx_code_label
*lab
;
8192 enum tree_code code
= ops
->code
;
8194 rtx subtarget
, original_target
;
8196 bool reduce_bit_field
;
8197 location_t loc
= ops
->location
;
8198 tree treeop0
, treeop1
, treeop2
;
8199 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8200 ? reduce_to_bit_field_precision ((expr), \
8206 mode
= TYPE_MODE (type
);
8207 unsignedp
= TYPE_UNSIGNED (type
);
8213 /* We should be called only on simple (binary or unary) expressions,
8214 exactly those that are valid in gimple expressions that aren't
8215 GIMPLE_SINGLE_RHS (or invalid). */
8216 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8217 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8218 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8220 ignore
= (target
== const0_rtx
8221 || ((CONVERT_EXPR_CODE_P (code
)
8222 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8223 && TREE_CODE (type
) == VOID_TYPE
));
8225 /* We should be called only if we need the result. */
8226 gcc_assert (!ignore
);
8228 /* An operation in what may be a bit-field type needs the
8229 result to be reduced to the precision of the bit-field type,
8230 which is narrower than that of the type's mode. */
8231 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8232 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8234 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8237 /* Use subtarget as the target for operand 0 of a binary operation. */
8238 subtarget
= get_subtarget (target
);
8239 original_target
= target
;
8243 case NON_LVALUE_EXPR
:
8246 if (treeop0
== error_mark_node
)
8249 if (TREE_CODE (type
) == UNION_TYPE
)
8251 tree valtype
= TREE_TYPE (treeop0
);
8253 /* If both input and output are BLKmode, this conversion isn't doing
8254 anything except possibly changing memory attribute. */
8255 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8257 rtx result
= expand_expr (treeop0
, target
, tmode
,
8260 result
= copy_rtx (result
);
8261 set_mem_attributes (result
, type
, 0);
8267 if (TYPE_MODE (type
) != BLKmode
)
8268 target
= gen_reg_rtx (TYPE_MODE (type
));
8270 target
= assign_temp (type
, 1, 1);
8274 /* Store data into beginning of memory target. */
8275 store_expr (treeop0
,
8276 adjust_address (target
, TYPE_MODE (valtype
), 0),
8277 modifier
== EXPAND_STACK_PARM
,
8278 false, TYPE_REVERSE_STORAGE_ORDER (type
));
8282 gcc_assert (REG_P (target
)
8283 && !TYPE_REVERSE_STORAGE_ORDER (type
));
8285 /* Store this field into a union of the proper type. */
8286 store_field (target
,
8287 MIN ((int_size_in_bytes (TREE_TYPE
8290 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8291 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0,
8295 /* Return the entire union. */
8299 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8301 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8304 /* If the signedness of the conversion differs and OP0 is
8305 a promoted SUBREG, clear that indication since we now
8306 have to do the proper extension. */
8307 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8308 && GET_CODE (op0
) == SUBREG
)
8309 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8311 return REDUCE_BIT_FIELD (op0
);
8314 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8315 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8316 if (GET_MODE (op0
) == mode
)
8319 /* If OP0 is a constant, just convert it into the proper mode. */
8320 else if (CONSTANT_P (op0
))
8322 tree inner_type
= TREE_TYPE (treeop0
);
8323 machine_mode inner_mode
= GET_MODE (op0
);
8325 if (inner_mode
== VOIDmode
)
8326 inner_mode
= TYPE_MODE (inner_type
);
8328 if (modifier
== EXPAND_INITIALIZER
)
8329 op0
= lowpart_subreg (mode
, op0
, inner_mode
);
8331 op0
= convert_modes (mode
, inner_mode
, op0
,
8332 TYPE_UNSIGNED (inner_type
));
8335 else if (modifier
== EXPAND_INITIALIZER
)
8336 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8338 else if (target
== 0)
8339 op0
= convert_to_mode (mode
, op0
,
8340 TYPE_UNSIGNED (TREE_TYPE
8344 convert_move (target
, op0
,
8345 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8349 return REDUCE_BIT_FIELD (op0
);
8351 case ADDR_SPACE_CONVERT_EXPR
:
8353 tree treeop0_type
= TREE_TYPE (treeop0
);
8355 gcc_assert (POINTER_TYPE_P (type
));
8356 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8358 addr_space_t as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8359 addr_space_t as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8361 /* Conversions between pointers to the same address space should
8362 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8363 gcc_assert (as_to
!= as_from
);
8365 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8367 /* Ask target code to handle conversion between pointers
8368 to overlapping address spaces. */
8369 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8370 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8372 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8376 /* For disjoint address spaces, converting anything but a null
8377 pointer invokes undefined behavior. We truncate or extend the
8378 value as if we'd converted via integers, which handles 0 as
8379 required, and all others as the programmer likely expects. */
8380 #ifndef POINTERS_EXTEND_UNSIGNED
8381 const int POINTERS_EXTEND_UNSIGNED
= 1;
8383 op0
= convert_modes (mode
, TYPE_MODE (treeop0_type
),
8384 op0
, POINTERS_EXTEND_UNSIGNED
);
8390 case POINTER_PLUS_EXPR
:
8391 /* Even though the sizetype mode and the pointer's mode can be different
8392 expand is able to handle this correctly and get the correct result out
8393 of the PLUS_EXPR code. */
8394 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8395 if sizetype precision is smaller than pointer precision. */
8396 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8397 treeop1
= fold_convert_loc (loc
, type
,
8398 fold_convert_loc (loc
, ssizetype
,
8400 /* If sizetype precision is larger than pointer precision, truncate the
8401 offset to have matching modes. */
8402 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8403 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8407 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8408 something else, make sure we add the register to the constant and
8409 then to the other thing. This case can occur during strength
8410 reduction and doing it this way will produce better code if the
8411 frame pointer or argument pointer is eliminated.
8413 fold-const.c will ensure that the constant is always in the inner
8414 PLUS_EXPR, so the only case we need to do anything about is if
8415 sp, ap, or fp is our second argument, in which case we must swap
8416 the innermost first argument and our second argument. */
8418 if (TREE_CODE (treeop0
) == PLUS_EXPR
8419 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8421 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8422 || DECL_RTL (treeop1
) == stack_pointer_rtx
8423 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8428 /* If the result is to be ptr_mode and we are adding an integer to
8429 something, we might be forming a constant. So try to use
8430 plus_constant. If it produces a sum and we can't accept it,
8431 use force_operand. This allows P = &ARR[const] to generate
8432 efficient code on machines where a SYMBOL_REF is not a valid
8435 If this is an EXPAND_SUM call, always return the sum. */
8436 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8437 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8439 if (modifier
== EXPAND_STACK_PARM
)
8441 if (TREE_CODE (treeop0
) == INTEGER_CST
8442 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8443 && TREE_CONSTANT (treeop1
))
8447 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
8449 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8451 /* Use wi::shwi to ensure that the constant is
8452 truncated according to the mode of OP1, then sign extended
8453 to a HOST_WIDE_INT. Using the constant directly can result
8454 in non-canonical RTL in a 64x32 cross compile. */
8455 wc
= TREE_INT_CST_LOW (treeop0
);
8457 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8458 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8459 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8460 op1
= force_operand (op1
, target
);
8461 return REDUCE_BIT_FIELD (op1
);
8464 else if (TREE_CODE (treeop1
) == INTEGER_CST
8465 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8466 && TREE_CONSTANT (treeop0
))
8470 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
8472 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8473 (modifier
== EXPAND_INITIALIZER
8474 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8475 if (! CONSTANT_P (op0
))
8477 op1
= expand_expr (treeop1
, NULL_RTX
,
8478 VOIDmode
, modifier
);
8479 /* Return a PLUS if modifier says it's OK. */
8480 if (modifier
== EXPAND_SUM
8481 || modifier
== EXPAND_INITIALIZER
)
8482 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8485 /* Use wi::shwi to ensure that the constant is
8486 truncated according to the mode of OP1, then sign extended
8487 to a HOST_WIDE_INT. Using the constant directly can result
8488 in non-canonical RTL in a 64x32 cross compile. */
8489 wc
= TREE_INT_CST_LOW (treeop1
);
8491 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8492 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8493 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8494 op0
= force_operand (op0
, target
);
8495 return REDUCE_BIT_FIELD (op0
);
8499 /* Use TER to expand pointer addition of a negated value
8500 as pointer subtraction. */
8501 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8502 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8503 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8504 && TREE_CODE (treeop1
) == SSA_NAME
8505 && TYPE_MODE (TREE_TYPE (treeop0
))
8506 == TYPE_MODE (TREE_TYPE (treeop1
)))
8508 gimple
*def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8511 treeop1
= gimple_assign_rhs1 (def
);
8517 /* No sense saving up arithmetic to be done
8518 if it's all in the wrong mode to form part of an address.
8519 And force_operand won't know whether to sign-extend or
8521 if (modifier
!= EXPAND_INITIALIZER
8522 && (modifier
!= EXPAND_SUM
|| mode
!= ptr_mode
))
8524 expand_operands (treeop0
, treeop1
,
8525 subtarget
, &op0
, &op1
, modifier
);
8526 if (op0
== const0_rtx
)
8528 if (op1
== const0_rtx
)
8533 expand_operands (treeop0
, treeop1
,
8534 subtarget
, &op0
, &op1
, modifier
);
8535 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8539 /* For initializers, we are allowed to return a MINUS of two
8540 symbolic constants. Here we handle all cases when both operands
8542 /* Handle difference of two symbolic constants,
8543 for the sake of an initializer. */
8544 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8545 && really_constant_p (treeop0
)
8546 && really_constant_p (treeop1
))
8548 expand_operands (treeop0
, treeop1
,
8549 NULL_RTX
, &op0
, &op1
, modifier
);
8551 /* If the last operand is a CONST_INT, use plus_constant of
8552 the negated constant. Else make the MINUS. */
8553 if (CONST_INT_P (op1
))
8554 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8557 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8560 /* No sense saving up arithmetic to be done
8561 if it's all in the wrong mode to form part of an address.
8562 And force_operand won't know whether to sign-extend or
8564 if (modifier
!= EXPAND_INITIALIZER
8565 && (modifier
!= EXPAND_SUM
|| mode
!= ptr_mode
))
8568 expand_operands (treeop0
, treeop1
,
8569 subtarget
, &op0
, &op1
, modifier
);
8571 /* Convert A - const to A + (-const). */
8572 if (CONST_INT_P (op1
))
8574 op1
= negate_rtx (mode
, op1
);
8575 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8580 case WIDEN_MULT_PLUS_EXPR
:
8581 case WIDEN_MULT_MINUS_EXPR
:
8582 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8583 op2
= expand_normal (treeop2
);
8584 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8588 case WIDEN_MULT_EXPR
:
8589 /* If first operand is constant, swap them.
8590 Thus the following special case checks need only
8591 check the second operand. */
8592 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8593 std::swap (treeop0
, treeop1
);
8595 /* First, check if we have a multiplication of one signed and one
8596 unsigned operand. */
8597 if (TREE_CODE (treeop1
) != INTEGER_CST
8598 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8599 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8601 machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8602 this_optab
= usmul_widen_optab
;
8603 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8604 != CODE_FOR_nothing
)
8606 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8607 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8610 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8612 /* op0 and op1 might still be constant, despite the above
8613 != INTEGER_CST check. Handle it. */
8614 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8616 op0
= convert_modes (innermode
, mode
, op0
, true);
8617 op1
= convert_modes (innermode
, mode
, op1
, false);
8618 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8619 target
, unsignedp
));
8624 /* Check for a multiplication with matching signedness. */
8625 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8626 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8627 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8628 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8630 tree op0type
= TREE_TYPE (treeop0
);
8631 machine_mode innermode
= TYPE_MODE (op0type
);
8632 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8633 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8634 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8636 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8638 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8639 != CODE_FOR_nothing
)
8641 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8643 /* op0 and op1 might still be constant, despite the above
8644 != INTEGER_CST check. Handle it. */
8645 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8648 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8650 = convert_modes (innermode
, mode
, op1
,
8651 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8652 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8656 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8657 unsignedp
, this_optab
);
8658 return REDUCE_BIT_FIELD (temp
);
8660 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8662 && innermode
== word_mode
)
8665 op0
= expand_normal (treeop0
);
8666 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8667 op1
= convert_modes (innermode
, mode
,
8668 expand_normal (treeop1
),
8669 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8671 op1
= expand_normal (treeop1
);
8672 /* op0 and op1 might still be constant, despite the above
8673 != INTEGER_CST check. Handle it. */
8674 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8675 goto widen_mult_const
;
8676 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8677 unsignedp
, OPTAB_LIB_WIDEN
);
8678 hipart
= gen_highpart (innermode
, temp
);
8679 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8683 emit_move_insn (hipart
, htem
);
8684 return REDUCE_BIT_FIELD (temp
);
8688 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8689 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8690 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8691 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8695 optab opt
= fma_optab
;
8696 gimple
*def0
, *def2
;
8698 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8700 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8702 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8705 gcc_assert (fn
!= NULL_TREE
);
8706 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8707 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8710 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8711 /* The multiplication is commutative - look at its 2nd operand
8712 if the first isn't fed by a negate. */
8715 def0
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8716 /* Swap operands if the 2nd operand is fed by a negate. */
8718 std::swap (treeop0
, treeop1
);
8720 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8725 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8728 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8729 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8732 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8735 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8738 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8741 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8745 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8747 op2
= expand_normal (treeop2
);
8748 op1
= expand_normal (treeop1
);
8750 return expand_ternary_op (TYPE_MODE (type
), opt
,
8751 op0
, op1
, op2
, target
, 0);
8755 /* If this is a fixed-point operation, then we cannot use the code
8756 below because "expand_mult" doesn't support sat/no-sat fixed-point
8758 if (ALL_FIXED_POINT_MODE_P (mode
))
8761 /* If first operand is constant, swap them.
8762 Thus the following special case checks need only
8763 check the second operand. */
8764 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8765 std::swap (treeop0
, treeop1
);
8767 /* Attempt to return something suitable for generating an
8768 indexed address, for machines that support that. */
8770 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8771 && tree_fits_shwi_p (treeop1
))
8773 tree exp1
= treeop1
;
8775 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8779 op0
= force_operand (op0
, NULL_RTX
);
8781 op0
= copy_to_mode_reg (mode
, op0
);
8783 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8784 gen_int_mode (tree_to_shwi (exp1
),
8785 TYPE_MODE (TREE_TYPE (exp1
)))));
8788 if (modifier
== EXPAND_STACK_PARM
)
8791 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8792 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8794 case TRUNC_DIV_EXPR
:
8795 case FLOOR_DIV_EXPR
:
8797 case ROUND_DIV_EXPR
:
8798 case EXACT_DIV_EXPR
:
8799 /* If this is a fixed-point operation, then we cannot use the code
8800 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8802 if (ALL_FIXED_POINT_MODE_P (mode
))
8805 if (modifier
== EXPAND_STACK_PARM
)
8807 /* Possible optimization: compute the dividend with EXPAND_SUM
8808 then if the divisor is constant can optimize the case
8809 where some terms of the dividend have coeffs divisible by it. */
8810 expand_operands (treeop0
, treeop1
,
8811 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8812 if (SCALAR_INT_MODE_P (mode
)
8814 && get_range_pos_neg (treeop0
) == 1
8815 && get_range_pos_neg (treeop1
) == 1)
8817 /* If both arguments are known to be positive when interpreted
8818 as signed, we can expand it as both signed and unsigned
8819 division or modulo. Choose the cheaper sequence in that case. */
8820 bool speed_p
= optimize_insn_for_speed_p ();
8821 do_pending_stack_adjust ();
8823 rtx uns_ret
= expand_divmod (0, code
, mode
, op0
, op1
, target
, 1);
8824 rtx_insn
*uns_insns
= get_insns ();
8827 rtx sgn_ret
= expand_divmod (0, code
, mode
, op0
, op1
, target
, 0);
8828 rtx_insn
*sgn_insns
= get_insns ();
8830 unsigned uns_cost
= seq_cost (uns_insns
, speed_p
);
8831 unsigned sgn_cost
= seq_cost (sgn_insns
, speed_p
);
8832 if (uns_cost
< sgn_cost
|| (uns_cost
== sgn_cost
&& unsignedp
))
8834 emit_insn (uns_insns
);
8837 emit_insn (sgn_insns
);
8840 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8845 case MULT_HIGHPART_EXPR
:
8846 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8847 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8851 case TRUNC_MOD_EXPR
:
8852 case FLOOR_MOD_EXPR
:
8854 case ROUND_MOD_EXPR
:
8855 if (modifier
== EXPAND_STACK_PARM
)
8857 expand_operands (treeop0
, treeop1
,
8858 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8859 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8861 case FIXED_CONVERT_EXPR
:
8862 op0
= expand_normal (treeop0
);
8863 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8864 target
= gen_reg_rtx (mode
);
8866 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8867 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8868 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8869 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8871 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8874 case FIX_TRUNC_EXPR
:
8875 op0
= expand_normal (treeop0
);
8876 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8877 target
= gen_reg_rtx (mode
);
8878 expand_fix (target
, op0
, unsignedp
);
8882 op0
= expand_normal (treeop0
);
8883 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8884 target
= gen_reg_rtx (mode
);
8885 /* expand_float can't figure out what to do if FROM has VOIDmode.
8886 So give it the correct mode. With -O, cse will optimize this. */
8887 if (GET_MODE (op0
) == VOIDmode
)
8888 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8890 expand_float (target
, op0
,
8891 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8895 op0
= expand_expr (treeop0
, subtarget
,
8896 VOIDmode
, EXPAND_NORMAL
);
8897 if (modifier
== EXPAND_STACK_PARM
)
8899 temp
= expand_unop (mode
,
8900 optab_for_tree_code (NEGATE_EXPR
, type
,
8904 return REDUCE_BIT_FIELD (temp
);
8907 op0
= expand_expr (treeop0
, subtarget
,
8908 VOIDmode
, EXPAND_NORMAL
);
8909 if (modifier
== EXPAND_STACK_PARM
)
8912 /* ABS_EXPR is not valid for complex arguments. */
8913 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8914 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8916 /* Unsigned abs is simply the operand. Testing here means we don't
8917 risk generating incorrect code below. */
8918 if (TYPE_UNSIGNED (type
))
8921 return expand_abs (mode
, op0
, target
, unsignedp
,
8922 safe_from_p (target
, treeop0
, 1));
8926 target
= original_target
;
8928 || modifier
== EXPAND_STACK_PARM
8929 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8930 || GET_MODE (target
) != mode
8932 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8933 target
= gen_reg_rtx (mode
);
8934 expand_operands (treeop0
, treeop1
,
8935 target
, &op0
, &op1
, EXPAND_NORMAL
);
8937 /* First try to do it with a special MIN or MAX instruction.
8938 If that does not win, use a conditional jump to select the proper
8940 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8941 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8946 /* At this point, a MEM target is no longer useful; we will get better
8949 if (! REG_P (target
))
8950 target
= gen_reg_rtx (mode
);
8952 /* If op1 was placed in target, swap op0 and op1. */
8953 if (target
!= op0
&& target
== op1
)
8954 std::swap (op0
, op1
);
8956 /* We generate better code and avoid problems with op1 mentioning
8957 target by forcing op1 into a pseudo if it isn't a constant. */
8958 if (! CONSTANT_P (op1
))
8959 op1
= force_reg (mode
, op1
);
8962 enum rtx_code comparison_code
;
8965 if (code
== MAX_EXPR
)
8966 comparison_code
= unsignedp
? GEU
: GE
;
8968 comparison_code
= unsignedp
? LEU
: LE
;
8970 /* Canonicalize to comparisons against 0. */
8971 if (op1
== const1_rtx
)
8973 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8974 or (a != 0 ? a : 1) for unsigned.
8975 For MIN we are safe converting (a <= 1 ? a : 1)
8976 into (a <= 0 ? a : 1) */
8977 cmpop1
= const0_rtx
;
8978 if (code
== MAX_EXPR
)
8979 comparison_code
= unsignedp
? NE
: GT
;
8981 if (op1
== constm1_rtx
&& !unsignedp
)
8983 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8984 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8985 cmpop1
= const0_rtx
;
8986 if (code
== MIN_EXPR
)
8987 comparison_code
= LT
;
8990 /* Use a conditional move if possible. */
8991 if (can_conditionally_move_p (mode
))
8997 /* Try to emit the conditional move. */
8998 insn
= emit_conditional_move (target
, comparison_code
,
9003 /* If we could do the conditional move, emit the sequence,
9007 rtx_insn
*seq
= get_insns ();
9013 /* Otherwise discard the sequence and fall back to code with
9019 emit_move_insn (target
, op0
);
9021 lab
= gen_label_rtx ();
9022 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
9023 unsignedp
, mode
, NULL_RTX
, NULL
, lab
,
9026 emit_move_insn (target
, op1
);
9031 op0
= expand_expr (treeop0
, subtarget
,
9032 VOIDmode
, EXPAND_NORMAL
);
9033 if (modifier
== EXPAND_STACK_PARM
)
9035 /* In case we have to reduce the result to bitfield precision
9036 for unsigned bitfield expand this as XOR with a proper constant
9038 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
9040 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
9041 false, GET_MODE_PRECISION (mode
));
9043 temp
= expand_binop (mode
, xor_optab
, op0
,
9044 immed_wide_int_const (mask
, mode
),
9045 target
, 1, OPTAB_LIB_WIDEN
);
9048 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
9052 /* ??? Can optimize bitwise operations with one arg constant.
9053 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
9054 and (a bitwise1 b) bitwise2 b (etc)
9055 but that is probably not worth while. */
9064 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
9065 || (GET_MODE_PRECISION (TYPE_MODE (type
))
9066 == TYPE_PRECISION (type
)));
9072 /* If this is a fixed-point operation, then we cannot use the code
9073 below because "expand_shift" doesn't support sat/no-sat fixed-point
9075 if (ALL_FIXED_POINT_MODE_P (mode
))
9078 if (! safe_from_p (subtarget
, treeop1
, 1))
9080 if (modifier
== EXPAND_STACK_PARM
)
9082 op0
= expand_expr (treeop0
, subtarget
,
9083 VOIDmode
, EXPAND_NORMAL
);
9085 /* Left shift optimization when shifting across word_size boundary.
9087 If mode == GET_MODE_WIDER_MODE (word_mode), then normally
9088 there isn't native instruction to support this wide mode
9089 left shift. Given below scenario:
9091 Type A = (Type) B << C
9094 | dest_high | dest_low |
9098 If the shift amount C caused we shift B to across the word
9099 size boundary, i.e part of B shifted into high half of
9100 destination register, and part of B remains in the low
9101 half, then GCC will use the following left shift expand
9104 1. Initialize dest_low to B.
9105 2. Initialize every bit of dest_high to the sign bit of B.
9106 3. Logic left shift dest_low by C bit to finalize dest_low.
9107 The value of dest_low before this shift is kept in a temp D.
9108 4. Logic left shift dest_high by C.
9109 5. Logic right shift D by (word_size - C).
9110 6. Or the result of 4 and 5 to finalize dest_high.
9112 While, by checking gimple statements, if operand B is
9113 coming from signed extension, then we can simplify above
9116 1. dest_high = src_low >> (word_size - C).
9117 2. dest_low = src_low << C.
9119 We can use one arithmetic right shift to finish all the
9120 purpose of steps 2, 4, 5, 6, thus we reduce the steps
9121 needed from 6 into 2.
9123 The case is similar for zero extension, except that we
9124 initialize dest_high to zero rather than copies of the sign
9125 bit from B. Furthermore, we need to use a logical right shift
9128 The choice of sign-extension versus zero-extension is
9129 determined entirely by whether or not B is signed and is
9130 independent of the current setting of unsignedp. */
9133 if (code
== LSHIFT_EXPR
9136 && mode
== GET_MODE_WIDER_MODE (word_mode
)
9137 && GET_MODE_SIZE (mode
) == 2 * GET_MODE_SIZE (word_mode
)
9138 && TREE_CONSTANT (treeop1
)
9139 && TREE_CODE (treeop0
) == SSA_NAME
)
9141 gimple
*def
= SSA_NAME_DEF_STMT (treeop0
);
9142 if (is_gimple_assign (def
)
9143 && gimple_assign_rhs_code (def
) == NOP_EXPR
)
9145 machine_mode rmode
= TYPE_MODE
9146 (TREE_TYPE (gimple_assign_rhs1 (def
)));
9148 if (GET_MODE_SIZE (rmode
) < GET_MODE_SIZE (mode
)
9149 && TREE_INT_CST_LOW (treeop1
) < GET_MODE_BITSIZE (word_mode
)
9150 && ((TREE_INT_CST_LOW (treeop1
) + GET_MODE_BITSIZE (rmode
))
9151 >= GET_MODE_BITSIZE (word_mode
)))
9153 rtx_insn
*seq
, *seq_old
;
9154 unsigned int high_off
= subreg_highpart_offset (word_mode
,
9156 bool extend_unsigned
9157 = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def
)));
9158 rtx low
= lowpart_subreg (word_mode
, op0
, mode
);
9159 rtx dest_low
= lowpart_subreg (word_mode
, target
, mode
);
9160 rtx dest_high
= simplify_gen_subreg (word_mode
, target
,
9162 HOST_WIDE_INT ramount
= (BITS_PER_WORD
9163 - TREE_INT_CST_LOW (treeop1
));
9164 tree rshift
= build_int_cst (TREE_TYPE (treeop1
), ramount
);
9167 /* dest_high = src_low >> (word_size - C). */
9168 temp
= expand_variable_shift (RSHIFT_EXPR
, word_mode
, low
,
9171 if (temp
!= dest_high
)
9172 emit_move_insn (dest_high
, temp
);
9174 /* dest_low = src_low << C. */
9175 temp
= expand_variable_shift (LSHIFT_EXPR
, word_mode
, low
,
9176 treeop1
, dest_low
, unsignedp
);
9177 if (temp
!= dest_low
)
9178 emit_move_insn (dest_low
, temp
);
9184 if (have_insn_for (ASHIFT
, mode
))
9186 bool speed_p
= optimize_insn_for_speed_p ();
9188 rtx ret_old
= expand_variable_shift (code
, mode
, op0
,
9192 seq_old
= get_insns ();
9194 if (seq_cost (seq
, speed_p
)
9195 >= seq_cost (seq_old
, speed_p
))
9206 if (temp
== NULL_RTX
)
9207 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
9209 if (code
== LSHIFT_EXPR
)
9210 temp
= REDUCE_BIT_FIELD (temp
);
9214 /* Could determine the answer when only additive constants differ. Also,
9215 the addition of one can be handled by changing the condition. */
9222 case UNORDERED_EXPR
:
9231 temp
= do_store_flag (ops
,
9232 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
9233 tmode
!= VOIDmode
? tmode
: mode
);
9237 /* Use a compare and a jump for BLKmode comparisons, or for function
9238 type comparisons is have_canonicalize_funcptr_for_compare. */
9241 || modifier
== EXPAND_STACK_PARM
9242 || ! safe_from_p (target
, treeop0
, 1)
9243 || ! safe_from_p (target
, treeop1
, 1)
9244 /* Make sure we don't have a hard reg (such as function's return
9245 value) live across basic blocks, if not optimizing. */
9246 || (!optimize
&& REG_P (target
)
9247 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
9248 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
9250 emit_move_insn (target
, const0_rtx
);
9252 rtx_code_label
*lab1
= gen_label_rtx ();
9253 jumpifnot_1 (code
, treeop0
, treeop1
, lab1
, -1);
9255 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
9256 emit_move_insn (target
, constm1_rtx
);
9258 emit_move_insn (target
, const1_rtx
);
9264 /* Get the rtx code of the operands. */
9265 op0
= expand_normal (treeop0
);
9266 op1
= expand_normal (treeop1
);
9269 target
= gen_reg_rtx (TYPE_MODE (type
));
9271 /* If target overlaps with op1, then either we need to force
9272 op1 into a pseudo (if target also overlaps with op0),
9273 or write the complex parts in reverse order. */
9274 switch (GET_CODE (target
))
9277 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
9279 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
9281 complex_expr_force_op1
:
9282 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
9283 emit_move_insn (temp
, op1
);
9287 complex_expr_swap_order
:
9288 /* Move the imaginary (op1) and real (op0) parts to their
9290 write_complex_part (target
, op1
, true);
9291 write_complex_part (target
, op0
, false);
9297 temp
= adjust_address_nv (target
,
9298 GET_MODE_INNER (GET_MODE (target
)), 0);
9299 if (reg_overlap_mentioned_p (temp
, op1
))
9301 machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
9302 temp
= adjust_address_nv (target
, imode
,
9303 GET_MODE_SIZE (imode
));
9304 if (reg_overlap_mentioned_p (temp
, op0
))
9305 goto complex_expr_force_op1
;
9306 goto complex_expr_swap_order
;
9310 if (reg_overlap_mentioned_p (target
, op1
))
9312 if (reg_overlap_mentioned_p (target
, op0
))
9313 goto complex_expr_force_op1
;
9314 goto complex_expr_swap_order
;
9319 /* Move the real (op0) and imaginary (op1) parts to their location. */
9320 write_complex_part (target
, op0
, false);
9321 write_complex_part (target
, op1
, true);
9325 case WIDEN_SUM_EXPR
:
9327 tree oprnd0
= treeop0
;
9328 tree oprnd1
= treeop1
;
9330 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9331 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9336 case REDUC_MAX_EXPR
:
9337 case REDUC_MIN_EXPR
:
9338 case REDUC_PLUS_EXPR
:
9340 op0
= expand_normal (treeop0
);
9341 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9342 machine_mode vec_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9344 struct expand_operand ops
[2];
9345 enum insn_code icode
= optab_handler (this_optab
, vec_mode
);
9347 create_output_operand (&ops
[0], target
, mode
);
9348 create_input_operand (&ops
[1], op0
, vec_mode
);
9349 expand_insn (icode
, 2, ops
);
9350 target
= ops
[0].value
;
9351 if (GET_MODE (target
) != mode
)
9352 return gen_lowpart (tmode
, target
);
9356 case VEC_UNPACK_HI_EXPR
:
9357 case VEC_UNPACK_LO_EXPR
:
9359 op0
= expand_normal (treeop0
);
9360 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9366 case VEC_UNPACK_FLOAT_HI_EXPR
:
9367 case VEC_UNPACK_FLOAT_LO_EXPR
:
9369 op0
= expand_normal (treeop0
);
9370 /* The signedness is determined from input operand. */
9371 temp
= expand_widen_pattern_expr
9372 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9373 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9379 case VEC_WIDEN_MULT_HI_EXPR
:
9380 case VEC_WIDEN_MULT_LO_EXPR
:
9381 case VEC_WIDEN_MULT_EVEN_EXPR
:
9382 case VEC_WIDEN_MULT_ODD_EXPR
:
9383 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9384 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9385 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9386 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9388 gcc_assert (target
);
9391 case VEC_PACK_TRUNC_EXPR
:
9392 case VEC_PACK_SAT_EXPR
:
9393 case VEC_PACK_FIX_TRUNC_EXPR
:
9394 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9398 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9399 op2
= expand_normal (treeop2
);
9401 /* Careful here: if the target doesn't support integral vector modes,
9402 a constant selection vector could wind up smooshed into a normal
9403 integral constant. */
9404 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9406 tree sel_type
= TREE_TYPE (treeop2
);
9408 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9409 TYPE_VECTOR_SUBPARTS (sel_type
));
9410 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9411 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9412 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9415 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9417 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9423 tree oprnd0
= treeop0
;
9424 tree oprnd1
= treeop1
;
9425 tree oprnd2
= treeop2
;
9428 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9429 op2
= expand_normal (oprnd2
);
9430 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9437 tree oprnd0
= treeop0
;
9438 tree oprnd1
= treeop1
;
9439 tree oprnd2
= treeop2
;
9442 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9443 op2
= expand_normal (oprnd2
);
9444 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9449 case REALIGN_LOAD_EXPR
:
9451 tree oprnd0
= treeop0
;
9452 tree oprnd1
= treeop1
;
9453 tree oprnd2
= treeop2
;
9456 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9457 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9458 op2
= expand_normal (oprnd2
);
9459 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9467 /* A COND_EXPR with its type being VOID_TYPE represents a
9468 conditional jump and is handled in
9469 expand_gimple_cond_expr. */
9470 gcc_assert (!VOID_TYPE_P (type
));
9472 /* Note that COND_EXPRs whose type is a structure or union
9473 are required to be constructed to contain assignments of
9474 a temporary variable, so that we can evaluate them here
9475 for side effect only. If type is void, we must do likewise. */
9477 gcc_assert (!TREE_ADDRESSABLE (type
)
9479 && TREE_TYPE (treeop1
) != void_type_node
9480 && TREE_TYPE (treeop2
) != void_type_node
);
9482 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9486 /* If we are not to produce a result, we have no target. Otherwise,
9487 if a target was specified use it; it will not be used as an
9488 intermediate target unless it is safe. If no target, use a
9491 if (modifier
!= EXPAND_STACK_PARM
9493 && safe_from_p (original_target
, treeop0
, 1)
9494 && GET_MODE (original_target
) == mode
9495 && !MEM_P (original_target
))
9496 temp
= original_target
;
9498 temp
= assign_temp (type
, 0, 1);
9500 do_pending_stack_adjust ();
9502 rtx_code_label
*lab0
= gen_label_rtx ();
9503 rtx_code_label
*lab1
= gen_label_rtx ();
9504 jumpifnot (treeop0
, lab0
, -1);
9505 store_expr (treeop1
, temp
,
9506 modifier
== EXPAND_STACK_PARM
,
9509 emit_jump_insn (targetm
.gen_jump (lab1
));
9512 store_expr (treeop2
, temp
,
9513 modifier
== EXPAND_STACK_PARM
,
9522 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9525 case BIT_INSERT_EXPR
:
9527 unsigned bitpos
= tree_to_uhwi (treeop2
);
9529 if (INTEGRAL_TYPE_P (TREE_TYPE (treeop1
)))
9530 bitsize
= TYPE_PRECISION (TREE_TYPE (treeop1
));
9532 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (treeop1
)));
9533 rtx op0
= expand_normal (treeop0
);
9534 rtx op1
= expand_normal (treeop1
);
9535 rtx dst
= gen_reg_rtx (mode
);
9536 emit_move_insn (dst
, op0
);
9537 store_bit_field (dst
, bitsize
, bitpos
, 0, 0,
9538 TYPE_MODE (TREE_TYPE (treeop1
)), op1
, false);
9546 /* Here to do an ordinary binary operator. */
9548 expand_operands (treeop0
, treeop1
,
9549 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9551 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9553 if (modifier
== EXPAND_STACK_PARM
)
9555 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9556 unsignedp
, OPTAB_LIB_WIDEN
);
9558 /* Bitwise operations do not need bitfield reduction as we expect their
9559 operands being properly truncated. */
9560 if (code
== BIT_XOR_EXPR
9561 || code
== BIT_AND_EXPR
9562 || code
== BIT_IOR_EXPR
)
9564 return REDUCE_BIT_FIELD (temp
);
9566 #undef REDUCE_BIT_FIELD
9569 /* Return TRUE if expression STMT is suitable for replacement.
9570 Never consider memory loads as replaceable, because those don't ever lead
9571 into constant expressions. */
9574 stmt_is_replaceable_p (gimple
*stmt
)
9576 if (ssa_is_replaceable_p (stmt
))
9578 /* Don't move around loads. */
9579 if (!gimple_assign_single_p (stmt
)
9580 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9587 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
9588 enum expand_modifier modifier
, rtx
*alt_rtl
,
9589 bool inner_reference_p
)
9591 rtx op0
, op1
, temp
, decl_rtl
;
9594 machine_mode mode
, dmode
;
9595 enum tree_code code
= TREE_CODE (exp
);
9596 rtx subtarget
, original_target
;
9599 bool reduce_bit_field
;
9600 location_t loc
= EXPR_LOCATION (exp
);
9601 struct separate_ops ops
;
9602 tree treeop0
, treeop1
, treeop2
;
9603 tree ssa_name
= NULL_TREE
;
9606 type
= TREE_TYPE (exp
);
9607 mode
= TYPE_MODE (type
);
9608 unsignedp
= TYPE_UNSIGNED (type
);
9610 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9611 if (!VL_EXP_CLASS_P (exp
))
9612 switch (TREE_CODE_LENGTH (code
))
9615 case 3: treeop2
= TREE_OPERAND (exp
, 2); /* FALLTHRU */
9616 case 2: treeop1
= TREE_OPERAND (exp
, 1); /* FALLTHRU */
9617 case 1: treeop0
= TREE_OPERAND (exp
, 0); /* FALLTHRU */
9627 ignore
= (target
== const0_rtx
9628 || ((CONVERT_EXPR_CODE_P (code
)
9629 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9630 && TREE_CODE (type
) == VOID_TYPE
));
9632 /* An operation in what may be a bit-field type needs the
9633 result to be reduced to the precision of the bit-field type,
9634 which is narrower than that of the type's mode. */
9635 reduce_bit_field
= (!ignore
9636 && INTEGRAL_TYPE_P (type
)
9637 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9639 /* If we are going to ignore this result, we need only do something
9640 if there is a side-effect somewhere in the expression. If there
9641 is, short-circuit the most common cases here. Note that we must
9642 not call expand_expr with anything but const0_rtx in case this
9643 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9647 if (! TREE_SIDE_EFFECTS (exp
))
9650 /* Ensure we reference a volatile object even if value is ignored, but
9651 don't do this if all we are doing is taking its address. */
9652 if (TREE_THIS_VOLATILE (exp
)
9653 && TREE_CODE (exp
) != FUNCTION_DECL
9654 && mode
!= VOIDmode
&& mode
!= BLKmode
9655 && modifier
!= EXPAND_CONST_ADDRESS
)
9657 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9663 if (TREE_CODE_CLASS (code
) == tcc_unary
9664 || code
== BIT_FIELD_REF
9665 || code
== COMPONENT_REF
9666 || code
== INDIRECT_REF
)
9667 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9670 else if (TREE_CODE_CLASS (code
) == tcc_binary
9671 || TREE_CODE_CLASS (code
) == tcc_comparison
9672 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9674 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9675 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9682 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9685 /* Use subtarget as the target for operand 0 of a binary operation. */
9686 subtarget
= get_subtarget (target
);
9687 original_target
= target
;
9693 tree function
= decl_function_context (exp
);
9695 temp
= label_rtx (exp
);
9696 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9698 if (function
!= current_function_decl
9700 LABEL_REF_NONLOCAL_P (temp
) = 1;
9702 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9707 /* ??? ivopts calls expander, without any preparation from
9708 out-of-ssa. So fake instructions as if this was an access to the
9709 base variable. This unnecessarily allocates a pseudo, see how we can
9710 reuse it, if partition base vars have it set already. */
9711 if (!currently_expanding_to_rtl
)
9713 tree var
= SSA_NAME_VAR (exp
);
9714 if (var
&& DECL_RTL_SET_P (var
))
9715 return DECL_RTL (var
);
9716 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9717 LAST_VIRTUAL_REGISTER
+ 1);
9720 g
= get_gimple_for_ssa_name (exp
);
9721 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9723 && modifier
== EXPAND_INITIALIZER
9724 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9725 && (optimize
|| !SSA_NAME_VAR (exp
)
9726 || DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9727 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9728 g
= SSA_NAME_DEF_STMT (exp
);
9732 location_t saved_loc
= curr_insn_location ();
9733 location_t loc
= gimple_location (g
);
9734 if (loc
!= UNKNOWN_LOCATION
)
9735 set_curr_insn_location (loc
);
9736 ops
.code
= gimple_assign_rhs_code (g
);
9737 switch (get_gimple_rhs_class (ops
.code
))
9739 case GIMPLE_TERNARY_RHS
:
9740 ops
.op2
= gimple_assign_rhs3 (g
);
9742 case GIMPLE_BINARY_RHS
:
9743 ops
.op1
= gimple_assign_rhs2 (g
);
9745 /* Try to expand conditonal compare. */
9746 if (targetm
.gen_ccmp_first
)
9748 gcc_checking_assert (targetm
.gen_ccmp_next
!= NULL
);
9749 r
= expand_ccmp_expr (g
);
9754 case GIMPLE_UNARY_RHS
:
9755 ops
.op0
= gimple_assign_rhs1 (g
);
9756 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9758 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9760 case GIMPLE_SINGLE_RHS
:
9762 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9763 tmode
, modifier
, NULL
, inner_reference_p
);
9769 set_curr_insn_location (saved_loc
);
9770 if (REG_P (r
) && !REG_EXPR (r
))
9771 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9776 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9777 exp
= SSA_NAME_VAR (ssa_name
);
9778 goto expand_decl_rtl
;
9782 /* If a static var's type was incomplete when the decl was written,
9783 but the type is complete now, lay out the decl now. */
9784 if (DECL_SIZE (exp
) == 0
9785 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9786 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9787 layout_decl (exp
, 0);
9793 decl_rtl
= DECL_RTL (exp
);
9795 gcc_assert (decl_rtl
);
9797 /* DECL_MODE might change when TYPE_MODE depends on attribute target
9798 settings for VECTOR_TYPE_P that might switch for the function. */
9799 if (currently_expanding_to_rtl
9800 && code
== VAR_DECL
&& MEM_P (decl_rtl
)
9801 && VECTOR_TYPE_P (type
) && exp
&& DECL_MODE (exp
) != mode
)
9802 decl_rtl
= change_address (decl_rtl
, TYPE_MODE (type
), 0);
9804 decl_rtl
= copy_rtx (decl_rtl
);
9806 /* Record writes to register variables. */
9807 if (modifier
== EXPAND_WRITE
9809 && HARD_REGISTER_P (decl_rtl
))
9810 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9811 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9813 /* Ensure variable marked as used even if it doesn't go through
9814 a parser. If it hasn't be used yet, write out an external
9817 TREE_USED (exp
) = 1;
9819 /* Show we haven't gotten RTL for this yet. */
9822 /* Variables inherited from containing functions should have
9823 been lowered by this point. */
9825 context
= decl_function_context (exp
);
9827 || SCOPE_FILE_SCOPE_P (context
)
9828 || context
== current_function_decl
9829 || TREE_STATIC (exp
)
9830 || DECL_EXTERNAL (exp
)
9831 /* ??? C++ creates functions that are not TREE_STATIC. */
9832 || TREE_CODE (exp
) == FUNCTION_DECL
);
9834 /* This is the case of an array whose size is to be determined
9835 from its initializer, while the initializer is still being parsed.
9836 ??? We aren't parsing while expanding anymore. */
9838 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9839 temp
= validize_mem (decl_rtl
);
9841 /* If DECL_RTL is memory, we are in the normal case and the
9842 address is not valid, get the address into a register. */
9844 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9847 *alt_rtl
= decl_rtl
;
9848 decl_rtl
= use_anchored_address (decl_rtl
);
9849 if (modifier
!= EXPAND_CONST_ADDRESS
9850 && modifier
!= EXPAND_SUM
9851 && !memory_address_addr_space_p (exp
? DECL_MODE (exp
)
9852 : GET_MODE (decl_rtl
),
9854 MEM_ADDR_SPACE (decl_rtl
)))
9855 temp
= replace_equiv_address (decl_rtl
,
9856 copy_rtx (XEXP (decl_rtl
, 0)));
9859 /* If we got something, return it. But first, set the alignment
9860 if the address is a register. */
9863 if (exp
&& MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9864 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9870 dmode
= DECL_MODE (exp
);
9872 dmode
= TYPE_MODE (TREE_TYPE (ssa_name
));
9874 /* If the mode of DECL_RTL does not match that of the decl,
9875 there are two cases: we are dealing with a BLKmode value
9876 that is returned in a register, or we are dealing with
9877 a promoted value. In the latter case, return a SUBREG
9878 of the wanted mode, but mark it so that we know that it
9879 was already extended. */
9880 if (REG_P (decl_rtl
)
9882 && GET_MODE (decl_rtl
) != dmode
)
9886 /* Get the signedness to be used for this variable. Ensure we get
9887 the same mode we got when the variable was declared. */
9888 if (code
!= SSA_NAME
)
9889 pmode
= promote_decl_mode (exp
, &unsignedp
);
9890 else if ((g
= SSA_NAME_DEF_STMT (ssa_name
))
9891 && gimple_code (g
) == GIMPLE_CALL
9892 && !gimple_call_internal_p (g
))
9893 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9894 gimple_call_fntype (g
),
9897 pmode
= promote_ssa_mode (ssa_name
, &unsignedp
);
9898 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9900 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9901 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9902 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9909 /* Given that TYPE_PRECISION (type) is not always equal to
9910 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9911 the former to the latter according to the signedness of the
9913 temp
= immed_wide_int_const (wi::to_wide
9915 GET_MODE_PRECISION (TYPE_MODE (type
))),
9921 tree tmp
= NULL_TREE
;
9922 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9923 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9924 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9925 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9926 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9927 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9928 return const_vector_from_tree (exp
);
9929 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9931 if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp
)))
9932 return const_scalar_mask_from_tree (exp
);
9935 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9937 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
,
9938 type_for_mode
, exp
);
9943 vec
<constructor_elt
, va_gc
> *v
;
9945 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9946 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9947 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9948 tmp
= build_constructor (type
, v
);
9950 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9955 if (modifier
== EXPAND_WRITE
)
9957 /* Writing into CONST_DECL is always invalid, but handle it
9959 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (exp
));
9960 machine_mode address_mode
= targetm
.addr_space
.address_mode (as
);
9961 op0
= expand_expr_addr_expr_1 (exp
, NULL_RTX
, address_mode
,
9963 op0
= memory_address_addr_space (mode
, op0
, as
);
9964 temp
= gen_rtx_MEM (mode
, op0
);
9965 set_mem_addr_space (temp
, as
);
9968 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9971 /* If optimized, generate immediate CONST_DOUBLE
9972 which will be turned into memory by reload if necessary.
9974 We used to force a register so that loop.c could see it. But
9975 this does not allow gen_* patterns to perform optimizations with
9976 the constants. It also produces two insns in cases like "x = 1.0;".
9977 On most machines, floating-point constants are not permitted in
9978 many insns, so we'd end up copying it to a register in any case.
9980 Now, we do the copying in expand_binop, if appropriate. */
9981 return const_double_from_real_value (TREE_REAL_CST (exp
),
9982 TYPE_MODE (TREE_TYPE (exp
)));
9985 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9986 TYPE_MODE (TREE_TYPE (exp
)));
9989 /* Handle evaluating a complex constant in a CONCAT target. */
9990 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9992 machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9995 rtarg
= XEXP (original_target
, 0);
9996 itarg
= XEXP (original_target
, 1);
9998 /* Move the real and imaginary parts separately. */
9999 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
10000 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
10003 emit_move_insn (rtarg
, op0
);
10005 emit_move_insn (itarg
, op1
);
10007 return original_target
;
10013 temp
= expand_expr_constant (exp
, 1, modifier
);
10015 /* temp contains a constant address.
10016 On RISC machines where a constant address isn't valid,
10017 make some insns to get that address into a register. */
10018 if (modifier
!= EXPAND_CONST_ADDRESS
10019 && modifier
!= EXPAND_INITIALIZER
10020 && modifier
!= EXPAND_SUM
10021 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
10022 MEM_ADDR_SPACE (temp
)))
10023 return replace_equiv_address (temp
,
10024 copy_rtx (XEXP (temp
, 0)));
10029 tree val
= treeop0
;
10030 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
10031 inner_reference_p
);
10033 if (!SAVE_EXPR_RESOLVED_P (exp
))
10035 /* We can indeed still hit this case, typically via builtin
10036 expanders calling save_expr immediately before expanding
10037 something. Assume this means that we only have to deal
10038 with non-BLKmode values. */
10039 gcc_assert (GET_MODE (ret
) != BLKmode
);
10041 val
= build_decl (curr_insn_location (),
10042 VAR_DECL
, NULL
, TREE_TYPE (exp
));
10043 DECL_ARTIFICIAL (val
) = 1;
10044 DECL_IGNORED_P (val
) = 1;
10046 TREE_OPERAND (exp
, 0) = treeop0
;
10047 SAVE_EXPR_RESOLVED_P (exp
) = 1;
10049 if (!CONSTANT_P (ret
))
10050 ret
= copy_to_reg (ret
);
10051 SET_DECL_RTL (val
, ret
);
10059 /* If we don't need the result, just ensure we evaluate any
10063 unsigned HOST_WIDE_INT idx
;
10066 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
10067 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
10072 return expand_constructor (exp
, target
, modifier
, false);
10074 case TARGET_MEM_REF
:
10077 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
10078 enum insn_code icode
;
10079 unsigned int align
;
10081 op0
= addr_for_mem_ref (exp
, as
, true);
10082 op0
= memory_address_addr_space (mode
, op0
, as
);
10083 temp
= gen_rtx_MEM (mode
, op0
);
10084 set_mem_attributes (temp
, exp
, 0);
10085 set_mem_addr_space (temp
, as
);
10086 align
= get_object_alignment (exp
);
10087 if (modifier
!= EXPAND_WRITE
10088 && modifier
!= EXPAND_MEMORY
10090 && align
< GET_MODE_ALIGNMENT (mode
)
10091 /* If the target does not have special handling for unaligned
10092 loads of mode then it can use regular moves for them. */
10093 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10094 != CODE_FOR_nothing
))
10096 struct expand_operand ops
[2];
10098 /* We've already validated the memory, and we're creating a
10099 new pseudo destination. The predicates really can't fail,
10100 nor can the generator. */
10101 create_output_operand (&ops
[0], NULL_RTX
, mode
);
10102 create_fixed_operand (&ops
[1], temp
);
10103 expand_insn (icode
, 2, ops
);
10104 temp
= ops
[0].value
;
10111 const bool reverse
= REF_REVERSE_STORAGE_ORDER (exp
);
10113 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
10114 machine_mode address_mode
;
10115 tree base
= TREE_OPERAND (exp
, 0);
10117 enum insn_code icode
;
10119 /* Handle expansion of non-aliased memory with non-BLKmode. That
10120 might end up in a register. */
10121 if (mem_ref_refers_to_non_mem_p (exp
))
10123 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
10124 base
= TREE_OPERAND (base
, 0);
10127 && tree_fits_uhwi_p (TYPE_SIZE (type
))
10128 && (GET_MODE_BITSIZE (DECL_MODE (base
))
10129 == tree_to_uhwi (TYPE_SIZE (type
))))
10130 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
10131 target
, tmode
, modifier
);
10132 if (TYPE_MODE (type
) == BLKmode
)
10134 temp
= assign_stack_temp (DECL_MODE (base
),
10135 GET_MODE_SIZE (DECL_MODE (base
)));
10136 store_expr (base
, temp
, 0, false, false);
10137 temp
= adjust_address (temp
, BLKmode
, offset
);
10138 set_mem_size (temp
, int_size_in_bytes (type
));
10141 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
10142 bitsize_int (offset
* BITS_PER_UNIT
));
10143 REF_REVERSE_STORAGE_ORDER (exp
) = reverse
;
10144 return expand_expr (exp
, target
, tmode
, modifier
);
10146 address_mode
= targetm
.addr_space
.address_mode (as
);
10147 base
= TREE_OPERAND (exp
, 0);
10148 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
10150 tree mask
= gimple_assign_rhs2 (def_stmt
);
10151 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
10152 gimple_assign_rhs1 (def_stmt
), mask
);
10153 TREE_OPERAND (exp
, 0) = base
;
10155 align
= get_object_alignment (exp
);
10156 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
10157 op0
= memory_address_addr_space (mode
, op0
, as
);
10158 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
10160 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
10161 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
10162 op0
= memory_address_addr_space (mode
, op0
, as
);
10164 temp
= gen_rtx_MEM (mode
, op0
);
10165 set_mem_attributes (temp
, exp
, 0);
10166 set_mem_addr_space (temp
, as
);
10167 if (TREE_THIS_VOLATILE (exp
))
10168 MEM_VOLATILE_P (temp
) = 1;
10169 if (modifier
!= EXPAND_WRITE
10170 && modifier
!= EXPAND_MEMORY
10171 && !inner_reference_p
10173 && align
< GET_MODE_ALIGNMENT (mode
))
10175 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10176 != CODE_FOR_nothing
)
10178 struct expand_operand ops
[2];
10180 /* We've already validated the memory, and we're creating a
10181 new pseudo destination. The predicates really can't fail,
10182 nor can the generator. */
10183 create_output_operand (&ops
[0], NULL_RTX
, mode
);
10184 create_fixed_operand (&ops
[1], temp
);
10185 expand_insn (icode
, 2, ops
);
10186 temp
= ops
[0].value
;
10188 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
10189 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
10190 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
10191 (modifier
== EXPAND_STACK_PARM
10192 ? NULL_RTX
: target
),
10193 mode
, mode
, false);
10196 && modifier
!= EXPAND_MEMORY
10197 && modifier
!= EXPAND_WRITE
)
10198 temp
= flip_storage_order (mode
, temp
);
10205 tree array
= treeop0
;
10206 tree index
= treeop1
;
10209 /* Fold an expression like: "foo"[2].
10210 This is not done in fold so it won't happen inside &.
10211 Don't fold if this is for wide characters since it's too
10212 difficult to do correctly and this is a very rare case. */
10214 if (modifier
!= EXPAND_CONST_ADDRESS
10215 && modifier
!= EXPAND_INITIALIZER
10216 && modifier
!= EXPAND_MEMORY
)
10218 tree t
= fold_read_from_constant_string (exp
);
10221 return expand_expr (t
, target
, tmode
, modifier
);
10224 /* If this is a constant index into a constant array,
10225 just get the value from the array. Handle both the cases when
10226 we have an explicit constructor and when our operand is a variable
10227 that was declared const. */
10229 if (modifier
!= EXPAND_CONST_ADDRESS
10230 && modifier
!= EXPAND_INITIALIZER
10231 && modifier
!= EXPAND_MEMORY
10232 && TREE_CODE (array
) == CONSTRUCTOR
10233 && ! TREE_SIDE_EFFECTS (array
)
10234 && TREE_CODE (index
) == INTEGER_CST
)
10236 unsigned HOST_WIDE_INT ix
;
10239 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
10241 if (tree_int_cst_equal (field
, index
))
10243 if (!TREE_SIDE_EFFECTS (value
))
10244 return expand_expr (fold (value
), target
, tmode
, modifier
);
10249 else if (optimize
>= 1
10250 && modifier
!= EXPAND_CONST_ADDRESS
10251 && modifier
!= EXPAND_INITIALIZER
10252 && modifier
!= EXPAND_MEMORY
10253 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
10254 && TREE_CODE (index
) == INTEGER_CST
10255 && (VAR_P (array
) || TREE_CODE (array
) == CONST_DECL
)
10256 && (init
= ctor_for_folding (array
)) != error_mark_node
)
10258 if (init
== NULL_TREE
)
10260 tree value
= build_zero_cst (type
);
10261 if (TREE_CODE (value
) == CONSTRUCTOR
)
10263 /* If VALUE is a CONSTRUCTOR, this optimization is only
10264 useful if this doesn't store the CONSTRUCTOR into
10265 memory. If it does, it is more efficient to just
10266 load the data from the array directly. */
10267 rtx ret
= expand_constructor (value
, target
,
10269 if (ret
== NULL_RTX
)
10274 return expand_expr (value
, target
, tmode
, modifier
);
10276 else if (TREE_CODE (init
) == CONSTRUCTOR
)
10278 unsigned HOST_WIDE_INT ix
;
10281 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
10283 if (tree_int_cst_equal (field
, index
))
10285 if (TREE_SIDE_EFFECTS (value
))
10288 if (TREE_CODE (value
) == CONSTRUCTOR
)
10290 /* If VALUE is a CONSTRUCTOR, this
10291 optimization is only useful if
10292 this doesn't store the CONSTRUCTOR
10293 into memory. If it does, it is more
10294 efficient to just load the data from
10295 the array directly. */
10296 rtx ret
= expand_constructor (value
, target
,
10298 if (ret
== NULL_RTX
)
10303 expand_expr (fold (value
), target
, tmode
, modifier
);
10306 else if (TREE_CODE (init
) == STRING_CST
)
10308 tree low_bound
= array_ref_low_bound (exp
);
10309 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
10311 /* Optimize the special case of a zero lower bound.
10313 We convert the lower bound to sizetype to avoid problems
10314 with constant folding. E.g. suppose the lower bound is
10315 1 and its mode is QI. Without the conversion
10316 (ARRAY + (INDEX - (unsigned char)1))
10318 (ARRAY + (-(unsigned char)1) + INDEX)
10320 (ARRAY + 255 + INDEX). Oops! */
10321 if (!integer_zerop (low_bound
))
10322 index1
= size_diffop_loc (loc
, index1
,
10323 fold_convert_loc (loc
, sizetype
,
10326 if (tree_fits_uhwi_p (index1
)
10327 && compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
10329 tree type
= TREE_TYPE (TREE_TYPE (init
));
10330 machine_mode mode
= TYPE_MODE (type
);
10332 if (GET_MODE_CLASS (mode
) == MODE_INT
10333 && GET_MODE_SIZE (mode
) == 1)
10334 return gen_int_mode (TREE_STRING_POINTER (init
)
10335 [TREE_INT_CST_LOW (index1
)],
10341 goto normal_inner_ref
;
10343 case COMPONENT_REF
:
10344 /* If the operand is a CONSTRUCTOR, we can just extract the
10345 appropriate field if it is present. */
10346 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
10348 unsigned HOST_WIDE_INT idx
;
10351 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
10353 if (field
== treeop1
10354 /* We can normally use the value of the field in the
10355 CONSTRUCTOR. However, if this is a bitfield in
10356 an integral mode that we can fit in a HOST_WIDE_INT,
10357 we must mask only the number of bits in the bitfield,
10358 since this is done implicitly by the constructor. If
10359 the bitfield does not meet either of those conditions,
10360 we can't do this optimization. */
10361 && (! DECL_BIT_FIELD (field
)
10362 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
10363 && (GET_MODE_PRECISION (DECL_MODE (field
))
10364 <= HOST_BITS_PER_WIDE_INT
))))
10366 if (DECL_BIT_FIELD (field
)
10367 && modifier
== EXPAND_STACK_PARM
)
10369 op0
= expand_expr (value
, target
, tmode
, modifier
);
10370 if (DECL_BIT_FIELD (field
))
10372 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
10373 machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
10375 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
10377 op1
= gen_int_mode ((HOST_WIDE_INT_1
<< bitsize
) - 1,
10379 op0
= expand_and (imode
, op0
, op1
, target
);
10383 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10385 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10387 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10395 goto normal_inner_ref
;
10397 case BIT_FIELD_REF
:
10398 case ARRAY_RANGE_REF
:
10401 machine_mode mode1
, mode2
;
10402 HOST_WIDE_INT bitsize
, bitpos
;
10404 int reversep
, volatilep
= 0, must_force_mem
;
10406 = get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode1
,
10407 &unsignedp
, &reversep
, &volatilep
);
10408 rtx orig_op0
, memloc
;
10409 bool clear_mem_expr
= false;
10411 /* If we got back the original object, something is wrong. Perhaps
10412 we are evaluating an expression too early. In any event, don't
10413 infinitely recurse. */
10414 gcc_assert (tem
!= exp
);
10416 /* If TEM's type is a union of variable size, pass TARGET to the inner
10417 computation, since it will need a temporary and TARGET is known
10418 to have to do. This occurs in unchecked conversion in Ada. */
10420 = expand_expr_real (tem
,
10421 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10422 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10423 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10425 && modifier
!= EXPAND_STACK_PARM
10426 ? target
: NULL_RTX
),
10428 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10431 /* If the field has a mode, we want to access it in the
10432 field's mode, not the computed mode.
10433 If a MEM has VOIDmode (external with incomplete type),
10434 use BLKmode for it instead. */
10437 if (mode1
!= VOIDmode
)
10438 op0
= adjust_address (op0
, mode1
, 0);
10439 else if (GET_MODE (op0
) == VOIDmode
)
10440 op0
= adjust_address (op0
, BLKmode
, 0);
10444 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10446 /* If we have either an offset, a BLKmode result, or a reference
10447 outside the underlying object, we must force it to memory.
10448 Such a case can occur in Ada if we have unchecked conversion
10449 of an expression from a scalar type to an aggregate type or
10450 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10451 passed a partially uninitialized object or a view-conversion
10452 to a larger size. */
10453 must_force_mem
= (offset
10454 || mode1
== BLKmode
10455 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10457 /* Handle CONCAT first. */
10458 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10461 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
))
10462 && COMPLEX_MODE_P (mode1
)
10463 && COMPLEX_MODE_P (GET_MODE (op0
))
10464 && (GET_MODE_PRECISION (GET_MODE_INNER (mode1
))
10465 == GET_MODE_PRECISION (GET_MODE_INNER (GET_MODE (op0
)))))
10468 op0
= flip_storage_order (GET_MODE (op0
), op0
);
10469 if (mode1
!= GET_MODE (op0
))
10472 for (int i
= 0; i
< 2; i
++)
10474 rtx op
= read_complex_part (op0
, i
!= 0);
10475 if (GET_CODE (op
) == SUBREG
)
10476 op
= force_reg (GET_MODE (op
), op
);
10477 rtx temp
= gen_lowpart_common (GET_MODE_INNER (mode1
),
10483 if (!REG_P (op
) && !MEM_P (op
))
10484 op
= force_reg (GET_MODE (op
), op
);
10485 op
= gen_lowpart (GET_MODE_INNER (mode1
), op
);
10489 op0
= gen_rtx_CONCAT (mode1
, parts
[0], parts
[1]);
10494 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10497 op0
= XEXP (op0
, 0);
10498 mode2
= GET_MODE (op0
);
10500 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10501 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10505 op0
= XEXP (op0
, 1);
10507 mode2
= GET_MODE (op0
);
10510 /* Otherwise force into memory. */
10511 must_force_mem
= 1;
10514 /* If this is a constant, put it in a register if it is a legitimate
10515 constant and we don't need a memory reference. */
10516 if (CONSTANT_P (op0
)
10517 && mode2
!= BLKmode
10518 && targetm
.legitimate_constant_p (mode2
, op0
)
10519 && !must_force_mem
)
10520 op0
= force_reg (mode2
, op0
);
10522 /* Otherwise, if this is a constant, try to force it to the constant
10523 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10524 is a legitimate constant. */
10525 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10526 op0
= validize_mem (memloc
);
10528 /* Otherwise, if this is a constant or the object is not in memory
10529 and need be, put it there. */
10530 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10532 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10533 emit_move_insn (memloc
, op0
);
10535 clear_mem_expr
= true;
10540 machine_mode address_mode
;
10541 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10544 gcc_assert (MEM_P (op0
));
10546 address_mode
= get_address_mode (op0
);
10547 if (GET_MODE (offset_rtx
) != address_mode
)
10549 /* We cannot be sure that the RTL in offset_rtx is valid outside
10550 of a memory address context, so force it into a register
10551 before attempting to convert it to the desired mode. */
10552 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
10553 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10556 /* See the comment in expand_assignment for the rationale. */
10557 if (mode1
!= VOIDmode
10560 && (bitpos
% bitsize
) == 0
10561 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10562 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10564 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10568 op0
= offset_address (op0
, offset_rtx
,
10569 highest_pow2_factor (offset
));
10572 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10573 record its alignment as BIGGEST_ALIGNMENT. */
10574 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10575 && is_aligning_offset (offset
, tem
))
10576 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10578 /* Don't forget about volatility even if this is a bitfield. */
10579 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10581 if (op0
== orig_op0
)
10582 op0
= copy_rtx (op0
);
10584 MEM_VOLATILE_P (op0
) = 1;
10587 /* In cases where an aligned union has an unaligned object
10588 as a field, we might be extracting a BLKmode value from
10589 an integer-mode (e.g., SImode) object. Handle this case
10590 by doing the extract into an object as wide as the field
10591 (which we know to be the width of a basic mode), then
10592 storing into memory, and changing the mode to BLKmode. */
10593 if (mode1
== VOIDmode
10594 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10595 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10596 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10597 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10598 && modifier
!= EXPAND_CONST_ADDRESS
10599 && modifier
!= EXPAND_INITIALIZER
10600 && modifier
!= EXPAND_MEMORY
)
10601 /* If the bitfield is volatile and the bitsize
10602 is narrower than the access size of the bitfield,
10603 we need to extract bitfields from the access. */
10604 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10605 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10606 && mode1
!= BLKmode
10607 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10608 /* If the field isn't aligned enough to fetch as a memref,
10609 fetch it as a bit field. */
10610 || (mode1
!= BLKmode
10611 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10612 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10614 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10615 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10616 && modifier
!= EXPAND_MEMORY
10617 && ((modifier
== EXPAND_CONST_ADDRESS
10618 || modifier
== EXPAND_INITIALIZER
)
10620 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10621 || (bitpos
% BITS_PER_UNIT
!= 0)))
10622 /* If the type and the field are a constant size and the
10623 size of the type isn't the same size as the bitfield,
10624 we must use bitfield operations. */
10626 && TYPE_SIZE (TREE_TYPE (exp
))
10627 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10628 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10631 machine_mode ext_mode
= mode
;
10633 if (ext_mode
== BLKmode
10634 && ! (target
!= 0 && MEM_P (op0
)
10636 && bitpos
% BITS_PER_UNIT
== 0))
10637 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10639 if (ext_mode
== BLKmode
)
10642 target
= assign_temp (type
, 1, 1);
10644 /* ??? Unlike the similar test a few lines below, this one is
10645 very likely obsolete. */
10649 /* In this case, BITPOS must start at a byte boundary and
10650 TARGET, if specified, must be a MEM. */
10651 gcc_assert (MEM_P (op0
)
10652 && (!target
|| MEM_P (target
))
10653 && !(bitpos
% BITS_PER_UNIT
));
10655 emit_block_move (target
,
10656 adjust_address (op0
, VOIDmode
,
10657 bitpos
/ BITS_PER_UNIT
),
10658 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10660 (modifier
== EXPAND_STACK_PARM
10661 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10666 /* If we have nothing to extract, the result will be 0 for targets
10667 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10668 return 0 for the sake of consistency, as reading a zero-sized
10669 bitfield is valid in Ada and the value is fully specified. */
10673 op0
= validize_mem (op0
);
10675 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10676 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10678 /* If the result has a record type and the extraction is done in
10679 an integral mode, then the field may be not aligned on a byte
10680 boundary; in this case, if it has reverse storage order, it
10681 needs to be extracted as a scalar field with reverse storage
10682 order and put back into memory order afterwards. */
10683 if (TREE_CODE (type
) == RECORD_TYPE
10684 && GET_MODE_CLASS (ext_mode
) == MODE_INT
)
10685 reversep
= TYPE_REVERSE_STORAGE_ORDER (type
);
10687 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10688 (modifier
== EXPAND_STACK_PARM
10689 ? NULL_RTX
: target
),
10690 ext_mode
, ext_mode
, reversep
);
10692 /* If the result has a record type and the mode of OP0 is an
10693 integral mode then, if BITSIZE is narrower than this mode
10694 and this is for big-endian data, we must put the field
10695 into the high-order bits. And we must also put it back
10696 into memory order if it has been previously reversed. */
10697 if (TREE_CODE (type
) == RECORD_TYPE
10698 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
10700 HOST_WIDE_INT size
= GET_MODE_BITSIZE (GET_MODE (op0
));
10703 && reversep
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
10704 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10705 size
- bitsize
, op0
, 1);
10708 op0
= flip_storage_order (GET_MODE (op0
), op0
);
10711 /* If the result type is BLKmode, store the data into a temporary
10712 of the appropriate type, but with the mode corresponding to the
10713 mode for the data we have (op0's mode). */
10714 if (mode
== BLKmode
)
10717 = assign_stack_temp_for_type (ext_mode
,
10718 GET_MODE_BITSIZE (ext_mode
),
10720 emit_move_insn (new_rtx
, op0
);
10721 op0
= copy_rtx (new_rtx
);
10722 PUT_MODE (op0
, BLKmode
);
10728 /* If the result is BLKmode, use that to access the object
10730 if (mode
== BLKmode
)
10733 /* Get a reference to just this component. */
10734 if (modifier
== EXPAND_CONST_ADDRESS
10735 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10736 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10738 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10740 if (op0
== orig_op0
)
10741 op0
= copy_rtx (op0
);
10743 /* Don't set memory attributes if the base expression is
10744 SSA_NAME that got expanded as a MEM. In that case, we should
10745 just honor its original memory attributes. */
10746 if (TREE_CODE (tem
) != SSA_NAME
|| !MEM_P (orig_op0
))
10747 set_mem_attributes (op0
, exp
, 0);
10749 if (REG_P (XEXP (op0
, 0)))
10750 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10752 /* If op0 is a temporary because the original expressions was forced
10753 to memory, clear MEM_EXPR so that the original expression cannot
10754 be marked as addressable through MEM_EXPR of the temporary. */
10755 if (clear_mem_expr
)
10756 set_mem_expr (op0
, NULL_TREE
);
10758 MEM_VOLATILE_P (op0
) |= volatilep
;
10761 && modifier
!= EXPAND_MEMORY
10762 && modifier
!= EXPAND_WRITE
)
10763 op0
= flip_storage_order (mode1
, op0
);
10765 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10766 || modifier
== EXPAND_CONST_ADDRESS
10767 || modifier
== EXPAND_INITIALIZER
)
10771 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10773 convert_move (target
, op0
, unsignedp
);
10778 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10781 /* All valid uses of __builtin_va_arg_pack () are removed during
10783 if (CALL_EXPR_VA_ARG_PACK (exp
))
10784 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10786 tree fndecl
= get_callee_fndecl (exp
), attr
;
10789 && (attr
= lookup_attribute ("error",
10790 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10791 error ("%Kcall to %qs declared with attribute error: %s",
10792 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10793 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10795 && (attr
= lookup_attribute ("warning",
10796 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10797 warning_at (tree_nonartificial_location (exp
),
10798 0, "%Kcall to %qs declared with attribute warning: %s",
10799 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10800 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10802 /* Check for a built-in function. */
10803 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10805 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10806 if (CALL_WITH_BOUNDS_P (exp
))
10807 return expand_builtin_with_bounds (exp
, target
, subtarget
,
10810 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10813 return expand_call (exp
, target
, ignore
);
10815 case VIEW_CONVERT_EXPR
:
10818 /* If we are converting to BLKmode, try to avoid an intermediate
10819 temporary by fetching an inner memory reference. */
10820 if (mode
== BLKmode
10821 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10822 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10823 && handled_component_p (treeop0
))
10825 machine_mode mode1
;
10826 HOST_WIDE_INT bitsize
, bitpos
;
10828 int unsignedp
, reversep
, volatilep
= 0;
10830 = get_inner_reference (treeop0
, &bitsize
, &bitpos
, &offset
, &mode1
,
10831 &unsignedp
, &reversep
, &volatilep
);
10834 /* ??? We should work harder and deal with non-zero offsets. */
10836 && (bitpos
% BITS_PER_UNIT
) == 0
10839 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10841 /* See the normal_inner_ref case for the rationale. */
10843 = expand_expr_real (tem
,
10844 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10845 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10847 && modifier
!= EXPAND_STACK_PARM
10848 ? target
: NULL_RTX
),
10850 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10853 if (MEM_P (orig_op0
))
10857 /* Get a reference to just this component. */
10858 if (modifier
== EXPAND_CONST_ADDRESS
10859 || modifier
== EXPAND_SUM
10860 || modifier
== EXPAND_INITIALIZER
)
10861 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10863 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10865 if (op0
== orig_op0
)
10866 op0
= copy_rtx (op0
);
10868 set_mem_attributes (op0
, treeop0
, 0);
10869 if (REG_P (XEXP (op0
, 0)))
10870 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10872 MEM_VOLATILE_P (op0
) |= volatilep
;
10878 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10879 NULL
, inner_reference_p
);
10881 /* If the input and output modes are both the same, we are done. */
10882 if (mode
== GET_MODE (op0
))
10884 /* If neither mode is BLKmode, and both modes are the same size
10885 then we can use gen_lowpart. */
10886 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10887 && (GET_MODE_PRECISION (mode
)
10888 == GET_MODE_PRECISION (GET_MODE (op0
)))
10889 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10891 if (GET_CODE (op0
) == SUBREG
)
10892 op0
= force_reg (GET_MODE (op0
), op0
);
10893 temp
= gen_lowpart_common (mode
, op0
);
10898 if (!REG_P (op0
) && !MEM_P (op0
))
10899 op0
= force_reg (GET_MODE (op0
), op0
);
10900 op0
= gen_lowpart (mode
, op0
);
10903 /* If both types are integral, convert from one mode to the other. */
10904 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10905 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10906 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10907 /* If the output type is a bit-field type, do an extraction. */
10908 else if (reduce_bit_field
)
10909 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10910 TYPE_UNSIGNED (type
), NULL_RTX
,
10911 mode
, mode
, false);
10912 /* As a last resort, spill op0 to memory, and reload it in a
10914 else if (!MEM_P (op0
))
10916 /* If the operand is not a MEM, force it into memory. Since we
10917 are going to be changing the mode of the MEM, don't call
10918 force_const_mem for constants because we don't allow pool
10919 constants to change mode. */
10920 tree inner_type
= TREE_TYPE (treeop0
);
10922 gcc_assert (!TREE_ADDRESSABLE (exp
));
10924 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10926 = assign_stack_temp_for_type
10927 (TYPE_MODE (inner_type
),
10928 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10930 emit_move_insn (target
, op0
);
10934 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10935 output type is such that the operand is known to be aligned, indicate
10936 that it is. Otherwise, we need only be concerned about alignment for
10937 non-BLKmode results. */
10940 enum insn_code icode
;
10942 if (modifier
!= EXPAND_WRITE
10943 && modifier
!= EXPAND_MEMORY
10944 && !inner_reference_p
10946 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10948 /* If the target does have special handling for unaligned
10949 loads of mode then use them. */
10950 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10951 != CODE_FOR_nothing
)
10955 op0
= adjust_address (op0
, mode
, 0);
10956 /* We've already validated the memory, and we're creating a
10957 new pseudo destination. The predicates really can't
10959 reg
= gen_reg_rtx (mode
);
10961 /* Nor can the insn generator. */
10962 rtx_insn
*insn
= GEN_FCN (icode
) (reg
, op0
);
10966 else if (STRICT_ALIGNMENT
)
10968 tree inner_type
= TREE_TYPE (treeop0
);
10969 HOST_WIDE_INT temp_size
10970 = MAX (int_size_in_bytes (inner_type
),
10971 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10973 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10974 rtx new_with_op0_mode
10975 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10977 gcc_assert (!TREE_ADDRESSABLE (exp
));
10979 if (GET_MODE (op0
) == BLKmode
)
10980 emit_block_move (new_with_op0_mode
, op0
,
10981 GEN_INT (GET_MODE_SIZE (mode
)),
10982 (modifier
== EXPAND_STACK_PARM
10983 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10985 emit_move_insn (new_with_op0_mode
, op0
);
10991 op0
= adjust_address (op0
, mode
, 0);
10998 tree lhs
= treeop0
;
10999 tree rhs
= treeop1
;
11000 gcc_assert (ignore
);
11002 /* Check for |= or &= of a bitfield of size one into another bitfield
11003 of size 1. In this case, (unless we need the result of the
11004 assignment) we can do this more efficiently with a
11005 test followed by an assignment, if necessary.
11007 ??? At this point, we can't get a BIT_FIELD_REF here. But if
11008 things change so we do, this code should be enhanced to
11010 if (TREE_CODE (lhs
) == COMPONENT_REF
11011 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
11012 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
11013 && TREE_OPERAND (rhs
, 0) == lhs
11014 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
11015 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
11016 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
11018 rtx_code_label
*label
= gen_label_rtx ();
11019 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
11020 do_jump (TREE_OPERAND (rhs
, 1),
11022 value
? 0 : label
, -1);
11023 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
11025 do_pending_stack_adjust ();
11026 emit_label (label
);
11030 expand_assignment (lhs
, rhs
, false);
11035 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
11037 case REALPART_EXPR
:
11038 op0
= expand_normal (treeop0
);
11039 return read_complex_part (op0
, false);
11041 case IMAGPART_EXPR
:
11042 op0
= expand_normal (treeop0
);
11043 return read_complex_part (op0
, true);
11050 /* Expanded in cfgexpand.c. */
11051 gcc_unreachable ();
11053 case TRY_CATCH_EXPR
:
11055 case EH_FILTER_EXPR
:
11056 case TRY_FINALLY_EXPR
:
11057 /* Lowered by tree-eh.c. */
11058 gcc_unreachable ();
11060 case WITH_CLEANUP_EXPR
:
11061 case CLEANUP_POINT_EXPR
:
11063 case CASE_LABEL_EXPR
:
11068 case COMPOUND_EXPR
:
11069 case PREINCREMENT_EXPR
:
11070 case PREDECREMENT_EXPR
:
11071 case POSTINCREMENT_EXPR
:
11072 case POSTDECREMENT_EXPR
:
11075 case COMPOUND_LITERAL_EXPR
:
11076 /* Lowered by gimplify.c. */
11077 gcc_unreachable ();
11080 /* Function descriptors are not valid except for as
11081 initialization constants, and should not be expanded. */
11082 gcc_unreachable ();
11084 case WITH_SIZE_EXPR
:
11085 /* WITH_SIZE_EXPR expands to its first argument. The caller should
11086 have pulled out the size to use in whatever context it needed. */
11087 return expand_expr_real (treeop0
, original_target
, tmode
,
11088 modifier
, alt_rtl
, inner_reference_p
);
11091 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
11095 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
11096 signedness of TYPE), possibly returning the result in TARGET. */
11098 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
11100 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
11101 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
11103 /* For constant values, reduce using build_int_cst_type. */
11104 if (CONST_INT_P (exp
))
11106 HOST_WIDE_INT value
= INTVAL (exp
);
11107 tree t
= build_int_cst_type (type
, value
);
11108 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
11110 else if (TYPE_UNSIGNED (type
))
11112 machine_mode mode
= GET_MODE (exp
);
11113 rtx mask
= immed_wide_int_const
11114 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
11115 return expand_and (mode
, exp
, mask
, target
);
11119 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
11120 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
11121 exp
, count
, target
, 0);
11122 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
11123 exp
, count
, target
, 0);
11127 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
11128 when applied to the address of EXP produces an address known to be
11129 aligned more than BIGGEST_ALIGNMENT. */
11132 is_aligning_offset (const_tree offset
, const_tree exp
)
11134 /* Strip off any conversions. */
11135 while (CONVERT_EXPR_P (offset
))
11136 offset
= TREE_OPERAND (offset
, 0);
11138 /* We must now have a BIT_AND_EXPR with a constant that is one less than
11139 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
11140 if (TREE_CODE (offset
) != BIT_AND_EXPR
11141 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
11142 || compare_tree_int (TREE_OPERAND (offset
, 1),
11143 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
11144 || !pow2p_hwi (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1))
11147 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
11148 It must be NEGATE_EXPR. Then strip any more conversions. */
11149 offset
= TREE_OPERAND (offset
, 0);
11150 while (CONVERT_EXPR_P (offset
))
11151 offset
= TREE_OPERAND (offset
, 0);
11153 if (TREE_CODE (offset
) != NEGATE_EXPR
)
11156 offset
= TREE_OPERAND (offset
, 0);
11157 while (CONVERT_EXPR_P (offset
))
11158 offset
= TREE_OPERAND (offset
, 0);
11160 /* This must now be the address of EXP. */
11161 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
11164 /* Return the tree node if an ARG corresponds to a string constant or zero
11165 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
11166 in bytes within the string that ARG is accessing. The type of the
11167 offset will be `sizetype'. */
11170 string_constant (tree arg
, tree
*ptr_offset
)
11172 tree array
, offset
, lower_bound
;
11175 if (TREE_CODE (arg
) == ADDR_EXPR
)
11177 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
11179 *ptr_offset
= size_zero_node
;
11180 return TREE_OPERAND (arg
, 0);
11182 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
11184 array
= TREE_OPERAND (arg
, 0);
11185 offset
= size_zero_node
;
11187 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
11189 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
11190 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
11191 if (TREE_CODE (array
) != STRING_CST
&& !VAR_P (array
))
11194 /* Check if the array has a nonzero lower bound. */
11195 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
11196 if (!integer_zerop (lower_bound
))
11198 /* If the offset and base aren't both constants, return 0. */
11199 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
11201 if (TREE_CODE (offset
) != INTEGER_CST
)
11203 /* Adjust offset by the lower bound. */
11204 offset
= size_diffop (fold_convert (sizetype
, offset
),
11205 fold_convert (sizetype
, lower_bound
));
11208 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
11210 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
11211 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
11212 if (TREE_CODE (array
) != ADDR_EXPR
)
11214 array
= TREE_OPERAND (array
, 0);
11215 if (TREE_CODE (array
) != STRING_CST
&& !VAR_P (array
))
11221 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
11223 tree arg0
= TREE_OPERAND (arg
, 0);
11224 tree arg1
= TREE_OPERAND (arg
, 1);
11229 if (TREE_CODE (arg0
) == ADDR_EXPR
11230 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
11231 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
11233 array
= TREE_OPERAND (arg0
, 0);
11236 else if (TREE_CODE (arg1
) == ADDR_EXPR
11237 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
11238 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
11240 array
= TREE_OPERAND (arg1
, 0);
11249 if (TREE_CODE (array
) == STRING_CST
)
11251 *ptr_offset
= fold_convert (sizetype
, offset
);
11254 else if (VAR_P (array
) || TREE_CODE (array
) == CONST_DECL
)
11257 tree init
= ctor_for_folding (array
);
11259 /* Variables initialized to string literals can be handled too. */
11260 if (init
== error_mark_node
11262 || TREE_CODE (init
) != STRING_CST
)
11265 /* Avoid const char foo[4] = "abcde"; */
11266 if (DECL_SIZE_UNIT (array
) == NULL_TREE
11267 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
11268 || (length
= TREE_STRING_LENGTH (init
)) <= 0
11269 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
11272 /* If variable is bigger than the string literal, OFFSET must be constant
11273 and inside of the bounds of the string literal. */
11274 offset
= fold_convert (sizetype
, offset
);
11275 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
11276 && (! tree_fits_uhwi_p (offset
)
11277 || compare_tree_int (offset
, length
) >= 0))
11280 *ptr_offset
= offset
;
11287 /* Generate code to calculate OPS, and exploded expression
11288 using a store-flag instruction and return an rtx for the result.
11289 OPS reflects a comparison.
11291 If TARGET is nonzero, store the result there if convenient.
11293 Return zero if there is no suitable set-flag instruction
11294 available on this machine.
11296 Once expand_expr has been called on the arguments of the comparison,
11297 we are committed to doing the store flag, since it is not safe to
11298 re-evaluate the expression. We emit the store-flag insn by calling
11299 emit_store_flag, but only expand the arguments if we have a reason
11300 to believe that emit_store_flag will be successful. If we think that
11301 it will, but it isn't, we have to simulate the store-flag with a
11302 set/jump/set sequence. */
11305 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
11307 enum rtx_code code
;
11308 tree arg0
, arg1
, type
;
11309 machine_mode operand_mode
;
11312 rtx subtarget
= target
;
11313 location_t loc
= ops
->location
;
11318 /* Don't crash if the comparison was erroneous. */
11319 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
11322 type
= TREE_TYPE (arg0
);
11323 operand_mode
= TYPE_MODE (type
);
11324 unsignedp
= TYPE_UNSIGNED (type
);
11326 /* We won't bother with BLKmode store-flag operations because it would mean
11327 passing a lot of information to emit_store_flag. */
11328 if (operand_mode
== BLKmode
)
11331 /* We won't bother with store-flag operations involving function pointers
11332 when function pointers must be canonicalized before comparisons. */
11333 if (targetm
.have_canonicalize_funcptr_for_compare ()
11334 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
11335 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
11337 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
11338 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
11339 == FUNCTION_TYPE
))))
11345 /* For vector typed comparisons emit code to generate the desired
11346 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
11347 expander for this. */
11348 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
11350 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
11351 if (VECTOR_BOOLEAN_TYPE_P (ops
->type
)
11352 && expand_vec_cmp_expr_p (TREE_TYPE (arg0
), ops
->type
, ops
->code
))
11353 return expand_vec_cmp_expr (ops
->type
, ifexp
, target
);
11356 tree if_true
= constant_boolean_node (true, ops
->type
);
11357 tree if_false
= constant_boolean_node (false, ops
->type
);
11358 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
,
11363 /* Get the rtx comparison code to use. We know that EXP is a comparison
11364 operation of some type. Some comparisons against 1 and -1 can be
11365 converted to comparisons with zero. Do so here so that the tests
11366 below will be aware that we have a comparison with zero. These
11367 tests will not catch constants in the first operand, but constants
11368 are rarely passed as the first operand. */
11379 if (integer_onep (arg1
))
11380 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
11382 code
= unsignedp
? LTU
: LT
;
11385 if (! unsignedp
&& integer_all_onesp (arg1
))
11386 arg1
= integer_zero_node
, code
= LT
;
11388 code
= unsignedp
? LEU
: LE
;
11391 if (! unsignedp
&& integer_all_onesp (arg1
))
11392 arg1
= integer_zero_node
, code
= GE
;
11394 code
= unsignedp
? GTU
: GT
;
11397 if (integer_onep (arg1
))
11398 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
11400 code
= unsignedp
? GEU
: GE
;
11403 case UNORDERED_EXPR
:
11429 gcc_unreachable ();
11432 /* Put a constant second. */
11433 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11434 || TREE_CODE (arg0
) == FIXED_CST
)
11436 std::swap (arg0
, arg1
);
11437 code
= swap_condition (code
);
11440 /* If this is an equality or inequality test of a single bit, we can
11441 do this by shifting the bit being tested to the low-order bit and
11442 masking the result with the constant 1. If the condition was EQ,
11443 we xor it with 1. This does not require an scc insn and is faster
11444 than an scc insn even if we have it.
11446 The code to make this transformation was moved into fold_single_bit_test,
11447 so we just call into the folder and expand its result. */
11449 if ((code
== NE
|| code
== EQ
)
11450 && integer_zerop (arg1
)
11451 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11453 gimple
*srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11455 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11457 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11458 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11459 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11460 gimple_assign_rhs1 (srcstmt
),
11461 gimple_assign_rhs2 (srcstmt
));
11462 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11464 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11468 if (! get_subtarget (target
)
11469 || GET_MODE (subtarget
) != operand_mode
)
11472 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11475 target
= gen_reg_rtx (mode
);
11477 /* Try a cstore if possible. */
11478 return emit_store_flag_force (target
, code
, op0
, op1
,
11479 operand_mode
, unsignedp
,
11480 (TYPE_PRECISION (ops
->type
) == 1
11481 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11484 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11485 0 otherwise (i.e. if there is no casesi instruction).
11487 DEFAULT_PROBABILITY is the probability of jumping to the default
11490 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11491 rtx table_label
, rtx default_label
, rtx fallback_label
,
11492 int default_probability
)
11494 struct expand_operand ops
[5];
11495 machine_mode index_mode
= SImode
;
11496 rtx op1
, op2
, index
;
11498 if (! targetm
.have_casesi ())
11501 /* Convert the index to SImode. */
11502 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11504 machine_mode omode
= TYPE_MODE (index_type
);
11505 rtx rangertx
= expand_normal (range
);
11507 /* We must handle the endpoints in the original mode. */
11508 index_expr
= build2 (MINUS_EXPR
, index_type
,
11509 index_expr
, minval
);
11510 minval
= integer_zero_node
;
11511 index
= expand_normal (index_expr
);
11513 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11514 omode
, 1, default_label
,
11515 default_probability
);
11516 /* Now we can safely truncate. */
11517 index
= convert_to_mode (index_mode
, index
, 0);
11521 if (TYPE_MODE (index_type
) != index_mode
)
11523 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11524 index_expr
= fold_convert (index_type
, index_expr
);
11527 index
= expand_normal (index_expr
);
11530 do_pending_stack_adjust ();
11532 op1
= expand_normal (minval
);
11533 op2
= expand_normal (range
);
11535 create_input_operand (&ops
[0], index
, index_mode
);
11536 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11537 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11538 create_fixed_operand (&ops
[3], table_label
);
11539 create_fixed_operand (&ops
[4], (default_label
11541 : fallback_label
));
11542 expand_jump_insn (targetm
.code_for_casesi
, 5, ops
);
11546 /* Attempt to generate a tablejump instruction; same concept. */
11547 /* Subroutine of the next function.
11549 INDEX is the value being switched on, with the lowest value
11550 in the table already subtracted.
11551 MODE is its expected mode (needed if INDEX is constant).
11552 RANGE is the length of the jump table.
11553 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11555 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11556 index value is out of range.
11557 DEFAULT_PROBABILITY is the probability of jumping to
11558 the default label. */
11561 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
11562 rtx default_label
, int default_probability
)
11566 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11567 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11569 /* Do an unsigned comparison (in the proper mode) between the index
11570 expression and the value which represents the length of the range.
11571 Since we just finished subtracting the lower bound of the range
11572 from the index expression, this comparison allows us to simultaneously
11573 check that the original index expression value is both greater than
11574 or equal to the minimum value of the range and less than or equal to
11575 the maximum value of the range. */
11578 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11579 default_label
, default_probability
);
11582 /* If index is in range, it must fit in Pmode.
11583 Convert to Pmode so we can index with it. */
11585 index
= convert_to_mode (Pmode
, index
, 1);
11587 /* Don't let a MEM slip through, because then INDEX that comes
11588 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11589 and break_out_memory_refs will go to work on it and mess it up. */
11590 #ifdef PIC_CASE_VECTOR_ADDRESS
11591 if (flag_pic
&& !REG_P (index
))
11592 index
= copy_to_mode_reg (Pmode
, index
);
11595 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11596 GET_MODE_SIZE, because this indicates how large insns are. The other
11597 uses should all be Pmode, because they are addresses. This code
11598 could fail if addresses and insns are not the same size. */
11599 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11600 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11602 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11603 gen_rtx_LABEL_REF (Pmode
, table_label
));
11605 #ifdef PIC_CASE_VECTOR_ADDRESS
11607 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11610 index
= memory_address (CASE_VECTOR_MODE
, index
);
11611 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11612 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11613 convert_move (temp
, vector
, 0);
11615 emit_jump_insn (targetm
.gen_tablejump (temp
, table_label
));
11617 /* If we are generating PIC code or if the table is PC-relative, the
11618 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11619 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11624 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11625 rtx table_label
, rtx default_label
, int default_probability
)
11629 if (! targetm
.have_tablejump ())
11632 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11633 fold_convert (index_type
, index_expr
),
11634 fold_convert (index_type
, minval
));
11635 index
= expand_normal (index_expr
);
11636 do_pending_stack_adjust ();
11638 do_tablejump (index
, TYPE_MODE (index_type
),
11639 convert_modes (TYPE_MODE (index_type
),
11640 TYPE_MODE (TREE_TYPE (range
)),
11641 expand_normal (range
),
11642 TYPE_UNSIGNED (TREE_TYPE (range
))),
11643 table_label
, default_label
, default_probability
);
11647 /* Return a CONST_VECTOR rtx representing vector mask for
11648 a VECTOR_CST of booleans. */
11650 const_vector_mask_from_tree (tree exp
)
11656 machine_mode inner
, mode
;
11658 mode
= TYPE_MODE (TREE_TYPE (exp
));
11659 units
= GET_MODE_NUNITS (mode
);
11660 inner
= GET_MODE_INNER (mode
);
11662 v
= rtvec_alloc (units
);
11664 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11666 elt
= VECTOR_CST_ELT (exp
, i
);
11668 gcc_assert (TREE_CODE (elt
) == INTEGER_CST
);
11669 if (integer_zerop (elt
))
11670 RTVEC_ELT (v
, i
) = CONST0_RTX (inner
);
11671 else if (integer_onep (elt
)
11672 || integer_minus_onep (elt
))
11673 RTVEC_ELT (v
, i
) = CONSTM1_RTX (inner
);
11675 gcc_unreachable ();
11678 return gen_rtx_CONST_VECTOR (mode
, v
);
11681 /* Return a CONST_INT rtx representing vector mask for
11682 a VECTOR_CST of booleans. */
11684 const_scalar_mask_from_tree (tree exp
)
11686 machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
11687 wide_int res
= wi::zero (GET_MODE_PRECISION (mode
));
11691 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11693 elt
= VECTOR_CST_ELT (exp
, i
);
11694 gcc_assert (TREE_CODE (elt
) == INTEGER_CST
);
11695 if (integer_all_onesp (elt
))
11696 res
= wi::set_bit (res
, i
);
11698 gcc_assert (integer_zerop (elt
));
11701 return immed_wide_int_const (res
, mode
);
11704 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11706 const_vector_from_tree (tree exp
)
11712 machine_mode inner
, mode
;
11714 mode
= TYPE_MODE (TREE_TYPE (exp
));
11716 if (initializer_zerop (exp
))
11717 return CONST0_RTX (mode
);
11719 if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp
)))
11720 return const_vector_mask_from_tree (exp
);
11722 units
= GET_MODE_NUNITS (mode
);
11723 inner
= GET_MODE_INNER (mode
);
11725 v
= rtvec_alloc (units
);
11727 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11729 elt
= VECTOR_CST_ELT (exp
, i
);
11731 if (TREE_CODE (elt
) == REAL_CST
)
11732 RTVEC_ELT (v
, i
) = const_double_from_real_value (TREE_REAL_CST (elt
),
11734 else if (TREE_CODE (elt
) == FIXED_CST
)
11735 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11738 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11741 return gen_rtx_CONST_VECTOR (mode
, v
);
11744 /* Build a decl for a personality function given a language prefix. */
11747 build_personality_function (const char *lang
)
11749 const char *unwind_and_version
;
11753 switch (targetm_common
.except_unwind_info (&global_options
))
11758 unwind_and_version
= "_sj0";
11762 unwind_and_version
= "_v0";
11765 unwind_and_version
= "_seh0";
11768 gcc_unreachable ();
11771 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11773 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11774 long_long_unsigned_type_node
,
11775 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11776 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11777 get_identifier (name
), type
);
11778 DECL_ARTIFICIAL (decl
) = 1;
11779 DECL_EXTERNAL (decl
) = 1;
11780 TREE_PUBLIC (decl
) = 1;
11782 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11783 are the flags assigned by targetm.encode_section_info. */
11784 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11789 /* Extracts the personality function of DECL and returns the corresponding
11793 get_personality_function (tree decl
)
11795 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11796 enum eh_personality_kind pk
;
11798 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11799 if (pk
== eh_personality_none
)
11803 && pk
== eh_personality_any
)
11804 personality
= lang_hooks
.eh_personality ();
11806 if (pk
== eh_personality_lang
)
11807 gcc_assert (personality
!= NULL_TREE
);
11809 return XEXP (DECL_RTL (personality
), 0);
11812 /* Returns a tree for the size of EXP in bytes. */
11815 tree_expr_size (const_tree exp
)
11818 && DECL_SIZE_UNIT (exp
) != 0)
11819 return DECL_SIZE_UNIT (exp
);
11821 return size_in_bytes (TREE_TYPE (exp
));
11824 /* Return an rtx for the size in bytes of the value of EXP. */
11827 expr_size (tree exp
)
11831 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11832 size
= TREE_OPERAND (exp
, 1);
11835 size
= tree_expr_size (exp
);
11837 gcc_assert (size
== SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, exp
));
11840 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), EXPAND_NORMAL
);
11843 /* Return a wide integer for the size in bytes of the value of EXP, or -1
11844 if the size can vary or is larger than an integer. */
11846 static HOST_WIDE_INT
11847 int_expr_size (tree exp
)
11851 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11852 size
= TREE_OPERAND (exp
, 1);
11855 size
= tree_expr_size (exp
);
11859 if (size
== 0 || !tree_fits_shwi_p (size
))
11862 return tree_to_shwi (size
);