1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2015 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"
31 #include "fold-const.h"
32 #include "stor-layout.h"
38 #include "insn-config.h"
39 #include "insn-attr.h"
46 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
48 #include "insn-codes.h"
53 #include "typeclass.h"
55 #include "langhooks.h"
58 #include "tree-iterator.h"
59 #include "internal-fn.h"
62 #include "common/common-target.h"
64 #include "diagnostic.h"
65 #include "tree-ssa-live.h"
66 #include "tree-outof-ssa.h"
67 #include "target-globals.h"
69 #include "tree-ssa-address.h"
70 #include "cfgexpand.h"
72 #include "tree-chkp.h"
77 /* If this is nonzero, we do not bother generating VOLATILE
78 around volatile memory references, and we are willing to
79 output indirect addresses. If cse is to follow, we reject
80 indirect addresses so a useful potential cse is generated;
81 if it is used only once, instruction combination will produce
82 the same indirect address eventually. */
85 /* This structure is used by move_by_pieces to describe the move to
87 struct move_by_pieces_d
96 int explicit_inc_from
;
97 unsigned HOST_WIDE_INT len
;
102 /* This structure is used by store_by_pieces to describe the clear to
105 struct store_by_pieces_d
111 unsigned HOST_WIDE_INT len
;
112 HOST_WIDE_INT offset
;
113 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
);
118 static void move_by_pieces_1 (insn_gen_fn
, machine_mode
,
119 struct move_by_pieces_d
*);
120 static bool block_move_libcall_safe_for_call_parm (void);
121 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
122 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
123 unsigned HOST_WIDE_INT
);
124 static tree
emit_block_move_libcall_fn (int);
125 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
126 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, machine_mode
);
127 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
128 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
129 static void store_by_pieces_2 (insn_gen_fn
, machine_mode
,
130 struct store_by_pieces_d
*);
131 static tree
clear_storage_libcall_fn (int);
132 static rtx_insn
*compress_float_constant (rtx
, rtx
);
133 static rtx
get_subtarget (rtx
);
134 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
135 HOST_WIDE_INT
, machine_mode
,
136 tree
, int, alias_set_type
);
137 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
138 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
139 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
140 machine_mode
, tree
, alias_set_type
, bool);
142 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
144 static int is_aligning_offset (const_tree
, const_tree
);
145 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
146 static rtx
do_store_flag (sepops
, rtx
, machine_mode
);
148 static void emit_single_push_insn (machine_mode
, rtx
, tree
);
150 static void do_tablejump (rtx
, machine_mode
, rtx
, rtx
, rtx
, int);
151 static rtx
const_vector_from_tree (tree
);
152 static tree
tree_expr_size (const_tree
);
153 static HOST_WIDE_INT
int_expr_size (tree
);
156 /* This is run to set up which modes can be used
157 directly in memory and to initialize the block move optab. It is run
158 at the beginning of compilation and when the target is reinitialized. */
161 init_expr_target (void)
169 /* Try indexing by frame ptr and try by stack ptr.
170 It is known that on the Convex the stack ptr isn't a valid index.
171 With luck, one or the other is valid on any machine. */
172 mem
= gen_rtx_MEM (word_mode
, stack_pointer_rtx
);
173 mem1
= gen_rtx_MEM (word_mode
, frame_pointer_rtx
);
175 /* A scratch register we can modify in-place below to avoid
176 useless RTL allocations. */
177 reg
= gen_rtx_REG (word_mode
, LAST_VIRTUAL_REGISTER
+ 1);
179 insn
= rtx_alloc (INSN
);
180 pat
= gen_rtx_SET (NULL_RTX
, NULL_RTX
);
181 PATTERN (insn
) = pat
;
183 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
184 mode
= (machine_mode
) ((int) mode
+ 1))
188 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
189 PUT_MODE (mem
, mode
);
190 PUT_MODE (mem1
, mode
);
192 /* See if there is some register that can be used in this mode and
193 directly loaded or stored from memory. */
195 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
196 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
197 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
200 if (! HARD_REGNO_MODE_OK (regno
, mode
))
203 set_mode_and_regno (reg
, mode
, regno
);
206 SET_DEST (pat
) = reg
;
207 if (recog (pat
, insn
, &num_clobbers
) >= 0)
208 direct_load
[(int) mode
] = 1;
210 SET_SRC (pat
) = mem1
;
211 SET_DEST (pat
) = reg
;
212 if (recog (pat
, insn
, &num_clobbers
) >= 0)
213 direct_load
[(int) mode
] = 1;
216 SET_DEST (pat
) = mem
;
217 if (recog (pat
, insn
, &num_clobbers
) >= 0)
218 direct_store
[(int) mode
] = 1;
221 SET_DEST (pat
) = mem1
;
222 if (recog (pat
, insn
, &num_clobbers
) >= 0)
223 direct_store
[(int) mode
] = 1;
227 mem
= gen_rtx_MEM (VOIDmode
, gen_raw_REG (Pmode
, LAST_VIRTUAL_REGISTER
+ 1));
229 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
230 mode
= GET_MODE_WIDER_MODE (mode
))
232 machine_mode srcmode
;
233 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
234 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
238 ic
= can_extend_p (mode
, srcmode
, 0);
239 if (ic
== CODE_FOR_nothing
)
242 PUT_MODE (mem
, srcmode
);
244 if (insn_operand_matches (ic
, 1, mem
))
245 float_extend_from_mem
[mode
][srcmode
] = true;
250 /* This is run at the start of compiling a function. */
255 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
258 /* Copy data from FROM to TO, where the machine modes are not the same.
259 Both modes may be integer, or both may be floating, or both may be
261 UNSIGNEDP should be nonzero if FROM is an unsigned type.
262 This causes zero-extension instead of sign-extension. */
265 convert_move (rtx to
, rtx from
, int unsignedp
)
267 machine_mode to_mode
= GET_MODE (to
);
268 machine_mode from_mode
= GET_MODE (from
);
269 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
270 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
274 /* rtx code for making an equivalent value. */
275 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
276 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
279 gcc_assert (to_real
== from_real
);
280 gcc_assert (to_mode
!= BLKmode
);
281 gcc_assert (from_mode
!= BLKmode
);
283 /* If the source and destination are already the same, then there's
288 /* If FROM is a SUBREG that indicates that we have already done at least
289 the required extension, strip it. We don't handle such SUBREGs as
292 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
293 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
294 >= GET_MODE_PRECISION (to_mode
))
295 && SUBREG_CHECK_PROMOTED_SIGN (from
, unsignedp
))
296 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
298 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
300 if (to_mode
== from_mode
301 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
303 emit_move_insn (to
, from
);
307 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
309 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
311 if (VECTOR_MODE_P (to_mode
))
312 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
314 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
316 emit_move_insn (to
, from
);
320 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
322 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
323 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
333 gcc_assert ((GET_MODE_PRECISION (from_mode
)
334 != GET_MODE_PRECISION (to_mode
))
335 || (DECIMAL_FLOAT_MODE_P (from_mode
)
336 != DECIMAL_FLOAT_MODE_P (to_mode
)));
338 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
339 /* Conversion between decimal float and binary float, same size. */
340 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
341 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
346 /* Try converting directly if the insn is supported. */
348 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
349 if (code
!= CODE_FOR_nothing
)
351 emit_unop_insn (code
, to
, from
,
352 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
356 /* Otherwise use a libcall. */
357 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
359 /* Is this conversion implemented yet? */
360 gcc_assert (libcall
);
363 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
365 insns
= get_insns ();
367 emit_libcall_block (insns
, to
, value
,
368 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
370 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
374 /* Handle pointer conversion. */ /* SPEE 900220. */
375 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
379 if (GET_MODE_PRECISION (from_mode
) > GET_MODE_PRECISION (to_mode
))
386 if (convert_optab_handler (ctab
, to_mode
, from_mode
)
389 emit_unop_insn (convert_optab_handler (ctab
, to_mode
, from_mode
),
395 /* Targets are expected to provide conversion insns between PxImode and
396 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
397 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
399 machine_mode full_mode
400 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
402 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
403 != CODE_FOR_nothing
);
405 if (full_mode
!= from_mode
)
406 from
= convert_to_mode (full_mode
, from
, unsignedp
);
407 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
411 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
414 machine_mode full_mode
415 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
416 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
417 enum insn_code icode
;
419 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
420 gcc_assert (icode
!= CODE_FOR_nothing
);
422 if (to_mode
== full_mode
)
424 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
428 new_from
= gen_reg_rtx (full_mode
);
429 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
431 /* else proceed to integer conversions below. */
432 from_mode
= full_mode
;
436 /* Make sure both are fixed-point modes or both are not. */
437 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
438 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
439 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
441 /* If we widen from_mode to to_mode and they are in the same class,
442 we won't saturate the result.
443 Otherwise, always saturate the result to play safe. */
444 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
445 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
446 expand_fixed_convert (to
, from
, 0, 0);
448 expand_fixed_convert (to
, from
, 0, 1);
452 /* Now both modes are integers. */
454 /* Handle expanding beyond a word. */
455 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
456 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
463 machine_mode lowpart_mode
;
464 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
466 /* Try converting directly if the insn is supported. */
467 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
470 /* If FROM is a SUBREG, put it into a register. Do this
471 so that we always generate the same set of insns for
472 better cse'ing; if an intermediate assignment occurred,
473 we won't be doing the operation directly on the SUBREG. */
474 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
475 from
= force_reg (from_mode
, from
);
476 emit_unop_insn (code
, to
, from
, equiv_code
);
479 /* Next, try converting via full word. */
480 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
481 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
482 != CODE_FOR_nothing
))
484 rtx word_to
= gen_reg_rtx (word_mode
);
487 if (reg_overlap_mentioned_p (to
, from
))
488 from
= force_reg (from_mode
, from
);
491 convert_move (word_to
, from
, unsignedp
);
492 emit_unop_insn (code
, to
, word_to
, equiv_code
);
496 /* No special multiword conversion insn; do it by hand. */
499 /* Since we will turn this into a no conflict block, we must ensure the
500 the source does not overlap the target so force it into an isolated
501 register when maybe so. Likewise for any MEM input, since the
502 conversion sequence might require several references to it and we
503 must ensure we're getting the same value every time. */
505 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
506 from
= force_reg (from_mode
, from
);
508 /* Get a copy of FROM widened to a word, if necessary. */
509 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
510 lowpart_mode
= word_mode
;
512 lowpart_mode
= from_mode
;
514 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
516 lowpart
= gen_lowpart (lowpart_mode
, to
);
517 emit_move_insn (lowpart
, lowfrom
);
519 /* Compute the value to put in each remaining word. */
521 fill_value
= const0_rtx
;
523 fill_value
= emit_store_flag_force (gen_reg_rtx (word_mode
),
524 LT
, lowfrom
, const0_rtx
,
525 lowpart_mode
, 0, -1);
527 /* Fill the remaining words. */
528 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
530 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
531 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
533 gcc_assert (subword
);
535 if (fill_value
!= subword
)
536 emit_move_insn (subword
, fill_value
);
539 insns
= get_insns ();
546 /* Truncating multi-word to a word or less. */
547 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
548 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
551 && ! MEM_VOLATILE_P (from
)
552 && direct_load
[(int) to_mode
]
553 && ! mode_dependent_address_p (XEXP (from
, 0),
554 MEM_ADDR_SPACE (from
)))
556 || GET_CODE (from
) == SUBREG
))
557 from
= force_reg (from_mode
, from
);
558 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
562 /* Now follow all the conversions between integers
563 no more than a word long. */
565 /* For truncation, usually we can just refer to FROM in a narrower mode. */
566 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
567 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
570 && ! MEM_VOLATILE_P (from
)
571 && direct_load
[(int) to_mode
]
572 && ! mode_dependent_address_p (XEXP (from
, 0),
573 MEM_ADDR_SPACE (from
)))
575 || GET_CODE (from
) == SUBREG
))
576 from
= force_reg (from_mode
, from
);
577 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
578 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
579 from
= copy_to_reg (from
);
580 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
584 /* Handle extension. */
585 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
587 /* Convert directly if that works. */
588 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
591 emit_unop_insn (code
, to
, from
, equiv_code
);
596 machine_mode intermediate
;
600 /* Search for a mode to convert via. */
601 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
602 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
603 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
605 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
606 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
607 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
608 != CODE_FOR_nothing
))
610 convert_move (to
, convert_to_mode (intermediate
, from
,
611 unsignedp
), unsignedp
);
615 /* No suitable intermediate mode.
616 Generate what we need with shifts. */
617 shift_amount
= (GET_MODE_PRECISION (to_mode
)
618 - GET_MODE_PRECISION (from_mode
));
619 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
620 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
622 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
625 emit_move_insn (to
, tmp
);
630 /* Support special truncate insns for certain modes. */
631 if (convert_optab_handler (trunc_optab
, to_mode
,
632 from_mode
) != CODE_FOR_nothing
)
634 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
639 /* Handle truncation of volatile memrefs, and so on;
640 the things that couldn't be truncated directly,
641 and for which there was no special instruction.
643 ??? Code above formerly short-circuited this, for most integer
644 mode pairs, with a force_reg in from_mode followed by a recursive
645 call to this routine. Appears always to have been wrong. */
646 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
648 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
649 emit_move_insn (to
, temp
);
653 /* Mode combination is not recognized. */
657 /* Return an rtx for a value that would result
658 from converting X to mode MODE.
659 Both X and MODE may be floating, or both integer.
660 UNSIGNEDP is nonzero if X is an unsigned value.
661 This can be done by referring to a part of X in place
662 or by copying to a new temporary with conversion. */
665 convert_to_mode (machine_mode mode
, rtx x
, int unsignedp
)
667 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
670 /* Return an rtx for a value that would result
671 from converting X from mode OLDMODE to mode MODE.
672 Both modes may be floating, or both integer.
673 UNSIGNEDP is nonzero if X is an unsigned value.
675 This can be done by referring to a part of X in place
676 or by copying to a new temporary with conversion.
678 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
681 convert_modes (machine_mode mode
, machine_mode oldmode
, rtx x
, int unsignedp
)
685 /* If FROM is a SUBREG that indicates that we have already done at least
686 the required extension, strip it. */
688 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
689 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
690 && SUBREG_CHECK_PROMOTED_SIGN (x
, unsignedp
))
691 x
= gen_lowpart (mode
, SUBREG_REG (x
));
693 if (GET_MODE (x
) != VOIDmode
)
694 oldmode
= GET_MODE (x
);
699 if (CONST_SCALAR_INT_P (x
) && GET_MODE_CLASS (mode
) == MODE_INT
)
701 /* If the caller did not tell us the old mode, then there is not
702 much to do with respect to canonicalization. We have to
703 assume that all the bits are significant. */
704 if (GET_MODE_CLASS (oldmode
) != MODE_INT
)
705 oldmode
= MAX_MODE_INT
;
706 wide_int w
= wide_int::from (std::make_pair (x
, oldmode
),
707 GET_MODE_PRECISION (mode
),
708 unsignedp
? UNSIGNED
: SIGNED
);
709 return immed_wide_int_const (w
, mode
);
712 /* We can do this with a gen_lowpart if both desired and current modes
713 are integer, and this is either a constant integer, a register, or a
715 if (GET_MODE_CLASS (mode
) == MODE_INT
716 && GET_MODE_CLASS (oldmode
) == MODE_INT
717 && GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
718 && ((MEM_P (x
) && !MEM_VOLATILE_P (x
) && direct_load
[(int) mode
])
720 && (!HARD_REGISTER_P (x
)
721 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
722 && TRULY_NOOP_TRUNCATION_MODES_P (mode
, GET_MODE (x
)))))
724 return gen_lowpart (mode
, x
);
726 /* Converting from integer constant into mode is always equivalent to an
728 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
730 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
731 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
734 temp
= gen_reg_rtx (mode
);
735 convert_move (temp
, x
, unsignedp
);
739 /* Return the largest alignment we can use for doing a move (or store)
740 of MAX_PIECES. ALIGN is the largest alignment we could use. */
743 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
747 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
748 if (align
>= GET_MODE_ALIGNMENT (tmode
))
749 align
= GET_MODE_ALIGNMENT (tmode
);
752 machine_mode tmode
, xmode
;
754 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
756 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
757 if (GET_MODE_SIZE (tmode
) > max_pieces
758 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
761 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
767 /* Return the widest integer mode no wider than SIZE. If no such mode
768 can be found, return VOIDmode. */
771 widest_int_mode_for_size (unsigned int size
)
773 machine_mode tmode
, mode
= VOIDmode
;
775 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
776 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
777 if (GET_MODE_SIZE (tmode
) < size
)
783 /* Determine whether the LEN bytes can be moved by using several move
784 instructions. Return nonzero if a call to move_by_pieces should
788 can_move_by_pieces (unsigned HOST_WIDE_INT len
,
791 return targetm
.use_by_pieces_infrastructure_p (len
, align
, MOVE_BY_PIECES
,
792 optimize_insn_for_speed_p ());
795 /* Generate several move instructions to copy LEN bytes from block FROM to
796 block TO. (These are MEM rtx's with BLKmode).
798 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
799 used to push FROM to the stack.
801 ALIGN is maximum stack alignment we can assume.
803 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
804 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
808 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
809 unsigned int align
, int endp
)
811 struct move_by_pieces_d data
;
812 machine_mode to_addr_mode
;
813 machine_mode from_addr_mode
= get_address_mode (from
);
814 rtx to_addr
, from_addr
= XEXP (from
, 0);
815 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
816 enum insn_code icode
;
818 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
821 data
.from_addr
= from_addr
;
824 to_addr_mode
= get_address_mode (to
);
825 to_addr
= XEXP (to
, 0);
828 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
829 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
831 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
835 to_addr_mode
= VOIDmode
;
839 if (STACK_GROWS_DOWNWARD
)
844 data
.to_addr
= to_addr
;
847 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
848 || GET_CODE (from_addr
) == POST_INC
849 || GET_CODE (from_addr
) == POST_DEC
);
851 data
.explicit_inc_from
= 0;
852 data
.explicit_inc_to
= 0;
853 if (data
.reverse
) data
.offset
= len
;
856 /* If copying requires more than two move insns,
857 copy addresses to registers (to make displacements shorter)
858 and use post-increment if available. */
859 if (!(data
.autinc_from
&& data
.autinc_to
)
860 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
862 /* Find the mode of the largest move...
863 MODE might not be used depending on the definitions of the
864 USE_* macros below. */
865 machine_mode mode ATTRIBUTE_UNUSED
866 = widest_int_mode_for_size (max_size
);
868 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
870 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
871 plus_constant (from_addr_mode
,
873 data
.autinc_from
= 1;
874 data
.explicit_inc_from
= -1;
876 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
878 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
879 data
.autinc_from
= 1;
880 data
.explicit_inc_from
= 1;
882 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
883 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
884 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
886 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
887 plus_constant (to_addr_mode
,
890 data
.explicit_inc_to
= -1;
892 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
894 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
896 data
.explicit_inc_to
= 1;
898 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
899 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
902 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
904 /* First move what we can in the largest integer mode, then go to
905 successively smaller modes. */
907 while (max_size
> 1 && data
.len
> 0)
909 machine_mode mode
= widest_int_mode_for_size (max_size
);
911 if (mode
== VOIDmode
)
914 icode
= optab_handler (mov_optab
, mode
);
915 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
916 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
918 max_size
= GET_MODE_SIZE (mode
);
921 /* The code above should have handled everything. */
922 gcc_assert (!data
.len
);
928 gcc_assert (!data
.reverse
);
933 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
934 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
936 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
937 plus_constant (to_addr_mode
,
941 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
948 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
956 /* Return number of insns required to move L bytes by pieces.
957 ALIGN (in bits) is maximum alignment we can assume. */
959 unsigned HOST_WIDE_INT
960 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
961 unsigned int max_size
)
963 unsigned HOST_WIDE_INT n_insns
= 0;
965 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
967 while (max_size
> 1 && l
> 0)
970 enum insn_code icode
;
972 mode
= widest_int_mode_for_size (max_size
);
974 if (mode
== VOIDmode
)
977 icode
= optab_handler (mov_optab
, mode
);
978 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
979 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
981 max_size
= GET_MODE_SIZE (mode
);
988 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
989 with move instructions for mode MODE. GENFUN is the gen_... function
990 to make a move insn for that mode. DATA has all the other info. */
993 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
994 struct move_by_pieces_d
*data
)
996 unsigned int size
= GET_MODE_SIZE (mode
);
997 rtx to1
= NULL_RTX
, from1
;
999 while (data
->len
>= size
)
1002 data
->offset
-= size
;
1006 if (data
->autinc_to
)
1007 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1010 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1013 if (data
->autinc_from
)
1014 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1017 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1019 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1020 emit_insn (gen_add2_insn (data
->to_addr
,
1021 gen_int_mode (-(HOST_WIDE_INT
) size
,
1022 GET_MODE (data
->to_addr
))));
1023 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1024 emit_insn (gen_add2_insn (data
->from_addr
,
1025 gen_int_mode (-(HOST_WIDE_INT
) size
,
1026 GET_MODE (data
->from_addr
))));
1029 emit_insn ((*genfun
) (to1
, from1
));
1032 #ifdef PUSH_ROUNDING
1033 emit_single_push_insn (mode
, from1
, NULL
);
1039 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1040 emit_insn (gen_add2_insn (data
->to_addr
,
1042 GET_MODE (data
->to_addr
))));
1043 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1044 emit_insn (gen_add2_insn (data
->from_addr
,
1046 GET_MODE (data
->from_addr
))));
1048 if (! data
->reverse
)
1049 data
->offset
+= size
;
1055 /* Emit code to move a block Y to a block X. This may be done with
1056 string-move instructions, with multiple scalar move instructions,
1057 or with a library call.
1059 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1060 SIZE is an rtx that says how long they are.
1061 ALIGN is the maximum alignment we can assume they have.
1062 METHOD describes what kind of copy this is, and what mechanisms may be used.
1063 MIN_SIZE is the minimal size of block to move
1064 MAX_SIZE is the maximal size of block to move, if it can not be represented
1065 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1067 Return the address of the new block, if memcpy is called and returns it,
1071 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1072 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1073 unsigned HOST_WIDE_INT min_size
,
1074 unsigned HOST_WIDE_INT max_size
,
1075 unsigned HOST_WIDE_INT probable_max_size
)
1082 if (CONST_INT_P (size
)
1083 && INTVAL (size
) == 0)
1088 case BLOCK_OP_NORMAL
:
1089 case BLOCK_OP_TAILCALL
:
1090 may_use_call
= true;
1093 case BLOCK_OP_CALL_PARM
:
1094 may_use_call
= block_move_libcall_safe_for_call_parm ();
1096 /* Make inhibit_defer_pop nonzero around the library call
1097 to force it to pop the arguments right away. */
1101 case BLOCK_OP_NO_LIBCALL
:
1102 may_use_call
= false;
1109 gcc_assert (MEM_P (x
) && MEM_P (y
));
1110 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1111 gcc_assert (align
>= BITS_PER_UNIT
);
1113 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1114 block copy is more efficient for other large modes, e.g. DCmode. */
1115 x
= adjust_address (x
, BLKmode
, 0);
1116 y
= adjust_address (y
, BLKmode
, 0);
1118 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1119 can be incorrect is coming from __builtin_memcpy. */
1120 if (CONST_INT_P (size
))
1122 x
= shallow_copy_rtx (x
);
1123 y
= shallow_copy_rtx (y
);
1124 set_mem_size (x
, INTVAL (size
));
1125 set_mem_size (y
, INTVAL (size
));
1128 if (CONST_INT_P (size
) && can_move_by_pieces (INTVAL (size
), align
))
1129 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1130 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1131 expected_align
, expected_size
,
1132 min_size
, max_size
, probable_max_size
))
1134 else if (may_use_call
1135 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1136 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1138 /* Since x and y are passed to a libcall, mark the corresponding
1139 tree EXPR as addressable. */
1140 tree y_expr
= MEM_EXPR (y
);
1141 tree x_expr
= MEM_EXPR (x
);
1143 mark_addressable (y_expr
);
1145 mark_addressable (x_expr
);
1146 retval
= emit_block_move_via_libcall (x
, y
, size
,
1147 method
== BLOCK_OP_TAILCALL
);
1151 emit_block_move_via_loop (x
, y
, size
, align
);
1153 if (method
== BLOCK_OP_CALL_PARM
)
1160 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1162 unsigned HOST_WIDE_INT max
, min
= 0;
1163 if (GET_CODE (size
) == CONST_INT
)
1164 min
= max
= UINTVAL (size
);
1166 max
= GET_MODE_MASK (GET_MODE (size
));
1167 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1171 /* A subroutine of emit_block_move. Returns true if calling the
1172 block move libcall will not clobber any parameters which may have
1173 already been placed on the stack. */
1176 block_move_libcall_safe_for_call_parm (void)
1178 #if defined (REG_PARM_STACK_SPACE)
1182 /* If arguments are pushed on the stack, then they're safe. */
1186 /* If registers go on the stack anyway, any argument is sure to clobber
1187 an outgoing argument. */
1188 #if defined (REG_PARM_STACK_SPACE)
1189 fn
= emit_block_move_libcall_fn (false);
1190 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1191 depend on its argument. */
1193 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1194 && REG_PARM_STACK_SPACE (fn
) != 0)
1198 /* If any argument goes in memory, then it might clobber an outgoing
1201 CUMULATIVE_ARGS args_so_far_v
;
1202 cumulative_args_t args_so_far
;
1205 fn
= emit_block_move_libcall_fn (false);
1206 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1207 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1209 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1210 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1212 machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1213 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1215 if (!tmp
|| !REG_P (tmp
))
1217 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1219 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1226 /* A subroutine of emit_block_move. Expand a movmem pattern;
1227 return true if successful. */
1230 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1231 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1232 unsigned HOST_WIDE_INT min_size
,
1233 unsigned HOST_WIDE_INT max_size
,
1234 unsigned HOST_WIDE_INT probable_max_size
)
1236 int save_volatile_ok
= volatile_ok
;
1239 if (expected_align
< align
)
1240 expected_align
= align
;
1241 if (expected_size
!= -1)
1243 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1244 expected_size
= probable_max_size
;
1245 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1246 expected_size
= min_size
;
1249 /* Since this is a move insn, we don't care about volatility. */
1252 /* Try the most limited insn first, because there's no point
1253 including more than one in the machine description unless
1254 the more limited one has some advantage. */
1256 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1257 mode
= GET_MODE_WIDER_MODE (mode
))
1259 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1261 if (code
!= CODE_FOR_nothing
1262 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1263 here because if SIZE is less than the mode mask, as it is
1264 returned by the macro, it will definitely be less than the
1265 actual mode mask. Since SIZE is within the Pmode address
1266 space, we limit MODE to Pmode. */
1267 && ((CONST_INT_P (size
)
1268 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1269 <= (GET_MODE_MASK (mode
) >> 1)))
1270 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1271 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1273 struct expand_operand ops
[9];
1276 /* ??? When called via emit_block_move_for_call, it'd be
1277 nice if there were some way to inform the backend, so
1278 that it doesn't fail the expansion because it thinks
1279 emitting the libcall would be more efficient. */
1280 nops
= insn_data
[(int) code
].n_generator_args
;
1281 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1283 create_fixed_operand (&ops
[0], x
);
1284 create_fixed_operand (&ops
[1], y
);
1285 /* The check above guarantees that this size conversion is valid. */
1286 create_convert_operand_to (&ops
[2], size
, mode
, true);
1287 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1290 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1291 create_integer_operand (&ops
[5], expected_size
);
1295 create_integer_operand (&ops
[6], min_size
);
1296 /* If we can not represent the maximal size,
1297 make parameter NULL. */
1298 if ((HOST_WIDE_INT
) max_size
!= -1)
1299 create_integer_operand (&ops
[7], max_size
);
1301 create_fixed_operand (&ops
[7], NULL
);
1305 /* If we can not represent the maximal size,
1306 make parameter NULL. */
1307 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1308 create_integer_operand (&ops
[8], probable_max_size
);
1310 create_fixed_operand (&ops
[8], NULL
);
1312 if (maybe_expand_insn (code
, nops
, ops
))
1314 volatile_ok
= save_volatile_ok
;
1320 volatile_ok
= save_volatile_ok
;
1324 /* A subroutine of emit_block_move. Expand a call to memcpy.
1325 Return the return value from memcpy, 0 otherwise. */
1328 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1330 rtx dst_addr
, src_addr
;
1331 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1332 machine_mode size_mode
;
1335 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1336 pseudos. We can then place those new pseudos into a VAR_DECL and
1339 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1340 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1342 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1343 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1345 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1346 src_tree
= make_tree (ptr_type_node
, src_addr
);
1348 size_mode
= TYPE_MODE (sizetype
);
1350 size
= convert_to_mode (size_mode
, size
, 1);
1351 size
= copy_to_mode_reg (size_mode
, size
);
1353 /* It is incorrect to use the libcall calling conventions to call
1354 memcpy in this context. This could be a user call to memcpy and
1355 the user may wish to examine the return value from memcpy. For
1356 targets where libcalls and normal calls have different conventions
1357 for returning pointers, we could end up generating incorrect code. */
1359 size_tree
= make_tree (sizetype
, size
);
1361 fn
= emit_block_move_libcall_fn (true);
1362 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1363 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1365 retval
= expand_normal (call_expr
);
1370 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1371 for the function we use for block copies. */
1373 static GTY(()) tree block_move_fn
;
1376 init_block_move_fn (const char *asmspec
)
1380 tree args
, fn
, attrs
, attr_args
;
1382 fn
= get_identifier ("memcpy");
1383 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1384 const_ptr_type_node
, sizetype
,
1387 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1388 DECL_EXTERNAL (fn
) = 1;
1389 TREE_PUBLIC (fn
) = 1;
1390 DECL_ARTIFICIAL (fn
) = 1;
1391 TREE_NOTHROW (fn
) = 1;
1392 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1393 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1395 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1396 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1398 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1404 set_user_assembler_name (block_move_fn
, asmspec
);
1408 emit_block_move_libcall_fn (int for_call
)
1410 static bool emitted_extern
;
1413 init_block_move_fn (NULL
);
1415 if (for_call
&& !emitted_extern
)
1417 emitted_extern
= true;
1418 make_decl_rtl (block_move_fn
);
1421 return block_move_fn
;
1424 /* A subroutine of emit_block_move. Copy the data via an explicit
1425 loop. This is used only when libcalls are forbidden. */
1426 /* ??? It'd be nice to copy in hunks larger than QImode. */
1429 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1430 unsigned int align ATTRIBUTE_UNUSED
)
1432 rtx_code_label
*cmp_label
, *top_label
;
1433 rtx iter
, x_addr
, y_addr
, tmp
;
1434 machine_mode x_addr_mode
= get_address_mode (x
);
1435 machine_mode y_addr_mode
= get_address_mode (y
);
1436 machine_mode iter_mode
;
1438 iter_mode
= GET_MODE (size
);
1439 if (iter_mode
== VOIDmode
)
1440 iter_mode
= word_mode
;
1442 top_label
= gen_label_rtx ();
1443 cmp_label
= gen_label_rtx ();
1444 iter
= gen_reg_rtx (iter_mode
);
1446 emit_move_insn (iter
, const0_rtx
);
1448 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1449 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1450 do_pending_stack_adjust ();
1452 emit_jump (cmp_label
);
1453 emit_label (top_label
);
1455 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1456 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1458 if (x_addr_mode
!= y_addr_mode
)
1459 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1460 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1462 x
= change_address (x
, QImode
, x_addr
);
1463 y
= change_address (y
, QImode
, y_addr
);
1465 emit_move_insn (x
, y
);
1467 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1468 true, OPTAB_LIB_WIDEN
);
1470 emit_move_insn (iter
, tmp
);
1472 emit_label (cmp_label
);
1474 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1475 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1478 /* Copy all or part of a value X into registers starting at REGNO.
1479 The number of registers to be filled is NREGS. */
1482 move_block_to_reg (int regno
, rtx x
, int nregs
, machine_mode mode
)
1487 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1488 x
= validize_mem (force_const_mem (mode
, x
));
1490 /* See if the machine can do this with a load multiple insn. */
1491 if (targetm
.have_load_multiple ())
1493 rtx_insn
*last
= get_last_insn ();
1494 rtx first
= gen_rtx_REG (word_mode
, regno
);
1495 if (rtx_insn
*pat
= targetm
.gen_load_multiple (first
, x
,
1502 delete_insns_since (last
);
1505 for (int i
= 0; i
< nregs
; i
++)
1506 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1507 operand_subword_force (x
, i
, mode
));
1510 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1511 The number of registers to be filled is NREGS. */
1514 move_block_from_reg (int regno
, rtx x
, int nregs
)
1519 /* See if the machine can do this with a store multiple insn. */
1520 if (targetm
.have_store_multiple ())
1522 rtx_insn
*last
= get_last_insn ();
1523 rtx first
= gen_rtx_REG (word_mode
, regno
);
1524 if (rtx_insn
*pat
= targetm
.gen_store_multiple (x
, first
,
1531 delete_insns_since (last
);
1534 for (int i
= 0; i
< nregs
; i
++)
1536 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1540 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1544 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1545 ORIG, where ORIG is a non-consecutive group of registers represented by
1546 a PARALLEL. The clone is identical to the original except in that the
1547 original set of registers is replaced by a new set of pseudo registers.
1548 The new set has the same modes as the original set. */
1551 gen_group_rtx (rtx orig
)
1556 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1558 length
= XVECLEN (orig
, 0);
1559 tmps
= XALLOCAVEC (rtx
, length
);
1561 /* Skip a NULL entry in first slot. */
1562 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1567 for (; i
< length
; i
++)
1569 machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1570 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1572 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1575 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1578 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1579 except that values are placed in TMPS[i], and must later be moved
1580 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1583 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1587 machine_mode m
= GET_MODE (orig_src
);
1589 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1592 && !SCALAR_INT_MODE_P (m
)
1593 && !MEM_P (orig_src
)
1594 && GET_CODE (orig_src
) != CONCAT
)
1596 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1597 if (imode
== BLKmode
)
1598 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1600 src
= gen_reg_rtx (imode
);
1601 if (imode
!= BLKmode
)
1602 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1603 emit_move_insn (src
, orig_src
);
1604 /* ...and back again. */
1605 if (imode
!= BLKmode
)
1606 src
= gen_lowpart (imode
, src
);
1607 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1611 /* Check for a NULL entry, used to indicate that the parameter goes
1612 both on the stack and in registers. */
1613 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1618 /* Process the pieces. */
1619 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1621 machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1622 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1623 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1626 /* Handle trailing fragments that run over the size of the struct. */
1627 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1629 /* Arrange to shift the fragment to where it belongs.
1630 extract_bit_field loads to the lsb of the reg. */
1632 #ifdef BLOCK_REG_PADDING
1633 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1634 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1639 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1640 bytelen
= ssize
- bytepos
;
1641 gcc_assert (bytelen
> 0);
1644 /* If we won't be loading directly from memory, protect the real source
1645 from strange tricks we might play; but make sure that the source can
1646 be loaded directly into the destination. */
1648 if (!MEM_P (orig_src
)
1649 && (!CONSTANT_P (orig_src
)
1650 || (GET_MODE (orig_src
) != mode
1651 && GET_MODE (orig_src
) != VOIDmode
)))
1653 if (GET_MODE (orig_src
) == VOIDmode
)
1654 src
= gen_reg_rtx (mode
);
1656 src
= gen_reg_rtx (GET_MODE (orig_src
));
1658 emit_move_insn (src
, orig_src
);
1661 /* Optimize the access just a bit. */
1663 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1664 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1665 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1666 && bytelen
== GET_MODE_SIZE (mode
))
1668 tmps
[i
] = gen_reg_rtx (mode
);
1669 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1671 else if (COMPLEX_MODE_P (mode
)
1672 && GET_MODE (src
) == mode
1673 && bytelen
== GET_MODE_SIZE (mode
))
1674 /* Let emit_move_complex do the bulk of the work. */
1676 else if (GET_CODE (src
) == CONCAT
)
1678 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1679 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1681 if ((bytepos
== 0 && bytelen
== slen0
)
1682 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1684 /* The following assumes that the concatenated objects all
1685 have the same size. In this case, a simple calculation
1686 can be used to determine the object and the bit field
1688 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1689 if (! CONSTANT_P (tmps
[i
])
1690 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1691 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1692 (bytepos
% slen0
) * BITS_PER_UNIT
,
1693 1, NULL_RTX
, mode
, mode
);
1699 gcc_assert (!bytepos
);
1700 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1701 emit_move_insn (mem
, src
);
1702 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1703 0, 1, NULL_RTX
, mode
, mode
);
1706 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1707 SIMD register, which is currently broken. While we get GCC
1708 to emit proper RTL for these cases, let's dump to memory. */
1709 else if (VECTOR_MODE_P (GET_MODE (dst
))
1712 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1715 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1716 emit_move_insn (mem
, src
);
1717 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1719 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1720 && XVECLEN (dst
, 0) > 1)
1721 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1722 else if (CONSTANT_P (src
))
1724 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1732 /* TODO: const_wide_int can have sizes other than this... */
1733 gcc_assert (2 * len
== ssize
);
1734 split_double (src
, &first
, &second
);
1741 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1744 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1745 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1749 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1754 /* Emit code to move a block SRC of type TYPE to a block DST,
1755 where DST is non-consecutive registers represented by a PARALLEL.
1756 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1760 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1765 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1766 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1768 /* Copy the extracted pieces into the proper (probable) hard regs. */
1769 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1771 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1774 emit_move_insn (d
, tmps
[i
]);
1778 /* Similar, but load SRC into new pseudos in a format that looks like
1779 PARALLEL. This can later be fed to emit_group_move to get things
1780 in the right place. */
1783 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1788 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1789 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1791 /* Convert the vector to look just like the original PARALLEL, except
1792 with the computed values. */
1793 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1795 rtx e
= XVECEXP (parallel
, 0, i
);
1796 rtx d
= XEXP (e
, 0);
1800 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1801 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1803 RTVEC_ELT (vec
, i
) = e
;
1806 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1809 /* Emit code to move a block SRC to block DST, where SRC and DST are
1810 non-consecutive groups of registers, each represented by a PARALLEL. */
1813 emit_group_move (rtx dst
, rtx src
)
1817 gcc_assert (GET_CODE (src
) == PARALLEL
1818 && GET_CODE (dst
) == PARALLEL
1819 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1821 /* Skip first entry if NULL. */
1822 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1823 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1824 XEXP (XVECEXP (src
, 0, i
), 0));
1827 /* Move a group of registers represented by a PARALLEL into pseudos. */
1830 emit_group_move_into_temps (rtx src
)
1832 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1835 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1837 rtx e
= XVECEXP (src
, 0, i
);
1838 rtx d
= XEXP (e
, 0);
1841 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1842 RTVEC_ELT (vec
, i
) = e
;
1845 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1848 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1849 where SRC is non-consecutive registers represented by a PARALLEL.
1850 SSIZE represents the total size of block ORIG_DST, or -1 if not
1854 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1857 int start
, finish
, i
;
1858 machine_mode m
= GET_MODE (orig_dst
);
1860 gcc_assert (GET_CODE (src
) == PARALLEL
);
1862 if (!SCALAR_INT_MODE_P (m
)
1863 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1865 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1866 if (imode
== BLKmode
)
1867 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1869 dst
= gen_reg_rtx (imode
);
1870 emit_group_store (dst
, src
, type
, ssize
);
1871 if (imode
!= BLKmode
)
1872 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1873 emit_move_insn (orig_dst
, dst
);
1877 /* Check for a NULL entry, used to indicate that the parameter goes
1878 both on the stack and in registers. */
1879 if (XEXP (XVECEXP (src
, 0, 0), 0))
1883 finish
= XVECLEN (src
, 0);
1885 tmps
= XALLOCAVEC (rtx
, finish
);
1887 /* Copy the (probable) hard regs into pseudos. */
1888 for (i
= start
; i
< finish
; i
++)
1890 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1891 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1893 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1894 emit_move_insn (tmps
[i
], reg
);
1900 /* If we won't be storing directly into memory, protect the real destination
1901 from strange tricks we might play. */
1903 if (GET_CODE (dst
) == PARALLEL
)
1907 /* We can get a PARALLEL dst if there is a conditional expression in
1908 a return statement. In that case, the dst and src are the same,
1909 so no action is necessary. */
1910 if (rtx_equal_p (dst
, src
))
1913 /* It is unclear if we can ever reach here, but we may as well handle
1914 it. Allocate a temporary, and split this into a store/load to/from
1916 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1917 emit_group_store (temp
, src
, type
, ssize
);
1918 emit_group_load (dst
, temp
, type
, ssize
);
1921 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1923 machine_mode outer
= GET_MODE (dst
);
1925 HOST_WIDE_INT bytepos
;
1929 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1930 dst
= gen_reg_rtx (outer
);
1932 /* Make life a bit easier for combine. */
1933 /* If the first element of the vector is the low part
1934 of the destination mode, use a paradoxical subreg to
1935 initialize the destination. */
1938 inner
= GET_MODE (tmps
[start
]);
1939 bytepos
= subreg_lowpart_offset (inner
, outer
);
1940 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1942 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1946 emit_move_insn (dst
, temp
);
1953 /* If the first element wasn't the low part, try the last. */
1955 && start
< finish
- 1)
1957 inner
= GET_MODE (tmps
[finish
- 1]);
1958 bytepos
= subreg_lowpart_offset (inner
, outer
);
1959 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1961 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1965 emit_move_insn (dst
, temp
);
1972 /* Otherwise, simply initialize the result to zero. */
1974 emit_move_insn (dst
, CONST0_RTX (outer
));
1977 /* Process the pieces. */
1978 for (i
= start
; i
< finish
; i
++)
1980 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
1981 machine_mode mode
= GET_MODE (tmps
[i
]);
1982 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1983 unsigned int adj_bytelen
;
1986 /* Handle trailing fragments that run over the size of the struct. */
1987 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1988 adj_bytelen
= ssize
- bytepos
;
1990 adj_bytelen
= bytelen
;
1992 if (GET_CODE (dst
) == CONCAT
)
1994 if (bytepos
+ adj_bytelen
1995 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
1996 dest
= XEXP (dst
, 0);
1997 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
1999 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2000 dest
= XEXP (dst
, 1);
2004 machine_mode dest_mode
= GET_MODE (dest
);
2005 machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2007 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2009 if (GET_MODE_ALIGNMENT (dest_mode
)
2010 >= GET_MODE_ALIGNMENT (tmp_mode
))
2012 dest
= assign_stack_temp (dest_mode
,
2013 GET_MODE_SIZE (dest_mode
));
2014 emit_move_insn (adjust_address (dest
,
2022 dest
= assign_stack_temp (tmp_mode
,
2023 GET_MODE_SIZE (tmp_mode
));
2024 emit_move_insn (dest
, tmps
[i
]);
2025 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2031 /* Handle trailing fragments that run over the size of the struct. */
2032 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2034 /* store_bit_field always takes its value from the lsb.
2035 Move the fragment to the lsb if it's not already there. */
2037 #ifdef BLOCK_REG_PADDING
2038 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2039 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2045 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2046 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2050 /* Make sure not to write past the end of the struct. */
2051 store_bit_field (dest
,
2052 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2053 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
- 1,
2057 /* Optimize the access just a bit. */
2058 else if (MEM_P (dest
)
2059 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2060 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2061 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2062 && bytelen
== GET_MODE_SIZE (mode
))
2063 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2066 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2067 0, 0, mode
, tmps
[i
]);
2070 /* Copy from the pseudo into the (probable) hard reg. */
2071 if (orig_dst
!= dst
)
2072 emit_move_insn (orig_dst
, dst
);
2075 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2076 of the value stored in X. */
2079 maybe_emit_group_store (rtx x
, tree type
)
2081 machine_mode mode
= TYPE_MODE (type
);
2082 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2083 if (GET_CODE (x
) == PARALLEL
)
2085 rtx result
= gen_reg_rtx (mode
);
2086 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2092 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2094 This is used on targets that return BLKmode values in registers. */
2097 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2099 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2100 rtx src
= NULL
, dst
= NULL
;
2101 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2102 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2103 machine_mode mode
= GET_MODE (srcreg
);
2104 machine_mode tmode
= GET_MODE (target
);
2105 machine_mode copy_mode
;
2107 /* BLKmode registers created in the back-end shouldn't have survived. */
2108 gcc_assert (mode
!= BLKmode
);
2110 /* If the structure doesn't take up a whole number of words, see whether
2111 SRCREG is padded on the left or on the right. If it's on the left,
2112 set PADDING_CORRECTION to the number of bits to skip.
2114 In most ABIs, the structure will be returned at the least end of
2115 the register, which translates to right padding on little-endian
2116 targets and left padding on big-endian targets. The opposite
2117 holds if the structure is returned at the most significant
2118 end of the register. */
2119 if (bytes
% UNITS_PER_WORD
!= 0
2120 && (targetm
.calls
.return_in_msb (type
)
2122 : BYTES_BIG_ENDIAN
))
2124 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2126 /* We can use a single move if we have an exact mode for the size. */
2127 else if (MEM_P (target
)
2128 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2129 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2130 && bytes
== GET_MODE_SIZE (mode
))
2132 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2136 /* And if we additionally have the same mode for a register. */
2137 else if (REG_P (target
)
2138 && GET_MODE (target
) == mode
2139 && bytes
== GET_MODE_SIZE (mode
))
2141 emit_move_insn (target
, srcreg
);
2145 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2146 into a new pseudo which is a full word. */
2147 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2149 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2153 /* Copy the structure BITSIZE bits at a time. If the target lives in
2154 memory, take care of not reading/writing past its end by selecting
2155 a copy mode suited to BITSIZE. This should always be possible given
2158 If the target lives in register, make sure not to select a copy mode
2159 larger than the mode of the register.
2161 We could probably emit more efficient code for machines which do not use
2162 strict alignment, but it doesn't seem worth the effort at the current
2165 copy_mode
= word_mode
;
2168 machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2169 if (mem_mode
!= BLKmode
)
2170 copy_mode
= mem_mode
;
2172 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2175 for (bitpos
= 0, xbitpos
= padding_correction
;
2176 bitpos
< bytes
* BITS_PER_UNIT
;
2177 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2179 /* We need a new source operand each time xbitpos is on a
2180 word boundary and when xbitpos == padding_correction
2181 (the first time through). */
2182 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2183 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2185 /* We need a new destination operand each time bitpos is on
2187 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2189 else if (bitpos
% BITS_PER_WORD
== 0)
2190 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2192 /* Use xbitpos for the source extraction (right justified) and
2193 bitpos for the destination store (left justified). */
2194 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2195 extract_bit_field (src
, bitsize
,
2196 xbitpos
% BITS_PER_WORD
, 1,
2197 NULL_RTX
, copy_mode
, copy_mode
));
2201 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2202 register if it contains any data, otherwise return null.
2204 This is used on targets that return BLKmode values in registers. */
2207 copy_blkmode_to_reg (machine_mode mode
, tree src
)
2210 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2211 unsigned int bitsize
;
2212 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2213 machine_mode dst_mode
;
2215 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2217 x
= expand_normal (src
);
2219 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2223 /* If the structure doesn't take up a whole number of words, see
2224 whether the register value should be padded on the left or on
2225 the right. Set PADDING_CORRECTION to the number of padding
2226 bits needed on the left side.
2228 In most ABIs, the structure will be returned at the least end of
2229 the register, which translates to right padding on little-endian
2230 targets and left padding on big-endian targets. The opposite
2231 holds if the structure is returned at the most significant
2232 end of the register. */
2233 if (bytes
% UNITS_PER_WORD
!= 0
2234 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2236 : BYTES_BIG_ENDIAN
))
2237 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2240 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2241 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2242 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2244 /* Copy the structure BITSIZE bits at a time. */
2245 for (bitpos
= 0, xbitpos
= padding_correction
;
2246 bitpos
< bytes
* BITS_PER_UNIT
;
2247 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2249 /* We need a new destination pseudo each time xbitpos is
2250 on a word boundary and when xbitpos == padding_correction
2251 (the first time through). */
2252 if (xbitpos
% BITS_PER_WORD
== 0
2253 || xbitpos
== padding_correction
)
2255 /* Generate an appropriate register. */
2256 dst_word
= gen_reg_rtx (word_mode
);
2257 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2259 /* Clear the destination before we move anything into it. */
2260 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2263 /* We need a new source operand each time bitpos is on a word
2265 if (bitpos
% BITS_PER_WORD
== 0)
2266 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2268 /* Use bitpos for the source extraction (left justified) and
2269 xbitpos for the destination store (right justified). */
2270 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2272 extract_bit_field (src_word
, bitsize
,
2273 bitpos
% BITS_PER_WORD
, 1,
2274 NULL_RTX
, word_mode
, word_mode
));
2277 if (mode
== BLKmode
)
2279 /* Find the smallest integer mode large enough to hold the
2280 entire structure. */
2281 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2283 mode
= GET_MODE_WIDER_MODE (mode
))
2284 /* Have we found a large enough mode? */
2285 if (GET_MODE_SIZE (mode
) >= bytes
)
2288 /* A suitable mode should have been found. */
2289 gcc_assert (mode
!= VOIDmode
);
2292 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2293 dst_mode
= word_mode
;
2296 dst
= gen_reg_rtx (dst_mode
);
2298 for (i
= 0; i
< n_regs
; i
++)
2299 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2301 if (mode
!= dst_mode
)
2302 dst
= gen_lowpart (mode
, dst
);
2307 /* Add a USE expression for REG to the (possibly empty) list pointed
2308 to by CALL_FUSAGE. REG must denote a hard register. */
2311 use_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2313 gcc_assert (REG_P (reg
));
2315 if (!HARD_REGISTER_P (reg
))
2319 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2322 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
2323 to by CALL_FUSAGE. REG must denote a hard register. */
2326 clobber_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2328 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2331 = gen_rtx_EXPR_LIST (mode
, gen_rtx_CLOBBER (VOIDmode
, reg
), *call_fusage
);
2334 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2335 starting at REGNO. All of these registers must be hard registers. */
2338 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2342 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2344 for (i
= 0; i
< nregs
; i
++)
2345 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2348 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2349 PARALLEL REGS. This is for calls that pass values in multiple
2350 non-contiguous locations. The Irix 6 ABI has examples of this. */
2353 use_group_regs (rtx
*call_fusage
, rtx regs
)
2357 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2359 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2361 /* A NULL entry means the parameter goes both on the stack and in
2362 registers. This can also be a MEM for targets that pass values
2363 partially on the stack and partially in registers. */
2364 if (reg
!= 0 && REG_P (reg
))
2365 use_reg (call_fusage
, reg
);
2369 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2370 assigment and the code of the expresion on the RHS is CODE. Return
2374 get_def_for_expr (tree name
, enum tree_code code
)
2378 if (TREE_CODE (name
) != SSA_NAME
)
2381 def_stmt
= get_gimple_for_ssa_name (name
);
2383 || gimple_assign_rhs_code (def_stmt
) != code
)
2389 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2390 assigment and the class of the expresion on the RHS is CLASS. Return
2394 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2398 if (TREE_CODE (name
) != SSA_NAME
)
2401 def_stmt
= get_gimple_for_ssa_name (name
);
2403 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2410 /* Determine whether the LEN bytes generated by CONSTFUN can be
2411 stored to memory using several move instructions. CONSTFUNDATA is
2412 a pointer which will be passed as argument in every CONSTFUN call.
2413 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2414 a memset operation and false if it's a copy of a constant string.
2415 Return nonzero if a call to store_by_pieces should succeed. */
2418 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2419 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2420 void *constfundata
, unsigned int align
, bool memsetp
)
2422 unsigned HOST_WIDE_INT l
;
2423 unsigned int max_size
;
2424 HOST_WIDE_INT offset
= 0;
2426 enum insn_code icode
;
2428 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2429 rtx cst ATTRIBUTE_UNUSED
;
2434 if (!targetm
.use_by_pieces_infrastructure_p (len
, align
,
2438 optimize_insn_for_speed_p ()))
2441 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2443 /* We would first store what we can in the largest integer mode, then go to
2444 successively smaller modes. */
2447 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2451 max_size
= STORE_MAX_PIECES
+ 1;
2452 while (max_size
> 1 && l
> 0)
2454 mode
= widest_int_mode_for_size (max_size
);
2456 if (mode
== VOIDmode
)
2459 icode
= optab_handler (mov_optab
, mode
);
2460 if (icode
!= CODE_FOR_nothing
2461 && align
>= GET_MODE_ALIGNMENT (mode
))
2463 unsigned int size
= GET_MODE_SIZE (mode
);
2470 cst
= (*constfun
) (constfundata
, offset
, mode
);
2471 if (!targetm
.legitimate_constant_p (mode
, cst
))
2481 max_size
= GET_MODE_SIZE (mode
);
2484 /* The code above should have handled everything. */
2491 /* Generate several move instructions to store LEN bytes generated by
2492 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2493 pointer which will be passed as argument in every CONSTFUN call.
2494 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2495 a memset operation and false if it's a copy of a constant string.
2496 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2497 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2501 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2502 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2503 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2505 machine_mode to_addr_mode
= get_address_mode (to
);
2506 struct store_by_pieces_d data
;
2510 gcc_assert (endp
!= 2);
2514 gcc_assert (targetm
.use_by_pieces_infrastructure_p
2519 optimize_insn_for_speed_p ()));
2521 data
.constfun
= constfun
;
2522 data
.constfundata
= constfundata
;
2525 store_by_pieces_1 (&data
, align
);
2530 gcc_assert (!data
.reverse
);
2535 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2536 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2538 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2539 plus_constant (to_addr_mode
,
2543 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2550 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2558 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2559 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2562 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2564 struct store_by_pieces_d data
;
2569 data
.constfun
= clear_by_pieces_1
;
2570 data
.constfundata
= NULL
;
2573 store_by_pieces_1 (&data
, align
);
2576 /* Callback routine for clear_by_pieces.
2577 Return const0_rtx unconditionally. */
2580 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2581 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2582 machine_mode mode ATTRIBUTE_UNUSED
)
2587 /* Subroutine of clear_by_pieces and store_by_pieces.
2588 Generate several move instructions to store LEN bytes of block TO. (A MEM
2589 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2592 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2593 unsigned int align ATTRIBUTE_UNUSED
)
2595 machine_mode to_addr_mode
= get_address_mode (data
->to
);
2596 rtx to_addr
= XEXP (data
->to
, 0);
2597 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2598 enum insn_code icode
;
2601 data
->to_addr
= to_addr
;
2603 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2604 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2606 data
->explicit_inc_to
= 0;
2608 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2610 data
->offset
= data
->len
;
2612 /* If storing requires more than two move insns,
2613 copy addresses to registers (to make displacements shorter)
2614 and use post-increment if available. */
2615 if (!data
->autinc_to
2616 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2618 /* Determine the main mode we'll be using.
2619 MODE might not be used depending on the definitions of the
2620 USE_* macros below. */
2621 machine_mode mode ATTRIBUTE_UNUSED
2622 = widest_int_mode_for_size (max_size
);
2624 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2626 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2627 plus_constant (to_addr_mode
,
2630 data
->autinc_to
= 1;
2631 data
->explicit_inc_to
= -1;
2634 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2635 && ! data
->autinc_to
)
2637 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2638 data
->autinc_to
= 1;
2639 data
->explicit_inc_to
= 1;
2642 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2643 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2646 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2648 /* First store what we can in the largest integer mode, then go to
2649 successively smaller modes. */
2651 while (max_size
> 1 && data
->len
> 0)
2653 machine_mode mode
= widest_int_mode_for_size (max_size
);
2655 if (mode
== VOIDmode
)
2658 icode
= optab_handler (mov_optab
, mode
);
2659 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2660 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2662 max_size
= GET_MODE_SIZE (mode
);
2665 /* The code above should have handled everything. */
2666 gcc_assert (!data
->len
);
2669 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2670 with move instructions for mode MODE. GENFUN is the gen_... function
2671 to make a move insn for that mode. DATA has all the other info. */
2674 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2675 struct store_by_pieces_d
*data
)
2677 unsigned int size
= GET_MODE_SIZE (mode
);
2680 while (data
->len
>= size
)
2683 data
->offset
-= size
;
2685 if (data
->autinc_to
)
2686 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2689 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2691 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2692 emit_insn (gen_add2_insn (data
->to_addr
,
2693 gen_int_mode (-(HOST_WIDE_INT
) size
,
2694 GET_MODE (data
->to_addr
))));
2696 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2697 emit_insn ((*genfun
) (to1
, cst
));
2699 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2700 emit_insn (gen_add2_insn (data
->to_addr
,
2702 GET_MODE (data
->to_addr
))));
2704 if (! data
->reverse
)
2705 data
->offset
+= size
;
2711 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2712 its length in bytes. */
2715 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2716 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2717 unsigned HOST_WIDE_INT min_size
,
2718 unsigned HOST_WIDE_INT max_size
,
2719 unsigned HOST_WIDE_INT probable_max_size
)
2721 machine_mode mode
= GET_MODE (object
);
2724 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2726 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2727 just move a zero. Otherwise, do this a piece at a time. */
2729 && CONST_INT_P (size
)
2730 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2732 rtx zero
= CONST0_RTX (mode
);
2735 emit_move_insn (object
, zero
);
2739 if (COMPLEX_MODE_P (mode
))
2741 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2744 write_complex_part (object
, zero
, 0);
2745 write_complex_part (object
, zero
, 1);
2751 if (size
== const0_rtx
)
2754 align
= MEM_ALIGN (object
);
2756 if (CONST_INT_P (size
)
2757 && targetm
.use_by_pieces_infrastructure_p (INTVAL (size
), align
,
2759 optimize_insn_for_speed_p ()))
2760 clear_by_pieces (object
, INTVAL (size
), align
);
2761 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2762 expected_align
, expected_size
,
2763 min_size
, max_size
, probable_max_size
))
2765 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2766 return set_storage_via_libcall (object
, size
, const0_rtx
,
2767 method
== BLOCK_OP_TAILCALL
);
2775 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2777 unsigned HOST_WIDE_INT max
, min
= 0;
2778 if (GET_CODE (size
) == CONST_INT
)
2779 min
= max
= UINTVAL (size
);
2781 max
= GET_MODE_MASK (GET_MODE (size
));
2782 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2786 /* A subroutine of clear_storage. Expand a call to memset.
2787 Return the return value of memset, 0 otherwise. */
2790 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2792 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2793 machine_mode size_mode
;
2796 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2797 place those into new pseudos into a VAR_DECL and use them later. */
2799 object
= copy_addr_to_reg (XEXP (object
, 0));
2801 size_mode
= TYPE_MODE (sizetype
);
2802 size
= convert_to_mode (size_mode
, size
, 1);
2803 size
= copy_to_mode_reg (size_mode
, size
);
2805 /* It is incorrect to use the libcall calling conventions to call
2806 memset in this context. This could be a user call to memset and
2807 the user may wish to examine the return value from memset. For
2808 targets where libcalls and normal calls have different conventions
2809 for returning pointers, we could end up generating incorrect code. */
2811 object_tree
= make_tree (ptr_type_node
, object
);
2812 if (!CONST_INT_P (val
))
2813 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2814 size_tree
= make_tree (sizetype
, size
);
2815 val_tree
= make_tree (integer_type_node
, val
);
2817 fn
= clear_storage_libcall_fn (true);
2818 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2819 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2821 retval
= expand_normal (call_expr
);
2826 /* A subroutine of set_storage_via_libcall. Create the tree node
2827 for the function we use for block clears. */
2829 tree block_clear_fn
;
2832 init_block_clear_fn (const char *asmspec
)
2834 if (!block_clear_fn
)
2838 fn
= get_identifier ("memset");
2839 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2840 integer_type_node
, sizetype
,
2843 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2844 DECL_EXTERNAL (fn
) = 1;
2845 TREE_PUBLIC (fn
) = 1;
2846 DECL_ARTIFICIAL (fn
) = 1;
2847 TREE_NOTHROW (fn
) = 1;
2848 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2849 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2851 block_clear_fn
= fn
;
2855 set_user_assembler_name (block_clear_fn
, asmspec
);
2859 clear_storage_libcall_fn (int for_call
)
2861 static bool emitted_extern
;
2863 if (!block_clear_fn
)
2864 init_block_clear_fn (NULL
);
2866 if (for_call
&& !emitted_extern
)
2868 emitted_extern
= true;
2869 make_decl_rtl (block_clear_fn
);
2872 return block_clear_fn
;
2875 /* Expand a setmem pattern; return true if successful. */
2878 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2879 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2880 unsigned HOST_WIDE_INT min_size
,
2881 unsigned HOST_WIDE_INT max_size
,
2882 unsigned HOST_WIDE_INT probable_max_size
)
2884 /* Try the most limited insn first, because there's no point
2885 including more than one in the machine description unless
2886 the more limited one has some advantage. */
2890 if (expected_align
< align
)
2891 expected_align
= align
;
2892 if (expected_size
!= -1)
2894 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2895 expected_size
= max_size
;
2896 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2897 expected_size
= min_size
;
2900 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2901 mode
= GET_MODE_WIDER_MODE (mode
))
2903 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2905 if (code
!= CODE_FOR_nothing
2906 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2907 here because if SIZE is less than the mode mask, as it is
2908 returned by the macro, it will definitely be less than the
2909 actual mode mask. Since SIZE is within the Pmode address
2910 space, we limit MODE to Pmode. */
2911 && ((CONST_INT_P (size
)
2912 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2913 <= (GET_MODE_MASK (mode
) >> 1)))
2914 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2915 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2917 struct expand_operand ops
[9];
2920 nops
= insn_data
[(int) code
].n_generator_args
;
2921 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2923 create_fixed_operand (&ops
[0], object
);
2924 /* The check above guarantees that this size conversion is valid. */
2925 create_convert_operand_to (&ops
[1], size
, mode
, true);
2926 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2927 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2930 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2931 create_integer_operand (&ops
[5], expected_size
);
2935 create_integer_operand (&ops
[6], min_size
);
2936 /* If we can not represent the maximal size,
2937 make parameter NULL. */
2938 if ((HOST_WIDE_INT
) max_size
!= -1)
2939 create_integer_operand (&ops
[7], max_size
);
2941 create_fixed_operand (&ops
[7], NULL
);
2945 /* If we can not represent the maximal size,
2946 make parameter NULL. */
2947 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2948 create_integer_operand (&ops
[8], probable_max_size
);
2950 create_fixed_operand (&ops
[8], NULL
);
2952 if (maybe_expand_insn (code
, nops
, ops
))
2961 /* Write to one of the components of the complex value CPLX. Write VAL to
2962 the real part if IMAG_P is false, and the imaginary part if its true. */
2965 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2971 if (GET_CODE (cplx
) == CONCAT
)
2973 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2977 cmode
= GET_MODE (cplx
);
2978 imode
= GET_MODE_INNER (cmode
);
2979 ibitsize
= GET_MODE_BITSIZE (imode
);
2981 /* For MEMs simplify_gen_subreg may generate an invalid new address
2982 because, e.g., the original address is considered mode-dependent
2983 by the target, which restricts simplify_subreg from invoking
2984 adjust_address_nv. Instead of preparing fallback support for an
2985 invalid address, we call adjust_address_nv directly. */
2988 emit_move_insn (adjust_address_nv (cplx
, imode
,
2989 imag_p
? GET_MODE_SIZE (imode
) : 0),
2994 /* If the sub-object is at least word sized, then we know that subregging
2995 will work. This special case is important, since store_bit_field
2996 wants to operate on integer modes, and there's rarely an OImode to
2997 correspond to TCmode. */
2998 if (ibitsize
>= BITS_PER_WORD
2999 /* For hard regs we have exact predicates. Assume we can split
3000 the original object if it spans an even number of hard regs.
3001 This special case is important for SCmode on 64-bit platforms
3002 where the natural size of floating-point regs is 32-bit. */
3004 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3005 && REG_NREGS (cplx
) % 2 == 0))
3007 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3008 imag_p
? GET_MODE_SIZE (imode
) : 0);
3011 emit_move_insn (part
, val
);
3015 /* simplify_gen_subreg may fail for sub-word MEMs. */
3016 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3019 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
3022 /* Extract one of the components of the complex value CPLX. Extract the
3023 real part if IMAG_P is false, and the imaginary part if it's true. */
3026 read_complex_part (rtx cplx
, bool imag_p
)
3028 machine_mode cmode
, imode
;
3031 if (GET_CODE (cplx
) == CONCAT
)
3032 return XEXP (cplx
, imag_p
);
3034 cmode
= GET_MODE (cplx
);
3035 imode
= GET_MODE_INNER (cmode
);
3036 ibitsize
= GET_MODE_BITSIZE (imode
);
3038 /* Special case reads from complex constants that got spilled to memory. */
3039 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3041 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3042 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3044 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3045 if (CONSTANT_CLASS_P (part
))
3046 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3050 /* For MEMs simplify_gen_subreg may generate an invalid new address
3051 because, e.g., the original address is considered mode-dependent
3052 by the target, which restricts simplify_subreg from invoking
3053 adjust_address_nv. Instead of preparing fallback support for an
3054 invalid address, we call adjust_address_nv directly. */
3056 return adjust_address_nv (cplx
, imode
,
3057 imag_p
? GET_MODE_SIZE (imode
) : 0);
3059 /* If the sub-object is at least word sized, then we know that subregging
3060 will work. This special case is important, since extract_bit_field
3061 wants to operate on integer modes, and there's rarely an OImode to
3062 correspond to TCmode. */
3063 if (ibitsize
>= BITS_PER_WORD
3064 /* For hard regs we have exact predicates. Assume we can split
3065 the original object if it spans an even number of hard regs.
3066 This special case is important for SCmode on 64-bit platforms
3067 where the natural size of floating-point regs is 32-bit. */
3069 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3070 && REG_NREGS (cplx
) % 2 == 0))
3072 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3073 imag_p
? GET_MODE_SIZE (imode
) : 0);
3077 /* simplify_gen_subreg may fail for sub-word MEMs. */
3078 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3081 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3082 true, NULL_RTX
, imode
, imode
);
3085 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3086 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3087 represented in NEW_MODE. If FORCE is true, this will never happen, as
3088 we'll force-create a SUBREG if needed. */
3091 emit_move_change_mode (machine_mode new_mode
,
3092 machine_mode old_mode
, rtx x
, bool force
)
3096 if (push_operand (x
, GET_MODE (x
)))
3098 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3099 MEM_COPY_ATTRIBUTES (ret
, x
);
3103 /* We don't have to worry about changing the address since the
3104 size in bytes is supposed to be the same. */
3105 if (reload_in_progress
)
3107 /* Copy the MEM to change the mode and move any
3108 substitutions from the old MEM to the new one. */
3109 ret
= adjust_address_nv (x
, new_mode
, 0);
3110 copy_replacements (x
, ret
);
3113 ret
= adjust_address (x
, new_mode
, 0);
3117 /* Note that we do want simplify_subreg's behavior of validating
3118 that the new mode is ok for a hard register. If we were to use
3119 simplify_gen_subreg, we would create the subreg, but would
3120 probably run into the target not being able to implement it. */
3121 /* Except, of course, when FORCE is true, when this is exactly what
3122 we want. Which is needed for CCmodes on some targets. */
3124 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3126 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3132 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3133 an integer mode of the same size as MODE. Returns the instruction
3134 emitted, or NULL if such a move could not be generated. */
3137 emit_move_via_integer (machine_mode mode
, rtx x
, rtx y
, bool force
)
3140 enum insn_code code
;
3142 /* There must exist a mode of the exact size we require. */
3143 imode
= int_mode_for_mode (mode
);
3144 if (imode
== BLKmode
)
3147 /* The target must support moves in this mode. */
3148 code
= optab_handler (mov_optab
, imode
);
3149 if (code
== CODE_FOR_nothing
)
3152 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3155 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3158 return emit_insn (GEN_FCN (code
) (x
, y
));
3161 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3162 Return an equivalent MEM that does not use an auto-increment. */
3165 emit_move_resolve_push (machine_mode mode
, rtx x
)
3167 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3168 HOST_WIDE_INT adjust
;
3171 adjust
= GET_MODE_SIZE (mode
);
3172 #ifdef PUSH_ROUNDING
3173 adjust
= PUSH_ROUNDING (adjust
);
3175 if (code
== PRE_DEC
|| code
== POST_DEC
)
3177 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3179 rtx expr
= XEXP (XEXP (x
, 0), 1);
3182 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3183 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3184 val
= INTVAL (XEXP (expr
, 1));
3185 if (GET_CODE (expr
) == MINUS
)
3187 gcc_assert (adjust
== val
|| adjust
== -val
);
3191 /* Do not use anti_adjust_stack, since we don't want to update
3192 stack_pointer_delta. */
3193 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3194 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3195 0, OPTAB_LIB_WIDEN
);
3196 if (temp
!= stack_pointer_rtx
)
3197 emit_move_insn (stack_pointer_rtx
, temp
);
3204 temp
= stack_pointer_rtx
;
3209 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3215 return replace_equiv_address (x
, temp
);
3218 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3219 X is known to satisfy push_operand, and MODE is known to be complex.
3220 Returns the last instruction emitted. */
3223 emit_move_complex_push (machine_mode mode
, rtx x
, rtx y
)
3225 machine_mode submode
= GET_MODE_INNER (mode
);
3228 #ifdef PUSH_ROUNDING
3229 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3231 /* In case we output to the stack, but the size is smaller than the
3232 machine can push exactly, we need to use move instructions. */
3233 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3235 x
= emit_move_resolve_push (mode
, x
);
3236 return emit_move_insn (x
, y
);
3240 /* Note that the real part always precedes the imag part in memory
3241 regardless of machine's endianness. */
3242 switch (GET_CODE (XEXP (x
, 0)))
3256 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3257 read_complex_part (y
, imag_first
));
3258 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3259 read_complex_part (y
, !imag_first
));
3262 /* A subroutine of emit_move_complex. Perform the move from Y to X
3263 via two moves of the parts. Returns the last instruction emitted. */
3266 emit_move_complex_parts (rtx x
, rtx y
)
3268 /* Show the output dies here. This is necessary for SUBREGs
3269 of pseudos since we cannot track their lifetimes correctly;
3270 hard regs shouldn't appear here except as return values. */
3271 if (!reload_completed
&& !reload_in_progress
3272 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3275 write_complex_part (x
, read_complex_part (y
, false), false);
3276 write_complex_part (x
, read_complex_part (y
, true), true);
3278 return get_last_insn ();
3281 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3282 MODE is known to be complex. Returns the last instruction emitted. */
3285 emit_move_complex (machine_mode mode
, rtx x
, rtx y
)
3289 /* Need to take special care for pushes, to maintain proper ordering
3290 of the data, and possibly extra padding. */
3291 if (push_operand (x
, mode
))
3292 return emit_move_complex_push (mode
, x
, y
);
3294 /* See if we can coerce the target into moving both values at once, except
3295 for floating point where we favor moving as parts if this is easy. */
3296 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3297 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3299 && HARD_REGISTER_P (x
)
3300 && REG_NREGS (x
) == 1)
3302 && HARD_REGISTER_P (y
)
3303 && REG_NREGS (y
) == 1))
3305 /* Not possible if the values are inherently not adjacent. */
3306 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3308 /* Is possible if both are registers (or subregs of registers). */
3309 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3311 /* If one of the operands is a memory, and alignment constraints
3312 are friendly enough, we may be able to do combined memory operations.
3313 We do not attempt this if Y is a constant because that combination is
3314 usually better with the by-parts thing below. */
3315 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3316 && (!STRICT_ALIGNMENT
3317 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3326 /* For memory to memory moves, optimal behavior can be had with the
3327 existing block move logic. */
3328 if (MEM_P (x
) && MEM_P (y
))
3330 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3331 BLOCK_OP_NO_LIBCALL
);
3332 return get_last_insn ();
3335 ret
= emit_move_via_integer (mode
, x
, y
, true);
3340 return emit_move_complex_parts (x
, y
);
3343 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3344 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3347 emit_move_ccmode (machine_mode mode
, rtx x
, rtx y
)
3351 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3354 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3355 if (code
!= CODE_FOR_nothing
)
3357 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3358 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3359 return emit_insn (GEN_FCN (code
) (x
, y
));
3363 /* Otherwise, find the MODE_INT mode of the same width. */
3364 ret
= emit_move_via_integer (mode
, x
, y
, false);
3365 gcc_assert (ret
!= NULL
);
3369 /* Return true if word I of OP lies entirely in the
3370 undefined bits of a paradoxical subreg. */
3373 undefined_operand_subword_p (const_rtx op
, int i
)
3375 machine_mode innermode
, innermostmode
;
3377 if (GET_CODE (op
) != SUBREG
)
3379 innermode
= GET_MODE (op
);
3380 innermostmode
= GET_MODE (SUBREG_REG (op
));
3381 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3382 /* The SUBREG_BYTE represents offset, as if the value were stored in
3383 memory, except for a paradoxical subreg where we define
3384 SUBREG_BYTE to be 0; undo this exception as in
3386 if (SUBREG_BYTE (op
) == 0
3387 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3389 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3390 if (WORDS_BIG_ENDIAN
)
3391 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3392 if (BYTES_BIG_ENDIAN
)
3393 offset
+= difference
% UNITS_PER_WORD
;
3395 if (offset
>= GET_MODE_SIZE (innermostmode
)
3396 || offset
<= -GET_MODE_SIZE (word_mode
))
3401 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3402 MODE is any multi-word or full-word mode that lacks a move_insn
3403 pattern. Note that you will get better code if you define such
3404 patterns, even if they must turn into multiple assembler instructions. */
3407 emit_move_multi_word (machine_mode mode
, rtx x
, rtx y
)
3409 rtx_insn
*last_insn
= 0;
3415 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3417 /* If X is a push on the stack, do the push now and replace
3418 X with a reference to the stack pointer. */
3419 if (push_operand (x
, mode
))
3420 x
= emit_move_resolve_push (mode
, x
);
3422 /* If we are in reload, see if either operand is a MEM whose address
3423 is scheduled for replacement. */
3424 if (reload_in_progress
&& MEM_P (x
)
3425 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3426 x
= replace_equiv_address_nv (x
, inner
);
3427 if (reload_in_progress
&& MEM_P (y
)
3428 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3429 y
= replace_equiv_address_nv (y
, inner
);
3433 need_clobber
= false;
3435 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3438 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3441 /* Do not generate code for a move if it would come entirely
3442 from the undefined bits of a paradoxical subreg. */
3443 if (undefined_operand_subword_p (y
, i
))
3446 ypart
= operand_subword (y
, i
, 1, mode
);
3448 /* If we can't get a part of Y, put Y into memory if it is a
3449 constant. Otherwise, force it into a register. Then we must
3450 be able to get a part of Y. */
3451 if (ypart
== 0 && CONSTANT_P (y
))
3453 y
= use_anchored_address (force_const_mem (mode
, y
));
3454 ypart
= operand_subword (y
, i
, 1, mode
);
3456 else if (ypart
== 0)
3457 ypart
= operand_subword_force (y
, i
, mode
);
3459 gcc_assert (xpart
&& ypart
);
3461 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3463 last_insn
= emit_move_insn (xpart
, ypart
);
3469 /* Show the output dies here. This is necessary for SUBREGs
3470 of pseudos since we cannot track their lifetimes correctly;
3471 hard regs shouldn't appear here except as return values.
3472 We never want to emit such a clobber after reload. */
3474 && ! (reload_in_progress
|| reload_completed
)
3475 && need_clobber
!= 0)
3483 /* Low level part of emit_move_insn.
3484 Called just like emit_move_insn, but assumes X and Y
3485 are basically valid. */
3488 emit_move_insn_1 (rtx x
, rtx y
)
3490 machine_mode mode
= GET_MODE (x
);
3491 enum insn_code code
;
3493 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3495 code
= optab_handler (mov_optab
, mode
);
3496 if (code
!= CODE_FOR_nothing
)
3497 return emit_insn (GEN_FCN (code
) (x
, y
));
3499 /* Expand complex moves by moving real part and imag part. */
3500 if (COMPLEX_MODE_P (mode
))
3501 return emit_move_complex (mode
, x
, y
);
3503 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3504 || ALL_FIXED_POINT_MODE_P (mode
))
3506 rtx_insn
*result
= emit_move_via_integer (mode
, x
, y
, true);
3508 /* If we can't find an integer mode, use multi words. */
3512 return emit_move_multi_word (mode
, x
, y
);
3515 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3516 return emit_move_ccmode (mode
, x
, y
);
3518 /* Try using a move pattern for the corresponding integer mode. This is
3519 only safe when simplify_subreg can convert MODE constants into integer
3520 constants. At present, it can only do this reliably if the value
3521 fits within a HOST_WIDE_INT. */
3522 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3524 rtx_insn
*ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3528 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3533 return emit_move_multi_word (mode
, x
, y
);
3536 /* Generate code to copy Y into X.
3537 Both Y and X must have the same mode, except that
3538 Y can be a constant with VOIDmode.
3539 This mode cannot be BLKmode; use emit_block_move for that.
3541 Return the last instruction emitted. */
3544 emit_move_insn (rtx x
, rtx y
)
3546 machine_mode mode
= GET_MODE (x
);
3547 rtx y_cst
= NULL_RTX
;
3548 rtx_insn
*last_insn
;
3551 gcc_assert (mode
!= BLKmode
3552 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3557 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3558 && (last_insn
= compress_float_constant (x
, y
)))
3563 if (!targetm
.legitimate_constant_p (mode
, y
))
3565 y
= force_const_mem (mode
, y
);
3567 /* If the target's cannot_force_const_mem prevented the spill,
3568 assume that the target's move expanders will also take care
3569 of the non-legitimate constant. */
3573 y
= use_anchored_address (y
);
3577 /* If X or Y are memory references, verify that their addresses are valid
3580 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3582 && ! push_operand (x
, GET_MODE (x
))))
3583 x
= validize_mem (x
);
3586 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3587 MEM_ADDR_SPACE (y
)))
3588 y
= validize_mem (y
);
3590 gcc_assert (mode
!= BLKmode
);
3592 last_insn
= emit_move_insn_1 (x
, y
);
3594 if (y_cst
&& REG_P (x
)
3595 && (set
= single_set (last_insn
)) != NULL_RTX
3596 && SET_DEST (set
) == x
3597 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3598 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3603 /* Generate the body of an instruction to copy Y into X.
3604 It may be a list of insns, if one insn isn't enough. */
3607 gen_move_insn (rtx x
, rtx y
)
3612 emit_move_insn_1 (x
, y
);
3618 /* If Y is representable exactly in a narrower mode, and the target can
3619 perform the extension directly from constant or memory, then emit the
3620 move as an extension. */
3623 compress_float_constant (rtx x
, rtx y
)
3625 machine_mode dstmode
= GET_MODE (x
);
3626 machine_mode orig_srcmode
= GET_MODE (y
);
3627 machine_mode srcmode
;
3629 int oldcost
, newcost
;
3630 bool speed
= optimize_insn_for_speed_p ();
3632 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3634 if (targetm
.legitimate_constant_p (dstmode
, y
))
3635 oldcost
= set_src_cost (y
, orig_srcmode
, speed
);
3637 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), dstmode
, speed
);
3639 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3640 srcmode
!= orig_srcmode
;
3641 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3645 rtx_insn
*last_insn
;
3647 /* Skip if the target can't extend this way. */
3648 ic
= can_extend_p (dstmode
, srcmode
, 0);
3649 if (ic
== CODE_FOR_nothing
)
3652 /* Skip if the narrowed value isn't exact. */
3653 if (! exact_real_truncate (srcmode
, &r
))
3656 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3658 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3660 /* Skip if the target needs extra instructions to perform
3662 if (!insn_operand_matches (ic
, 1, trunc_y
))
3664 /* This is valid, but may not be cheaper than the original. */
3665 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3667 if (oldcost
< newcost
)
3670 else if (float_extend_from_mem
[dstmode
][srcmode
])
3672 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3673 /* This is valid, but may not be cheaper than the original. */
3674 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3676 if (oldcost
< newcost
)
3678 trunc_y
= validize_mem (trunc_y
);
3683 /* For CSE's benefit, force the compressed constant pool entry
3684 into a new pseudo. This constant may be used in different modes,
3685 and if not, combine will put things back together for us. */
3686 trunc_y
= force_reg (srcmode
, trunc_y
);
3688 /* If x is a hard register, perform the extension into a pseudo,
3689 so that e.g. stack realignment code is aware of it. */
3691 if (REG_P (x
) && HARD_REGISTER_P (x
))
3692 target
= gen_reg_rtx (dstmode
);
3694 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
3695 last_insn
= get_last_insn ();
3698 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3701 return emit_move_insn (x
, target
);
3708 /* Pushing data onto the stack. */
3710 /* Push a block of length SIZE (perhaps variable)
3711 and return an rtx to address the beginning of the block.
3712 The value may be virtual_outgoing_args_rtx.
3714 EXTRA is the number of bytes of padding to push in addition to SIZE.
3715 BELOW nonzero means this padding comes at low addresses;
3716 otherwise, the padding comes at high addresses. */
3719 push_block (rtx size
, int extra
, int below
)
3723 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3724 if (CONSTANT_P (size
))
3725 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3726 else if (REG_P (size
) && extra
== 0)
3727 anti_adjust_stack (size
);
3730 temp
= copy_to_mode_reg (Pmode
, size
);
3732 temp
= expand_binop (Pmode
, add_optab
, temp
,
3733 gen_int_mode (extra
, Pmode
),
3734 temp
, 0, OPTAB_LIB_WIDEN
);
3735 anti_adjust_stack (temp
);
3738 if (STACK_GROWS_DOWNWARD
)
3740 temp
= virtual_outgoing_args_rtx
;
3741 if (extra
!= 0 && below
)
3742 temp
= plus_constant (Pmode
, temp
, extra
);
3746 if (CONST_INT_P (size
))
3747 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3748 -INTVAL (size
) - (below
? 0 : extra
));
3749 else if (extra
!= 0 && !below
)
3750 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3751 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3754 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3755 negate_rtx (Pmode
, size
));
3758 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3761 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3764 mem_autoinc_base (rtx mem
)
3768 rtx addr
= XEXP (mem
, 0);
3769 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3770 return XEXP (addr
, 0);
3775 /* A utility routine used here, in reload, and in try_split. The insns
3776 after PREV up to and including LAST are known to adjust the stack,
3777 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3778 placing notes as appropriate. PREV may be NULL, indicating the
3779 entire insn sequence prior to LAST should be scanned.
3781 The set of allowed stack pointer modifications is small:
3782 (1) One or more auto-inc style memory references (aka pushes),
3783 (2) One or more addition/subtraction with the SP as destination,
3784 (3) A single move insn with the SP as destination,
3785 (4) A call_pop insn,
3786 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3788 Insns in the sequence that do not modify the SP are ignored,
3789 except for noreturn calls.
3791 The return value is the amount of adjustment that can be trivially
3792 verified, via immediate operand or auto-inc. If the adjustment
3793 cannot be trivially extracted, the return value is INT_MIN. */
3796 find_args_size_adjust (rtx_insn
*insn
)
3801 pat
= PATTERN (insn
);
3804 /* Look for a call_pop pattern. */
3807 /* We have to allow non-call_pop patterns for the case
3808 of emit_single_push_insn of a TLS address. */
3809 if (GET_CODE (pat
) != PARALLEL
)
3812 /* All call_pop have a stack pointer adjust in the parallel.
3813 The call itself is always first, and the stack adjust is
3814 usually last, so search from the end. */
3815 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3817 set
= XVECEXP (pat
, 0, i
);
3818 if (GET_CODE (set
) != SET
)
3820 dest
= SET_DEST (set
);
3821 if (dest
== stack_pointer_rtx
)
3824 /* We'd better have found the stack pointer adjust. */
3827 /* Fall through to process the extracted SET and DEST
3828 as if it was a standalone insn. */
3830 else if (GET_CODE (pat
) == SET
)
3832 else if ((set
= single_set (insn
)) != NULL
)
3834 else if (GET_CODE (pat
) == PARALLEL
)
3836 /* ??? Some older ports use a parallel with a stack adjust
3837 and a store for a PUSH_ROUNDING pattern, rather than a
3838 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3839 /* ??? See h8300 and m68k, pushqi1. */
3840 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3842 set
= XVECEXP (pat
, 0, i
);
3843 if (GET_CODE (set
) != SET
)
3845 dest
= SET_DEST (set
);
3846 if (dest
== stack_pointer_rtx
)
3849 /* We do not expect an auto-inc of the sp in the parallel. */
3850 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3851 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3852 != stack_pointer_rtx
);
3860 dest
= SET_DEST (set
);
3862 /* Look for direct modifications of the stack pointer. */
3863 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3865 /* Look for a trivial adjustment, otherwise assume nothing. */
3866 /* Note that the SPU restore_stack_block pattern refers to
3867 the stack pointer in V4SImode. Consider that non-trivial. */
3868 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3869 && GET_CODE (SET_SRC (set
)) == PLUS
3870 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3871 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3872 return INTVAL (XEXP (SET_SRC (set
), 1));
3873 /* ??? Reload can generate no-op moves, which will be cleaned
3874 up later. Recognize it and continue searching. */
3875 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3878 return HOST_WIDE_INT_MIN
;
3884 /* Otherwise only think about autoinc patterns. */
3885 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3888 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3889 != stack_pointer_rtx
);
3891 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3892 mem
= SET_SRC (set
);
3896 addr
= XEXP (mem
, 0);
3897 switch (GET_CODE (addr
))
3901 return GET_MODE_SIZE (GET_MODE (mem
));
3904 return -GET_MODE_SIZE (GET_MODE (mem
));
3907 addr
= XEXP (addr
, 1);
3908 gcc_assert (GET_CODE (addr
) == PLUS
);
3909 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3910 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3911 return INTVAL (XEXP (addr
, 1));
3919 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
, int end_args_size
)
3921 int args_size
= end_args_size
;
3922 bool saw_unknown
= false;
3925 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3927 HOST_WIDE_INT this_delta
;
3929 if (!NONDEBUG_INSN_P (insn
))
3932 this_delta
= find_args_size_adjust (insn
);
3933 if (this_delta
== 0)
3936 || ACCUMULATE_OUTGOING_ARGS
3937 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3941 gcc_assert (!saw_unknown
);
3942 if (this_delta
== HOST_WIDE_INT_MIN
)
3945 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3946 if (STACK_GROWS_DOWNWARD
)
3947 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3949 args_size
-= this_delta
;
3952 return saw_unknown
? INT_MIN
: args_size
;
3955 #ifdef PUSH_ROUNDING
3956 /* Emit single push insn. */
3959 emit_single_push_insn_1 (machine_mode mode
, rtx x
, tree type
)
3962 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3964 enum insn_code icode
;
3966 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3967 /* If there is push pattern, use it. Otherwise try old way of throwing
3968 MEM representing push operation to move expander. */
3969 icode
= optab_handler (push_optab
, mode
);
3970 if (icode
!= CODE_FOR_nothing
)
3972 struct expand_operand ops
[1];
3974 create_input_operand (&ops
[0], x
, mode
);
3975 if (maybe_expand_insn (icode
, 1, ops
))
3978 if (GET_MODE_SIZE (mode
) == rounded_size
)
3979 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3980 /* If we are to pad downward, adjust the stack pointer first and
3981 then store X into the stack location using an offset. This is
3982 because emit_move_insn does not know how to pad; it does not have
3984 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3986 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3987 HOST_WIDE_INT offset
;
3989 emit_move_insn (stack_pointer_rtx
,
3990 expand_binop (Pmode
,
3991 STACK_GROWS_DOWNWARD
? sub_optab
3994 gen_int_mode (rounded_size
, Pmode
),
3995 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3997 offset
= (HOST_WIDE_INT
) padding_size
;
3998 if (STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_DEC
)
3999 /* We have already decremented the stack pointer, so get the
4001 offset
+= (HOST_WIDE_INT
) rounded_size
;
4003 if (!STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_INC
)
4004 /* We have already incremented the stack pointer, so get the
4006 offset
-= (HOST_WIDE_INT
) rounded_size
;
4008 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4009 gen_int_mode (offset
, Pmode
));
4013 if (STACK_GROWS_DOWNWARD
)
4014 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4015 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4016 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4019 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4020 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4021 gen_int_mode (rounded_size
, Pmode
));
4023 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4026 dest
= gen_rtx_MEM (mode
, dest_addr
);
4030 set_mem_attributes (dest
, type
, 1);
4032 if (cfun
->tail_call_marked
)
4033 /* Function incoming arguments may overlap with sibling call
4034 outgoing arguments and we cannot allow reordering of reads
4035 from function arguments with stores to outgoing arguments
4036 of sibling calls. */
4037 set_mem_alias_set (dest
, 0);
4039 emit_move_insn (dest
, x
);
4042 /* Emit and annotate a single push insn. */
4045 emit_single_push_insn (machine_mode mode
, rtx x
, tree type
)
4047 int delta
, old_delta
= stack_pointer_delta
;
4048 rtx_insn
*prev
= get_last_insn ();
4051 emit_single_push_insn_1 (mode
, x
, type
);
4053 last
= get_last_insn ();
4055 /* Notice the common case where we emitted exactly one insn. */
4056 if (PREV_INSN (last
) == prev
)
4058 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4062 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4063 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4067 /* If reading SIZE bytes from X will end up reading from
4068 Y return the number of bytes that overlap. Return -1
4069 if there is no overlap or -2 if we can't determine
4070 (for example when X and Y have different base registers). */
4073 memory_load_overlap (rtx x
, rtx y
, HOST_WIDE_INT size
)
4075 rtx tmp
= plus_constant (Pmode
, x
, size
);
4076 rtx sub
= simplify_gen_binary (MINUS
, Pmode
, tmp
, y
);
4078 if (!CONST_INT_P (sub
))
4081 HOST_WIDE_INT val
= INTVAL (sub
);
4083 return IN_RANGE (val
, 1, size
) ? val
: -1;
4086 /* Generate code to push X onto the stack, assuming it has mode MODE and
4088 MODE is redundant except when X is a CONST_INT (since they don't
4090 SIZE is an rtx for the size of data to be copied (in bytes),
4091 needed only if X is BLKmode.
4092 Return true if successful. May return false if asked to push a
4093 partial argument during a sibcall optimization (as specified by
4094 SIBCALL_P) and the incoming and outgoing pointers cannot be shown
4097 ALIGN (in bits) is maximum alignment we can assume.
4099 If PARTIAL and REG are both nonzero, then copy that many of the first
4100 bytes of X into registers starting with REG, and push the rest of X.
4101 The amount of space pushed is decreased by PARTIAL bytes.
4102 REG must be a hard register in this case.
4103 If REG is zero but PARTIAL is not, take any all others actions for an
4104 argument partially in registers, but do not actually load any
4107 EXTRA is the amount in bytes of extra space to leave next to this arg.
4108 This is ignored if an argument block has already been allocated.
4110 On a machine that lacks real push insns, ARGS_ADDR is the address of
4111 the bottom of the argument block for this call. We use indexing off there
4112 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4113 argument block has not been preallocated.
4115 ARGS_SO_FAR is the size of args previously pushed for this call.
4117 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4118 for arguments passed in registers. If nonzero, it will be the number
4119 of bytes required. */
4122 emit_push_insn (rtx x
, machine_mode mode
, tree type
, rtx size
,
4123 unsigned int align
, int partial
, rtx reg
, int extra
,
4124 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4125 rtx alignment_pad
, bool sibcall_p
)
4128 enum direction stack_direction
= STACK_GROWS_DOWNWARD
? downward
: upward
;
4130 /* Decide where to pad the argument: `downward' for below,
4131 `upward' for above, or `none' for don't pad it.
4132 Default is below for small data on big-endian machines; else above. */
4133 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4135 /* Invert direction if stack is post-decrement.
4137 if (STACK_PUSH_CODE
== POST_DEC
)
4138 if (where_pad
!= none
)
4139 where_pad
= (where_pad
== downward
? upward
: downward
);
4143 int nregs
= partial
/ UNITS_PER_WORD
;
4144 rtx
*tmp_regs
= NULL
;
4145 int overlapping
= 0;
4148 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4150 /* Copy a block into the stack, entirely or partially. */
4157 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4158 used
= partial
- offset
;
4160 if (mode
!= BLKmode
)
4162 /* A value is to be stored in an insufficiently aligned
4163 stack slot; copy via a suitably aligned slot if
4165 size
= GEN_INT (GET_MODE_SIZE (mode
));
4166 if (!MEM_P (xinner
))
4168 temp
= assign_temp (type
, 1, 1);
4169 emit_move_insn (temp
, xinner
);
4176 /* USED is now the # of bytes we need not copy to the stack
4177 because registers will take care of them. */
4180 xinner
= adjust_address (xinner
, BLKmode
, used
);
4182 /* If the partial register-part of the arg counts in its stack size,
4183 skip the part of stack space corresponding to the registers.
4184 Otherwise, start copying to the beginning of the stack space,
4185 by setting SKIP to 0. */
4186 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4188 #ifdef PUSH_ROUNDING
4189 /* Do it with several push insns if that doesn't take lots of insns
4190 and if there is no difficulty with push insns that skip bytes
4191 on the stack for alignment purposes. */
4194 && CONST_INT_P (size
)
4196 && MEM_ALIGN (xinner
) >= align
4197 && can_move_by_pieces ((unsigned) INTVAL (size
) - used
, align
)
4198 /* Here we avoid the case of a structure whose weak alignment
4199 forces many pushes of a small amount of data,
4200 and such small pushes do rounding that causes trouble. */
4201 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4202 || align
>= BIGGEST_ALIGNMENT
4203 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4204 == (align
/ BITS_PER_UNIT
)))
4205 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4207 /* Push padding now if padding above and stack grows down,
4208 or if padding below and stack grows up.
4209 But if space already allocated, this has already been done. */
4210 if (extra
&& args_addr
== 0
4211 && where_pad
!= none
&& where_pad
!= stack_direction
)
4212 anti_adjust_stack (GEN_INT (extra
));
4214 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4217 #endif /* PUSH_ROUNDING */
4221 /* Otherwise make space on the stack and copy the data
4222 to the address of that space. */
4224 /* Deduct words put into registers from the size we must copy. */
4227 if (CONST_INT_P (size
))
4228 size
= GEN_INT (INTVAL (size
) - used
);
4230 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4231 gen_int_mode (used
, GET_MODE (size
)),
4232 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4235 /* Get the address of the stack space.
4236 In this case, we do not deal with EXTRA separately.
4237 A single stack adjust will do. */
4240 temp
= push_block (size
, extra
, where_pad
== downward
);
4243 else if (CONST_INT_P (args_so_far
))
4244 temp
= memory_address (BLKmode
,
4245 plus_constant (Pmode
, args_addr
,
4246 skip
+ INTVAL (args_so_far
)));
4248 temp
= memory_address (BLKmode
,
4249 plus_constant (Pmode
,
4250 gen_rtx_PLUS (Pmode
,
4255 if (!ACCUMULATE_OUTGOING_ARGS
)
4257 /* If the source is referenced relative to the stack pointer,
4258 copy it to another register to stabilize it. We do not need
4259 to do this if we know that we won't be changing sp. */
4261 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4262 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4263 temp
= copy_to_reg (temp
);
4266 target
= gen_rtx_MEM (BLKmode
, temp
);
4268 /* We do *not* set_mem_attributes here, because incoming arguments
4269 may overlap with sibling call outgoing arguments and we cannot
4270 allow reordering of reads from function arguments with stores
4271 to outgoing arguments of sibling calls. We do, however, want
4272 to record the alignment of the stack slot. */
4273 /* ALIGN may well be better aligned than TYPE, e.g. due to
4274 PARM_BOUNDARY. Assume the caller isn't lying. */
4275 set_mem_align (target
, align
);
4277 /* If part should go in registers and pushing to that part would
4278 overwrite some of the values that need to go into regs, load the
4279 overlapping values into temporary pseudos to be moved into the hard
4280 regs at the end after the stack pushing has completed.
4281 We cannot load them directly into the hard regs here because
4282 they can be clobbered by the block move expansions.
4285 if (partial
> 0 && reg
!= 0 && mode
== BLKmode
4286 && GET_CODE (reg
) != PARALLEL
)
4288 overlapping
= memory_load_overlap (XEXP (x
, 0), temp
, partial
);
4289 if (overlapping
> 0)
4291 gcc_assert (overlapping
% UNITS_PER_WORD
== 0);
4292 overlapping
/= UNITS_PER_WORD
;
4294 tmp_regs
= XALLOCAVEC (rtx
, overlapping
);
4296 for (int i
= 0; i
< overlapping
; i
++)
4297 tmp_regs
[i
] = gen_reg_rtx (word_mode
);
4299 for (int i
= 0; i
< overlapping
; i
++)
4300 emit_move_insn (tmp_regs
[i
],
4301 operand_subword_force (target
, i
, mode
));
4303 else if (overlapping
== -1)
4305 /* Could not determine whether there is overlap.
4306 Fail the sibcall. */
4314 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4317 else if (partial
> 0)
4319 /* Scalar partly in registers. */
4321 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4324 /* # bytes of start of argument
4325 that we must make space for but need not store. */
4326 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4327 int args_offset
= INTVAL (args_so_far
);
4330 /* Push padding now if padding above and stack grows down,
4331 or if padding below and stack grows up.
4332 But if space already allocated, this has already been done. */
4333 if (extra
&& args_addr
== 0
4334 && where_pad
!= none
&& where_pad
!= stack_direction
)
4335 anti_adjust_stack (GEN_INT (extra
));
4337 /* If we make space by pushing it, we might as well push
4338 the real data. Otherwise, we can leave OFFSET nonzero
4339 and leave the space uninitialized. */
4343 /* Now NOT_STACK gets the number of words that we don't need to
4344 allocate on the stack. Convert OFFSET to words too. */
4345 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4346 offset
/= UNITS_PER_WORD
;
4348 /* If the partial register-part of the arg counts in its stack size,
4349 skip the part of stack space corresponding to the registers.
4350 Otherwise, start copying to the beginning of the stack space,
4351 by setting SKIP to 0. */
4352 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4354 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4355 x
= validize_mem (force_const_mem (mode
, x
));
4357 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4358 SUBREGs of such registers are not allowed. */
4359 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4360 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4361 x
= copy_to_reg (x
);
4363 /* Loop over all the words allocated on the stack for this arg. */
4364 /* We can do it by words, because any scalar bigger than a word
4365 has a size a multiple of a word. */
4366 for (i
= size
- 1; i
>= not_stack
; i
--)
4367 if (i
>= not_stack
+ offset
)
4368 if (!emit_push_insn (operand_subword_force (x
, i
, mode
),
4369 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4371 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4373 reg_parm_stack_space
, alignment_pad
, sibcall_p
))
4381 /* Push padding now if padding above and stack grows down,
4382 or if padding below and stack grows up.
4383 But if space already allocated, this has already been done. */
4384 if (extra
&& args_addr
== 0
4385 && where_pad
!= none
&& where_pad
!= stack_direction
)
4386 anti_adjust_stack (GEN_INT (extra
));
4388 #ifdef PUSH_ROUNDING
4389 if (args_addr
== 0 && PUSH_ARGS
)
4390 emit_single_push_insn (mode
, x
, type
);
4394 if (CONST_INT_P (args_so_far
))
4396 = memory_address (mode
,
4397 plus_constant (Pmode
, args_addr
,
4398 INTVAL (args_so_far
)));
4400 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4402 dest
= gen_rtx_MEM (mode
, addr
);
4404 /* We do *not* set_mem_attributes here, because incoming arguments
4405 may overlap with sibling call outgoing arguments and we cannot
4406 allow reordering of reads from function arguments with stores
4407 to outgoing arguments of sibling calls. We do, however, want
4408 to record the alignment of the stack slot. */
4409 /* ALIGN may well be better aligned than TYPE, e.g. due to
4410 PARM_BOUNDARY. Assume the caller isn't lying. */
4411 set_mem_align (dest
, align
);
4413 emit_move_insn (dest
, x
);
4417 /* Move the partial arguments into the registers and any overlapping
4418 values that we moved into the pseudos in tmp_regs. */
4419 if (partial
> 0 && reg
!= 0)
4421 /* Handle calls that pass values in multiple non-contiguous locations.
4422 The Irix 6 ABI has examples of this. */
4423 if (GET_CODE (reg
) == PARALLEL
)
4424 emit_group_load (reg
, x
, type
, -1);
4427 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4428 move_block_to_reg (REGNO (reg
), x
, nregs
- overlapping
, mode
);
4430 for (int i
= 0; i
< overlapping
; i
++)
4431 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
)
4432 + nregs
- overlapping
+ i
),
4438 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4439 anti_adjust_stack (GEN_INT (extra
));
4441 if (alignment_pad
&& args_addr
== 0)
4442 anti_adjust_stack (alignment_pad
);
4447 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4451 get_subtarget (rtx x
)
4455 /* Only registers can be subtargets. */
4457 /* Don't use hard regs to avoid extending their life. */
4458 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4462 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4463 FIELD is a bitfield. Returns true if the optimization was successful,
4464 and there's nothing else to do. */
4467 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4468 unsigned HOST_WIDE_INT bitpos
,
4469 unsigned HOST_WIDE_INT bitregion_start
,
4470 unsigned HOST_WIDE_INT bitregion_end
,
4471 machine_mode mode1
, rtx str_rtx
,
4474 machine_mode str_mode
= GET_MODE (str_rtx
);
4475 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4480 enum tree_code code
;
4482 if (mode1
!= VOIDmode
4483 || bitsize
>= BITS_PER_WORD
4484 || str_bitsize
> BITS_PER_WORD
4485 || TREE_SIDE_EFFECTS (to
)
4486 || TREE_THIS_VOLATILE (to
))
4490 if (TREE_CODE (src
) != SSA_NAME
)
4492 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4495 srcstmt
= get_gimple_for_ssa_name (src
);
4497 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4500 code
= gimple_assign_rhs_code (srcstmt
);
4502 op0
= gimple_assign_rhs1 (srcstmt
);
4504 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4505 to find its initialization. Hopefully the initialization will
4506 be from a bitfield load. */
4507 if (TREE_CODE (op0
) == SSA_NAME
)
4509 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4511 /* We want to eventually have OP0 be the same as TO, which
4512 should be a bitfield. */
4514 || !is_gimple_assign (op0stmt
)
4515 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4517 op0
= gimple_assign_rhs1 (op0stmt
);
4520 op1
= gimple_assign_rhs2 (srcstmt
);
4522 if (!operand_equal_p (to
, op0
, 0))
4525 if (MEM_P (str_rtx
))
4527 unsigned HOST_WIDE_INT offset1
;
4529 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4530 str_mode
= word_mode
;
4531 str_mode
= get_best_mode (bitsize
, bitpos
,
4532 bitregion_start
, bitregion_end
,
4533 MEM_ALIGN (str_rtx
), str_mode
, 0);
4534 if (str_mode
== VOIDmode
)
4536 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4539 bitpos
%= str_bitsize
;
4540 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4541 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4543 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4546 /* If the bit field covers the whole REG/MEM, store_field
4547 will likely generate better code. */
4548 if (bitsize
>= str_bitsize
)
4551 /* We can't handle fields split across multiple entities. */
4552 if (bitpos
+ bitsize
> str_bitsize
)
4555 if (BYTES_BIG_ENDIAN
)
4556 bitpos
= str_bitsize
- bitpos
- bitsize
;
4562 /* For now, just optimize the case of the topmost bitfield
4563 where we don't need to do any masking and also
4564 1 bit bitfields where xor can be used.
4565 We might win by one instruction for the other bitfields
4566 too if insv/extv instructions aren't used, so that
4567 can be added later. */
4568 if (bitpos
+ bitsize
!= str_bitsize
4569 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4572 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4573 value
= convert_modes (str_mode
,
4574 TYPE_MODE (TREE_TYPE (op1
)), value
,
4575 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4577 /* We may be accessing data outside the field, which means
4578 we can alias adjacent data. */
4579 if (MEM_P (str_rtx
))
4581 str_rtx
= shallow_copy_rtx (str_rtx
);
4582 set_mem_alias_set (str_rtx
, 0);
4583 set_mem_expr (str_rtx
, 0);
4586 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4587 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4589 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4592 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4593 result
= expand_binop (str_mode
, binop
, str_rtx
,
4594 value
, str_rtx
, 1, OPTAB_WIDEN
);
4595 if (result
!= str_rtx
)
4596 emit_move_insn (str_rtx
, result
);
4601 if (TREE_CODE (op1
) != INTEGER_CST
)
4603 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4604 value
= convert_modes (str_mode
,
4605 TYPE_MODE (TREE_TYPE (op1
)), value
,
4606 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4608 /* We may be accessing data outside the field, which means
4609 we can alias adjacent data. */
4610 if (MEM_P (str_rtx
))
4612 str_rtx
= shallow_copy_rtx (str_rtx
);
4613 set_mem_alias_set (str_rtx
, 0);
4614 set_mem_expr (str_rtx
, 0);
4617 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4618 if (bitpos
+ bitsize
!= str_bitsize
)
4620 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4622 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4624 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4625 result
= expand_binop (str_mode
, binop
, str_rtx
,
4626 value
, str_rtx
, 1, OPTAB_WIDEN
);
4627 if (result
!= str_rtx
)
4628 emit_move_insn (str_rtx
, result
);
4638 /* In the C++ memory model, consecutive bit fields in a structure are
4639 considered one memory location.
4641 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4642 returns the bit range of consecutive bits in which this COMPONENT_REF
4643 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4644 and *OFFSET may be adjusted in the process.
4646 If the access does not need to be restricted, 0 is returned in both
4647 *BITSTART and *BITEND. */
4650 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4651 unsigned HOST_WIDE_INT
*bitend
,
4653 HOST_WIDE_INT
*bitpos
,
4656 HOST_WIDE_INT bitoffset
;
4659 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4661 field
= TREE_OPERAND (exp
, 1);
4662 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4663 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4664 need to limit the range we can access. */
4667 *bitstart
= *bitend
= 0;
4671 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4672 part of a larger bit field, then the representative does not serve any
4673 useful purpose. This can occur in Ada. */
4674 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4677 HOST_WIDE_INT rbitsize
, rbitpos
;
4681 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4682 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4683 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4685 *bitstart
= *bitend
= 0;
4690 /* Compute the adjustment to bitpos from the offset of the field
4691 relative to the representative. DECL_FIELD_OFFSET of field and
4692 repr are the same by construction if they are not constants,
4693 see finish_bitfield_layout. */
4694 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4695 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4696 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4697 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4700 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4701 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4703 /* If the adjustment is larger than bitpos, we would have a negative bit
4704 position for the lower bound and this may wreak havoc later. Adjust
4705 offset and bitpos to make the lower bound non-negative in that case. */
4706 if (bitoffset
> *bitpos
)
4708 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4709 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4712 if (*offset
== NULL_TREE
)
4713 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4716 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4720 *bitstart
= *bitpos
- bitoffset
;
4722 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4725 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4726 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4727 DECL_RTL was not set yet, return NORTL. */
4730 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4732 if (TREE_CODE (addr
) != ADDR_EXPR
)
4735 tree base
= TREE_OPERAND (addr
, 0);
4738 || TREE_ADDRESSABLE (base
)
4739 || DECL_MODE (base
) == BLKmode
)
4742 if (!DECL_RTL_SET_P (base
))
4745 return (!MEM_P (DECL_RTL (base
)));
4748 /* Returns true if the MEM_REF REF refers to an object that does not
4749 reside in memory and has non-BLKmode. */
4752 mem_ref_refers_to_non_mem_p (tree ref
)
4754 tree base
= TREE_OPERAND (ref
, 0);
4755 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4758 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4759 is true, try generating a nontemporal store. */
4762 expand_assignment (tree to
, tree from
, bool nontemporal
)
4768 enum insn_code icode
;
4770 /* Don't crash if the lhs of the assignment was erroneous. */
4771 if (TREE_CODE (to
) == ERROR_MARK
)
4773 expand_normal (from
);
4777 /* Optimize away no-op moves without side-effects. */
4778 if (operand_equal_p (to
, from
, 0))
4781 /* Handle misaligned stores. */
4782 mode
= TYPE_MODE (TREE_TYPE (to
));
4783 if ((TREE_CODE (to
) == MEM_REF
4784 || TREE_CODE (to
) == TARGET_MEM_REF
)
4786 && !mem_ref_refers_to_non_mem_p (to
)
4787 && ((align
= get_object_alignment (to
))
4788 < GET_MODE_ALIGNMENT (mode
))
4789 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4790 != CODE_FOR_nothing
)
4791 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4795 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4796 reg
= force_not_mem (reg
);
4797 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4799 if (icode
!= CODE_FOR_nothing
)
4801 struct expand_operand ops
[2];
4803 create_fixed_operand (&ops
[0], mem
);
4804 create_input_operand (&ops
[1], reg
, mode
);
4805 /* The movmisalign<mode> pattern cannot fail, else the assignment
4806 would silently be omitted. */
4807 expand_insn (icode
, 2, ops
);
4810 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
);
4814 /* Assignment of a structure component needs special treatment
4815 if the structure component's rtx is not simply a MEM.
4816 Assignment of an array element at a constant index, and assignment of
4817 an array element in an unaligned packed structure field, has the same
4818 problem. Same for (partially) storing into a non-memory object. */
4819 if (handled_component_p (to
)
4820 || (TREE_CODE (to
) == MEM_REF
4821 && mem_ref_refers_to_non_mem_p (to
))
4822 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4825 HOST_WIDE_INT bitsize
, bitpos
;
4826 unsigned HOST_WIDE_INT bitregion_start
= 0;
4827 unsigned HOST_WIDE_INT bitregion_end
= 0;
4834 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4835 &unsignedp
, &volatilep
, true);
4837 /* Make sure bitpos is not negative, it can wreak havoc later. */
4840 gcc_assert (offset
== NULL_TREE
);
4841 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4842 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4843 bitpos
&= BITS_PER_UNIT
- 1;
4846 if (TREE_CODE (to
) == COMPONENT_REF
4847 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4848 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4849 /* The C++ memory model naturally applies to byte-aligned fields.
4850 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
4851 BITSIZE are not byte-aligned, there is no need to limit the range
4852 we can access. This can occur with packed structures in Ada. */
4853 else if (bitsize
> 0
4854 && bitsize
% BITS_PER_UNIT
== 0
4855 && bitpos
% BITS_PER_UNIT
== 0)
4857 bitregion_start
= bitpos
;
4858 bitregion_end
= bitpos
+ bitsize
- 1;
4861 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4863 /* If the field has a mode, we want to access it in the
4864 field's mode, not the computed mode.
4865 If a MEM has VOIDmode (external with incomplete type),
4866 use BLKmode for it instead. */
4869 if (mode1
!= VOIDmode
)
4870 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4871 else if (GET_MODE (to_rtx
) == VOIDmode
)
4872 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4877 machine_mode address_mode
;
4880 if (!MEM_P (to_rtx
))
4882 /* We can get constant negative offsets into arrays with broken
4883 user code. Translate this to a trap instead of ICEing. */
4884 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4885 expand_builtin_trap ();
4886 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4889 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4890 address_mode
= get_address_mode (to_rtx
);
4891 if (GET_MODE (offset_rtx
) != address_mode
)
4893 /* We cannot be sure that the RTL in offset_rtx is valid outside
4894 of a memory address context, so force it into a register
4895 before attempting to convert it to the desired mode. */
4896 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
4897 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4900 /* If we have an expression in OFFSET_RTX and a non-zero
4901 byte offset in BITPOS, adding the byte offset before the
4902 OFFSET_RTX results in better intermediate code, which makes
4903 later rtl optimization passes perform better.
4905 We prefer intermediate code like this:
4907 r124:DI=r123:DI+0x18
4912 r124:DI=r123:DI+0x10
4913 [r124:DI+0x8]=r121:DI
4915 This is only done for aligned data values, as these can
4916 be expected to result in single move instructions. */
4917 if (mode1
!= VOIDmode
4920 && (bitpos
% bitsize
) == 0
4921 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4922 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
4924 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4925 bitregion_start
= 0;
4926 if (bitregion_end
>= (unsigned HOST_WIDE_INT
) bitpos
)
4927 bitregion_end
-= bitpos
;
4931 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4932 highest_pow2_factor_for_target (to
,
4936 /* No action is needed if the target is not a memory and the field
4937 lies completely outside that target. This can occur if the source
4938 code contains an out-of-bounds access to a small array. */
4940 && GET_MODE (to_rtx
) != BLKmode
4941 && (unsigned HOST_WIDE_INT
) bitpos
4942 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4944 expand_normal (from
);
4947 /* Handle expand_expr of a complex value returning a CONCAT. */
4948 else if (GET_CODE (to_rtx
) == CONCAT
)
4950 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4951 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4953 && bitsize
== mode_bitsize
)
4954 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4955 else if (bitsize
== mode_bitsize
/ 2
4956 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4957 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4959 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4960 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4961 bitregion_start
, bitregion_end
,
4963 get_alias_set (to
), nontemporal
);
4964 else if (bitpos
>= mode_bitsize
/ 2)
4965 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4966 bitpos
- mode_bitsize
/ 2,
4967 bitregion_start
, bitregion_end
,
4969 get_alias_set (to
), nontemporal
);
4970 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4973 result
= expand_normal (from
);
4974 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4975 TYPE_MODE (TREE_TYPE (from
)), 0);
4976 emit_move_insn (XEXP (to_rtx
, 0),
4977 read_complex_part (from_rtx
, false));
4978 emit_move_insn (XEXP (to_rtx
, 1),
4979 read_complex_part (from_rtx
, true));
4983 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4984 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4985 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4986 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4987 result
= store_field (temp
, bitsize
, bitpos
,
4988 bitregion_start
, bitregion_end
,
4990 get_alias_set (to
), nontemporal
);
4991 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4992 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4999 /* If the field is at offset zero, we could have been given the
5000 DECL_RTX of the parent struct. Don't munge it. */
5001 to_rtx
= shallow_copy_rtx (to_rtx
);
5002 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
5004 MEM_VOLATILE_P (to_rtx
) = 1;
5007 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
5008 bitregion_start
, bitregion_end
,
5013 result
= store_field (to_rtx
, bitsize
, bitpos
,
5014 bitregion_start
, bitregion_end
,
5016 get_alias_set (to
), nontemporal
);
5020 preserve_temp_slots (result
);
5025 /* If the rhs is a function call and its value is not an aggregate,
5026 call the function before we start to compute the lhs.
5027 This is needed for correct code for cases such as
5028 val = setjmp (buf) on machines where reference to val
5029 requires loading up part of an address in a separate insn.
5031 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
5032 since it might be a promoted variable where the zero- or sign- extension
5033 needs to be done. Handling this in the normal way is safe because no
5034 computation is done before the call. The same is true for SSA names. */
5035 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
5036 && COMPLETE_TYPE_P (TREE_TYPE (from
))
5037 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
5038 && ! (((TREE_CODE (to
) == VAR_DECL
5039 || TREE_CODE (to
) == PARM_DECL
5040 || TREE_CODE (to
) == RESULT_DECL
)
5041 && REG_P (DECL_RTL (to
)))
5042 || TREE_CODE (to
) == SSA_NAME
))
5048 value
= expand_normal (from
);
5050 /* Split value and bounds to store them separately. */
5051 chkp_split_slot (value
, &value
, &bounds
);
5054 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5056 /* Handle calls that return values in multiple non-contiguous locations.
5057 The Irix 6 ABI has examples of this. */
5058 if (GET_CODE (to_rtx
) == PARALLEL
)
5060 if (GET_CODE (value
) == PARALLEL
)
5061 emit_group_move (to_rtx
, value
);
5063 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5064 int_size_in_bytes (TREE_TYPE (from
)));
5066 else if (GET_CODE (value
) == PARALLEL
)
5067 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5068 int_size_in_bytes (TREE_TYPE (from
)));
5069 else if (GET_MODE (to_rtx
) == BLKmode
)
5071 /* Handle calls that return BLKmode values in registers. */
5073 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5075 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5079 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5080 value
= convert_memory_address_addr_space
5081 (GET_MODE (to_rtx
), value
,
5082 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5084 emit_move_insn (to_rtx
, value
);
5087 /* Store bounds if required. */
5089 && (BOUNDED_P (to
) || chkp_type_has_pointer (TREE_TYPE (to
))))
5091 gcc_assert (MEM_P (to_rtx
));
5092 chkp_emit_bounds_store (bounds
, value
, to_rtx
);
5095 preserve_temp_slots (to_rtx
);
5100 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5101 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5103 /* Don't move directly into a return register. */
5104 if (TREE_CODE (to
) == RESULT_DECL
5105 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5111 /* If the source is itself a return value, it still is in a pseudo at
5112 this point so we can move it back to the return register directly. */
5114 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5115 && TREE_CODE (from
) != CALL_EXPR
)
5116 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5118 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5120 /* Handle calls that return values in multiple non-contiguous locations.
5121 The Irix 6 ABI has examples of this. */
5122 if (GET_CODE (to_rtx
) == PARALLEL
)
5124 if (GET_CODE (temp
) == PARALLEL
)
5125 emit_group_move (to_rtx
, temp
);
5127 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5128 int_size_in_bytes (TREE_TYPE (from
)));
5131 emit_move_insn (to_rtx
, temp
);
5133 preserve_temp_slots (to_rtx
);
5138 /* In case we are returning the contents of an object which overlaps
5139 the place the value is being stored, use a safe function when copying
5140 a value through a pointer into a structure value return block. */
5141 if (TREE_CODE (to
) == RESULT_DECL
5142 && TREE_CODE (from
) == INDIRECT_REF
5143 && ADDR_SPACE_GENERIC_P
5144 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5145 && refs_may_alias_p (to
, from
)
5146 && cfun
->returns_struct
5147 && !cfun
->returns_pcc_struct
)
5152 size
= expr_size (from
);
5153 from_rtx
= expand_normal (from
);
5155 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5156 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5157 XEXP (from_rtx
, 0), Pmode
,
5158 convert_to_mode (TYPE_MODE (sizetype
),
5159 size
, TYPE_UNSIGNED (sizetype
)),
5160 TYPE_MODE (sizetype
));
5162 preserve_temp_slots (to_rtx
);
5167 /* Compute FROM and store the value in the rtx we got. */
5170 result
= store_expr_with_bounds (from
, to_rtx
, 0, nontemporal
, to
);
5171 preserve_temp_slots (result
);
5176 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5177 succeeded, false otherwise. */
5180 emit_storent_insn (rtx to
, rtx from
)
5182 struct expand_operand ops
[2];
5183 machine_mode mode
= GET_MODE (to
);
5184 enum insn_code code
= optab_handler (storent_optab
, mode
);
5186 if (code
== CODE_FOR_nothing
)
5189 create_fixed_operand (&ops
[0], to
);
5190 create_input_operand (&ops
[1], from
, mode
);
5191 return maybe_expand_insn (code
, 2, ops
);
5194 /* Generate code for computing expression EXP,
5195 and storing the value into TARGET.
5197 If the mode is BLKmode then we may return TARGET itself.
5198 It turns out that in BLKmode it doesn't cause a problem.
5199 because C has no operators that could combine two different
5200 assignments into the same BLKmode object with different values
5201 with no sequence point. Will other languages need this to
5204 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5205 stack, and block moves may need to be treated specially.
5207 If NONTEMPORAL is true, try using a nontemporal store instruction.
5209 If BTARGET is not NULL then computed bounds of EXP are
5210 associated with BTARGET. */
5213 store_expr_with_bounds (tree exp
, rtx target
, int call_param_p
,
5214 bool nontemporal
, tree btarget
)
5217 rtx alt_rtl
= NULL_RTX
;
5218 location_t loc
= curr_insn_location ();
5220 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5222 /* C++ can generate ?: expressions with a throw expression in one
5223 branch and an rvalue in the other. Here, we resolve attempts to
5224 store the throw expression's nonexistent result. */
5225 gcc_assert (!call_param_p
);
5226 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5229 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5231 /* Perform first part of compound expression, then assign from second
5233 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5234 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5235 return store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
,
5236 call_param_p
, nontemporal
, btarget
);
5238 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5240 /* For conditional expression, get safe form of the target. Then
5241 test the condition, doing the appropriate assignment on either
5242 side. This avoids the creation of unnecessary temporaries.
5243 For non-BLKmode, it is more efficient not to do this. */
5245 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
5247 do_pending_stack_adjust ();
5249 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5250 store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5251 nontemporal
, btarget
);
5252 emit_jump_insn (targetm
.gen_jump (lab2
));
5255 store_expr_with_bounds (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5256 nontemporal
, btarget
);
5262 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5263 /* If this is a scalar in a register that is stored in a wider mode
5264 than the declared mode, compute the result into its declared mode
5265 and then convert to the wider mode. Our value is the computed
5268 rtx inner_target
= 0;
5270 /* We can do the conversion inside EXP, which will often result
5271 in some optimizations. Do the conversion in two steps: first
5272 change the signedness, if needed, then the extend. But don't
5273 do this if the type of EXP is a subtype of something else
5274 since then the conversion might involve more than just
5275 converting modes. */
5276 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5277 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5278 && GET_MODE_PRECISION (GET_MODE (target
))
5279 == TYPE_PRECISION (TREE_TYPE (exp
)))
5281 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
5282 TYPE_UNSIGNED (TREE_TYPE (exp
))))
5284 /* Some types, e.g. Fortran's logical*4, won't have a signed
5285 version, so use the mode instead. */
5287 = (signed_or_unsigned_type_for
5288 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
5290 ntype
= lang_hooks
.types
.type_for_mode
5291 (TYPE_MODE (TREE_TYPE (exp
)),
5292 SUBREG_PROMOTED_SIGN (target
));
5294 exp
= fold_convert_loc (loc
, ntype
, exp
);
5297 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5298 (GET_MODE (SUBREG_REG (target
)),
5299 SUBREG_PROMOTED_SIGN (target
)),
5302 inner_target
= SUBREG_REG (target
);
5305 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5306 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5308 /* Handle bounds returned by call. */
5309 if (TREE_CODE (exp
) == CALL_EXPR
)
5312 chkp_split_slot (temp
, &temp
, &bounds
);
5313 if (bounds
&& btarget
)
5315 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5316 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5317 chkp_set_rtl_bounds (btarget
, tmp
);
5321 /* If TEMP is a VOIDmode constant, use convert_modes to make
5322 sure that we properly convert it. */
5323 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5325 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5326 temp
, SUBREG_PROMOTED_SIGN (target
));
5327 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5328 GET_MODE (target
), temp
,
5329 SUBREG_PROMOTED_SIGN (target
));
5332 convert_move (SUBREG_REG (target
), temp
,
5333 SUBREG_PROMOTED_SIGN (target
));
5337 else if ((TREE_CODE (exp
) == STRING_CST
5338 || (TREE_CODE (exp
) == MEM_REF
5339 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5340 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5342 && integer_zerop (TREE_OPERAND (exp
, 1))))
5343 && !nontemporal
&& !call_param_p
5346 /* Optimize initialization of an array with a STRING_CST. */
5347 HOST_WIDE_INT exp_len
, str_copy_len
;
5349 tree str
= TREE_CODE (exp
) == STRING_CST
5350 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5352 exp_len
= int_expr_size (exp
);
5356 if (TREE_STRING_LENGTH (str
) <= 0)
5359 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5360 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5363 str_copy_len
= TREE_STRING_LENGTH (str
);
5364 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5365 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5367 str_copy_len
+= STORE_MAX_PIECES
- 1;
5368 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5370 str_copy_len
= MIN (str_copy_len
, exp_len
);
5371 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5372 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5373 MEM_ALIGN (target
), false))
5378 dest_mem
= store_by_pieces (dest_mem
,
5379 str_copy_len
, builtin_strncpy_read_str
,
5381 TREE_STRING_POINTER (str
)),
5382 MEM_ALIGN (target
), false,
5383 exp_len
> str_copy_len
? 1 : 0);
5384 if (exp_len
> str_copy_len
)
5385 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5386 GEN_INT (exp_len
- str_copy_len
),
5395 /* If we want to use a nontemporal store, force the value to
5397 tmp_target
= nontemporal
? NULL_RTX
: target
;
5398 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5400 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5403 /* Handle bounds returned by call. */
5404 if (TREE_CODE (exp
) == CALL_EXPR
)
5407 chkp_split_slot (temp
, &temp
, &bounds
);
5408 if (bounds
&& btarget
)
5410 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5411 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5412 chkp_set_rtl_bounds (btarget
, tmp
);
5417 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5418 the same as that of TARGET, adjust the constant. This is needed, for
5419 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5420 only a word-sized value. */
5421 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5422 && TREE_CODE (exp
) != ERROR_MARK
5423 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5424 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5425 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5427 /* If value was not generated in the target, store it there.
5428 Convert the value to TARGET's type first if necessary and emit the
5429 pending incrementations that have been queued when expanding EXP.
5430 Note that we cannot emit the whole queue blindly because this will
5431 effectively disable the POST_INC optimization later.
5433 If TEMP and TARGET compare equal according to rtx_equal_p, but
5434 one or both of them are volatile memory refs, we have to distinguish
5436 - expand_expr has used TARGET. In this case, we must not generate
5437 another copy. This can be detected by TARGET being equal according
5439 - expand_expr has not used TARGET - that means that the source just
5440 happens to have the same RTX form. Since temp will have been created
5441 by expand_expr, it will compare unequal according to == .
5442 We must generate a copy in this case, to reach the correct number
5443 of volatile memory references. */
5445 if ((! rtx_equal_p (temp
, target
)
5446 || (temp
!= target
&& (side_effects_p (temp
)
5447 || side_effects_p (target
))))
5448 && TREE_CODE (exp
) != ERROR_MARK
5449 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5450 but TARGET is not valid memory reference, TEMP will differ
5451 from TARGET although it is really the same location. */
5453 && rtx_equal_p (alt_rtl
, target
)
5454 && !side_effects_p (alt_rtl
)
5455 && !side_effects_p (target
))
5456 /* If there's nothing to copy, don't bother. Don't call
5457 expr_size unless necessary, because some front-ends (C++)
5458 expr_size-hook must not be given objects that are not
5459 supposed to be bit-copied or bit-initialized. */
5460 && expr_size (exp
) != const0_rtx
)
5462 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5464 if (GET_MODE (target
) == BLKmode
)
5466 /* Handle calls that return BLKmode values in registers. */
5467 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5468 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5470 store_bit_field (target
,
5471 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5472 0, 0, 0, GET_MODE (temp
), temp
);
5475 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5478 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5480 /* Handle copying a string constant into an array. The string
5481 constant may be shorter than the array. So copy just the string's
5482 actual length, and clear the rest. First get the size of the data
5483 type of the string, which is actually the size of the target. */
5484 rtx size
= expr_size (exp
);
5486 if (CONST_INT_P (size
)
5487 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5488 emit_block_move (target
, temp
, size
,
5490 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5493 machine_mode pointer_mode
5494 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5495 machine_mode address_mode
= get_address_mode (target
);
5497 /* Compute the size of the data to copy from the string. */
5499 = size_binop_loc (loc
, MIN_EXPR
,
5500 make_tree (sizetype
, size
),
5501 size_int (TREE_STRING_LENGTH (exp
)));
5503 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5505 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5506 rtx_code_label
*label
= 0;
5508 /* Copy that much. */
5509 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5510 TYPE_UNSIGNED (sizetype
));
5511 emit_block_move (target
, temp
, copy_size_rtx
,
5513 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5515 /* Figure out how much is left in TARGET that we have to clear.
5516 Do all calculations in pointer_mode. */
5517 if (CONST_INT_P (copy_size_rtx
))
5519 size
= plus_constant (address_mode
, size
,
5520 -INTVAL (copy_size_rtx
));
5521 target
= adjust_address (target
, BLKmode
,
5522 INTVAL (copy_size_rtx
));
5526 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5527 copy_size_rtx
, NULL_RTX
, 0,
5530 if (GET_MODE (copy_size_rtx
) != address_mode
)
5531 copy_size_rtx
= convert_to_mode (address_mode
,
5533 TYPE_UNSIGNED (sizetype
));
5535 target
= offset_address (target
, copy_size_rtx
,
5536 highest_pow2_factor (copy_size
));
5537 label
= gen_label_rtx ();
5538 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5539 GET_MODE (size
), 0, label
);
5542 if (size
!= const0_rtx
)
5543 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5549 /* Handle calls that return values in multiple non-contiguous locations.
5550 The Irix 6 ABI has examples of this. */
5551 else if (GET_CODE (target
) == PARALLEL
)
5553 if (GET_CODE (temp
) == PARALLEL
)
5554 emit_group_move (target
, temp
);
5556 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5557 int_size_in_bytes (TREE_TYPE (exp
)));
5559 else if (GET_CODE (temp
) == PARALLEL
)
5560 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5561 int_size_in_bytes (TREE_TYPE (exp
)));
5562 else if (GET_MODE (temp
) == BLKmode
)
5563 emit_block_move (target
, temp
, expr_size (exp
),
5565 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5566 /* If we emit a nontemporal store, there is nothing else to do. */
5567 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5571 temp
= force_operand (temp
, target
);
5573 emit_move_insn (target
, temp
);
5580 /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
5582 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5584 return store_expr_with_bounds (exp
, target
, call_param_p
, nontemporal
, NULL
);
5587 /* Return true if field F of structure TYPE is a flexible array. */
5590 flexible_array_member_p (const_tree f
, const_tree type
)
5595 return (DECL_CHAIN (f
) == NULL
5596 && TREE_CODE (tf
) == ARRAY_TYPE
5598 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5599 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5600 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5601 && int_size_in_bytes (type
) >= 0);
5604 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5605 must have in order for it to completely initialize a value of type TYPE.
5606 Return -1 if the number isn't known.
5608 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5610 static HOST_WIDE_INT
5611 count_type_elements (const_tree type
, bool for_ctor_p
)
5613 switch (TREE_CODE (type
))
5619 nelts
= array_type_nelts (type
);
5620 if (nelts
&& tree_fits_uhwi_p (nelts
))
5622 unsigned HOST_WIDE_INT n
;
5624 n
= tree_to_uhwi (nelts
) + 1;
5625 if (n
== 0 || for_ctor_p
)
5628 return n
* count_type_elements (TREE_TYPE (type
), false);
5630 return for_ctor_p
? -1 : 1;
5635 unsigned HOST_WIDE_INT n
;
5639 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5640 if (TREE_CODE (f
) == FIELD_DECL
)
5643 n
+= count_type_elements (TREE_TYPE (f
), false);
5644 else if (!flexible_array_member_p (f
, type
))
5645 /* Don't count flexible arrays, which are not supposed
5646 to be initialized. */
5654 case QUAL_UNION_TYPE
:
5659 gcc_assert (!for_ctor_p
);
5660 /* Estimate the number of scalars in each field and pick the
5661 maximum. Other estimates would do instead; the idea is simply
5662 to make sure that the estimate is not sensitive to the ordering
5665 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5666 if (TREE_CODE (f
) == FIELD_DECL
)
5668 m
= count_type_elements (TREE_TYPE (f
), false);
5669 /* If the field doesn't span the whole union, add an extra
5670 scalar for the rest. */
5671 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5672 TYPE_SIZE (type
)) != 1)
5684 return TYPE_VECTOR_SUBPARTS (type
);
5688 case FIXED_POINT_TYPE
:
5693 case REFERENCE_TYPE
:
5709 /* Helper for categorize_ctor_elements. Identical interface. */
5712 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5713 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5715 unsigned HOST_WIDE_INT idx
;
5716 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5717 tree value
, purpose
, elt_type
;
5719 /* Whether CTOR is a valid constant initializer, in accordance with what
5720 initializer_constant_valid_p does. If inferred from the constructor
5721 elements, true until proven otherwise. */
5722 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5723 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5728 elt_type
= NULL_TREE
;
5730 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5732 HOST_WIDE_INT mult
= 1;
5734 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5736 tree lo_index
= TREE_OPERAND (purpose
, 0);
5737 tree hi_index
= TREE_OPERAND (purpose
, 1);
5739 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5740 mult
= (tree_to_uhwi (hi_index
)
5741 - tree_to_uhwi (lo_index
) + 1);
5744 elt_type
= TREE_TYPE (value
);
5746 switch (TREE_CODE (value
))
5750 HOST_WIDE_INT nz
= 0, ic
= 0;
5752 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5755 nz_elts
+= mult
* nz
;
5756 init_elts
+= mult
* ic
;
5758 if (const_from_elts_p
&& const_p
)
5759 const_p
= const_elt_p
;
5766 if (!initializer_zerop (value
))
5772 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5773 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5777 if (!initializer_zerop (TREE_REALPART (value
)))
5779 if (!initializer_zerop (TREE_IMAGPART (value
)))
5787 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5789 tree v
= VECTOR_CST_ELT (value
, i
);
5790 if (!initializer_zerop (v
))
5799 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5800 nz_elts
+= mult
* tc
;
5801 init_elts
+= mult
* tc
;
5803 if (const_from_elts_p
&& const_p
)
5804 const_p
= initializer_constant_valid_p (value
, elt_type
)
5811 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5812 num_fields
, elt_type
))
5813 *p_complete
= false;
5815 *p_nz_elts
+= nz_elts
;
5816 *p_init_elts
+= init_elts
;
5821 /* Examine CTOR to discover:
5822 * how many scalar fields are set to nonzero values,
5823 and place it in *P_NZ_ELTS;
5824 * how many scalar fields in total are in CTOR,
5825 and place it in *P_ELT_COUNT.
5826 * whether the constructor is complete -- in the sense that every
5827 meaningful byte is explicitly given a value --
5828 and place it in *P_COMPLETE.
5830 Return whether or not CTOR is a valid static constant initializer, the same
5831 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5834 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5835 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5841 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5844 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5845 of which had type LAST_TYPE. Each element was itself a complete
5846 initializer, in the sense that every meaningful byte was explicitly
5847 given a value. Return true if the same is true for the constructor
5851 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5852 const_tree last_type
)
5854 if (TREE_CODE (type
) == UNION_TYPE
5855 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5860 gcc_assert (num_elts
== 1 && last_type
);
5862 /* ??? We could look at each element of the union, and find the
5863 largest element. Which would avoid comparing the size of the
5864 initialized element against any tail padding in the union.
5865 Doesn't seem worth the effort... */
5866 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5869 return count_type_elements (type
, true) == num_elts
;
5872 /* Return 1 if EXP contains mostly (3/4) zeros. */
5875 mostly_zeros_p (const_tree exp
)
5877 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5879 HOST_WIDE_INT nz_elts
, init_elts
;
5882 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5883 return !complete_p
|| nz_elts
< init_elts
/ 4;
5886 return initializer_zerop (exp
);
5889 /* Return 1 if EXP contains all zeros. */
5892 all_zeros_p (const_tree exp
)
5894 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5896 HOST_WIDE_INT nz_elts
, init_elts
;
5899 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5900 return nz_elts
== 0;
5903 return initializer_zerop (exp
);
5906 /* Helper function for store_constructor.
5907 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5908 CLEARED is as for store_constructor.
5909 ALIAS_SET is the alias set to use for any stores.
5911 This provides a recursive shortcut back to store_constructor when it isn't
5912 necessary to go through store_field. This is so that we can pass through
5913 the cleared field to let store_constructor know that we may not have to
5914 clear a substructure if the outer structure has already been cleared. */
5917 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5918 HOST_WIDE_INT bitpos
, machine_mode mode
,
5919 tree exp
, int cleared
, alias_set_type alias_set
)
5921 if (TREE_CODE (exp
) == CONSTRUCTOR
5922 /* We can only call store_constructor recursively if the size and
5923 bit position are on a byte boundary. */
5924 && bitpos
% BITS_PER_UNIT
== 0
5925 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5926 /* If we have a nonzero bitpos for a register target, then we just
5927 let store_field do the bitfield handling. This is unlikely to
5928 generate unnecessary clear instructions anyways. */
5929 && (bitpos
== 0 || MEM_P (target
)))
5933 = adjust_address (target
,
5934 GET_MODE (target
) == BLKmode
5936 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5937 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5940 /* Update the alias set, if required. */
5941 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5942 && MEM_ALIAS_SET (target
) != 0)
5944 target
= copy_rtx (target
);
5945 set_mem_alias_set (target
, alias_set
);
5948 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5951 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5955 /* Returns the number of FIELD_DECLs in TYPE. */
5958 fields_length (const_tree type
)
5960 tree t
= TYPE_FIELDS (type
);
5963 for (; t
; t
= DECL_CHAIN (t
))
5964 if (TREE_CODE (t
) == FIELD_DECL
)
5971 /* Store the value of constructor EXP into the rtx TARGET.
5972 TARGET is either a REG or a MEM; we know it cannot conflict, since
5973 safe_from_p has been called.
5974 CLEARED is true if TARGET is known to have been zero'd.
5975 SIZE is the number of bytes of TARGET we are allowed to modify: this
5976 may not be the same as the size of EXP if we are assigning to a field
5977 which has been packed to exclude padding bits. */
5980 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5982 tree type
= TREE_TYPE (exp
);
5983 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5985 switch (TREE_CODE (type
))
5989 case QUAL_UNION_TYPE
:
5991 unsigned HOST_WIDE_INT idx
;
5994 /* If size is zero or the target is already cleared, do nothing. */
5995 if (size
== 0 || cleared
)
5997 /* We either clear the aggregate or indicate the value is dead. */
5998 else if ((TREE_CODE (type
) == UNION_TYPE
5999 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
6000 && ! CONSTRUCTOR_ELTS (exp
))
6001 /* If the constructor is empty, clear the union. */
6003 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
6007 /* If we are building a static constructor into a register,
6008 set the initial value as zero so we can fold the value into
6009 a constant. But if more than one register is involved,
6010 this probably loses. */
6011 else if (REG_P (target
) && TREE_STATIC (exp
)
6012 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
6014 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6018 /* If the constructor has fewer fields than the structure or
6019 if we are initializing the structure to mostly zeros, clear
6020 the whole structure first. Don't do this if TARGET is a
6021 register whose mode size isn't equal to SIZE since
6022 clear_storage can't handle this case. */
6024 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
6025 != fields_length (type
))
6026 || mostly_zeros_p (exp
))
6028 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
6031 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6035 if (REG_P (target
) && !cleared
)
6036 emit_clobber (target
);
6038 /* Store each element of the constructor into the
6039 corresponding field of TARGET. */
6040 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
6043 HOST_WIDE_INT bitsize
;
6044 HOST_WIDE_INT bitpos
= 0;
6046 rtx to_rtx
= target
;
6048 /* Just ignore missing fields. We cleared the whole
6049 structure, above, if any fields are missing. */
6053 if (cleared
&& initializer_zerop (value
))
6056 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
6057 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
6061 mode
= DECL_MODE (field
);
6062 if (DECL_BIT_FIELD (field
))
6065 offset
= DECL_FIELD_OFFSET (field
);
6066 if (tree_fits_shwi_p (offset
)
6067 && tree_fits_shwi_p (bit_position (field
)))
6069 bitpos
= int_bit_position (field
);
6073 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
6077 machine_mode address_mode
;
6081 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
6082 make_tree (TREE_TYPE (exp
),
6085 offset_rtx
= expand_normal (offset
);
6086 gcc_assert (MEM_P (to_rtx
));
6088 address_mode
= get_address_mode (to_rtx
);
6089 if (GET_MODE (offset_rtx
) != address_mode
)
6090 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6092 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6093 highest_pow2_factor (offset
));
6096 /* If this initializes a field that is smaller than a
6097 word, at the start of a word, try to widen it to a full
6098 word. This special case allows us to output C++ member
6099 function initializations in a form that the optimizers
6101 if (WORD_REGISTER_OPERATIONS
6103 && bitsize
< BITS_PER_WORD
6104 && bitpos
% BITS_PER_WORD
== 0
6105 && GET_MODE_CLASS (mode
) == MODE_INT
6106 && TREE_CODE (value
) == INTEGER_CST
6108 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6110 tree type
= TREE_TYPE (value
);
6112 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6114 type
= lang_hooks
.types
.type_for_mode
6115 (word_mode
, TYPE_UNSIGNED (type
));
6116 value
= fold_convert (type
, value
);
6119 if (BYTES_BIG_ENDIAN
)
6121 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6122 build_int_cst (type
,
6123 BITS_PER_WORD
- bitsize
));
6124 bitsize
= BITS_PER_WORD
;
6128 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6129 && DECL_NONADDRESSABLE_P (field
))
6131 to_rtx
= copy_rtx (to_rtx
);
6132 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6135 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6137 get_alias_set (TREE_TYPE (field
)));
6144 unsigned HOST_WIDE_INT i
;
6147 tree elttype
= TREE_TYPE (type
);
6149 HOST_WIDE_INT minelt
= 0;
6150 HOST_WIDE_INT maxelt
= 0;
6152 domain
= TYPE_DOMAIN (type
);
6153 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6154 && TYPE_MAX_VALUE (domain
)
6155 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6156 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6158 /* If we have constant bounds for the range of the type, get them. */
6161 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6162 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6165 /* If the constructor has fewer elements than the array, clear
6166 the whole array first. Similarly if this is static
6167 constructor of a non-BLKmode object. */
6170 else if (REG_P (target
) && TREE_STATIC (exp
))
6174 unsigned HOST_WIDE_INT idx
;
6176 HOST_WIDE_INT count
= 0, zero_count
= 0;
6177 need_to_clear
= ! const_bounds_p
;
6179 /* This loop is a more accurate version of the loop in
6180 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6181 is also needed to check for missing elements. */
6182 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6184 HOST_WIDE_INT this_node_count
;
6189 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6191 tree lo_index
= TREE_OPERAND (index
, 0);
6192 tree hi_index
= TREE_OPERAND (index
, 1);
6194 if (! tree_fits_uhwi_p (lo_index
)
6195 || ! tree_fits_uhwi_p (hi_index
))
6201 this_node_count
= (tree_to_uhwi (hi_index
)
6202 - tree_to_uhwi (lo_index
) + 1);
6205 this_node_count
= 1;
6207 count
+= this_node_count
;
6208 if (mostly_zeros_p (value
))
6209 zero_count
+= this_node_count
;
6212 /* Clear the entire array first if there are any missing
6213 elements, or if the incidence of zero elements is >=
6216 && (count
< maxelt
- minelt
+ 1
6217 || 4 * zero_count
>= 3 * count
))
6221 if (need_to_clear
&& size
> 0)
6224 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6226 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6230 if (!cleared
&& REG_P (target
))
6231 /* Inform later passes that the old value is dead. */
6232 emit_clobber (target
);
6234 /* Store each element of the constructor into the
6235 corresponding element of TARGET, determined by counting the
6237 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6240 HOST_WIDE_INT bitsize
;
6241 HOST_WIDE_INT bitpos
;
6242 rtx xtarget
= target
;
6244 if (cleared
&& initializer_zerop (value
))
6247 mode
= TYPE_MODE (elttype
);
6248 if (mode
== BLKmode
)
6249 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6250 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6253 bitsize
= GET_MODE_BITSIZE (mode
);
6255 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6257 tree lo_index
= TREE_OPERAND (index
, 0);
6258 tree hi_index
= TREE_OPERAND (index
, 1);
6259 rtx index_r
, pos_rtx
;
6260 HOST_WIDE_INT lo
, hi
, count
;
6263 /* If the range is constant and "small", unroll the loop. */
6265 && tree_fits_shwi_p (lo_index
)
6266 && tree_fits_shwi_p (hi_index
)
6267 && (lo
= tree_to_shwi (lo_index
),
6268 hi
= tree_to_shwi (hi_index
),
6269 count
= hi
- lo
+ 1,
6272 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6273 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6276 lo
-= minelt
; hi
-= minelt
;
6277 for (; lo
<= hi
; lo
++)
6279 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6282 && !MEM_KEEP_ALIAS_SET_P (target
)
6283 && TREE_CODE (type
) == ARRAY_TYPE
6284 && TYPE_NONALIASED_COMPONENT (type
))
6286 target
= copy_rtx (target
);
6287 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6290 store_constructor_field
6291 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6292 get_alias_set (elttype
));
6297 rtx_code_label
*loop_start
= gen_label_rtx ();
6298 rtx_code_label
*loop_end
= gen_label_rtx ();
6301 expand_normal (hi_index
);
6303 index
= build_decl (EXPR_LOCATION (exp
),
6304 VAR_DECL
, NULL_TREE
, domain
);
6305 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6306 SET_DECL_RTL (index
, index_r
);
6307 store_expr (lo_index
, index_r
, 0, false);
6309 /* Build the head of the loop. */
6310 do_pending_stack_adjust ();
6311 emit_label (loop_start
);
6313 /* Assign value to element index. */
6315 fold_convert (ssizetype
,
6316 fold_build2 (MINUS_EXPR
,
6319 TYPE_MIN_VALUE (domain
)));
6322 size_binop (MULT_EXPR
, position
,
6323 fold_convert (ssizetype
,
6324 TYPE_SIZE_UNIT (elttype
)));
6326 pos_rtx
= expand_normal (position
);
6327 xtarget
= offset_address (target
, pos_rtx
,
6328 highest_pow2_factor (position
));
6329 xtarget
= adjust_address (xtarget
, mode
, 0);
6330 if (TREE_CODE (value
) == CONSTRUCTOR
)
6331 store_constructor (value
, xtarget
, cleared
,
6332 bitsize
/ BITS_PER_UNIT
);
6334 store_expr (value
, xtarget
, 0, false);
6336 /* Generate a conditional jump to exit the loop. */
6337 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6339 jumpif (exit_cond
, loop_end
, -1);
6341 /* Update the loop counter, and jump to the head of
6343 expand_assignment (index
,
6344 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6345 index
, integer_one_node
),
6348 emit_jump (loop_start
);
6350 /* Build the end of the loop. */
6351 emit_label (loop_end
);
6354 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6355 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6360 index
= ssize_int (1);
6363 index
= fold_convert (ssizetype
,
6364 fold_build2 (MINUS_EXPR
,
6367 TYPE_MIN_VALUE (domain
)));
6370 size_binop (MULT_EXPR
, index
,
6371 fold_convert (ssizetype
,
6372 TYPE_SIZE_UNIT (elttype
)));
6373 xtarget
= offset_address (target
,
6374 expand_normal (position
),
6375 highest_pow2_factor (position
));
6376 xtarget
= adjust_address (xtarget
, mode
, 0);
6377 store_expr (value
, xtarget
, 0, false);
6382 bitpos
= ((tree_to_shwi (index
) - minelt
)
6383 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6385 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6387 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6388 && TREE_CODE (type
) == ARRAY_TYPE
6389 && TYPE_NONALIASED_COMPONENT (type
))
6391 target
= copy_rtx (target
);
6392 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6394 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6395 cleared
, get_alias_set (elttype
));
6403 unsigned HOST_WIDE_INT idx
;
6404 constructor_elt
*ce
;
6407 int icode
= CODE_FOR_nothing
;
6408 tree elttype
= TREE_TYPE (type
);
6409 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6410 machine_mode eltmode
= TYPE_MODE (elttype
);
6411 HOST_WIDE_INT bitsize
;
6412 HOST_WIDE_INT bitpos
;
6413 rtvec vector
= NULL
;
6415 alias_set_type alias
;
6417 gcc_assert (eltmode
!= BLKmode
);
6419 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6420 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6422 machine_mode mode
= GET_MODE (target
);
6424 icode
= (int) optab_handler (vec_init_optab
, mode
);
6425 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6426 if (icode
!= CODE_FOR_nothing
)
6430 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6431 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6433 icode
= CODE_FOR_nothing
;
6437 if (icode
!= CODE_FOR_nothing
)
6441 vector
= rtvec_alloc (n_elts
);
6442 for (i
= 0; i
< n_elts
; i
++)
6443 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6447 /* If the constructor has fewer elements than the vector,
6448 clear the whole array first. Similarly if this is static
6449 constructor of a non-BLKmode object. */
6452 else if (REG_P (target
) && TREE_STATIC (exp
))
6456 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6459 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6461 int n_elts_here
= tree_to_uhwi
6462 (int_const_binop (TRUNC_DIV_EXPR
,
6463 TYPE_SIZE (TREE_TYPE (value
)),
6464 TYPE_SIZE (elttype
)));
6466 count
+= n_elts_here
;
6467 if (mostly_zeros_p (value
))
6468 zero_count
+= n_elts_here
;
6471 /* Clear the entire vector first if there are any missing elements,
6472 or if the incidence of zero elements is >= 75%. */
6473 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6476 if (need_to_clear
&& size
> 0 && !vector
)
6479 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6481 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6485 /* Inform later passes that the old value is dead. */
6486 if (!cleared
&& !vector
&& REG_P (target
))
6487 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6490 alias
= MEM_ALIAS_SET (target
);
6492 alias
= get_alias_set (elttype
);
6494 /* Store each element of the constructor into the corresponding
6495 element of TARGET, determined by counting the elements. */
6496 for (idx
= 0, i
= 0;
6497 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6498 idx
++, i
+= bitsize
/ elt_size
)
6500 HOST_WIDE_INT eltpos
;
6501 tree value
= ce
->value
;
6503 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6504 if (cleared
&& initializer_zerop (value
))
6508 eltpos
= tree_to_uhwi (ce
->index
);
6514 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6516 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6517 RTVEC_ELT (vector
, eltpos
)
6518 = expand_normal (value
);
6522 machine_mode value_mode
=
6523 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6524 ? TYPE_MODE (TREE_TYPE (value
))
6526 bitpos
= eltpos
* elt_size
;
6527 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6528 value
, cleared
, alias
);
6533 emit_insn (GEN_FCN (icode
)
6535 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6544 /* Store the value of EXP (an expression tree)
6545 into a subfield of TARGET which has mode MODE and occupies
6546 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6547 If MODE is VOIDmode, it means that we are storing into a bit-field.
6549 BITREGION_START is bitpos of the first bitfield in this region.
6550 BITREGION_END is the bitpos of the ending bitfield in this region.
6551 These two fields are 0, if the C++ memory model does not apply,
6552 or we are not interested in keeping track of bitfield regions.
6554 Always return const0_rtx unless we have something particular to
6557 ALIAS_SET is the alias set for the destination. This value will
6558 (in general) be different from that for TARGET, since TARGET is a
6559 reference to the containing structure.
6561 If NONTEMPORAL is true, try generating a nontemporal store. */
6564 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6565 unsigned HOST_WIDE_INT bitregion_start
,
6566 unsigned HOST_WIDE_INT bitregion_end
,
6567 machine_mode mode
, tree exp
,
6568 alias_set_type alias_set
, bool nontemporal
)
6570 if (TREE_CODE (exp
) == ERROR_MARK
)
6573 /* If we have nothing to store, do nothing unless the expression has
6576 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6578 if (GET_CODE (target
) == CONCAT
)
6580 /* We're storing into a struct containing a single __complex. */
6582 gcc_assert (!bitpos
);
6583 return store_expr (exp
, target
, 0, nontemporal
);
6586 /* If the structure is in a register or if the component
6587 is a bit field, we cannot use addressing to access it.
6588 Use bit-field techniques or SUBREG to store in it. */
6590 if (mode
== VOIDmode
6591 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6592 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6593 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6595 || GET_CODE (target
) == SUBREG
6596 /* If the field isn't aligned enough to store as an ordinary memref,
6597 store it as a bit field. */
6599 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6600 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6601 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6602 || (bitpos
% BITS_PER_UNIT
!= 0)))
6603 || (bitsize
>= 0 && mode
!= BLKmode
6604 && GET_MODE_BITSIZE (mode
) > bitsize
)
6605 /* If the RHS and field are a constant size and the size of the
6606 RHS isn't the same size as the bitfield, we must use bitfield
6609 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6610 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6611 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6612 decl we must use bitfield operations. */
6614 && TREE_CODE (exp
) == MEM_REF
6615 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6616 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6617 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6618 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6623 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6624 implies a mask operation. If the precision is the same size as
6625 the field we're storing into, that mask is redundant. This is
6626 particularly common with bit field assignments generated by the
6628 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6631 tree type
= TREE_TYPE (exp
);
6632 if (INTEGRAL_TYPE_P (type
)
6633 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6634 && bitsize
== TYPE_PRECISION (type
))
6636 tree op
= gimple_assign_rhs1 (nop_def
);
6637 type
= TREE_TYPE (op
);
6638 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6643 temp
= expand_normal (exp
);
6645 /* If BITSIZE is narrower than the size of the type of EXP
6646 we will be narrowing TEMP. Normally, what's wanted are the
6647 low-order bits. However, if EXP's type is a record and this is
6648 big-endian machine, we want the upper BITSIZE bits. */
6649 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6650 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6651 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6652 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6653 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6656 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6657 if (mode
!= VOIDmode
&& mode
!= BLKmode
6658 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6659 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6661 /* If TEMP is not a PARALLEL (see below) and its mode and that of TARGET
6662 are both BLKmode, both must be in memory and BITPOS must be aligned
6663 on a byte boundary. If so, we simply do a block copy. Likewise for
6664 a BLKmode-like TARGET. */
6665 if (GET_CODE (temp
) != PARALLEL
6666 && GET_MODE (temp
) == BLKmode
6667 && (GET_MODE (target
) == BLKmode
6669 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6670 && (bitpos
% BITS_PER_UNIT
) == 0
6671 && (bitsize
% BITS_PER_UNIT
) == 0)))
6673 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6674 && (bitpos
% BITS_PER_UNIT
) == 0);
6676 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6677 emit_block_move (target
, temp
,
6678 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6685 /* Handle calls that return values in multiple non-contiguous locations.
6686 The Irix 6 ABI has examples of this. */
6687 if (GET_CODE (temp
) == PARALLEL
)
6689 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6691 if (mode
== BLKmode
|| mode
== VOIDmode
)
6692 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6693 temp_target
= gen_reg_rtx (mode
);
6694 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6697 else if (mode
== BLKmode
)
6699 /* Handle calls that return BLKmode values in registers. */
6700 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6702 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6703 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6708 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6710 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6711 temp_target
= gen_reg_rtx (mode
);
6713 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6714 temp_target
, mode
, mode
);
6719 /* Store the value in the bitfield. */
6720 store_bit_field (target
, bitsize
, bitpos
,
6721 bitregion_start
, bitregion_end
,
6728 /* Now build a reference to just the desired component. */
6729 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6731 if (to_rtx
== target
)
6732 to_rtx
= copy_rtx (to_rtx
);
6734 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6735 set_mem_alias_set (to_rtx
, alias_set
);
6737 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6741 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6742 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6743 codes and find the ultimate containing object, which we return.
6745 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6746 bit position, and *PUNSIGNEDP to the signedness of the field.
6747 If the position of the field is variable, we store a tree
6748 giving the variable offset (in units) in *POFFSET.
6749 This offset is in addition to the bit position.
6750 If the position is not variable, we store 0 in *POFFSET.
6752 If any of the extraction expressions is volatile,
6753 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6755 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6756 Otherwise, it is a mode that can be used to access the field.
6758 If the field describes a variable-sized object, *PMODE is set to
6759 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6760 this case, but the address of the object can be found.
6762 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6763 look through nodes that serve as markers of a greater alignment than
6764 the one that can be deduced from the expression. These nodes make it
6765 possible for front-ends to prevent temporaries from being created by
6766 the middle-end on alignment considerations. For that purpose, the
6767 normal operating mode at high-level is to always pass FALSE so that
6768 the ultimate containing object is really returned; moreover, the
6769 associated predicate handled_component_p will always return TRUE
6770 on these nodes, thus indicating that they are essentially handled
6771 by get_inner_reference. TRUE should only be passed when the caller
6772 is scanning the expression in order to build another representation
6773 and specifically knows how to handle these nodes; as such, this is
6774 the normal operating mode in the RTL expanders. */
6777 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6778 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6779 machine_mode
*pmode
, int *punsignedp
,
6780 int *pvolatilep
, bool keep_aligning
)
6783 machine_mode mode
= VOIDmode
;
6784 bool blkmode_bitfield
= false;
6785 tree offset
= size_zero_node
;
6786 offset_int bit_offset
= 0;
6788 /* First get the mode, signedness, and size. We do this from just the
6789 outermost expression. */
6791 if (TREE_CODE (exp
) == COMPONENT_REF
)
6793 tree field
= TREE_OPERAND (exp
, 1);
6794 size_tree
= DECL_SIZE (field
);
6795 if (flag_strict_volatile_bitfields
> 0
6796 && TREE_THIS_VOLATILE (exp
)
6797 && DECL_BIT_FIELD_TYPE (field
)
6798 && DECL_MODE (field
) != BLKmode
)
6799 /* Volatile bitfields should be accessed in the mode of the
6800 field's type, not the mode computed based on the bit
6802 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6803 else if (!DECL_BIT_FIELD (field
))
6804 mode
= DECL_MODE (field
);
6805 else if (DECL_MODE (field
) == BLKmode
)
6806 blkmode_bitfield
= true;
6808 *punsignedp
= DECL_UNSIGNED (field
);
6810 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6812 size_tree
= TREE_OPERAND (exp
, 1);
6813 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6814 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6816 /* For vector types, with the correct size of access, use the mode of
6818 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6819 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6820 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6821 mode
= TYPE_MODE (TREE_TYPE (exp
));
6825 mode
= TYPE_MODE (TREE_TYPE (exp
));
6826 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6828 if (mode
== BLKmode
)
6829 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6831 *pbitsize
= GET_MODE_BITSIZE (mode
);
6836 if (! tree_fits_uhwi_p (size_tree
))
6837 mode
= BLKmode
, *pbitsize
= -1;
6839 *pbitsize
= tree_to_uhwi (size_tree
);
6842 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6843 and find the ultimate containing object. */
6846 switch (TREE_CODE (exp
))
6849 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
6854 tree field
= TREE_OPERAND (exp
, 1);
6855 tree this_offset
= component_ref_field_offset (exp
);
6857 /* If this field hasn't been filled in yet, don't go past it.
6858 This should only happen when folding expressions made during
6859 type construction. */
6860 if (this_offset
== 0)
6863 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6864 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
6866 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6871 case ARRAY_RANGE_REF
:
6873 tree index
= TREE_OPERAND (exp
, 1);
6874 tree low_bound
= array_ref_low_bound (exp
);
6875 tree unit_size
= array_ref_element_size (exp
);
6877 /* We assume all arrays have sizes that are a multiple of a byte.
6878 First subtract the lower bound, if any, in the type of the
6879 index, then convert to sizetype and multiply by the size of
6880 the array element. */
6881 if (! integer_zerop (low_bound
))
6882 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6885 offset
= size_binop (PLUS_EXPR
, offset
,
6886 size_binop (MULT_EXPR
,
6887 fold_convert (sizetype
, index
),
6896 bit_offset
+= *pbitsize
;
6899 case VIEW_CONVERT_EXPR
:
6900 if (keep_aligning
&& STRICT_ALIGNMENT
6901 && (TYPE_ALIGN (TREE_TYPE (exp
))
6902 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6903 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6904 < BIGGEST_ALIGNMENT
)
6905 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6906 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6911 /* Hand back the decl for MEM[&decl, off]. */
6912 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6914 tree off
= TREE_OPERAND (exp
, 1);
6915 if (!integer_zerop (off
))
6917 offset_int boff
, coff
= mem_ref_offset (exp
);
6918 boff
= wi::lshift (coff
, LOG2_BITS_PER_UNIT
);
6921 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6929 /* If any reference in the chain is volatile, the effect is volatile. */
6930 if (TREE_THIS_VOLATILE (exp
))
6933 exp
= TREE_OPERAND (exp
, 0);
6937 /* If OFFSET is constant, see if we can return the whole thing as a
6938 constant bit position. Make sure to handle overflow during
6940 if (TREE_CODE (offset
) == INTEGER_CST
)
6942 offset_int tem
= wi::sext (wi::to_offset (offset
),
6943 TYPE_PRECISION (sizetype
));
6944 tem
= wi::lshift (tem
, LOG2_BITS_PER_UNIT
);
6946 if (wi::fits_shwi_p (tem
))
6948 *pbitpos
= tem
.to_shwi ();
6949 *poffset
= offset
= NULL_TREE
;
6953 /* Otherwise, split it up. */
6956 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6957 if (wi::neg_p (bit_offset
) || !wi::fits_shwi_p (bit_offset
))
6959 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
6960 offset_int tem
= bit_offset
.and_not (mask
);
6961 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6962 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6964 tem
= wi::arshift (tem
, LOG2_BITS_PER_UNIT
);
6965 offset
= size_binop (PLUS_EXPR
, offset
,
6966 wide_int_to_tree (sizetype
, tem
));
6969 *pbitpos
= bit_offset
.to_shwi ();
6973 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6974 if (mode
== VOIDmode
6976 && (*pbitpos
% BITS_PER_UNIT
) == 0
6977 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6985 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6987 static unsigned HOST_WIDE_INT
6988 target_align (const_tree target
)
6990 /* We might have a chain of nested references with intermediate misaligning
6991 bitfields components, so need to recurse to find out. */
6993 unsigned HOST_WIDE_INT this_align
, outer_align
;
6995 switch (TREE_CODE (target
))
7001 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7002 outer_align
= target_align (TREE_OPERAND (target
, 0));
7003 return MIN (this_align
, outer_align
);
7006 case ARRAY_RANGE_REF
:
7007 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7008 outer_align
= target_align (TREE_OPERAND (target
, 0));
7009 return MIN (this_align
, outer_align
);
7012 case NON_LVALUE_EXPR
:
7013 case VIEW_CONVERT_EXPR
:
7014 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7015 outer_align
= target_align (TREE_OPERAND (target
, 0));
7016 return MAX (this_align
, outer_align
);
7019 return TYPE_ALIGN (TREE_TYPE (target
));
7024 /* Given an rtx VALUE that may contain additions and multiplications, return
7025 an equivalent value that just refers to a register, memory, or constant.
7026 This is done by generating instructions to perform the arithmetic and
7027 returning a pseudo-register containing the value.
7029 The returned value may be a REG, SUBREG, MEM or constant. */
7032 force_operand (rtx value
, rtx target
)
7035 /* Use subtarget as the target for operand 0 of a binary operation. */
7036 rtx subtarget
= get_subtarget (target
);
7037 enum rtx_code code
= GET_CODE (value
);
7039 /* Check for subreg applied to an expression produced by loop optimizer. */
7041 && !REG_P (SUBREG_REG (value
))
7042 && !MEM_P (SUBREG_REG (value
)))
7045 = simplify_gen_subreg (GET_MODE (value
),
7046 force_reg (GET_MODE (SUBREG_REG (value
)),
7047 force_operand (SUBREG_REG (value
),
7049 GET_MODE (SUBREG_REG (value
)),
7050 SUBREG_BYTE (value
));
7051 code
= GET_CODE (value
);
7054 /* Check for a PIC address load. */
7055 if ((code
== PLUS
|| code
== MINUS
)
7056 && XEXP (value
, 0) == pic_offset_table_rtx
7057 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7058 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7059 || GET_CODE (XEXP (value
, 1)) == CONST
))
7062 subtarget
= gen_reg_rtx (GET_MODE (value
));
7063 emit_move_insn (subtarget
, value
);
7067 if (ARITHMETIC_P (value
))
7069 op2
= XEXP (value
, 1);
7070 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7072 if (code
== MINUS
&& CONST_INT_P (op2
))
7075 op2
= negate_rtx (GET_MODE (value
), op2
);
7078 /* Check for an addition with OP2 a constant integer and our first
7079 operand a PLUS of a virtual register and something else. In that
7080 case, we want to emit the sum of the virtual register and the
7081 constant first and then add the other value. This allows virtual
7082 register instantiation to simply modify the constant rather than
7083 creating another one around this addition. */
7084 if (code
== PLUS
&& CONST_INT_P (op2
)
7085 && GET_CODE (XEXP (value
, 0)) == PLUS
7086 && REG_P (XEXP (XEXP (value
, 0), 0))
7087 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7088 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7090 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7091 XEXP (XEXP (value
, 0), 0), op2
,
7092 subtarget
, 0, OPTAB_LIB_WIDEN
);
7093 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7094 force_operand (XEXP (XEXP (value
,
7096 target
, 0, OPTAB_LIB_WIDEN
);
7099 op1
= force_operand (XEXP (value
, 0), subtarget
);
7100 op2
= force_operand (op2
, NULL_RTX
);
7104 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7106 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7107 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7108 target
, 1, OPTAB_LIB_WIDEN
);
7110 return expand_divmod (0,
7111 FLOAT_MODE_P (GET_MODE (value
))
7112 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7113 GET_MODE (value
), op1
, op2
, target
, 0);
7115 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7118 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7121 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7124 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7125 target
, 0, OPTAB_LIB_WIDEN
);
7127 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7128 target
, 1, OPTAB_LIB_WIDEN
);
7131 if (UNARY_P (value
))
7134 target
= gen_reg_rtx (GET_MODE (value
));
7135 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7142 case FLOAT_TRUNCATE
:
7143 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7148 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7152 case UNSIGNED_FLOAT
:
7153 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7157 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7161 #ifdef INSN_SCHEDULING
7162 /* On machines that have insn scheduling, we want all memory reference to be
7163 explicit, so we need to deal with such paradoxical SUBREGs. */
7164 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7166 = simplify_gen_subreg (GET_MODE (value
),
7167 force_reg (GET_MODE (SUBREG_REG (value
)),
7168 force_operand (SUBREG_REG (value
),
7170 GET_MODE (SUBREG_REG (value
)),
7171 SUBREG_BYTE (value
));
7177 /* Subroutine of expand_expr: return nonzero iff there is no way that
7178 EXP can reference X, which is being modified. TOP_P is nonzero if this
7179 call is going to be used to determine whether we need a temporary
7180 for EXP, as opposed to a recursive call to this function.
7182 It is always safe for this routine to return zero since it merely
7183 searches for optimization opportunities. */
7186 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7192 /* If EXP has varying size, we MUST use a target since we currently
7193 have no way of allocating temporaries of variable size
7194 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7195 So we assume here that something at a higher level has prevented a
7196 clash. This is somewhat bogus, but the best we can do. Only
7197 do this when X is BLKmode and when we are at the top level. */
7198 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7199 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7200 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7201 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7202 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7204 && GET_MODE (x
) == BLKmode
)
7205 /* If X is in the outgoing argument area, it is always safe. */
7207 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7208 || (GET_CODE (XEXP (x
, 0)) == PLUS
7209 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7212 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7213 find the underlying pseudo. */
7214 if (GET_CODE (x
) == SUBREG
)
7217 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7221 /* Now look at our tree code and possibly recurse. */
7222 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7224 case tcc_declaration
:
7225 exp_rtl
= DECL_RTL_IF_SET (exp
);
7231 case tcc_exceptional
:
7232 if (TREE_CODE (exp
) == TREE_LIST
)
7236 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7238 exp
= TREE_CHAIN (exp
);
7241 if (TREE_CODE (exp
) != TREE_LIST
)
7242 return safe_from_p (x
, exp
, 0);
7245 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7247 constructor_elt
*ce
;
7248 unsigned HOST_WIDE_INT idx
;
7250 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7251 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7252 || !safe_from_p (x
, ce
->value
, 0))
7256 else if (TREE_CODE (exp
) == ERROR_MARK
)
7257 return 1; /* An already-visited SAVE_EXPR? */
7262 /* The only case we look at here is the DECL_INITIAL inside a
7264 return (TREE_CODE (exp
) != DECL_EXPR
7265 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7266 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7267 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7270 case tcc_comparison
:
7271 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7276 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7278 case tcc_expression
:
7281 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7282 the expression. If it is set, we conflict iff we are that rtx or
7283 both are in memory. Otherwise, we check all operands of the
7284 expression recursively. */
7286 switch (TREE_CODE (exp
))
7289 /* If the operand is static or we are static, we can't conflict.
7290 Likewise if we don't conflict with the operand at all. */
7291 if (staticp (TREE_OPERAND (exp
, 0))
7292 || TREE_STATIC (exp
)
7293 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7296 /* Otherwise, the only way this can conflict is if we are taking
7297 the address of a DECL a that address if part of X, which is
7299 exp
= TREE_OPERAND (exp
, 0);
7302 if (!DECL_RTL_SET_P (exp
)
7303 || !MEM_P (DECL_RTL (exp
)))
7306 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7312 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7313 get_alias_set (exp
)))
7318 /* Assume that the call will clobber all hard registers and
7320 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7325 case WITH_CLEANUP_EXPR
:
7326 case CLEANUP_POINT_EXPR
:
7327 /* Lowered by gimplify.c. */
7331 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7337 /* If we have an rtx, we do not need to scan our operands. */
7341 nops
= TREE_OPERAND_LENGTH (exp
);
7342 for (i
= 0; i
< nops
; i
++)
7343 if (TREE_OPERAND (exp
, i
) != 0
7344 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7350 /* Should never get a type here. */
7354 /* If we have an rtl, find any enclosed object. Then see if we conflict
7358 if (GET_CODE (exp_rtl
) == SUBREG
)
7360 exp_rtl
= SUBREG_REG (exp_rtl
);
7362 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7366 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7367 are memory and they conflict. */
7368 return ! (rtx_equal_p (x
, exp_rtl
)
7369 || (MEM_P (x
) && MEM_P (exp_rtl
)
7370 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7373 /* If we reach here, it is safe. */
7378 /* Return the highest power of two that EXP is known to be a multiple of.
7379 This is used in updating alignment of MEMs in array references. */
7381 unsigned HOST_WIDE_INT
7382 highest_pow2_factor (const_tree exp
)
7384 unsigned HOST_WIDE_INT ret
;
7385 int trailing_zeros
= tree_ctz (exp
);
7386 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7387 return BIGGEST_ALIGNMENT
;
7388 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7389 if (ret
> BIGGEST_ALIGNMENT
)
7390 return BIGGEST_ALIGNMENT
;
7394 /* Similar, except that the alignment requirements of TARGET are
7395 taken into account. Assume it is at least as aligned as its
7396 type, unless it is a COMPONENT_REF in which case the layout of
7397 the structure gives the alignment. */
7399 static unsigned HOST_WIDE_INT
7400 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7402 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7403 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7405 return MAX (factor
, talign
);
7408 /* Convert the tree comparison code TCODE to the rtl one where the
7409 signedness is UNSIGNEDP. */
7411 static enum rtx_code
7412 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7424 code
= unsignedp
? LTU
: LT
;
7427 code
= unsignedp
? LEU
: LE
;
7430 code
= unsignedp
? GTU
: GT
;
7433 code
= unsignedp
? GEU
: GE
;
7435 case UNORDERED_EXPR
:
7466 /* Subroutine of expand_expr. Expand the two operands of a binary
7467 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7468 The value may be stored in TARGET if TARGET is nonzero. The
7469 MODIFIER argument is as documented by expand_expr. */
7472 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7473 enum expand_modifier modifier
)
7475 if (! safe_from_p (target
, exp1
, 1))
7477 if (operand_equal_p (exp0
, exp1
, 0))
7479 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7480 *op1
= copy_rtx (*op0
);
7484 /* If we need to preserve evaluation order, copy exp0 into its own
7485 temporary variable so that it can't be clobbered by exp1. */
7486 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7487 exp0
= save_expr (exp0
);
7488 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7489 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7494 /* Return a MEM that contains constant EXP. DEFER is as for
7495 output_constant_def and MODIFIER is as for expand_expr. */
7498 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7502 mem
= output_constant_def (exp
, defer
);
7503 if (modifier
!= EXPAND_INITIALIZER
)
7504 mem
= use_anchored_address (mem
);
7508 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7509 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7512 expand_expr_addr_expr_1 (tree exp
, rtx target
, machine_mode tmode
,
7513 enum expand_modifier modifier
, addr_space_t as
)
7515 rtx result
, subtarget
;
7517 HOST_WIDE_INT bitsize
, bitpos
;
7518 int volatilep
, unsignedp
;
7521 /* If we are taking the address of a constant and are at the top level,
7522 we have to use output_constant_def since we can't call force_const_mem
7524 /* ??? This should be considered a front-end bug. We should not be
7525 generating ADDR_EXPR of something that isn't an LVALUE. The only
7526 exception here is STRING_CST. */
7527 if (CONSTANT_CLASS_P (exp
))
7529 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7530 if (modifier
< EXPAND_SUM
)
7531 result
= force_operand (result
, target
);
7535 /* Everything must be something allowed by is_gimple_addressable. */
7536 switch (TREE_CODE (exp
))
7539 /* This case will happen via recursion for &a->b. */
7540 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7544 tree tem
= TREE_OPERAND (exp
, 0);
7545 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7546 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7547 return expand_expr (tem
, target
, tmode
, modifier
);
7551 /* Expand the initializer like constants above. */
7552 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7554 if (modifier
< EXPAND_SUM
)
7555 result
= force_operand (result
, target
);
7559 /* The real part of the complex number is always first, therefore
7560 the address is the same as the address of the parent object. */
7563 inner
= TREE_OPERAND (exp
, 0);
7567 /* The imaginary part of the complex number is always second.
7568 The expression is therefore always offset by the size of the
7571 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7572 inner
= TREE_OPERAND (exp
, 0);
7575 case COMPOUND_LITERAL_EXPR
:
7576 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
7577 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
7578 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
7579 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
7580 the initializers aren't gimplified. */
7581 if (COMPOUND_LITERAL_EXPR_DECL (exp
)
7582 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp
)))
7583 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7584 target
, tmode
, modifier
, as
);
7587 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7588 expand_expr, as that can have various side effects; LABEL_DECLs for
7589 example, may not have their DECL_RTL set yet. Expand the rtl of
7590 CONSTRUCTORs too, which should yield a memory reference for the
7591 constructor's contents. Assume language specific tree nodes can
7592 be expanded in some interesting way. */
7593 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7595 || TREE_CODE (exp
) == CONSTRUCTOR
7596 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7598 result
= expand_expr (exp
, target
, tmode
,
7599 modifier
== EXPAND_INITIALIZER
7600 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7602 /* If the DECL isn't in memory, then the DECL wasn't properly
7603 marked TREE_ADDRESSABLE, which will be either a front-end
7604 or a tree optimizer bug. */
7606 gcc_assert (MEM_P (result
));
7607 result
= XEXP (result
, 0);
7609 /* ??? Is this needed anymore? */
7611 TREE_USED (exp
) = 1;
7613 if (modifier
!= EXPAND_INITIALIZER
7614 && modifier
!= EXPAND_CONST_ADDRESS
7615 && modifier
!= EXPAND_SUM
)
7616 result
= force_operand (result
, target
);
7620 /* Pass FALSE as the last argument to get_inner_reference although
7621 we are expanding to RTL. The rationale is that we know how to
7622 handle "aligning nodes" here: we can just bypass them because
7623 they won't change the final object whose address will be returned
7624 (they actually exist only for that purpose). */
7625 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7626 &mode1
, &unsignedp
, &volatilep
, false);
7630 /* We must have made progress. */
7631 gcc_assert (inner
!= exp
);
7633 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7634 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7635 inner alignment, force the inner to be sufficiently aligned. */
7636 if (CONSTANT_CLASS_P (inner
)
7637 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7639 inner
= copy_node (inner
);
7640 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7641 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7642 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7644 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7650 if (modifier
!= EXPAND_NORMAL
)
7651 result
= force_operand (result
, NULL
);
7652 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7653 modifier
== EXPAND_INITIALIZER
7654 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7656 /* expand_expr is allowed to return an object in a mode other
7657 than TMODE. If it did, we need to convert. */
7658 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7659 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7660 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7661 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7662 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7664 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7665 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7668 subtarget
= bitpos
? NULL_RTX
: target
;
7669 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7670 1, OPTAB_LIB_WIDEN
);
7676 /* Someone beforehand should have rejected taking the address
7677 of such an object. */
7678 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7680 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7681 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7682 if (modifier
< EXPAND_SUM
)
7683 result
= force_operand (result
, target
);
7689 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7690 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7693 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
7694 enum expand_modifier modifier
)
7696 addr_space_t as
= ADDR_SPACE_GENERIC
;
7697 machine_mode address_mode
= Pmode
;
7698 machine_mode pointer_mode
= ptr_mode
;
7702 /* Target mode of VOIDmode says "whatever's natural". */
7703 if (tmode
== VOIDmode
)
7704 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7706 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7708 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7709 address_mode
= targetm
.addr_space
.address_mode (as
);
7710 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7713 /* We can get called with some Weird Things if the user does silliness
7714 like "(short) &a". In that case, convert_memory_address won't do
7715 the right thing, so ignore the given target mode. */
7716 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7717 tmode
= address_mode
;
7719 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7720 tmode
, modifier
, as
);
7722 /* Despite expand_expr claims concerning ignoring TMODE when not
7723 strictly convenient, stuff breaks if we don't honor it. Note
7724 that combined with the above, we only do this for pointer modes. */
7725 rmode
= GET_MODE (result
);
7726 if (rmode
== VOIDmode
)
7729 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7734 /* Generate code for computing CONSTRUCTOR EXP.
7735 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7736 is TRUE, instead of creating a temporary variable in memory
7737 NULL is returned and the caller needs to handle it differently. */
7740 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7741 bool avoid_temp_mem
)
7743 tree type
= TREE_TYPE (exp
);
7744 machine_mode mode
= TYPE_MODE (type
);
7746 /* Try to avoid creating a temporary at all. This is possible
7747 if all of the initializer is zero.
7748 FIXME: try to handle all [0..255] initializers we can handle
7750 if (TREE_STATIC (exp
)
7751 && !TREE_ADDRESSABLE (exp
)
7752 && target
!= 0 && mode
== BLKmode
7753 && all_zeros_p (exp
))
7755 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7759 /* All elts simple constants => refer to a constant in memory. But
7760 if this is a non-BLKmode mode, let it store a field at a time
7761 since that should make a CONST_INT, CONST_WIDE_INT or
7762 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7763 use, it is best to store directly into the target unless the type
7764 is large enough that memcpy will be used. If we are making an
7765 initializer and all operands are constant, put it in memory as
7768 FIXME: Avoid trying to fill vector constructors piece-meal.
7769 Output them with output_constant_def below unless we're sure
7770 they're zeros. This should go away when vector initializers
7771 are treated like VECTOR_CST instead of arrays. */
7772 if ((TREE_STATIC (exp
)
7773 && ((mode
== BLKmode
7774 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7775 || TREE_ADDRESSABLE (exp
)
7776 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7777 && (! can_move_by_pieces
7778 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7780 && ! mostly_zeros_p (exp
))))
7781 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7782 && TREE_CONSTANT (exp
)))
7789 constructor
= expand_expr_constant (exp
, 1, modifier
);
7791 if (modifier
!= EXPAND_CONST_ADDRESS
7792 && modifier
!= EXPAND_INITIALIZER
7793 && modifier
!= EXPAND_SUM
)
7794 constructor
= validize_mem (constructor
);
7799 /* Handle calls that pass values in multiple non-contiguous
7800 locations. The Irix 6 ABI has examples of this. */
7801 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7802 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7807 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7810 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7815 /* expand_expr: generate code for computing expression EXP.
7816 An rtx for the computed value is returned. The value is never null.
7817 In the case of a void EXP, const0_rtx is returned.
7819 The value may be stored in TARGET if TARGET is nonzero.
7820 TARGET is just a suggestion; callers must assume that
7821 the rtx returned may not be the same as TARGET.
7823 If TARGET is CONST0_RTX, it means that the value will be ignored.
7825 If TMODE is not VOIDmode, it suggests generating the
7826 result in mode TMODE. But this is done only when convenient.
7827 Otherwise, TMODE is ignored and the value generated in its natural mode.
7828 TMODE is just a suggestion; callers must assume that
7829 the rtx returned may not have mode TMODE.
7831 Note that TARGET may have neither TMODE nor MODE. In that case, it
7832 probably will not be used.
7834 If MODIFIER is EXPAND_SUM then when EXP is an addition
7835 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7836 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7837 products as above, or REG or MEM, or constant.
7838 Ordinarily in such cases we would output mul or add instructions
7839 and then return a pseudo reg containing the sum.
7841 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7842 it also marks a label as absolutely required (it can't be dead).
7843 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7844 This is used for outputting expressions used in initializers.
7846 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7847 with a constant address even if that address is not normally legitimate.
7848 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7850 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7851 a call parameter. Such targets require special care as we haven't yet
7852 marked TARGET so that it's safe from being trashed by libcalls. We
7853 don't want to use TARGET for anything but the final result;
7854 Intermediate values must go elsewhere. Additionally, calls to
7855 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7857 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7858 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7859 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7860 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7863 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7864 In this case, we don't adjust a returned MEM rtx that wouldn't be
7865 sufficiently aligned for its mode; instead, it's up to the caller
7866 to deal with it afterwards. This is used to make sure that unaligned
7867 base objects for which out-of-bounds accesses are supported, for
7868 example record types with trailing arrays, aren't realigned behind
7869 the back of the caller.
7870 The normal operating mode is to pass FALSE for this parameter. */
7873 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
7874 enum expand_modifier modifier
, rtx
*alt_rtl
,
7875 bool inner_reference_p
)
7879 /* Handle ERROR_MARK before anybody tries to access its type. */
7880 if (TREE_CODE (exp
) == ERROR_MARK
7881 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7883 ret
= CONST0_RTX (tmode
);
7884 return ret
? ret
: const0_rtx
;
7887 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
7892 /* Try to expand the conditional expression which is represented by
7893 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
7894 return the rtl reg which represents the result. Otherwise return
7898 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7899 tree treeop1 ATTRIBUTE_UNUSED
,
7900 tree treeop2 ATTRIBUTE_UNUSED
)
7903 rtx op00
, op01
, op1
, op2
;
7904 enum rtx_code comparison_code
;
7905 machine_mode comparison_mode
;
7908 tree type
= TREE_TYPE (treeop1
);
7909 int unsignedp
= TYPE_UNSIGNED (type
);
7910 machine_mode mode
= TYPE_MODE (type
);
7911 machine_mode orig_mode
= mode
;
7913 /* If we cannot do a conditional move on the mode, try doing it
7914 with the promoted mode. */
7915 if (!can_conditionally_move_p (mode
))
7917 mode
= promote_mode (type
, mode
, &unsignedp
);
7918 if (!can_conditionally_move_p (mode
))
7920 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7923 temp
= assign_temp (type
, 0, 1);
7926 expand_operands (treeop1
, treeop2
,
7927 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7929 if (TREE_CODE (treeop0
) == SSA_NAME
7930 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7932 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7933 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7934 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7935 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7936 comparison_mode
= TYPE_MODE (type
);
7937 unsignedp
= TYPE_UNSIGNED (type
);
7938 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7940 else if (COMPARISON_CLASS_P (treeop0
))
7942 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7943 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7944 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7945 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7946 unsignedp
= TYPE_UNSIGNED (type
);
7947 comparison_mode
= TYPE_MODE (type
);
7948 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7952 op00
= expand_normal (treeop0
);
7954 comparison_code
= NE
;
7955 comparison_mode
= GET_MODE (op00
);
7956 if (comparison_mode
== VOIDmode
)
7957 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7960 if (GET_MODE (op1
) != mode
)
7961 op1
= gen_lowpart (mode
, op1
);
7963 if (GET_MODE (op2
) != mode
)
7964 op2
= gen_lowpart (mode
, op2
);
7966 /* Try to emit the conditional move. */
7967 insn
= emit_conditional_move (temp
, comparison_code
,
7968 op00
, op01
, comparison_mode
,
7972 /* If we could do the conditional move, emit the sequence,
7976 rtx_insn
*seq
= get_insns ();
7979 return convert_modes (orig_mode
, mode
, temp
, 0);
7982 /* Otherwise discard the sequence and fall back to code with
7989 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
7990 enum expand_modifier modifier
)
7992 rtx op0
, op1
, op2
, temp
;
7993 rtx_code_label
*lab
;
7997 enum tree_code code
= ops
->code
;
7999 rtx subtarget
, original_target
;
8001 bool reduce_bit_field
;
8002 location_t loc
= ops
->location
;
8003 tree treeop0
, treeop1
, treeop2
;
8004 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8005 ? reduce_to_bit_field_precision ((expr), \
8011 mode
= TYPE_MODE (type
);
8012 unsignedp
= TYPE_UNSIGNED (type
);
8018 /* We should be called only on simple (binary or unary) expressions,
8019 exactly those that are valid in gimple expressions that aren't
8020 GIMPLE_SINGLE_RHS (or invalid). */
8021 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8022 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8023 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8025 ignore
= (target
== const0_rtx
8026 || ((CONVERT_EXPR_CODE_P (code
)
8027 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8028 && TREE_CODE (type
) == VOID_TYPE
));
8030 /* We should be called only if we need the result. */
8031 gcc_assert (!ignore
);
8033 /* An operation in what may be a bit-field type needs the
8034 result to be reduced to the precision of the bit-field type,
8035 which is narrower than that of the type's mode. */
8036 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8037 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8039 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8042 /* Use subtarget as the target for operand 0 of a binary operation. */
8043 subtarget
= get_subtarget (target
);
8044 original_target
= target
;
8048 case NON_LVALUE_EXPR
:
8051 if (treeop0
== error_mark_node
)
8054 if (TREE_CODE (type
) == UNION_TYPE
)
8056 tree valtype
= TREE_TYPE (treeop0
);
8058 /* If both input and output are BLKmode, this conversion isn't doing
8059 anything except possibly changing memory attribute. */
8060 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8062 rtx result
= expand_expr (treeop0
, target
, tmode
,
8065 result
= copy_rtx (result
);
8066 set_mem_attributes (result
, type
, 0);
8072 if (TYPE_MODE (type
) != BLKmode
)
8073 target
= gen_reg_rtx (TYPE_MODE (type
));
8075 target
= assign_temp (type
, 1, 1);
8079 /* Store data into beginning of memory target. */
8080 store_expr (treeop0
,
8081 adjust_address (target
, TYPE_MODE (valtype
), 0),
8082 modifier
== EXPAND_STACK_PARM
,
8087 gcc_assert (REG_P (target
));
8089 /* Store this field into a union of the proper type. */
8090 store_field (target
,
8091 MIN ((int_size_in_bytes (TREE_TYPE
8094 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8095 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8098 /* Return the entire union. */
8102 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8104 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8107 /* If the signedness of the conversion differs and OP0 is
8108 a promoted SUBREG, clear that indication since we now
8109 have to do the proper extension. */
8110 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8111 && GET_CODE (op0
) == SUBREG
)
8112 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8114 return REDUCE_BIT_FIELD (op0
);
8117 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8118 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8119 if (GET_MODE (op0
) == mode
)
8122 /* If OP0 is a constant, just convert it into the proper mode. */
8123 else if (CONSTANT_P (op0
))
8125 tree inner_type
= TREE_TYPE (treeop0
);
8126 machine_mode inner_mode
= GET_MODE (op0
);
8128 if (inner_mode
== VOIDmode
)
8129 inner_mode
= TYPE_MODE (inner_type
);
8131 if (modifier
== EXPAND_INITIALIZER
)
8132 op0
= lowpart_subreg (mode
, op0
, inner_mode
);
8134 op0
= convert_modes (mode
, inner_mode
, op0
,
8135 TYPE_UNSIGNED (inner_type
));
8138 else if (modifier
== EXPAND_INITIALIZER
)
8139 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8141 else if (target
== 0)
8142 op0
= convert_to_mode (mode
, op0
,
8143 TYPE_UNSIGNED (TREE_TYPE
8147 convert_move (target
, op0
,
8148 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8152 return REDUCE_BIT_FIELD (op0
);
8154 case ADDR_SPACE_CONVERT_EXPR
:
8156 tree treeop0_type
= TREE_TYPE (treeop0
);
8158 addr_space_t as_from
;
8160 gcc_assert (POINTER_TYPE_P (type
));
8161 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8163 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8164 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8166 /* Conversions between pointers to the same address space should
8167 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8168 gcc_assert (as_to
!= as_from
);
8170 /* Ask target code to handle conversion between pointers
8171 to overlapping address spaces. */
8172 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8173 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8175 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8176 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8181 /* For disjoint address spaces, converting anything but
8182 a null pointer invokes undefined behaviour. We simply
8183 always return a null pointer here. */
8184 return CONST0_RTX (mode
);
8187 case POINTER_PLUS_EXPR
:
8188 /* Even though the sizetype mode and the pointer's mode can be different
8189 expand is able to handle this correctly and get the correct result out
8190 of the PLUS_EXPR code. */
8191 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8192 if sizetype precision is smaller than pointer precision. */
8193 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8194 treeop1
= fold_convert_loc (loc
, type
,
8195 fold_convert_loc (loc
, ssizetype
,
8197 /* If sizetype precision is larger than pointer precision, truncate the
8198 offset to have matching modes. */
8199 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8200 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8203 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8204 something else, make sure we add the register to the constant and
8205 then to the other thing. This case can occur during strength
8206 reduction and doing it this way will produce better code if the
8207 frame pointer or argument pointer is eliminated.
8209 fold-const.c will ensure that the constant is always in the inner
8210 PLUS_EXPR, so the only case we need to do anything about is if
8211 sp, ap, or fp is our second argument, in which case we must swap
8212 the innermost first argument and our second argument. */
8214 if (TREE_CODE (treeop0
) == PLUS_EXPR
8215 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8216 && TREE_CODE (treeop1
) == VAR_DECL
8217 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8218 || DECL_RTL (treeop1
) == stack_pointer_rtx
8219 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8224 /* If the result is to be ptr_mode and we are adding an integer to
8225 something, we might be forming a constant. So try to use
8226 plus_constant. If it produces a sum and we can't accept it,
8227 use force_operand. This allows P = &ARR[const] to generate
8228 efficient code on machines where a SYMBOL_REF is not a valid
8231 If this is an EXPAND_SUM call, always return the sum. */
8232 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8233 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8235 if (modifier
== EXPAND_STACK_PARM
)
8237 if (TREE_CODE (treeop0
) == INTEGER_CST
8238 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8239 && TREE_CONSTANT (treeop1
))
8243 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
8245 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8247 /* Use wi::shwi to ensure that the constant is
8248 truncated according to the mode of OP1, then sign extended
8249 to a HOST_WIDE_INT. Using the constant directly can result
8250 in non-canonical RTL in a 64x32 cross compile. */
8251 wc
= TREE_INT_CST_LOW (treeop0
);
8253 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8254 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8255 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8256 op1
= force_operand (op1
, target
);
8257 return REDUCE_BIT_FIELD (op1
);
8260 else if (TREE_CODE (treeop1
) == INTEGER_CST
8261 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8262 && TREE_CONSTANT (treeop0
))
8266 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
8268 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8269 (modifier
== EXPAND_INITIALIZER
8270 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8271 if (! CONSTANT_P (op0
))
8273 op1
= expand_expr (treeop1
, NULL_RTX
,
8274 VOIDmode
, modifier
);
8275 /* Return a PLUS if modifier says it's OK. */
8276 if (modifier
== EXPAND_SUM
8277 || modifier
== EXPAND_INITIALIZER
)
8278 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8281 /* Use wi::shwi to ensure that the constant is
8282 truncated according to the mode of OP1, then sign extended
8283 to a HOST_WIDE_INT. Using the constant directly can result
8284 in non-canonical RTL in a 64x32 cross compile. */
8285 wc
= TREE_INT_CST_LOW (treeop1
);
8287 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8288 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8289 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8290 op0
= force_operand (op0
, target
);
8291 return REDUCE_BIT_FIELD (op0
);
8295 /* Use TER to expand pointer addition of a negated value
8296 as pointer subtraction. */
8297 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8298 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8299 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8300 && TREE_CODE (treeop1
) == SSA_NAME
8301 && TYPE_MODE (TREE_TYPE (treeop0
))
8302 == TYPE_MODE (TREE_TYPE (treeop1
)))
8304 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8307 treeop1
= gimple_assign_rhs1 (def
);
8313 /* No sense saving up arithmetic to be done
8314 if it's all in the wrong mode to form part of an address.
8315 And force_operand won't know whether to sign-extend or
8317 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8318 || mode
!= ptr_mode
)
8320 expand_operands (treeop0
, treeop1
,
8321 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8322 if (op0
== const0_rtx
)
8324 if (op1
== const0_rtx
)
8329 expand_operands (treeop0
, treeop1
,
8330 subtarget
, &op0
, &op1
, modifier
);
8331 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8335 /* For initializers, we are allowed to return a MINUS of two
8336 symbolic constants. Here we handle all cases when both operands
8338 /* Handle difference of two symbolic constants,
8339 for the sake of an initializer. */
8340 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8341 && really_constant_p (treeop0
)
8342 && really_constant_p (treeop1
))
8344 expand_operands (treeop0
, treeop1
,
8345 NULL_RTX
, &op0
, &op1
, modifier
);
8347 /* If the last operand is a CONST_INT, use plus_constant of
8348 the negated constant. Else make the MINUS. */
8349 if (CONST_INT_P (op1
))
8350 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8353 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8356 /* No sense saving up arithmetic to be done
8357 if it's all in the wrong mode to form part of an address.
8358 And force_operand won't know whether to sign-extend or
8360 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8361 || mode
!= ptr_mode
)
8364 expand_operands (treeop0
, treeop1
,
8365 subtarget
, &op0
, &op1
, modifier
);
8367 /* Convert A - const to A + (-const). */
8368 if (CONST_INT_P (op1
))
8370 op1
= negate_rtx (mode
, op1
);
8371 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8376 case WIDEN_MULT_PLUS_EXPR
:
8377 case WIDEN_MULT_MINUS_EXPR
:
8378 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8379 op2
= expand_normal (treeop2
);
8380 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8384 case WIDEN_MULT_EXPR
:
8385 /* If first operand is constant, swap them.
8386 Thus the following special case checks need only
8387 check the second operand. */
8388 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8389 std::swap (treeop0
, treeop1
);
8391 /* First, check if we have a multiplication of one signed and one
8392 unsigned operand. */
8393 if (TREE_CODE (treeop1
) != INTEGER_CST
8394 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8395 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8397 machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8398 this_optab
= usmul_widen_optab
;
8399 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8400 != CODE_FOR_nothing
)
8402 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8403 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8406 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8408 /* op0 and op1 might still be constant, despite the above
8409 != INTEGER_CST check. Handle it. */
8410 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8412 op0
= convert_modes (innermode
, mode
, op0
, true);
8413 op1
= convert_modes (innermode
, mode
, op1
, false);
8414 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8415 target
, unsignedp
));
8420 /* Check for a multiplication with matching signedness. */
8421 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8422 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8423 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8424 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8426 tree op0type
= TREE_TYPE (treeop0
);
8427 machine_mode innermode
= TYPE_MODE (op0type
);
8428 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8429 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8430 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8432 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8434 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8435 != CODE_FOR_nothing
)
8437 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8439 /* op0 and op1 might still be constant, despite the above
8440 != INTEGER_CST check. Handle it. */
8441 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8444 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8446 = convert_modes (innermode
, mode
, op1
,
8447 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8448 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8452 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8453 unsignedp
, this_optab
);
8454 return REDUCE_BIT_FIELD (temp
);
8456 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8458 && innermode
== word_mode
)
8461 op0
= expand_normal (treeop0
);
8462 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8463 op1
= convert_modes (innermode
, mode
,
8464 expand_normal (treeop1
),
8465 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8467 op1
= expand_normal (treeop1
);
8468 /* op0 and op1 might still be constant, despite the above
8469 != INTEGER_CST check. Handle it. */
8470 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8471 goto widen_mult_const
;
8472 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8473 unsignedp
, OPTAB_LIB_WIDEN
);
8474 hipart
= gen_highpart (innermode
, temp
);
8475 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8479 emit_move_insn (hipart
, htem
);
8480 return REDUCE_BIT_FIELD (temp
);
8484 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8485 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8486 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8487 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8491 optab opt
= fma_optab
;
8494 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8496 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8498 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8501 gcc_assert (fn
!= NULL_TREE
);
8502 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8503 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8506 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8507 /* The multiplication is commutative - look at its 2nd operand
8508 if the first isn't fed by a negate. */
8511 def0
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8512 /* Swap operands if the 2nd operand is fed by a negate. */
8514 std::swap (treeop0
, treeop1
);
8516 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8521 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8524 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8525 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8528 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8531 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8534 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8537 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8541 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8543 op2
= expand_normal (treeop2
);
8544 op1
= expand_normal (treeop1
);
8546 return expand_ternary_op (TYPE_MODE (type
), opt
,
8547 op0
, op1
, op2
, target
, 0);
8551 /* If this is a fixed-point operation, then we cannot use the code
8552 below because "expand_mult" doesn't support sat/no-sat fixed-point
8554 if (ALL_FIXED_POINT_MODE_P (mode
))
8557 /* If first operand is constant, swap them.
8558 Thus the following special case checks need only
8559 check the second operand. */
8560 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8561 std::swap (treeop0
, treeop1
);
8563 /* Attempt to return something suitable for generating an
8564 indexed address, for machines that support that. */
8566 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8567 && tree_fits_shwi_p (treeop1
))
8569 tree exp1
= treeop1
;
8571 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8575 op0
= force_operand (op0
, NULL_RTX
);
8577 op0
= copy_to_mode_reg (mode
, op0
);
8579 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8580 gen_int_mode (tree_to_shwi (exp1
),
8581 TYPE_MODE (TREE_TYPE (exp1
)))));
8584 if (modifier
== EXPAND_STACK_PARM
)
8587 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8588 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8590 case TRUNC_DIV_EXPR
:
8591 case FLOOR_DIV_EXPR
:
8593 case ROUND_DIV_EXPR
:
8594 case EXACT_DIV_EXPR
:
8595 /* If this is a fixed-point operation, then we cannot use the code
8596 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8598 if (ALL_FIXED_POINT_MODE_P (mode
))
8601 if (modifier
== EXPAND_STACK_PARM
)
8603 /* Possible optimization: compute the dividend with EXPAND_SUM
8604 then if the divisor is constant can optimize the case
8605 where some terms of the dividend have coeffs divisible by it. */
8606 expand_operands (treeop0
, treeop1
,
8607 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8608 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8613 case MULT_HIGHPART_EXPR
:
8614 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8615 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8619 case TRUNC_MOD_EXPR
:
8620 case FLOOR_MOD_EXPR
:
8622 case ROUND_MOD_EXPR
:
8623 if (modifier
== EXPAND_STACK_PARM
)
8625 expand_operands (treeop0
, treeop1
,
8626 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8627 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8629 case FIXED_CONVERT_EXPR
:
8630 op0
= expand_normal (treeop0
);
8631 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8632 target
= gen_reg_rtx (mode
);
8634 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8635 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8636 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8637 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8639 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8642 case FIX_TRUNC_EXPR
:
8643 op0
= expand_normal (treeop0
);
8644 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8645 target
= gen_reg_rtx (mode
);
8646 expand_fix (target
, op0
, unsignedp
);
8650 op0
= expand_normal (treeop0
);
8651 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8652 target
= gen_reg_rtx (mode
);
8653 /* expand_float can't figure out what to do if FROM has VOIDmode.
8654 So give it the correct mode. With -O, cse will optimize this. */
8655 if (GET_MODE (op0
) == VOIDmode
)
8656 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8658 expand_float (target
, op0
,
8659 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8663 op0
= expand_expr (treeop0
, subtarget
,
8664 VOIDmode
, EXPAND_NORMAL
);
8665 if (modifier
== EXPAND_STACK_PARM
)
8667 temp
= expand_unop (mode
,
8668 optab_for_tree_code (NEGATE_EXPR
, type
,
8672 return REDUCE_BIT_FIELD (temp
);
8675 op0
= expand_expr (treeop0
, subtarget
,
8676 VOIDmode
, EXPAND_NORMAL
);
8677 if (modifier
== EXPAND_STACK_PARM
)
8680 /* ABS_EXPR is not valid for complex arguments. */
8681 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8682 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8684 /* Unsigned abs is simply the operand. Testing here means we don't
8685 risk generating incorrect code below. */
8686 if (TYPE_UNSIGNED (type
))
8689 return expand_abs (mode
, op0
, target
, unsignedp
,
8690 safe_from_p (target
, treeop0
, 1));
8694 target
= original_target
;
8696 || modifier
== EXPAND_STACK_PARM
8697 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8698 || GET_MODE (target
) != mode
8700 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8701 target
= gen_reg_rtx (mode
);
8702 expand_operands (treeop0
, treeop1
,
8703 target
, &op0
, &op1
, EXPAND_NORMAL
);
8705 /* First try to do it with a special MIN or MAX instruction.
8706 If that does not win, use a conditional jump to select the proper
8708 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8709 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8714 /* At this point, a MEM target is no longer useful; we will get better
8717 if (! REG_P (target
))
8718 target
= gen_reg_rtx (mode
);
8720 /* If op1 was placed in target, swap op0 and op1. */
8721 if (target
!= op0
&& target
== op1
)
8722 std::swap (op0
, op1
);
8724 /* We generate better code and avoid problems with op1 mentioning
8725 target by forcing op1 into a pseudo if it isn't a constant. */
8726 if (! CONSTANT_P (op1
))
8727 op1
= force_reg (mode
, op1
);
8730 enum rtx_code comparison_code
;
8733 if (code
== MAX_EXPR
)
8734 comparison_code
= unsignedp
? GEU
: GE
;
8736 comparison_code
= unsignedp
? LEU
: LE
;
8738 /* Canonicalize to comparisons against 0. */
8739 if (op1
== const1_rtx
)
8741 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8742 or (a != 0 ? a : 1) for unsigned.
8743 For MIN we are safe converting (a <= 1 ? a : 1)
8744 into (a <= 0 ? a : 1) */
8745 cmpop1
= const0_rtx
;
8746 if (code
== MAX_EXPR
)
8747 comparison_code
= unsignedp
? NE
: GT
;
8749 if (op1
== constm1_rtx
&& !unsignedp
)
8751 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8752 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8753 cmpop1
= const0_rtx
;
8754 if (code
== MIN_EXPR
)
8755 comparison_code
= LT
;
8758 /* Use a conditional move if possible. */
8759 if (can_conditionally_move_p (mode
))
8765 /* Try to emit the conditional move. */
8766 insn
= emit_conditional_move (target
, comparison_code
,
8771 /* If we could do the conditional move, emit the sequence,
8775 rtx_insn
*seq
= get_insns ();
8781 /* Otherwise discard the sequence and fall back to code with
8787 emit_move_insn (target
, op0
);
8789 lab
= gen_label_rtx ();
8790 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8791 unsignedp
, mode
, NULL_RTX
, NULL
, lab
,
8794 emit_move_insn (target
, op1
);
8799 op0
= expand_expr (treeop0
, subtarget
,
8800 VOIDmode
, EXPAND_NORMAL
);
8801 if (modifier
== EXPAND_STACK_PARM
)
8803 /* In case we have to reduce the result to bitfield precision
8804 for unsigned bitfield expand this as XOR with a proper constant
8806 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8808 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
8809 false, GET_MODE_PRECISION (mode
));
8811 temp
= expand_binop (mode
, xor_optab
, op0
,
8812 immed_wide_int_const (mask
, mode
),
8813 target
, 1, OPTAB_LIB_WIDEN
);
8816 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8820 /* ??? Can optimize bitwise operations with one arg constant.
8821 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8822 and (a bitwise1 b) bitwise2 b (etc)
8823 but that is probably not worth while. */
8832 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8833 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8834 == TYPE_PRECISION (type
)));
8840 /* If this is a fixed-point operation, then we cannot use the code
8841 below because "expand_shift" doesn't support sat/no-sat fixed-point
8843 if (ALL_FIXED_POINT_MODE_P (mode
))
8846 if (! safe_from_p (subtarget
, treeop1
, 1))
8848 if (modifier
== EXPAND_STACK_PARM
)
8850 op0
= expand_expr (treeop0
, subtarget
,
8851 VOIDmode
, EXPAND_NORMAL
);
8853 /* Left shift optimization when shifting across word_size boundary.
8855 If mode == GET_MODE_WIDER_MODE (word_mode), then normally there isn't
8856 native instruction to support this wide mode left shift. Given below
8859 Type A = (Type) B << C
8862 | dest_high | dest_low |
8866 If the shift amount C caused we shift B to across the word size
8867 boundary, i.e part of B shifted into high half of destination
8868 register, and part of B remains in the low half, then GCC will use
8869 the following left shift expand logic:
8871 1. Initialize dest_low to B.
8872 2. Initialize every bit of dest_high to the sign bit of B.
8873 3. Logic left shift dest_low by C bit to finalize dest_low.
8874 The value of dest_low before this shift is kept in a temp D.
8875 4. Logic left shift dest_high by C.
8876 5. Logic right shift D by (word_size - C).
8877 6. Or the result of 4 and 5 to finalize dest_high.
8879 While, by checking gimple statements, if operand B is coming from
8880 signed extension, then we can simplify above expand logic into:
8882 1. dest_high = src_low >> (word_size - C).
8883 2. dest_low = src_low << C.
8885 We can use one arithmetic right shift to finish all the purpose of
8886 steps 2, 4, 5, 6, thus we reduce the steps needed from 6 into 2. */
8889 if (code
== LSHIFT_EXPR
8893 && mode
== GET_MODE_WIDER_MODE (word_mode
)
8894 && GET_MODE_SIZE (mode
) == 2 * GET_MODE_SIZE (word_mode
)
8895 && ! have_insn_for (ASHIFT
, mode
)
8896 && TREE_CONSTANT (treeop1
)
8897 && TREE_CODE (treeop0
) == SSA_NAME
)
8899 gimple def
= SSA_NAME_DEF_STMT (treeop0
);
8900 if (is_gimple_assign (def
)
8901 && gimple_assign_rhs_code (def
) == NOP_EXPR
)
8903 machine_mode rmode
= TYPE_MODE
8904 (TREE_TYPE (gimple_assign_rhs1 (def
)));
8906 if (GET_MODE_SIZE (rmode
) < GET_MODE_SIZE (mode
)
8907 && TREE_INT_CST_LOW (treeop1
) < GET_MODE_BITSIZE (word_mode
)
8908 && ((TREE_INT_CST_LOW (treeop1
) + GET_MODE_BITSIZE (rmode
))
8909 >= GET_MODE_BITSIZE (word_mode
)))
8911 unsigned int high_off
= subreg_highpart_offset (word_mode
,
8913 rtx low
= lowpart_subreg (word_mode
, op0
, mode
);
8914 rtx dest_low
= lowpart_subreg (word_mode
, target
, mode
);
8915 rtx dest_high
= simplify_gen_subreg (word_mode
, target
,
8917 HOST_WIDE_INT ramount
= (BITS_PER_WORD
8918 - TREE_INT_CST_LOW (treeop1
));
8919 tree rshift
= build_int_cst (TREE_TYPE (treeop1
), ramount
);
8921 /* dest_high = src_low >> (word_size - C). */
8922 temp
= expand_variable_shift (RSHIFT_EXPR
, word_mode
, low
,
8923 rshift
, dest_high
, unsignedp
);
8924 if (temp
!= dest_high
)
8925 emit_move_insn (dest_high
, temp
);
8927 /* dest_low = src_low << C. */
8928 temp
= expand_variable_shift (LSHIFT_EXPR
, word_mode
, low
,
8929 treeop1
, dest_low
, unsignedp
);
8930 if (temp
!= dest_low
)
8931 emit_move_insn (dest_low
, temp
);
8938 if (temp
== NULL_RTX
)
8939 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8941 if (code
== LSHIFT_EXPR
)
8942 temp
= REDUCE_BIT_FIELD (temp
);
8946 /* Could determine the answer when only additive constants differ. Also,
8947 the addition of one can be handled by changing the condition. */
8954 case UNORDERED_EXPR
:
8963 temp
= do_store_flag (ops
,
8964 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8965 tmode
!= VOIDmode
? tmode
: mode
);
8969 /* Use a compare and a jump for BLKmode comparisons, or for function
8970 type comparisons is have_canonicalize_funcptr_for_compare. */
8973 || modifier
== EXPAND_STACK_PARM
8974 || ! safe_from_p (target
, treeop0
, 1)
8975 || ! safe_from_p (target
, treeop1
, 1)
8976 /* Make sure we don't have a hard reg (such as function's return
8977 value) live across basic blocks, if not optimizing. */
8978 || (!optimize
&& REG_P (target
)
8979 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8980 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8982 emit_move_insn (target
, const0_rtx
);
8984 rtx_code_label
*lab1
= gen_label_rtx ();
8985 jumpifnot_1 (code
, treeop0
, treeop1
, lab1
, -1);
8987 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8988 emit_move_insn (target
, constm1_rtx
);
8990 emit_move_insn (target
, const1_rtx
);
8996 /* Get the rtx code of the operands. */
8997 op0
= expand_normal (treeop0
);
8998 op1
= expand_normal (treeop1
);
9001 target
= gen_reg_rtx (TYPE_MODE (type
));
9003 /* If target overlaps with op1, then either we need to force
9004 op1 into a pseudo (if target also overlaps with op0),
9005 or write the complex parts in reverse order. */
9006 switch (GET_CODE (target
))
9009 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
9011 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
9013 complex_expr_force_op1
:
9014 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
9015 emit_move_insn (temp
, op1
);
9019 complex_expr_swap_order
:
9020 /* Move the imaginary (op1) and real (op0) parts to their
9022 write_complex_part (target
, op1
, true);
9023 write_complex_part (target
, op0
, false);
9029 temp
= adjust_address_nv (target
,
9030 GET_MODE_INNER (GET_MODE (target
)), 0);
9031 if (reg_overlap_mentioned_p (temp
, op1
))
9033 machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
9034 temp
= adjust_address_nv (target
, imode
,
9035 GET_MODE_SIZE (imode
));
9036 if (reg_overlap_mentioned_p (temp
, op0
))
9037 goto complex_expr_force_op1
;
9038 goto complex_expr_swap_order
;
9042 if (reg_overlap_mentioned_p (target
, op1
))
9044 if (reg_overlap_mentioned_p (target
, op0
))
9045 goto complex_expr_force_op1
;
9046 goto complex_expr_swap_order
;
9051 /* Move the real (op0) and imaginary (op1) parts to their location. */
9052 write_complex_part (target
, op0
, false);
9053 write_complex_part (target
, op1
, true);
9057 case WIDEN_SUM_EXPR
:
9059 tree oprnd0
= treeop0
;
9060 tree oprnd1
= treeop1
;
9062 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9063 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9068 case REDUC_MAX_EXPR
:
9069 case REDUC_MIN_EXPR
:
9070 case REDUC_PLUS_EXPR
:
9072 op0
= expand_normal (treeop0
);
9073 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9074 machine_mode vec_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9076 if (optab_handler (this_optab
, vec_mode
) != CODE_FOR_nothing
)
9078 struct expand_operand ops
[2];
9079 enum insn_code icode
= optab_handler (this_optab
, vec_mode
);
9081 create_output_operand (&ops
[0], target
, mode
);
9082 create_input_operand (&ops
[1], op0
, vec_mode
);
9083 if (maybe_expand_insn (icode
, 2, ops
))
9085 target
= ops
[0].value
;
9086 if (GET_MODE (target
) != mode
)
9087 return gen_lowpart (tmode
, target
);
9091 /* Fall back to optab with vector result, and then extract scalar. */
9092 this_optab
= scalar_reduc_to_vector (this_optab
, type
);
9093 temp
= expand_unop (vec_mode
, this_optab
, op0
, NULL_RTX
, unsignedp
);
9095 /* The tree code produces a scalar result, but (somewhat by convention)
9096 the optab produces a vector with the result in element 0 if
9097 little-endian, or element N-1 if big-endian. So pull the scalar
9098 result out of that element. */
9099 int index
= BYTES_BIG_ENDIAN
? GET_MODE_NUNITS (vec_mode
) - 1 : 0;
9100 int bitsize
= GET_MODE_UNIT_BITSIZE (vec_mode
);
9101 temp
= extract_bit_field (temp
, bitsize
, bitsize
* index
, unsignedp
,
9102 target
, mode
, mode
);
9107 case VEC_UNPACK_HI_EXPR
:
9108 case VEC_UNPACK_LO_EXPR
:
9110 op0
= expand_normal (treeop0
);
9111 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9117 case VEC_UNPACK_FLOAT_HI_EXPR
:
9118 case VEC_UNPACK_FLOAT_LO_EXPR
:
9120 op0
= expand_normal (treeop0
);
9121 /* The signedness is determined from input operand. */
9122 temp
= expand_widen_pattern_expr
9123 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9124 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9130 case VEC_WIDEN_MULT_HI_EXPR
:
9131 case VEC_WIDEN_MULT_LO_EXPR
:
9132 case VEC_WIDEN_MULT_EVEN_EXPR
:
9133 case VEC_WIDEN_MULT_ODD_EXPR
:
9134 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9135 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9136 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9137 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9139 gcc_assert (target
);
9142 case VEC_PACK_TRUNC_EXPR
:
9143 case VEC_PACK_SAT_EXPR
:
9144 case VEC_PACK_FIX_TRUNC_EXPR
:
9145 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9149 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9150 op2
= expand_normal (treeop2
);
9152 /* Careful here: if the target doesn't support integral vector modes,
9153 a constant selection vector could wind up smooshed into a normal
9154 integral constant. */
9155 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9157 tree sel_type
= TREE_TYPE (treeop2
);
9159 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9160 TYPE_VECTOR_SUBPARTS (sel_type
));
9161 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9162 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9163 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9166 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9168 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9174 tree oprnd0
= treeop0
;
9175 tree oprnd1
= treeop1
;
9176 tree oprnd2
= treeop2
;
9179 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9180 op2
= expand_normal (oprnd2
);
9181 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9188 tree oprnd0
= treeop0
;
9189 tree oprnd1
= treeop1
;
9190 tree oprnd2
= treeop2
;
9193 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9194 op2
= expand_normal (oprnd2
);
9195 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9200 case REALIGN_LOAD_EXPR
:
9202 tree oprnd0
= treeop0
;
9203 tree oprnd1
= treeop1
;
9204 tree oprnd2
= treeop2
;
9207 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9208 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9209 op2
= expand_normal (oprnd2
);
9210 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9218 /* A COND_EXPR with its type being VOID_TYPE represents a
9219 conditional jump and is handled in
9220 expand_gimple_cond_expr. */
9221 gcc_assert (!VOID_TYPE_P (type
));
9223 /* Note that COND_EXPRs whose type is a structure or union
9224 are required to be constructed to contain assignments of
9225 a temporary variable, so that we can evaluate them here
9226 for side effect only. If type is void, we must do likewise. */
9228 gcc_assert (!TREE_ADDRESSABLE (type
)
9230 && TREE_TYPE (treeop1
) != void_type_node
9231 && TREE_TYPE (treeop2
) != void_type_node
);
9233 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9237 /* If we are not to produce a result, we have no target. Otherwise,
9238 if a target was specified use it; it will not be used as an
9239 intermediate target unless it is safe. If no target, use a
9242 if (modifier
!= EXPAND_STACK_PARM
9244 && safe_from_p (original_target
, treeop0
, 1)
9245 && GET_MODE (original_target
) == mode
9246 && !MEM_P (original_target
))
9247 temp
= original_target
;
9249 temp
= assign_temp (type
, 0, 1);
9251 do_pending_stack_adjust ();
9253 rtx_code_label
*lab0
= gen_label_rtx ();
9254 rtx_code_label
*lab1
= gen_label_rtx ();
9255 jumpifnot (treeop0
, lab0
, -1);
9256 store_expr (treeop1
, temp
,
9257 modifier
== EXPAND_STACK_PARM
,
9260 emit_jump_insn (targetm
.gen_jump (lab1
));
9263 store_expr (treeop2
, temp
,
9264 modifier
== EXPAND_STACK_PARM
,
9273 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9280 /* Here to do an ordinary binary operator. */
9282 expand_operands (treeop0
, treeop1
,
9283 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9285 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9287 if (modifier
== EXPAND_STACK_PARM
)
9289 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9290 unsignedp
, OPTAB_LIB_WIDEN
);
9292 /* Bitwise operations do not need bitfield reduction as we expect their
9293 operands being properly truncated. */
9294 if (code
== BIT_XOR_EXPR
9295 || code
== BIT_AND_EXPR
9296 || code
== BIT_IOR_EXPR
)
9298 return REDUCE_BIT_FIELD (temp
);
9300 #undef REDUCE_BIT_FIELD
9303 /* Return TRUE if expression STMT is suitable for replacement.
9304 Never consider memory loads as replaceable, because those don't ever lead
9305 into constant expressions. */
9308 stmt_is_replaceable_p (gimple stmt
)
9310 if (ssa_is_replaceable_p (stmt
))
9312 /* Don't move around loads. */
9313 if (!gimple_assign_single_p (stmt
)
9314 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9321 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
9322 enum expand_modifier modifier
, rtx
*alt_rtl
,
9323 bool inner_reference_p
)
9325 rtx op0
, op1
, temp
, decl_rtl
;
9328 machine_mode mode
, dmode
;
9329 enum tree_code code
= TREE_CODE (exp
);
9330 rtx subtarget
, original_target
;
9333 bool reduce_bit_field
;
9334 location_t loc
= EXPR_LOCATION (exp
);
9335 struct separate_ops ops
;
9336 tree treeop0
, treeop1
, treeop2
;
9337 tree ssa_name
= NULL_TREE
;
9340 type
= TREE_TYPE (exp
);
9341 mode
= TYPE_MODE (type
);
9342 unsignedp
= TYPE_UNSIGNED (type
);
9344 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9345 if (!VL_EXP_CLASS_P (exp
))
9346 switch (TREE_CODE_LENGTH (code
))
9349 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9350 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9351 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9361 ignore
= (target
== const0_rtx
9362 || ((CONVERT_EXPR_CODE_P (code
)
9363 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9364 && TREE_CODE (type
) == VOID_TYPE
));
9366 /* An operation in what may be a bit-field type needs the
9367 result to be reduced to the precision of the bit-field type,
9368 which is narrower than that of the type's mode. */
9369 reduce_bit_field
= (!ignore
9370 && INTEGRAL_TYPE_P (type
)
9371 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9373 /* If we are going to ignore this result, we need only do something
9374 if there is a side-effect somewhere in the expression. If there
9375 is, short-circuit the most common cases here. Note that we must
9376 not call expand_expr with anything but const0_rtx in case this
9377 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9381 if (! TREE_SIDE_EFFECTS (exp
))
9384 /* Ensure we reference a volatile object even if value is ignored, but
9385 don't do this if all we are doing is taking its address. */
9386 if (TREE_THIS_VOLATILE (exp
)
9387 && TREE_CODE (exp
) != FUNCTION_DECL
9388 && mode
!= VOIDmode
&& mode
!= BLKmode
9389 && modifier
!= EXPAND_CONST_ADDRESS
)
9391 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9397 if (TREE_CODE_CLASS (code
) == tcc_unary
9398 || code
== BIT_FIELD_REF
9399 || code
== COMPONENT_REF
9400 || code
== INDIRECT_REF
)
9401 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9404 else if (TREE_CODE_CLASS (code
) == tcc_binary
9405 || TREE_CODE_CLASS (code
) == tcc_comparison
9406 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9408 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9409 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9416 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9419 /* Use subtarget as the target for operand 0 of a binary operation. */
9420 subtarget
= get_subtarget (target
);
9421 original_target
= target
;
9427 tree function
= decl_function_context (exp
);
9429 temp
= label_rtx (exp
);
9430 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9432 if (function
!= current_function_decl
9434 LABEL_REF_NONLOCAL_P (temp
) = 1;
9436 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9441 /* ??? ivopts calls expander, without any preparation from
9442 out-of-ssa. So fake instructions as if this was an access to the
9443 base variable. This unnecessarily allocates a pseudo, see how we can
9444 reuse it, if partition base vars have it set already. */
9445 if (!currently_expanding_to_rtl
)
9447 tree var
= SSA_NAME_VAR (exp
);
9448 if (var
&& DECL_RTL_SET_P (var
))
9449 return DECL_RTL (var
);
9450 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9451 LAST_VIRTUAL_REGISTER
+ 1);
9454 g
= get_gimple_for_ssa_name (exp
);
9455 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9457 && modifier
== EXPAND_INITIALIZER
9458 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9459 && (optimize
|| !SSA_NAME_VAR (exp
)
9460 || DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9461 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9462 g
= SSA_NAME_DEF_STMT (exp
);
9466 location_t saved_loc
= curr_insn_location ();
9467 location_t loc
= gimple_location (g
);
9468 if (loc
!= UNKNOWN_LOCATION
)
9469 set_curr_insn_location (loc
);
9470 ops
.code
= gimple_assign_rhs_code (g
);
9471 switch (get_gimple_rhs_class (ops
.code
))
9473 case GIMPLE_TERNARY_RHS
:
9474 ops
.op2
= gimple_assign_rhs3 (g
);
9476 case GIMPLE_BINARY_RHS
:
9477 ops
.op1
= gimple_assign_rhs2 (g
);
9479 /* Try to expand conditonal compare. */
9480 if (targetm
.gen_ccmp_first
)
9482 gcc_checking_assert (targetm
.gen_ccmp_next
!= NULL
);
9483 r
= expand_ccmp_expr (g
);
9488 case GIMPLE_UNARY_RHS
:
9489 ops
.op0
= gimple_assign_rhs1 (g
);
9490 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9492 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9494 case GIMPLE_SINGLE_RHS
:
9496 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9497 tmode
, modifier
, NULL
, inner_reference_p
);
9503 set_curr_insn_location (saved_loc
);
9504 if (REG_P (r
) && !REG_EXPR (r
))
9505 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9510 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9511 exp
= SSA_NAME_VAR (ssa_name
);
9512 goto expand_decl_rtl
;
9516 /* If a static var's type was incomplete when the decl was written,
9517 but the type is complete now, lay out the decl now. */
9518 if (DECL_SIZE (exp
) == 0
9519 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9520 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9521 layout_decl (exp
, 0);
9523 /* ... fall through ... */
9527 decl_rtl
= DECL_RTL (exp
);
9529 gcc_assert (decl_rtl
);
9530 decl_rtl
= copy_rtx (decl_rtl
);
9531 /* Record writes to register variables. */
9532 if (modifier
== EXPAND_WRITE
9534 && HARD_REGISTER_P (decl_rtl
))
9535 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9536 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9538 /* Ensure variable marked as used even if it doesn't go through
9539 a parser. If it hasn't be used yet, write out an external
9542 TREE_USED (exp
) = 1;
9544 /* Show we haven't gotten RTL for this yet. */
9547 /* Variables inherited from containing functions should have
9548 been lowered by this point. */
9550 context
= decl_function_context (exp
);
9552 || SCOPE_FILE_SCOPE_P (context
)
9553 || context
== current_function_decl
9554 || TREE_STATIC (exp
)
9555 || DECL_EXTERNAL (exp
)
9556 /* ??? C++ creates functions that are not TREE_STATIC. */
9557 || TREE_CODE (exp
) == FUNCTION_DECL
);
9559 /* This is the case of an array whose size is to be determined
9560 from its initializer, while the initializer is still being parsed.
9561 ??? We aren't parsing while expanding anymore. */
9563 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9564 temp
= validize_mem (decl_rtl
);
9566 /* If DECL_RTL is memory, we are in the normal case and the
9567 address is not valid, get the address into a register. */
9569 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9572 *alt_rtl
= decl_rtl
;
9573 decl_rtl
= use_anchored_address (decl_rtl
);
9574 if (modifier
!= EXPAND_CONST_ADDRESS
9575 && modifier
!= EXPAND_SUM
9576 && !memory_address_addr_space_p (exp
? DECL_MODE (exp
)
9577 : GET_MODE (decl_rtl
),
9579 MEM_ADDR_SPACE (decl_rtl
)))
9580 temp
= replace_equiv_address (decl_rtl
,
9581 copy_rtx (XEXP (decl_rtl
, 0)));
9584 /* If we got something, return it. But first, set the alignment
9585 if the address is a register. */
9588 if (exp
&& MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9589 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9595 dmode
= DECL_MODE (exp
);
9597 dmode
= TYPE_MODE (TREE_TYPE (ssa_name
));
9599 /* If the mode of DECL_RTL does not match that of the decl,
9600 there are two cases: we are dealing with a BLKmode value
9601 that is returned in a register, or we are dealing with
9602 a promoted value. In the latter case, return a SUBREG
9603 of the wanted mode, but mark it so that we know that it
9604 was already extended. */
9605 if (REG_P (decl_rtl
)
9607 && GET_MODE (decl_rtl
) != dmode
)
9611 /* Get the signedness to be used for this variable. Ensure we get
9612 the same mode we got when the variable was declared. */
9613 if (code
!= SSA_NAME
)
9614 pmode
= promote_decl_mode (exp
, &unsignedp
);
9615 else if ((g
= SSA_NAME_DEF_STMT (ssa_name
))
9616 && gimple_code (g
) == GIMPLE_CALL
9617 && !gimple_call_internal_p (g
))
9618 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9619 gimple_call_fntype (g
),
9622 pmode
= promote_ssa_mode (ssa_name
, &unsignedp
);
9623 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9625 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9626 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9627 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9634 /* Given that TYPE_PRECISION (type) is not always equal to
9635 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9636 the former to the latter according to the signedness of the
9638 temp
= immed_wide_int_const (wide_int::from
9640 GET_MODE_PRECISION (TYPE_MODE (type
)),
9647 tree tmp
= NULL_TREE
;
9648 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9649 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9650 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9651 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9652 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9653 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9654 return const_vector_from_tree (exp
);
9655 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9657 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9659 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9663 vec
<constructor_elt
, va_gc
> *v
;
9665 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9666 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9667 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9668 tmp
= build_constructor (type
, v
);
9670 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9675 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9678 /* If optimized, generate immediate CONST_DOUBLE
9679 which will be turned into memory by reload if necessary.
9681 We used to force a register so that loop.c could see it. But
9682 this does not allow gen_* patterns to perform optimizations with
9683 the constants. It also produces two insns in cases like "x = 1.0;".
9684 On most machines, floating-point constants are not permitted in
9685 many insns, so we'd end up copying it to a register in any case.
9687 Now, we do the copying in expand_binop, if appropriate. */
9688 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9689 TYPE_MODE (TREE_TYPE (exp
)));
9692 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9693 TYPE_MODE (TREE_TYPE (exp
)));
9696 /* Handle evaluating a complex constant in a CONCAT target. */
9697 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9699 machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9702 rtarg
= XEXP (original_target
, 0);
9703 itarg
= XEXP (original_target
, 1);
9705 /* Move the real and imaginary parts separately. */
9706 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9707 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9710 emit_move_insn (rtarg
, op0
);
9712 emit_move_insn (itarg
, op1
);
9714 return original_target
;
9717 /* ... fall through ... */
9720 temp
= expand_expr_constant (exp
, 1, modifier
);
9722 /* temp contains a constant address.
9723 On RISC machines where a constant address isn't valid,
9724 make some insns to get that address into a register. */
9725 if (modifier
!= EXPAND_CONST_ADDRESS
9726 && modifier
!= EXPAND_INITIALIZER
9727 && modifier
!= EXPAND_SUM
9728 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9729 MEM_ADDR_SPACE (temp
)))
9730 return replace_equiv_address (temp
,
9731 copy_rtx (XEXP (temp
, 0)));
9737 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
9740 if (!SAVE_EXPR_RESOLVED_P (exp
))
9742 /* We can indeed still hit this case, typically via builtin
9743 expanders calling save_expr immediately before expanding
9744 something. Assume this means that we only have to deal
9745 with non-BLKmode values. */
9746 gcc_assert (GET_MODE (ret
) != BLKmode
);
9748 val
= build_decl (curr_insn_location (),
9749 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9750 DECL_ARTIFICIAL (val
) = 1;
9751 DECL_IGNORED_P (val
) = 1;
9753 TREE_OPERAND (exp
, 0) = treeop0
;
9754 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9756 if (!CONSTANT_P (ret
))
9757 ret
= copy_to_reg (ret
);
9758 SET_DECL_RTL (val
, ret
);
9766 /* If we don't need the result, just ensure we evaluate any
9770 unsigned HOST_WIDE_INT idx
;
9773 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9774 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9779 return expand_constructor (exp
, target
, modifier
, false);
9781 case TARGET_MEM_REF
:
9784 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9785 enum insn_code icode
;
9788 op0
= addr_for_mem_ref (exp
, as
, true);
9789 op0
= memory_address_addr_space (mode
, op0
, as
);
9790 temp
= gen_rtx_MEM (mode
, op0
);
9791 set_mem_attributes (temp
, exp
, 0);
9792 set_mem_addr_space (temp
, as
);
9793 align
= get_object_alignment (exp
);
9794 if (modifier
!= EXPAND_WRITE
9795 && modifier
!= EXPAND_MEMORY
9797 && align
< GET_MODE_ALIGNMENT (mode
)
9798 /* If the target does not have special handling for unaligned
9799 loads of mode then it can use regular moves for them. */
9800 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9801 != CODE_FOR_nothing
))
9803 struct expand_operand ops
[2];
9805 /* We've already validated the memory, and we're creating a
9806 new pseudo destination. The predicates really can't fail,
9807 nor can the generator. */
9808 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9809 create_fixed_operand (&ops
[1], temp
);
9810 expand_insn (icode
, 2, ops
);
9811 temp
= ops
[0].value
;
9819 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9820 machine_mode address_mode
;
9821 tree base
= TREE_OPERAND (exp
, 0);
9823 enum insn_code icode
;
9825 /* Handle expansion of non-aliased memory with non-BLKmode. That
9826 might end up in a register. */
9827 if (mem_ref_refers_to_non_mem_p (exp
))
9829 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
9830 base
= TREE_OPERAND (base
, 0);
9832 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9833 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9834 == tree_to_uhwi (TYPE_SIZE (type
))))
9835 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9836 target
, tmode
, modifier
);
9837 if (TYPE_MODE (type
) == BLKmode
)
9839 temp
= assign_stack_temp (DECL_MODE (base
),
9840 GET_MODE_SIZE (DECL_MODE (base
)));
9841 store_expr (base
, temp
, 0, false);
9842 temp
= adjust_address (temp
, BLKmode
, offset
);
9843 set_mem_size (temp
, int_size_in_bytes (type
));
9846 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9847 bitsize_int (offset
* BITS_PER_UNIT
));
9848 return expand_expr (exp
, target
, tmode
, modifier
);
9850 address_mode
= targetm
.addr_space
.address_mode (as
);
9851 base
= TREE_OPERAND (exp
, 0);
9852 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9854 tree mask
= gimple_assign_rhs2 (def_stmt
);
9855 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9856 gimple_assign_rhs1 (def_stmt
), mask
);
9857 TREE_OPERAND (exp
, 0) = base
;
9859 align
= get_object_alignment (exp
);
9860 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9861 op0
= memory_address_addr_space (mode
, op0
, as
);
9862 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9864 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
9865 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9866 op0
= memory_address_addr_space (mode
, op0
, as
);
9868 temp
= gen_rtx_MEM (mode
, op0
);
9869 set_mem_attributes (temp
, exp
, 0);
9870 set_mem_addr_space (temp
, as
);
9871 if (TREE_THIS_VOLATILE (exp
))
9872 MEM_VOLATILE_P (temp
) = 1;
9873 if (modifier
!= EXPAND_WRITE
9874 && modifier
!= EXPAND_MEMORY
9875 && !inner_reference_p
9877 && align
< GET_MODE_ALIGNMENT (mode
))
9879 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9880 != CODE_FOR_nothing
)
9882 struct expand_operand ops
[2];
9884 /* We've already validated the memory, and we're creating a
9885 new pseudo destination. The predicates really can't fail,
9886 nor can the generator. */
9887 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9888 create_fixed_operand (&ops
[1], temp
);
9889 expand_insn (icode
, 2, ops
);
9890 temp
= ops
[0].value
;
9892 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9893 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9894 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9895 (modifier
== EXPAND_STACK_PARM
9896 ? NULL_RTX
: target
),
9905 tree array
= treeop0
;
9906 tree index
= treeop1
;
9909 /* Fold an expression like: "foo"[2].
9910 This is not done in fold so it won't happen inside &.
9911 Don't fold if this is for wide characters since it's too
9912 difficult to do correctly and this is a very rare case. */
9914 if (modifier
!= EXPAND_CONST_ADDRESS
9915 && modifier
!= EXPAND_INITIALIZER
9916 && modifier
!= EXPAND_MEMORY
)
9918 tree t
= fold_read_from_constant_string (exp
);
9921 return expand_expr (t
, target
, tmode
, modifier
);
9924 /* If this is a constant index into a constant array,
9925 just get the value from the array. Handle both the cases when
9926 we have an explicit constructor and when our operand is a variable
9927 that was declared const. */
9929 if (modifier
!= EXPAND_CONST_ADDRESS
9930 && modifier
!= EXPAND_INITIALIZER
9931 && modifier
!= EXPAND_MEMORY
9932 && TREE_CODE (array
) == CONSTRUCTOR
9933 && ! TREE_SIDE_EFFECTS (array
)
9934 && TREE_CODE (index
) == INTEGER_CST
)
9936 unsigned HOST_WIDE_INT ix
;
9939 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9941 if (tree_int_cst_equal (field
, index
))
9943 if (!TREE_SIDE_EFFECTS (value
))
9944 return expand_expr (fold (value
), target
, tmode
, modifier
);
9949 else if (optimize
>= 1
9950 && modifier
!= EXPAND_CONST_ADDRESS
9951 && modifier
!= EXPAND_INITIALIZER
9952 && modifier
!= EXPAND_MEMORY
9953 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9954 && TREE_CODE (index
) == INTEGER_CST
9955 && (TREE_CODE (array
) == VAR_DECL
9956 || TREE_CODE (array
) == CONST_DECL
)
9957 && (init
= ctor_for_folding (array
)) != error_mark_node
)
9959 if (init
== NULL_TREE
)
9961 tree value
= build_zero_cst (type
);
9962 if (TREE_CODE (value
) == CONSTRUCTOR
)
9964 /* If VALUE is a CONSTRUCTOR, this optimization is only
9965 useful if this doesn't store the CONSTRUCTOR into
9966 memory. If it does, it is more efficient to just
9967 load the data from the array directly. */
9968 rtx ret
= expand_constructor (value
, target
,
9970 if (ret
== NULL_RTX
)
9975 return expand_expr (value
, target
, tmode
, modifier
);
9977 else if (TREE_CODE (init
) == CONSTRUCTOR
)
9979 unsigned HOST_WIDE_INT ix
;
9982 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9984 if (tree_int_cst_equal (field
, index
))
9986 if (TREE_SIDE_EFFECTS (value
))
9989 if (TREE_CODE (value
) == CONSTRUCTOR
)
9991 /* If VALUE is a CONSTRUCTOR, this
9992 optimization is only useful if
9993 this doesn't store the CONSTRUCTOR
9994 into memory. If it does, it is more
9995 efficient to just load the data from
9996 the array directly. */
9997 rtx ret
= expand_constructor (value
, target
,
9999 if (ret
== NULL_RTX
)
10004 expand_expr (fold (value
), target
, tmode
, modifier
);
10007 else if (TREE_CODE (init
) == STRING_CST
)
10009 tree low_bound
= array_ref_low_bound (exp
);
10010 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
10012 /* Optimize the special case of a zero lower bound.
10014 We convert the lower bound to sizetype to avoid problems
10015 with constant folding. E.g. suppose the lower bound is
10016 1 and its mode is QI. Without the conversion
10017 (ARRAY + (INDEX - (unsigned char)1))
10019 (ARRAY + (-(unsigned char)1) + INDEX)
10021 (ARRAY + 255 + INDEX). Oops! */
10022 if (!integer_zerop (low_bound
))
10023 index1
= size_diffop_loc (loc
, index1
,
10024 fold_convert_loc (loc
, sizetype
,
10027 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
10029 tree type
= TREE_TYPE (TREE_TYPE (init
));
10030 machine_mode mode
= TYPE_MODE (type
);
10032 if (GET_MODE_CLASS (mode
) == MODE_INT
10033 && GET_MODE_SIZE (mode
) == 1)
10034 return gen_int_mode (TREE_STRING_POINTER (init
)
10035 [TREE_INT_CST_LOW (index1
)],
10041 goto normal_inner_ref
;
10043 case COMPONENT_REF
:
10044 /* If the operand is a CONSTRUCTOR, we can just extract the
10045 appropriate field if it is present. */
10046 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
10048 unsigned HOST_WIDE_INT idx
;
10051 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
10053 if (field
== treeop1
10054 /* We can normally use the value of the field in the
10055 CONSTRUCTOR. However, if this is a bitfield in
10056 an integral mode that we can fit in a HOST_WIDE_INT,
10057 we must mask only the number of bits in the bitfield,
10058 since this is done implicitly by the constructor. If
10059 the bitfield does not meet either of those conditions,
10060 we can't do this optimization. */
10061 && (! DECL_BIT_FIELD (field
)
10062 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
10063 && (GET_MODE_PRECISION (DECL_MODE (field
))
10064 <= HOST_BITS_PER_WIDE_INT
))))
10066 if (DECL_BIT_FIELD (field
)
10067 && modifier
== EXPAND_STACK_PARM
)
10069 op0
= expand_expr (value
, target
, tmode
, modifier
);
10070 if (DECL_BIT_FIELD (field
))
10072 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
10073 machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
10075 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
10077 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
10079 op0
= expand_and (imode
, op0
, op1
, target
);
10083 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10085 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10087 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10095 goto normal_inner_ref
;
10097 case BIT_FIELD_REF
:
10098 case ARRAY_RANGE_REF
:
10101 machine_mode mode1
, mode2
;
10102 HOST_WIDE_INT bitsize
, bitpos
;
10104 int volatilep
= 0, must_force_mem
;
10105 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
10106 &mode1
, &unsignedp
, &volatilep
, true);
10107 rtx orig_op0
, memloc
;
10108 bool clear_mem_expr
= false;
10110 /* If we got back the original object, something is wrong. Perhaps
10111 we are evaluating an expression too early. In any event, don't
10112 infinitely recurse. */
10113 gcc_assert (tem
!= exp
);
10115 /* If TEM's type is a union of variable size, pass TARGET to the inner
10116 computation, since it will need a temporary and TARGET is known
10117 to have to do. This occurs in unchecked conversion in Ada. */
10119 = expand_expr_real (tem
,
10120 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10121 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10122 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10124 && modifier
!= EXPAND_STACK_PARM
10125 ? target
: NULL_RTX
),
10127 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10130 /* If the field has a mode, we want to access it in the
10131 field's mode, not the computed mode.
10132 If a MEM has VOIDmode (external with incomplete type),
10133 use BLKmode for it instead. */
10136 if (mode1
!= VOIDmode
)
10137 op0
= adjust_address (op0
, mode1
, 0);
10138 else if (GET_MODE (op0
) == VOIDmode
)
10139 op0
= adjust_address (op0
, BLKmode
, 0);
10143 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10145 /* If we have either an offset, a BLKmode result, or a reference
10146 outside the underlying object, we must force it to memory.
10147 Such a case can occur in Ada if we have unchecked conversion
10148 of an expression from a scalar type to an aggregate type or
10149 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10150 passed a partially uninitialized object or a view-conversion
10151 to a larger size. */
10152 must_force_mem
= (offset
10153 || mode1
== BLKmode
10154 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10156 /* Handle CONCAT first. */
10157 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10160 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
10163 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10166 op0
= XEXP (op0
, 0);
10167 mode2
= GET_MODE (op0
);
10169 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10170 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10174 op0
= XEXP (op0
, 1);
10176 mode2
= GET_MODE (op0
);
10179 /* Otherwise force into memory. */
10180 must_force_mem
= 1;
10183 /* If this is a constant, put it in a register if it is a legitimate
10184 constant and we don't need a memory reference. */
10185 if (CONSTANT_P (op0
)
10186 && mode2
!= BLKmode
10187 && targetm
.legitimate_constant_p (mode2
, op0
)
10188 && !must_force_mem
)
10189 op0
= force_reg (mode2
, op0
);
10191 /* Otherwise, if this is a constant, try to force it to the constant
10192 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10193 is a legitimate constant. */
10194 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10195 op0
= validize_mem (memloc
);
10197 /* Otherwise, if this is a constant or the object is not in memory
10198 and need be, put it there. */
10199 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10201 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10202 emit_move_insn (memloc
, op0
);
10204 clear_mem_expr
= true;
10209 machine_mode address_mode
;
10210 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10213 gcc_assert (MEM_P (op0
));
10215 address_mode
= get_address_mode (op0
);
10216 if (GET_MODE (offset_rtx
) != address_mode
)
10218 /* We cannot be sure that the RTL in offset_rtx is valid outside
10219 of a memory address context, so force it into a register
10220 before attempting to convert it to the desired mode. */
10221 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
10222 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10225 /* See the comment in expand_assignment for the rationale. */
10226 if (mode1
!= VOIDmode
10229 && (bitpos
% bitsize
) == 0
10230 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10231 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10233 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10237 op0
= offset_address (op0
, offset_rtx
,
10238 highest_pow2_factor (offset
));
10241 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10242 record its alignment as BIGGEST_ALIGNMENT. */
10243 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10244 && is_aligning_offset (offset
, tem
))
10245 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10247 /* Don't forget about volatility even if this is a bitfield. */
10248 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10250 if (op0
== orig_op0
)
10251 op0
= copy_rtx (op0
);
10253 MEM_VOLATILE_P (op0
) = 1;
10256 /* In cases where an aligned union has an unaligned object
10257 as a field, we might be extracting a BLKmode value from
10258 an integer-mode (e.g., SImode) object. Handle this case
10259 by doing the extract into an object as wide as the field
10260 (which we know to be the width of a basic mode), then
10261 storing into memory, and changing the mode to BLKmode. */
10262 if (mode1
== VOIDmode
10263 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10264 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10265 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10266 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10267 && modifier
!= EXPAND_CONST_ADDRESS
10268 && modifier
!= EXPAND_INITIALIZER
10269 && modifier
!= EXPAND_MEMORY
)
10270 /* If the bitfield is volatile and the bitsize
10271 is narrower than the access size of the bitfield,
10272 we need to extract bitfields from the access. */
10273 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10274 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10275 && mode1
!= BLKmode
10276 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10277 /* If the field isn't aligned enough to fetch as a memref,
10278 fetch it as a bit field. */
10279 || (mode1
!= BLKmode
10280 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10281 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10283 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10284 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10285 && modifier
!= EXPAND_MEMORY
10286 && ((modifier
== EXPAND_CONST_ADDRESS
10287 || modifier
== EXPAND_INITIALIZER
)
10289 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10290 || (bitpos
% BITS_PER_UNIT
!= 0)))
10291 /* If the type and the field are a constant size and the
10292 size of the type isn't the same size as the bitfield,
10293 we must use bitfield operations. */
10295 && TYPE_SIZE (TREE_TYPE (exp
))
10296 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10297 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10300 machine_mode ext_mode
= mode
;
10302 if (ext_mode
== BLKmode
10303 && ! (target
!= 0 && MEM_P (op0
)
10305 && bitpos
% BITS_PER_UNIT
== 0))
10306 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10308 if (ext_mode
== BLKmode
)
10311 target
= assign_temp (type
, 1, 1);
10313 /* ??? Unlike the similar test a few lines below, this one is
10314 very likely obsolete. */
10318 /* In this case, BITPOS must start at a byte boundary and
10319 TARGET, if specified, must be a MEM. */
10320 gcc_assert (MEM_P (op0
)
10321 && (!target
|| MEM_P (target
))
10322 && !(bitpos
% BITS_PER_UNIT
));
10324 emit_block_move (target
,
10325 adjust_address (op0
, VOIDmode
,
10326 bitpos
/ BITS_PER_UNIT
),
10327 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10329 (modifier
== EXPAND_STACK_PARM
10330 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10335 /* If we have nothing to extract, the result will be 0 for targets
10336 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10337 return 0 for the sake of consistency, as reading a zero-sized
10338 bitfield is valid in Ada and the value is fully specified. */
10342 op0
= validize_mem (op0
);
10344 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10345 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10347 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10348 (modifier
== EXPAND_STACK_PARM
10349 ? NULL_RTX
: target
),
10350 ext_mode
, ext_mode
);
10352 /* If the result is a record type and BITSIZE is narrower than
10353 the mode of OP0, an integral mode, and this is a big endian
10354 machine, we must put the field into the high-order bits. */
10355 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10356 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10357 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10358 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10359 GET_MODE_BITSIZE (GET_MODE (op0
))
10360 - bitsize
, op0
, 1);
10362 /* If the result type is BLKmode, store the data into a temporary
10363 of the appropriate type, but with the mode corresponding to the
10364 mode for the data we have (op0's mode). */
10365 if (mode
== BLKmode
)
10368 = assign_stack_temp_for_type (ext_mode
,
10369 GET_MODE_BITSIZE (ext_mode
),
10371 emit_move_insn (new_rtx
, op0
);
10372 op0
= copy_rtx (new_rtx
);
10373 PUT_MODE (op0
, BLKmode
);
10379 /* If the result is BLKmode, use that to access the object
10381 if (mode
== BLKmode
)
10384 /* Get a reference to just this component. */
10385 if (modifier
== EXPAND_CONST_ADDRESS
10386 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10387 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10389 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10391 if (op0
== orig_op0
)
10392 op0
= copy_rtx (op0
);
10394 set_mem_attributes (op0
, exp
, 0);
10396 if (REG_P (XEXP (op0
, 0)))
10397 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10399 /* If op0 is a temporary because the original expressions was forced
10400 to memory, clear MEM_EXPR so that the original expression cannot
10401 be marked as addressable through MEM_EXPR of the temporary. */
10402 if (clear_mem_expr
)
10403 set_mem_expr (op0
, NULL_TREE
);
10405 MEM_VOLATILE_P (op0
) |= volatilep
;
10406 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10407 || modifier
== EXPAND_CONST_ADDRESS
10408 || modifier
== EXPAND_INITIALIZER
)
10412 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10414 convert_move (target
, op0
, unsignedp
);
10419 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10422 /* All valid uses of __builtin_va_arg_pack () are removed during
10424 if (CALL_EXPR_VA_ARG_PACK (exp
))
10425 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10427 tree fndecl
= get_callee_fndecl (exp
), attr
;
10430 && (attr
= lookup_attribute ("error",
10431 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10432 error ("%Kcall to %qs declared with attribute error: %s",
10433 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10434 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10436 && (attr
= lookup_attribute ("warning",
10437 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10438 warning_at (tree_nonartificial_location (exp
),
10439 0, "%Kcall to %qs declared with attribute warning: %s",
10440 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10441 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10443 /* Check for a built-in function. */
10444 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10446 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10447 if (CALL_WITH_BOUNDS_P (exp
))
10448 return expand_builtin_with_bounds (exp
, target
, subtarget
,
10451 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10454 return expand_call (exp
, target
, ignore
);
10456 case VIEW_CONVERT_EXPR
:
10459 /* If we are converting to BLKmode, try to avoid an intermediate
10460 temporary by fetching an inner memory reference. */
10461 if (mode
== BLKmode
10462 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10463 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10464 && handled_component_p (treeop0
))
10466 machine_mode mode1
;
10467 HOST_WIDE_INT bitsize
, bitpos
;
10472 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10473 &offset
, &mode1
, &unsignedp
, &volatilep
,
10477 /* ??? We should work harder and deal with non-zero offsets. */
10479 && (bitpos
% BITS_PER_UNIT
) == 0
10481 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10483 /* See the normal_inner_ref case for the rationale. */
10485 = expand_expr_real (tem
,
10486 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10487 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10489 && modifier
!= EXPAND_STACK_PARM
10490 ? target
: NULL_RTX
),
10492 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10495 if (MEM_P (orig_op0
))
10499 /* Get a reference to just this component. */
10500 if (modifier
== EXPAND_CONST_ADDRESS
10501 || modifier
== EXPAND_SUM
10502 || modifier
== EXPAND_INITIALIZER
)
10503 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10505 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10507 if (op0
== orig_op0
)
10508 op0
= copy_rtx (op0
);
10510 set_mem_attributes (op0
, treeop0
, 0);
10511 if (REG_P (XEXP (op0
, 0)))
10512 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10514 MEM_VOLATILE_P (op0
) |= volatilep
;
10520 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10521 NULL
, inner_reference_p
);
10523 /* If the input and output modes are both the same, we are done. */
10524 if (mode
== GET_MODE (op0
))
10526 /* If neither mode is BLKmode, and both modes are the same size
10527 then we can use gen_lowpart. */
10528 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10529 && (GET_MODE_PRECISION (mode
)
10530 == GET_MODE_PRECISION (GET_MODE (op0
)))
10531 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10533 if (GET_CODE (op0
) == SUBREG
)
10534 op0
= force_reg (GET_MODE (op0
), op0
);
10535 temp
= gen_lowpart_common (mode
, op0
);
10540 if (!REG_P (op0
) && !MEM_P (op0
))
10541 op0
= force_reg (GET_MODE (op0
), op0
);
10542 op0
= gen_lowpart (mode
, op0
);
10545 /* If both types are integral, convert from one mode to the other. */
10546 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10547 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10548 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10549 /* If the output type is a bit-field type, do an extraction. */
10550 else if (reduce_bit_field
)
10551 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10552 TYPE_UNSIGNED (type
), NULL_RTX
,
10554 /* As a last resort, spill op0 to memory, and reload it in a
10556 else if (!MEM_P (op0
))
10558 /* If the operand is not a MEM, force it into memory. Since we
10559 are going to be changing the mode of the MEM, don't call
10560 force_const_mem for constants because we don't allow pool
10561 constants to change mode. */
10562 tree inner_type
= TREE_TYPE (treeop0
);
10564 gcc_assert (!TREE_ADDRESSABLE (exp
));
10566 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10568 = assign_stack_temp_for_type
10569 (TYPE_MODE (inner_type
),
10570 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10572 emit_move_insn (target
, op0
);
10576 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10577 output type is such that the operand is known to be aligned, indicate
10578 that it is. Otherwise, we need only be concerned about alignment for
10579 non-BLKmode results. */
10582 enum insn_code icode
;
10584 if (TYPE_ALIGN_OK (type
))
10586 /* ??? Copying the MEM without substantially changing it might
10587 run afoul of the code handling volatile memory references in
10588 store_expr, which assumes that TARGET is returned unmodified
10589 if it has been used. */
10590 op0
= copy_rtx (op0
);
10591 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10593 else if (modifier
!= EXPAND_WRITE
10594 && modifier
!= EXPAND_MEMORY
10595 && !inner_reference_p
10597 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10599 /* If the target does have special handling for unaligned
10600 loads of mode then use them. */
10601 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10602 != CODE_FOR_nothing
)
10606 op0
= adjust_address (op0
, mode
, 0);
10607 /* We've already validated the memory, and we're creating a
10608 new pseudo destination. The predicates really can't
10610 reg
= gen_reg_rtx (mode
);
10612 /* Nor can the insn generator. */
10613 rtx_insn
*insn
= GEN_FCN (icode
) (reg
, op0
);
10617 else if (STRICT_ALIGNMENT
)
10619 tree inner_type
= TREE_TYPE (treeop0
);
10620 HOST_WIDE_INT temp_size
10621 = MAX (int_size_in_bytes (inner_type
),
10622 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10624 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10625 rtx new_with_op0_mode
10626 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10628 gcc_assert (!TREE_ADDRESSABLE (exp
));
10630 if (GET_MODE (op0
) == BLKmode
)
10631 emit_block_move (new_with_op0_mode
, op0
,
10632 GEN_INT (GET_MODE_SIZE (mode
)),
10633 (modifier
== EXPAND_STACK_PARM
10634 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10636 emit_move_insn (new_with_op0_mode
, op0
);
10642 op0
= adjust_address (op0
, mode
, 0);
10649 tree lhs
= treeop0
;
10650 tree rhs
= treeop1
;
10651 gcc_assert (ignore
);
10653 /* Check for |= or &= of a bitfield of size one into another bitfield
10654 of size 1. In this case, (unless we need the result of the
10655 assignment) we can do this more efficiently with a
10656 test followed by an assignment, if necessary.
10658 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10659 things change so we do, this code should be enhanced to
10661 if (TREE_CODE (lhs
) == COMPONENT_REF
10662 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10663 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10664 && TREE_OPERAND (rhs
, 0) == lhs
10665 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10666 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10667 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10669 rtx_code_label
*label
= gen_label_rtx ();
10670 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10671 do_jump (TREE_OPERAND (rhs
, 1),
10673 value
? 0 : label
, -1);
10674 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10676 do_pending_stack_adjust ();
10677 emit_label (label
);
10681 expand_assignment (lhs
, rhs
, false);
10686 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10688 case REALPART_EXPR
:
10689 op0
= expand_normal (treeop0
);
10690 return read_complex_part (op0
, false);
10692 case IMAGPART_EXPR
:
10693 op0
= expand_normal (treeop0
);
10694 return read_complex_part (op0
, true);
10701 /* Expanded in cfgexpand.c. */
10702 gcc_unreachable ();
10704 case TRY_CATCH_EXPR
:
10706 case EH_FILTER_EXPR
:
10707 case TRY_FINALLY_EXPR
:
10708 /* Lowered by tree-eh.c. */
10709 gcc_unreachable ();
10711 case WITH_CLEANUP_EXPR
:
10712 case CLEANUP_POINT_EXPR
:
10714 case CASE_LABEL_EXPR
:
10719 case COMPOUND_EXPR
:
10720 case PREINCREMENT_EXPR
:
10721 case PREDECREMENT_EXPR
:
10722 case POSTINCREMENT_EXPR
:
10723 case POSTDECREMENT_EXPR
:
10726 case COMPOUND_LITERAL_EXPR
:
10727 /* Lowered by gimplify.c. */
10728 gcc_unreachable ();
10731 /* Function descriptors are not valid except for as
10732 initialization constants, and should not be expanded. */
10733 gcc_unreachable ();
10735 case WITH_SIZE_EXPR
:
10736 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10737 have pulled out the size to use in whatever context it needed. */
10738 return expand_expr_real (treeop0
, original_target
, tmode
,
10739 modifier
, alt_rtl
, inner_reference_p
);
10742 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10746 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10747 signedness of TYPE), possibly returning the result in TARGET. */
10749 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10751 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10752 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10754 /* For constant values, reduce using build_int_cst_type. */
10755 if (CONST_INT_P (exp
))
10757 HOST_WIDE_INT value
= INTVAL (exp
);
10758 tree t
= build_int_cst_type (type
, value
);
10759 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10761 else if (TYPE_UNSIGNED (type
))
10763 machine_mode mode
= GET_MODE (exp
);
10764 rtx mask
= immed_wide_int_const
10765 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
10766 return expand_and (mode
, exp
, mask
, target
);
10770 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10771 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10772 exp
, count
, target
, 0);
10773 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10774 exp
, count
, target
, 0);
10778 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10779 when applied to the address of EXP produces an address known to be
10780 aligned more than BIGGEST_ALIGNMENT. */
10783 is_aligning_offset (const_tree offset
, const_tree exp
)
10785 /* Strip off any conversions. */
10786 while (CONVERT_EXPR_P (offset
))
10787 offset
= TREE_OPERAND (offset
, 0);
10789 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10790 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10791 if (TREE_CODE (offset
) != BIT_AND_EXPR
10792 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10793 || compare_tree_int (TREE_OPERAND (offset
, 1),
10794 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10795 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10798 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10799 It must be NEGATE_EXPR. Then strip any more conversions. */
10800 offset
= TREE_OPERAND (offset
, 0);
10801 while (CONVERT_EXPR_P (offset
))
10802 offset
= TREE_OPERAND (offset
, 0);
10804 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10807 offset
= TREE_OPERAND (offset
, 0);
10808 while (CONVERT_EXPR_P (offset
))
10809 offset
= TREE_OPERAND (offset
, 0);
10811 /* This must now be the address of EXP. */
10812 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10815 /* Return the tree node if an ARG corresponds to a string constant or zero
10816 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10817 in bytes within the string that ARG is accessing. The type of the
10818 offset will be `sizetype'. */
10821 string_constant (tree arg
, tree
*ptr_offset
)
10823 tree array
, offset
, lower_bound
;
10826 if (TREE_CODE (arg
) == ADDR_EXPR
)
10828 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10830 *ptr_offset
= size_zero_node
;
10831 return TREE_OPERAND (arg
, 0);
10833 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10835 array
= TREE_OPERAND (arg
, 0);
10836 offset
= size_zero_node
;
10838 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10840 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10841 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10842 if (TREE_CODE (array
) != STRING_CST
10843 && TREE_CODE (array
) != VAR_DECL
)
10846 /* Check if the array has a nonzero lower bound. */
10847 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10848 if (!integer_zerop (lower_bound
))
10850 /* If the offset and base aren't both constants, return 0. */
10851 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10853 if (TREE_CODE (offset
) != INTEGER_CST
)
10855 /* Adjust offset by the lower bound. */
10856 offset
= size_diffop (fold_convert (sizetype
, offset
),
10857 fold_convert (sizetype
, lower_bound
));
10860 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10862 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10863 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10864 if (TREE_CODE (array
) != ADDR_EXPR
)
10866 array
= TREE_OPERAND (array
, 0);
10867 if (TREE_CODE (array
) != STRING_CST
10868 && TREE_CODE (array
) != VAR_DECL
)
10874 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10876 tree arg0
= TREE_OPERAND (arg
, 0);
10877 tree arg1
= TREE_OPERAND (arg
, 1);
10882 if (TREE_CODE (arg0
) == ADDR_EXPR
10883 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10884 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10886 array
= TREE_OPERAND (arg0
, 0);
10889 else if (TREE_CODE (arg1
) == ADDR_EXPR
10890 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10891 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10893 array
= TREE_OPERAND (arg1
, 0);
10902 if (TREE_CODE (array
) == STRING_CST
)
10904 *ptr_offset
= fold_convert (sizetype
, offset
);
10907 else if (TREE_CODE (array
) == VAR_DECL
10908 || TREE_CODE (array
) == CONST_DECL
)
10911 tree init
= ctor_for_folding (array
);
10913 /* Variables initialized to string literals can be handled too. */
10914 if (init
== error_mark_node
10916 || TREE_CODE (init
) != STRING_CST
)
10919 /* Avoid const char foo[4] = "abcde"; */
10920 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10921 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10922 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10923 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10926 /* If variable is bigger than the string literal, OFFSET must be constant
10927 and inside of the bounds of the string literal. */
10928 offset
= fold_convert (sizetype
, offset
);
10929 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10930 && (! tree_fits_uhwi_p (offset
)
10931 || compare_tree_int (offset
, length
) >= 0))
10934 *ptr_offset
= offset
;
10941 /* Generate code to calculate OPS, and exploded expression
10942 using a store-flag instruction and return an rtx for the result.
10943 OPS reflects a comparison.
10945 If TARGET is nonzero, store the result there if convenient.
10947 Return zero if there is no suitable set-flag instruction
10948 available on this machine.
10950 Once expand_expr has been called on the arguments of the comparison,
10951 we are committed to doing the store flag, since it is not safe to
10952 re-evaluate the expression. We emit the store-flag insn by calling
10953 emit_store_flag, but only expand the arguments if we have a reason
10954 to believe that emit_store_flag will be successful. If we think that
10955 it will, but it isn't, we have to simulate the store-flag with a
10956 set/jump/set sequence. */
10959 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
10961 enum rtx_code code
;
10962 tree arg0
, arg1
, type
;
10963 machine_mode operand_mode
;
10966 rtx subtarget
= target
;
10967 location_t loc
= ops
->location
;
10972 /* Don't crash if the comparison was erroneous. */
10973 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10976 type
= TREE_TYPE (arg0
);
10977 operand_mode
= TYPE_MODE (type
);
10978 unsignedp
= TYPE_UNSIGNED (type
);
10980 /* We won't bother with BLKmode store-flag operations because it would mean
10981 passing a lot of information to emit_store_flag. */
10982 if (operand_mode
== BLKmode
)
10985 /* We won't bother with store-flag operations involving function pointers
10986 when function pointers must be canonicalized before comparisons. */
10987 if (targetm
.have_canonicalize_funcptr_for_compare ()
10988 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10989 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10991 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10992 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10993 == FUNCTION_TYPE
))))
10999 /* For vector typed comparisons emit code to generate the desired
11000 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
11001 expander for this. */
11002 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
11004 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
11005 tree if_true
= constant_boolean_node (true, ops
->type
);
11006 tree if_false
= constant_boolean_node (false, ops
->type
);
11007 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
11010 /* Get the rtx comparison code to use. We know that EXP is a comparison
11011 operation of some type. Some comparisons against 1 and -1 can be
11012 converted to comparisons with zero. Do so here so that the tests
11013 below will be aware that we have a comparison with zero. These
11014 tests will not catch constants in the first operand, but constants
11015 are rarely passed as the first operand. */
11026 if (integer_onep (arg1
))
11027 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
11029 code
= unsignedp
? LTU
: LT
;
11032 if (! unsignedp
&& integer_all_onesp (arg1
))
11033 arg1
= integer_zero_node
, code
= LT
;
11035 code
= unsignedp
? LEU
: LE
;
11038 if (! unsignedp
&& integer_all_onesp (arg1
))
11039 arg1
= integer_zero_node
, code
= GE
;
11041 code
= unsignedp
? GTU
: GT
;
11044 if (integer_onep (arg1
))
11045 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
11047 code
= unsignedp
? GEU
: GE
;
11050 case UNORDERED_EXPR
:
11076 gcc_unreachable ();
11079 /* Put a constant second. */
11080 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11081 || TREE_CODE (arg0
) == FIXED_CST
)
11083 std::swap (arg0
, arg1
);
11084 code
= swap_condition (code
);
11087 /* If this is an equality or inequality test of a single bit, we can
11088 do this by shifting the bit being tested to the low-order bit and
11089 masking the result with the constant 1. If the condition was EQ,
11090 we xor it with 1. This does not require an scc insn and is faster
11091 than an scc insn even if we have it.
11093 The code to make this transformation was moved into fold_single_bit_test,
11094 so we just call into the folder and expand its result. */
11096 if ((code
== NE
|| code
== EQ
)
11097 && integer_zerop (arg1
)
11098 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11100 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11102 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11104 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11105 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11106 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11107 gimple_assign_rhs1 (srcstmt
),
11108 gimple_assign_rhs2 (srcstmt
));
11109 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11111 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11115 if (! get_subtarget (target
)
11116 || GET_MODE (subtarget
) != operand_mode
)
11119 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11122 target
= gen_reg_rtx (mode
);
11124 /* Try a cstore if possible. */
11125 return emit_store_flag_force (target
, code
, op0
, op1
,
11126 operand_mode
, unsignedp
,
11127 (TYPE_PRECISION (ops
->type
) == 1
11128 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11131 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11132 0 otherwise (i.e. if there is no casesi instruction).
11134 DEFAULT_PROBABILITY is the probability of jumping to the default
11137 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11138 rtx table_label
, rtx default_label
, rtx fallback_label
,
11139 int default_probability
)
11141 struct expand_operand ops
[5];
11142 machine_mode index_mode
= SImode
;
11143 rtx op1
, op2
, index
;
11145 if (! targetm
.have_casesi ())
11148 /* Convert the index to SImode. */
11149 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11151 machine_mode omode
= TYPE_MODE (index_type
);
11152 rtx rangertx
= expand_normal (range
);
11154 /* We must handle the endpoints in the original mode. */
11155 index_expr
= build2 (MINUS_EXPR
, index_type
,
11156 index_expr
, minval
);
11157 minval
= integer_zero_node
;
11158 index
= expand_normal (index_expr
);
11160 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11161 omode
, 1, default_label
,
11162 default_probability
);
11163 /* Now we can safely truncate. */
11164 index
= convert_to_mode (index_mode
, index
, 0);
11168 if (TYPE_MODE (index_type
) != index_mode
)
11170 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11171 index_expr
= fold_convert (index_type
, index_expr
);
11174 index
= expand_normal (index_expr
);
11177 do_pending_stack_adjust ();
11179 op1
= expand_normal (minval
);
11180 op2
= expand_normal (range
);
11182 create_input_operand (&ops
[0], index
, index_mode
);
11183 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11184 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11185 create_fixed_operand (&ops
[3], table_label
);
11186 create_fixed_operand (&ops
[4], (default_label
11188 : fallback_label
));
11189 expand_jump_insn (targetm
.code_for_casesi
, 5, ops
);
11193 /* Attempt to generate a tablejump instruction; same concept. */
11194 /* Subroutine of the next function.
11196 INDEX is the value being switched on, with the lowest value
11197 in the table already subtracted.
11198 MODE is its expected mode (needed if INDEX is constant).
11199 RANGE is the length of the jump table.
11200 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11202 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11203 index value is out of range.
11204 DEFAULT_PROBABILITY is the probability of jumping to
11205 the default label. */
11208 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
11209 rtx default_label
, int default_probability
)
11213 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11214 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11216 /* Do an unsigned comparison (in the proper mode) between the index
11217 expression and the value which represents the length of the range.
11218 Since we just finished subtracting the lower bound of the range
11219 from the index expression, this comparison allows us to simultaneously
11220 check that the original index expression value is both greater than
11221 or equal to the minimum value of the range and less than or equal to
11222 the maximum value of the range. */
11225 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11226 default_label
, default_probability
);
11229 /* If index is in range, it must fit in Pmode.
11230 Convert to Pmode so we can index with it. */
11232 index
= convert_to_mode (Pmode
, index
, 1);
11234 /* Don't let a MEM slip through, because then INDEX that comes
11235 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11236 and break_out_memory_refs will go to work on it and mess it up. */
11237 #ifdef PIC_CASE_VECTOR_ADDRESS
11238 if (flag_pic
&& !REG_P (index
))
11239 index
= copy_to_mode_reg (Pmode
, index
);
11242 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11243 GET_MODE_SIZE, because this indicates how large insns are. The other
11244 uses should all be Pmode, because they are addresses. This code
11245 could fail if addresses and insns are not the same size. */
11246 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11247 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11249 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11250 gen_rtx_LABEL_REF (Pmode
, table_label
));
11252 #ifdef PIC_CASE_VECTOR_ADDRESS
11254 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11257 index
= memory_address (CASE_VECTOR_MODE
, index
);
11258 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11259 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11260 convert_move (temp
, vector
, 0);
11262 emit_jump_insn (targetm
.gen_tablejump (temp
, table_label
));
11264 /* If we are generating PIC code or if the table is PC-relative, the
11265 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11266 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11271 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11272 rtx table_label
, rtx default_label
, int default_probability
)
11276 if (! targetm
.have_tablejump ())
11279 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11280 fold_convert (index_type
, index_expr
),
11281 fold_convert (index_type
, minval
));
11282 index
= expand_normal (index_expr
);
11283 do_pending_stack_adjust ();
11285 do_tablejump (index
, TYPE_MODE (index_type
),
11286 convert_modes (TYPE_MODE (index_type
),
11287 TYPE_MODE (TREE_TYPE (range
)),
11288 expand_normal (range
),
11289 TYPE_UNSIGNED (TREE_TYPE (range
))),
11290 table_label
, default_label
, default_probability
);
11294 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11296 const_vector_from_tree (tree exp
)
11302 machine_mode inner
, mode
;
11304 mode
= TYPE_MODE (TREE_TYPE (exp
));
11306 if (initializer_zerop (exp
))
11307 return CONST0_RTX (mode
);
11309 units
= GET_MODE_NUNITS (mode
);
11310 inner
= GET_MODE_INNER (mode
);
11312 v
= rtvec_alloc (units
);
11314 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11316 elt
= VECTOR_CST_ELT (exp
, i
);
11318 if (TREE_CODE (elt
) == REAL_CST
)
11319 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11321 else if (TREE_CODE (elt
) == FIXED_CST
)
11322 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11325 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11328 return gen_rtx_CONST_VECTOR (mode
, v
);
11331 /* Build a decl for a personality function given a language prefix. */
11334 build_personality_function (const char *lang
)
11336 const char *unwind_and_version
;
11340 switch (targetm_common
.except_unwind_info (&global_options
))
11345 unwind_and_version
= "_sj0";
11349 unwind_and_version
= "_v0";
11352 unwind_and_version
= "_seh0";
11355 gcc_unreachable ();
11358 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11360 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11361 long_long_unsigned_type_node
,
11362 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11363 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11364 get_identifier (name
), type
);
11365 DECL_ARTIFICIAL (decl
) = 1;
11366 DECL_EXTERNAL (decl
) = 1;
11367 TREE_PUBLIC (decl
) = 1;
11369 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11370 are the flags assigned by targetm.encode_section_info. */
11371 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11376 /* Extracts the personality function of DECL and returns the corresponding
11380 get_personality_function (tree decl
)
11382 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11383 enum eh_personality_kind pk
;
11385 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11386 if (pk
== eh_personality_none
)
11390 && pk
== eh_personality_any
)
11391 personality
= lang_hooks
.eh_personality ();
11393 if (pk
== eh_personality_lang
)
11394 gcc_assert (personality
!= NULL_TREE
);
11396 return XEXP (DECL_RTL (personality
), 0);
11399 /* Returns a tree for the size of EXP in bytes. */
11402 tree_expr_size (const_tree exp
)
11405 && DECL_SIZE_UNIT (exp
) != 0)
11406 return DECL_SIZE_UNIT (exp
);
11408 return size_in_bytes (TREE_TYPE (exp
));
11411 /* Return an rtx for the size in bytes of the value of EXP. */
11414 expr_size (tree exp
)
11418 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11419 size
= TREE_OPERAND (exp
, 1);
11422 size
= tree_expr_size (exp
);
11424 gcc_assert (size
== SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, exp
));
11427 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), EXPAND_NORMAL
);
11430 /* Return a wide integer for the size in bytes of the value of EXP, or -1
11431 if the size can vary or is larger than an integer. */
11433 static HOST_WIDE_INT
11434 int_expr_size (tree exp
)
11438 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11439 size
= TREE_OPERAND (exp
, 1);
11442 size
= tree_expr_size (exp
);
11446 if (size
== 0 || !tree_fits_shwi_p (size
))
11449 return tree_to_shwi (size
);
11452 #include "gt-expr.h"