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"
28 #include "fold-const.h"
29 #include "stringpool.h"
30 #include "stor-layout.h"
35 #include "hard-reg-set.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"
60 #include "dominance.h"
62 #include "basic-block.h"
63 #include "tree-ssa-alias.h"
64 #include "internal-fn.h"
65 #include "gimple-expr.h"
67 #include "gimple-ssa.h"
69 #include "tree-ssanames.h"
71 #include "common/common-target.h"
74 #include "diagnostic.h"
75 #include "tree-ssa-live.h"
76 #include "tree-outof-ssa.h"
77 #include "target-globals.h"
79 #include "tree-ssa-address.h"
80 #include "cfgexpand.h"
82 #include "tree-chkp.h"
87 /* If this is nonzero, we do not bother generating VOLATILE
88 around volatile memory references, and we are willing to
89 output indirect addresses. If cse is to follow, we reject
90 indirect addresses so a useful potential cse is generated;
91 if it is used only once, instruction combination will produce
92 the same indirect address eventually. */
95 /* This structure is used by move_by_pieces to describe the move to
97 struct move_by_pieces_d
106 int explicit_inc_from
;
107 unsigned HOST_WIDE_INT len
;
108 HOST_WIDE_INT offset
;
112 /* This structure is used by store_by_pieces to describe the clear to
115 struct store_by_pieces_d
121 unsigned HOST_WIDE_INT len
;
122 HOST_WIDE_INT offset
;
123 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
);
128 static void move_by_pieces_1 (insn_gen_fn
, machine_mode
,
129 struct move_by_pieces_d
*);
130 static bool block_move_libcall_safe_for_call_parm (void);
131 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
132 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
133 unsigned HOST_WIDE_INT
);
134 static tree
emit_block_move_libcall_fn (int);
135 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
136 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, machine_mode
);
137 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
138 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
139 static void store_by_pieces_2 (insn_gen_fn
, machine_mode
,
140 struct store_by_pieces_d
*);
141 static tree
clear_storage_libcall_fn (int);
142 static rtx_insn
*compress_float_constant (rtx
, rtx
);
143 static rtx
get_subtarget (rtx
);
144 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
145 HOST_WIDE_INT
, machine_mode
,
146 tree
, int, alias_set_type
);
147 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
148 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
149 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
150 machine_mode
, tree
, alias_set_type
, bool);
152 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
154 static int is_aligning_offset (const_tree
, const_tree
);
155 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
156 static rtx
do_store_flag (sepops
, rtx
, machine_mode
);
158 static void emit_single_push_insn (machine_mode
, rtx
, tree
);
160 static void do_tablejump (rtx
, machine_mode
, rtx
, rtx
, rtx
, int);
161 static rtx
const_vector_from_tree (tree
);
162 static tree
tree_expr_size (const_tree
);
163 static HOST_WIDE_INT
int_expr_size (tree
);
166 /* This is run to set up which modes can be used
167 directly in memory and to initialize the block move optab. It is run
168 at the beginning of compilation and when the target is reinitialized. */
171 init_expr_target (void)
179 /* Try indexing by frame ptr and try by stack ptr.
180 It is known that on the Convex the stack ptr isn't a valid index.
181 With luck, one or the other is valid on any machine. */
182 mem
= gen_rtx_MEM (word_mode
, stack_pointer_rtx
);
183 mem1
= gen_rtx_MEM (word_mode
, frame_pointer_rtx
);
185 /* A scratch register we can modify in-place below to avoid
186 useless RTL allocations. */
187 reg
= gen_rtx_REG (word_mode
, LAST_VIRTUAL_REGISTER
+ 1);
189 insn
= rtx_alloc (INSN
);
190 pat
= gen_rtx_SET (NULL_RTX
, NULL_RTX
);
191 PATTERN (insn
) = pat
;
193 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
194 mode
= (machine_mode
) ((int) mode
+ 1))
198 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
199 PUT_MODE (mem
, mode
);
200 PUT_MODE (mem1
, mode
);
202 /* See if there is some register that can be used in this mode and
203 directly loaded or stored from memory. */
205 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
206 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
207 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
210 if (! HARD_REGNO_MODE_OK (regno
, mode
))
213 set_mode_and_regno (reg
, mode
, regno
);
216 SET_DEST (pat
) = reg
;
217 if (recog (pat
, insn
, &num_clobbers
) >= 0)
218 direct_load
[(int) mode
] = 1;
220 SET_SRC (pat
) = mem1
;
221 SET_DEST (pat
) = reg
;
222 if (recog (pat
, insn
, &num_clobbers
) >= 0)
223 direct_load
[(int) mode
] = 1;
226 SET_DEST (pat
) = mem
;
227 if (recog (pat
, insn
, &num_clobbers
) >= 0)
228 direct_store
[(int) mode
] = 1;
231 SET_DEST (pat
) = mem1
;
232 if (recog (pat
, insn
, &num_clobbers
) >= 0)
233 direct_store
[(int) mode
] = 1;
237 mem
= gen_rtx_MEM (VOIDmode
, gen_raw_REG (Pmode
, LAST_VIRTUAL_REGISTER
+ 1));
239 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
240 mode
= GET_MODE_WIDER_MODE (mode
))
242 machine_mode srcmode
;
243 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
244 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
248 ic
= can_extend_p (mode
, srcmode
, 0);
249 if (ic
== CODE_FOR_nothing
)
252 PUT_MODE (mem
, srcmode
);
254 if (insn_operand_matches (ic
, 1, mem
))
255 float_extend_from_mem
[mode
][srcmode
] = true;
260 /* This is run at the start of compiling a function. */
265 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
268 /* Copy data from FROM to TO, where the machine modes are not the same.
269 Both modes may be integer, or both may be floating, or both may be
271 UNSIGNEDP should be nonzero if FROM is an unsigned type.
272 This causes zero-extension instead of sign-extension. */
275 convert_move (rtx to
, rtx from
, int unsignedp
)
277 machine_mode to_mode
= GET_MODE (to
);
278 machine_mode from_mode
= GET_MODE (from
);
279 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
280 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
284 /* rtx code for making an equivalent value. */
285 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
286 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
289 gcc_assert (to_real
== from_real
);
290 gcc_assert (to_mode
!= BLKmode
);
291 gcc_assert (from_mode
!= BLKmode
);
293 /* If the source and destination are already the same, then there's
298 /* If FROM is a SUBREG that indicates that we have already done at least
299 the required extension, strip it. We don't handle such SUBREGs as
302 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
303 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
304 >= GET_MODE_PRECISION (to_mode
))
305 && SUBREG_CHECK_PROMOTED_SIGN (from
, unsignedp
))
306 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
308 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
310 if (to_mode
== from_mode
311 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
313 emit_move_insn (to
, from
);
317 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
319 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
321 if (VECTOR_MODE_P (to_mode
))
322 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
324 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
326 emit_move_insn (to
, from
);
330 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
332 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
333 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
343 gcc_assert ((GET_MODE_PRECISION (from_mode
)
344 != GET_MODE_PRECISION (to_mode
))
345 || (DECIMAL_FLOAT_MODE_P (from_mode
)
346 != DECIMAL_FLOAT_MODE_P (to_mode
)));
348 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
349 /* Conversion between decimal float and binary float, same size. */
350 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
351 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
356 /* Try converting directly if the insn is supported. */
358 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
359 if (code
!= CODE_FOR_nothing
)
361 emit_unop_insn (code
, to
, from
,
362 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
366 /* Otherwise use a libcall. */
367 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
369 /* Is this conversion implemented yet? */
370 gcc_assert (libcall
);
373 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
375 insns
= get_insns ();
377 emit_libcall_block (insns
, to
, value
,
378 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
380 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
384 /* Handle pointer conversion. */ /* SPEE 900220. */
385 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
389 if (GET_MODE_PRECISION (from_mode
) > GET_MODE_PRECISION (to_mode
))
396 if (convert_optab_handler (ctab
, to_mode
, from_mode
)
399 emit_unop_insn (convert_optab_handler (ctab
, to_mode
, from_mode
),
405 /* Targets are expected to provide conversion insns between PxImode and
406 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
407 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
409 machine_mode full_mode
410 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
412 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
413 != CODE_FOR_nothing
);
415 if (full_mode
!= from_mode
)
416 from
= convert_to_mode (full_mode
, from
, unsignedp
);
417 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
421 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
424 machine_mode full_mode
425 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
426 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
427 enum insn_code icode
;
429 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
430 gcc_assert (icode
!= CODE_FOR_nothing
);
432 if (to_mode
== full_mode
)
434 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
438 new_from
= gen_reg_rtx (full_mode
);
439 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
441 /* else proceed to integer conversions below. */
442 from_mode
= full_mode
;
446 /* Make sure both are fixed-point modes or both are not. */
447 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
448 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
449 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
451 /* If we widen from_mode to to_mode and they are in the same class,
452 we won't saturate the result.
453 Otherwise, always saturate the result to play safe. */
454 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
455 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
456 expand_fixed_convert (to
, from
, 0, 0);
458 expand_fixed_convert (to
, from
, 0, 1);
462 /* Now both modes are integers. */
464 /* Handle expanding beyond a word. */
465 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
466 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
473 machine_mode lowpart_mode
;
474 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
476 /* Try converting directly if the insn is supported. */
477 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
480 /* If FROM is a SUBREG, put it into a register. Do this
481 so that we always generate the same set of insns for
482 better cse'ing; if an intermediate assignment occurred,
483 we won't be doing the operation directly on the SUBREG. */
484 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
485 from
= force_reg (from_mode
, from
);
486 emit_unop_insn (code
, to
, from
, equiv_code
);
489 /* Next, try converting via full word. */
490 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
491 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
492 != CODE_FOR_nothing
))
494 rtx word_to
= gen_reg_rtx (word_mode
);
497 if (reg_overlap_mentioned_p (to
, from
))
498 from
= force_reg (from_mode
, from
);
501 convert_move (word_to
, from
, unsignedp
);
502 emit_unop_insn (code
, to
, word_to
, equiv_code
);
506 /* No special multiword conversion insn; do it by hand. */
509 /* Since we will turn this into a no conflict block, we must ensure the
510 the source does not overlap the target so force it into an isolated
511 register when maybe so. Likewise for any MEM input, since the
512 conversion sequence might require several references to it and we
513 must ensure we're getting the same value every time. */
515 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
516 from
= force_reg (from_mode
, from
);
518 /* Get a copy of FROM widened to a word, if necessary. */
519 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
520 lowpart_mode
= word_mode
;
522 lowpart_mode
= from_mode
;
524 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
526 lowpart
= gen_lowpart (lowpart_mode
, to
);
527 emit_move_insn (lowpart
, lowfrom
);
529 /* Compute the value to put in each remaining word. */
531 fill_value
= const0_rtx
;
533 fill_value
= emit_store_flag_force (gen_reg_rtx (word_mode
),
534 LT
, lowfrom
, const0_rtx
,
535 lowpart_mode
, 0, -1);
537 /* Fill the remaining words. */
538 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
540 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
541 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
543 gcc_assert (subword
);
545 if (fill_value
!= subword
)
546 emit_move_insn (subword
, fill_value
);
549 insns
= get_insns ();
556 /* Truncating multi-word to a word or less. */
557 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
558 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
561 && ! MEM_VOLATILE_P (from
)
562 && direct_load
[(int) to_mode
]
563 && ! mode_dependent_address_p (XEXP (from
, 0),
564 MEM_ADDR_SPACE (from
)))
566 || GET_CODE (from
) == SUBREG
))
567 from
= force_reg (from_mode
, from
);
568 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
572 /* Now follow all the conversions between integers
573 no more than a word long. */
575 /* For truncation, usually we can just refer to FROM in a narrower mode. */
576 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
577 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
580 && ! MEM_VOLATILE_P (from
)
581 && direct_load
[(int) to_mode
]
582 && ! mode_dependent_address_p (XEXP (from
, 0),
583 MEM_ADDR_SPACE (from
)))
585 || GET_CODE (from
) == SUBREG
))
586 from
= force_reg (from_mode
, from
);
587 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
588 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
589 from
= copy_to_reg (from
);
590 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
594 /* Handle extension. */
595 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
597 /* Convert directly if that works. */
598 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
601 emit_unop_insn (code
, to
, from
, equiv_code
);
606 machine_mode intermediate
;
610 /* Search for a mode to convert via. */
611 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
612 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
613 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
615 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
616 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
617 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
618 != CODE_FOR_nothing
))
620 convert_move (to
, convert_to_mode (intermediate
, from
,
621 unsignedp
), unsignedp
);
625 /* No suitable intermediate mode.
626 Generate what we need with shifts. */
627 shift_amount
= (GET_MODE_PRECISION (to_mode
)
628 - GET_MODE_PRECISION (from_mode
));
629 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
630 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
632 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
635 emit_move_insn (to
, tmp
);
640 /* Support special truncate insns for certain modes. */
641 if (convert_optab_handler (trunc_optab
, to_mode
,
642 from_mode
) != CODE_FOR_nothing
)
644 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
649 /* Handle truncation of volatile memrefs, and so on;
650 the things that couldn't be truncated directly,
651 and for which there was no special instruction.
653 ??? Code above formerly short-circuited this, for most integer
654 mode pairs, with a force_reg in from_mode followed by a recursive
655 call to this routine. Appears always to have been wrong. */
656 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
658 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
659 emit_move_insn (to
, temp
);
663 /* Mode combination is not recognized. */
667 /* Return an rtx for a value that would result
668 from converting X to mode MODE.
669 Both X and MODE may be floating, or both integer.
670 UNSIGNEDP is nonzero if X is an unsigned value.
671 This can be done by referring to a part of X in place
672 or by copying to a new temporary with conversion. */
675 convert_to_mode (machine_mode mode
, rtx x
, int unsignedp
)
677 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
680 /* Return an rtx for a value that would result
681 from converting X from mode OLDMODE to mode MODE.
682 Both modes may be floating, or both integer.
683 UNSIGNEDP is nonzero if X is an unsigned value.
685 This can be done by referring to a part of X in place
686 or by copying to a new temporary with conversion.
688 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
691 convert_modes (machine_mode mode
, machine_mode oldmode
, rtx x
, int unsignedp
)
695 /* If FROM is a SUBREG that indicates that we have already done at least
696 the required extension, strip it. */
698 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
699 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
700 && SUBREG_CHECK_PROMOTED_SIGN (x
, unsignedp
))
701 x
= gen_lowpart (mode
, SUBREG_REG (x
));
703 if (GET_MODE (x
) != VOIDmode
)
704 oldmode
= GET_MODE (x
);
709 if (CONST_SCALAR_INT_P (x
) && GET_MODE_CLASS (mode
) == MODE_INT
)
711 /* If the caller did not tell us the old mode, then there is not
712 much to do with respect to canonicalization. We have to
713 assume that all the bits are significant. */
714 if (GET_MODE_CLASS (oldmode
) != MODE_INT
)
715 oldmode
= MAX_MODE_INT
;
716 wide_int w
= wide_int::from (std::make_pair (x
, oldmode
),
717 GET_MODE_PRECISION (mode
),
718 unsignedp
? UNSIGNED
: SIGNED
);
719 return immed_wide_int_const (w
, mode
);
722 /* We can do this with a gen_lowpart if both desired and current modes
723 are integer, and this is either a constant integer, a register, or a
725 if (GET_MODE_CLASS (mode
) == MODE_INT
726 && GET_MODE_CLASS (oldmode
) == MODE_INT
727 && GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
728 && ((MEM_P (x
) && !MEM_VOLATILE_P (x
) && direct_load
[(int) mode
])
730 && (!HARD_REGISTER_P (x
)
731 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
732 && TRULY_NOOP_TRUNCATION_MODES_P (mode
, GET_MODE (x
)))))
734 return gen_lowpart (mode
, x
);
736 /* Converting from integer constant into mode is always equivalent to an
738 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
740 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
741 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
744 temp
= gen_reg_rtx (mode
);
745 convert_move (temp
, x
, unsignedp
);
749 /* Return the largest alignment we can use for doing a move (or store)
750 of MAX_PIECES. ALIGN is the largest alignment we could use. */
753 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
757 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
758 if (align
>= GET_MODE_ALIGNMENT (tmode
))
759 align
= GET_MODE_ALIGNMENT (tmode
);
762 machine_mode tmode
, xmode
;
764 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
766 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
767 if (GET_MODE_SIZE (tmode
) > max_pieces
768 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
771 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
777 /* Return the widest integer mode no wider than SIZE. If no such mode
778 can be found, return VOIDmode. */
781 widest_int_mode_for_size (unsigned int size
)
783 machine_mode tmode
, mode
= VOIDmode
;
785 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
786 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
787 if (GET_MODE_SIZE (tmode
) < size
)
793 /* Determine whether the LEN bytes can be moved by using several move
794 instructions. Return nonzero if a call to move_by_pieces should
798 can_move_by_pieces (unsigned HOST_WIDE_INT len
,
801 return targetm
.use_by_pieces_infrastructure_p (len
, align
, MOVE_BY_PIECES
,
802 optimize_insn_for_speed_p ());
805 /* Generate several move instructions to copy LEN bytes from block FROM to
806 block TO. (These are MEM rtx's with BLKmode).
808 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
809 used to push FROM to the stack.
811 ALIGN is maximum stack alignment we can assume.
813 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
814 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
818 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
819 unsigned int align
, int endp
)
821 struct move_by_pieces_d data
;
822 machine_mode to_addr_mode
;
823 machine_mode from_addr_mode
= get_address_mode (from
);
824 rtx to_addr
, from_addr
= XEXP (from
, 0);
825 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
826 enum insn_code icode
;
828 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
831 data
.from_addr
= from_addr
;
834 to_addr_mode
= get_address_mode (to
);
835 to_addr
= XEXP (to
, 0);
838 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
839 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
841 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
845 to_addr_mode
= VOIDmode
;
849 if (STACK_GROWS_DOWNWARD
)
854 data
.to_addr
= to_addr
;
857 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
858 || GET_CODE (from_addr
) == POST_INC
859 || GET_CODE (from_addr
) == POST_DEC
);
861 data
.explicit_inc_from
= 0;
862 data
.explicit_inc_to
= 0;
863 if (data
.reverse
) data
.offset
= len
;
866 /* If copying requires more than two move insns,
867 copy addresses to registers (to make displacements shorter)
868 and use post-increment if available. */
869 if (!(data
.autinc_from
&& data
.autinc_to
)
870 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
872 /* Find the mode of the largest move...
873 MODE might not be used depending on the definitions of the
874 USE_* macros below. */
875 machine_mode mode ATTRIBUTE_UNUSED
876 = widest_int_mode_for_size (max_size
);
878 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
880 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
881 plus_constant (from_addr_mode
,
883 data
.autinc_from
= 1;
884 data
.explicit_inc_from
= -1;
886 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
888 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
889 data
.autinc_from
= 1;
890 data
.explicit_inc_from
= 1;
892 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
893 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
894 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
896 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
897 plus_constant (to_addr_mode
,
900 data
.explicit_inc_to
= -1;
902 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
904 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
906 data
.explicit_inc_to
= 1;
908 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
909 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
912 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
914 /* First move what we can in the largest integer mode, then go to
915 successively smaller modes. */
917 while (max_size
> 1 && data
.len
> 0)
919 machine_mode mode
= widest_int_mode_for_size (max_size
);
921 if (mode
== VOIDmode
)
924 icode
= optab_handler (mov_optab
, mode
);
925 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
926 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
928 max_size
= GET_MODE_SIZE (mode
);
931 /* The code above should have handled everything. */
932 gcc_assert (!data
.len
);
938 gcc_assert (!data
.reverse
);
943 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
944 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
946 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
947 plus_constant (to_addr_mode
,
951 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
958 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
966 /* Return number of insns required to move L bytes by pieces.
967 ALIGN (in bits) is maximum alignment we can assume. */
969 unsigned HOST_WIDE_INT
970 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
971 unsigned int max_size
)
973 unsigned HOST_WIDE_INT n_insns
= 0;
975 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
977 while (max_size
> 1 && l
> 0)
980 enum insn_code icode
;
982 mode
= widest_int_mode_for_size (max_size
);
984 if (mode
== VOIDmode
)
987 icode
= optab_handler (mov_optab
, mode
);
988 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
989 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
991 max_size
= GET_MODE_SIZE (mode
);
998 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
999 with move instructions for mode MODE. GENFUN is the gen_... function
1000 to make a move insn for that mode. DATA has all the other info. */
1003 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
1004 struct move_by_pieces_d
*data
)
1006 unsigned int size
= GET_MODE_SIZE (mode
);
1007 rtx to1
= NULL_RTX
, from1
;
1009 while (data
->len
>= size
)
1012 data
->offset
-= size
;
1016 if (data
->autinc_to
)
1017 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1020 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1023 if (data
->autinc_from
)
1024 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1027 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1029 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1030 emit_insn (gen_add2_insn (data
->to_addr
,
1031 gen_int_mode (-(HOST_WIDE_INT
) size
,
1032 GET_MODE (data
->to_addr
))));
1033 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1034 emit_insn (gen_add2_insn (data
->from_addr
,
1035 gen_int_mode (-(HOST_WIDE_INT
) size
,
1036 GET_MODE (data
->from_addr
))));
1039 emit_insn ((*genfun
) (to1
, from1
));
1042 #ifdef PUSH_ROUNDING
1043 emit_single_push_insn (mode
, from1
, NULL
);
1049 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1050 emit_insn (gen_add2_insn (data
->to_addr
,
1052 GET_MODE (data
->to_addr
))));
1053 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1054 emit_insn (gen_add2_insn (data
->from_addr
,
1056 GET_MODE (data
->from_addr
))));
1058 if (! data
->reverse
)
1059 data
->offset
+= size
;
1065 /* Emit code to move a block Y to a block X. This may be done with
1066 string-move instructions, with multiple scalar move instructions,
1067 or with a library call.
1069 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1070 SIZE is an rtx that says how long they are.
1071 ALIGN is the maximum alignment we can assume they have.
1072 METHOD describes what kind of copy this is, and what mechanisms may be used.
1073 MIN_SIZE is the minimal size of block to move
1074 MAX_SIZE is the maximal size of block to move, if it can not be represented
1075 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1077 Return the address of the new block, if memcpy is called and returns it,
1081 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1082 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1083 unsigned HOST_WIDE_INT min_size
,
1084 unsigned HOST_WIDE_INT max_size
,
1085 unsigned HOST_WIDE_INT probable_max_size
)
1092 if (CONST_INT_P (size
)
1093 && INTVAL (size
) == 0)
1098 case BLOCK_OP_NORMAL
:
1099 case BLOCK_OP_TAILCALL
:
1100 may_use_call
= true;
1103 case BLOCK_OP_CALL_PARM
:
1104 may_use_call
= block_move_libcall_safe_for_call_parm ();
1106 /* Make inhibit_defer_pop nonzero around the library call
1107 to force it to pop the arguments right away. */
1111 case BLOCK_OP_NO_LIBCALL
:
1112 may_use_call
= false;
1119 gcc_assert (MEM_P (x
) && MEM_P (y
));
1120 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1121 gcc_assert (align
>= BITS_PER_UNIT
);
1123 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1124 block copy is more efficient for other large modes, e.g. DCmode. */
1125 x
= adjust_address (x
, BLKmode
, 0);
1126 y
= adjust_address (y
, BLKmode
, 0);
1128 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1129 can be incorrect is coming from __builtin_memcpy. */
1130 if (CONST_INT_P (size
))
1132 x
= shallow_copy_rtx (x
);
1133 y
= shallow_copy_rtx (y
);
1134 set_mem_size (x
, INTVAL (size
));
1135 set_mem_size (y
, INTVAL (size
));
1138 if (CONST_INT_P (size
) && can_move_by_pieces (INTVAL (size
), align
))
1139 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1140 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1141 expected_align
, expected_size
,
1142 min_size
, max_size
, probable_max_size
))
1144 else if (may_use_call
1145 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1146 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1148 /* Since x and y are passed to a libcall, mark the corresponding
1149 tree EXPR as addressable. */
1150 tree y_expr
= MEM_EXPR (y
);
1151 tree x_expr
= MEM_EXPR (x
);
1153 mark_addressable (y_expr
);
1155 mark_addressable (x_expr
);
1156 retval
= emit_block_move_via_libcall (x
, y
, size
,
1157 method
== BLOCK_OP_TAILCALL
);
1161 emit_block_move_via_loop (x
, y
, size
, align
);
1163 if (method
== BLOCK_OP_CALL_PARM
)
1170 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1172 unsigned HOST_WIDE_INT max
, min
= 0;
1173 if (GET_CODE (size
) == CONST_INT
)
1174 min
= max
= UINTVAL (size
);
1176 max
= GET_MODE_MASK (GET_MODE (size
));
1177 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1181 /* A subroutine of emit_block_move. Returns true if calling the
1182 block move libcall will not clobber any parameters which may have
1183 already been placed on the stack. */
1186 block_move_libcall_safe_for_call_parm (void)
1188 #if defined (REG_PARM_STACK_SPACE)
1192 /* If arguments are pushed on the stack, then they're safe. */
1196 /* If registers go on the stack anyway, any argument is sure to clobber
1197 an outgoing argument. */
1198 #if defined (REG_PARM_STACK_SPACE)
1199 fn
= emit_block_move_libcall_fn (false);
1200 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1201 depend on its argument. */
1203 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1204 && REG_PARM_STACK_SPACE (fn
) != 0)
1208 /* If any argument goes in memory, then it might clobber an outgoing
1211 CUMULATIVE_ARGS args_so_far_v
;
1212 cumulative_args_t args_so_far
;
1215 fn
= emit_block_move_libcall_fn (false);
1216 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1217 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1219 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1220 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1222 machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1223 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1225 if (!tmp
|| !REG_P (tmp
))
1227 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1229 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1236 /* A subroutine of emit_block_move. Expand a movmem pattern;
1237 return true if successful. */
1240 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1241 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1242 unsigned HOST_WIDE_INT min_size
,
1243 unsigned HOST_WIDE_INT max_size
,
1244 unsigned HOST_WIDE_INT probable_max_size
)
1246 int save_volatile_ok
= volatile_ok
;
1249 if (expected_align
< align
)
1250 expected_align
= align
;
1251 if (expected_size
!= -1)
1253 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1254 expected_size
= probable_max_size
;
1255 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1256 expected_size
= min_size
;
1259 /* Since this is a move insn, we don't care about volatility. */
1262 /* Try the most limited insn first, because there's no point
1263 including more than one in the machine description unless
1264 the more limited one has some advantage. */
1266 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1267 mode
= GET_MODE_WIDER_MODE (mode
))
1269 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1271 if (code
!= CODE_FOR_nothing
1272 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1273 here because if SIZE is less than the mode mask, as it is
1274 returned by the macro, it will definitely be less than the
1275 actual mode mask. Since SIZE is within the Pmode address
1276 space, we limit MODE to Pmode. */
1277 && ((CONST_INT_P (size
)
1278 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1279 <= (GET_MODE_MASK (mode
) >> 1)))
1280 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1281 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1283 struct expand_operand ops
[9];
1286 /* ??? When called via emit_block_move_for_call, it'd be
1287 nice if there were some way to inform the backend, so
1288 that it doesn't fail the expansion because it thinks
1289 emitting the libcall would be more efficient. */
1290 nops
= insn_data
[(int) code
].n_generator_args
;
1291 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1293 create_fixed_operand (&ops
[0], x
);
1294 create_fixed_operand (&ops
[1], y
);
1295 /* The check above guarantees that this size conversion is valid. */
1296 create_convert_operand_to (&ops
[2], size
, mode
, true);
1297 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1300 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1301 create_integer_operand (&ops
[5], expected_size
);
1305 create_integer_operand (&ops
[6], min_size
);
1306 /* If we can not represent the maximal size,
1307 make parameter NULL. */
1308 if ((HOST_WIDE_INT
) max_size
!= -1)
1309 create_integer_operand (&ops
[7], max_size
);
1311 create_fixed_operand (&ops
[7], NULL
);
1315 /* If we can not represent the maximal size,
1316 make parameter NULL. */
1317 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1318 create_integer_operand (&ops
[8], probable_max_size
);
1320 create_fixed_operand (&ops
[8], NULL
);
1322 if (maybe_expand_insn (code
, nops
, ops
))
1324 volatile_ok
= save_volatile_ok
;
1330 volatile_ok
= save_volatile_ok
;
1334 /* A subroutine of emit_block_move. Expand a call to memcpy.
1335 Return the return value from memcpy, 0 otherwise. */
1338 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1340 rtx dst_addr
, src_addr
;
1341 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1342 machine_mode size_mode
;
1345 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1346 pseudos. We can then place those new pseudos into a VAR_DECL and
1349 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1350 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1352 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1353 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1355 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1356 src_tree
= make_tree (ptr_type_node
, src_addr
);
1358 size_mode
= TYPE_MODE (sizetype
);
1360 size
= convert_to_mode (size_mode
, size
, 1);
1361 size
= copy_to_mode_reg (size_mode
, size
);
1363 /* It is incorrect to use the libcall calling conventions to call
1364 memcpy in this context. This could be a user call to memcpy and
1365 the user may wish to examine the return value from memcpy. For
1366 targets where libcalls and normal calls have different conventions
1367 for returning pointers, we could end up generating incorrect code. */
1369 size_tree
= make_tree (sizetype
, size
);
1371 fn
= emit_block_move_libcall_fn (true);
1372 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1373 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1375 retval
= expand_normal (call_expr
);
1380 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1381 for the function we use for block copies. */
1383 static GTY(()) tree block_move_fn
;
1386 init_block_move_fn (const char *asmspec
)
1390 tree args
, fn
, attrs
, attr_args
;
1392 fn
= get_identifier ("memcpy");
1393 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1394 const_ptr_type_node
, sizetype
,
1397 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1398 DECL_EXTERNAL (fn
) = 1;
1399 TREE_PUBLIC (fn
) = 1;
1400 DECL_ARTIFICIAL (fn
) = 1;
1401 TREE_NOTHROW (fn
) = 1;
1402 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1403 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1405 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1406 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1408 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1414 set_user_assembler_name (block_move_fn
, asmspec
);
1418 emit_block_move_libcall_fn (int for_call
)
1420 static bool emitted_extern
;
1423 init_block_move_fn (NULL
);
1425 if (for_call
&& !emitted_extern
)
1427 emitted_extern
= true;
1428 make_decl_rtl (block_move_fn
);
1431 return block_move_fn
;
1434 /* A subroutine of emit_block_move. Copy the data via an explicit
1435 loop. This is used only when libcalls are forbidden. */
1436 /* ??? It'd be nice to copy in hunks larger than QImode. */
1439 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1440 unsigned int align ATTRIBUTE_UNUSED
)
1442 rtx_code_label
*cmp_label
, *top_label
;
1443 rtx iter
, x_addr
, y_addr
, tmp
;
1444 machine_mode x_addr_mode
= get_address_mode (x
);
1445 machine_mode y_addr_mode
= get_address_mode (y
);
1446 machine_mode iter_mode
;
1448 iter_mode
= GET_MODE (size
);
1449 if (iter_mode
== VOIDmode
)
1450 iter_mode
= word_mode
;
1452 top_label
= gen_label_rtx ();
1453 cmp_label
= gen_label_rtx ();
1454 iter
= gen_reg_rtx (iter_mode
);
1456 emit_move_insn (iter
, const0_rtx
);
1458 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1459 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1460 do_pending_stack_adjust ();
1462 emit_jump (cmp_label
);
1463 emit_label (top_label
);
1465 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1466 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1468 if (x_addr_mode
!= y_addr_mode
)
1469 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1470 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1472 x
= change_address (x
, QImode
, x_addr
);
1473 y
= change_address (y
, QImode
, y_addr
);
1475 emit_move_insn (x
, y
);
1477 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1478 true, OPTAB_LIB_WIDEN
);
1480 emit_move_insn (iter
, tmp
);
1482 emit_label (cmp_label
);
1484 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1485 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1488 /* Copy all or part of a value X into registers starting at REGNO.
1489 The number of registers to be filled is NREGS. */
1492 move_block_to_reg (int regno
, rtx x
, int nregs
, machine_mode mode
)
1497 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1498 x
= validize_mem (force_const_mem (mode
, x
));
1500 /* See if the machine can do this with a load multiple insn. */
1501 if (targetm
.have_load_multiple ())
1503 rtx_insn
*last
= get_last_insn ();
1504 rtx first
= gen_rtx_REG (word_mode
, regno
);
1505 if (rtx_insn
*pat
= targetm
.gen_load_multiple (first
, x
,
1512 delete_insns_since (last
);
1515 for (int i
= 0; i
< nregs
; i
++)
1516 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1517 operand_subword_force (x
, i
, mode
));
1520 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1521 The number of registers to be filled is NREGS. */
1524 move_block_from_reg (int regno
, rtx x
, int nregs
)
1529 /* See if the machine can do this with a store multiple insn. */
1530 if (targetm
.have_store_multiple ())
1532 rtx_insn
*last
= get_last_insn ();
1533 rtx first
= gen_rtx_REG (word_mode
, regno
);
1534 if (rtx_insn
*pat
= targetm
.gen_store_multiple (x
, first
,
1541 delete_insns_since (last
);
1544 for (int i
= 0; i
< nregs
; i
++)
1546 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1550 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1554 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1555 ORIG, where ORIG is a non-consecutive group of registers represented by
1556 a PARALLEL. The clone is identical to the original except in that the
1557 original set of registers is replaced by a new set of pseudo registers.
1558 The new set has the same modes as the original set. */
1561 gen_group_rtx (rtx orig
)
1566 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1568 length
= XVECLEN (orig
, 0);
1569 tmps
= XALLOCAVEC (rtx
, length
);
1571 /* Skip a NULL entry in first slot. */
1572 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1577 for (; i
< length
; i
++)
1579 machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1580 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1582 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1585 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1588 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1589 except that values are placed in TMPS[i], and must later be moved
1590 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1593 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1597 machine_mode m
= GET_MODE (orig_src
);
1599 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1602 && !SCALAR_INT_MODE_P (m
)
1603 && !MEM_P (orig_src
)
1604 && GET_CODE (orig_src
) != CONCAT
)
1606 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1607 if (imode
== BLKmode
)
1608 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1610 src
= gen_reg_rtx (imode
);
1611 if (imode
!= BLKmode
)
1612 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1613 emit_move_insn (src
, orig_src
);
1614 /* ...and back again. */
1615 if (imode
!= BLKmode
)
1616 src
= gen_lowpart (imode
, src
);
1617 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1621 /* Check for a NULL entry, used to indicate that the parameter goes
1622 both on the stack and in registers. */
1623 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1628 /* Process the pieces. */
1629 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1631 machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1632 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1633 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1636 /* Handle trailing fragments that run over the size of the struct. */
1637 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1639 /* Arrange to shift the fragment to where it belongs.
1640 extract_bit_field loads to the lsb of the reg. */
1642 #ifdef BLOCK_REG_PADDING
1643 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1644 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1649 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1650 bytelen
= ssize
- bytepos
;
1651 gcc_assert (bytelen
> 0);
1654 /* If we won't be loading directly from memory, protect the real source
1655 from strange tricks we might play; but make sure that the source can
1656 be loaded directly into the destination. */
1658 if (!MEM_P (orig_src
)
1659 && (!CONSTANT_P (orig_src
)
1660 || (GET_MODE (orig_src
) != mode
1661 && GET_MODE (orig_src
) != VOIDmode
)))
1663 if (GET_MODE (orig_src
) == VOIDmode
)
1664 src
= gen_reg_rtx (mode
);
1666 src
= gen_reg_rtx (GET_MODE (orig_src
));
1668 emit_move_insn (src
, orig_src
);
1671 /* Optimize the access just a bit. */
1673 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1674 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1675 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1676 && bytelen
== GET_MODE_SIZE (mode
))
1678 tmps
[i
] = gen_reg_rtx (mode
);
1679 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1681 else if (COMPLEX_MODE_P (mode
)
1682 && GET_MODE (src
) == mode
1683 && bytelen
== GET_MODE_SIZE (mode
))
1684 /* Let emit_move_complex do the bulk of the work. */
1686 else if (GET_CODE (src
) == CONCAT
)
1688 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1689 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1691 if ((bytepos
== 0 && bytelen
== slen0
)
1692 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1694 /* The following assumes that the concatenated objects all
1695 have the same size. In this case, a simple calculation
1696 can be used to determine the object and the bit field
1698 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1699 if (! CONSTANT_P (tmps
[i
])
1700 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1701 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1702 (bytepos
% slen0
) * BITS_PER_UNIT
,
1703 1, NULL_RTX
, mode
, mode
);
1709 gcc_assert (!bytepos
);
1710 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1711 emit_move_insn (mem
, src
);
1712 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1713 0, 1, NULL_RTX
, mode
, mode
);
1716 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1717 SIMD register, which is currently broken. While we get GCC
1718 to emit proper RTL for these cases, let's dump to memory. */
1719 else if (VECTOR_MODE_P (GET_MODE (dst
))
1722 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1725 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1726 emit_move_insn (mem
, src
);
1727 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1729 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1730 && XVECLEN (dst
, 0) > 1)
1731 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1732 else if (CONSTANT_P (src
))
1734 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1742 /* TODO: const_wide_int can have sizes other than this... */
1743 gcc_assert (2 * len
== ssize
);
1744 split_double (src
, &first
, &second
);
1751 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1754 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1755 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1759 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1764 /* Emit code to move a block SRC of type TYPE to a block DST,
1765 where DST is non-consecutive registers represented by a PARALLEL.
1766 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1770 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1775 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1776 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1778 /* Copy the extracted pieces into the proper (probable) hard regs. */
1779 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1781 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1784 emit_move_insn (d
, tmps
[i
]);
1788 /* Similar, but load SRC into new pseudos in a format that looks like
1789 PARALLEL. This can later be fed to emit_group_move to get things
1790 in the right place. */
1793 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1798 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1799 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1801 /* Convert the vector to look just like the original PARALLEL, except
1802 with the computed values. */
1803 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1805 rtx e
= XVECEXP (parallel
, 0, i
);
1806 rtx d
= XEXP (e
, 0);
1810 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1811 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1813 RTVEC_ELT (vec
, i
) = e
;
1816 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1819 /* Emit code to move a block SRC to block DST, where SRC and DST are
1820 non-consecutive groups of registers, each represented by a PARALLEL. */
1823 emit_group_move (rtx dst
, rtx src
)
1827 gcc_assert (GET_CODE (src
) == PARALLEL
1828 && GET_CODE (dst
) == PARALLEL
1829 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1831 /* Skip first entry if NULL. */
1832 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1833 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1834 XEXP (XVECEXP (src
, 0, i
), 0));
1837 /* Move a group of registers represented by a PARALLEL into pseudos. */
1840 emit_group_move_into_temps (rtx src
)
1842 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1845 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1847 rtx e
= XVECEXP (src
, 0, i
);
1848 rtx d
= XEXP (e
, 0);
1851 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1852 RTVEC_ELT (vec
, i
) = e
;
1855 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1858 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1859 where SRC is non-consecutive registers represented by a PARALLEL.
1860 SSIZE represents the total size of block ORIG_DST, or -1 if not
1864 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1867 int start
, finish
, i
;
1868 machine_mode m
= GET_MODE (orig_dst
);
1870 gcc_assert (GET_CODE (src
) == PARALLEL
);
1872 if (!SCALAR_INT_MODE_P (m
)
1873 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1875 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1876 if (imode
== BLKmode
)
1877 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1879 dst
= gen_reg_rtx (imode
);
1880 emit_group_store (dst
, src
, type
, ssize
);
1881 if (imode
!= BLKmode
)
1882 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1883 emit_move_insn (orig_dst
, dst
);
1887 /* Check for a NULL entry, used to indicate that the parameter goes
1888 both on the stack and in registers. */
1889 if (XEXP (XVECEXP (src
, 0, 0), 0))
1893 finish
= XVECLEN (src
, 0);
1895 tmps
= XALLOCAVEC (rtx
, finish
);
1897 /* Copy the (probable) hard regs into pseudos. */
1898 for (i
= start
; i
< finish
; i
++)
1900 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1901 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1903 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1904 emit_move_insn (tmps
[i
], reg
);
1910 /* If we won't be storing directly into memory, protect the real destination
1911 from strange tricks we might play. */
1913 if (GET_CODE (dst
) == PARALLEL
)
1917 /* We can get a PARALLEL dst if there is a conditional expression in
1918 a return statement. In that case, the dst and src are the same,
1919 so no action is necessary. */
1920 if (rtx_equal_p (dst
, src
))
1923 /* It is unclear if we can ever reach here, but we may as well handle
1924 it. Allocate a temporary, and split this into a store/load to/from
1926 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1927 emit_group_store (temp
, src
, type
, ssize
);
1928 emit_group_load (dst
, temp
, type
, ssize
);
1931 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1933 machine_mode outer
= GET_MODE (dst
);
1935 HOST_WIDE_INT bytepos
;
1939 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1940 dst
= gen_reg_rtx (outer
);
1942 /* Make life a bit easier for combine. */
1943 /* If the first element of the vector is the low part
1944 of the destination mode, use a paradoxical subreg to
1945 initialize the destination. */
1948 inner
= GET_MODE (tmps
[start
]);
1949 bytepos
= subreg_lowpart_offset (inner
, outer
);
1950 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1952 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1956 emit_move_insn (dst
, temp
);
1963 /* If the first element wasn't the low part, try the last. */
1965 && start
< finish
- 1)
1967 inner
= GET_MODE (tmps
[finish
- 1]);
1968 bytepos
= subreg_lowpart_offset (inner
, outer
);
1969 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1971 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1975 emit_move_insn (dst
, temp
);
1982 /* Otherwise, simply initialize the result to zero. */
1984 emit_move_insn (dst
, CONST0_RTX (outer
));
1987 /* Process the pieces. */
1988 for (i
= start
; i
< finish
; i
++)
1990 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
1991 machine_mode mode
= GET_MODE (tmps
[i
]);
1992 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1993 unsigned int adj_bytelen
;
1996 /* Handle trailing fragments that run over the size of the struct. */
1997 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1998 adj_bytelen
= ssize
- bytepos
;
2000 adj_bytelen
= bytelen
;
2002 if (GET_CODE (dst
) == CONCAT
)
2004 if (bytepos
+ adj_bytelen
2005 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2006 dest
= XEXP (dst
, 0);
2007 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2009 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2010 dest
= XEXP (dst
, 1);
2014 machine_mode dest_mode
= GET_MODE (dest
);
2015 machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2017 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2019 if (GET_MODE_ALIGNMENT (dest_mode
)
2020 >= GET_MODE_ALIGNMENT (tmp_mode
))
2022 dest
= assign_stack_temp (dest_mode
,
2023 GET_MODE_SIZE (dest_mode
));
2024 emit_move_insn (adjust_address (dest
,
2032 dest
= assign_stack_temp (tmp_mode
,
2033 GET_MODE_SIZE (tmp_mode
));
2034 emit_move_insn (dest
, tmps
[i
]);
2035 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2041 /* Handle trailing fragments that run over the size of the struct. */
2042 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2044 /* store_bit_field always takes its value from the lsb.
2045 Move the fragment to the lsb if it's not already there. */
2047 #ifdef BLOCK_REG_PADDING
2048 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2049 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2055 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2056 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2060 /* Make sure not to write past the end of the struct. */
2061 store_bit_field (dest
,
2062 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2063 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
- 1,
2067 /* Optimize the access just a bit. */
2068 else if (MEM_P (dest
)
2069 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2070 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2071 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2072 && bytelen
== GET_MODE_SIZE (mode
))
2073 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2076 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2077 0, 0, mode
, tmps
[i
]);
2080 /* Copy from the pseudo into the (probable) hard reg. */
2081 if (orig_dst
!= dst
)
2082 emit_move_insn (orig_dst
, dst
);
2085 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2086 of the value stored in X. */
2089 maybe_emit_group_store (rtx x
, tree type
)
2091 machine_mode mode
= TYPE_MODE (type
);
2092 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2093 if (GET_CODE (x
) == PARALLEL
)
2095 rtx result
= gen_reg_rtx (mode
);
2096 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2102 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2104 This is used on targets that return BLKmode values in registers. */
2107 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2109 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2110 rtx src
= NULL
, dst
= NULL
;
2111 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2112 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2113 machine_mode mode
= GET_MODE (srcreg
);
2114 machine_mode tmode
= GET_MODE (target
);
2115 machine_mode copy_mode
;
2117 /* BLKmode registers created in the back-end shouldn't have survived. */
2118 gcc_assert (mode
!= BLKmode
);
2120 /* If the structure doesn't take up a whole number of words, see whether
2121 SRCREG is padded on the left or on the right. If it's on the left,
2122 set PADDING_CORRECTION to the number of bits to skip.
2124 In most ABIs, the structure will be returned at the least end of
2125 the register, which translates to right padding on little-endian
2126 targets and left padding on big-endian targets. The opposite
2127 holds if the structure is returned at the most significant
2128 end of the register. */
2129 if (bytes
% UNITS_PER_WORD
!= 0
2130 && (targetm
.calls
.return_in_msb (type
)
2132 : BYTES_BIG_ENDIAN
))
2134 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2136 /* We can use a single move if we have an exact mode for the size. */
2137 else if (MEM_P (target
)
2138 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2139 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2140 && bytes
== GET_MODE_SIZE (mode
))
2142 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2146 /* And if we additionally have the same mode for a register. */
2147 else if (REG_P (target
)
2148 && GET_MODE (target
) == mode
2149 && bytes
== GET_MODE_SIZE (mode
))
2151 emit_move_insn (target
, srcreg
);
2155 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2156 into a new pseudo which is a full word. */
2157 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2159 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2163 /* Copy the structure BITSIZE bits at a time. If the target lives in
2164 memory, take care of not reading/writing past its end by selecting
2165 a copy mode suited to BITSIZE. This should always be possible given
2168 If the target lives in register, make sure not to select a copy mode
2169 larger than the mode of the register.
2171 We could probably emit more efficient code for machines which do not use
2172 strict alignment, but it doesn't seem worth the effort at the current
2175 copy_mode
= word_mode
;
2178 machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2179 if (mem_mode
!= BLKmode
)
2180 copy_mode
= mem_mode
;
2182 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2185 for (bitpos
= 0, xbitpos
= padding_correction
;
2186 bitpos
< bytes
* BITS_PER_UNIT
;
2187 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2189 /* We need a new source operand each time xbitpos is on a
2190 word boundary and when xbitpos == padding_correction
2191 (the first time through). */
2192 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2193 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2195 /* We need a new destination operand each time bitpos is on
2197 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2199 else if (bitpos
% BITS_PER_WORD
== 0)
2200 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2202 /* Use xbitpos for the source extraction (right justified) and
2203 bitpos for the destination store (left justified). */
2204 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2205 extract_bit_field (src
, bitsize
,
2206 xbitpos
% BITS_PER_WORD
, 1,
2207 NULL_RTX
, copy_mode
, copy_mode
));
2211 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2212 register if it contains any data, otherwise return null.
2214 This is used on targets that return BLKmode values in registers. */
2217 copy_blkmode_to_reg (machine_mode mode
, tree src
)
2220 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2221 unsigned int bitsize
;
2222 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2223 machine_mode dst_mode
;
2225 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2227 x
= expand_normal (src
);
2229 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2233 /* If the structure doesn't take up a whole number of words, see
2234 whether the register value should be padded on the left or on
2235 the right. Set PADDING_CORRECTION to the number of padding
2236 bits needed on the left side.
2238 In most ABIs, the structure will be returned at the least end of
2239 the register, which translates to right padding on little-endian
2240 targets and left padding on big-endian targets. The opposite
2241 holds if the structure is returned at the most significant
2242 end of the register. */
2243 if (bytes
% UNITS_PER_WORD
!= 0
2244 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2246 : BYTES_BIG_ENDIAN
))
2247 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2250 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2251 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2252 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2254 /* Copy the structure BITSIZE bits at a time. */
2255 for (bitpos
= 0, xbitpos
= padding_correction
;
2256 bitpos
< bytes
* BITS_PER_UNIT
;
2257 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2259 /* We need a new destination pseudo each time xbitpos is
2260 on a word boundary and when xbitpos == padding_correction
2261 (the first time through). */
2262 if (xbitpos
% BITS_PER_WORD
== 0
2263 || xbitpos
== padding_correction
)
2265 /* Generate an appropriate register. */
2266 dst_word
= gen_reg_rtx (word_mode
);
2267 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2269 /* Clear the destination before we move anything into it. */
2270 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2273 /* We need a new source operand each time bitpos is on a word
2275 if (bitpos
% BITS_PER_WORD
== 0)
2276 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2278 /* Use bitpos for the source extraction (left justified) and
2279 xbitpos for the destination store (right justified). */
2280 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2282 extract_bit_field (src_word
, bitsize
,
2283 bitpos
% BITS_PER_WORD
, 1,
2284 NULL_RTX
, word_mode
, word_mode
));
2287 if (mode
== BLKmode
)
2289 /* Find the smallest integer mode large enough to hold the
2290 entire structure. */
2291 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2293 mode
= GET_MODE_WIDER_MODE (mode
))
2294 /* Have we found a large enough mode? */
2295 if (GET_MODE_SIZE (mode
) >= bytes
)
2298 /* A suitable mode should have been found. */
2299 gcc_assert (mode
!= VOIDmode
);
2302 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2303 dst_mode
= word_mode
;
2306 dst
= gen_reg_rtx (dst_mode
);
2308 for (i
= 0; i
< n_regs
; i
++)
2309 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2311 if (mode
!= dst_mode
)
2312 dst
= gen_lowpart (mode
, dst
);
2317 /* Add a USE expression for REG to the (possibly empty) list pointed
2318 to by CALL_FUSAGE. REG must denote a hard register. */
2321 use_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2323 gcc_assert (REG_P (reg
));
2325 if (!HARD_REGISTER_P (reg
))
2329 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2332 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
2333 to by CALL_FUSAGE. REG must denote a hard register. */
2336 clobber_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2338 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2341 = gen_rtx_EXPR_LIST (mode
, gen_rtx_CLOBBER (VOIDmode
, reg
), *call_fusage
);
2344 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2345 starting at REGNO. All of these registers must be hard registers. */
2348 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2352 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2354 for (i
= 0; i
< nregs
; i
++)
2355 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2358 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2359 PARALLEL REGS. This is for calls that pass values in multiple
2360 non-contiguous locations. The Irix 6 ABI has examples of this. */
2363 use_group_regs (rtx
*call_fusage
, rtx regs
)
2367 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2369 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2371 /* A NULL entry means the parameter goes both on the stack and in
2372 registers. This can also be a MEM for targets that pass values
2373 partially on the stack and partially in registers. */
2374 if (reg
!= 0 && REG_P (reg
))
2375 use_reg (call_fusage
, reg
);
2379 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2380 assigment and the code of the expresion on the RHS is CODE. Return
2384 get_def_for_expr (tree name
, enum tree_code code
)
2388 if (TREE_CODE (name
) != SSA_NAME
)
2391 def_stmt
= get_gimple_for_ssa_name (name
);
2393 || gimple_assign_rhs_code (def_stmt
) != code
)
2399 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2400 assigment and the class of the expresion on the RHS is CLASS. Return
2404 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2408 if (TREE_CODE (name
) != SSA_NAME
)
2411 def_stmt
= get_gimple_for_ssa_name (name
);
2413 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2420 /* Determine whether the LEN bytes generated by CONSTFUN can be
2421 stored to memory using several move instructions. CONSTFUNDATA is
2422 a pointer which will be passed as argument in every CONSTFUN call.
2423 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2424 a memset operation and false if it's a copy of a constant string.
2425 Return nonzero if a call to store_by_pieces should succeed. */
2428 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2429 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2430 void *constfundata
, unsigned int align
, bool memsetp
)
2432 unsigned HOST_WIDE_INT l
;
2433 unsigned int max_size
;
2434 HOST_WIDE_INT offset
= 0;
2436 enum insn_code icode
;
2438 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2439 rtx cst ATTRIBUTE_UNUSED
;
2444 if (!targetm
.use_by_pieces_infrastructure_p (len
, align
,
2448 optimize_insn_for_speed_p ()))
2451 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2453 /* We would first store what we can in the largest integer mode, then go to
2454 successively smaller modes. */
2457 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2461 max_size
= STORE_MAX_PIECES
+ 1;
2462 while (max_size
> 1 && l
> 0)
2464 mode
= widest_int_mode_for_size (max_size
);
2466 if (mode
== VOIDmode
)
2469 icode
= optab_handler (mov_optab
, mode
);
2470 if (icode
!= CODE_FOR_nothing
2471 && align
>= GET_MODE_ALIGNMENT (mode
))
2473 unsigned int size
= GET_MODE_SIZE (mode
);
2480 cst
= (*constfun
) (constfundata
, offset
, mode
);
2481 if (!targetm
.legitimate_constant_p (mode
, cst
))
2491 max_size
= GET_MODE_SIZE (mode
);
2494 /* The code above should have handled everything. */
2501 /* Generate several move instructions to store LEN bytes generated by
2502 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2503 pointer which will be passed as argument in every CONSTFUN call.
2504 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2505 a memset operation and false if it's a copy of a constant string.
2506 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2507 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2511 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2512 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2513 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2515 machine_mode to_addr_mode
= get_address_mode (to
);
2516 struct store_by_pieces_d data
;
2520 gcc_assert (endp
!= 2);
2524 gcc_assert (targetm
.use_by_pieces_infrastructure_p
2529 optimize_insn_for_speed_p ()));
2531 data
.constfun
= constfun
;
2532 data
.constfundata
= constfundata
;
2535 store_by_pieces_1 (&data
, align
);
2540 gcc_assert (!data
.reverse
);
2545 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2546 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2548 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2549 plus_constant (to_addr_mode
,
2553 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2560 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2568 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2569 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2572 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2574 struct store_by_pieces_d data
;
2579 data
.constfun
= clear_by_pieces_1
;
2580 data
.constfundata
= NULL
;
2583 store_by_pieces_1 (&data
, align
);
2586 /* Callback routine for clear_by_pieces.
2587 Return const0_rtx unconditionally. */
2590 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2591 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2592 machine_mode mode ATTRIBUTE_UNUSED
)
2597 /* Subroutine of clear_by_pieces and store_by_pieces.
2598 Generate several move instructions to store LEN bytes of block TO. (A MEM
2599 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2602 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2603 unsigned int align ATTRIBUTE_UNUSED
)
2605 machine_mode to_addr_mode
= get_address_mode (data
->to
);
2606 rtx to_addr
= XEXP (data
->to
, 0);
2607 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2608 enum insn_code icode
;
2611 data
->to_addr
= to_addr
;
2613 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2614 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2616 data
->explicit_inc_to
= 0;
2618 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2620 data
->offset
= data
->len
;
2622 /* If storing requires more than two move insns,
2623 copy addresses to registers (to make displacements shorter)
2624 and use post-increment if available. */
2625 if (!data
->autinc_to
2626 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2628 /* Determine the main mode we'll be using.
2629 MODE might not be used depending on the definitions of the
2630 USE_* macros below. */
2631 machine_mode mode ATTRIBUTE_UNUSED
2632 = widest_int_mode_for_size (max_size
);
2634 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2636 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2637 plus_constant (to_addr_mode
,
2640 data
->autinc_to
= 1;
2641 data
->explicit_inc_to
= -1;
2644 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2645 && ! data
->autinc_to
)
2647 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2648 data
->autinc_to
= 1;
2649 data
->explicit_inc_to
= 1;
2652 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2653 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2656 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2658 /* First store what we can in the largest integer mode, then go to
2659 successively smaller modes. */
2661 while (max_size
> 1 && data
->len
> 0)
2663 machine_mode mode
= widest_int_mode_for_size (max_size
);
2665 if (mode
== VOIDmode
)
2668 icode
= optab_handler (mov_optab
, mode
);
2669 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2670 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2672 max_size
= GET_MODE_SIZE (mode
);
2675 /* The code above should have handled everything. */
2676 gcc_assert (!data
->len
);
2679 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2680 with move instructions for mode MODE. GENFUN is the gen_... function
2681 to make a move insn for that mode. DATA has all the other info. */
2684 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2685 struct store_by_pieces_d
*data
)
2687 unsigned int size
= GET_MODE_SIZE (mode
);
2690 while (data
->len
>= size
)
2693 data
->offset
-= size
;
2695 if (data
->autinc_to
)
2696 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2699 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2701 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2702 emit_insn (gen_add2_insn (data
->to_addr
,
2703 gen_int_mode (-(HOST_WIDE_INT
) size
,
2704 GET_MODE (data
->to_addr
))));
2706 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2707 emit_insn ((*genfun
) (to1
, cst
));
2709 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2710 emit_insn (gen_add2_insn (data
->to_addr
,
2712 GET_MODE (data
->to_addr
))));
2714 if (! data
->reverse
)
2715 data
->offset
+= size
;
2721 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2722 its length in bytes. */
2725 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2726 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2727 unsigned HOST_WIDE_INT min_size
,
2728 unsigned HOST_WIDE_INT max_size
,
2729 unsigned HOST_WIDE_INT probable_max_size
)
2731 machine_mode mode
= GET_MODE (object
);
2734 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2736 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2737 just move a zero. Otherwise, do this a piece at a time. */
2739 && CONST_INT_P (size
)
2740 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2742 rtx zero
= CONST0_RTX (mode
);
2745 emit_move_insn (object
, zero
);
2749 if (COMPLEX_MODE_P (mode
))
2751 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2754 write_complex_part (object
, zero
, 0);
2755 write_complex_part (object
, zero
, 1);
2761 if (size
== const0_rtx
)
2764 align
= MEM_ALIGN (object
);
2766 if (CONST_INT_P (size
)
2767 && targetm
.use_by_pieces_infrastructure_p (INTVAL (size
), align
,
2769 optimize_insn_for_speed_p ()))
2770 clear_by_pieces (object
, INTVAL (size
), align
);
2771 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2772 expected_align
, expected_size
,
2773 min_size
, max_size
, probable_max_size
))
2775 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2776 return set_storage_via_libcall (object
, size
, const0_rtx
,
2777 method
== BLOCK_OP_TAILCALL
);
2785 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2787 unsigned HOST_WIDE_INT max
, min
= 0;
2788 if (GET_CODE (size
) == CONST_INT
)
2789 min
= max
= UINTVAL (size
);
2791 max
= GET_MODE_MASK (GET_MODE (size
));
2792 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2796 /* A subroutine of clear_storage. Expand a call to memset.
2797 Return the return value of memset, 0 otherwise. */
2800 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2802 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2803 machine_mode size_mode
;
2806 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2807 place those into new pseudos into a VAR_DECL and use them later. */
2809 object
= copy_addr_to_reg (XEXP (object
, 0));
2811 size_mode
= TYPE_MODE (sizetype
);
2812 size
= convert_to_mode (size_mode
, size
, 1);
2813 size
= copy_to_mode_reg (size_mode
, size
);
2815 /* It is incorrect to use the libcall calling conventions to call
2816 memset in this context. This could be a user call to memset and
2817 the user may wish to examine the return value from memset. For
2818 targets where libcalls and normal calls have different conventions
2819 for returning pointers, we could end up generating incorrect code. */
2821 object_tree
= make_tree (ptr_type_node
, object
);
2822 if (!CONST_INT_P (val
))
2823 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2824 size_tree
= make_tree (sizetype
, size
);
2825 val_tree
= make_tree (integer_type_node
, val
);
2827 fn
= clear_storage_libcall_fn (true);
2828 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2829 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2831 retval
= expand_normal (call_expr
);
2836 /* A subroutine of set_storage_via_libcall. Create the tree node
2837 for the function we use for block clears. */
2839 tree block_clear_fn
;
2842 init_block_clear_fn (const char *asmspec
)
2844 if (!block_clear_fn
)
2848 fn
= get_identifier ("memset");
2849 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2850 integer_type_node
, sizetype
,
2853 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2854 DECL_EXTERNAL (fn
) = 1;
2855 TREE_PUBLIC (fn
) = 1;
2856 DECL_ARTIFICIAL (fn
) = 1;
2857 TREE_NOTHROW (fn
) = 1;
2858 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2859 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2861 block_clear_fn
= fn
;
2865 set_user_assembler_name (block_clear_fn
, asmspec
);
2869 clear_storage_libcall_fn (int for_call
)
2871 static bool emitted_extern
;
2873 if (!block_clear_fn
)
2874 init_block_clear_fn (NULL
);
2876 if (for_call
&& !emitted_extern
)
2878 emitted_extern
= true;
2879 make_decl_rtl (block_clear_fn
);
2882 return block_clear_fn
;
2885 /* Expand a setmem pattern; return true if successful. */
2888 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2889 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2890 unsigned HOST_WIDE_INT min_size
,
2891 unsigned HOST_WIDE_INT max_size
,
2892 unsigned HOST_WIDE_INT probable_max_size
)
2894 /* Try the most limited insn first, because there's no point
2895 including more than one in the machine description unless
2896 the more limited one has some advantage. */
2900 if (expected_align
< align
)
2901 expected_align
= align
;
2902 if (expected_size
!= -1)
2904 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2905 expected_size
= max_size
;
2906 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2907 expected_size
= min_size
;
2910 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2911 mode
= GET_MODE_WIDER_MODE (mode
))
2913 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2915 if (code
!= CODE_FOR_nothing
2916 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2917 here because if SIZE is less than the mode mask, as it is
2918 returned by the macro, it will definitely be less than the
2919 actual mode mask. Since SIZE is within the Pmode address
2920 space, we limit MODE to Pmode. */
2921 && ((CONST_INT_P (size
)
2922 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2923 <= (GET_MODE_MASK (mode
) >> 1)))
2924 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2925 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2927 struct expand_operand ops
[9];
2930 nops
= insn_data
[(int) code
].n_generator_args
;
2931 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2933 create_fixed_operand (&ops
[0], object
);
2934 /* The check above guarantees that this size conversion is valid. */
2935 create_convert_operand_to (&ops
[1], size
, mode
, true);
2936 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2937 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2940 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2941 create_integer_operand (&ops
[5], expected_size
);
2945 create_integer_operand (&ops
[6], min_size
);
2946 /* If we can not represent the maximal size,
2947 make parameter NULL. */
2948 if ((HOST_WIDE_INT
) max_size
!= -1)
2949 create_integer_operand (&ops
[7], max_size
);
2951 create_fixed_operand (&ops
[7], NULL
);
2955 /* If we can not represent the maximal size,
2956 make parameter NULL. */
2957 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2958 create_integer_operand (&ops
[8], probable_max_size
);
2960 create_fixed_operand (&ops
[8], NULL
);
2962 if (maybe_expand_insn (code
, nops
, ops
))
2971 /* Write to one of the components of the complex value CPLX. Write VAL to
2972 the real part if IMAG_P is false, and the imaginary part if its true. */
2975 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2981 if (GET_CODE (cplx
) == CONCAT
)
2983 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2987 cmode
= GET_MODE (cplx
);
2988 imode
= GET_MODE_INNER (cmode
);
2989 ibitsize
= GET_MODE_BITSIZE (imode
);
2991 /* For MEMs simplify_gen_subreg may generate an invalid new address
2992 because, e.g., the original address is considered mode-dependent
2993 by the target, which restricts simplify_subreg from invoking
2994 adjust_address_nv. Instead of preparing fallback support for an
2995 invalid address, we call adjust_address_nv directly. */
2998 emit_move_insn (adjust_address_nv (cplx
, imode
,
2999 imag_p
? GET_MODE_SIZE (imode
) : 0),
3004 /* If the sub-object is at least word sized, then we know that subregging
3005 will work. This special case is important, since store_bit_field
3006 wants to operate on integer modes, and there's rarely an OImode to
3007 correspond to TCmode. */
3008 if (ibitsize
>= BITS_PER_WORD
3009 /* For hard regs we have exact predicates. Assume we can split
3010 the original object if it spans an even number of hard regs.
3011 This special case is important for SCmode on 64-bit platforms
3012 where the natural size of floating-point regs is 32-bit. */
3014 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3015 && REG_NREGS (cplx
) % 2 == 0))
3017 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3018 imag_p
? GET_MODE_SIZE (imode
) : 0);
3021 emit_move_insn (part
, val
);
3025 /* simplify_gen_subreg may fail for sub-word MEMs. */
3026 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3029 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
3032 /* Extract one of the components of the complex value CPLX. Extract the
3033 real part if IMAG_P is false, and the imaginary part if it's true. */
3036 read_complex_part (rtx cplx
, bool imag_p
)
3038 machine_mode cmode
, imode
;
3041 if (GET_CODE (cplx
) == CONCAT
)
3042 return XEXP (cplx
, imag_p
);
3044 cmode
= GET_MODE (cplx
);
3045 imode
= GET_MODE_INNER (cmode
);
3046 ibitsize
= GET_MODE_BITSIZE (imode
);
3048 /* Special case reads from complex constants that got spilled to memory. */
3049 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3051 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3052 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3054 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3055 if (CONSTANT_CLASS_P (part
))
3056 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3060 /* For MEMs simplify_gen_subreg may generate an invalid new address
3061 because, e.g., the original address is considered mode-dependent
3062 by the target, which restricts simplify_subreg from invoking
3063 adjust_address_nv. Instead of preparing fallback support for an
3064 invalid address, we call adjust_address_nv directly. */
3066 return adjust_address_nv (cplx
, imode
,
3067 imag_p
? GET_MODE_SIZE (imode
) : 0);
3069 /* If the sub-object is at least word sized, then we know that subregging
3070 will work. This special case is important, since extract_bit_field
3071 wants to operate on integer modes, and there's rarely an OImode to
3072 correspond to TCmode. */
3073 if (ibitsize
>= BITS_PER_WORD
3074 /* For hard regs we have exact predicates. Assume we can split
3075 the original object if it spans an even number of hard regs.
3076 This special case is important for SCmode on 64-bit platforms
3077 where the natural size of floating-point regs is 32-bit. */
3079 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3080 && REG_NREGS (cplx
) % 2 == 0))
3082 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3083 imag_p
? GET_MODE_SIZE (imode
) : 0);
3087 /* simplify_gen_subreg may fail for sub-word MEMs. */
3088 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3091 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3092 true, NULL_RTX
, imode
, imode
);
3095 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3096 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3097 represented in NEW_MODE. If FORCE is true, this will never happen, as
3098 we'll force-create a SUBREG if needed. */
3101 emit_move_change_mode (machine_mode new_mode
,
3102 machine_mode old_mode
, rtx x
, bool force
)
3106 if (push_operand (x
, GET_MODE (x
)))
3108 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3109 MEM_COPY_ATTRIBUTES (ret
, x
);
3113 /* We don't have to worry about changing the address since the
3114 size in bytes is supposed to be the same. */
3115 if (reload_in_progress
)
3117 /* Copy the MEM to change the mode and move any
3118 substitutions from the old MEM to the new one. */
3119 ret
= adjust_address_nv (x
, new_mode
, 0);
3120 copy_replacements (x
, ret
);
3123 ret
= adjust_address (x
, new_mode
, 0);
3127 /* Note that we do want simplify_subreg's behavior of validating
3128 that the new mode is ok for a hard register. If we were to use
3129 simplify_gen_subreg, we would create the subreg, but would
3130 probably run into the target not being able to implement it. */
3131 /* Except, of course, when FORCE is true, when this is exactly what
3132 we want. Which is needed for CCmodes on some targets. */
3134 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3136 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3142 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3143 an integer mode of the same size as MODE. Returns the instruction
3144 emitted, or NULL if such a move could not be generated. */
3147 emit_move_via_integer (machine_mode mode
, rtx x
, rtx y
, bool force
)
3150 enum insn_code code
;
3152 /* There must exist a mode of the exact size we require. */
3153 imode
= int_mode_for_mode (mode
);
3154 if (imode
== BLKmode
)
3157 /* The target must support moves in this mode. */
3158 code
= optab_handler (mov_optab
, imode
);
3159 if (code
== CODE_FOR_nothing
)
3162 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3165 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3168 return emit_insn (GEN_FCN (code
) (x
, y
));
3171 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3172 Return an equivalent MEM that does not use an auto-increment. */
3175 emit_move_resolve_push (machine_mode mode
, rtx x
)
3177 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3178 HOST_WIDE_INT adjust
;
3181 adjust
= GET_MODE_SIZE (mode
);
3182 #ifdef PUSH_ROUNDING
3183 adjust
= PUSH_ROUNDING (adjust
);
3185 if (code
== PRE_DEC
|| code
== POST_DEC
)
3187 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3189 rtx expr
= XEXP (XEXP (x
, 0), 1);
3192 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3193 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3194 val
= INTVAL (XEXP (expr
, 1));
3195 if (GET_CODE (expr
) == MINUS
)
3197 gcc_assert (adjust
== val
|| adjust
== -val
);
3201 /* Do not use anti_adjust_stack, since we don't want to update
3202 stack_pointer_delta. */
3203 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3204 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3205 0, OPTAB_LIB_WIDEN
);
3206 if (temp
!= stack_pointer_rtx
)
3207 emit_move_insn (stack_pointer_rtx
, temp
);
3214 temp
= stack_pointer_rtx
;
3219 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3225 return replace_equiv_address (x
, temp
);
3228 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3229 X is known to satisfy push_operand, and MODE is known to be complex.
3230 Returns the last instruction emitted. */
3233 emit_move_complex_push (machine_mode mode
, rtx x
, rtx y
)
3235 machine_mode submode
= GET_MODE_INNER (mode
);
3238 #ifdef PUSH_ROUNDING
3239 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3241 /* In case we output to the stack, but the size is smaller than the
3242 machine can push exactly, we need to use move instructions. */
3243 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3245 x
= emit_move_resolve_push (mode
, x
);
3246 return emit_move_insn (x
, y
);
3250 /* Note that the real part always precedes the imag part in memory
3251 regardless of machine's endianness. */
3252 switch (GET_CODE (XEXP (x
, 0)))
3266 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3267 read_complex_part (y
, imag_first
));
3268 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3269 read_complex_part (y
, !imag_first
));
3272 /* A subroutine of emit_move_complex. Perform the move from Y to X
3273 via two moves of the parts. Returns the last instruction emitted. */
3276 emit_move_complex_parts (rtx x
, rtx y
)
3278 /* Show the output dies here. This is necessary for SUBREGs
3279 of pseudos since we cannot track their lifetimes correctly;
3280 hard regs shouldn't appear here except as return values. */
3281 if (!reload_completed
&& !reload_in_progress
3282 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3285 write_complex_part (x
, read_complex_part (y
, false), false);
3286 write_complex_part (x
, read_complex_part (y
, true), true);
3288 return get_last_insn ();
3291 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3292 MODE is known to be complex. Returns the last instruction emitted. */
3295 emit_move_complex (machine_mode mode
, rtx x
, rtx y
)
3299 /* Need to take special care for pushes, to maintain proper ordering
3300 of the data, and possibly extra padding. */
3301 if (push_operand (x
, mode
))
3302 return emit_move_complex_push (mode
, x
, y
);
3304 /* See if we can coerce the target into moving both values at once, except
3305 for floating point where we favor moving as parts if this is easy. */
3306 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3307 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3309 && HARD_REGISTER_P (x
)
3310 && REG_NREGS (x
) == 1)
3312 && HARD_REGISTER_P (y
)
3313 && REG_NREGS (y
) == 1))
3315 /* Not possible if the values are inherently not adjacent. */
3316 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3318 /* Is possible if both are registers (or subregs of registers). */
3319 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3321 /* If one of the operands is a memory, and alignment constraints
3322 are friendly enough, we may be able to do combined memory operations.
3323 We do not attempt this if Y is a constant because that combination is
3324 usually better with the by-parts thing below. */
3325 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3326 && (!STRICT_ALIGNMENT
3327 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3336 /* For memory to memory moves, optimal behavior can be had with the
3337 existing block move logic. */
3338 if (MEM_P (x
) && MEM_P (y
))
3340 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3341 BLOCK_OP_NO_LIBCALL
);
3342 return get_last_insn ();
3345 ret
= emit_move_via_integer (mode
, x
, y
, true);
3350 return emit_move_complex_parts (x
, y
);
3353 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3354 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3357 emit_move_ccmode (machine_mode mode
, rtx x
, rtx y
)
3361 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3364 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3365 if (code
!= CODE_FOR_nothing
)
3367 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3368 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3369 return emit_insn (GEN_FCN (code
) (x
, y
));
3373 /* Otherwise, find the MODE_INT mode of the same width. */
3374 ret
= emit_move_via_integer (mode
, x
, y
, false);
3375 gcc_assert (ret
!= NULL
);
3379 /* Return true if word I of OP lies entirely in the
3380 undefined bits of a paradoxical subreg. */
3383 undefined_operand_subword_p (const_rtx op
, int i
)
3385 machine_mode innermode
, innermostmode
;
3387 if (GET_CODE (op
) != SUBREG
)
3389 innermode
= GET_MODE (op
);
3390 innermostmode
= GET_MODE (SUBREG_REG (op
));
3391 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3392 /* The SUBREG_BYTE represents offset, as if the value were stored in
3393 memory, except for a paradoxical subreg where we define
3394 SUBREG_BYTE to be 0; undo this exception as in
3396 if (SUBREG_BYTE (op
) == 0
3397 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3399 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3400 if (WORDS_BIG_ENDIAN
)
3401 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3402 if (BYTES_BIG_ENDIAN
)
3403 offset
+= difference
% UNITS_PER_WORD
;
3405 if (offset
>= GET_MODE_SIZE (innermostmode
)
3406 || offset
<= -GET_MODE_SIZE (word_mode
))
3411 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3412 MODE is any multi-word or full-word mode that lacks a move_insn
3413 pattern. Note that you will get better code if you define such
3414 patterns, even if they must turn into multiple assembler instructions. */
3417 emit_move_multi_word (machine_mode mode
, rtx x
, rtx y
)
3419 rtx_insn
*last_insn
= 0;
3425 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3427 /* If X is a push on the stack, do the push now and replace
3428 X with a reference to the stack pointer. */
3429 if (push_operand (x
, mode
))
3430 x
= emit_move_resolve_push (mode
, x
);
3432 /* If we are in reload, see if either operand is a MEM whose address
3433 is scheduled for replacement. */
3434 if (reload_in_progress
&& MEM_P (x
)
3435 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3436 x
= replace_equiv_address_nv (x
, inner
);
3437 if (reload_in_progress
&& MEM_P (y
)
3438 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3439 y
= replace_equiv_address_nv (y
, inner
);
3443 need_clobber
= false;
3445 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3448 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3451 /* Do not generate code for a move if it would come entirely
3452 from the undefined bits of a paradoxical subreg. */
3453 if (undefined_operand_subword_p (y
, i
))
3456 ypart
= operand_subword (y
, i
, 1, mode
);
3458 /* If we can't get a part of Y, put Y into memory if it is a
3459 constant. Otherwise, force it into a register. Then we must
3460 be able to get a part of Y. */
3461 if (ypart
== 0 && CONSTANT_P (y
))
3463 y
= use_anchored_address (force_const_mem (mode
, y
));
3464 ypart
= operand_subword (y
, i
, 1, mode
);
3466 else if (ypart
== 0)
3467 ypart
= operand_subword_force (y
, i
, mode
);
3469 gcc_assert (xpart
&& ypart
);
3471 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3473 last_insn
= emit_move_insn (xpart
, ypart
);
3479 /* Show the output dies here. This is necessary for SUBREGs
3480 of pseudos since we cannot track their lifetimes correctly;
3481 hard regs shouldn't appear here except as return values.
3482 We never want to emit such a clobber after reload. */
3484 && ! (reload_in_progress
|| reload_completed
)
3485 && need_clobber
!= 0)
3493 /* Low level part of emit_move_insn.
3494 Called just like emit_move_insn, but assumes X and Y
3495 are basically valid. */
3498 emit_move_insn_1 (rtx x
, rtx y
)
3500 machine_mode mode
= GET_MODE (x
);
3501 enum insn_code code
;
3503 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3505 code
= optab_handler (mov_optab
, mode
);
3506 if (code
!= CODE_FOR_nothing
)
3507 return emit_insn (GEN_FCN (code
) (x
, y
));
3509 /* Expand complex moves by moving real part and imag part. */
3510 if (COMPLEX_MODE_P (mode
))
3511 return emit_move_complex (mode
, x
, y
);
3513 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3514 || ALL_FIXED_POINT_MODE_P (mode
))
3516 rtx_insn
*result
= emit_move_via_integer (mode
, x
, y
, true);
3518 /* If we can't find an integer mode, use multi words. */
3522 return emit_move_multi_word (mode
, x
, y
);
3525 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3526 return emit_move_ccmode (mode
, x
, y
);
3528 /* Try using a move pattern for the corresponding integer mode. This is
3529 only safe when simplify_subreg can convert MODE constants into integer
3530 constants. At present, it can only do this reliably if the value
3531 fits within a HOST_WIDE_INT. */
3532 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3534 rtx_insn
*ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3538 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3543 return emit_move_multi_word (mode
, x
, y
);
3546 /* Generate code to copy Y into X.
3547 Both Y and X must have the same mode, except that
3548 Y can be a constant with VOIDmode.
3549 This mode cannot be BLKmode; use emit_block_move for that.
3551 Return the last instruction emitted. */
3554 emit_move_insn (rtx x
, rtx y
)
3556 machine_mode mode
= GET_MODE (x
);
3557 rtx y_cst
= NULL_RTX
;
3558 rtx_insn
*last_insn
;
3561 gcc_assert (mode
!= BLKmode
3562 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3567 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3568 && (last_insn
= compress_float_constant (x
, y
)))
3573 if (!targetm
.legitimate_constant_p (mode
, y
))
3575 y
= force_const_mem (mode
, y
);
3577 /* If the target's cannot_force_const_mem prevented the spill,
3578 assume that the target's move expanders will also take care
3579 of the non-legitimate constant. */
3583 y
= use_anchored_address (y
);
3587 /* If X or Y are memory references, verify that their addresses are valid
3590 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3592 && ! push_operand (x
, GET_MODE (x
))))
3593 x
= validize_mem (x
);
3596 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3597 MEM_ADDR_SPACE (y
)))
3598 y
= validize_mem (y
);
3600 gcc_assert (mode
!= BLKmode
);
3602 last_insn
= emit_move_insn_1 (x
, y
);
3604 if (y_cst
&& REG_P (x
)
3605 && (set
= single_set (last_insn
)) != NULL_RTX
3606 && SET_DEST (set
) == x
3607 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3608 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3613 /* Generate the body of an instruction to copy Y into X.
3614 It may be a list of insns, if one insn isn't enough. */
3617 gen_move_insn (rtx x
, rtx y
)
3622 emit_move_insn_1 (x
, y
);
3628 /* If Y is representable exactly in a narrower mode, and the target can
3629 perform the extension directly from constant or memory, then emit the
3630 move as an extension. */
3633 compress_float_constant (rtx x
, rtx y
)
3635 machine_mode dstmode
= GET_MODE (x
);
3636 machine_mode orig_srcmode
= GET_MODE (y
);
3637 machine_mode srcmode
;
3639 int oldcost
, newcost
;
3640 bool speed
= optimize_insn_for_speed_p ();
3642 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3644 if (targetm
.legitimate_constant_p (dstmode
, y
))
3645 oldcost
= set_src_cost (y
, speed
);
3647 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3649 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3650 srcmode
!= orig_srcmode
;
3651 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3655 rtx_insn
*last_insn
;
3657 /* Skip if the target can't extend this way. */
3658 ic
= can_extend_p (dstmode
, srcmode
, 0);
3659 if (ic
== CODE_FOR_nothing
)
3662 /* Skip if the narrowed value isn't exact. */
3663 if (! exact_real_truncate (srcmode
, &r
))
3666 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3668 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3670 /* Skip if the target needs extra instructions to perform
3672 if (!insn_operand_matches (ic
, 1, trunc_y
))
3674 /* This is valid, but may not be cheaper than the original. */
3675 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3677 if (oldcost
< newcost
)
3680 else if (float_extend_from_mem
[dstmode
][srcmode
])
3682 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3683 /* This is valid, but may not be cheaper than the original. */
3684 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3686 if (oldcost
< newcost
)
3688 trunc_y
= validize_mem (trunc_y
);
3693 /* For CSE's benefit, force the compressed constant pool entry
3694 into a new pseudo. This constant may be used in different modes,
3695 and if not, combine will put things back together for us. */
3696 trunc_y
= force_reg (srcmode
, trunc_y
);
3698 /* If x is a hard register, perform the extension into a pseudo,
3699 so that e.g. stack realignment code is aware of it. */
3701 if (REG_P (x
) && HARD_REGISTER_P (x
))
3702 target
= gen_reg_rtx (dstmode
);
3704 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
3705 last_insn
= get_last_insn ();
3708 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3711 return emit_move_insn (x
, target
);
3718 /* Pushing data onto the stack. */
3720 /* Push a block of length SIZE (perhaps variable)
3721 and return an rtx to address the beginning of the block.
3722 The value may be virtual_outgoing_args_rtx.
3724 EXTRA is the number of bytes of padding to push in addition to SIZE.
3725 BELOW nonzero means this padding comes at low addresses;
3726 otherwise, the padding comes at high addresses. */
3729 push_block (rtx size
, int extra
, int below
)
3733 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3734 if (CONSTANT_P (size
))
3735 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3736 else if (REG_P (size
) && extra
== 0)
3737 anti_adjust_stack (size
);
3740 temp
= copy_to_mode_reg (Pmode
, size
);
3742 temp
= expand_binop (Pmode
, add_optab
, temp
,
3743 gen_int_mode (extra
, Pmode
),
3744 temp
, 0, OPTAB_LIB_WIDEN
);
3745 anti_adjust_stack (temp
);
3748 if (STACK_GROWS_DOWNWARD
)
3750 temp
= virtual_outgoing_args_rtx
;
3751 if (extra
!= 0 && below
)
3752 temp
= plus_constant (Pmode
, temp
, extra
);
3756 if (CONST_INT_P (size
))
3757 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3758 -INTVAL (size
) - (below
? 0 : extra
));
3759 else if (extra
!= 0 && !below
)
3760 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3761 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3764 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3765 negate_rtx (Pmode
, size
));
3768 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3771 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3774 mem_autoinc_base (rtx mem
)
3778 rtx addr
= XEXP (mem
, 0);
3779 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3780 return XEXP (addr
, 0);
3785 /* A utility routine used here, in reload, and in try_split. The insns
3786 after PREV up to and including LAST are known to adjust the stack,
3787 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3788 placing notes as appropriate. PREV may be NULL, indicating the
3789 entire insn sequence prior to LAST should be scanned.
3791 The set of allowed stack pointer modifications is small:
3792 (1) One or more auto-inc style memory references (aka pushes),
3793 (2) One or more addition/subtraction with the SP as destination,
3794 (3) A single move insn with the SP as destination,
3795 (4) A call_pop insn,
3796 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3798 Insns in the sequence that do not modify the SP are ignored,
3799 except for noreturn calls.
3801 The return value is the amount of adjustment that can be trivially
3802 verified, via immediate operand or auto-inc. If the adjustment
3803 cannot be trivially extracted, the return value is INT_MIN. */
3806 find_args_size_adjust (rtx_insn
*insn
)
3811 pat
= PATTERN (insn
);
3814 /* Look for a call_pop pattern. */
3817 /* We have to allow non-call_pop patterns for the case
3818 of emit_single_push_insn of a TLS address. */
3819 if (GET_CODE (pat
) != PARALLEL
)
3822 /* All call_pop have a stack pointer adjust in the parallel.
3823 The call itself is always first, and the stack adjust is
3824 usually last, so search from the end. */
3825 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3827 set
= XVECEXP (pat
, 0, i
);
3828 if (GET_CODE (set
) != SET
)
3830 dest
= SET_DEST (set
);
3831 if (dest
== stack_pointer_rtx
)
3834 /* We'd better have found the stack pointer adjust. */
3837 /* Fall through to process the extracted SET and DEST
3838 as if it was a standalone insn. */
3840 else if (GET_CODE (pat
) == SET
)
3842 else if ((set
= single_set (insn
)) != NULL
)
3844 else if (GET_CODE (pat
) == PARALLEL
)
3846 /* ??? Some older ports use a parallel with a stack adjust
3847 and a store for a PUSH_ROUNDING pattern, rather than a
3848 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3849 /* ??? See h8300 and m68k, pushqi1. */
3850 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3852 set
= XVECEXP (pat
, 0, i
);
3853 if (GET_CODE (set
) != SET
)
3855 dest
= SET_DEST (set
);
3856 if (dest
== stack_pointer_rtx
)
3859 /* We do not expect an auto-inc of the sp in the parallel. */
3860 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3861 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3862 != stack_pointer_rtx
);
3870 dest
= SET_DEST (set
);
3872 /* Look for direct modifications of the stack pointer. */
3873 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3875 /* Look for a trivial adjustment, otherwise assume nothing. */
3876 /* Note that the SPU restore_stack_block pattern refers to
3877 the stack pointer in V4SImode. Consider that non-trivial. */
3878 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3879 && GET_CODE (SET_SRC (set
)) == PLUS
3880 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3881 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3882 return INTVAL (XEXP (SET_SRC (set
), 1));
3883 /* ??? Reload can generate no-op moves, which will be cleaned
3884 up later. Recognize it and continue searching. */
3885 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3888 return HOST_WIDE_INT_MIN
;
3894 /* Otherwise only think about autoinc patterns. */
3895 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3898 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3899 != stack_pointer_rtx
);
3901 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3902 mem
= SET_SRC (set
);
3906 addr
= XEXP (mem
, 0);
3907 switch (GET_CODE (addr
))
3911 return GET_MODE_SIZE (GET_MODE (mem
));
3914 return -GET_MODE_SIZE (GET_MODE (mem
));
3917 addr
= XEXP (addr
, 1);
3918 gcc_assert (GET_CODE (addr
) == PLUS
);
3919 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3920 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3921 return INTVAL (XEXP (addr
, 1));
3929 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
, int end_args_size
)
3931 int args_size
= end_args_size
;
3932 bool saw_unknown
= false;
3935 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3937 HOST_WIDE_INT this_delta
;
3939 if (!NONDEBUG_INSN_P (insn
))
3942 this_delta
= find_args_size_adjust (insn
);
3943 if (this_delta
== 0)
3946 || ACCUMULATE_OUTGOING_ARGS
3947 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3951 gcc_assert (!saw_unknown
);
3952 if (this_delta
== HOST_WIDE_INT_MIN
)
3955 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3956 if (STACK_GROWS_DOWNWARD
)
3957 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3959 args_size
-= this_delta
;
3962 return saw_unknown
? INT_MIN
: args_size
;
3965 #ifdef PUSH_ROUNDING
3966 /* Emit single push insn. */
3969 emit_single_push_insn_1 (machine_mode mode
, rtx x
, tree type
)
3972 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3974 enum insn_code icode
;
3976 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3977 /* If there is push pattern, use it. Otherwise try old way of throwing
3978 MEM representing push operation to move expander. */
3979 icode
= optab_handler (push_optab
, mode
);
3980 if (icode
!= CODE_FOR_nothing
)
3982 struct expand_operand ops
[1];
3984 create_input_operand (&ops
[0], x
, mode
);
3985 if (maybe_expand_insn (icode
, 1, ops
))
3988 if (GET_MODE_SIZE (mode
) == rounded_size
)
3989 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3990 /* If we are to pad downward, adjust the stack pointer first and
3991 then store X into the stack location using an offset. This is
3992 because emit_move_insn does not know how to pad; it does not have
3994 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3996 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3997 HOST_WIDE_INT offset
;
3999 emit_move_insn (stack_pointer_rtx
,
4000 expand_binop (Pmode
,
4001 STACK_GROWS_DOWNWARD
? sub_optab
4004 gen_int_mode (rounded_size
, Pmode
),
4005 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
4007 offset
= (HOST_WIDE_INT
) padding_size
;
4008 if (STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_DEC
)
4009 /* We have already decremented the stack pointer, so get the
4011 offset
+= (HOST_WIDE_INT
) rounded_size
;
4013 if (!STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_INC
)
4014 /* We have already incremented the stack pointer, so get the
4016 offset
-= (HOST_WIDE_INT
) rounded_size
;
4018 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4019 gen_int_mode (offset
, Pmode
));
4023 if (STACK_GROWS_DOWNWARD
)
4024 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4025 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4026 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4029 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4030 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4031 gen_int_mode (rounded_size
, Pmode
));
4033 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4036 dest
= gen_rtx_MEM (mode
, dest_addr
);
4040 set_mem_attributes (dest
, type
, 1);
4042 if (cfun
->tail_call_marked
)
4043 /* Function incoming arguments may overlap with sibling call
4044 outgoing arguments and we cannot allow reordering of reads
4045 from function arguments with stores to outgoing arguments
4046 of sibling calls. */
4047 set_mem_alias_set (dest
, 0);
4049 emit_move_insn (dest
, x
);
4052 /* Emit and annotate a single push insn. */
4055 emit_single_push_insn (machine_mode mode
, rtx x
, tree type
)
4057 int delta
, old_delta
= stack_pointer_delta
;
4058 rtx_insn
*prev
= get_last_insn ();
4061 emit_single_push_insn_1 (mode
, x
, type
);
4063 last
= get_last_insn ();
4065 /* Notice the common case where we emitted exactly one insn. */
4066 if (PREV_INSN (last
) == prev
)
4068 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4072 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4073 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4077 /* If reading SIZE bytes from X will end up reading from
4078 Y return the number of bytes that overlap. Return -1
4079 if there is no overlap or -2 if we can't determine
4080 (for example when X and Y have different base registers). */
4083 memory_load_overlap (rtx x
, rtx y
, HOST_WIDE_INT size
)
4085 rtx tmp
= plus_constant (Pmode
, x
, size
);
4086 rtx sub
= simplify_gen_binary (MINUS
, Pmode
, tmp
, y
);
4088 if (!CONST_INT_P (sub
))
4091 HOST_WIDE_INT val
= INTVAL (sub
);
4093 return IN_RANGE (val
, 1, size
) ? val
: -1;
4096 /* Generate code to push X onto the stack, assuming it has mode MODE and
4098 MODE is redundant except when X is a CONST_INT (since they don't
4100 SIZE is an rtx for the size of data to be copied (in bytes),
4101 needed only if X is BLKmode.
4102 Return true if successful. May return false if asked to push a
4103 partial argument during a sibcall optimization (as specified by
4104 SIBCALL_P) and the incoming and outgoing pointers cannot be shown
4107 ALIGN (in bits) is maximum alignment we can assume.
4109 If PARTIAL and REG are both nonzero, then copy that many of the first
4110 bytes of X into registers starting with REG, and push the rest of X.
4111 The amount of space pushed is decreased by PARTIAL bytes.
4112 REG must be a hard register in this case.
4113 If REG is zero but PARTIAL is not, take any all others actions for an
4114 argument partially in registers, but do not actually load any
4117 EXTRA is the amount in bytes of extra space to leave next to this arg.
4118 This is ignored if an argument block has already been allocated.
4120 On a machine that lacks real push insns, ARGS_ADDR is the address of
4121 the bottom of the argument block for this call. We use indexing off there
4122 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4123 argument block has not been preallocated.
4125 ARGS_SO_FAR is the size of args previously pushed for this call.
4127 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4128 for arguments passed in registers. If nonzero, it will be the number
4129 of bytes required. */
4132 emit_push_insn (rtx x
, machine_mode mode
, tree type
, rtx size
,
4133 unsigned int align
, int partial
, rtx reg
, int extra
,
4134 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4135 rtx alignment_pad
, bool sibcall_p
)
4138 enum direction stack_direction
= STACK_GROWS_DOWNWARD
? downward
: upward
;
4140 /* Decide where to pad the argument: `downward' for below,
4141 `upward' for above, or `none' for don't pad it.
4142 Default is below for small data on big-endian machines; else above. */
4143 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4145 /* Invert direction if stack is post-decrement.
4147 if (STACK_PUSH_CODE
== POST_DEC
)
4148 if (where_pad
!= none
)
4149 where_pad
= (where_pad
== downward
? upward
: downward
);
4153 int nregs
= partial
/ UNITS_PER_WORD
;
4154 rtx
*tmp_regs
= NULL
;
4155 int overlapping
= 0;
4158 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4160 /* Copy a block into the stack, entirely or partially. */
4167 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4168 used
= partial
- offset
;
4170 if (mode
!= BLKmode
)
4172 /* A value is to be stored in an insufficiently aligned
4173 stack slot; copy via a suitably aligned slot if
4175 size
= GEN_INT (GET_MODE_SIZE (mode
));
4176 if (!MEM_P (xinner
))
4178 temp
= assign_temp (type
, 1, 1);
4179 emit_move_insn (temp
, xinner
);
4186 /* USED is now the # of bytes we need not copy to the stack
4187 because registers will take care of them. */
4190 xinner
= adjust_address (xinner
, BLKmode
, used
);
4192 /* If the partial register-part of the arg counts in its stack size,
4193 skip the part of stack space corresponding to the registers.
4194 Otherwise, start copying to the beginning of the stack space,
4195 by setting SKIP to 0. */
4196 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4198 #ifdef PUSH_ROUNDING
4199 /* Do it with several push insns if that doesn't take lots of insns
4200 and if there is no difficulty with push insns that skip bytes
4201 on the stack for alignment purposes. */
4204 && CONST_INT_P (size
)
4206 && MEM_ALIGN (xinner
) >= align
4207 && can_move_by_pieces ((unsigned) INTVAL (size
) - used
, align
)
4208 /* Here we avoid the case of a structure whose weak alignment
4209 forces many pushes of a small amount of data,
4210 and such small pushes do rounding that causes trouble. */
4211 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4212 || align
>= BIGGEST_ALIGNMENT
4213 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4214 == (align
/ BITS_PER_UNIT
)))
4215 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4217 /* Push padding now if padding above and stack grows down,
4218 or if padding below and stack grows up.
4219 But if space already allocated, this has already been done. */
4220 if (extra
&& args_addr
== 0
4221 && where_pad
!= none
&& where_pad
!= stack_direction
)
4222 anti_adjust_stack (GEN_INT (extra
));
4224 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4227 #endif /* PUSH_ROUNDING */
4231 /* Otherwise make space on the stack and copy the data
4232 to the address of that space. */
4234 /* Deduct words put into registers from the size we must copy. */
4237 if (CONST_INT_P (size
))
4238 size
= GEN_INT (INTVAL (size
) - used
);
4240 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4241 gen_int_mode (used
, GET_MODE (size
)),
4242 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4245 /* Get the address of the stack space.
4246 In this case, we do not deal with EXTRA separately.
4247 A single stack adjust will do. */
4250 temp
= push_block (size
, extra
, where_pad
== downward
);
4253 else if (CONST_INT_P (args_so_far
))
4254 temp
= memory_address (BLKmode
,
4255 plus_constant (Pmode
, args_addr
,
4256 skip
+ INTVAL (args_so_far
)));
4258 temp
= memory_address (BLKmode
,
4259 plus_constant (Pmode
,
4260 gen_rtx_PLUS (Pmode
,
4265 if (!ACCUMULATE_OUTGOING_ARGS
)
4267 /* If the source is referenced relative to the stack pointer,
4268 copy it to another register to stabilize it. We do not need
4269 to do this if we know that we won't be changing sp. */
4271 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4272 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4273 temp
= copy_to_reg (temp
);
4276 target
= gen_rtx_MEM (BLKmode
, temp
);
4278 /* We do *not* set_mem_attributes here, because incoming arguments
4279 may overlap with sibling call outgoing arguments and we cannot
4280 allow reordering of reads from function arguments with stores
4281 to outgoing arguments of sibling calls. We do, however, want
4282 to record the alignment of the stack slot. */
4283 /* ALIGN may well be better aligned than TYPE, e.g. due to
4284 PARM_BOUNDARY. Assume the caller isn't lying. */
4285 set_mem_align (target
, align
);
4287 /* If part should go in registers and pushing to that part would
4288 overwrite some of the values that need to go into regs, load the
4289 overlapping values into temporary pseudos to be moved into the hard
4290 regs at the end after the stack pushing has completed.
4291 We cannot load them directly into the hard regs here because
4292 they can be clobbered by the block move expansions.
4295 if (partial
> 0 && reg
!= 0 && mode
== BLKmode
4296 && GET_CODE (reg
) != PARALLEL
)
4298 overlapping
= memory_load_overlap (XEXP (x
, 0), temp
, partial
);
4299 if (overlapping
> 0)
4301 gcc_assert (overlapping
% UNITS_PER_WORD
== 0);
4302 overlapping
/= UNITS_PER_WORD
;
4304 tmp_regs
= XALLOCAVEC (rtx
, overlapping
);
4306 for (int i
= 0; i
< overlapping
; i
++)
4307 tmp_regs
[i
] = gen_reg_rtx (word_mode
);
4309 for (int i
= 0; i
< overlapping
; i
++)
4310 emit_move_insn (tmp_regs
[i
],
4311 operand_subword_force (target
, i
, mode
));
4313 else if (overlapping
== -1)
4315 /* Could not determine whether there is overlap.
4316 Fail the sibcall. */
4324 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4327 else if (partial
> 0)
4329 /* Scalar partly in registers. */
4331 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4334 /* # bytes of start of argument
4335 that we must make space for but need not store. */
4336 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4337 int args_offset
= INTVAL (args_so_far
);
4340 /* Push padding now if padding above and stack grows down,
4341 or if padding below and stack grows up.
4342 But if space already allocated, this has already been done. */
4343 if (extra
&& args_addr
== 0
4344 && where_pad
!= none
&& where_pad
!= stack_direction
)
4345 anti_adjust_stack (GEN_INT (extra
));
4347 /* If we make space by pushing it, we might as well push
4348 the real data. Otherwise, we can leave OFFSET nonzero
4349 and leave the space uninitialized. */
4353 /* Now NOT_STACK gets the number of words that we don't need to
4354 allocate on the stack. Convert OFFSET to words too. */
4355 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4356 offset
/= UNITS_PER_WORD
;
4358 /* If the partial register-part of the arg counts in its stack size,
4359 skip the part of stack space corresponding to the registers.
4360 Otherwise, start copying to the beginning of the stack space,
4361 by setting SKIP to 0. */
4362 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4364 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4365 x
= validize_mem (force_const_mem (mode
, x
));
4367 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4368 SUBREGs of such registers are not allowed. */
4369 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4370 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4371 x
= copy_to_reg (x
);
4373 /* Loop over all the words allocated on the stack for this arg. */
4374 /* We can do it by words, because any scalar bigger than a word
4375 has a size a multiple of a word. */
4376 for (i
= size
- 1; i
>= not_stack
; i
--)
4377 if (i
>= not_stack
+ offset
)
4378 if (!emit_push_insn (operand_subword_force (x
, i
, mode
),
4379 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4381 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4383 reg_parm_stack_space
, alignment_pad
, sibcall_p
))
4391 /* Push padding now if padding above and stack grows down,
4392 or if padding below and stack grows up.
4393 But if space already allocated, this has already been done. */
4394 if (extra
&& args_addr
== 0
4395 && where_pad
!= none
&& where_pad
!= stack_direction
)
4396 anti_adjust_stack (GEN_INT (extra
));
4398 #ifdef PUSH_ROUNDING
4399 if (args_addr
== 0 && PUSH_ARGS
)
4400 emit_single_push_insn (mode
, x
, type
);
4404 if (CONST_INT_P (args_so_far
))
4406 = memory_address (mode
,
4407 plus_constant (Pmode
, args_addr
,
4408 INTVAL (args_so_far
)));
4410 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4412 dest
= gen_rtx_MEM (mode
, addr
);
4414 /* We do *not* set_mem_attributes here, because incoming arguments
4415 may overlap with sibling call outgoing arguments and we cannot
4416 allow reordering of reads from function arguments with stores
4417 to outgoing arguments of sibling calls. We do, however, want
4418 to record the alignment of the stack slot. */
4419 /* ALIGN may well be better aligned than TYPE, e.g. due to
4420 PARM_BOUNDARY. Assume the caller isn't lying. */
4421 set_mem_align (dest
, align
);
4423 emit_move_insn (dest
, x
);
4427 /* Move the partial arguments into the registers and any overlapping
4428 values that we moved into the pseudos in tmp_regs. */
4429 if (partial
> 0 && reg
!= 0)
4431 /* Handle calls that pass values in multiple non-contiguous locations.
4432 The Irix 6 ABI has examples of this. */
4433 if (GET_CODE (reg
) == PARALLEL
)
4434 emit_group_load (reg
, x
, type
, -1);
4437 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4438 move_block_to_reg (REGNO (reg
), x
, nregs
- overlapping
, mode
);
4440 for (int i
= 0; i
< overlapping
; i
++)
4441 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
)
4442 + nregs
- overlapping
+ i
),
4448 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4449 anti_adjust_stack (GEN_INT (extra
));
4451 if (alignment_pad
&& args_addr
== 0)
4452 anti_adjust_stack (alignment_pad
);
4457 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4461 get_subtarget (rtx x
)
4465 /* Only registers can be subtargets. */
4467 /* Don't use hard regs to avoid extending their life. */
4468 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4472 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4473 FIELD is a bitfield. Returns true if the optimization was successful,
4474 and there's nothing else to do. */
4477 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4478 unsigned HOST_WIDE_INT bitpos
,
4479 unsigned HOST_WIDE_INT bitregion_start
,
4480 unsigned HOST_WIDE_INT bitregion_end
,
4481 machine_mode mode1
, rtx str_rtx
,
4484 machine_mode str_mode
= GET_MODE (str_rtx
);
4485 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4490 enum tree_code code
;
4492 if (mode1
!= VOIDmode
4493 || bitsize
>= BITS_PER_WORD
4494 || str_bitsize
> BITS_PER_WORD
4495 || TREE_SIDE_EFFECTS (to
)
4496 || TREE_THIS_VOLATILE (to
))
4500 if (TREE_CODE (src
) != SSA_NAME
)
4502 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4505 srcstmt
= get_gimple_for_ssa_name (src
);
4507 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4510 code
= gimple_assign_rhs_code (srcstmt
);
4512 op0
= gimple_assign_rhs1 (srcstmt
);
4514 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4515 to find its initialization. Hopefully the initialization will
4516 be from a bitfield load. */
4517 if (TREE_CODE (op0
) == SSA_NAME
)
4519 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4521 /* We want to eventually have OP0 be the same as TO, which
4522 should be a bitfield. */
4524 || !is_gimple_assign (op0stmt
)
4525 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4527 op0
= gimple_assign_rhs1 (op0stmt
);
4530 op1
= gimple_assign_rhs2 (srcstmt
);
4532 if (!operand_equal_p (to
, op0
, 0))
4535 if (MEM_P (str_rtx
))
4537 unsigned HOST_WIDE_INT offset1
;
4539 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4540 str_mode
= word_mode
;
4541 str_mode
= get_best_mode (bitsize
, bitpos
,
4542 bitregion_start
, bitregion_end
,
4543 MEM_ALIGN (str_rtx
), str_mode
, 0);
4544 if (str_mode
== VOIDmode
)
4546 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4549 bitpos
%= str_bitsize
;
4550 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4551 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4553 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4556 /* If the bit field covers the whole REG/MEM, store_field
4557 will likely generate better code. */
4558 if (bitsize
>= str_bitsize
)
4561 /* We can't handle fields split across multiple entities. */
4562 if (bitpos
+ bitsize
> str_bitsize
)
4565 if (BYTES_BIG_ENDIAN
)
4566 bitpos
= str_bitsize
- bitpos
- bitsize
;
4572 /* For now, just optimize the case of the topmost bitfield
4573 where we don't need to do any masking and also
4574 1 bit bitfields where xor can be used.
4575 We might win by one instruction for the other bitfields
4576 too if insv/extv instructions aren't used, so that
4577 can be added later. */
4578 if (bitpos
+ bitsize
!= str_bitsize
4579 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4582 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4583 value
= convert_modes (str_mode
,
4584 TYPE_MODE (TREE_TYPE (op1
)), value
,
4585 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4587 /* We may be accessing data outside the field, which means
4588 we can alias adjacent data. */
4589 if (MEM_P (str_rtx
))
4591 str_rtx
= shallow_copy_rtx (str_rtx
);
4592 set_mem_alias_set (str_rtx
, 0);
4593 set_mem_expr (str_rtx
, 0);
4596 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4597 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4599 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4602 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4603 result
= expand_binop (str_mode
, binop
, str_rtx
,
4604 value
, str_rtx
, 1, OPTAB_WIDEN
);
4605 if (result
!= str_rtx
)
4606 emit_move_insn (str_rtx
, result
);
4611 if (TREE_CODE (op1
) != INTEGER_CST
)
4613 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4614 value
= convert_modes (str_mode
,
4615 TYPE_MODE (TREE_TYPE (op1
)), value
,
4616 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4618 /* We may be accessing data outside the field, which means
4619 we can alias adjacent data. */
4620 if (MEM_P (str_rtx
))
4622 str_rtx
= shallow_copy_rtx (str_rtx
);
4623 set_mem_alias_set (str_rtx
, 0);
4624 set_mem_expr (str_rtx
, 0);
4627 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4628 if (bitpos
+ bitsize
!= str_bitsize
)
4630 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4632 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4634 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4635 result
= expand_binop (str_mode
, binop
, str_rtx
,
4636 value
, str_rtx
, 1, OPTAB_WIDEN
);
4637 if (result
!= str_rtx
)
4638 emit_move_insn (str_rtx
, result
);
4648 /* In the C++ memory model, consecutive bit fields in a structure are
4649 considered one memory location.
4651 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4652 returns the bit range of consecutive bits in which this COMPONENT_REF
4653 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4654 and *OFFSET may be adjusted in the process.
4656 If the access does not need to be restricted, 0 is returned in both
4657 *BITSTART and *BITEND. */
4660 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4661 unsigned HOST_WIDE_INT
*bitend
,
4663 HOST_WIDE_INT
*bitpos
,
4666 HOST_WIDE_INT bitoffset
;
4669 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4671 field
= TREE_OPERAND (exp
, 1);
4672 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4673 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4674 need to limit the range we can access. */
4677 *bitstart
= *bitend
= 0;
4681 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4682 part of a larger bit field, then the representative does not serve any
4683 useful purpose. This can occur in Ada. */
4684 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4687 HOST_WIDE_INT rbitsize
, rbitpos
;
4691 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4692 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4693 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4695 *bitstart
= *bitend
= 0;
4700 /* Compute the adjustment to bitpos from the offset of the field
4701 relative to the representative. DECL_FIELD_OFFSET of field and
4702 repr are the same by construction if they are not constants,
4703 see finish_bitfield_layout. */
4704 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4705 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4706 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4707 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4710 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4711 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4713 /* If the adjustment is larger than bitpos, we would have a negative bit
4714 position for the lower bound and this may wreak havoc later. Adjust
4715 offset and bitpos to make the lower bound non-negative in that case. */
4716 if (bitoffset
> *bitpos
)
4718 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4719 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4722 if (*offset
== NULL_TREE
)
4723 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4726 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4730 *bitstart
= *bitpos
- bitoffset
;
4732 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4735 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4736 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4737 DECL_RTL was not set yet, return NORTL. */
4740 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4742 if (TREE_CODE (addr
) != ADDR_EXPR
)
4745 tree base
= TREE_OPERAND (addr
, 0);
4748 || TREE_ADDRESSABLE (base
)
4749 || DECL_MODE (base
) == BLKmode
)
4752 if (!DECL_RTL_SET_P (base
))
4755 return (!MEM_P (DECL_RTL (base
)));
4758 /* Returns true if the MEM_REF REF refers to an object that does not
4759 reside in memory and has non-BLKmode. */
4762 mem_ref_refers_to_non_mem_p (tree ref
)
4764 tree base
= TREE_OPERAND (ref
, 0);
4765 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4768 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4769 is true, try generating a nontemporal store. */
4772 expand_assignment (tree to
, tree from
, bool nontemporal
)
4778 enum insn_code icode
;
4780 /* Don't crash if the lhs of the assignment was erroneous. */
4781 if (TREE_CODE (to
) == ERROR_MARK
)
4783 expand_normal (from
);
4787 /* Optimize away no-op moves without side-effects. */
4788 if (operand_equal_p (to
, from
, 0))
4791 /* Handle misaligned stores. */
4792 mode
= TYPE_MODE (TREE_TYPE (to
));
4793 if ((TREE_CODE (to
) == MEM_REF
4794 || TREE_CODE (to
) == TARGET_MEM_REF
)
4796 && !mem_ref_refers_to_non_mem_p (to
)
4797 && ((align
= get_object_alignment (to
))
4798 < GET_MODE_ALIGNMENT (mode
))
4799 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4800 != CODE_FOR_nothing
)
4801 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4805 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4806 reg
= force_not_mem (reg
);
4807 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4809 if (icode
!= CODE_FOR_nothing
)
4811 struct expand_operand ops
[2];
4813 create_fixed_operand (&ops
[0], mem
);
4814 create_input_operand (&ops
[1], reg
, mode
);
4815 /* The movmisalign<mode> pattern cannot fail, else the assignment
4816 would silently be omitted. */
4817 expand_insn (icode
, 2, ops
);
4820 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
);
4824 /* Assignment of a structure component needs special treatment
4825 if the structure component's rtx is not simply a MEM.
4826 Assignment of an array element at a constant index, and assignment of
4827 an array element in an unaligned packed structure field, has the same
4828 problem. Same for (partially) storing into a non-memory object. */
4829 if (handled_component_p (to
)
4830 || (TREE_CODE (to
) == MEM_REF
4831 && mem_ref_refers_to_non_mem_p (to
))
4832 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4835 HOST_WIDE_INT bitsize
, bitpos
;
4836 unsigned HOST_WIDE_INT bitregion_start
= 0;
4837 unsigned HOST_WIDE_INT bitregion_end
= 0;
4844 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4845 &unsignedp
, &volatilep
, true);
4847 /* Make sure bitpos is not negative, it can wreak havoc later. */
4850 gcc_assert (offset
== NULL_TREE
);
4851 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4852 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4853 bitpos
&= BITS_PER_UNIT
- 1;
4856 if (TREE_CODE (to
) == COMPONENT_REF
4857 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4858 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4859 /* The C++ memory model naturally applies to byte-aligned fields.
4860 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
4861 BITSIZE are not byte-aligned, there is no need to limit the range
4862 we can access. This can occur with packed structures in Ada. */
4863 else if (bitsize
> 0
4864 && bitsize
% BITS_PER_UNIT
== 0
4865 && bitpos
% BITS_PER_UNIT
== 0)
4867 bitregion_start
= bitpos
;
4868 bitregion_end
= bitpos
+ bitsize
- 1;
4871 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4873 /* If the field has a mode, we want to access it in the
4874 field's mode, not the computed mode.
4875 If a MEM has VOIDmode (external with incomplete type),
4876 use BLKmode for it instead. */
4879 if (mode1
!= VOIDmode
)
4880 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4881 else if (GET_MODE (to_rtx
) == VOIDmode
)
4882 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4887 machine_mode address_mode
;
4890 if (!MEM_P (to_rtx
))
4892 /* We can get constant negative offsets into arrays with broken
4893 user code. Translate this to a trap instead of ICEing. */
4894 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4895 expand_builtin_trap ();
4896 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4899 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4900 address_mode
= get_address_mode (to_rtx
);
4901 if (GET_MODE (offset_rtx
) != address_mode
)
4903 /* We cannot be sure that the RTL in offset_rtx is valid outside
4904 of a memory address context, so force it into a register
4905 before attempting to convert it to the desired mode. */
4906 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
4907 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4910 /* If we have an expression in OFFSET_RTX and a non-zero
4911 byte offset in BITPOS, adding the byte offset before the
4912 OFFSET_RTX results in better intermediate code, which makes
4913 later rtl optimization passes perform better.
4915 We prefer intermediate code like this:
4917 r124:DI=r123:DI+0x18
4922 r124:DI=r123:DI+0x10
4923 [r124:DI+0x8]=r121:DI
4925 This is only done for aligned data values, as these can
4926 be expected to result in single move instructions. */
4927 if (mode1
!= VOIDmode
4930 && (bitpos
% bitsize
) == 0
4931 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4932 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
4934 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4935 bitregion_start
= 0;
4936 if (bitregion_end
>= (unsigned HOST_WIDE_INT
) bitpos
)
4937 bitregion_end
-= bitpos
;
4941 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4942 highest_pow2_factor_for_target (to
,
4946 /* No action is needed if the target is not a memory and the field
4947 lies completely outside that target. This can occur if the source
4948 code contains an out-of-bounds access to a small array. */
4950 && GET_MODE (to_rtx
) != BLKmode
4951 && (unsigned HOST_WIDE_INT
) bitpos
4952 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4954 expand_normal (from
);
4957 /* Handle expand_expr of a complex value returning a CONCAT. */
4958 else if (GET_CODE (to_rtx
) == CONCAT
)
4960 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4961 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4963 && bitsize
== mode_bitsize
)
4964 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4965 else if (bitsize
== mode_bitsize
/ 2
4966 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4967 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4969 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4970 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4971 bitregion_start
, bitregion_end
,
4973 get_alias_set (to
), nontemporal
);
4974 else if (bitpos
>= mode_bitsize
/ 2)
4975 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4976 bitpos
- mode_bitsize
/ 2,
4977 bitregion_start
, bitregion_end
,
4979 get_alias_set (to
), nontemporal
);
4980 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4983 result
= expand_normal (from
);
4984 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4985 TYPE_MODE (TREE_TYPE (from
)), 0);
4986 emit_move_insn (XEXP (to_rtx
, 0),
4987 read_complex_part (from_rtx
, false));
4988 emit_move_insn (XEXP (to_rtx
, 1),
4989 read_complex_part (from_rtx
, true));
4993 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4994 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4995 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4996 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4997 result
= store_field (temp
, bitsize
, bitpos
,
4998 bitregion_start
, bitregion_end
,
5000 get_alias_set (to
), nontemporal
);
5001 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
5002 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
5009 /* If the field is at offset zero, we could have been given the
5010 DECL_RTX of the parent struct. Don't munge it. */
5011 to_rtx
= shallow_copy_rtx (to_rtx
);
5012 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
5014 MEM_VOLATILE_P (to_rtx
) = 1;
5017 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
5018 bitregion_start
, bitregion_end
,
5023 result
= store_field (to_rtx
, bitsize
, bitpos
,
5024 bitregion_start
, bitregion_end
,
5026 get_alias_set (to
), nontemporal
);
5030 preserve_temp_slots (result
);
5035 /* If the rhs is a function call and its value is not an aggregate,
5036 call the function before we start to compute the lhs.
5037 This is needed for correct code for cases such as
5038 val = setjmp (buf) on machines where reference to val
5039 requires loading up part of an address in a separate insn.
5041 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
5042 since it might be a promoted variable where the zero- or sign- extension
5043 needs to be done. Handling this in the normal way is safe because no
5044 computation is done before the call. The same is true for SSA names. */
5045 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
5046 && COMPLETE_TYPE_P (TREE_TYPE (from
))
5047 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
5048 && ! (((TREE_CODE (to
) == VAR_DECL
5049 || TREE_CODE (to
) == PARM_DECL
5050 || TREE_CODE (to
) == RESULT_DECL
)
5051 && REG_P (DECL_RTL (to
)))
5052 || TREE_CODE (to
) == SSA_NAME
))
5058 value
= expand_normal (from
);
5060 /* Split value and bounds to store them separately. */
5061 chkp_split_slot (value
, &value
, &bounds
);
5064 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5066 /* Handle calls that return values in multiple non-contiguous locations.
5067 The Irix 6 ABI has examples of this. */
5068 if (GET_CODE (to_rtx
) == PARALLEL
)
5070 if (GET_CODE (value
) == PARALLEL
)
5071 emit_group_move (to_rtx
, value
);
5073 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5074 int_size_in_bytes (TREE_TYPE (from
)));
5076 else if (GET_CODE (value
) == PARALLEL
)
5077 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5078 int_size_in_bytes (TREE_TYPE (from
)));
5079 else if (GET_MODE (to_rtx
) == BLKmode
)
5081 /* Handle calls that return BLKmode values in registers. */
5083 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5085 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5089 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5090 value
= convert_memory_address_addr_space
5091 (GET_MODE (to_rtx
), value
,
5092 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5094 emit_move_insn (to_rtx
, value
);
5097 /* Store bounds if required. */
5099 && (BOUNDED_P (to
) || chkp_type_has_pointer (TREE_TYPE (to
))))
5101 gcc_assert (MEM_P (to_rtx
));
5102 chkp_emit_bounds_store (bounds
, value
, to_rtx
);
5105 preserve_temp_slots (to_rtx
);
5110 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5111 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5113 /* Don't move directly into a return register. */
5114 if (TREE_CODE (to
) == RESULT_DECL
5115 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5121 /* If the source is itself a return value, it still is in a pseudo at
5122 this point so we can move it back to the return register directly. */
5124 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5125 && TREE_CODE (from
) != CALL_EXPR
)
5126 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5128 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5130 /* Handle calls that return values in multiple non-contiguous locations.
5131 The Irix 6 ABI has examples of this. */
5132 if (GET_CODE (to_rtx
) == PARALLEL
)
5134 if (GET_CODE (temp
) == PARALLEL
)
5135 emit_group_move (to_rtx
, temp
);
5137 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5138 int_size_in_bytes (TREE_TYPE (from
)));
5141 emit_move_insn (to_rtx
, temp
);
5143 preserve_temp_slots (to_rtx
);
5148 /* In case we are returning the contents of an object which overlaps
5149 the place the value is being stored, use a safe function when copying
5150 a value through a pointer into a structure value return block. */
5151 if (TREE_CODE (to
) == RESULT_DECL
5152 && TREE_CODE (from
) == INDIRECT_REF
5153 && ADDR_SPACE_GENERIC_P
5154 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5155 && refs_may_alias_p (to
, from
)
5156 && cfun
->returns_struct
5157 && !cfun
->returns_pcc_struct
)
5162 size
= expr_size (from
);
5163 from_rtx
= expand_normal (from
);
5165 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5166 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5167 XEXP (from_rtx
, 0), Pmode
,
5168 convert_to_mode (TYPE_MODE (sizetype
),
5169 size
, TYPE_UNSIGNED (sizetype
)),
5170 TYPE_MODE (sizetype
));
5172 preserve_temp_slots (to_rtx
);
5177 /* Compute FROM and store the value in the rtx we got. */
5180 result
= store_expr_with_bounds (from
, to_rtx
, 0, nontemporal
, to
);
5181 preserve_temp_slots (result
);
5186 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5187 succeeded, false otherwise. */
5190 emit_storent_insn (rtx to
, rtx from
)
5192 struct expand_operand ops
[2];
5193 machine_mode mode
= GET_MODE (to
);
5194 enum insn_code code
= optab_handler (storent_optab
, mode
);
5196 if (code
== CODE_FOR_nothing
)
5199 create_fixed_operand (&ops
[0], to
);
5200 create_input_operand (&ops
[1], from
, mode
);
5201 return maybe_expand_insn (code
, 2, ops
);
5204 /* Generate code for computing expression EXP,
5205 and storing the value into TARGET.
5207 If the mode is BLKmode then we may return TARGET itself.
5208 It turns out that in BLKmode it doesn't cause a problem.
5209 because C has no operators that could combine two different
5210 assignments into the same BLKmode object with different values
5211 with no sequence point. Will other languages need this to
5214 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5215 stack, and block moves may need to be treated specially.
5217 If NONTEMPORAL is true, try using a nontemporal store instruction.
5219 If BTARGET is not NULL then computed bounds of EXP are
5220 associated with BTARGET. */
5223 store_expr_with_bounds (tree exp
, rtx target
, int call_param_p
,
5224 bool nontemporal
, tree btarget
)
5227 rtx alt_rtl
= NULL_RTX
;
5228 location_t loc
= curr_insn_location ();
5230 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5232 /* C++ can generate ?: expressions with a throw expression in one
5233 branch and an rvalue in the other. Here, we resolve attempts to
5234 store the throw expression's nonexistent result. */
5235 gcc_assert (!call_param_p
);
5236 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5239 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5241 /* Perform first part of compound expression, then assign from second
5243 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5244 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5245 return store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
,
5246 call_param_p
, nontemporal
, btarget
);
5248 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5250 /* For conditional expression, get safe form of the target. Then
5251 test the condition, doing the appropriate assignment on either
5252 side. This avoids the creation of unnecessary temporaries.
5253 For non-BLKmode, it is more efficient not to do this. */
5255 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
5257 do_pending_stack_adjust ();
5259 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5260 store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5261 nontemporal
, btarget
);
5262 emit_jump_insn (targetm
.gen_jump (lab2
));
5265 store_expr_with_bounds (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5266 nontemporal
, btarget
);
5272 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5273 /* If this is a scalar in a register that is stored in a wider mode
5274 than the declared mode, compute the result into its declared mode
5275 and then convert to the wider mode. Our value is the computed
5278 rtx inner_target
= 0;
5280 /* We can do the conversion inside EXP, which will often result
5281 in some optimizations. Do the conversion in two steps: first
5282 change the signedness, if needed, then the extend. But don't
5283 do this if the type of EXP is a subtype of something else
5284 since then the conversion might involve more than just
5285 converting modes. */
5286 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5287 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5288 && GET_MODE_PRECISION (GET_MODE (target
))
5289 == TYPE_PRECISION (TREE_TYPE (exp
)))
5291 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
5292 TYPE_UNSIGNED (TREE_TYPE (exp
))))
5294 /* Some types, e.g. Fortran's logical*4, won't have a signed
5295 version, so use the mode instead. */
5297 = (signed_or_unsigned_type_for
5298 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
5300 ntype
= lang_hooks
.types
.type_for_mode
5301 (TYPE_MODE (TREE_TYPE (exp
)),
5302 SUBREG_PROMOTED_SIGN (target
));
5304 exp
= fold_convert_loc (loc
, ntype
, exp
);
5307 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5308 (GET_MODE (SUBREG_REG (target
)),
5309 SUBREG_PROMOTED_SIGN (target
)),
5312 inner_target
= SUBREG_REG (target
);
5315 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5316 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5318 /* Handle bounds returned by call. */
5319 if (TREE_CODE (exp
) == CALL_EXPR
)
5322 chkp_split_slot (temp
, &temp
, &bounds
);
5323 if (bounds
&& btarget
)
5325 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5326 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5327 chkp_set_rtl_bounds (btarget
, tmp
);
5331 /* If TEMP is a VOIDmode constant, use convert_modes to make
5332 sure that we properly convert it. */
5333 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5335 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5336 temp
, SUBREG_PROMOTED_SIGN (target
));
5337 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5338 GET_MODE (target
), temp
,
5339 SUBREG_PROMOTED_SIGN (target
));
5342 convert_move (SUBREG_REG (target
), temp
,
5343 SUBREG_PROMOTED_SIGN (target
));
5347 else if ((TREE_CODE (exp
) == STRING_CST
5348 || (TREE_CODE (exp
) == MEM_REF
5349 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5350 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5352 && integer_zerop (TREE_OPERAND (exp
, 1))))
5353 && !nontemporal
&& !call_param_p
5356 /* Optimize initialization of an array with a STRING_CST. */
5357 HOST_WIDE_INT exp_len
, str_copy_len
;
5359 tree str
= TREE_CODE (exp
) == STRING_CST
5360 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5362 exp_len
= int_expr_size (exp
);
5366 if (TREE_STRING_LENGTH (str
) <= 0)
5369 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5370 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5373 str_copy_len
= TREE_STRING_LENGTH (str
);
5374 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5375 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5377 str_copy_len
+= STORE_MAX_PIECES
- 1;
5378 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5380 str_copy_len
= MIN (str_copy_len
, exp_len
);
5381 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5382 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5383 MEM_ALIGN (target
), false))
5388 dest_mem
= store_by_pieces (dest_mem
,
5389 str_copy_len
, builtin_strncpy_read_str
,
5391 TREE_STRING_POINTER (str
)),
5392 MEM_ALIGN (target
), false,
5393 exp_len
> str_copy_len
? 1 : 0);
5394 if (exp_len
> str_copy_len
)
5395 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5396 GEN_INT (exp_len
- str_copy_len
),
5405 /* If we want to use a nontemporal store, force the value to
5407 tmp_target
= nontemporal
? NULL_RTX
: target
;
5408 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5410 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5413 /* Handle bounds returned by call. */
5414 if (TREE_CODE (exp
) == CALL_EXPR
)
5417 chkp_split_slot (temp
, &temp
, &bounds
);
5418 if (bounds
&& btarget
)
5420 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5421 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5422 chkp_set_rtl_bounds (btarget
, tmp
);
5427 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5428 the same as that of TARGET, adjust the constant. This is needed, for
5429 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5430 only a word-sized value. */
5431 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5432 && TREE_CODE (exp
) != ERROR_MARK
5433 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5434 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5435 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5437 /* If value was not generated in the target, store it there.
5438 Convert the value to TARGET's type first if necessary and emit the
5439 pending incrementations that have been queued when expanding EXP.
5440 Note that we cannot emit the whole queue blindly because this will
5441 effectively disable the POST_INC optimization later.
5443 If TEMP and TARGET compare equal according to rtx_equal_p, but
5444 one or both of them are volatile memory refs, we have to distinguish
5446 - expand_expr has used TARGET. In this case, we must not generate
5447 another copy. This can be detected by TARGET being equal according
5449 - expand_expr has not used TARGET - that means that the source just
5450 happens to have the same RTX form. Since temp will have been created
5451 by expand_expr, it will compare unequal according to == .
5452 We must generate a copy in this case, to reach the correct number
5453 of volatile memory references. */
5455 if ((! rtx_equal_p (temp
, target
)
5456 || (temp
!= target
&& (side_effects_p (temp
)
5457 || side_effects_p (target
))))
5458 && TREE_CODE (exp
) != ERROR_MARK
5459 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5460 but TARGET is not valid memory reference, TEMP will differ
5461 from TARGET although it is really the same location. */
5463 && rtx_equal_p (alt_rtl
, target
)
5464 && !side_effects_p (alt_rtl
)
5465 && !side_effects_p (target
))
5466 /* If there's nothing to copy, don't bother. Don't call
5467 expr_size unless necessary, because some front-ends (C++)
5468 expr_size-hook must not be given objects that are not
5469 supposed to be bit-copied or bit-initialized. */
5470 && expr_size (exp
) != const0_rtx
)
5472 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5474 if (GET_MODE (target
) == BLKmode
)
5476 /* Handle calls that return BLKmode values in registers. */
5477 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5478 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5480 store_bit_field (target
,
5481 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5482 0, 0, 0, GET_MODE (temp
), temp
);
5485 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5488 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5490 /* Handle copying a string constant into an array. The string
5491 constant may be shorter than the array. So copy just the string's
5492 actual length, and clear the rest. First get the size of the data
5493 type of the string, which is actually the size of the target. */
5494 rtx size
= expr_size (exp
);
5496 if (CONST_INT_P (size
)
5497 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5498 emit_block_move (target
, temp
, size
,
5500 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5503 machine_mode pointer_mode
5504 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5505 machine_mode address_mode
= get_address_mode (target
);
5507 /* Compute the size of the data to copy from the string. */
5509 = size_binop_loc (loc
, MIN_EXPR
,
5510 make_tree (sizetype
, size
),
5511 size_int (TREE_STRING_LENGTH (exp
)));
5513 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5515 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5516 rtx_code_label
*label
= 0;
5518 /* Copy that much. */
5519 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5520 TYPE_UNSIGNED (sizetype
));
5521 emit_block_move (target
, temp
, copy_size_rtx
,
5523 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5525 /* Figure out how much is left in TARGET that we have to clear.
5526 Do all calculations in pointer_mode. */
5527 if (CONST_INT_P (copy_size_rtx
))
5529 size
= plus_constant (address_mode
, size
,
5530 -INTVAL (copy_size_rtx
));
5531 target
= adjust_address (target
, BLKmode
,
5532 INTVAL (copy_size_rtx
));
5536 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5537 copy_size_rtx
, NULL_RTX
, 0,
5540 if (GET_MODE (copy_size_rtx
) != address_mode
)
5541 copy_size_rtx
= convert_to_mode (address_mode
,
5543 TYPE_UNSIGNED (sizetype
));
5545 target
= offset_address (target
, copy_size_rtx
,
5546 highest_pow2_factor (copy_size
));
5547 label
= gen_label_rtx ();
5548 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5549 GET_MODE (size
), 0, label
);
5552 if (size
!= const0_rtx
)
5553 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5559 /* Handle calls that return values in multiple non-contiguous locations.
5560 The Irix 6 ABI has examples of this. */
5561 else if (GET_CODE (target
) == PARALLEL
)
5563 if (GET_CODE (temp
) == PARALLEL
)
5564 emit_group_move (target
, temp
);
5566 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5567 int_size_in_bytes (TREE_TYPE (exp
)));
5569 else if (GET_CODE (temp
) == PARALLEL
)
5570 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5571 int_size_in_bytes (TREE_TYPE (exp
)));
5572 else if (GET_MODE (temp
) == BLKmode
)
5573 emit_block_move (target
, temp
, expr_size (exp
),
5575 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5576 /* If we emit a nontemporal store, there is nothing else to do. */
5577 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5581 temp
= force_operand (temp
, target
);
5583 emit_move_insn (target
, temp
);
5590 /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
5592 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5594 return store_expr_with_bounds (exp
, target
, call_param_p
, nontemporal
, NULL
);
5597 /* Return true if field F of structure TYPE is a flexible array. */
5600 flexible_array_member_p (const_tree f
, const_tree type
)
5605 return (DECL_CHAIN (f
) == NULL
5606 && TREE_CODE (tf
) == ARRAY_TYPE
5608 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5609 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5610 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5611 && int_size_in_bytes (type
) >= 0);
5614 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5615 must have in order for it to completely initialize a value of type TYPE.
5616 Return -1 if the number isn't known.
5618 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5620 static HOST_WIDE_INT
5621 count_type_elements (const_tree type
, bool for_ctor_p
)
5623 switch (TREE_CODE (type
))
5629 nelts
= array_type_nelts (type
);
5630 if (nelts
&& tree_fits_uhwi_p (nelts
))
5632 unsigned HOST_WIDE_INT n
;
5634 n
= tree_to_uhwi (nelts
) + 1;
5635 if (n
== 0 || for_ctor_p
)
5638 return n
* count_type_elements (TREE_TYPE (type
), false);
5640 return for_ctor_p
? -1 : 1;
5645 unsigned HOST_WIDE_INT n
;
5649 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5650 if (TREE_CODE (f
) == FIELD_DECL
)
5653 n
+= count_type_elements (TREE_TYPE (f
), false);
5654 else if (!flexible_array_member_p (f
, type
))
5655 /* Don't count flexible arrays, which are not supposed
5656 to be initialized. */
5664 case QUAL_UNION_TYPE
:
5669 gcc_assert (!for_ctor_p
);
5670 /* Estimate the number of scalars in each field and pick the
5671 maximum. Other estimates would do instead; the idea is simply
5672 to make sure that the estimate is not sensitive to the ordering
5675 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5676 if (TREE_CODE (f
) == FIELD_DECL
)
5678 m
= count_type_elements (TREE_TYPE (f
), false);
5679 /* If the field doesn't span the whole union, add an extra
5680 scalar for the rest. */
5681 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5682 TYPE_SIZE (type
)) != 1)
5694 return TYPE_VECTOR_SUBPARTS (type
);
5698 case FIXED_POINT_TYPE
:
5703 case REFERENCE_TYPE
:
5719 /* Helper for categorize_ctor_elements. Identical interface. */
5722 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5723 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5725 unsigned HOST_WIDE_INT idx
;
5726 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5727 tree value
, purpose
, elt_type
;
5729 /* Whether CTOR is a valid constant initializer, in accordance with what
5730 initializer_constant_valid_p does. If inferred from the constructor
5731 elements, true until proven otherwise. */
5732 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5733 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5738 elt_type
= NULL_TREE
;
5740 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5742 HOST_WIDE_INT mult
= 1;
5744 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5746 tree lo_index
= TREE_OPERAND (purpose
, 0);
5747 tree hi_index
= TREE_OPERAND (purpose
, 1);
5749 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5750 mult
= (tree_to_uhwi (hi_index
)
5751 - tree_to_uhwi (lo_index
) + 1);
5754 elt_type
= TREE_TYPE (value
);
5756 switch (TREE_CODE (value
))
5760 HOST_WIDE_INT nz
= 0, ic
= 0;
5762 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5765 nz_elts
+= mult
* nz
;
5766 init_elts
+= mult
* ic
;
5768 if (const_from_elts_p
&& const_p
)
5769 const_p
= const_elt_p
;
5776 if (!initializer_zerop (value
))
5782 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5783 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5787 if (!initializer_zerop (TREE_REALPART (value
)))
5789 if (!initializer_zerop (TREE_IMAGPART (value
)))
5797 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5799 tree v
= VECTOR_CST_ELT (value
, i
);
5800 if (!initializer_zerop (v
))
5809 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5810 nz_elts
+= mult
* tc
;
5811 init_elts
+= mult
* tc
;
5813 if (const_from_elts_p
&& const_p
)
5814 const_p
= initializer_constant_valid_p (value
, elt_type
)
5821 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5822 num_fields
, elt_type
))
5823 *p_complete
= false;
5825 *p_nz_elts
+= nz_elts
;
5826 *p_init_elts
+= init_elts
;
5831 /* Examine CTOR to discover:
5832 * how many scalar fields are set to nonzero values,
5833 and place it in *P_NZ_ELTS;
5834 * how many scalar fields in total are in CTOR,
5835 and place it in *P_ELT_COUNT.
5836 * whether the constructor is complete -- in the sense that every
5837 meaningful byte is explicitly given a value --
5838 and place it in *P_COMPLETE.
5840 Return whether or not CTOR is a valid static constant initializer, the same
5841 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5844 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5845 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5851 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5854 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5855 of which had type LAST_TYPE. Each element was itself a complete
5856 initializer, in the sense that every meaningful byte was explicitly
5857 given a value. Return true if the same is true for the constructor
5861 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5862 const_tree last_type
)
5864 if (TREE_CODE (type
) == UNION_TYPE
5865 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5870 gcc_assert (num_elts
== 1 && last_type
);
5872 /* ??? We could look at each element of the union, and find the
5873 largest element. Which would avoid comparing the size of the
5874 initialized element against any tail padding in the union.
5875 Doesn't seem worth the effort... */
5876 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5879 return count_type_elements (type
, true) == num_elts
;
5882 /* Return 1 if EXP contains mostly (3/4) zeros. */
5885 mostly_zeros_p (const_tree exp
)
5887 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5889 HOST_WIDE_INT nz_elts
, init_elts
;
5892 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5893 return !complete_p
|| nz_elts
< init_elts
/ 4;
5896 return initializer_zerop (exp
);
5899 /* Return 1 if EXP contains all zeros. */
5902 all_zeros_p (const_tree exp
)
5904 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5906 HOST_WIDE_INT nz_elts
, init_elts
;
5909 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5910 return nz_elts
== 0;
5913 return initializer_zerop (exp
);
5916 /* Helper function for store_constructor.
5917 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5918 CLEARED is as for store_constructor.
5919 ALIAS_SET is the alias set to use for any stores.
5921 This provides a recursive shortcut back to store_constructor when it isn't
5922 necessary to go through store_field. This is so that we can pass through
5923 the cleared field to let store_constructor know that we may not have to
5924 clear a substructure if the outer structure has already been cleared. */
5927 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5928 HOST_WIDE_INT bitpos
, machine_mode mode
,
5929 tree exp
, int cleared
, alias_set_type alias_set
)
5931 if (TREE_CODE (exp
) == CONSTRUCTOR
5932 /* We can only call store_constructor recursively if the size and
5933 bit position are on a byte boundary. */
5934 && bitpos
% BITS_PER_UNIT
== 0
5935 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5936 /* If we have a nonzero bitpos for a register target, then we just
5937 let store_field do the bitfield handling. This is unlikely to
5938 generate unnecessary clear instructions anyways. */
5939 && (bitpos
== 0 || MEM_P (target
)))
5943 = adjust_address (target
,
5944 GET_MODE (target
) == BLKmode
5946 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5947 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5950 /* Update the alias set, if required. */
5951 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5952 && MEM_ALIAS_SET (target
) != 0)
5954 target
= copy_rtx (target
);
5955 set_mem_alias_set (target
, alias_set
);
5958 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5961 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5965 /* Returns the number of FIELD_DECLs in TYPE. */
5968 fields_length (const_tree type
)
5970 tree t
= TYPE_FIELDS (type
);
5973 for (; t
; t
= DECL_CHAIN (t
))
5974 if (TREE_CODE (t
) == FIELD_DECL
)
5981 /* Store the value of constructor EXP into the rtx TARGET.
5982 TARGET is either a REG or a MEM; we know it cannot conflict, since
5983 safe_from_p has been called.
5984 CLEARED is true if TARGET is known to have been zero'd.
5985 SIZE is the number of bytes of TARGET we are allowed to modify: this
5986 may not be the same as the size of EXP if we are assigning to a field
5987 which has been packed to exclude padding bits. */
5990 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5992 tree type
= TREE_TYPE (exp
);
5993 #ifdef WORD_REGISTER_OPERATIONS
5994 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5997 switch (TREE_CODE (type
))
6001 case QUAL_UNION_TYPE
:
6003 unsigned HOST_WIDE_INT idx
;
6006 /* If size is zero or the target is already cleared, do nothing. */
6007 if (size
== 0 || cleared
)
6009 /* We either clear the aggregate or indicate the value is dead. */
6010 else if ((TREE_CODE (type
) == UNION_TYPE
6011 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
6012 && ! CONSTRUCTOR_ELTS (exp
))
6013 /* If the constructor is empty, clear the union. */
6015 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
6019 /* If we are building a static constructor into a register,
6020 set the initial value as zero so we can fold the value into
6021 a constant. But if more than one register is involved,
6022 this probably loses. */
6023 else if (REG_P (target
) && TREE_STATIC (exp
)
6024 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
6026 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6030 /* If the constructor has fewer fields than the structure or
6031 if we are initializing the structure to mostly zeros, clear
6032 the whole structure first. Don't do this if TARGET is a
6033 register whose mode size isn't equal to SIZE since
6034 clear_storage can't handle this case. */
6036 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
6037 != fields_length (type
))
6038 || mostly_zeros_p (exp
))
6040 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
6043 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6047 if (REG_P (target
) && !cleared
)
6048 emit_clobber (target
);
6050 /* Store each element of the constructor into the
6051 corresponding field of TARGET. */
6052 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
6055 HOST_WIDE_INT bitsize
;
6056 HOST_WIDE_INT bitpos
= 0;
6058 rtx to_rtx
= target
;
6060 /* Just ignore missing fields. We cleared the whole
6061 structure, above, if any fields are missing. */
6065 if (cleared
&& initializer_zerop (value
))
6068 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
6069 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
6073 mode
= DECL_MODE (field
);
6074 if (DECL_BIT_FIELD (field
))
6077 offset
= DECL_FIELD_OFFSET (field
);
6078 if (tree_fits_shwi_p (offset
)
6079 && tree_fits_shwi_p (bit_position (field
)))
6081 bitpos
= int_bit_position (field
);
6085 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
6089 machine_mode address_mode
;
6093 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
6094 make_tree (TREE_TYPE (exp
),
6097 offset_rtx
= expand_normal (offset
);
6098 gcc_assert (MEM_P (to_rtx
));
6100 address_mode
= get_address_mode (to_rtx
);
6101 if (GET_MODE (offset_rtx
) != address_mode
)
6102 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6104 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6105 highest_pow2_factor (offset
));
6108 #ifdef WORD_REGISTER_OPERATIONS
6109 /* If this initializes a field that is smaller than a
6110 word, at the start of a word, try to widen it to a full
6111 word. This special case allows us to output C++ member
6112 function initializations in a form that the optimizers
6115 && bitsize
< BITS_PER_WORD
6116 && bitpos
% BITS_PER_WORD
== 0
6117 && GET_MODE_CLASS (mode
) == MODE_INT
6118 && TREE_CODE (value
) == INTEGER_CST
6120 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6122 tree type
= TREE_TYPE (value
);
6124 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6126 type
= lang_hooks
.types
.type_for_mode
6127 (word_mode
, TYPE_UNSIGNED (type
));
6128 value
= fold_convert (type
, value
);
6131 if (BYTES_BIG_ENDIAN
)
6133 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6134 build_int_cst (type
,
6135 BITS_PER_WORD
- bitsize
));
6136 bitsize
= BITS_PER_WORD
;
6141 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6142 && DECL_NONADDRESSABLE_P (field
))
6144 to_rtx
= copy_rtx (to_rtx
);
6145 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6148 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6150 get_alias_set (TREE_TYPE (field
)));
6157 unsigned HOST_WIDE_INT i
;
6160 tree elttype
= TREE_TYPE (type
);
6162 HOST_WIDE_INT minelt
= 0;
6163 HOST_WIDE_INT maxelt
= 0;
6165 domain
= TYPE_DOMAIN (type
);
6166 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6167 && TYPE_MAX_VALUE (domain
)
6168 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6169 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6171 /* If we have constant bounds for the range of the type, get them. */
6174 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6175 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6178 /* If the constructor has fewer elements than the array, clear
6179 the whole array first. Similarly if this is static
6180 constructor of a non-BLKmode object. */
6183 else if (REG_P (target
) && TREE_STATIC (exp
))
6187 unsigned HOST_WIDE_INT idx
;
6189 HOST_WIDE_INT count
= 0, zero_count
= 0;
6190 need_to_clear
= ! const_bounds_p
;
6192 /* This loop is a more accurate version of the loop in
6193 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6194 is also needed to check for missing elements. */
6195 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6197 HOST_WIDE_INT this_node_count
;
6202 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6204 tree lo_index
= TREE_OPERAND (index
, 0);
6205 tree hi_index
= TREE_OPERAND (index
, 1);
6207 if (! tree_fits_uhwi_p (lo_index
)
6208 || ! tree_fits_uhwi_p (hi_index
))
6214 this_node_count
= (tree_to_uhwi (hi_index
)
6215 - tree_to_uhwi (lo_index
) + 1);
6218 this_node_count
= 1;
6220 count
+= this_node_count
;
6221 if (mostly_zeros_p (value
))
6222 zero_count
+= this_node_count
;
6225 /* Clear the entire array first if there are any missing
6226 elements, or if the incidence of zero elements is >=
6229 && (count
< maxelt
- minelt
+ 1
6230 || 4 * zero_count
>= 3 * count
))
6234 if (need_to_clear
&& size
> 0)
6237 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6239 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6243 if (!cleared
&& REG_P (target
))
6244 /* Inform later passes that the old value is dead. */
6245 emit_clobber (target
);
6247 /* Store each element of the constructor into the
6248 corresponding element of TARGET, determined by counting the
6250 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6253 HOST_WIDE_INT bitsize
;
6254 HOST_WIDE_INT bitpos
;
6255 rtx xtarget
= target
;
6257 if (cleared
&& initializer_zerop (value
))
6260 mode
= TYPE_MODE (elttype
);
6261 if (mode
== BLKmode
)
6262 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6263 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6266 bitsize
= GET_MODE_BITSIZE (mode
);
6268 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6270 tree lo_index
= TREE_OPERAND (index
, 0);
6271 tree hi_index
= TREE_OPERAND (index
, 1);
6272 rtx index_r
, pos_rtx
;
6273 HOST_WIDE_INT lo
, hi
, count
;
6276 /* If the range is constant and "small", unroll the loop. */
6278 && tree_fits_shwi_p (lo_index
)
6279 && tree_fits_shwi_p (hi_index
)
6280 && (lo
= tree_to_shwi (lo_index
),
6281 hi
= tree_to_shwi (hi_index
),
6282 count
= hi
- lo
+ 1,
6285 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6286 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6289 lo
-= minelt
; hi
-= minelt
;
6290 for (; lo
<= hi
; lo
++)
6292 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6295 && !MEM_KEEP_ALIAS_SET_P (target
)
6296 && TREE_CODE (type
) == ARRAY_TYPE
6297 && TYPE_NONALIASED_COMPONENT (type
))
6299 target
= copy_rtx (target
);
6300 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6303 store_constructor_field
6304 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6305 get_alias_set (elttype
));
6310 rtx_code_label
*loop_start
= gen_label_rtx ();
6311 rtx_code_label
*loop_end
= gen_label_rtx ();
6314 expand_normal (hi_index
);
6316 index
= build_decl (EXPR_LOCATION (exp
),
6317 VAR_DECL
, NULL_TREE
, domain
);
6318 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6319 SET_DECL_RTL (index
, index_r
);
6320 store_expr (lo_index
, index_r
, 0, false);
6322 /* Build the head of the loop. */
6323 do_pending_stack_adjust ();
6324 emit_label (loop_start
);
6326 /* Assign value to element index. */
6328 fold_convert (ssizetype
,
6329 fold_build2 (MINUS_EXPR
,
6332 TYPE_MIN_VALUE (domain
)));
6335 size_binop (MULT_EXPR
, position
,
6336 fold_convert (ssizetype
,
6337 TYPE_SIZE_UNIT (elttype
)));
6339 pos_rtx
= expand_normal (position
);
6340 xtarget
= offset_address (target
, pos_rtx
,
6341 highest_pow2_factor (position
));
6342 xtarget
= adjust_address (xtarget
, mode
, 0);
6343 if (TREE_CODE (value
) == CONSTRUCTOR
)
6344 store_constructor (value
, xtarget
, cleared
,
6345 bitsize
/ BITS_PER_UNIT
);
6347 store_expr (value
, xtarget
, 0, false);
6349 /* Generate a conditional jump to exit the loop. */
6350 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6352 jumpif (exit_cond
, loop_end
, -1);
6354 /* Update the loop counter, and jump to the head of
6356 expand_assignment (index
,
6357 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6358 index
, integer_one_node
),
6361 emit_jump (loop_start
);
6363 /* Build the end of the loop. */
6364 emit_label (loop_end
);
6367 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6368 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6373 index
= ssize_int (1);
6376 index
= fold_convert (ssizetype
,
6377 fold_build2 (MINUS_EXPR
,
6380 TYPE_MIN_VALUE (domain
)));
6383 size_binop (MULT_EXPR
, index
,
6384 fold_convert (ssizetype
,
6385 TYPE_SIZE_UNIT (elttype
)));
6386 xtarget
= offset_address (target
,
6387 expand_normal (position
),
6388 highest_pow2_factor (position
));
6389 xtarget
= adjust_address (xtarget
, mode
, 0);
6390 store_expr (value
, xtarget
, 0, false);
6395 bitpos
= ((tree_to_shwi (index
) - minelt
)
6396 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6398 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6400 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6401 && TREE_CODE (type
) == ARRAY_TYPE
6402 && TYPE_NONALIASED_COMPONENT (type
))
6404 target
= copy_rtx (target
);
6405 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6407 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6408 cleared
, get_alias_set (elttype
));
6416 unsigned HOST_WIDE_INT idx
;
6417 constructor_elt
*ce
;
6420 int icode
= CODE_FOR_nothing
;
6421 tree elttype
= TREE_TYPE (type
);
6422 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6423 machine_mode eltmode
= TYPE_MODE (elttype
);
6424 HOST_WIDE_INT bitsize
;
6425 HOST_WIDE_INT bitpos
;
6426 rtvec vector
= NULL
;
6428 alias_set_type alias
;
6430 gcc_assert (eltmode
!= BLKmode
);
6432 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6433 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6435 machine_mode mode
= GET_MODE (target
);
6437 icode
= (int) optab_handler (vec_init_optab
, mode
);
6438 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6439 if (icode
!= CODE_FOR_nothing
)
6443 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6444 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6446 icode
= CODE_FOR_nothing
;
6450 if (icode
!= CODE_FOR_nothing
)
6454 vector
= rtvec_alloc (n_elts
);
6455 for (i
= 0; i
< n_elts
; i
++)
6456 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6460 /* If the constructor has fewer elements than the vector,
6461 clear the whole array first. Similarly if this is static
6462 constructor of a non-BLKmode object. */
6465 else if (REG_P (target
) && TREE_STATIC (exp
))
6469 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6472 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6474 int n_elts_here
= tree_to_uhwi
6475 (int_const_binop (TRUNC_DIV_EXPR
,
6476 TYPE_SIZE (TREE_TYPE (value
)),
6477 TYPE_SIZE (elttype
)));
6479 count
+= n_elts_here
;
6480 if (mostly_zeros_p (value
))
6481 zero_count
+= n_elts_here
;
6484 /* Clear the entire vector first if there are any missing elements,
6485 or if the incidence of zero elements is >= 75%. */
6486 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6489 if (need_to_clear
&& size
> 0 && !vector
)
6492 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6494 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6498 /* Inform later passes that the old value is dead. */
6499 if (!cleared
&& !vector
&& REG_P (target
))
6500 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6503 alias
= MEM_ALIAS_SET (target
);
6505 alias
= get_alias_set (elttype
);
6507 /* Store each element of the constructor into the corresponding
6508 element of TARGET, determined by counting the elements. */
6509 for (idx
= 0, i
= 0;
6510 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6511 idx
++, i
+= bitsize
/ elt_size
)
6513 HOST_WIDE_INT eltpos
;
6514 tree value
= ce
->value
;
6516 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6517 if (cleared
&& initializer_zerop (value
))
6521 eltpos
= tree_to_uhwi (ce
->index
);
6527 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6529 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6530 RTVEC_ELT (vector
, eltpos
)
6531 = expand_normal (value
);
6535 machine_mode value_mode
=
6536 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6537 ? TYPE_MODE (TREE_TYPE (value
))
6539 bitpos
= eltpos
* elt_size
;
6540 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6541 value
, cleared
, alias
);
6546 emit_insn (GEN_FCN (icode
)
6548 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6557 /* Store the value of EXP (an expression tree)
6558 into a subfield of TARGET which has mode MODE and occupies
6559 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6560 If MODE is VOIDmode, it means that we are storing into a bit-field.
6562 BITREGION_START is bitpos of the first bitfield in this region.
6563 BITREGION_END is the bitpos of the ending bitfield in this region.
6564 These two fields are 0, if the C++ memory model does not apply,
6565 or we are not interested in keeping track of bitfield regions.
6567 Always return const0_rtx unless we have something particular to
6570 ALIAS_SET is the alias set for the destination. This value will
6571 (in general) be different from that for TARGET, since TARGET is a
6572 reference to the containing structure.
6574 If NONTEMPORAL is true, try generating a nontemporal store. */
6577 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6578 unsigned HOST_WIDE_INT bitregion_start
,
6579 unsigned HOST_WIDE_INT bitregion_end
,
6580 machine_mode mode
, tree exp
,
6581 alias_set_type alias_set
, bool nontemporal
)
6583 if (TREE_CODE (exp
) == ERROR_MARK
)
6586 /* If we have nothing to store, do nothing unless the expression has
6589 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6591 if (GET_CODE (target
) == CONCAT
)
6593 /* We're storing into a struct containing a single __complex. */
6595 gcc_assert (!bitpos
);
6596 return store_expr (exp
, target
, 0, nontemporal
);
6599 /* If the structure is in a register or if the component
6600 is a bit field, we cannot use addressing to access it.
6601 Use bit-field techniques or SUBREG to store in it. */
6603 if (mode
== VOIDmode
6604 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6605 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6606 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6608 || GET_CODE (target
) == SUBREG
6609 /* If the field isn't aligned enough to store as an ordinary memref,
6610 store it as a bit field. */
6612 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6613 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6614 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6615 || (bitpos
% BITS_PER_UNIT
!= 0)))
6616 || (bitsize
>= 0 && mode
!= BLKmode
6617 && GET_MODE_BITSIZE (mode
) > bitsize
)
6618 /* If the RHS and field are a constant size and the size of the
6619 RHS isn't the same size as the bitfield, we must use bitfield
6622 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6623 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6624 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6625 decl we must use bitfield operations. */
6627 && TREE_CODE (exp
) == MEM_REF
6628 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6629 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6630 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6631 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6636 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6637 implies a mask operation. If the precision is the same size as
6638 the field we're storing into, that mask is redundant. This is
6639 particularly common with bit field assignments generated by the
6641 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6644 tree type
= TREE_TYPE (exp
);
6645 if (INTEGRAL_TYPE_P (type
)
6646 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6647 && bitsize
== TYPE_PRECISION (type
))
6649 tree op
= gimple_assign_rhs1 (nop_def
);
6650 type
= TREE_TYPE (op
);
6651 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6656 temp
= expand_normal (exp
);
6658 /* If BITSIZE is narrower than the size of the type of EXP
6659 we will be narrowing TEMP. Normally, what's wanted are the
6660 low-order bits. However, if EXP's type is a record and this is
6661 big-endian machine, we want the upper BITSIZE bits. */
6662 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6663 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6664 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6665 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6666 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6669 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6670 if (mode
!= VOIDmode
&& mode
!= BLKmode
6671 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6672 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6674 /* If TEMP is not a PARALLEL (see below) and its mode and that of TARGET
6675 are both BLKmode, both must be in memory and BITPOS must be aligned
6676 on a byte boundary. If so, we simply do a block copy. Likewise for
6677 a BLKmode-like TARGET. */
6678 if (GET_CODE (temp
) != PARALLEL
6679 && GET_MODE (temp
) == BLKmode
6680 && (GET_MODE (target
) == BLKmode
6682 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6683 && (bitpos
% BITS_PER_UNIT
) == 0
6684 && (bitsize
% BITS_PER_UNIT
) == 0)))
6686 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6687 && (bitpos
% BITS_PER_UNIT
) == 0);
6689 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6690 emit_block_move (target
, temp
,
6691 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6698 /* Handle calls that return values in multiple non-contiguous locations.
6699 The Irix 6 ABI has examples of this. */
6700 if (GET_CODE (temp
) == PARALLEL
)
6702 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6704 if (mode
== BLKmode
|| mode
== VOIDmode
)
6705 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6706 temp_target
= gen_reg_rtx (mode
);
6707 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6710 else if (mode
== BLKmode
)
6712 /* Handle calls that return BLKmode values in registers. */
6713 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6715 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6716 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6721 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6723 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6724 temp_target
= gen_reg_rtx (mode
);
6726 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6727 temp_target
, mode
, mode
);
6732 /* Store the value in the bitfield. */
6733 store_bit_field (target
, bitsize
, bitpos
,
6734 bitregion_start
, bitregion_end
,
6741 /* Now build a reference to just the desired component. */
6742 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6744 if (to_rtx
== target
)
6745 to_rtx
= copy_rtx (to_rtx
);
6747 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6748 set_mem_alias_set (to_rtx
, alias_set
);
6750 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6754 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6755 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6756 codes and find the ultimate containing object, which we return.
6758 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6759 bit position, and *PUNSIGNEDP to the signedness of the field.
6760 If the position of the field is variable, we store a tree
6761 giving the variable offset (in units) in *POFFSET.
6762 This offset is in addition to the bit position.
6763 If the position is not variable, we store 0 in *POFFSET.
6765 If any of the extraction expressions is volatile,
6766 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6768 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6769 Otherwise, it is a mode that can be used to access the field.
6771 If the field describes a variable-sized object, *PMODE is set to
6772 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6773 this case, but the address of the object can be found.
6775 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6776 look through nodes that serve as markers of a greater alignment than
6777 the one that can be deduced from the expression. These nodes make it
6778 possible for front-ends to prevent temporaries from being created by
6779 the middle-end on alignment considerations. For that purpose, the
6780 normal operating mode at high-level is to always pass FALSE so that
6781 the ultimate containing object is really returned; moreover, the
6782 associated predicate handled_component_p will always return TRUE
6783 on these nodes, thus indicating that they are essentially handled
6784 by get_inner_reference. TRUE should only be passed when the caller
6785 is scanning the expression in order to build another representation
6786 and specifically knows how to handle these nodes; as such, this is
6787 the normal operating mode in the RTL expanders. */
6790 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6791 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6792 machine_mode
*pmode
, int *punsignedp
,
6793 int *pvolatilep
, bool keep_aligning
)
6796 machine_mode mode
= VOIDmode
;
6797 bool blkmode_bitfield
= false;
6798 tree offset
= size_zero_node
;
6799 offset_int bit_offset
= 0;
6801 /* First get the mode, signedness, and size. We do this from just the
6802 outermost expression. */
6804 if (TREE_CODE (exp
) == COMPONENT_REF
)
6806 tree field
= TREE_OPERAND (exp
, 1);
6807 size_tree
= DECL_SIZE (field
);
6808 if (flag_strict_volatile_bitfields
> 0
6809 && TREE_THIS_VOLATILE (exp
)
6810 && DECL_BIT_FIELD_TYPE (field
)
6811 && DECL_MODE (field
) != BLKmode
)
6812 /* Volatile bitfields should be accessed in the mode of the
6813 field's type, not the mode computed based on the bit
6815 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6816 else if (!DECL_BIT_FIELD (field
))
6817 mode
= DECL_MODE (field
);
6818 else if (DECL_MODE (field
) == BLKmode
)
6819 blkmode_bitfield
= true;
6821 *punsignedp
= DECL_UNSIGNED (field
);
6823 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6825 size_tree
= TREE_OPERAND (exp
, 1);
6826 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6827 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6829 /* For vector types, with the correct size of access, use the mode of
6831 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6832 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6833 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6834 mode
= TYPE_MODE (TREE_TYPE (exp
));
6838 mode
= TYPE_MODE (TREE_TYPE (exp
));
6839 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6841 if (mode
== BLKmode
)
6842 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6844 *pbitsize
= GET_MODE_BITSIZE (mode
);
6849 if (! tree_fits_uhwi_p (size_tree
))
6850 mode
= BLKmode
, *pbitsize
= -1;
6852 *pbitsize
= tree_to_uhwi (size_tree
);
6855 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6856 and find the ultimate containing object. */
6859 switch (TREE_CODE (exp
))
6862 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
6867 tree field
= TREE_OPERAND (exp
, 1);
6868 tree this_offset
= component_ref_field_offset (exp
);
6870 /* If this field hasn't been filled in yet, don't go past it.
6871 This should only happen when folding expressions made during
6872 type construction. */
6873 if (this_offset
== 0)
6876 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6877 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
6879 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6884 case ARRAY_RANGE_REF
:
6886 tree index
= TREE_OPERAND (exp
, 1);
6887 tree low_bound
= array_ref_low_bound (exp
);
6888 tree unit_size
= array_ref_element_size (exp
);
6890 /* We assume all arrays have sizes that are a multiple of a byte.
6891 First subtract the lower bound, if any, in the type of the
6892 index, then convert to sizetype and multiply by the size of
6893 the array element. */
6894 if (! integer_zerop (low_bound
))
6895 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6898 offset
= size_binop (PLUS_EXPR
, offset
,
6899 size_binop (MULT_EXPR
,
6900 fold_convert (sizetype
, index
),
6909 bit_offset
+= *pbitsize
;
6912 case VIEW_CONVERT_EXPR
:
6913 if (keep_aligning
&& STRICT_ALIGNMENT
6914 && (TYPE_ALIGN (TREE_TYPE (exp
))
6915 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6916 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6917 < BIGGEST_ALIGNMENT
)
6918 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6919 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6924 /* Hand back the decl for MEM[&decl, off]. */
6925 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6927 tree off
= TREE_OPERAND (exp
, 1);
6928 if (!integer_zerop (off
))
6930 offset_int boff
, coff
= mem_ref_offset (exp
);
6931 boff
= wi::lshift (coff
, LOG2_BITS_PER_UNIT
);
6934 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6942 /* If any reference in the chain is volatile, the effect is volatile. */
6943 if (TREE_THIS_VOLATILE (exp
))
6946 exp
= TREE_OPERAND (exp
, 0);
6950 /* If OFFSET is constant, see if we can return the whole thing as a
6951 constant bit position. Make sure to handle overflow during
6953 if (TREE_CODE (offset
) == INTEGER_CST
)
6955 offset_int tem
= wi::sext (wi::to_offset (offset
),
6956 TYPE_PRECISION (sizetype
));
6957 tem
= wi::lshift (tem
, LOG2_BITS_PER_UNIT
);
6959 if (wi::fits_shwi_p (tem
))
6961 *pbitpos
= tem
.to_shwi ();
6962 *poffset
= offset
= NULL_TREE
;
6966 /* Otherwise, split it up. */
6969 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6970 if (wi::neg_p (bit_offset
) || !wi::fits_shwi_p (bit_offset
))
6972 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
6973 offset_int tem
= bit_offset
.and_not (mask
);
6974 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6975 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6977 tem
= wi::arshift (tem
, LOG2_BITS_PER_UNIT
);
6978 offset
= size_binop (PLUS_EXPR
, offset
,
6979 wide_int_to_tree (sizetype
, tem
));
6982 *pbitpos
= bit_offset
.to_shwi ();
6986 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6987 if (mode
== VOIDmode
6989 && (*pbitpos
% BITS_PER_UNIT
) == 0
6990 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6998 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7000 static unsigned HOST_WIDE_INT
7001 target_align (const_tree target
)
7003 /* We might have a chain of nested references with intermediate misaligning
7004 bitfields components, so need to recurse to find out. */
7006 unsigned HOST_WIDE_INT this_align
, outer_align
;
7008 switch (TREE_CODE (target
))
7014 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7015 outer_align
= target_align (TREE_OPERAND (target
, 0));
7016 return MIN (this_align
, outer_align
);
7019 case ARRAY_RANGE_REF
:
7020 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7021 outer_align
= target_align (TREE_OPERAND (target
, 0));
7022 return MIN (this_align
, outer_align
);
7025 case NON_LVALUE_EXPR
:
7026 case VIEW_CONVERT_EXPR
:
7027 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7028 outer_align
= target_align (TREE_OPERAND (target
, 0));
7029 return MAX (this_align
, outer_align
);
7032 return TYPE_ALIGN (TREE_TYPE (target
));
7037 /* Given an rtx VALUE that may contain additions and multiplications, return
7038 an equivalent value that just refers to a register, memory, or constant.
7039 This is done by generating instructions to perform the arithmetic and
7040 returning a pseudo-register containing the value.
7042 The returned value may be a REG, SUBREG, MEM or constant. */
7045 force_operand (rtx value
, rtx target
)
7048 /* Use subtarget as the target for operand 0 of a binary operation. */
7049 rtx subtarget
= get_subtarget (target
);
7050 enum rtx_code code
= GET_CODE (value
);
7052 /* Check for subreg applied to an expression produced by loop optimizer. */
7054 && !REG_P (SUBREG_REG (value
))
7055 && !MEM_P (SUBREG_REG (value
)))
7058 = simplify_gen_subreg (GET_MODE (value
),
7059 force_reg (GET_MODE (SUBREG_REG (value
)),
7060 force_operand (SUBREG_REG (value
),
7062 GET_MODE (SUBREG_REG (value
)),
7063 SUBREG_BYTE (value
));
7064 code
= GET_CODE (value
);
7067 /* Check for a PIC address load. */
7068 if ((code
== PLUS
|| code
== MINUS
)
7069 && XEXP (value
, 0) == pic_offset_table_rtx
7070 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7071 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7072 || GET_CODE (XEXP (value
, 1)) == CONST
))
7075 subtarget
= gen_reg_rtx (GET_MODE (value
));
7076 emit_move_insn (subtarget
, value
);
7080 if (ARITHMETIC_P (value
))
7082 op2
= XEXP (value
, 1);
7083 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7085 if (code
== MINUS
&& CONST_INT_P (op2
))
7088 op2
= negate_rtx (GET_MODE (value
), op2
);
7091 /* Check for an addition with OP2 a constant integer and our first
7092 operand a PLUS of a virtual register and something else. In that
7093 case, we want to emit the sum of the virtual register and the
7094 constant first and then add the other value. This allows virtual
7095 register instantiation to simply modify the constant rather than
7096 creating another one around this addition. */
7097 if (code
== PLUS
&& CONST_INT_P (op2
)
7098 && GET_CODE (XEXP (value
, 0)) == PLUS
7099 && REG_P (XEXP (XEXP (value
, 0), 0))
7100 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7101 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7103 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7104 XEXP (XEXP (value
, 0), 0), op2
,
7105 subtarget
, 0, OPTAB_LIB_WIDEN
);
7106 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7107 force_operand (XEXP (XEXP (value
,
7109 target
, 0, OPTAB_LIB_WIDEN
);
7112 op1
= force_operand (XEXP (value
, 0), subtarget
);
7113 op2
= force_operand (op2
, NULL_RTX
);
7117 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7119 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7120 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7121 target
, 1, OPTAB_LIB_WIDEN
);
7123 return expand_divmod (0,
7124 FLOAT_MODE_P (GET_MODE (value
))
7125 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7126 GET_MODE (value
), op1
, op2
, target
, 0);
7128 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7131 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7134 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7137 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7138 target
, 0, OPTAB_LIB_WIDEN
);
7140 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7141 target
, 1, OPTAB_LIB_WIDEN
);
7144 if (UNARY_P (value
))
7147 target
= gen_reg_rtx (GET_MODE (value
));
7148 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7155 case FLOAT_TRUNCATE
:
7156 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7161 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7165 case UNSIGNED_FLOAT
:
7166 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7170 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7174 #ifdef INSN_SCHEDULING
7175 /* On machines that have insn scheduling, we want all memory reference to be
7176 explicit, so we need to deal with such paradoxical SUBREGs. */
7177 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7179 = simplify_gen_subreg (GET_MODE (value
),
7180 force_reg (GET_MODE (SUBREG_REG (value
)),
7181 force_operand (SUBREG_REG (value
),
7183 GET_MODE (SUBREG_REG (value
)),
7184 SUBREG_BYTE (value
));
7190 /* Subroutine of expand_expr: return nonzero iff there is no way that
7191 EXP can reference X, which is being modified. TOP_P is nonzero if this
7192 call is going to be used to determine whether we need a temporary
7193 for EXP, as opposed to a recursive call to this function.
7195 It is always safe for this routine to return zero since it merely
7196 searches for optimization opportunities. */
7199 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7205 /* If EXP has varying size, we MUST use a target since we currently
7206 have no way of allocating temporaries of variable size
7207 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7208 So we assume here that something at a higher level has prevented a
7209 clash. This is somewhat bogus, but the best we can do. Only
7210 do this when X is BLKmode and when we are at the top level. */
7211 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7212 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7213 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7214 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7215 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7217 && GET_MODE (x
) == BLKmode
)
7218 /* If X is in the outgoing argument area, it is always safe. */
7220 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7221 || (GET_CODE (XEXP (x
, 0)) == PLUS
7222 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7225 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7226 find the underlying pseudo. */
7227 if (GET_CODE (x
) == SUBREG
)
7230 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7234 /* Now look at our tree code and possibly recurse. */
7235 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7237 case tcc_declaration
:
7238 exp_rtl
= DECL_RTL_IF_SET (exp
);
7244 case tcc_exceptional
:
7245 if (TREE_CODE (exp
) == TREE_LIST
)
7249 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7251 exp
= TREE_CHAIN (exp
);
7254 if (TREE_CODE (exp
) != TREE_LIST
)
7255 return safe_from_p (x
, exp
, 0);
7258 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7260 constructor_elt
*ce
;
7261 unsigned HOST_WIDE_INT idx
;
7263 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7264 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7265 || !safe_from_p (x
, ce
->value
, 0))
7269 else if (TREE_CODE (exp
) == ERROR_MARK
)
7270 return 1; /* An already-visited SAVE_EXPR? */
7275 /* The only case we look at here is the DECL_INITIAL inside a
7277 return (TREE_CODE (exp
) != DECL_EXPR
7278 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7279 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7280 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7283 case tcc_comparison
:
7284 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7289 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7291 case tcc_expression
:
7294 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7295 the expression. If it is set, we conflict iff we are that rtx or
7296 both are in memory. Otherwise, we check all operands of the
7297 expression recursively. */
7299 switch (TREE_CODE (exp
))
7302 /* If the operand is static or we are static, we can't conflict.
7303 Likewise if we don't conflict with the operand at all. */
7304 if (staticp (TREE_OPERAND (exp
, 0))
7305 || TREE_STATIC (exp
)
7306 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7309 /* Otherwise, the only way this can conflict is if we are taking
7310 the address of a DECL a that address if part of X, which is
7312 exp
= TREE_OPERAND (exp
, 0);
7315 if (!DECL_RTL_SET_P (exp
)
7316 || !MEM_P (DECL_RTL (exp
)))
7319 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7325 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7326 get_alias_set (exp
)))
7331 /* Assume that the call will clobber all hard registers and
7333 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7338 case WITH_CLEANUP_EXPR
:
7339 case CLEANUP_POINT_EXPR
:
7340 /* Lowered by gimplify.c. */
7344 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7350 /* If we have an rtx, we do not need to scan our operands. */
7354 nops
= TREE_OPERAND_LENGTH (exp
);
7355 for (i
= 0; i
< nops
; i
++)
7356 if (TREE_OPERAND (exp
, i
) != 0
7357 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7363 /* Should never get a type here. */
7367 /* If we have an rtl, find any enclosed object. Then see if we conflict
7371 if (GET_CODE (exp_rtl
) == SUBREG
)
7373 exp_rtl
= SUBREG_REG (exp_rtl
);
7375 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7379 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7380 are memory and they conflict. */
7381 return ! (rtx_equal_p (x
, exp_rtl
)
7382 || (MEM_P (x
) && MEM_P (exp_rtl
)
7383 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7386 /* If we reach here, it is safe. */
7391 /* Return the highest power of two that EXP is known to be a multiple of.
7392 This is used in updating alignment of MEMs in array references. */
7394 unsigned HOST_WIDE_INT
7395 highest_pow2_factor (const_tree exp
)
7397 unsigned HOST_WIDE_INT ret
;
7398 int trailing_zeros
= tree_ctz (exp
);
7399 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7400 return BIGGEST_ALIGNMENT
;
7401 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7402 if (ret
> BIGGEST_ALIGNMENT
)
7403 return BIGGEST_ALIGNMENT
;
7407 /* Similar, except that the alignment requirements of TARGET are
7408 taken into account. Assume it is at least as aligned as its
7409 type, unless it is a COMPONENT_REF in which case the layout of
7410 the structure gives the alignment. */
7412 static unsigned HOST_WIDE_INT
7413 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7415 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7416 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7418 return MAX (factor
, talign
);
7421 /* Convert the tree comparison code TCODE to the rtl one where the
7422 signedness is UNSIGNEDP. */
7424 static enum rtx_code
7425 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7437 code
= unsignedp
? LTU
: LT
;
7440 code
= unsignedp
? LEU
: LE
;
7443 code
= unsignedp
? GTU
: GT
;
7446 code
= unsignedp
? GEU
: GE
;
7448 case UNORDERED_EXPR
:
7479 /* Subroutine of expand_expr. Expand the two operands of a binary
7480 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7481 The value may be stored in TARGET if TARGET is nonzero. The
7482 MODIFIER argument is as documented by expand_expr. */
7485 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7486 enum expand_modifier modifier
)
7488 if (! safe_from_p (target
, exp1
, 1))
7490 if (operand_equal_p (exp0
, exp1
, 0))
7492 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7493 *op1
= copy_rtx (*op0
);
7497 /* If we need to preserve evaluation order, copy exp0 into its own
7498 temporary variable so that it can't be clobbered by exp1. */
7499 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7500 exp0
= save_expr (exp0
);
7501 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7502 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7507 /* Return a MEM that contains constant EXP. DEFER is as for
7508 output_constant_def and MODIFIER is as for expand_expr. */
7511 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7515 mem
= output_constant_def (exp
, defer
);
7516 if (modifier
!= EXPAND_INITIALIZER
)
7517 mem
= use_anchored_address (mem
);
7521 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7522 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7525 expand_expr_addr_expr_1 (tree exp
, rtx target
, machine_mode tmode
,
7526 enum expand_modifier modifier
, addr_space_t as
)
7528 rtx result
, subtarget
;
7530 HOST_WIDE_INT bitsize
, bitpos
;
7531 int volatilep
, unsignedp
;
7534 /* If we are taking the address of a constant and are at the top level,
7535 we have to use output_constant_def since we can't call force_const_mem
7537 /* ??? This should be considered a front-end bug. We should not be
7538 generating ADDR_EXPR of something that isn't an LVALUE. The only
7539 exception here is STRING_CST. */
7540 if (CONSTANT_CLASS_P (exp
))
7542 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7543 if (modifier
< EXPAND_SUM
)
7544 result
= force_operand (result
, target
);
7548 /* Everything must be something allowed by is_gimple_addressable. */
7549 switch (TREE_CODE (exp
))
7552 /* This case will happen via recursion for &a->b. */
7553 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7557 tree tem
= TREE_OPERAND (exp
, 0);
7558 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7559 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7560 return expand_expr (tem
, target
, tmode
, modifier
);
7564 /* Expand the initializer like constants above. */
7565 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7567 if (modifier
< EXPAND_SUM
)
7568 result
= force_operand (result
, target
);
7572 /* The real part of the complex number is always first, therefore
7573 the address is the same as the address of the parent object. */
7576 inner
= TREE_OPERAND (exp
, 0);
7580 /* The imaginary part of the complex number is always second.
7581 The expression is therefore always offset by the size of the
7584 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7585 inner
= TREE_OPERAND (exp
, 0);
7588 case COMPOUND_LITERAL_EXPR
:
7589 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
7590 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
7591 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
7592 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
7593 the initializers aren't gimplified. */
7594 if (COMPOUND_LITERAL_EXPR_DECL (exp
)
7595 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp
)))
7596 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7597 target
, tmode
, modifier
, as
);
7600 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7601 expand_expr, as that can have various side effects; LABEL_DECLs for
7602 example, may not have their DECL_RTL set yet. Expand the rtl of
7603 CONSTRUCTORs too, which should yield a memory reference for the
7604 constructor's contents. Assume language specific tree nodes can
7605 be expanded in some interesting way. */
7606 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7608 || TREE_CODE (exp
) == CONSTRUCTOR
7609 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7611 result
= expand_expr (exp
, target
, tmode
,
7612 modifier
== EXPAND_INITIALIZER
7613 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7615 /* If the DECL isn't in memory, then the DECL wasn't properly
7616 marked TREE_ADDRESSABLE, which will be either a front-end
7617 or a tree optimizer bug. */
7619 if (TREE_ADDRESSABLE (exp
)
7621 && ! targetm
.calls
.allocate_stack_slots_for_args ())
7623 error ("local frame unavailable (naked function?)");
7627 gcc_assert (MEM_P (result
));
7628 result
= XEXP (result
, 0);
7630 /* ??? Is this needed anymore? */
7632 TREE_USED (exp
) = 1;
7634 if (modifier
!= EXPAND_INITIALIZER
7635 && modifier
!= EXPAND_CONST_ADDRESS
7636 && modifier
!= EXPAND_SUM
)
7637 result
= force_operand (result
, target
);
7641 /* Pass FALSE as the last argument to get_inner_reference although
7642 we are expanding to RTL. The rationale is that we know how to
7643 handle "aligning nodes" here: we can just bypass them because
7644 they won't change the final object whose address will be returned
7645 (they actually exist only for that purpose). */
7646 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7647 &mode1
, &unsignedp
, &volatilep
, false);
7651 /* We must have made progress. */
7652 gcc_assert (inner
!= exp
);
7654 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7655 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7656 inner alignment, force the inner to be sufficiently aligned. */
7657 if (CONSTANT_CLASS_P (inner
)
7658 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7660 inner
= copy_node (inner
);
7661 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7662 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7663 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7665 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7671 if (modifier
!= EXPAND_NORMAL
)
7672 result
= force_operand (result
, NULL
);
7673 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7674 modifier
== EXPAND_INITIALIZER
7675 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7677 /* expand_expr is allowed to return an object in a mode other
7678 than TMODE. If it did, we need to convert. */
7679 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7680 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7681 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7682 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7683 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7685 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7686 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7689 subtarget
= bitpos
? NULL_RTX
: target
;
7690 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7691 1, OPTAB_LIB_WIDEN
);
7697 /* Someone beforehand should have rejected taking the address
7698 of such an object. */
7699 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7701 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7702 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7703 if (modifier
< EXPAND_SUM
)
7704 result
= force_operand (result
, target
);
7710 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7711 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7714 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
7715 enum expand_modifier modifier
)
7717 addr_space_t as
= ADDR_SPACE_GENERIC
;
7718 machine_mode address_mode
= Pmode
;
7719 machine_mode pointer_mode
= ptr_mode
;
7723 /* Target mode of VOIDmode says "whatever's natural". */
7724 if (tmode
== VOIDmode
)
7725 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7727 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7729 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7730 address_mode
= targetm
.addr_space
.address_mode (as
);
7731 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7734 /* We can get called with some Weird Things if the user does silliness
7735 like "(short) &a". In that case, convert_memory_address won't do
7736 the right thing, so ignore the given target mode. */
7737 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7738 tmode
= address_mode
;
7740 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7741 tmode
, modifier
, as
);
7743 /* Despite expand_expr claims concerning ignoring TMODE when not
7744 strictly convenient, stuff breaks if we don't honor it. Note
7745 that combined with the above, we only do this for pointer modes. */
7746 rmode
= GET_MODE (result
);
7747 if (rmode
== VOIDmode
)
7750 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7755 /* Generate code for computing CONSTRUCTOR EXP.
7756 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7757 is TRUE, instead of creating a temporary variable in memory
7758 NULL is returned and the caller needs to handle it differently. */
7761 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7762 bool avoid_temp_mem
)
7764 tree type
= TREE_TYPE (exp
);
7765 machine_mode mode
= TYPE_MODE (type
);
7767 /* Try to avoid creating a temporary at all. This is possible
7768 if all of the initializer is zero.
7769 FIXME: try to handle all [0..255] initializers we can handle
7771 if (TREE_STATIC (exp
)
7772 && !TREE_ADDRESSABLE (exp
)
7773 && target
!= 0 && mode
== BLKmode
7774 && all_zeros_p (exp
))
7776 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7780 /* All elts simple constants => refer to a constant in memory. But
7781 if this is a non-BLKmode mode, let it store a field at a time
7782 since that should make a CONST_INT, CONST_WIDE_INT or
7783 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7784 use, it is best to store directly into the target unless the type
7785 is large enough that memcpy will be used. If we are making an
7786 initializer and all operands are constant, put it in memory as
7789 FIXME: Avoid trying to fill vector constructors piece-meal.
7790 Output them with output_constant_def below unless we're sure
7791 they're zeros. This should go away when vector initializers
7792 are treated like VECTOR_CST instead of arrays. */
7793 if ((TREE_STATIC (exp
)
7794 && ((mode
== BLKmode
7795 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7796 || TREE_ADDRESSABLE (exp
)
7797 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7798 && (! can_move_by_pieces
7799 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7801 && ! mostly_zeros_p (exp
))))
7802 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7803 && TREE_CONSTANT (exp
)))
7810 constructor
= expand_expr_constant (exp
, 1, modifier
);
7812 if (modifier
!= EXPAND_CONST_ADDRESS
7813 && modifier
!= EXPAND_INITIALIZER
7814 && modifier
!= EXPAND_SUM
)
7815 constructor
= validize_mem (constructor
);
7820 /* Handle calls that pass values in multiple non-contiguous
7821 locations. The Irix 6 ABI has examples of this. */
7822 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7823 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7828 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7831 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7836 /* expand_expr: generate code for computing expression EXP.
7837 An rtx for the computed value is returned. The value is never null.
7838 In the case of a void EXP, const0_rtx is returned.
7840 The value may be stored in TARGET if TARGET is nonzero.
7841 TARGET is just a suggestion; callers must assume that
7842 the rtx returned may not be the same as TARGET.
7844 If TARGET is CONST0_RTX, it means that the value will be ignored.
7846 If TMODE is not VOIDmode, it suggests generating the
7847 result in mode TMODE. But this is done only when convenient.
7848 Otherwise, TMODE is ignored and the value generated in its natural mode.
7849 TMODE is just a suggestion; callers must assume that
7850 the rtx returned may not have mode TMODE.
7852 Note that TARGET may have neither TMODE nor MODE. In that case, it
7853 probably will not be used.
7855 If MODIFIER is EXPAND_SUM then when EXP is an addition
7856 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7857 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7858 products as above, or REG or MEM, or constant.
7859 Ordinarily in such cases we would output mul or add instructions
7860 and then return a pseudo reg containing the sum.
7862 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7863 it also marks a label as absolutely required (it can't be dead).
7864 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7865 This is used for outputting expressions used in initializers.
7867 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7868 with a constant address even if that address is not normally legitimate.
7869 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7871 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7872 a call parameter. Such targets require special care as we haven't yet
7873 marked TARGET so that it's safe from being trashed by libcalls. We
7874 don't want to use TARGET for anything but the final result;
7875 Intermediate values must go elsewhere. Additionally, calls to
7876 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7878 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7879 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7880 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7881 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7884 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7885 In this case, we don't adjust a returned MEM rtx that wouldn't be
7886 sufficiently aligned for its mode; instead, it's up to the caller
7887 to deal with it afterwards. This is used to make sure that unaligned
7888 base objects for which out-of-bounds accesses are supported, for
7889 example record types with trailing arrays, aren't realigned behind
7890 the back of the caller.
7891 The normal operating mode is to pass FALSE for this parameter. */
7894 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
7895 enum expand_modifier modifier
, rtx
*alt_rtl
,
7896 bool inner_reference_p
)
7900 /* Handle ERROR_MARK before anybody tries to access its type. */
7901 if (TREE_CODE (exp
) == ERROR_MARK
7902 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7904 ret
= CONST0_RTX (tmode
);
7905 return ret
? ret
: const0_rtx
;
7908 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
7913 /* Try to expand the conditional expression which is represented by
7914 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7915 return the rtl reg which repsents the result. Otherwise return
7919 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7920 tree treeop1 ATTRIBUTE_UNUSED
,
7921 tree treeop2 ATTRIBUTE_UNUSED
)
7924 rtx op00
, op01
, op1
, op2
;
7925 enum rtx_code comparison_code
;
7926 machine_mode comparison_mode
;
7929 tree type
= TREE_TYPE (treeop1
);
7930 int unsignedp
= TYPE_UNSIGNED (type
);
7931 machine_mode mode
= TYPE_MODE (type
);
7932 machine_mode orig_mode
= mode
;
7934 /* If we cannot do a conditional move on the mode, try doing it
7935 with the promoted mode. */
7936 if (!can_conditionally_move_p (mode
))
7938 mode
= promote_mode (type
, mode
, &unsignedp
);
7939 if (!can_conditionally_move_p (mode
))
7941 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7944 temp
= assign_temp (type
, 0, 1);
7947 expand_operands (treeop1
, treeop2
,
7948 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7950 if (TREE_CODE (treeop0
) == SSA_NAME
7951 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7953 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7954 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7955 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7956 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7957 comparison_mode
= TYPE_MODE (type
);
7958 unsignedp
= TYPE_UNSIGNED (type
);
7959 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7961 else if (COMPARISON_CLASS_P (treeop0
))
7963 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7964 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7965 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7966 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7967 unsignedp
= TYPE_UNSIGNED (type
);
7968 comparison_mode
= TYPE_MODE (type
);
7969 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7973 op00
= expand_normal (treeop0
);
7975 comparison_code
= NE
;
7976 comparison_mode
= GET_MODE (op00
);
7977 if (comparison_mode
== VOIDmode
)
7978 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7981 if (GET_MODE (op1
) != mode
)
7982 op1
= gen_lowpart (mode
, op1
);
7984 if (GET_MODE (op2
) != mode
)
7985 op2
= gen_lowpart (mode
, op2
);
7987 /* Try to emit the conditional move. */
7988 insn
= emit_conditional_move (temp
, comparison_code
,
7989 op00
, op01
, comparison_mode
,
7993 /* If we could do the conditional move, emit the sequence,
7997 rtx_insn
*seq
= get_insns ();
8000 return convert_modes (orig_mode
, mode
, temp
, 0);
8003 /* Otherwise discard the sequence and fall back to code with
8010 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
8011 enum expand_modifier modifier
)
8013 rtx op0
, op1
, op2
, temp
;
8014 rtx_code_label
*lab
;
8018 enum tree_code code
= ops
->code
;
8020 rtx subtarget
, original_target
;
8022 bool reduce_bit_field
;
8023 location_t loc
= ops
->location
;
8024 tree treeop0
, treeop1
, treeop2
;
8025 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8026 ? reduce_to_bit_field_precision ((expr), \
8032 mode
= TYPE_MODE (type
);
8033 unsignedp
= TYPE_UNSIGNED (type
);
8039 /* We should be called only on simple (binary or unary) expressions,
8040 exactly those that are valid in gimple expressions that aren't
8041 GIMPLE_SINGLE_RHS (or invalid). */
8042 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8043 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8044 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8046 ignore
= (target
== const0_rtx
8047 || ((CONVERT_EXPR_CODE_P (code
)
8048 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8049 && TREE_CODE (type
) == VOID_TYPE
));
8051 /* We should be called only if we need the result. */
8052 gcc_assert (!ignore
);
8054 /* An operation in what may be a bit-field type needs the
8055 result to be reduced to the precision of the bit-field type,
8056 which is narrower than that of the type's mode. */
8057 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8058 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8060 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8063 /* Use subtarget as the target for operand 0 of a binary operation. */
8064 subtarget
= get_subtarget (target
);
8065 original_target
= target
;
8069 case NON_LVALUE_EXPR
:
8072 if (treeop0
== error_mark_node
)
8075 if (TREE_CODE (type
) == UNION_TYPE
)
8077 tree valtype
= TREE_TYPE (treeop0
);
8079 /* If both input and output are BLKmode, this conversion isn't doing
8080 anything except possibly changing memory attribute. */
8081 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8083 rtx result
= expand_expr (treeop0
, target
, tmode
,
8086 result
= copy_rtx (result
);
8087 set_mem_attributes (result
, type
, 0);
8093 if (TYPE_MODE (type
) != BLKmode
)
8094 target
= gen_reg_rtx (TYPE_MODE (type
));
8096 target
= assign_temp (type
, 1, 1);
8100 /* Store data into beginning of memory target. */
8101 store_expr (treeop0
,
8102 adjust_address (target
, TYPE_MODE (valtype
), 0),
8103 modifier
== EXPAND_STACK_PARM
,
8108 gcc_assert (REG_P (target
));
8110 /* Store this field into a union of the proper type. */
8111 store_field (target
,
8112 MIN ((int_size_in_bytes (TREE_TYPE
8115 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8116 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8119 /* Return the entire union. */
8123 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8125 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8128 /* If the signedness of the conversion differs and OP0 is
8129 a promoted SUBREG, clear that indication since we now
8130 have to do the proper extension. */
8131 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8132 && GET_CODE (op0
) == SUBREG
)
8133 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8135 return REDUCE_BIT_FIELD (op0
);
8138 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8139 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8140 if (GET_MODE (op0
) == mode
)
8143 /* If OP0 is a constant, just convert it into the proper mode. */
8144 else if (CONSTANT_P (op0
))
8146 tree inner_type
= TREE_TYPE (treeop0
);
8147 machine_mode inner_mode
= GET_MODE (op0
);
8149 if (inner_mode
== VOIDmode
)
8150 inner_mode
= TYPE_MODE (inner_type
);
8152 if (modifier
== EXPAND_INITIALIZER
)
8153 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8154 subreg_lowpart_offset (mode
,
8157 op0
= convert_modes (mode
, inner_mode
, op0
,
8158 TYPE_UNSIGNED (inner_type
));
8161 else if (modifier
== EXPAND_INITIALIZER
)
8162 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8164 else if (target
== 0)
8165 op0
= convert_to_mode (mode
, op0
,
8166 TYPE_UNSIGNED (TREE_TYPE
8170 convert_move (target
, op0
,
8171 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8175 return REDUCE_BIT_FIELD (op0
);
8177 case ADDR_SPACE_CONVERT_EXPR
:
8179 tree treeop0_type
= TREE_TYPE (treeop0
);
8181 addr_space_t as_from
;
8183 gcc_assert (POINTER_TYPE_P (type
));
8184 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8186 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8187 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8189 /* Conversions between pointers to the same address space should
8190 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8191 gcc_assert (as_to
!= as_from
);
8193 /* Ask target code to handle conversion between pointers
8194 to overlapping address spaces. */
8195 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8196 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8198 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8199 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8204 /* For disjoint address spaces, converting anything but
8205 a null pointer invokes undefined behaviour. We simply
8206 always return a null pointer here. */
8207 return CONST0_RTX (mode
);
8210 case POINTER_PLUS_EXPR
:
8211 /* Even though the sizetype mode and the pointer's mode can be different
8212 expand is able to handle this correctly and get the correct result out
8213 of the PLUS_EXPR code. */
8214 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8215 if sizetype precision is smaller than pointer precision. */
8216 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8217 treeop1
= fold_convert_loc (loc
, type
,
8218 fold_convert_loc (loc
, ssizetype
,
8220 /* If sizetype precision is larger than pointer precision, truncate the
8221 offset to have matching modes. */
8222 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8223 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8226 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8227 something else, make sure we add the register to the constant and
8228 then to the other thing. This case can occur during strength
8229 reduction and doing it this way will produce better code if the
8230 frame pointer or argument pointer is eliminated.
8232 fold-const.c will ensure that the constant is always in the inner
8233 PLUS_EXPR, so the only case we need to do anything about is if
8234 sp, ap, or fp is our second argument, in which case we must swap
8235 the innermost first argument and our second argument. */
8237 if (TREE_CODE (treeop0
) == PLUS_EXPR
8238 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8239 && TREE_CODE (treeop1
) == VAR_DECL
8240 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8241 || DECL_RTL (treeop1
) == stack_pointer_rtx
8242 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8247 /* If the result is to be ptr_mode and we are adding an integer to
8248 something, we might be forming a constant. So try to use
8249 plus_constant. If it produces a sum and we can't accept it,
8250 use force_operand. This allows P = &ARR[const] to generate
8251 efficient code on machines where a SYMBOL_REF is not a valid
8254 If this is an EXPAND_SUM call, always return the sum. */
8255 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8256 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8258 if (modifier
== EXPAND_STACK_PARM
)
8260 if (TREE_CODE (treeop0
) == INTEGER_CST
8261 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8262 && TREE_CONSTANT (treeop1
))
8266 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
8268 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8270 /* Use wi::shwi to ensure that the constant is
8271 truncated according to the mode of OP1, then sign extended
8272 to a HOST_WIDE_INT. Using the constant directly can result
8273 in non-canonical RTL in a 64x32 cross compile. */
8274 wc
= TREE_INT_CST_LOW (treeop0
);
8276 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8277 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8278 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8279 op1
= force_operand (op1
, target
);
8280 return REDUCE_BIT_FIELD (op1
);
8283 else if (TREE_CODE (treeop1
) == INTEGER_CST
8284 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8285 && TREE_CONSTANT (treeop0
))
8289 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
8291 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8292 (modifier
== EXPAND_INITIALIZER
8293 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8294 if (! CONSTANT_P (op0
))
8296 op1
= expand_expr (treeop1
, NULL_RTX
,
8297 VOIDmode
, modifier
);
8298 /* Return a PLUS if modifier says it's OK. */
8299 if (modifier
== EXPAND_SUM
8300 || modifier
== EXPAND_INITIALIZER
)
8301 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8304 /* Use wi::shwi to ensure that the constant is
8305 truncated according to the mode of OP1, then sign extended
8306 to a HOST_WIDE_INT. Using the constant directly can result
8307 in non-canonical RTL in a 64x32 cross compile. */
8308 wc
= TREE_INT_CST_LOW (treeop1
);
8310 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8311 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8312 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8313 op0
= force_operand (op0
, target
);
8314 return REDUCE_BIT_FIELD (op0
);
8318 /* Use TER to expand pointer addition of a negated value
8319 as pointer subtraction. */
8320 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8321 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8322 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8323 && TREE_CODE (treeop1
) == SSA_NAME
8324 && TYPE_MODE (TREE_TYPE (treeop0
))
8325 == TYPE_MODE (TREE_TYPE (treeop1
)))
8327 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8330 treeop1
= gimple_assign_rhs1 (def
);
8336 /* No sense saving up arithmetic to be done
8337 if it's all in the wrong mode to form part of an address.
8338 And force_operand won't know whether to sign-extend or
8340 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8341 || mode
!= ptr_mode
)
8343 expand_operands (treeop0
, treeop1
,
8344 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8345 if (op0
== const0_rtx
)
8347 if (op1
== const0_rtx
)
8352 expand_operands (treeop0
, treeop1
,
8353 subtarget
, &op0
, &op1
, modifier
);
8354 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8358 /* For initializers, we are allowed to return a MINUS of two
8359 symbolic constants. Here we handle all cases when both operands
8361 /* Handle difference of two symbolic constants,
8362 for the sake of an initializer. */
8363 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8364 && really_constant_p (treeop0
)
8365 && really_constant_p (treeop1
))
8367 expand_operands (treeop0
, treeop1
,
8368 NULL_RTX
, &op0
, &op1
, modifier
);
8370 /* If the last operand is a CONST_INT, use plus_constant of
8371 the negated constant. Else make the MINUS. */
8372 if (CONST_INT_P (op1
))
8373 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8376 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8379 /* No sense saving up arithmetic to be done
8380 if it's all in the wrong mode to form part of an address.
8381 And force_operand won't know whether to sign-extend or
8383 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8384 || mode
!= ptr_mode
)
8387 expand_operands (treeop0
, treeop1
,
8388 subtarget
, &op0
, &op1
, modifier
);
8390 /* Convert A - const to A + (-const). */
8391 if (CONST_INT_P (op1
))
8393 op1
= negate_rtx (mode
, op1
);
8394 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8399 case WIDEN_MULT_PLUS_EXPR
:
8400 case WIDEN_MULT_MINUS_EXPR
:
8401 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8402 op2
= expand_normal (treeop2
);
8403 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8407 case WIDEN_MULT_EXPR
:
8408 /* If first operand is constant, swap them.
8409 Thus the following special case checks need only
8410 check the second operand. */
8411 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8412 std::swap (treeop0
, treeop1
);
8414 /* First, check if we have a multiplication of one signed and one
8415 unsigned operand. */
8416 if (TREE_CODE (treeop1
) != INTEGER_CST
8417 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8418 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8420 machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8421 this_optab
= usmul_widen_optab
;
8422 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8423 != CODE_FOR_nothing
)
8425 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8426 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8429 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8431 /* op0 and op1 might still be constant, despite the above
8432 != INTEGER_CST check. Handle it. */
8433 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8435 op0
= convert_modes (innermode
, mode
, op0
, true);
8436 op1
= convert_modes (innermode
, mode
, op1
, false);
8437 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8438 target
, unsignedp
));
8443 /* Check for a multiplication with matching signedness. */
8444 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8445 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8446 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8447 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8449 tree op0type
= TREE_TYPE (treeop0
);
8450 machine_mode innermode
= TYPE_MODE (op0type
);
8451 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8452 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8453 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8455 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8457 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8458 != CODE_FOR_nothing
)
8460 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8462 /* op0 and op1 might still be constant, despite the above
8463 != INTEGER_CST check. Handle it. */
8464 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8467 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8469 = convert_modes (innermode
, mode
, op1
,
8470 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8471 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8475 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8476 unsignedp
, this_optab
);
8477 return REDUCE_BIT_FIELD (temp
);
8479 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8481 && innermode
== word_mode
)
8484 op0
= expand_normal (treeop0
);
8485 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8486 op1
= convert_modes (innermode
, mode
,
8487 expand_normal (treeop1
),
8488 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8490 op1
= expand_normal (treeop1
);
8491 /* op0 and op1 might still be constant, despite the above
8492 != INTEGER_CST check. Handle it. */
8493 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8494 goto widen_mult_const
;
8495 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8496 unsignedp
, OPTAB_LIB_WIDEN
);
8497 hipart
= gen_highpart (innermode
, temp
);
8498 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8502 emit_move_insn (hipart
, htem
);
8503 return REDUCE_BIT_FIELD (temp
);
8507 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8508 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8509 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8510 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8514 optab opt
= fma_optab
;
8517 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8519 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8521 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8524 gcc_assert (fn
!= NULL_TREE
);
8525 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8526 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8529 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8530 /* The multiplication is commutative - look at its 2nd operand
8531 if the first isn't fed by a negate. */
8534 def0
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8535 /* Swap operands if the 2nd operand is fed by a negate. */
8537 std::swap (treeop0
, treeop1
);
8539 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8544 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8547 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8548 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8551 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8554 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8557 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8560 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8564 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8566 op2
= expand_normal (treeop2
);
8567 op1
= expand_normal (treeop1
);
8569 return expand_ternary_op (TYPE_MODE (type
), opt
,
8570 op0
, op1
, op2
, target
, 0);
8574 /* If this is a fixed-point operation, then we cannot use the code
8575 below because "expand_mult" doesn't support sat/no-sat fixed-point
8577 if (ALL_FIXED_POINT_MODE_P (mode
))
8580 /* If first operand is constant, swap them.
8581 Thus the following special case checks need only
8582 check the second operand. */
8583 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8584 std::swap (treeop0
, treeop1
);
8586 /* Attempt to return something suitable for generating an
8587 indexed address, for machines that support that. */
8589 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8590 && tree_fits_shwi_p (treeop1
))
8592 tree exp1
= treeop1
;
8594 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8598 op0
= force_operand (op0
, NULL_RTX
);
8600 op0
= copy_to_mode_reg (mode
, op0
);
8602 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8603 gen_int_mode (tree_to_shwi (exp1
),
8604 TYPE_MODE (TREE_TYPE (exp1
)))));
8607 if (modifier
== EXPAND_STACK_PARM
)
8610 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8611 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8613 case TRUNC_DIV_EXPR
:
8614 case FLOOR_DIV_EXPR
:
8616 case ROUND_DIV_EXPR
:
8617 case EXACT_DIV_EXPR
:
8618 /* If this is a fixed-point operation, then we cannot use the code
8619 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8621 if (ALL_FIXED_POINT_MODE_P (mode
))
8624 if (modifier
== EXPAND_STACK_PARM
)
8626 /* Possible optimization: compute the dividend with EXPAND_SUM
8627 then if the divisor is constant can optimize the case
8628 where some terms of the dividend have coeffs divisible by it. */
8629 expand_operands (treeop0
, treeop1
,
8630 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8631 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8636 case MULT_HIGHPART_EXPR
:
8637 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8638 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8642 case TRUNC_MOD_EXPR
:
8643 case FLOOR_MOD_EXPR
:
8645 case ROUND_MOD_EXPR
:
8646 if (modifier
== EXPAND_STACK_PARM
)
8648 expand_operands (treeop0
, treeop1
,
8649 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8650 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8652 case FIXED_CONVERT_EXPR
:
8653 op0
= expand_normal (treeop0
);
8654 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8655 target
= gen_reg_rtx (mode
);
8657 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8658 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8659 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8660 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8662 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8665 case FIX_TRUNC_EXPR
:
8666 op0
= expand_normal (treeop0
);
8667 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8668 target
= gen_reg_rtx (mode
);
8669 expand_fix (target
, op0
, unsignedp
);
8673 op0
= expand_normal (treeop0
);
8674 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8675 target
= gen_reg_rtx (mode
);
8676 /* expand_float can't figure out what to do if FROM has VOIDmode.
8677 So give it the correct mode. With -O, cse will optimize this. */
8678 if (GET_MODE (op0
) == VOIDmode
)
8679 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8681 expand_float (target
, op0
,
8682 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8686 op0
= expand_expr (treeop0
, subtarget
,
8687 VOIDmode
, EXPAND_NORMAL
);
8688 if (modifier
== EXPAND_STACK_PARM
)
8690 temp
= expand_unop (mode
,
8691 optab_for_tree_code (NEGATE_EXPR
, type
,
8695 return REDUCE_BIT_FIELD (temp
);
8698 op0
= expand_expr (treeop0
, subtarget
,
8699 VOIDmode
, EXPAND_NORMAL
);
8700 if (modifier
== EXPAND_STACK_PARM
)
8703 /* ABS_EXPR is not valid for complex arguments. */
8704 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8705 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8707 /* Unsigned abs is simply the operand. Testing here means we don't
8708 risk generating incorrect code below. */
8709 if (TYPE_UNSIGNED (type
))
8712 return expand_abs (mode
, op0
, target
, unsignedp
,
8713 safe_from_p (target
, treeop0
, 1));
8717 target
= original_target
;
8719 || modifier
== EXPAND_STACK_PARM
8720 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8721 || GET_MODE (target
) != mode
8723 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8724 target
= gen_reg_rtx (mode
);
8725 expand_operands (treeop0
, treeop1
,
8726 target
, &op0
, &op1
, EXPAND_NORMAL
);
8728 /* First try to do it with a special MIN or MAX instruction.
8729 If that does not win, use a conditional jump to select the proper
8731 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8732 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8737 /* At this point, a MEM target is no longer useful; we will get better
8740 if (! REG_P (target
))
8741 target
= gen_reg_rtx (mode
);
8743 /* If op1 was placed in target, swap op0 and op1. */
8744 if (target
!= op0
&& target
== op1
)
8745 std::swap (op0
, op1
);
8747 /* We generate better code and avoid problems with op1 mentioning
8748 target by forcing op1 into a pseudo if it isn't a constant. */
8749 if (! CONSTANT_P (op1
))
8750 op1
= force_reg (mode
, op1
);
8753 enum rtx_code comparison_code
;
8756 if (code
== MAX_EXPR
)
8757 comparison_code
= unsignedp
? GEU
: GE
;
8759 comparison_code
= unsignedp
? LEU
: LE
;
8761 /* Canonicalize to comparisons against 0. */
8762 if (op1
== const1_rtx
)
8764 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8765 or (a != 0 ? a : 1) for unsigned.
8766 For MIN we are safe converting (a <= 1 ? a : 1)
8767 into (a <= 0 ? a : 1) */
8768 cmpop1
= const0_rtx
;
8769 if (code
== MAX_EXPR
)
8770 comparison_code
= unsignedp
? NE
: GT
;
8772 if (op1
== constm1_rtx
&& !unsignedp
)
8774 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8775 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8776 cmpop1
= const0_rtx
;
8777 if (code
== MIN_EXPR
)
8778 comparison_code
= LT
;
8781 /* Use a conditional move if possible. */
8782 if (can_conditionally_move_p (mode
))
8788 /* Try to emit the conditional move. */
8789 insn
= emit_conditional_move (target
, comparison_code
,
8794 /* If we could do the conditional move, emit the sequence,
8798 rtx_insn
*seq
= get_insns ();
8804 /* Otherwise discard the sequence and fall back to code with
8810 emit_move_insn (target
, op0
);
8812 lab
= gen_label_rtx ();
8813 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8814 unsignedp
, mode
, NULL_RTX
, NULL
, lab
,
8817 emit_move_insn (target
, op1
);
8822 op0
= expand_expr (treeop0
, subtarget
,
8823 VOIDmode
, EXPAND_NORMAL
);
8824 if (modifier
== EXPAND_STACK_PARM
)
8826 /* In case we have to reduce the result to bitfield precision
8827 for unsigned bitfield expand this as XOR with a proper constant
8829 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8831 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
8832 false, GET_MODE_PRECISION (mode
));
8834 temp
= expand_binop (mode
, xor_optab
, op0
,
8835 immed_wide_int_const (mask
, mode
),
8836 target
, 1, OPTAB_LIB_WIDEN
);
8839 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8843 /* ??? Can optimize bitwise operations with one arg constant.
8844 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8845 and (a bitwise1 b) bitwise2 b (etc)
8846 but that is probably not worth while. */
8855 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8856 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8857 == TYPE_PRECISION (type
)));
8862 /* If this is a fixed-point operation, then we cannot use the code
8863 below because "expand_shift" doesn't support sat/no-sat fixed-point
8865 if (ALL_FIXED_POINT_MODE_P (mode
))
8868 if (! safe_from_p (subtarget
, treeop1
, 1))
8870 if (modifier
== EXPAND_STACK_PARM
)
8872 op0
= expand_expr (treeop0
, subtarget
,
8873 VOIDmode
, EXPAND_NORMAL
);
8874 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8876 if (code
== LSHIFT_EXPR
)
8877 temp
= REDUCE_BIT_FIELD (temp
);
8880 /* Could determine the answer when only additive constants differ. Also,
8881 the addition of one can be handled by changing the condition. */
8888 case UNORDERED_EXPR
:
8897 temp
= do_store_flag (ops
,
8898 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8899 tmode
!= VOIDmode
? tmode
: mode
);
8903 /* Use a compare and a jump for BLKmode comparisons, or for function
8904 type comparisons is have_canonicalize_funcptr_for_compare. */
8907 || modifier
== EXPAND_STACK_PARM
8908 || ! safe_from_p (target
, treeop0
, 1)
8909 || ! safe_from_p (target
, treeop1
, 1)
8910 /* Make sure we don't have a hard reg (such as function's return
8911 value) live across basic blocks, if not optimizing. */
8912 || (!optimize
&& REG_P (target
)
8913 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8914 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8916 emit_move_insn (target
, const0_rtx
);
8918 rtx_code_label
*lab1
= gen_label_rtx ();
8919 jumpifnot_1 (code
, treeop0
, treeop1
, lab1
, -1);
8921 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8922 emit_move_insn (target
, constm1_rtx
);
8924 emit_move_insn (target
, const1_rtx
);
8930 /* Get the rtx code of the operands. */
8931 op0
= expand_normal (treeop0
);
8932 op1
= expand_normal (treeop1
);
8935 target
= gen_reg_rtx (TYPE_MODE (type
));
8937 /* If target overlaps with op1, then either we need to force
8938 op1 into a pseudo (if target also overlaps with op0),
8939 or write the complex parts in reverse order. */
8940 switch (GET_CODE (target
))
8943 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
8945 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
8947 complex_expr_force_op1
:
8948 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
8949 emit_move_insn (temp
, op1
);
8953 complex_expr_swap_order
:
8954 /* Move the imaginary (op1) and real (op0) parts to their
8956 write_complex_part (target
, op1
, true);
8957 write_complex_part (target
, op0
, false);
8963 temp
= adjust_address_nv (target
,
8964 GET_MODE_INNER (GET_MODE (target
)), 0);
8965 if (reg_overlap_mentioned_p (temp
, op1
))
8967 machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
8968 temp
= adjust_address_nv (target
, imode
,
8969 GET_MODE_SIZE (imode
));
8970 if (reg_overlap_mentioned_p (temp
, op0
))
8971 goto complex_expr_force_op1
;
8972 goto complex_expr_swap_order
;
8976 if (reg_overlap_mentioned_p (target
, op1
))
8978 if (reg_overlap_mentioned_p (target
, op0
))
8979 goto complex_expr_force_op1
;
8980 goto complex_expr_swap_order
;
8985 /* Move the real (op0) and imaginary (op1) parts to their location. */
8986 write_complex_part (target
, op0
, false);
8987 write_complex_part (target
, op1
, true);
8991 case WIDEN_SUM_EXPR
:
8993 tree oprnd0
= treeop0
;
8994 tree oprnd1
= treeop1
;
8996 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8997 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9002 case REDUC_MAX_EXPR
:
9003 case REDUC_MIN_EXPR
:
9004 case REDUC_PLUS_EXPR
:
9006 op0
= expand_normal (treeop0
);
9007 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9008 machine_mode vec_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9010 if (optab_handler (this_optab
, vec_mode
) != CODE_FOR_nothing
)
9012 struct expand_operand ops
[2];
9013 enum insn_code icode
= optab_handler (this_optab
, vec_mode
);
9015 create_output_operand (&ops
[0], target
, mode
);
9016 create_input_operand (&ops
[1], op0
, vec_mode
);
9017 if (maybe_expand_insn (icode
, 2, ops
))
9019 target
= ops
[0].value
;
9020 if (GET_MODE (target
) != mode
)
9021 return gen_lowpart (tmode
, target
);
9025 /* Fall back to optab with vector result, and then extract scalar. */
9026 this_optab
= scalar_reduc_to_vector (this_optab
, type
);
9027 temp
= expand_unop (vec_mode
, this_optab
, op0
, NULL_RTX
, unsignedp
);
9029 /* The tree code produces a scalar result, but (somewhat by convention)
9030 the optab produces a vector with the result in element 0 if
9031 little-endian, or element N-1 if big-endian. So pull the scalar
9032 result out of that element. */
9033 int index
= BYTES_BIG_ENDIAN
? GET_MODE_NUNITS (vec_mode
) - 1 : 0;
9034 int bitsize
= GET_MODE_BITSIZE (GET_MODE_INNER (vec_mode
));
9035 temp
= extract_bit_field (temp
, bitsize
, bitsize
* index
, unsignedp
,
9036 target
, mode
, mode
);
9041 case VEC_UNPACK_HI_EXPR
:
9042 case VEC_UNPACK_LO_EXPR
:
9044 op0
= expand_normal (treeop0
);
9045 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9051 case VEC_UNPACK_FLOAT_HI_EXPR
:
9052 case VEC_UNPACK_FLOAT_LO_EXPR
:
9054 op0
= expand_normal (treeop0
);
9055 /* The signedness is determined from input operand. */
9056 temp
= expand_widen_pattern_expr
9057 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9058 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9064 case VEC_WIDEN_MULT_HI_EXPR
:
9065 case VEC_WIDEN_MULT_LO_EXPR
:
9066 case VEC_WIDEN_MULT_EVEN_EXPR
:
9067 case VEC_WIDEN_MULT_ODD_EXPR
:
9068 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9069 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9070 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9071 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9073 gcc_assert (target
);
9076 case VEC_PACK_TRUNC_EXPR
:
9077 case VEC_PACK_SAT_EXPR
:
9078 case VEC_PACK_FIX_TRUNC_EXPR
:
9079 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9083 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9084 op2
= expand_normal (treeop2
);
9086 /* Careful here: if the target doesn't support integral vector modes,
9087 a constant selection vector could wind up smooshed into a normal
9088 integral constant. */
9089 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9091 tree sel_type
= TREE_TYPE (treeop2
);
9093 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9094 TYPE_VECTOR_SUBPARTS (sel_type
));
9095 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9096 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9097 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9100 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9102 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9108 tree oprnd0
= treeop0
;
9109 tree oprnd1
= treeop1
;
9110 tree oprnd2
= treeop2
;
9113 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9114 op2
= expand_normal (oprnd2
);
9115 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9122 tree oprnd0
= treeop0
;
9123 tree oprnd1
= treeop1
;
9124 tree oprnd2
= treeop2
;
9127 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9128 op2
= expand_normal (oprnd2
);
9129 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9134 case REALIGN_LOAD_EXPR
:
9136 tree oprnd0
= treeop0
;
9137 tree oprnd1
= treeop1
;
9138 tree oprnd2
= treeop2
;
9141 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9142 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9143 op2
= expand_normal (oprnd2
);
9144 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9152 /* A COND_EXPR with its type being VOID_TYPE represents a
9153 conditional jump and is handled in
9154 expand_gimple_cond_expr. */
9155 gcc_assert (!VOID_TYPE_P (type
));
9157 /* Note that COND_EXPRs whose type is a structure or union
9158 are required to be constructed to contain assignments of
9159 a temporary variable, so that we can evaluate them here
9160 for side effect only. If type is void, we must do likewise. */
9162 gcc_assert (!TREE_ADDRESSABLE (type
)
9164 && TREE_TYPE (treeop1
) != void_type_node
9165 && TREE_TYPE (treeop2
) != void_type_node
);
9167 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9171 /* If we are not to produce a result, we have no target. Otherwise,
9172 if a target was specified use it; it will not be used as an
9173 intermediate target unless it is safe. If no target, use a
9176 if (modifier
!= EXPAND_STACK_PARM
9178 && safe_from_p (original_target
, treeop0
, 1)
9179 && GET_MODE (original_target
) == mode
9180 && !MEM_P (original_target
))
9181 temp
= original_target
;
9183 temp
= assign_temp (type
, 0, 1);
9185 do_pending_stack_adjust ();
9187 rtx_code_label
*lab0
= gen_label_rtx ();
9188 rtx_code_label
*lab1
= gen_label_rtx ();
9189 jumpifnot (treeop0
, lab0
, -1);
9190 store_expr (treeop1
, temp
,
9191 modifier
== EXPAND_STACK_PARM
,
9194 emit_jump_insn (targetm
.gen_jump (lab1
));
9197 store_expr (treeop2
, temp
,
9198 modifier
== EXPAND_STACK_PARM
,
9207 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9214 /* Here to do an ordinary binary operator. */
9216 expand_operands (treeop0
, treeop1
,
9217 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9219 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9221 if (modifier
== EXPAND_STACK_PARM
)
9223 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9224 unsignedp
, OPTAB_LIB_WIDEN
);
9226 /* Bitwise operations do not need bitfield reduction as we expect their
9227 operands being properly truncated. */
9228 if (code
== BIT_XOR_EXPR
9229 || code
== BIT_AND_EXPR
9230 || code
== BIT_IOR_EXPR
)
9232 return REDUCE_BIT_FIELD (temp
);
9234 #undef REDUCE_BIT_FIELD
9237 /* Return TRUE if expression STMT is suitable for replacement.
9238 Never consider memory loads as replaceable, because those don't ever lead
9239 into constant expressions. */
9242 stmt_is_replaceable_p (gimple stmt
)
9244 if (ssa_is_replaceable_p (stmt
))
9246 /* Don't move around loads. */
9247 if (!gimple_assign_single_p (stmt
)
9248 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9255 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
9256 enum expand_modifier modifier
, rtx
*alt_rtl
,
9257 bool inner_reference_p
)
9259 rtx op0
, op1
, temp
, decl_rtl
;
9263 enum tree_code code
= TREE_CODE (exp
);
9264 rtx subtarget
, original_target
;
9267 bool reduce_bit_field
;
9268 location_t loc
= EXPR_LOCATION (exp
);
9269 struct separate_ops ops
;
9270 tree treeop0
, treeop1
, treeop2
;
9271 tree ssa_name
= NULL_TREE
;
9274 type
= TREE_TYPE (exp
);
9275 mode
= TYPE_MODE (type
);
9276 unsignedp
= TYPE_UNSIGNED (type
);
9278 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9279 if (!VL_EXP_CLASS_P (exp
))
9280 switch (TREE_CODE_LENGTH (code
))
9283 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9284 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9285 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9295 ignore
= (target
== const0_rtx
9296 || ((CONVERT_EXPR_CODE_P (code
)
9297 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9298 && TREE_CODE (type
) == VOID_TYPE
));
9300 /* An operation in what may be a bit-field type needs the
9301 result to be reduced to the precision of the bit-field type,
9302 which is narrower than that of the type's mode. */
9303 reduce_bit_field
= (!ignore
9304 && INTEGRAL_TYPE_P (type
)
9305 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9307 /* If we are going to ignore this result, we need only do something
9308 if there is a side-effect somewhere in the expression. If there
9309 is, short-circuit the most common cases here. Note that we must
9310 not call expand_expr with anything but const0_rtx in case this
9311 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9315 if (! TREE_SIDE_EFFECTS (exp
))
9318 /* Ensure we reference a volatile object even if value is ignored, but
9319 don't do this if all we are doing is taking its address. */
9320 if (TREE_THIS_VOLATILE (exp
)
9321 && TREE_CODE (exp
) != FUNCTION_DECL
9322 && mode
!= VOIDmode
&& mode
!= BLKmode
9323 && modifier
!= EXPAND_CONST_ADDRESS
)
9325 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9331 if (TREE_CODE_CLASS (code
) == tcc_unary
9332 || code
== BIT_FIELD_REF
9333 || code
== COMPONENT_REF
9334 || code
== INDIRECT_REF
)
9335 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9338 else if (TREE_CODE_CLASS (code
) == tcc_binary
9339 || TREE_CODE_CLASS (code
) == tcc_comparison
9340 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9342 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9343 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9350 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9353 /* Use subtarget as the target for operand 0 of a binary operation. */
9354 subtarget
= get_subtarget (target
);
9355 original_target
= target
;
9361 tree function
= decl_function_context (exp
);
9363 temp
= label_rtx (exp
);
9364 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9366 if (function
!= current_function_decl
9368 LABEL_REF_NONLOCAL_P (temp
) = 1;
9370 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9375 /* ??? ivopts calls expander, without any preparation from
9376 out-of-ssa. So fake instructions as if this was an access to the
9377 base variable. This unnecessarily allocates a pseudo, see how we can
9378 reuse it, if partition base vars have it set already. */
9379 if (!currently_expanding_to_rtl
)
9381 tree var
= SSA_NAME_VAR (exp
);
9382 if (var
&& DECL_RTL_SET_P (var
))
9383 return DECL_RTL (var
);
9384 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9385 LAST_VIRTUAL_REGISTER
+ 1);
9388 g
= get_gimple_for_ssa_name (exp
);
9389 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9391 && modifier
== EXPAND_INITIALIZER
9392 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9393 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9394 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9395 g
= SSA_NAME_DEF_STMT (exp
);
9399 ops
.code
= gimple_assign_rhs_code (g
);
9400 switch (get_gimple_rhs_class (ops
.code
))
9402 case GIMPLE_TERNARY_RHS
:
9403 ops
.op2
= gimple_assign_rhs3 (g
);
9405 case GIMPLE_BINARY_RHS
:
9406 ops
.op1
= gimple_assign_rhs2 (g
);
9408 /* Try to expand conditonal compare. */
9409 if (targetm
.gen_ccmp_first
)
9411 gcc_checking_assert (targetm
.gen_ccmp_next
!= NULL
);
9412 r
= expand_ccmp_expr (g
);
9417 case GIMPLE_UNARY_RHS
:
9418 ops
.op0
= gimple_assign_rhs1 (g
);
9419 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9420 ops
.location
= gimple_location (g
);
9421 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9423 case GIMPLE_SINGLE_RHS
:
9425 location_t saved_loc
= curr_insn_location ();
9426 set_curr_insn_location (gimple_location (g
));
9427 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9428 tmode
, modifier
, NULL
, inner_reference_p
);
9429 set_curr_insn_location (saved_loc
);
9435 if (REG_P (r
) && !REG_EXPR (r
))
9436 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9441 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9442 exp
= SSA_NAME_VAR (ssa_name
);
9443 goto expand_decl_rtl
;
9447 /* If a static var's type was incomplete when the decl was written,
9448 but the type is complete now, lay out the decl now. */
9449 if (DECL_SIZE (exp
) == 0
9450 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9451 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9452 layout_decl (exp
, 0);
9454 /* ... fall through ... */
9458 decl_rtl
= DECL_RTL (exp
);
9460 gcc_assert (decl_rtl
);
9461 decl_rtl
= copy_rtx (decl_rtl
);
9462 /* Record writes to register variables. */
9463 if (modifier
== EXPAND_WRITE
9465 && HARD_REGISTER_P (decl_rtl
))
9466 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9467 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9469 /* Ensure variable marked as used even if it doesn't go through
9470 a parser. If it hasn't be used yet, write out an external
9472 TREE_USED (exp
) = 1;
9474 /* Show we haven't gotten RTL for this yet. */
9477 /* Variables inherited from containing functions should have
9478 been lowered by this point. */
9479 context
= decl_function_context (exp
);
9480 gcc_assert (SCOPE_FILE_SCOPE_P (context
)
9481 || context
== current_function_decl
9482 || TREE_STATIC (exp
)
9483 || DECL_EXTERNAL (exp
)
9484 /* ??? C++ creates functions that are not TREE_STATIC. */
9485 || TREE_CODE (exp
) == FUNCTION_DECL
);
9487 /* This is the case of an array whose size is to be determined
9488 from its initializer, while the initializer is still being parsed.
9489 ??? We aren't parsing while expanding anymore. */
9491 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9492 temp
= validize_mem (decl_rtl
);
9494 /* If DECL_RTL is memory, we are in the normal case and the
9495 address is not valid, get the address into a register. */
9497 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9500 *alt_rtl
= decl_rtl
;
9501 decl_rtl
= use_anchored_address (decl_rtl
);
9502 if (modifier
!= EXPAND_CONST_ADDRESS
9503 && modifier
!= EXPAND_SUM
9504 && !memory_address_addr_space_p (DECL_MODE (exp
),
9506 MEM_ADDR_SPACE (decl_rtl
)))
9507 temp
= replace_equiv_address (decl_rtl
,
9508 copy_rtx (XEXP (decl_rtl
, 0)));
9511 /* If we got something, return it. But first, set the alignment
9512 if the address is a register. */
9515 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9516 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9521 /* If the mode of DECL_RTL does not match that of the decl,
9522 there are two cases: we are dealing with a BLKmode value
9523 that is returned in a register, or we are dealing with
9524 a promoted value. In the latter case, return a SUBREG
9525 of the wanted mode, but mark it so that we know that it
9526 was already extended. */
9527 if (REG_P (decl_rtl
)
9528 && DECL_MODE (exp
) != BLKmode
9529 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9533 /* Get the signedness to be used for this variable. Ensure we get
9534 the same mode we got when the variable was declared. */
9535 if (code
== SSA_NAME
9536 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9537 && gimple_code (g
) == GIMPLE_CALL
9538 && !gimple_call_internal_p (g
))
9539 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9540 gimple_call_fntype (g
),
9543 pmode
= promote_decl_mode (exp
, &unsignedp
);
9544 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9546 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9547 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9548 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9555 /* Given that TYPE_PRECISION (type) is not always equal to
9556 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9557 the former to the latter according to the signedness of the
9559 temp
= immed_wide_int_const (wide_int::from
9561 GET_MODE_PRECISION (TYPE_MODE (type
)),
9568 tree tmp
= NULL_TREE
;
9569 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9570 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9571 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9572 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9573 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9574 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9575 return const_vector_from_tree (exp
);
9576 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9578 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9580 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9584 vec
<constructor_elt
, va_gc
> *v
;
9586 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9587 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9588 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9589 tmp
= build_constructor (type
, v
);
9591 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9596 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9599 /* If optimized, generate immediate CONST_DOUBLE
9600 which will be turned into memory by reload if necessary.
9602 We used to force a register so that loop.c could see it. But
9603 this does not allow gen_* patterns to perform optimizations with
9604 the constants. It also produces two insns in cases like "x = 1.0;".
9605 On most machines, floating-point constants are not permitted in
9606 many insns, so we'd end up copying it to a register in any case.
9608 Now, we do the copying in expand_binop, if appropriate. */
9609 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9610 TYPE_MODE (TREE_TYPE (exp
)));
9613 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9614 TYPE_MODE (TREE_TYPE (exp
)));
9617 /* Handle evaluating a complex constant in a CONCAT target. */
9618 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9620 machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9623 rtarg
= XEXP (original_target
, 0);
9624 itarg
= XEXP (original_target
, 1);
9626 /* Move the real and imaginary parts separately. */
9627 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9628 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9631 emit_move_insn (rtarg
, op0
);
9633 emit_move_insn (itarg
, op1
);
9635 return original_target
;
9638 /* ... fall through ... */
9641 temp
= expand_expr_constant (exp
, 1, modifier
);
9643 /* temp contains a constant address.
9644 On RISC machines where a constant address isn't valid,
9645 make some insns to get that address into a register. */
9646 if (modifier
!= EXPAND_CONST_ADDRESS
9647 && modifier
!= EXPAND_INITIALIZER
9648 && modifier
!= EXPAND_SUM
9649 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9650 MEM_ADDR_SPACE (temp
)))
9651 return replace_equiv_address (temp
,
9652 copy_rtx (XEXP (temp
, 0)));
9658 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
9661 if (!SAVE_EXPR_RESOLVED_P (exp
))
9663 /* We can indeed still hit this case, typically via builtin
9664 expanders calling save_expr immediately before expanding
9665 something. Assume this means that we only have to deal
9666 with non-BLKmode values. */
9667 gcc_assert (GET_MODE (ret
) != BLKmode
);
9669 val
= build_decl (curr_insn_location (),
9670 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9671 DECL_ARTIFICIAL (val
) = 1;
9672 DECL_IGNORED_P (val
) = 1;
9674 TREE_OPERAND (exp
, 0) = treeop0
;
9675 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9677 if (!CONSTANT_P (ret
))
9678 ret
= copy_to_reg (ret
);
9679 SET_DECL_RTL (val
, ret
);
9687 /* If we don't need the result, just ensure we evaluate any
9691 unsigned HOST_WIDE_INT idx
;
9694 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9695 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9700 return expand_constructor (exp
, target
, modifier
, false);
9702 case TARGET_MEM_REF
:
9705 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9706 enum insn_code icode
;
9709 op0
= addr_for_mem_ref (exp
, as
, true);
9710 op0
= memory_address_addr_space (mode
, op0
, as
);
9711 temp
= gen_rtx_MEM (mode
, op0
);
9712 set_mem_attributes (temp
, exp
, 0);
9713 set_mem_addr_space (temp
, as
);
9714 align
= get_object_alignment (exp
);
9715 if (modifier
!= EXPAND_WRITE
9716 && modifier
!= EXPAND_MEMORY
9718 && align
< GET_MODE_ALIGNMENT (mode
)
9719 /* If the target does not have special handling for unaligned
9720 loads of mode then it can use regular moves for them. */
9721 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9722 != CODE_FOR_nothing
))
9724 struct expand_operand ops
[2];
9726 /* We've already validated the memory, and we're creating a
9727 new pseudo destination. The predicates really can't fail,
9728 nor can the generator. */
9729 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9730 create_fixed_operand (&ops
[1], temp
);
9731 expand_insn (icode
, 2, ops
);
9732 temp
= ops
[0].value
;
9740 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9741 machine_mode address_mode
;
9742 tree base
= TREE_OPERAND (exp
, 0);
9744 enum insn_code icode
;
9746 /* Handle expansion of non-aliased memory with non-BLKmode. That
9747 might end up in a register. */
9748 if (mem_ref_refers_to_non_mem_p (exp
))
9750 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
9751 base
= TREE_OPERAND (base
, 0);
9753 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9754 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9755 == tree_to_uhwi (TYPE_SIZE (type
))))
9756 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9757 target
, tmode
, modifier
);
9758 if (TYPE_MODE (type
) == BLKmode
)
9760 temp
= assign_stack_temp (DECL_MODE (base
),
9761 GET_MODE_SIZE (DECL_MODE (base
)));
9762 store_expr (base
, temp
, 0, false);
9763 temp
= adjust_address (temp
, BLKmode
, offset
);
9764 set_mem_size (temp
, int_size_in_bytes (type
));
9767 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9768 bitsize_int (offset
* BITS_PER_UNIT
));
9769 return expand_expr (exp
, target
, tmode
, modifier
);
9771 address_mode
= targetm
.addr_space
.address_mode (as
);
9772 base
= TREE_OPERAND (exp
, 0);
9773 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9775 tree mask
= gimple_assign_rhs2 (def_stmt
);
9776 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9777 gimple_assign_rhs1 (def_stmt
), mask
);
9778 TREE_OPERAND (exp
, 0) = base
;
9780 align
= get_object_alignment (exp
);
9781 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9782 op0
= memory_address_addr_space (mode
, op0
, as
);
9783 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9785 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
9786 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9787 op0
= memory_address_addr_space (mode
, op0
, as
);
9789 temp
= gen_rtx_MEM (mode
, op0
);
9790 set_mem_attributes (temp
, exp
, 0);
9791 set_mem_addr_space (temp
, as
);
9792 if (TREE_THIS_VOLATILE (exp
))
9793 MEM_VOLATILE_P (temp
) = 1;
9794 if (modifier
!= EXPAND_WRITE
9795 && modifier
!= EXPAND_MEMORY
9796 && !inner_reference_p
9798 && align
< GET_MODE_ALIGNMENT (mode
))
9800 if ((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
;
9813 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9814 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9815 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9816 (modifier
== EXPAND_STACK_PARM
9817 ? NULL_RTX
: target
),
9826 tree array
= treeop0
;
9827 tree index
= treeop1
;
9830 /* Fold an expression like: "foo"[2].
9831 This is not done in fold so it won't happen inside &.
9832 Don't fold if this is for wide characters since it's too
9833 difficult to do correctly and this is a very rare case. */
9835 if (modifier
!= EXPAND_CONST_ADDRESS
9836 && modifier
!= EXPAND_INITIALIZER
9837 && modifier
!= EXPAND_MEMORY
)
9839 tree t
= fold_read_from_constant_string (exp
);
9842 return expand_expr (t
, target
, tmode
, modifier
);
9845 /* If this is a constant index into a constant array,
9846 just get the value from the array. Handle both the cases when
9847 we have an explicit constructor and when our operand is a variable
9848 that was declared const. */
9850 if (modifier
!= EXPAND_CONST_ADDRESS
9851 && modifier
!= EXPAND_INITIALIZER
9852 && modifier
!= EXPAND_MEMORY
9853 && TREE_CODE (array
) == CONSTRUCTOR
9854 && ! TREE_SIDE_EFFECTS (array
)
9855 && TREE_CODE (index
) == INTEGER_CST
)
9857 unsigned HOST_WIDE_INT ix
;
9860 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9862 if (tree_int_cst_equal (field
, index
))
9864 if (!TREE_SIDE_EFFECTS (value
))
9865 return expand_expr (fold (value
), target
, tmode
, modifier
);
9870 else if (optimize
>= 1
9871 && modifier
!= EXPAND_CONST_ADDRESS
9872 && modifier
!= EXPAND_INITIALIZER
9873 && modifier
!= EXPAND_MEMORY
9874 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9875 && TREE_CODE (index
) == INTEGER_CST
9876 && (TREE_CODE (array
) == VAR_DECL
9877 || TREE_CODE (array
) == CONST_DECL
)
9878 && (init
= ctor_for_folding (array
)) != error_mark_node
)
9880 if (init
== NULL_TREE
)
9882 tree value
= build_zero_cst (type
);
9883 if (TREE_CODE (value
) == CONSTRUCTOR
)
9885 /* If VALUE is a CONSTRUCTOR, this optimization is only
9886 useful if this doesn't store the CONSTRUCTOR into
9887 memory. If it does, it is more efficient to just
9888 load the data from the array directly. */
9889 rtx ret
= expand_constructor (value
, target
,
9891 if (ret
== NULL_RTX
)
9896 return expand_expr (value
, target
, tmode
, modifier
);
9898 else if (TREE_CODE (init
) == CONSTRUCTOR
)
9900 unsigned HOST_WIDE_INT ix
;
9903 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9905 if (tree_int_cst_equal (field
, index
))
9907 if (TREE_SIDE_EFFECTS (value
))
9910 if (TREE_CODE (value
) == CONSTRUCTOR
)
9912 /* If VALUE is a CONSTRUCTOR, this
9913 optimization is only useful if
9914 this doesn't store the CONSTRUCTOR
9915 into memory. If it does, it is more
9916 efficient to just load the data from
9917 the array directly. */
9918 rtx ret
= expand_constructor (value
, target
,
9920 if (ret
== NULL_RTX
)
9925 expand_expr (fold (value
), target
, tmode
, modifier
);
9928 else if (TREE_CODE (init
) == STRING_CST
)
9930 tree low_bound
= array_ref_low_bound (exp
);
9931 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
9933 /* Optimize the special case of a zero lower bound.
9935 We convert the lower bound to sizetype to avoid problems
9936 with constant folding. E.g. suppose the lower bound is
9937 1 and its mode is QI. Without the conversion
9938 (ARRAY + (INDEX - (unsigned char)1))
9940 (ARRAY + (-(unsigned char)1) + INDEX)
9942 (ARRAY + 255 + INDEX). Oops! */
9943 if (!integer_zerop (low_bound
))
9944 index1
= size_diffop_loc (loc
, index1
,
9945 fold_convert_loc (loc
, sizetype
,
9948 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
9950 tree type
= TREE_TYPE (TREE_TYPE (init
));
9951 machine_mode mode
= TYPE_MODE (type
);
9953 if (GET_MODE_CLASS (mode
) == MODE_INT
9954 && GET_MODE_SIZE (mode
) == 1)
9955 return gen_int_mode (TREE_STRING_POINTER (init
)
9956 [TREE_INT_CST_LOW (index1
)],
9962 goto normal_inner_ref
;
9965 /* If the operand is a CONSTRUCTOR, we can just extract the
9966 appropriate field if it is present. */
9967 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9969 unsigned HOST_WIDE_INT idx
;
9972 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9974 if (field
== treeop1
9975 /* We can normally use the value of the field in the
9976 CONSTRUCTOR. However, if this is a bitfield in
9977 an integral mode that we can fit in a HOST_WIDE_INT,
9978 we must mask only the number of bits in the bitfield,
9979 since this is done implicitly by the constructor. If
9980 the bitfield does not meet either of those conditions,
9981 we can't do this optimization. */
9982 && (! DECL_BIT_FIELD (field
)
9983 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9984 && (GET_MODE_PRECISION (DECL_MODE (field
))
9985 <= HOST_BITS_PER_WIDE_INT
))))
9987 if (DECL_BIT_FIELD (field
)
9988 && modifier
== EXPAND_STACK_PARM
)
9990 op0
= expand_expr (value
, target
, tmode
, modifier
);
9991 if (DECL_BIT_FIELD (field
))
9993 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9994 machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9996 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9998 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
10000 op0
= expand_and (imode
, op0
, op1
, target
);
10004 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10006 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10008 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10016 goto normal_inner_ref
;
10018 case BIT_FIELD_REF
:
10019 case ARRAY_RANGE_REF
:
10022 machine_mode mode1
, mode2
;
10023 HOST_WIDE_INT bitsize
, bitpos
;
10025 int volatilep
= 0, must_force_mem
;
10026 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
10027 &mode1
, &unsignedp
, &volatilep
, true);
10028 rtx orig_op0
, memloc
;
10029 bool clear_mem_expr
= false;
10031 /* If we got back the original object, something is wrong. Perhaps
10032 we are evaluating an expression too early. In any event, don't
10033 infinitely recurse. */
10034 gcc_assert (tem
!= exp
);
10036 /* If TEM's type is a union of variable size, pass TARGET to the inner
10037 computation, since it will need a temporary and TARGET is known
10038 to have to do. This occurs in unchecked conversion in Ada. */
10040 = expand_expr_real (tem
,
10041 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10042 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10043 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10045 && modifier
!= EXPAND_STACK_PARM
10046 ? target
: NULL_RTX
),
10048 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10051 /* If the field has a mode, we want to access it in the
10052 field's mode, not the computed mode.
10053 If a MEM has VOIDmode (external with incomplete type),
10054 use BLKmode for it instead. */
10057 if (mode1
!= VOIDmode
)
10058 op0
= adjust_address (op0
, mode1
, 0);
10059 else if (GET_MODE (op0
) == VOIDmode
)
10060 op0
= adjust_address (op0
, BLKmode
, 0);
10064 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10066 /* If we have either an offset, a BLKmode result, or a reference
10067 outside the underlying object, we must force it to memory.
10068 Such a case can occur in Ada if we have unchecked conversion
10069 of an expression from a scalar type to an aggregate type or
10070 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10071 passed a partially uninitialized object or a view-conversion
10072 to a larger size. */
10073 must_force_mem
= (offset
10074 || mode1
== BLKmode
10075 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10077 /* Handle CONCAT first. */
10078 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10081 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
10084 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10087 op0
= XEXP (op0
, 0);
10088 mode2
= GET_MODE (op0
);
10090 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10091 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10095 op0
= XEXP (op0
, 1);
10097 mode2
= GET_MODE (op0
);
10100 /* Otherwise force into memory. */
10101 must_force_mem
= 1;
10104 /* If this is a constant, put it in a register if it is a legitimate
10105 constant and we don't need a memory reference. */
10106 if (CONSTANT_P (op0
)
10107 && mode2
!= BLKmode
10108 && targetm
.legitimate_constant_p (mode2
, op0
)
10109 && !must_force_mem
)
10110 op0
= force_reg (mode2
, op0
);
10112 /* Otherwise, if this is a constant, try to force it to the constant
10113 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10114 is a legitimate constant. */
10115 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10116 op0
= validize_mem (memloc
);
10118 /* Otherwise, if this is a constant or the object is not in memory
10119 and need be, put it there. */
10120 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10122 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10123 emit_move_insn (memloc
, op0
);
10125 clear_mem_expr
= true;
10130 machine_mode address_mode
;
10131 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10134 gcc_assert (MEM_P (op0
));
10136 address_mode
= get_address_mode (op0
);
10137 if (GET_MODE (offset_rtx
) != address_mode
)
10139 /* We cannot be sure that the RTL in offset_rtx is valid outside
10140 of a memory address context, so force it into a register
10141 before attempting to convert it to the desired mode. */
10142 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
10143 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10146 /* See the comment in expand_assignment for the rationale. */
10147 if (mode1
!= VOIDmode
10150 && (bitpos
% bitsize
) == 0
10151 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10152 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10154 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10158 op0
= offset_address (op0
, offset_rtx
,
10159 highest_pow2_factor (offset
));
10162 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10163 record its alignment as BIGGEST_ALIGNMENT. */
10164 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10165 && is_aligning_offset (offset
, tem
))
10166 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10168 /* Don't forget about volatility even if this is a bitfield. */
10169 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10171 if (op0
== orig_op0
)
10172 op0
= copy_rtx (op0
);
10174 MEM_VOLATILE_P (op0
) = 1;
10177 /* In cases where an aligned union has an unaligned object
10178 as a field, we might be extracting a BLKmode value from
10179 an integer-mode (e.g., SImode) object. Handle this case
10180 by doing the extract into an object as wide as the field
10181 (which we know to be the width of a basic mode), then
10182 storing into memory, and changing the mode to BLKmode. */
10183 if (mode1
== VOIDmode
10184 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10185 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10186 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10187 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10188 && modifier
!= EXPAND_CONST_ADDRESS
10189 && modifier
!= EXPAND_INITIALIZER
10190 && modifier
!= EXPAND_MEMORY
)
10191 /* If the bitfield is volatile and the bitsize
10192 is narrower than the access size of the bitfield,
10193 we need to extract bitfields from the access. */
10194 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10195 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10196 && mode1
!= BLKmode
10197 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10198 /* If the field isn't aligned enough to fetch as a memref,
10199 fetch it as a bit field. */
10200 || (mode1
!= BLKmode
10201 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10202 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10204 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10205 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10206 && modifier
!= EXPAND_MEMORY
10207 && ((modifier
== EXPAND_CONST_ADDRESS
10208 || modifier
== EXPAND_INITIALIZER
)
10210 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10211 || (bitpos
% BITS_PER_UNIT
!= 0)))
10212 /* If the type and the field are a constant size and the
10213 size of the type isn't the same size as the bitfield,
10214 we must use bitfield operations. */
10216 && TYPE_SIZE (TREE_TYPE (exp
))
10217 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10218 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10221 machine_mode ext_mode
= mode
;
10223 if (ext_mode
== BLKmode
10224 && ! (target
!= 0 && MEM_P (op0
)
10226 && bitpos
% BITS_PER_UNIT
== 0))
10227 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10229 if (ext_mode
== BLKmode
)
10232 target
= assign_temp (type
, 1, 1);
10234 /* ??? Unlike the similar test a few lines below, this one is
10235 very likely obsolete. */
10239 /* In this case, BITPOS must start at a byte boundary and
10240 TARGET, if specified, must be a MEM. */
10241 gcc_assert (MEM_P (op0
)
10242 && (!target
|| MEM_P (target
))
10243 && !(bitpos
% BITS_PER_UNIT
));
10245 emit_block_move (target
,
10246 adjust_address (op0
, VOIDmode
,
10247 bitpos
/ BITS_PER_UNIT
),
10248 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10250 (modifier
== EXPAND_STACK_PARM
10251 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10256 /* If we have nothing to extract, the result will be 0 for targets
10257 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10258 return 0 for the sake of consistency, as reading a zero-sized
10259 bitfield is valid in Ada and the value is fully specified. */
10263 op0
= validize_mem (op0
);
10265 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10266 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10268 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10269 (modifier
== EXPAND_STACK_PARM
10270 ? NULL_RTX
: target
),
10271 ext_mode
, ext_mode
);
10273 /* If the result is a record type and BITSIZE is narrower than
10274 the mode of OP0, an integral mode, and this is a big endian
10275 machine, we must put the field into the high-order bits. */
10276 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10277 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10278 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10279 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10280 GET_MODE_BITSIZE (GET_MODE (op0
))
10281 - bitsize
, op0
, 1);
10283 /* If the result type is BLKmode, store the data into a temporary
10284 of the appropriate type, but with the mode corresponding to the
10285 mode for the data we have (op0's mode). */
10286 if (mode
== BLKmode
)
10289 = assign_stack_temp_for_type (ext_mode
,
10290 GET_MODE_BITSIZE (ext_mode
),
10292 emit_move_insn (new_rtx
, op0
);
10293 op0
= copy_rtx (new_rtx
);
10294 PUT_MODE (op0
, BLKmode
);
10300 /* If the result is BLKmode, use that to access the object
10302 if (mode
== BLKmode
)
10305 /* Get a reference to just this component. */
10306 if (modifier
== EXPAND_CONST_ADDRESS
10307 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10308 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10310 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10312 if (op0
== orig_op0
)
10313 op0
= copy_rtx (op0
);
10315 set_mem_attributes (op0
, exp
, 0);
10317 if (REG_P (XEXP (op0
, 0)))
10318 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10320 /* If op0 is a temporary because the original expressions was forced
10321 to memory, clear MEM_EXPR so that the original expression cannot
10322 be marked as addressable through MEM_EXPR of the temporary. */
10323 if (clear_mem_expr
)
10324 set_mem_expr (op0
, NULL_TREE
);
10326 MEM_VOLATILE_P (op0
) |= volatilep
;
10327 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10328 || modifier
== EXPAND_CONST_ADDRESS
10329 || modifier
== EXPAND_INITIALIZER
)
10333 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10335 convert_move (target
, op0
, unsignedp
);
10340 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10343 /* All valid uses of __builtin_va_arg_pack () are removed during
10345 if (CALL_EXPR_VA_ARG_PACK (exp
))
10346 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10348 tree fndecl
= get_callee_fndecl (exp
), attr
;
10351 && (attr
= lookup_attribute ("error",
10352 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10353 error ("%Kcall to %qs declared with attribute error: %s",
10354 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10355 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10357 && (attr
= lookup_attribute ("warning",
10358 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10359 warning_at (tree_nonartificial_location (exp
),
10360 0, "%Kcall to %qs declared with attribute warning: %s",
10361 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10362 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10364 /* Check for a built-in function. */
10365 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10367 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10368 if (CALL_WITH_BOUNDS_P (exp
))
10369 return expand_builtin_with_bounds (exp
, target
, subtarget
,
10372 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10375 return expand_call (exp
, target
, ignore
);
10377 case VIEW_CONVERT_EXPR
:
10380 /* If we are converting to BLKmode, try to avoid an intermediate
10381 temporary by fetching an inner memory reference. */
10382 if (mode
== BLKmode
10383 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10384 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10385 && handled_component_p (treeop0
))
10387 machine_mode mode1
;
10388 HOST_WIDE_INT bitsize
, bitpos
;
10393 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10394 &offset
, &mode1
, &unsignedp
, &volatilep
,
10398 /* ??? We should work harder and deal with non-zero offsets. */
10400 && (bitpos
% BITS_PER_UNIT
) == 0
10402 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10404 /* See the normal_inner_ref case for the rationale. */
10406 = expand_expr_real (tem
,
10407 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10408 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10410 && modifier
!= EXPAND_STACK_PARM
10411 ? target
: NULL_RTX
),
10413 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10416 if (MEM_P (orig_op0
))
10420 /* Get a reference to just this component. */
10421 if (modifier
== EXPAND_CONST_ADDRESS
10422 || modifier
== EXPAND_SUM
10423 || modifier
== EXPAND_INITIALIZER
)
10424 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10426 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10428 if (op0
== orig_op0
)
10429 op0
= copy_rtx (op0
);
10431 set_mem_attributes (op0
, treeop0
, 0);
10432 if (REG_P (XEXP (op0
, 0)))
10433 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10435 MEM_VOLATILE_P (op0
) |= volatilep
;
10441 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10442 NULL
, inner_reference_p
);
10444 /* If the input and output modes are both the same, we are done. */
10445 if (mode
== GET_MODE (op0
))
10447 /* If neither mode is BLKmode, and both modes are the same size
10448 then we can use gen_lowpart. */
10449 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10450 && (GET_MODE_PRECISION (mode
)
10451 == GET_MODE_PRECISION (GET_MODE (op0
)))
10452 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10454 if (GET_CODE (op0
) == SUBREG
)
10455 op0
= force_reg (GET_MODE (op0
), op0
);
10456 temp
= gen_lowpart_common (mode
, op0
);
10461 if (!REG_P (op0
) && !MEM_P (op0
))
10462 op0
= force_reg (GET_MODE (op0
), op0
);
10463 op0
= gen_lowpart (mode
, op0
);
10466 /* If both types are integral, convert from one mode to the other. */
10467 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10468 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10469 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10470 /* If the output type is a bit-field type, do an extraction. */
10471 else if (reduce_bit_field
)
10472 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10473 TYPE_UNSIGNED (type
), NULL_RTX
,
10475 /* As a last resort, spill op0 to memory, and reload it in a
10477 else if (!MEM_P (op0
))
10479 /* If the operand is not a MEM, force it into memory. Since we
10480 are going to be changing the mode of the MEM, don't call
10481 force_const_mem for constants because we don't allow pool
10482 constants to change mode. */
10483 tree inner_type
= TREE_TYPE (treeop0
);
10485 gcc_assert (!TREE_ADDRESSABLE (exp
));
10487 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10489 = assign_stack_temp_for_type
10490 (TYPE_MODE (inner_type
),
10491 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10493 emit_move_insn (target
, op0
);
10497 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10498 output type is such that the operand is known to be aligned, indicate
10499 that it is. Otherwise, we need only be concerned about alignment for
10500 non-BLKmode results. */
10503 enum insn_code icode
;
10505 if (TYPE_ALIGN_OK (type
))
10507 /* ??? Copying the MEM without substantially changing it might
10508 run afoul of the code handling volatile memory references in
10509 store_expr, which assumes that TARGET is returned unmodified
10510 if it has been used. */
10511 op0
= copy_rtx (op0
);
10512 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10514 else if (modifier
!= EXPAND_WRITE
10515 && modifier
!= EXPAND_MEMORY
10516 && !inner_reference_p
10518 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10520 /* If the target does have special handling for unaligned
10521 loads of mode then use them. */
10522 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10523 != CODE_FOR_nothing
)
10527 op0
= adjust_address (op0
, mode
, 0);
10528 /* We've already validated the memory, and we're creating a
10529 new pseudo destination. The predicates really can't
10531 reg
= gen_reg_rtx (mode
);
10533 /* Nor can the insn generator. */
10534 rtx_insn
*insn
= GEN_FCN (icode
) (reg
, op0
);
10538 else if (STRICT_ALIGNMENT
)
10540 tree inner_type
= TREE_TYPE (treeop0
);
10541 HOST_WIDE_INT temp_size
10542 = MAX (int_size_in_bytes (inner_type
),
10543 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10545 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10546 rtx new_with_op0_mode
10547 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10549 gcc_assert (!TREE_ADDRESSABLE (exp
));
10551 if (GET_MODE (op0
) == BLKmode
)
10552 emit_block_move (new_with_op0_mode
, op0
,
10553 GEN_INT (GET_MODE_SIZE (mode
)),
10554 (modifier
== EXPAND_STACK_PARM
10555 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10557 emit_move_insn (new_with_op0_mode
, op0
);
10563 op0
= adjust_address (op0
, mode
, 0);
10570 tree lhs
= treeop0
;
10571 tree rhs
= treeop1
;
10572 gcc_assert (ignore
);
10574 /* Check for |= or &= of a bitfield of size one into another bitfield
10575 of size 1. In this case, (unless we need the result of the
10576 assignment) we can do this more efficiently with a
10577 test followed by an assignment, if necessary.
10579 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10580 things change so we do, this code should be enhanced to
10582 if (TREE_CODE (lhs
) == COMPONENT_REF
10583 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10584 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10585 && TREE_OPERAND (rhs
, 0) == lhs
10586 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10587 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10588 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10590 rtx_code_label
*label
= gen_label_rtx ();
10591 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10592 do_jump (TREE_OPERAND (rhs
, 1),
10594 value
? 0 : label
, -1);
10595 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10597 do_pending_stack_adjust ();
10598 emit_label (label
);
10602 expand_assignment (lhs
, rhs
, false);
10607 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10609 case REALPART_EXPR
:
10610 op0
= expand_normal (treeop0
);
10611 return read_complex_part (op0
, false);
10613 case IMAGPART_EXPR
:
10614 op0
= expand_normal (treeop0
);
10615 return read_complex_part (op0
, true);
10622 /* Expanded in cfgexpand.c. */
10623 gcc_unreachable ();
10625 case TRY_CATCH_EXPR
:
10627 case EH_FILTER_EXPR
:
10628 case TRY_FINALLY_EXPR
:
10629 /* Lowered by tree-eh.c. */
10630 gcc_unreachable ();
10632 case WITH_CLEANUP_EXPR
:
10633 case CLEANUP_POINT_EXPR
:
10635 case CASE_LABEL_EXPR
:
10640 case COMPOUND_EXPR
:
10641 case PREINCREMENT_EXPR
:
10642 case PREDECREMENT_EXPR
:
10643 case POSTINCREMENT_EXPR
:
10644 case POSTDECREMENT_EXPR
:
10647 case COMPOUND_LITERAL_EXPR
:
10648 /* Lowered by gimplify.c. */
10649 gcc_unreachable ();
10652 /* Function descriptors are not valid except for as
10653 initialization constants, and should not be expanded. */
10654 gcc_unreachable ();
10656 case WITH_SIZE_EXPR
:
10657 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10658 have pulled out the size to use in whatever context it needed. */
10659 return expand_expr_real (treeop0
, original_target
, tmode
,
10660 modifier
, alt_rtl
, inner_reference_p
);
10663 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10667 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10668 signedness of TYPE), possibly returning the result in TARGET. */
10670 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10672 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10673 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10675 /* For constant values, reduce using build_int_cst_type. */
10676 if (CONST_INT_P (exp
))
10678 HOST_WIDE_INT value
= INTVAL (exp
);
10679 tree t
= build_int_cst_type (type
, value
);
10680 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10682 else if (TYPE_UNSIGNED (type
))
10684 machine_mode mode
= GET_MODE (exp
);
10685 rtx mask
= immed_wide_int_const
10686 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
10687 return expand_and (mode
, exp
, mask
, target
);
10691 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10692 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10693 exp
, count
, target
, 0);
10694 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10695 exp
, count
, target
, 0);
10699 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10700 when applied to the address of EXP produces an address known to be
10701 aligned more than BIGGEST_ALIGNMENT. */
10704 is_aligning_offset (const_tree offset
, const_tree exp
)
10706 /* Strip off any conversions. */
10707 while (CONVERT_EXPR_P (offset
))
10708 offset
= TREE_OPERAND (offset
, 0);
10710 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10711 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10712 if (TREE_CODE (offset
) != BIT_AND_EXPR
10713 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10714 || compare_tree_int (TREE_OPERAND (offset
, 1),
10715 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10716 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10719 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10720 It must be NEGATE_EXPR. Then strip any more conversions. */
10721 offset
= TREE_OPERAND (offset
, 0);
10722 while (CONVERT_EXPR_P (offset
))
10723 offset
= TREE_OPERAND (offset
, 0);
10725 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10728 offset
= TREE_OPERAND (offset
, 0);
10729 while (CONVERT_EXPR_P (offset
))
10730 offset
= TREE_OPERAND (offset
, 0);
10732 /* This must now be the address of EXP. */
10733 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10736 /* Return the tree node if an ARG corresponds to a string constant or zero
10737 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10738 in bytes within the string that ARG is accessing. The type of the
10739 offset will be `sizetype'. */
10742 string_constant (tree arg
, tree
*ptr_offset
)
10744 tree array
, offset
, lower_bound
;
10747 if (TREE_CODE (arg
) == ADDR_EXPR
)
10749 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10751 *ptr_offset
= size_zero_node
;
10752 return TREE_OPERAND (arg
, 0);
10754 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10756 array
= TREE_OPERAND (arg
, 0);
10757 offset
= size_zero_node
;
10759 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10761 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10762 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10763 if (TREE_CODE (array
) != STRING_CST
10764 && TREE_CODE (array
) != VAR_DECL
)
10767 /* Check if the array has a nonzero lower bound. */
10768 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10769 if (!integer_zerop (lower_bound
))
10771 /* If the offset and base aren't both constants, return 0. */
10772 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10774 if (TREE_CODE (offset
) != INTEGER_CST
)
10776 /* Adjust offset by the lower bound. */
10777 offset
= size_diffop (fold_convert (sizetype
, offset
),
10778 fold_convert (sizetype
, lower_bound
));
10781 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10783 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10784 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10785 if (TREE_CODE (array
) != ADDR_EXPR
)
10787 array
= TREE_OPERAND (array
, 0);
10788 if (TREE_CODE (array
) != STRING_CST
10789 && TREE_CODE (array
) != VAR_DECL
)
10795 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10797 tree arg0
= TREE_OPERAND (arg
, 0);
10798 tree arg1
= TREE_OPERAND (arg
, 1);
10803 if (TREE_CODE (arg0
) == ADDR_EXPR
10804 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10805 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10807 array
= TREE_OPERAND (arg0
, 0);
10810 else if (TREE_CODE (arg1
) == ADDR_EXPR
10811 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10812 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10814 array
= TREE_OPERAND (arg1
, 0);
10823 if (TREE_CODE (array
) == STRING_CST
)
10825 *ptr_offset
= fold_convert (sizetype
, offset
);
10828 else if (TREE_CODE (array
) == VAR_DECL
10829 || TREE_CODE (array
) == CONST_DECL
)
10832 tree init
= ctor_for_folding (array
);
10834 /* Variables initialized to string literals can be handled too. */
10835 if (init
== error_mark_node
10837 || TREE_CODE (init
) != STRING_CST
)
10840 /* Avoid const char foo[4] = "abcde"; */
10841 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10842 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10843 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10844 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10847 /* If variable is bigger than the string literal, OFFSET must be constant
10848 and inside of the bounds of the string literal. */
10849 offset
= fold_convert (sizetype
, offset
);
10850 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10851 && (! tree_fits_uhwi_p (offset
)
10852 || compare_tree_int (offset
, length
) >= 0))
10855 *ptr_offset
= offset
;
10862 /* Generate code to calculate OPS, and exploded expression
10863 using a store-flag instruction and return an rtx for the result.
10864 OPS reflects a comparison.
10866 If TARGET is nonzero, store the result there if convenient.
10868 Return zero if there is no suitable set-flag instruction
10869 available on this machine.
10871 Once expand_expr has been called on the arguments of the comparison,
10872 we are committed to doing the store flag, since it is not safe to
10873 re-evaluate the expression. We emit the store-flag insn by calling
10874 emit_store_flag, but only expand the arguments if we have a reason
10875 to believe that emit_store_flag will be successful. If we think that
10876 it will, but it isn't, we have to simulate the store-flag with a
10877 set/jump/set sequence. */
10880 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
10882 enum rtx_code code
;
10883 tree arg0
, arg1
, type
;
10884 machine_mode operand_mode
;
10887 rtx subtarget
= target
;
10888 location_t loc
= ops
->location
;
10893 /* Don't crash if the comparison was erroneous. */
10894 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10897 type
= TREE_TYPE (arg0
);
10898 operand_mode
= TYPE_MODE (type
);
10899 unsignedp
= TYPE_UNSIGNED (type
);
10901 /* We won't bother with BLKmode store-flag operations because it would mean
10902 passing a lot of information to emit_store_flag. */
10903 if (operand_mode
== BLKmode
)
10906 /* We won't bother with store-flag operations involving function pointers
10907 when function pointers must be canonicalized before comparisons. */
10908 if (targetm
.have_canonicalize_funcptr_for_compare ()
10909 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10910 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10912 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10913 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10914 == FUNCTION_TYPE
))))
10920 /* For vector typed comparisons emit code to generate the desired
10921 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10922 expander for this. */
10923 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10925 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10926 tree if_true
= constant_boolean_node (true, ops
->type
);
10927 tree if_false
= constant_boolean_node (false, ops
->type
);
10928 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10931 /* Get the rtx comparison code to use. We know that EXP is a comparison
10932 operation of some type. Some comparisons against 1 and -1 can be
10933 converted to comparisons with zero. Do so here so that the tests
10934 below will be aware that we have a comparison with zero. These
10935 tests will not catch constants in the first operand, but constants
10936 are rarely passed as the first operand. */
10947 if (integer_onep (arg1
))
10948 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10950 code
= unsignedp
? LTU
: LT
;
10953 if (! unsignedp
&& integer_all_onesp (arg1
))
10954 arg1
= integer_zero_node
, code
= LT
;
10956 code
= unsignedp
? LEU
: LE
;
10959 if (! unsignedp
&& integer_all_onesp (arg1
))
10960 arg1
= integer_zero_node
, code
= GE
;
10962 code
= unsignedp
? GTU
: GT
;
10965 if (integer_onep (arg1
))
10966 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10968 code
= unsignedp
? GEU
: GE
;
10971 case UNORDERED_EXPR
:
10997 gcc_unreachable ();
11000 /* Put a constant second. */
11001 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11002 || TREE_CODE (arg0
) == FIXED_CST
)
11004 std::swap (arg0
, arg1
);
11005 code
= swap_condition (code
);
11008 /* If this is an equality or inequality test of a single bit, we can
11009 do this by shifting the bit being tested to the low-order bit and
11010 masking the result with the constant 1. If the condition was EQ,
11011 we xor it with 1. This does not require an scc insn and is faster
11012 than an scc insn even if we have it.
11014 The code to make this transformation was moved into fold_single_bit_test,
11015 so we just call into the folder and expand its result. */
11017 if ((code
== NE
|| code
== EQ
)
11018 && integer_zerop (arg1
)
11019 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11021 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11023 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11025 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11026 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11027 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11028 gimple_assign_rhs1 (srcstmt
),
11029 gimple_assign_rhs2 (srcstmt
));
11030 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11032 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11036 if (! get_subtarget (target
)
11037 || GET_MODE (subtarget
) != operand_mode
)
11040 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11043 target
= gen_reg_rtx (mode
);
11045 /* Try a cstore if possible. */
11046 return emit_store_flag_force (target
, code
, op0
, op1
,
11047 operand_mode
, unsignedp
,
11048 (TYPE_PRECISION (ops
->type
) == 1
11049 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11052 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11053 0 otherwise (i.e. if there is no casesi instruction).
11055 DEFAULT_PROBABILITY is the probability of jumping to the default
11058 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11059 rtx table_label
, rtx default_label
, rtx fallback_label
,
11060 int default_probability
)
11062 struct expand_operand ops
[5];
11063 machine_mode index_mode
= SImode
;
11064 rtx op1
, op2
, index
;
11066 if (! targetm
.have_casesi ())
11069 /* Convert the index to SImode. */
11070 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11072 machine_mode omode
= TYPE_MODE (index_type
);
11073 rtx rangertx
= expand_normal (range
);
11075 /* We must handle the endpoints in the original mode. */
11076 index_expr
= build2 (MINUS_EXPR
, index_type
,
11077 index_expr
, minval
);
11078 minval
= integer_zero_node
;
11079 index
= expand_normal (index_expr
);
11081 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11082 omode
, 1, default_label
,
11083 default_probability
);
11084 /* Now we can safely truncate. */
11085 index
= convert_to_mode (index_mode
, index
, 0);
11089 if (TYPE_MODE (index_type
) != index_mode
)
11091 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11092 index_expr
= fold_convert (index_type
, index_expr
);
11095 index
= expand_normal (index_expr
);
11098 do_pending_stack_adjust ();
11100 op1
= expand_normal (minval
);
11101 op2
= expand_normal (range
);
11103 create_input_operand (&ops
[0], index
, index_mode
);
11104 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11105 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11106 create_fixed_operand (&ops
[3], table_label
);
11107 create_fixed_operand (&ops
[4], (default_label
11109 : fallback_label
));
11110 expand_jump_insn (targetm
.code_for_casesi
, 5, ops
);
11114 /* Attempt to generate a tablejump instruction; same concept. */
11115 /* Subroutine of the next function.
11117 INDEX is the value being switched on, with the lowest value
11118 in the table already subtracted.
11119 MODE is its expected mode (needed if INDEX is constant).
11120 RANGE is the length of the jump table.
11121 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11123 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11124 index value is out of range.
11125 DEFAULT_PROBABILITY is the probability of jumping to
11126 the default label. */
11129 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
11130 rtx default_label
, int default_probability
)
11134 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11135 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11137 /* Do an unsigned comparison (in the proper mode) between the index
11138 expression and the value which represents the length of the range.
11139 Since we just finished subtracting the lower bound of the range
11140 from the index expression, this comparison allows us to simultaneously
11141 check that the original index expression value is both greater than
11142 or equal to the minimum value of the range and less than or equal to
11143 the maximum value of the range. */
11146 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11147 default_label
, default_probability
);
11150 /* If index is in range, it must fit in Pmode.
11151 Convert to Pmode so we can index with it. */
11153 index
= convert_to_mode (Pmode
, index
, 1);
11155 /* Don't let a MEM slip through, because then INDEX that comes
11156 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11157 and break_out_memory_refs will go to work on it and mess it up. */
11158 #ifdef PIC_CASE_VECTOR_ADDRESS
11159 if (flag_pic
&& !REG_P (index
))
11160 index
= copy_to_mode_reg (Pmode
, index
);
11163 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11164 GET_MODE_SIZE, because this indicates how large insns are. The other
11165 uses should all be Pmode, because they are addresses. This code
11166 could fail if addresses and insns are not the same size. */
11167 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11168 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11170 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11171 gen_rtx_LABEL_REF (Pmode
, table_label
));
11173 #ifdef PIC_CASE_VECTOR_ADDRESS
11175 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11178 index
= memory_address (CASE_VECTOR_MODE
, index
);
11179 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11180 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11181 convert_move (temp
, vector
, 0);
11183 emit_jump_insn (targetm
.gen_tablejump (temp
, table_label
));
11185 /* If we are generating PIC code or if the table is PC-relative, the
11186 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11187 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11192 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11193 rtx table_label
, rtx default_label
, int default_probability
)
11197 if (! targetm
.have_tablejump ())
11200 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11201 fold_convert (index_type
, index_expr
),
11202 fold_convert (index_type
, minval
));
11203 index
= expand_normal (index_expr
);
11204 do_pending_stack_adjust ();
11206 do_tablejump (index
, TYPE_MODE (index_type
),
11207 convert_modes (TYPE_MODE (index_type
),
11208 TYPE_MODE (TREE_TYPE (range
)),
11209 expand_normal (range
),
11210 TYPE_UNSIGNED (TREE_TYPE (range
))),
11211 table_label
, default_label
, default_probability
);
11215 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11217 const_vector_from_tree (tree exp
)
11223 machine_mode inner
, mode
;
11225 mode
= TYPE_MODE (TREE_TYPE (exp
));
11227 if (initializer_zerop (exp
))
11228 return CONST0_RTX (mode
);
11230 units
= GET_MODE_NUNITS (mode
);
11231 inner
= GET_MODE_INNER (mode
);
11233 v
= rtvec_alloc (units
);
11235 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11237 elt
= VECTOR_CST_ELT (exp
, i
);
11239 if (TREE_CODE (elt
) == REAL_CST
)
11240 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11242 else if (TREE_CODE (elt
) == FIXED_CST
)
11243 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11246 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11249 return gen_rtx_CONST_VECTOR (mode
, v
);
11252 /* Build a decl for a personality function given a language prefix. */
11255 build_personality_function (const char *lang
)
11257 const char *unwind_and_version
;
11261 switch (targetm_common
.except_unwind_info (&global_options
))
11266 unwind_and_version
= "_sj0";
11270 unwind_and_version
= "_v0";
11273 unwind_and_version
= "_seh0";
11276 gcc_unreachable ();
11279 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11281 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11282 long_long_unsigned_type_node
,
11283 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11284 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11285 get_identifier (name
), type
);
11286 DECL_ARTIFICIAL (decl
) = 1;
11287 DECL_EXTERNAL (decl
) = 1;
11288 TREE_PUBLIC (decl
) = 1;
11290 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11291 are the flags assigned by targetm.encode_section_info. */
11292 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11297 /* Extracts the personality function of DECL and returns the corresponding
11301 get_personality_function (tree decl
)
11303 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11304 enum eh_personality_kind pk
;
11306 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11307 if (pk
== eh_personality_none
)
11311 && pk
== eh_personality_any
)
11312 personality
= lang_hooks
.eh_personality ();
11314 if (pk
== eh_personality_lang
)
11315 gcc_assert (personality
!= NULL_TREE
);
11317 return XEXP (DECL_RTL (personality
), 0);
11320 /* Returns a tree for the size of EXP in bytes. */
11323 tree_expr_size (const_tree exp
)
11326 && DECL_SIZE_UNIT (exp
) != 0)
11327 return DECL_SIZE_UNIT (exp
);
11329 return size_in_bytes (TREE_TYPE (exp
));
11332 /* Return an rtx for the size in bytes of the value of EXP. */
11335 expr_size (tree exp
)
11339 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11340 size
= TREE_OPERAND (exp
, 1);
11343 size
= tree_expr_size (exp
);
11345 gcc_assert (size
== SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, exp
));
11348 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), EXPAND_NORMAL
);
11351 /* Return a wide integer for the size in bytes of the value of EXP, or -1
11352 if the size can vary or is larger than an integer. */
11354 static HOST_WIDE_INT
11355 int_expr_size (tree exp
)
11359 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11360 size
= TREE_OPERAND (exp
, 1);
11363 size
= tree_expr_size (exp
);
11367 if (size
== 0 || !tree_fits_shwi_p (size
))
11370 return tree_to_shwi (size
);
11373 #include "gt-expr.h"