1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
31 #include "fold-const.h"
32 #include "stor-layout.h"
38 #include "insn-config.h"
39 #include "insn-attr.h"
46 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
48 #include "insn-codes.h"
49 #include "optabs-tree.h"
54 #include "typeclass.h"
56 #include "langhooks.h"
59 #include "tree-iterator.h"
60 #include "internal-fn.h"
63 #include "common/common-target.h"
65 #include "diagnostic.h"
66 #include "tree-ssa-live.h"
67 #include "tree-outof-ssa.h"
68 #include "target-globals.h"
70 #include "tree-ssa-address.h"
71 #include "cfgexpand.h"
73 #include "tree-chkp.h"
78 /* If this is nonzero, we do not bother generating VOLATILE
79 around volatile memory references, and we are willing to
80 output indirect addresses. If cse is to follow, we reject
81 indirect addresses so a useful potential cse is generated;
82 if it is used only once, instruction combination will produce
83 the same indirect address eventually. */
86 /* This structure is used by move_by_pieces to describe the move to
88 struct move_by_pieces_d
97 int explicit_inc_from
;
98 unsigned HOST_WIDE_INT len
;
103 /* This structure is used by store_by_pieces to describe the clear to
106 struct store_by_pieces_d
112 unsigned HOST_WIDE_INT len
;
113 HOST_WIDE_INT offset
;
114 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
);
119 static void move_by_pieces_1 (insn_gen_fn
, machine_mode
,
120 struct move_by_pieces_d
*);
121 static bool block_move_libcall_safe_for_call_parm (void);
122 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
123 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
124 unsigned HOST_WIDE_INT
);
125 static tree
emit_block_move_libcall_fn (int);
126 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
127 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, machine_mode
);
128 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
129 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
130 static void store_by_pieces_2 (insn_gen_fn
, machine_mode
,
131 struct store_by_pieces_d
*);
132 static tree
clear_storage_libcall_fn (int);
133 static rtx_insn
*compress_float_constant (rtx
, rtx
);
134 static rtx
get_subtarget (rtx
);
135 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
136 HOST_WIDE_INT
, machine_mode
,
137 tree
, int, alias_set_type
);
138 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
139 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
140 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
141 machine_mode
, tree
, alias_set_type
, bool);
143 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
145 static int is_aligning_offset (const_tree
, const_tree
);
146 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
147 static rtx
do_store_flag (sepops
, rtx
, machine_mode
);
149 static void emit_single_push_insn (machine_mode
, rtx
, tree
);
151 static void do_tablejump (rtx
, machine_mode
, rtx
, rtx
, rtx
, int);
152 static rtx
const_vector_from_tree (tree
);
153 static tree
tree_expr_size (const_tree
);
154 static HOST_WIDE_INT
int_expr_size (tree
);
157 /* This is run to set up which modes can be used
158 directly in memory and to initialize the block move optab. It is run
159 at the beginning of compilation and when the target is reinitialized. */
162 init_expr_target (void)
170 /* Try indexing by frame ptr and try by stack ptr.
171 It is known that on the Convex the stack ptr isn't a valid index.
172 With luck, one or the other is valid on any machine. */
173 mem
= gen_rtx_MEM (word_mode
, stack_pointer_rtx
);
174 mem1
= gen_rtx_MEM (word_mode
, frame_pointer_rtx
);
176 /* A scratch register we can modify in-place below to avoid
177 useless RTL allocations. */
178 reg
= gen_rtx_REG (word_mode
, LAST_VIRTUAL_REGISTER
+ 1);
180 insn
= rtx_alloc (INSN
);
181 pat
= gen_rtx_SET (NULL_RTX
, NULL_RTX
);
182 PATTERN (insn
) = pat
;
184 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
185 mode
= (machine_mode
) ((int) mode
+ 1))
189 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
190 PUT_MODE (mem
, mode
);
191 PUT_MODE (mem1
, mode
);
193 /* See if there is some register that can be used in this mode and
194 directly loaded or stored from memory. */
196 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
197 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
198 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
201 if (! HARD_REGNO_MODE_OK (regno
, mode
))
204 set_mode_and_regno (reg
, mode
, regno
);
207 SET_DEST (pat
) = reg
;
208 if (recog (pat
, insn
, &num_clobbers
) >= 0)
209 direct_load
[(int) mode
] = 1;
211 SET_SRC (pat
) = mem1
;
212 SET_DEST (pat
) = reg
;
213 if (recog (pat
, insn
, &num_clobbers
) >= 0)
214 direct_load
[(int) mode
] = 1;
217 SET_DEST (pat
) = mem
;
218 if (recog (pat
, insn
, &num_clobbers
) >= 0)
219 direct_store
[(int) mode
] = 1;
222 SET_DEST (pat
) = mem1
;
223 if (recog (pat
, insn
, &num_clobbers
) >= 0)
224 direct_store
[(int) mode
] = 1;
228 mem
= gen_rtx_MEM (VOIDmode
, gen_raw_REG (Pmode
, LAST_VIRTUAL_REGISTER
+ 1));
230 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
231 mode
= GET_MODE_WIDER_MODE (mode
))
233 machine_mode srcmode
;
234 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
235 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
239 ic
= can_extend_p (mode
, srcmode
, 0);
240 if (ic
== CODE_FOR_nothing
)
243 PUT_MODE (mem
, srcmode
);
245 if (insn_operand_matches (ic
, 1, mem
))
246 float_extend_from_mem
[mode
][srcmode
] = true;
251 /* This is run at the start of compiling a function. */
256 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
259 /* Copy data from FROM to TO, where the machine modes are not the same.
260 Both modes may be integer, or both may be floating, or both may be
262 UNSIGNEDP should be nonzero if FROM is an unsigned type.
263 This causes zero-extension instead of sign-extension. */
266 convert_move (rtx to
, rtx from
, int unsignedp
)
268 machine_mode to_mode
= GET_MODE (to
);
269 machine_mode from_mode
= GET_MODE (from
);
270 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
271 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
275 /* rtx code for making an equivalent value. */
276 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
277 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
280 gcc_assert (to_real
== from_real
);
281 gcc_assert (to_mode
!= BLKmode
);
282 gcc_assert (from_mode
!= BLKmode
);
284 /* If the source and destination are already the same, then there's
289 /* If FROM is a SUBREG that indicates that we have already done at least
290 the required extension, strip it. We don't handle such SUBREGs as
293 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
294 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
295 >= GET_MODE_PRECISION (to_mode
))
296 && SUBREG_CHECK_PROMOTED_SIGN (from
, unsignedp
))
297 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
299 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
301 if (to_mode
== from_mode
302 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
304 emit_move_insn (to
, from
);
308 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
310 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
312 if (VECTOR_MODE_P (to_mode
))
313 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
315 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
317 emit_move_insn (to
, from
);
321 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
323 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
324 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
334 gcc_assert ((GET_MODE_PRECISION (from_mode
)
335 != GET_MODE_PRECISION (to_mode
))
336 || (DECIMAL_FLOAT_MODE_P (from_mode
)
337 != DECIMAL_FLOAT_MODE_P (to_mode
)));
339 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
340 /* Conversion between decimal float and binary float, same size. */
341 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
342 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
347 /* Try converting directly if the insn is supported. */
349 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
350 if (code
!= CODE_FOR_nothing
)
352 emit_unop_insn (code
, to
, from
,
353 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
357 /* Otherwise use a libcall. */
358 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
360 /* Is this conversion implemented yet? */
361 gcc_assert (libcall
);
364 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
366 insns
= get_insns ();
368 emit_libcall_block (insns
, to
, value
,
369 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
371 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
375 /* Handle pointer conversion. */ /* SPEE 900220. */
376 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
380 if (GET_MODE_PRECISION (from_mode
) > GET_MODE_PRECISION (to_mode
))
387 if (convert_optab_handler (ctab
, to_mode
, from_mode
)
390 emit_unop_insn (convert_optab_handler (ctab
, to_mode
, from_mode
),
396 /* Targets are expected to provide conversion insns between PxImode and
397 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
398 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
400 machine_mode full_mode
401 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
403 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
404 != CODE_FOR_nothing
);
406 if (full_mode
!= from_mode
)
407 from
= convert_to_mode (full_mode
, from
, unsignedp
);
408 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
412 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
415 machine_mode full_mode
416 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
417 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
418 enum insn_code icode
;
420 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
421 gcc_assert (icode
!= CODE_FOR_nothing
);
423 if (to_mode
== full_mode
)
425 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
429 new_from
= gen_reg_rtx (full_mode
);
430 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
432 /* else proceed to integer conversions below. */
433 from_mode
= full_mode
;
437 /* Make sure both are fixed-point modes or both are not. */
438 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
439 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
440 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
442 /* If we widen from_mode to to_mode and they are in the same class,
443 we won't saturate the result.
444 Otherwise, always saturate the result to play safe. */
445 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
446 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
447 expand_fixed_convert (to
, from
, 0, 0);
449 expand_fixed_convert (to
, from
, 0, 1);
453 /* Now both modes are integers. */
455 /* Handle expanding beyond a word. */
456 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
457 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
464 machine_mode lowpart_mode
;
465 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
467 /* Try converting directly if the insn is supported. */
468 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
471 /* If FROM is a SUBREG, put it into a register. Do this
472 so that we always generate the same set of insns for
473 better cse'ing; if an intermediate assignment occurred,
474 we won't be doing the operation directly on the SUBREG. */
475 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
476 from
= force_reg (from_mode
, from
);
477 emit_unop_insn (code
, to
, from
, equiv_code
);
480 /* Next, try converting via full word. */
481 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
482 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
483 != CODE_FOR_nothing
))
485 rtx word_to
= gen_reg_rtx (word_mode
);
488 if (reg_overlap_mentioned_p (to
, from
))
489 from
= force_reg (from_mode
, from
);
492 convert_move (word_to
, from
, unsignedp
);
493 emit_unop_insn (code
, to
, word_to
, equiv_code
);
497 /* No special multiword conversion insn; do it by hand. */
500 /* Since we will turn this into a no conflict block, we must ensure the
501 the source does not overlap the target so force it into an isolated
502 register when maybe so. Likewise for any MEM input, since the
503 conversion sequence might require several references to it and we
504 must ensure we're getting the same value every time. */
506 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
507 from
= force_reg (from_mode
, from
);
509 /* Get a copy of FROM widened to a word, if necessary. */
510 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
511 lowpart_mode
= word_mode
;
513 lowpart_mode
= from_mode
;
515 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
517 lowpart
= gen_lowpart (lowpart_mode
, to
);
518 emit_move_insn (lowpart
, lowfrom
);
520 /* Compute the value to put in each remaining word. */
522 fill_value
= const0_rtx
;
524 fill_value
= emit_store_flag_force (gen_reg_rtx (word_mode
),
525 LT
, lowfrom
, const0_rtx
,
526 lowpart_mode
, 0, -1);
528 /* Fill the remaining words. */
529 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
531 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
532 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
534 gcc_assert (subword
);
536 if (fill_value
!= subword
)
537 emit_move_insn (subword
, fill_value
);
540 insns
= get_insns ();
547 /* Truncating multi-word to a word or less. */
548 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
549 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
552 && ! MEM_VOLATILE_P (from
)
553 && direct_load
[(int) to_mode
]
554 && ! mode_dependent_address_p (XEXP (from
, 0),
555 MEM_ADDR_SPACE (from
)))
557 || GET_CODE (from
) == SUBREG
))
558 from
= force_reg (from_mode
, from
);
559 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
563 /* Now follow all the conversions between integers
564 no more than a word long. */
566 /* For truncation, usually we can just refer to FROM in a narrower mode. */
567 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
568 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
571 && ! MEM_VOLATILE_P (from
)
572 && direct_load
[(int) to_mode
]
573 && ! mode_dependent_address_p (XEXP (from
, 0),
574 MEM_ADDR_SPACE (from
)))
576 || GET_CODE (from
) == SUBREG
))
577 from
= force_reg (from_mode
, from
);
578 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
579 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
580 from
= copy_to_reg (from
);
581 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
585 /* Handle extension. */
586 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
588 /* Convert directly if that works. */
589 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
592 emit_unop_insn (code
, to
, from
, equiv_code
);
597 machine_mode intermediate
;
601 /* Search for a mode to convert via. */
602 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
603 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
604 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
606 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
607 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
608 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
609 != CODE_FOR_nothing
))
611 convert_move (to
, convert_to_mode (intermediate
, from
,
612 unsignedp
), unsignedp
);
616 /* No suitable intermediate mode.
617 Generate what we need with shifts. */
618 shift_amount
= (GET_MODE_PRECISION (to_mode
)
619 - GET_MODE_PRECISION (from_mode
));
620 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
621 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
623 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
626 emit_move_insn (to
, tmp
);
631 /* Support special truncate insns for certain modes. */
632 if (convert_optab_handler (trunc_optab
, to_mode
,
633 from_mode
) != CODE_FOR_nothing
)
635 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
640 /* Handle truncation of volatile memrefs, and so on;
641 the things that couldn't be truncated directly,
642 and for which there was no special instruction.
644 ??? Code above formerly short-circuited this, for most integer
645 mode pairs, with a force_reg in from_mode followed by a recursive
646 call to this routine. Appears always to have been wrong. */
647 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
649 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
650 emit_move_insn (to
, temp
);
654 /* Mode combination is not recognized. */
658 /* Return an rtx for a value that would result
659 from converting X to mode MODE.
660 Both X and MODE may be floating, or both integer.
661 UNSIGNEDP is nonzero if X is an unsigned value.
662 This can be done by referring to a part of X in place
663 or by copying to a new temporary with conversion. */
666 convert_to_mode (machine_mode mode
, rtx x
, int unsignedp
)
668 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
671 /* Return an rtx for a value that would result
672 from converting X from mode OLDMODE to mode MODE.
673 Both modes may be floating, or both integer.
674 UNSIGNEDP is nonzero if X is an unsigned value.
676 This can be done by referring to a part of X in place
677 or by copying to a new temporary with conversion.
679 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
682 convert_modes (machine_mode mode
, machine_mode oldmode
, rtx x
, int unsignedp
)
686 /* If FROM is a SUBREG that indicates that we have already done at least
687 the required extension, strip it. */
689 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
690 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
691 && SUBREG_CHECK_PROMOTED_SIGN (x
, unsignedp
))
692 x
= gen_lowpart (mode
, SUBREG_REG (x
));
694 if (GET_MODE (x
) != VOIDmode
)
695 oldmode
= GET_MODE (x
);
700 if (CONST_SCALAR_INT_P (x
) && GET_MODE_CLASS (mode
) == MODE_INT
)
702 /* If the caller did not tell us the old mode, then there is not
703 much to do with respect to canonicalization. We have to
704 assume that all the bits are significant. */
705 if (GET_MODE_CLASS (oldmode
) != MODE_INT
)
706 oldmode
= MAX_MODE_INT
;
707 wide_int w
= wide_int::from (std::make_pair (x
, oldmode
),
708 GET_MODE_PRECISION (mode
),
709 unsignedp
? UNSIGNED
: SIGNED
);
710 return immed_wide_int_const (w
, mode
);
713 /* We can do this with a gen_lowpart if both desired and current modes
714 are integer, and this is either a constant integer, a register, or a
716 if (GET_MODE_CLASS (mode
) == MODE_INT
717 && GET_MODE_CLASS (oldmode
) == MODE_INT
718 && GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
719 && ((MEM_P (x
) && !MEM_VOLATILE_P (x
) && direct_load
[(int) mode
])
721 && (!HARD_REGISTER_P (x
)
722 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
723 && TRULY_NOOP_TRUNCATION_MODES_P (mode
, GET_MODE (x
)))))
725 return gen_lowpart (mode
, x
);
727 /* Converting from integer constant into mode is always equivalent to an
729 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
731 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
732 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
735 temp
= gen_reg_rtx (mode
);
736 convert_move (temp
, x
, unsignedp
);
740 /* Return the largest alignment we can use for doing a move (or store)
741 of MAX_PIECES. ALIGN is the largest alignment we could use. */
744 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
748 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
749 if (align
>= GET_MODE_ALIGNMENT (tmode
))
750 align
= GET_MODE_ALIGNMENT (tmode
);
753 machine_mode tmode
, xmode
;
755 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
757 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
758 if (GET_MODE_SIZE (tmode
) > max_pieces
759 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
762 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
768 /* Return the widest integer mode no wider than SIZE. If no such mode
769 can be found, return VOIDmode. */
772 widest_int_mode_for_size (unsigned int size
)
774 machine_mode tmode
, mode
= VOIDmode
;
776 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
777 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
778 if (GET_MODE_SIZE (tmode
) < size
)
784 /* Determine whether the LEN bytes can be moved by using several move
785 instructions. Return nonzero if a call to move_by_pieces should
789 can_move_by_pieces (unsigned HOST_WIDE_INT len
,
792 return targetm
.use_by_pieces_infrastructure_p (len
, align
, MOVE_BY_PIECES
,
793 optimize_insn_for_speed_p ());
796 /* Generate several move instructions to copy LEN bytes from block FROM to
797 block TO. (These are MEM rtx's with BLKmode).
799 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
800 used to push FROM to the stack.
802 ALIGN is maximum stack alignment we can assume.
804 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
805 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
809 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
810 unsigned int align
, int endp
)
812 struct move_by_pieces_d data
;
813 machine_mode to_addr_mode
;
814 machine_mode from_addr_mode
= get_address_mode (from
);
815 rtx to_addr
, from_addr
= XEXP (from
, 0);
816 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
817 enum insn_code icode
;
819 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
822 data
.from_addr
= from_addr
;
825 to_addr_mode
= get_address_mode (to
);
826 to_addr
= XEXP (to
, 0);
829 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
830 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
832 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
836 to_addr_mode
= VOIDmode
;
840 if (STACK_GROWS_DOWNWARD
)
845 data
.to_addr
= to_addr
;
848 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
849 || GET_CODE (from_addr
) == POST_INC
850 || GET_CODE (from_addr
) == POST_DEC
);
852 data
.explicit_inc_from
= 0;
853 data
.explicit_inc_to
= 0;
854 if (data
.reverse
) data
.offset
= len
;
857 /* If copying requires more than two move insns,
858 copy addresses to registers (to make displacements shorter)
859 and use post-increment if available. */
860 if (!(data
.autinc_from
&& data
.autinc_to
)
861 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
863 /* Find the mode of the largest move...
864 MODE might not be used depending on the definitions of the
865 USE_* macros below. */
866 machine_mode mode ATTRIBUTE_UNUSED
867 = widest_int_mode_for_size (max_size
);
869 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
871 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
872 plus_constant (from_addr_mode
,
874 data
.autinc_from
= 1;
875 data
.explicit_inc_from
= -1;
877 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
879 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
880 data
.autinc_from
= 1;
881 data
.explicit_inc_from
= 1;
883 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
884 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
885 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
887 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
888 plus_constant (to_addr_mode
,
891 data
.explicit_inc_to
= -1;
893 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
895 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
897 data
.explicit_inc_to
= 1;
899 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
900 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
903 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
905 /* First move what we can in the largest integer mode, then go to
906 successively smaller modes. */
908 while (max_size
> 1 && data
.len
> 0)
910 machine_mode mode
= widest_int_mode_for_size (max_size
);
912 if (mode
== VOIDmode
)
915 icode
= optab_handler (mov_optab
, mode
);
916 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
917 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
919 max_size
= GET_MODE_SIZE (mode
);
922 /* The code above should have handled everything. */
923 gcc_assert (!data
.len
);
929 gcc_assert (!data
.reverse
);
934 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
935 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
937 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
938 plus_constant (to_addr_mode
,
942 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
949 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
957 /* Return number of insns required to move L bytes by pieces.
958 ALIGN (in bits) is maximum alignment we can assume. */
960 unsigned HOST_WIDE_INT
961 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
962 unsigned int max_size
)
964 unsigned HOST_WIDE_INT n_insns
= 0;
966 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
968 while (max_size
> 1 && l
> 0)
971 enum insn_code icode
;
973 mode
= widest_int_mode_for_size (max_size
);
975 if (mode
== VOIDmode
)
978 icode
= optab_handler (mov_optab
, mode
);
979 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
980 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
982 max_size
= GET_MODE_SIZE (mode
);
989 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
990 with move instructions for mode MODE. GENFUN is the gen_... function
991 to make a move insn for that mode. DATA has all the other info. */
994 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
995 struct move_by_pieces_d
*data
)
997 unsigned int size
= GET_MODE_SIZE (mode
);
998 rtx to1
= NULL_RTX
, from1
;
1000 while (data
->len
>= size
)
1003 data
->offset
-= size
;
1007 if (data
->autinc_to
)
1008 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1011 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1014 if (data
->autinc_from
)
1015 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1018 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1020 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1021 emit_insn (gen_add2_insn (data
->to_addr
,
1022 gen_int_mode (-(HOST_WIDE_INT
) size
,
1023 GET_MODE (data
->to_addr
))));
1024 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1025 emit_insn (gen_add2_insn (data
->from_addr
,
1026 gen_int_mode (-(HOST_WIDE_INT
) size
,
1027 GET_MODE (data
->from_addr
))));
1030 emit_insn ((*genfun
) (to1
, from1
));
1033 #ifdef PUSH_ROUNDING
1034 emit_single_push_insn (mode
, from1
, NULL
);
1040 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1041 emit_insn (gen_add2_insn (data
->to_addr
,
1043 GET_MODE (data
->to_addr
))));
1044 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1045 emit_insn (gen_add2_insn (data
->from_addr
,
1047 GET_MODE (data
->from_addr
))));
1049 if (! data
->reverse
)
1050 data
->offset
+= size
;
1056 /* Emit code to move a block Y to a block X. This may be done with
1057 string-move instructions, with multiple scalar move instructions,
1058 or with a library call.
1060 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1061 SIZE is an rtx that says how long they are.
1062 ALIGN is the maximum alignment we can assume they have.
1063 METHOD describes what kind of copy this is, and what mechanisms may be used.
1064 MIN_SIZE is the minimal size of block to move
1065 MAX_SIZE is the maximal size of block to move, if it can not be represented
1066 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1068 Return the address of the new block, if memcpy is called and returns it,
1072 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1073 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1074 unsigned HOST_WIDE_INT min_size
,
1075 unsigned HOST_WIDE_INT max_size
,
1076 unsigned HOST_WIDE_INT probable_max_size
)
1083 if (CONST_INT_P (size
)
1084 && INTVAL (size
) == 0)
1089 case BLOCK_OP_NORMAL
:
1090 case BLOCK_OP_TAILCALL
:
1091 may_use_call
= true;
1094 case BLOCK_OP_CALL_PARM
:
1095 may_use_call
= block_move_libcall_safe_for_call_parm ();
1097 /* Make inhibit_defer_pop nonzero around the library call
1098 to force it to pop the arguments right away. */
1102 case BLOCK_OP_NO_LIBCALL
:
1103 may_use_call
= false;
1110 gcc_assert (MEM_P (x
) && MEM_P (y
));
1111 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1112 gcc_assert (align
>= BITS_PER_UNIT
);
1114 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1115 block copy is more efficient for other large modes, e.g. DCmode. */
1116 x
= adjust_address (x
, BLKmode
, 0);
1117 y
= adjust_address (y
, BLKmode
, 0);
1119 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1120 can be incorrect is coming from __builtin_memcpy. */
1121 if (CONST_INT_P (size
))
1123 x
= shallow_copy_rtx (x
);
1124 y
= shallow_copy_rtx (y
);
1125 set_mem_size (x
, INTVAL (size
));
1126 set_mem_size (y
, INTVAL (size
));
1129 if (CONST_INT_P (size
) && can_move_by_pieces (INTVAL (size
), align
))
1130 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1131 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1132 expected_align
, expected_size
,
1133 min_size
, max_size
, probable_max_size
))
1135 else if (may_use_call
1136 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1137 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1139 /* Since x and y are passed to a libcall, mark the corresponding
1140 tree EXPR as addressable. */
1141 tree y_expr
= MEM_EXPR (y
);
1142 tree x_expr
= MEM_EXPR (x
);
1144 mark_addressable (y_expr
);
1146 mark_addressable (x_expr
);
1147 retval
= emit_block_move_via_libcall (x
, y
, size
,
1148 method
== BLOCK_OP_TAILCALL
);
1152 emit_block_move_via_loop (x
, y
, size
, align
);
1154 if (method
== BLOCK_OP_CALL_PARM
)
1161 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1163 unsigned HOST_WIDE_INT max
, min
= 0;
1164 if (GET_CODE (size
) == CONST_INT
)
1165 min
= max
= UINTVAL (size
);
1167 max
= GET_MODE_MASK (GET_MODE (size
));
1168 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1172 /* A subroutine of emit_block_move. Returns true if calling the
1173 block move libcall will not clobber any parameters which may have
1174 already been placed on the stack. */
1177 block_move_libcall_safe_for_call_parm (void)
1179 #if defined (REG_PARM_STACK_SPACE)
1183 /* If arguments are pushed on the stack, then they're safe. */
1187 /* If registers go on the stack anyway, any argument is sure to clobber
1188 an outgoing argument. */
1189 #if defined (REG_PARM_STACK_SPACE)
1190 fn
= emit_block_move_libcall_fn (false);
1191 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1192 depend on its argument. */
1194 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1195 && REG_PARM_STACK_SPACE (fn
) != 0)
1199 /* If any argument goes in memory, then it might clobber an outgoing
1202 CUMULATIVE_ARGS args_so_far_v
;
1203 cumulative_args_t args_so_far
;
1206 fn
= emit_block_move_libcall_fn (false);
1207 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1208 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1210 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1211 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1213 machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1214 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1216 if (!tmp
|| !REG_P (tmp
))
1218 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1220 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1227 /* A subroutine of emit_block_move. Expand a movmem pattern;
1228 return true if successful. */
1231 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1232 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1233 unsigned HOST_WIDE_INT min_size
,
1234 unsigned HOST_WIDE_INT max_size
,
1235 unsigned HOST_WIDE_INT probable_max_size
)
1237 int save_volatile_ok
= volatile_ok
;
1240 if (expected_align
< align
)
1241 expected_align
= align
;
1242 if (expected_size
!= -1)
1244 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1245 expected_size
= probable_max_size
;
1246 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1247 expected_size
= min_size
;
1250 /* Since this is a move insn, we don't care about volatility. */
1253 /* Try the most limited insn first, because there's no point
1254 including more than one in the machine description unless
1255 the more limited one has some advantage. */
1257 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1258 mode
= GET_MODE_WIDER_MODE (mode
))
1260 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1262 if (code
!= CODE_FOR_nothing
1263 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1264 here because if SIZE is less than the mode mask, as it is
1265 returned by the macro, it will definitely be less than the
1266 actual mode mask. Since SIZE is within the Pmode address
1267 space, we limit MODE to Pmode. */
1268 && ((CONST_INT_P (size
)
1269 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1270 <= (GET_MODE_MASK (mode
) >> 1)))
1271 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1272 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1274 struct expand_operand ops
[9];
1277 /* ??? When called via emit_block_move_for_call, it'd be
1278 nice if there were some way to inform the backend, so
1279 that it doesn't fail the expansion because it thinks
1280 emitting the libcall would be more efficient. */
1281 nops
= insn_data
[(int) code
].n_generator_args
;
1282 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1284 create_fixed_operand (&ops
[0], x
);
1285 create_fixed_operand (&ops
[1], y
);
1286 /* The check above guarantees that this size conversion is valid. */
1287 create_convert_operand_to (&ops
[2], size
, mode
, true);
1288 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1291 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1292 create_integer_operand (&ops
[5], expected_size
);
1296 create_integer_operand (&ops
[6], min_size
);
1297 /* If we can not represent the maximal size,
1298 make parameter NULL. */
1299 if ((HOST_WIDE_INT
) max_size
!= -1)
1300 create_integer_operand (&ops
[7], max_size
);
1302 create_fixed_operand (&ops
[7], NULL
);
1306 /* If we can not represent the maximal size,
1307 make parameter NULL. */
1308 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1309 create_integer_operand (&ops
[8], probable_max_size
);
1311 create_fixed_operand (&ops
[8], NULL
);
1313 if (maybe_expand_insn (code
, nops
, ops
))
1315 volatile_ok
= save_volatile_ok
;
1321 volatile_ok
= save_volatile_ok
;
1325 /* A subroutine of emit_block_move. Expand a call to memcpy.
1326 Return the return value from memcpy, 0 otherwise. */
1329 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1331 rtx dst_addr
, src_addr
;
1332 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1333 machine_mode size_mode
;
1336 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1337 pseudos. We can then place those new pseudos into a VAR_DECL and
1340 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1341 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1343 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1344 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1346 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1347 src_tree
= make_tree (ptr_type_node
, src_addr
);
1349 size_mode
= TYPE_MODE (sizetype
);
1351 size
= convert_to_mode (size_mode
, size
, 1);
1352 size
= copy_to_mode_reg (size_mode
, size
);
1354 /* It is incorrect to use the libcall calling conventions to call
1355 memcpy in this context. This could be a user call to memcpy and
1356 the user may wish to examine the return value from memcpy. For
1357 targets where libcalls and normal calls have different conventions
1358 for returning pointers, we could end up generating incorrect code. */
1360 size_tree
= make_tree (sizetype
, size
);
1362 fn
= emit_block_move_libcall_fn (true);
1363 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1364 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1366 retval
= expand_normal (call_expr
);
1371 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1372 for the function we use for block copies. */
1374 static GTY(()) tree block_move_fn
;
1377 init_block_move_fn (const char *asmspec
)
1381 tree args
, fn
, attrs
, attr_args
;
1383 fn
= get_identifier ("memcpy");
1384 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1385 const_ptr_type_node
, sizetype
,
1388 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1389 DECL_EXTERNAL (fn
) = 1;
1390 TREE_PUBLIC (fn
) = 1;
1391 DECL_ARTIFICIAL (fn
) = 1;
1392 TREE_NOTHROW (fn
) = 1;
1393 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1394 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1396 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1397 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1399 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1405 set_user_assembler_name (block_move_fn
, asmspec
);
1409 emit_block_move_libcall_fn (int for_call
)
1411 static bool emitted_extern
;
1414 init_block_move_fn (NULL
);
1416 if (for_call
&& !emitted_extern
)
1418 emitted_extern
= true;
1419 make_decl_rtl (block_move_fn
);
1422 return block_move_fn
;
1425 /* A subroutine of emit_block_move. Copy the data via an explicit
1426 loop. This is used only when libcalls are forbidden. */
1427 /* ??? It'd be nice to copy in hunks larger than QImode. */
1430 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1431 unsigned int align ATTRIBUTE_UNUSED
)
1433 rtx_code_label
*cmp_label
, *top_label
;
1434 rtx iter
, x_addr
, y_addr
, tmp
;
1435 machine_mode x_addr_mode
= get_address_mode (x
);
1436 machine_mode y_addr_mode
= get_address_mode (y
);
1437 machine_mode iter_mode
;
1439 iter_mode
= GET_MODE (size
);
1440 if (iter_mode
== VOIDmode
)
1441 iter_mode
= word_mode
;
1443 top_label
= gen_label_rtx ();
1444 cmp_label
= gen_label_rtx ();
1445 iter
= gen_reg_rtx (iter_mode
);
1447 emit_move_insn (iter
, const0_rtx
);
1449 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1450 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1451 do_pending_stack_adjust ();
1453 emit_jump (cmp_label
);
1454 emit_label (top_label
);
1456 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1457 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1459 if (x_addr_mode
!= y_addr_mode
)
1460 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1461 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1463 x
= change_address (x
, QImode
, x_addr
);
1464 y
= change_address (y
, QImode
, y_addr
);
1466 emit_move_insn (x
, y
);
1468 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1469 true, OPTAB_LIB_WIDEN
);
1471 emit_move_insn (iter
, tmp
);
1473 emit_label (cmp_label
);
1475 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1476 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1479 /* Copy all or part of a value X into registers starting at REGNO.
1480 The number of registers to be filled is NREGS. */
1483 move_block_to_reg (int regno
, rtx x
, int nregs
, machine_mode mode
)
1488 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1489 x
= validize_mem (force_const_mem (mode
, x
));
1491 /* See if the machine can do this with a load multiple insn. */
1492 if (targetm
.have_load_multiple ())
1494 rtx_insn
*last
= get_last_insn ();
1495 rtx first
= gen_rtx_REG (word_mode
, regno
);
1496 if (rtx_insn
*pat
= targetm
.gen_load_multiple (first
, x
,
1503 delete_insns_since (last
);
1506 for (int i
= 0; i
< nregs
; i
++)
1507 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1508 operand_subword_force (x
, i
, mode
));
1511 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1512 The number of registers to be filled is NREGS. */
1515 move_block_from_reg (int regno
, rtx x
, int nregs
)
1520 /* See if the machine can do this with a store multiple insn. */
1521 if (targetm
.have_store_multiple ())
1523 rtx_insn
*last
= get_last_insn ();
1524 rtx first
= gen_rtx_REG (word_mode
, regno
);
1525 if (rtx_insn
*pat
= targetm
.gen_store_multiple (x
, first
,
1532 delete_insns_since (last
);
1535 for (int i
= 0; i
< nregs
; i
++)
1537 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1541 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1545 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1546 ORIG, where ORIG is a non-consecutive group of registers represented by
1547 a PARALLEL. The clone is identical to the original except in that the
1548 original set of registers is replaced by a new set of pseudo registers.
1549 The new set has the same modes as the original set. */
1552 gen_group_rtx (rtx orig
)
1557 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1559 length
= XVECLEN (orig
, 0);
1560 tmps
= XALLOCAVEC (rtx
, length
);
1562 /* Skip a NULL entry in first slot. */
1563 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1568 for (; i
< length
; i
++)
1570 machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1571 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1573 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1576 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1579 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1580 except that values are placed in TMPS[i], and must later be moved
1581 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1584 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1588 machine_mode m
= GET_MODE (orig_src
);
1590 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1593 && !SCALAR_INT_MODE_P (m
)
1594 && !MEM_P (orig_src
)
1595 && GET_CODE (orig_src
) != CONCAT
)
1597 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1598 if (imode
== BLKmode
)
1599 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1601 src
= gen_reg_rtx (imode
);
1602 if (imode
!= BLKmode
)
1603 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1604 emit_move_insn (src
, orig_src
);
1605 /* ...and back again. */
1606 if (imode
!= BLKmode
)
1607 src
= gen_lowpart (imode
, src
);
1608 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1612 /* Check for a NULL entry, used to indicate that the parameter goes
1613 both on the stack and in registers. */
1614 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1619 /* Process the pieces. */
1620 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1622 machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1623 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1624 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1627 /* Handle trailing fragments that run over the size of the struct. */
1628 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1630 /* Arrange to shift the fragment to where it belongs.
1631 extract_bit_field loads to the lsb of the reg. */
1633 #ifdef BLOCK_REG_PADDING
1634 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1635 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1640 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1641 bytelen
= ssize
- bytepos
;
1642 gcc_assert (bytelen
> 0);
1645 /* If we won't be loading directly from memory, protect the real source
1646 from strange tricks we might play; but make sure that the source can
1647 be loaded directly into the destination. */
1649 if (!MEM_P (orig_src
)
1650 && (!CONSTANT_P (orig_src
)
1651 || (GET_MODE (orig_src
) != mode
1652 && GET_MODE (orig_src
) != VOIDmode
)))
1654 if (GET_MODE (orig_src
) == VOIDmode
)
1655 src
= gen_reg_rtx (mode
);
1657 src
= gen_reg_rtx (GET_MODE (orig_src
));
1659 emit_move_insn (src
, orig_src
);
1662 /* Optimize the access just a bit. */
1664 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1665 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1666 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1667 && bytelen
== GET_MODE_SIZE (mode
))
1669 tmps
[i
] = gen_reg_rtx (mode
);
1670 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1672 else if (COMPLEX_MODE_P (mode
)
1673 && GET_MODE (src
) == mode
1674 && bytelen
== GET_MODE_SIZE (mode
))
1675 /* Let emit_move_complex do the bulk of the work. */
1677 else if (GET_CODE (src
) == CONCAT
)
1679 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1680 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1682 if ((bytepos
== 0 && bytelen
== slen0
)
1683 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1685 /* The following assumes that the concatenated objects all
1686 have the same size. In this case, a simple calculation
1687 can be used to determine the object and the bit field
1689 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1690 if (! CONSTANT_P (tmps
[i
])
1691 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1692 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1693 (bytepos
% slen0
) * BITS_PER_UNIT
,
1694 1, NULL_RTX
, mode
, mode
);
1700 gcc_assert (!bytepos
);
1701 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1702 emit_move_insn (mem
, src
);
1703 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1704 0, 1, NULL_RTX
, mode
, mode
);
1707 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1708 SIMD register, which is currently broken. While we get GCC
1709 to emit proper RTL for these cases, let's dump to memory. */
1710 else if (VECTOR_MODE_P (GET_MODE (dst
))
1713 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1716 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1717 emit_move_insn (mem
, src
);
1718 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1720 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1721 && XVECLEN (dst
, 0) > 1)
1722 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1723 else if (CONSTANT_P (src
))
1725 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1733 /* TODO: const_wide_int can have sizes other than this... */
1734 gcc_assert (2 * len
== ssize
);
1735 split_double (src
, &first
, &second
);
1742 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1745 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1746 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1750 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1755 /* Emit code to move a block SRC of type TYPE to a block DST,
1756 where DST is non-consecutive registers represented by a PARALLEL.
1757 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1761 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1766 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1767 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1769 /* Copy the extracted pieces into the proper (probable) hard regs. */
1770 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1772 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1775 emit_move_insn (d
, tmps
[i
]);
1779 /* Similar, but load SRC into new pseudos in a format that looks like
1780 PARALLEL. This can later be fed to emit_group_move to get things
1781 in the right place. */
1784 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1789 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1790 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1792 /* Convert the vector to look just like the original PARALLEL, except
1793 with the computed values. */
1794 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1796 rtx e
= XVECEXP (parallel
, 0, i
);
1797 rtx d
= XEXP (e
, 0);
1801 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1802 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1804 RTVEC_ELT (vec
, i
) = e
;
1807 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1810 /* Emit code to move a block SRC to block DST, where SRC and DST are
1811 non-consecutive groups of registers, each represented by a PARALLEL. */
1814 emit_group_move (rtx dst
, rtx src
)
1818 gcc_assert (GET_CODE (src
) == PARALLEL
1819 && GET_CODE (dst
) == PARALLEL
1820 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1822 /* Skip first entry if NULL. */
1823 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1824 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1825 XEXP (XVECEXP (src
, 0, i
), 0));
1828 /* Move a group of registers represented by a PARALLEL into pseudos. */
1831 emit_group_move_into_temps (rtx src
)
1833 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1836 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1838 rtx e
= XVECEXP (src
, 0, i
);
1839 rtx d
= XEXP (e
, 0);
1842 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1843 RTVEC_ELT (vec
, i
) = e
;
1846 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1849 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1850 where SRC is non-consecutive registers represented by a PARALLEL.
1851 SSIZE represents the total size of block ORIG_DST, or -1 if not
1855 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1858 int start
, finish
, i
;
1859 machine_mode m
= GET_MODE (orig_dst
);
1861 gcc_assert (GET_CODE (src
) == PARALLEL
);
1863 if (!SCALAR_INT_MODE_P (m
)
1864 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1866 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1867 if (imode
== BLKmode
)
1868 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1870 dst
= gen_reg_rtx (imode
);
1871 emit_group_store (dst
, src
, type
, ssize
);
1872 if (imode
!= BLKmode
)
1873 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1874 emit_move_insn (orig_dst
, dst
);
1878 /* Check for a NULL entry, used to indicate that the parameter goes
1879 both on the stack and in registers. */
1880 if (XEXP (XVECEXP (src
, 0, 0), 0))
1884 finish
= XVECLEN (src
, 0);
1886 tmps
= XALLOCAVEC (rtx
, finish
);
1888 /* Copy the (probable) hard regs into pseudos. */
1889 for (i
= start
; i
< finish
; i
++)
1891 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1892 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1894 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1895 emit_move_insn (tmps
[i
], reg
);
1901 /* If we won't be storing directly into memory, protect the real destination
1902 from strange tricks we might play. */
1904 if (GET_CODE (dst
) == PARALLEL
)
1908 /* We can get a PARALLEL dst if there is a conditional expression in
1909 a return statement. In that case, the dst and src are the same,
1910 so no action is necessary. */
1911 if (rtx_equal_p (dst
, src
))
1914 /* It is unclear if we can ever reach here, but we may as well handle
1915 it. Allocate a temporary, and split this into a store/load to/from
1917 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1918 emit_group_store (temp
, src
, type
, ssize
);
1919 emit_group_load (dst
, temp
, type
, ssize
);
1922 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1924 machine_mode outer
= GET_MODE (dst
);
1926 HOST_WIDE_INT bytepos
;
1930 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1931 dst
= gen_reg_rtx (outer
);
1933 /* Make life a bit easier for combine. */
1934 /* If the first element of the vector is the low part
1935 of the destination mode, use a paradoxical subreg to
1936 initialize the destination. */
1939 inner
= GET_MODE (tmps
[start
]);
1940 bytepos
= subreg_lowpart_offset (inner
, outer
);
1941 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1943 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1947 emit_move_insn (dst
, temp
);
1954 /* If the first element wasn't the low part, try the last. */
1956 && start
< finish
- 1)
1958 inner
= GET_MODE (tmps
[finish
- 1]);
1959 bytepos
= subreg_lowpart_offset (inner
, outer
);
1960 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1962 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1966 emit_move_insn (dst
, temp
);
1973 /* Otherwise, simply initialize the result to zero. */
1975 emit_move_insn (dst
, CONST0_RTX (outer
));
1978 /* Process the pieces. */
1979 for (i
= start
; i
< finish
; i
++)
1981 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
1982 machine_mode mode
= GET_MODE (tmps
[i
]);
1983 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1984 unsigned int adj_bytelen
;
1987 /* Handle trailing fragments that run over the size of the struct. */
1988 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1989 adj_bytelen
= ssize
- bytepos
;
1991 adj_bytelen
= bytelen
;
1993 if (GET_CODE (dst
) == CONCAT
)
1995 if (bytepos
+ adj_bytelen
1996 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
1997 dest
= XEXP (dst
, 0);
1998 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2000 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2001 dest
= XEXP (dst
, 1);
2005 machine_mode dest_mode
= GET_MODE (dest
);
2006 machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2008 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2010 if (GET_MODE_ALIGNMENT (dest_mode
)
2011 >= GET_MODE_ALIGNMENT (tmp_mode
))
2013 dest
= assign_stack_temp (dest_mode
,
2014 GET_MODE_SIZE (dest_mode
));
2015 emit_move_insn (adjust_address (dest
,
2023 dest
= assign_stack_temp (tmp_mode
,
2024 GET_MODE_SIZE (tmp_mode
));
2025 emit_move_insn (dest
, tmps
[i
]);
2026 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2032 /* Handle trailing fragments that run over the size of the struct. */
2033 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2035 /* store_bit_field always takes its value from the lsb.
2036 Move the fragment to the lsb if it's not already there. */
2038 #ifdef BLOCK_REG_PADDING
2039 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2040 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2046 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2047 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2051 /* Make sure not to write past the end of the struct. */
2052 store_bit_field (dest
,
2053 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2054 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
- 1,
2058 /* Optimize the access just a bit. */
2059 else if (MEM_P (dest
)
2060 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2061 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2062 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2063 && bytelen
== GET_MODE_SIZE (mode
))
2064 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2067 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2068 0, 0, mode
, tmps
[i
]);
2071 /* Copy from the pseudo into the (probable) hard reg. */
2072 if (orig_dst
!= dst
)
2073 emit_move_insn (orig_dst
, dst
);
2076 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2077 of the value stored in X. */
2080 maybe_emit_group_store (rtx x
, tree type
)
2082 machine_mode mode
= TYPE_MODE (type
);
2083 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2084 if (GET_CODE (x
) == PARALLEL
)
2086 rtx result
= gen_reg_rtx (mode
);
2087 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2093 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2095 This is used on targets that return BLKmode values in registers. */
2098 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2100 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2101 rtx src
= NULL
, dst
= NULL
;
2102 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2103 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2104 machine_mode mode
= GET_MODE (srcreg
);
2105 machine_mode tmode
= GET_MODE (target
);
2106 machine_mode copy_mode
;
2108 /* BLKmode registers created in the back-end shouldn't have survived. */
2109 gcc_assert (mode
!= BLKmode
);
2111 /* If the structure doesn't take up a whole number of words, see whether
2112 SRCREG is padded on the left or on the right. If it's on the left,
2113 set PADDING_CORRECTION to the number of bits to skip.
2115 In most ABIs, the structure will be returned at the least end of
2116 the register, which translates to right padding on little-endian
2117 targets and left padding on big-endian targets. The opposite
2118 holds if the structure is returned at the most significant
2119 end of the register. */
2120 if (bytes
% UNITS_PER_WORD
!= 0
2121 && (targetm
.calls
.return_in_msb (type
)
2123 : BYTES_BIG_ENDIAN
))
2125 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2127 /* We can use a single move if we have an exact mode for the size. */
2128 else if (MEM_P (target
)
2129 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2130 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2131 && bytes
== GET_MODE_SIZE (mode
))
2133 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2137 /* And if we additionally have the same mode for a register. */
2138 else if (REG_P (target
)
2139 && GET_MODE (target
) == mode
2140 && bytes
== GET_MODE_SIZE (mode
))
2142 emit_move_insn (target
, srcreg
);
2146 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2147 into a new pseudo which is a full word. */
2148 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2150 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2154 /* Copy the structure BITSIZE bits at a time. If the target lives in
2155 memory, take care of not reading/writing past its end by selecting
2156 a copy mode suited to BITSIZE. This should always be possible given
2159 If the target lives in register, make sure not to select a copy mode
2160 larger than the mode of the register.
2162 We could probably emit more efficient code for machines which do not use
2163 strict alignment, but it doesn't seem worth the effort at the current
2166 copy_mode
= word_mode
;
2169 machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2170 if (mem_mode
!= BLKmode
)
2171 copy_mode
= mem_mode
;
2173 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2176 for (bitpos
= 0, xbitpos
= padding_correction
;
2177 bitpos
< bytes
* BITS_PER_UNIT
;
2178 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2180 /* We need a new source operand each time xbitpos is on a
2181 word boundary and when xbitpos == padding_correction
2182 (the first time through). */
2183 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2184 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2186 /* We need a new destination operand each time bitpos is on
2188 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2190 else if (bitpos
% BITS_PER_WORD
== 0)
2191 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2193 /* Use xbitpos for the source extraction (right justified) and
2194 bitpos for the destination store (left justified). */
2195 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2196 extract_bit_field (src
, bitsize
,
2197 xbitpos
% BITS_PER_WORD
, 1,
2198 NULL_RTX
, copy_mode
, copy_mode
));
2202 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2203 register if it contains any data, otherwise return null.
2205 This is used on targets that return BLKmode values in registers. */
2208 copy_blkmode_to_reg (machine_mode mode
, tree src
)
2211 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2212 unsigned int bitsize
;
2213 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2214 machine_mode dst_mode
;
2216 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2218 x
= expand_normal (src
);
2220 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2224 /* If the structure doesn't take up a whole number of words, see
2225 whether the register value should be padded on the left or on
2226 the right. Set PADDING_CORRECTION to the number of padding
2227 bits needed on the left side.
2229 In most ABIs, the structure will be returned at the least end of
2230 the register, which translates to right padding on little-endian
2231 targets and left padding on big-endian targets. The opposite
2232 holds if the structure is returned at the most significant
2233 end of the register. */
2234 if (bytes
% UNITS_PER_WORD
!= 0
2235 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2237 : BYTES_BIG_ENDIAN
))
2238 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2241 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2242 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2243 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2245 /* Copy the structure BITSIZE bits at a time. */
2246 for (bitpos
= 0, xbitpos
= padding_correction
;
2247 bitpos
< bytes
* BITS_PER_UNIT
;
2248 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2250 /* We need a new destination pseudo each time xbitpos is
2251 on a word boundary and when xbitpos == padding_correction
2252 (the first time through). */
2253 if (xbitpos
% BITS_PER_WORD
== 0
2254 || xbitpos
== padding_correction
)
2256 /* Generate an appropriate register. */
2257 dst_word
= gen_reg_rtx (word_mode
);
2258 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2260 /* Clear the destination before we move anything into it. */
2261 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2264 /* We need a new source operand each time bitpos is on a word
2266 if (bitpos
% BITS_PER_WORD
== 0)
2267 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2269 /* Use bitpos for the source extraction (left justified) and
2270 xbitpos for the destination store (right justified). */
2271 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2273 extract_bit_field (src_word
, bitsize
,
2274 bitpos
% BITS_PER_WORD
, 1,
2275 NULL_RTX
, word_mode
, word_mode
));
2278 if (mode
== BLKmode
)
2280 /* Find the smallest integer mode large enough to hold the
2281 entire structure. */
2282 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2284 mode
= GET_MODE_WIDER_MODE (mode
))
2285 /* Have we found a large enough mode? */
2286 if (GET_MODE_SIZE (mode
) >= bytes
)
2289 /* A suitable mode should have been found. */
2290 gcc_assert (mode
!= VOIDmode
);
2293 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2294 dst_mode
= word_mode
;
2297 dst
= gen_reg_rtx (dst_mode
);
2299 for (i
= 0; i
< n_regs
; i
++)
2300 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2302 if (mode
!= dst_mode
)
2303 dst
= gen_lowpart (mode
, dst
);
2308 /* Add a USE expression for REG to the (possibly empty) list pointed
2309 to by CALL_FUSAGE. REG must denote a hard register. */
2312 use_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2314 gcc_assert (REG_P (reg
));
2316 if (!HARD_REGISTER_P (reg
))
2320 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2323 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
2324 to by CALL_FUSAGE. REG must denote a hard register. */
2327 clobber_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2329 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2332 = gen_rtx_EXPR_LIST (mode
, gen_rtx_CLOBBER (VOIDmode
, reg
), *call_fusage
);
2335 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2336 starting at REGNO. All of these registers must be hard registers. */
2339 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2343 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2345 for (i
= 0; i
< nregs
; i
++)
2346 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2349 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2350 PARALLEL REGS. This is for calls that pass values in multiple
2351 non-contiguous locations. The Irix 6 ABI has examples of this. */
2354 use_group_regs (rtx
*call_fusage
, rtx regs
)
2358 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2360 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2362 /* A NULL entry means the parameter goes both on the stack and in
2363 registers. This can also be a MEM for targets that pass values
2364 partially on the stack and partially in registers. */
2365 if (reg
!= 0 && REG_P (reg
))
2366 use_reg (call_fusage
, reg
);
2370 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2371 assigment and the code of the expresion on the RHS is CODE. Return
2375 get_def_for_expr (tree name
, enum tree_code code
)
2379 if (TREE_CODE (name
) != SSA_NAME
)
2382 def_stmt
= get_gimple_for_ssa_name (name
);
2384 || gimple_assign_rhs_code (def_stmt
) != code
)
2390 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2391 assigment and the class of the expresion on the RHS is CLASS. Return
2395 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2399 if (TREE_CODE (name
) != SSA_NAME
)
2402 def_stmt
= get_gimple_for_ssa_name (name
);
2404 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2411 /* Determine whether the LEN bytes generated by CONSTFUN can be
2412 stored to memory using several move instructions. CONSTFUNDATA is
2413 a pointer which will be passed as argument in every CONSTFUN call.
2414 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2415 a memset operation and false if it's a copy of a constant string.
2416 Return nonzero if a call to store_by_pieces should succeed. */
2419 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2420 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2421 void *constfundata
, unsigned int align
, bool memsetp
)
2423 unsigned HOST_WIDE_INT l
;
2424 unsigned int max_size
;
2425 HOST_WIDE_INT offset
= 0;
2427 enum insn_code icode
;
2429 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2430 rtx cst ATTRIBUTE_UNUSED
;
2435 if (!targetm
.use_by_pieces_infrastructure_p (len
, align
,
2439 optimize_insn_for_speed_p ()))
2442 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2444 /* We would first store what we can in the largest integer mode, then go to
2445 successively smaller modes. */
2448 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2452 max_size
= STORE_MAX_PIECES
+ 1;
2453 while (max_size
> 1 && l
> 0)
2455 mode
= widest_int_mode_for_size (max_size
);
2457 if (mode
== VOIDmode
)
2460 icode
= optab_handler (mov_optab
, mode
);
2461 if (icode
!= CODE_FOR_nothing
2462 && align
>= GET_MODE_ALIGNMENT (mode
))
2464 unsigned int size
= GET_MODE_SIZE (mode
);
2471 cst
= (*constfun
) (constfundata
, offset
, mode
);
2472 if (!targetm
.legitimate_constant_p (mode
, cst
))
2482 max_size
= GET_MODE_SIZE (mode
);
2485 /* The code above should have handled everything. */
2492 /* Generate several move instructions to store LEN bytes generated by
2493 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2494 pointer which will be passed as argument in every CONSTFUN call.
2495 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2496 a memset operation and false if it's a copy of a constant string.
2497 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2498 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2502 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2503 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2504 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2506 machine_mode to_addr_mode
= get_address_mode (to
);
2507 struct store_by_pieces_d data
;
2511 gcc_assert (endp
!= 2);
2515 gcc_assert (targetm
.use_by_pieces_infrastructure_p
2520 optimize_insn_for_speed_p ()));
2522 data
.constfun
= constfun
;
2523 data
.constfundata
= constfundata
;
2526 store_by_pieces_1 (&data
, align
);
2531 gcc_assert (!data
.reverse
);
2536 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2537 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2539 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2540 plus_constant (to_addr_mode
,
2544 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2551 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2559 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2560 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2563 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2565 struct store_by_pieces_d data
;
2570 data
.constfun
= clear_by_pieces_1
;
2571 data
.constfundata
= NULL
;
2574 store_by_pieces_1 (&data
, align
);
2577 /* Callback routine for clear_by_pieces.
2578 Return const0_rtx unconditionally. */
2581 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2582 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2583 machine_mode mode ATTRIBUTE_UNUSED
)
2588 /* Subroutine of clear_by_pieces and store_by_pieces.
2589 Generate several move instructions to store LEN bytes of block TO. (A MEM
2590 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2593 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2594 unsigned int align ATTRIBUTE_UNUSED
)
2596 machine_mode to_addr_mode
= get_address_mode (data
->to
);
2597 rtx to_addr
= XEXP (data
->to
, 0);
2598 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2599 enum insn_code icode
;
2602 data
->to_addr
= to_addr
;
2604 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2605 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2607 data
->explicit_inc_to
= 0;
2609 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2611 data
->offset
= data
->len
;
2613 /* If storing requires more than two move insns,
2614 copy addresses to registers (to make displacements shorter)
2615 and use post-increment if available. */
2616 if (!data
->autinc_to
2617 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2619 /* Determine the main mode we'll be using.
2620 MODE might not be used depending on the definitions of the
2621 USE_* macros below. */
2622 machine_mode mode ATTRIBUTE_UNUSED
2623 = widest_int_mode_for_size (max_size
);
2625 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2627 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2628 plus_constant (to_addr_mode
,
2631 data
->autinc_to
= 1;
2632 data
->explicit_inc_to
= -1;
2635 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2636 && ! data
->autinc_to
)
2638 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2639 data
->autinc_to
= 1;
2640 data
->explicit_inc_to
= 1;
2643 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2644 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2647 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2649 /* First store what we can in the largest integer mode, then go to
2650 successively smaller modes. */
2652 while (max_size
> 1 && data
->len
> 0)
2654 machine_mode mode
= widest_int_mode_for_size (max_size
);
2656 if (mode
== VOIDmode
)
2659 icode
= optab_handler (mov_optab
, mode
);
2660 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2661 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2663 max_size
= GET_MODE_SIZE (mode
);
2666 /* The code above should have handled everything. */
2667 gcc_assert (!data
->len
);
2670 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2671 with move instructions for mode MODE. GENFUN is the gen_... function
2672 to make a move insn for that mode. DATA has all the other info. */
2675 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2676 struct store_by_pieces_d
*data
)
2678 unsigned int size
= GET_MODE_SIZE (mode
);
2681 while (data
->len
>= size
)
2684 data
->offset
-= size
;
2686 if (data
->autinc_to
)
2687 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2690 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2692 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2693 emit_insn (gen_add2_insn (data
->to_addr
,
2694 gen_int_mode (-(HOST_WIDE_INT
) size
,
2695 GET_MODE (data
->to_addr
))));
2697 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2698 emit_insn ((*genfun
) (to1
, cst
));
2700 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2701 emit_insn (gen_add2_insn (data
->to_addr
,
2703 GET_MODE (data
->to_addr
))));
2705 if (! data
->reverse
)
2706 data
->offset
+= size
;
2712 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2713 its length in bytes. */
2716 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2717 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2718 unsigned HOST_WIDE_INT min_size
,
2719 unsigned HOST_WIDE_INT max_size
,
2720 unsigned HOST_WIDE_INT probable_max_size
)
2722 machine_mode mode
= GET_MODE (object
);
2725 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2727 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2728 just move a zero. Otherwise, do this a piece at a time. */
2730 && CONST_INT_P (size
)
2731 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2733 rtx zero
= CONST0_RTX (mode
);
2736 emit_move_insn (object
, zero
);
2740 if (COMPLEX_MODE_P (mode
))
2742 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2745 write_complex_part (object
, zero
, 0);
2746 write_complex_part (object
, zero
, 1);
2752 if (size
== const0_rtx
)
2755 align
= MEM_ALIGN (object
);
2757 if (CONST_INT_P (size
)
2758 && targetm
.use_by_pieces_infrastructure_p (INTVAL (size
), align
,
2760 optimize_insn_for_speed_p ()))
2761 clear_by_pieces (object
, INTVAL (size
), align
);
2762 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2763 expected_align
, expected_size
,
2764 min_size
, max_size
, probable_max_size
))
2766 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2767 return set_storage_via_libcall (object
, size
, const0_rtx
,
2768 method
== BLOCK_OP_TAILCALL
);
2776 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2778 unsigned HOST_WIDE_INT max
, min
= 0;
2779 if (GET_CODE (size
) == CONST_INT
)
2780 min
= max
= UINTVAL (size
);
2782 max
= GET_MODE_MASK (GET_MODE (size
));
2783 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2787 /* A subroutine of clear_storage. Expand a call to memset.
2788 Return the return value of memset, 0 otherwise. */
2791 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2793 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2794 machine_mode size_mode
;
2797 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2798 place those into new pseudos into a VAR_DECL and use them later. */
2800 object
= copy_addr_to_reg (XEXP (object
, 0));
2802 size_mode
= TYPE_MODE (sizetype
);
2803 size
= convert_to_mode (size_mode
, size
, 1);
2804 size
= copy_to_mode_reg (size_mode
, size
);
2806 /* It is incorrect to use the libcall calling conventions to call
2807 memset in this context. This could be a user call to memset and
2808 the user may wish to examine the return value from memset. For
2809 targets where libcalls and normal calls have different conventions
2810 for returning pointers, we could end up generating incorrect code. */
2812 object_tree
= make_tree (ptr_type_node
, object
);
2813 if (!CONST_INT_P (val
))
2814 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2815 size_tree
= make_tree (sizetype
, size
);
2816 val_tree
= make_tree (integer_type_node
, val
);
2818 fn
= clear_storage_libcall_fn (true);
2819 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2820 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2822 retval
= expand_normal (call_expr
);
2827 /* A subroutine of set_storage_via_libcall. Create the tree node
2828 for the function we use for block clears. */
2830 tree block_clear_fn
;
2833 init_block_clear_fn (const char *asmspec
)
2835 if (!block_clear_fn
)
2839 fn
= get_identifier ("memset");
2840 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2841 integer_type_node
, sizetype
,
2844 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2845 DECL_EXTERNAL (fn
) = 1;
2846 TREE_PUBLIC (fn
) = 1;
2847 DECL_ARTIFICIAL (fn
) = 1;
2848 TREE_NOTHROW (fn
) = 1;
2849 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2850 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2852 block_clear_fn
= fn
;
2856 set_user_assembler_name (block_clear_fn
, asmspec
);
2860 clear_storage_libcall_fn (int for_call
)
2862 static bool emitted_extern
;
2864 if (!block_clear_fn
)
2865 init_block_clear_fn (NULL
);
2867 if (for_call
&& !emitted_extern
)
2869 emitted_extern
= true;
2870 make_decl_rtl (block_clear_fn
);
2873 return block_clear_fn
;
2876 /* Expand a setmem pattern; return true if successful. */
2879 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2880 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2881 unsigned HOST_WIDE_INT min_size
,
2882 unsigned HOST_WIDE_INT max_size
,
2883 unsigned HOST_WIDE_INT probable_max_size
)
2885 /* Try the most limited insn first, because there's no point
2886 including more than one in the machine description unless
2887 the more limited one has some advantage. */
2891 if (expected_align
< align
)
2892 expected_align
= align
;
2893 if (expected_size
!= -1)
2895 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2896 expected_size
= max_size
;
2897 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2898 expected_size
= min_size
;
2901 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2902 mode
= GET_MODE_WIDER_MODE (mode
))
2904 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2906 if (code
!= CODE_FOR_nothing
2907 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2908 here because if SIZE is less than the mode mask, as it is
2909 returned by the macro, it will definitely be less than the
2910 actual mode mask. Since SIZE is within the Pmode address
2911 space, we limit MODE to Pmode. */
2912 && ((CONST_INT_P (size
)
2913 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2914 <= (GET_MODE_MASK (mode
) >> 1)))
2915 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2916 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2918 struct expand_operand ops
[9];
2921 nops
= insn_data
[(int) code
].n_generator_args
;
2922 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2924 create_fixed_operand (&ops
[0], object
);
2925 /* The check above guarantees that this size conversion is valid. */
2926 create_convert_operand_to (&ops
[1], size
, mode
, true);
2927 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2928 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2931 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2932 create_integer_operand (&ops
[5], expected_size
);
2936 create_integer_operand (&ops
[6], min_size
);
2937 /* If we can not represent the maximal size,
2938 make parameter NULL. */
2939 if ((HOST_WIDE_INT
) max_size
!= -1)
2940 create_integer_operand (&ops
[7], max_size
);
2942 create_fixed_operand (&ops
[7], NULL
);
2946 /* If we can not represent the maximal size,
2947 make parameter NULL. */
2948 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2949 create_integer_operand (&ops
[8], probable_max_size
);
2951 create_fixed_operand (&ops
[8], NULL
);
2953 if (maybe_expand_insn (code
, nops
, ops
))
2962 /* Write to one of the components of the complex value CPLX. Write VAL to
2963 the real part if IMAG_P is false, and the imaginary part if its true. */
2966 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2972 if (GET_CODE (cplx
) == CONCAT
)
2974 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2978 cmode
= GET_MODE (cplx
);
2979 imode
= GET_MODE_INNER (cmode
);
2980 ibitsize
= GET_MODE_BITSIZE (imode
);
2982 /* For MEMs simplify_gen_subreg may generate an invalid new address
2983 because, e.g., the original address is considered mode-dependent
2984 by the target, which restricts simplify_subreg from invoking
2985 adjust_address_nv. Instead of preparing fallback support for an
2986 invalid address, we call adjust_address_nv directly. */
2989 emit_move_insn (adjust_address_nv (cplx
, imode
,
2990 imag_p
? GET_MODE_SIZE (imode
) : 0),
2995 /* If the sub-object is at least word sized, then we know that subregging
2996 will work. This special case is important, since store_bit_field
2997 wants to operate on integer modes, and there's rarely an OImode to
2998 correspond to TCmode. */
2999 if (ibitsize
>= BITS_PER_WORD
3000 /* For hard regs we have exact predicates. Assume we can split
3001 the original object if it spans an even number of hard regs.
3002 This special case is important for SCmode on 64-bit platforms
3003 where the natural size of floating-point regs is 32-bit. */
3005 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3006 && REG_NREGS (cplx
) % 2 == 0))
3008 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3009 imag_p
? GET_MODE_SIZE (imode
) : 0);
3012 emit_move_insn (part
, val
);
3016 /* simplify_gen_subreg may fail for sub-word MEMs. */
3017 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3020 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
3023 /* Extract one of the components of the complex value CPLX. Extract the
3024 real part if IMAG_P is false, and the imaginary part if it's true. */
3027 read_complex_part (rtx cplx
, bool imag_p
)
3029 machine_mode cmode
, imode
;
3032 if (GET_CODE (cplx
) == CONCAT
)
3033 return XEXP (cplx
, imag_p
);
3035 cmode
= GET_MODE (cplx
);
3036 imode
= GET_MODE_INNER (cmode
);
3037 ibitsize
= GET_MODE_BITSIZE (imode
);
3039 /* Special case reads from complex constants that got spilled to memory. */
3040 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3042 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3043 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3045 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3046 if (CONSTANT_CLASS_P (part
))
3047 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3051 /* For MEMs simplify_gen_subreg may generate an invalid new address
3052 because, e.g., the original address is considered mode-dependent
3053 by the target, which restricts simplify_subreg from invoking
3054 adjust_address_nv. Instead of preparing fallback support for an
3055 invalid address, we call adjust_address_nv directly. */
3057 return adjust_address_nv (cplx
, imode
,
3058 imag_p
? GET_MODE_SIZE (imode
) : 0);
3060 /* If the sub-object is at least word sized, then we know that subregging
3061 will work. This special case is important, since extract_bit_field
3062 wants to operate on integer modes, and there's rarely an OImode to
3063 correspond to TCmode. */
3064 if (ibitsize
>= BITS_PER_WORD
3065 /* For hard regs we have exact predicates. Assume we can split
3066 the original object if it spans an even number of hard regs.
3067 This special case is important for SCmode on 64-bit platforms
3068 where the natural size of floating-point regs is 32-bit. */
3070 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3071 && REG_NREGS (cplx
) % 2 == 0))
3073 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3074 imag_p
? GET_MODE_SIZE (imode
) : 0);
3078 /* simplify_gen_subreg may fail for sub-word MEMs. */
3079 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3082 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3083 true, NULL_RTX
, imode
, imode
);
3086 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3087 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3088 represented in NEW_MODE. If FORCE is true, this will never happen, as
3089 we'll force-create a SUBREG if needed. */
3092 emit_move_change_mode (machine_mode new_mode
,
3093 machine_mode old_mode
, rtx x
, bool force
)
3097 if (push_operand (x
, GET_MODE (x
)))
3099 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3100 MEM_COPY_ATTRIBUTES (ret
, x
);
3104 /* We don't have to worry about changing the address since the
3105 size in bytes is supposed to be the same. */
3106 if (reload_in_progress
)
3108 /* Copy the MEM to change the mode and move any
3109 substitutions from the old MEM to the new one. */
3110 ret
= adjust_address_nv (x
, new_mode
, 0);
3111 copy_replacements (x
, ret
);
3114 ret
= adjust_address (x
, new_mode
, 0);
3118 /* Note that we do want simplify_subreg's behavior of validating
3119 that the new mode is ok for a hard register. If we were to use
3120 simplify_gen_subreg, we would create the subreg, but would
3121 probably run into the target not being able to implement it. */
3122 /* Except, of course, when FORCE is true, when this is exactly what
3123 we want. Which is needed for CCmodes on some targets. */
3125 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3127 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3133 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3134 an integer mode of the same size as MODE. Returns the instruction
3135 emitted, or NULL if such a move could not be generated. */
3138 emit_move_via_integer (machine_mode mode
, rtx x
, rtx y
, bool force
)
3141 enum insn_code code
;
3143 /* There must exist a mode of the exact size we require. */
3144 imode
= int_mode_for_mode (mode
);
3145 if (imode
== BLKmode
)
3148 /* The target must support moves in this mode. */
3149 code
= optab_handler (mov_optab
, imode
);
3150 if (code
== CODE_FOR_nothing
)
3153 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3156 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3159 return emit_insn (GEN_FCN (code
) (x
, y
));
3162 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3163 Return an equivalent MEM that does not use an auto-increment. */
3166 emit_move_resolve_push (machine_mode mode
, rtx x
)
3168 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3169 HOST_WIDE_INT adjust
;
3172 adjust
= GET_MODE_SIZE (mode
);
3173 #ifdef PUSH_ROUNDING
3174 adjust
= PUSH_ROUNDING (adjust
);
3176 if (code
== PRE_DEC
|| code
== POST_DEC
)
3178 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3180 rtx expr
= XEXP (XEXP (x
, 0), 1);
3183 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3184 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3185 val
= INTVAL (XEXP (expr
, 1));
3186 if (GET_CODE (expr
) == MINUS
)
3188 gcc_assert (adjust
== val
|| adjust
== -val
);
3192 /* Do not use anti_adjust_stack, since we don't want to update
3193 stack_pointer_delta. */
3194 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3195 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3196 0, OPTAB_LIB_WIDEN
);
3197 if (temp
!= stack_pointer_rtx
)
3198 emit_move_insn (stack_pointer_rtx
, temp
);
3205 temp
= stack_pointer_rtx
;
3210 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3216 return replace_equiv_address (x
, temp
);
3219 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3220 X is known to satisfy push_operand, and MODE is known to be complex.
3221 Returns the last instruction emitted. */
3224 emit_move_complex_push (machine_mode mode
, rtx x
, rtx y
)
3226 machine_mode submode
= GET_MODE_INNER (mode
);
3229 #ifdef PUSH_ROUNDING
3230 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3232 /* In case we output to the stack, but the size is smaller than the
3233 machine can push exactly, we need to use move instructions. */
3234 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3236 x
= emit_move_resolve_push (mode
, x
);
3237 return emit_move_insn (x
, y
);
3241 /* Note that the real part always precedes the imag part in memory
3242 regardless of machine's endianness. */
3243 switch (GET_CODE (XEXP (x
, 0)))
3257 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3258 read_complex_part (y
, imag_first
));
3259 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3260 read_complex_part (y
, !imag_first
));
3263 /* A subroutine of emit_move_complex. Perform the move from Y to X
3264 via two moves of the parts. Returns the last instruction emitted. */
3267 emit_move_complex_parts (rtx x
, rtx y
)
3269 /* Show the output dies here. This is necessary for SUBREGs
3270 of pseudos since we cannot track their lifetimes correctly;
3271 hard regs shouldn't appear here except as return values. */
3272 if (!reload_completed
&& !reload_in_progress
3273 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3276 write_complex_part (x
, read_complex_part (y
, false), false);
3277 write_complex_part (x
, read_complex_part (y
, true), true);
3279 return get_last_insn ();
3282 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3283 MODE is known to be complex. Returns the last instruction emitted. */
3286 emit_move_complex (machine_mode mode
, rtx x
, rtx y
)
3290 /* Need to take special care for pushes, to maintain proper ordering
3291 of the data, and possibly extra padding. */
3292 if (push_operand (x
, mode
))
3293 return emit_move_complex_push (mode
, x
, y
);
3295 /* See if we can coerce the target into moving both values at once, except
3296 for floating point where we favor moving as parts if this is easy. */
3297 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3298 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3300 && HARD_REGISTER_P (x
)
3301 && REG_NREGS (x
) == 1)
3303 && HARD_REGISTER_P (y
)
3304 && REG_NREGS (y
) == 1))
3306 /* Not possible if the values are inherently not adjacent. */
3307 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3309 /* Is possible if both are registers (or subregs of registers). */
3310 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3312 /* If one of the operands is a memory, and alignment constraints
3313 are friendly enough, we may be able to do combined memory operations.
3314 We do not attempt this if Y is a constant because that combination is
3315 usually better with the by-parts thing below. */
3316 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3317 && (!STRICT_ALIGNMENT
3318 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3327 /* For memory to memory moves, optimal behavior can be had with the
3328 existing block move logic. */
3329 if (MEM_P (x
) && MEM_P (y
))
3331 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3332 BLOCK_OP_NO_LIBCALL
);
3333 return get_last_insn ();
3336 ret
= emit_move_via_integer (mode
, x
, y
, true);
3341 return emit_move_complex_parts (x
, y
);
3344 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3345 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3348 emit_move_ccmode (machine_mode mode
, rtx x
, rtx y
)
3352 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3355 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3356 if (code
!= CODE_FOR_nothing
)
3358 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3359 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3360 return emit_insn (GEN_FCN (code
) (x
, y
));
3364 /* Otherwise, find the MODE_INT mode of the same width. */
3365 ret
= emit_move_via_integer (mode
, x
, y
, false);
3366 gcc_assert (ret
!= NULL
);
3370 /* Return true if word I of OP lies entirely in the
3371 undefined bits of a paradoxical subreg. */
3374 undefined_operand_subword_p (const_rtx op
, int i
)
3376 machine_mode innermode
, innermostmode
;
3378 if (GET_CODE (op
) != SUBREG
)
3380 innermode
= GET_MODE (op
);
3381 innermostmode
= GET_MODE (SUBREG_REG (op
));
3382 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3383 /* The SUBREG_BYTE represents offset, as if the value were stored in
3384 memory, except for a paradoxical subreg where we define
3385 SUBREG_BYTE to be 0; undo this exception as in
3387 if (SUBREG_BYTE (op
) == 0
3388 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3390 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3391 if (WORDS_BIG_ENDIAN
)
3392 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3393 if (BYTES_BIG_ENDIAN
)
3394 offset
+= difference
% UNITS_PER_WORD
;
3396 if (offset
>= GET_MODE_SIZE (innermostmode
)
3397 || offset
<= -GET_MODE_SIZE (word_mode
))
3402 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3403 MODE is any multi-word or full-word mode that lacks a move_insn
3404 pattern. Note that you will get better code if you define such
3405 patterns, even if they must turn into multiple assembler instructions. */
3408 emit_move_multi_word (machine_mode mode
, rtx x
, rtx y
)
3410 rtx_insn
*last_insn
= 0;
3416 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3418 /* If X is a push on the stack, do the push now and replace
3419 X with a reference to the stack pointer. */
3420 if (push_operand (x
, mode
))
3421 x
= emit_move_resolve_push (mode
, x
);
3423 /* If we are in reload, see if either operand is a MEM whose address
3424 is scheduled for replacement. */
3425 if (reload_in_progress
&& MEM_P (x
)
3426 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3427 x
= replace_equiv_address_nv (x
, inner
);
3428 if (reload_in_progress
&& MEM_P (y
)
3429 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3430 y
= replace_equiv_address_nv (y
, inner
);
3434 need_clobber
= false;
3436 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3439 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3442 /* Do not generate code for a move if it would come entirely
3443 from the undefined bits of a paradoxical subreg. */
3444 if (undefined_operand_subword_p (y
, i
))
3447 ypart
= operand_subword (y
, i
, 1, mode
);
3449 /* If we can't get a part of Y, put Y into memory if it is a
3450 constant. Otherwise, force it into a register. Then we must
3451 be able to get a part of Y. */
3452 if (ypart
== 0 && CONSTANT_P (y
))
3454 y
= use_anchored_address (force_const_mem (mode
, y
));
3455 ypart
= operand_subword (y
, i
, 1, mode
);
3457 else if (ypart
== 0)
3458 ypart
= operand_subword_force (y
, i
, mode
);
3460 gcc_assert (xpart
&& ypart
);
3462 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3464 last_insn
= emit_move_insn (xpart
, ypart
);
3470 /* Show the output dies here. This is necessary for SUBREGs
3471 of pseudos since we cannot track their lifetimes correctly;
3472 hard regs shouldn't appear here except as return values.
3473 We never want to emit such a clobber after reload. */
3475 && ! (reload_in_progress
|| reload_completed
)
3476 && need_clobber
!= 0)
3484 /* Low level part of emit_move_insn.
3485 Called just like emit_move_insn, but assumes X and Y
3486 are basically valid. */
3489 emit_move_insn_1 (rtx x
, rtx y
)
3491 machine_mode mode
= GET_MODE (x
);
3492 enum insn_code code
;
3494 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3496 code
= optab_handler (mov_optab
, mode
);
3497 if (code
!= CODE_FOR_nothing
)
3498 return emit_insn (GEN_FCN (code
) (x
, y
));
3500 /* Expand complex moves by moving real part and imag part. */
3501 if (COMPLEX_MODE_P (mode
))
3502 return emit_move_complex (mode
, x
, y
);
3504 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3505 || ALL_FIXED_POINT_MODE_P (mode
))
3507 rtx_insn
*result
= emit_move_via_integer (mode
, x
, y
, true);
3509 /* If we can't find an integer mode, use multi words. */
3513 return emit_move_multi_word (mode
, x
, y
);
3516 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3517 return emit_move_ccmode (mode
, x
, y
);
3519 /* Try using a move pattern for the corresponding integer mode. This is
3520 only safe when simplify_subreg can convert MODE constants into integer
3521 constants. At present, it can only do this reliably if the value
3522 fits within a HOST_WIDE_INT. */
3523 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3525 rtx_insn
*ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3529 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3534 return emit_move_multi_word (mode
, x
, y
);
3537 /* Generate code to copy Y into X.
3538 Both Y and X must have the same mode, except that
3539 Y can be a constant with VOIDmode.
3540 This mode cannot be BLKmode; use emit_block_move for that.
3542 Return the last instruction emitted. */
3545 emit_move_insn (rtx x
, rtx y
)
3547 machine_mode mode
= GET_MODE (x
);
3548 rtx y_cst
= NULL_RTX
;
3549 rtx_insn
*last_insn
;
3552 gcc_assert (mode
!= BLKmode
3553 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3558 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3559 && (last_insn
= compress_float_constant (x
, y
)))
3564 if (!targetm
.legitimate_constant_p (mode
, y
))
3566 y
= force_const_mem (mode
, y
);
3568 /* If the target's cannot_force_const_mem prevented the spill,
3569 assume that the target's move expanders will also take care
3570 of the non-legitimate constant. */
3574 y
= use_anchored_address (y
);
3578 /* If X or Y are memory references, verify that their addresses are valid
3581 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3583 && ! push_operand (x
, GET_MODE (x
))))
3584 x
= validize_mem (x
);
3587 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3588 MEM_ADDR_SPACE (y
)))
3589 y
= validize_mem (y
);
3591 gcc_assert (mode
!= BLKmode
);
3593 last_insn
= emit_move_insn_1 (x
, y
);
3595 if (y_cst
&& REG_P (x
)
3596 && (set
= single_set (last_insn
)) != NULL_RTX
3597 && SET_DEST (set
) == x
3598 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3599 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3604 /* Generate the body of an instruction to copy Y into X.
3605 It may be a list of insns, if one insn isn't enough. */
3608 gen_move_insn (rtx x
, rtx y
)
3613 emit_move_insn_1 (x
, y
);
3619 /* If Y is representable exactly in a narrower mode, and the target can
3620 perform the extension directly from constant or memory, then emit the
3621 move as an extension. */
3624 compress_float_constant (rtx x
, rtx y
)
3626 machine_mode dstmode
= GET_MODE (x
);
3627 machine_mode orig_srcmode
= GET_MODE (y
);
3628 machine_mode srcmode
;
3629 const REAL_VALUE_TYPE
*r
;
3630 int oldcost
, newcost
;
3631 bool speed
= optimize_insn_for_speed_p ();
3633 r
= CONST_DOUBLE_REAL_VALUE (y
);
3635 if (targetm
.legitimate_constant_p (dstmode
, y
))
3636 oldcost
= set_src_cost (y
, orig_srcmode
, speed
);
3638 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), dstmode
, speed
);
3640 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3641 srcmode
!= orig_srcmode
;
3642 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3646 rtx_insn
*last_insn
;
3648 /* Skip if the target can't extend this way. */
3649 ic
= can_extend_p (dstmode
, srcmode
, 0);
3650 if (ic
== CODE_FOR_nothing
)
3653 /* Skip if the narrowed value isn't exact. */
3654 if (! exact_real_truncate (srcmode
, r
))
3657 trunc_y
= const_double_from_real_value (*r
, srcmode
);
3659 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3661 /* Skip if the target needs extra instructions to perform
3663 if (!insn_operand_matches (ic
, 1, trunc_y
))
3665 /* This is valid, but may not be cheaper than the original. */
3666 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3668 if (oldcost
< newcost
)
3671 else if (float_extend_from_mem
[dstmode
][srcmode
])
3673 trunc_y
= force_const_mem (srcmode
, 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
)
3679 trunc_y
= validize_mem (trunc_y
);
3684 /* For CSE's benefit, force the compressed constant pool entry
3685 into a new pseudo. This constant may be used in different modes,
3686 and if not, combine will put things back together for us. */
3687 trunc_y
= force_reg (srcmode
, trunc_y
);
3689 /* If x is a hard register, perform the extension into a pseudo,
3690 so that e.g. stack realignment code is aware of it. */
3692 if (REG_P (x
) && HARD_REGISTER_P (x
))
3693 target
= gen_reg_rtx (dstmode
);
3695 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
3696 last_insn
= get_last_insn ();
3699 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3702 return emit_move_insn (x
, target
);
3709 /* Pushing data onto the stack. */
3711 /* Push a block of length SIZE (perhaps variable)
3712 and return an rtx to address the beginning of the block.
3713 The value may be virtual_outgoing_args_rtx.
3715 EXTRA is the number of bytes of padding to push in addition to SIZE.
3716 BELOW nonzero means this padding comes at low addresses;
3717 otherwise, the padding comes at high addresses. */
3720 push_block (rtx size
, int extra
, int below
)
3724 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3725 if (CONSTANT_P (size
))
3726 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3727 else if (REG_P (size
) && extra
== 0)
3728 anti_adjust_stack (size
);
3731 temp
= copy_to_mode_reg (Pmode
, size
);
3733 temp
= expand_binop (Pmode
, add_optab
, temp
,
3734 gen_int_mode (extra
, Pmode
),
3735 temp
, 0, OPTAB_LIB_WIDEN
);
3736 anti_adjust_stack (temp
);
3739 if (STACK_GROWS_DOWNWARD
)
3741 temp
= virtual_outgoing_args_rtx
;
3742 if (extra
!= 0 && below
)
3743 temp
= plus_constant (Pmode
, temp
, extra
);
3747 if (CONST_INT_P (size
))
3748 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3749 -INTVAL (size
) - (below
? 0 : extra
));
3750 else if (extra
!= 0 && !below
)
3751 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3752 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3755 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3756 negate_rtx (Pmode
, size
));
3759 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3762 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3765 mem_autoinc_base (rtx mem
)
3769 rtx addr
= XEXP (mem
, 0);
3770 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3771 return XEXP (addr
, 0);
3776 /* A utility routine used here, in reload, and in try_split. The insns
3777 after PREV up to and including LAST are known to adjust the stack,
3778 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3779 placing notes as appropriate. PREV may be NULL, indicating the
3780 entire insn sequence prior to LAST should be scanned.
3782 The set of allowed stack pointer modifications is small:
3783 (1) One or more auto-inc style memory references (aka pushes),
3784 (2) One or more addition/subtraction with the SP as destination,
3785 (3) A single move insn with the SP as destination,
3786 (4) A call_pop insn,
3787 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3789 Insns in the sequence that do not modify the SP are ignored,
3790 except for noreturn calls.
3792 The return value is the amount of adjustment that can be trivially
3793 verified, via immediate operand or auto-inc. If the adjustment
3794 cannot be trivially extracted, the return value is INT_MIN. */
3797 find_args_size_adjust (rtx_insn
*insn
)
3802 pat
= PATTERN (insn
);
3805 /* Look for a call_pop pattern. */
3808 /* We have to allow non-call_pop patterns for the case
3809 of emit_single_push_insn of a TLS address. */
3810 if (GET_CODE (pat
) != PARALLEL
)
3813 /* All call_pop have a stack pointer adjust in the parallel.
3814 The call itself is always first, and the stack adjust is
3815 usually last, so search from the end. */
3816 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3818 set
= XVECEXP (pat
, 0, i
);
3819 if (GET_CODE (set
) != SET
)
3821 dest
= SET_DEST (set
);
3822 if (dest
== stack_pointer_rtx
)
3825 /* We'd better have found the stack pointer adjust. */
3828 /* Fall through to process the extracted SET and DEST
3829 as if it was a standalone insn. */
3831 else if (GET_CODE (pat
) == SET
)
3833 else if ((set
= single_set (insn
)) != NULL
)
3835 else if (GET_CODE (pat
) == PARALLEL
)
3837 /* ??? Some older ports use a parallel with a stack adjust
3838 and a store for a PUSH_ROUNDING pattern, rather than a
3839 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3840 /* ??? See h8300 and m68k, pushqi1. */
3841 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3843 set
= XVECEXP (pat
, 0, i
);
3844 if (GET_CODE (set
) != SET
)
3846 dest
= SET_DEST (set
);
3847 if (dest
== stack_pointer_rtx
)
3850 /* We do not expect an auto-inc of the sp in the parallel. */
3851 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3852 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3853 != stack_pointer_rtx
);
3861 dest
= SET_DEST (set
);
3863 /* Look for direct modifications of the stack pointer. */
3864 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3866 /* Look for a trivial adjustment, otherwise assume nothing. */
3867 /* Note that the SPU restore_stack_block pattern refers to
3868 the stack pointer in V4SImode. Consider that non-trivial. */
3869 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3870 && GET_CODE (SET_SRC (set
)) == PLUS
3871 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3872 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3873 return INTVAL (XEXP (SET_SRC (set
), 1));
3874 /* ??? Reload can generate no-op moves, which will be cleaned
3875 up later. Recognize it and continue searching. */
3876 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3879 return HOST_WIDE_INT_MIN
;
3885 /* Otherwise only think about autoinc patterns. */
3886 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3889 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3890 != stack_pointer_rtx
);
3892 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3893 mem
= SET_SRC (set
);
3897 addr
= XEXP (mem
, 0);
3898 switch (GET_CODE (addr
))
3902 return GET_MODE_SIZE (GET_MODE (mem
));
3905 return -GET_MODE_SIZE (GET_MODE (mem
));
3908 addr
= XEXP (addr
, 1);
3909 gcc_assert (GET_CODE (addr
) == PLUS
);
3910 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3911 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3912 return INTVAL (XEXP (addr
, 1));
3920 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
, int end_args_size
)
3922 int args_size
= end_args_size
;
3923 bool saw_unknown
= false;
3926 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3928 HOST_WIDE_INT this_delta
;
3930 if (!NONDEBUG_INSN_P (insn
))
3933 this_delta
= find_args_size_adjust (insn
);
3934 if (this_delta
== 0)
3937 || ACCUMULATE_OUTGOING_ARGS
3938 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3942 gcc_assert (!saw_unknown
);
3943 if (this_delta
== HOST_WIDE_INT_MIN
)
3946 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3947 if (STACK_GROWS_DOWNWARD
)
3948 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3950 args_size
-= this_delta
;
3953 return saw_unknown
? INT_MIN
: args_size
;
3956 #ifdef PUSH_ROUNDING
3957 /* Emit single push insn. */
3960 emit_single_push_insn_1 (machine_mode mode
, rtx x
, tree type
)
3963 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3965 enum insn_code icode
;
3967 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3968 /* If there is push pattern, use it. Otherwise try old way of throwing
3969 MEM representing push operation to move expander. */
3970 icode
= optab_handler (push_optab
, mode
);
3971 if (icode
!= CODE_FOR_nothing
)
3973 struct expand_operand ops
[1];
3975 create_input_operand (&ops
[0], x
, mode
);
3976 if (maybe_expand_insn (icode
, 1, ops
))
3979 if (GET_MODE_SIZE (mode
) == rounded_size
)
3980 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3981 /* If we are to pad downward, adjust the stack pointer first and
3982 then store X into the stack location using an offset. This is
3983 because emit_move_insn does not know how to pad; it does not have
3985 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3987 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3988 HOST_WIDE_INT offset
;
3990 emit_move_insn (stack_pointer_rtx
,
3991 expand_binop (Pmode
,
3992 STACK_GROWS_DOWNWARD
? sub_optab
3995 gen_int_mode (rounded_size
, Pmode
),
3996 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3998 offset
= (HOST_WIDE_INT
) padding_size
;
3999 if (STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_DEC
)
4000 /* We have already decremented the stack pointer, so get the
4002 offset
+= (HOST_WIDE_INT
) rounded_size
;
4004 if (!STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_INC
)
4005 /* We have already incremented the stack pointer, so get the
4007 offset
-= (HOST_WIDE_INT
) rounded_size
;
4009 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4010 gen_int_mode (offset
, Pmode
));
4014 if (STACK_GROWS_DOWNWARD
)
4015 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4016 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4017 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4020 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4021 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4022 gen_int_mode (rounded_size
, Pmode
));
4024 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4027 dest
= gen_rtx_MEM (mode
, dest_addr
);
4031 set_mem_attributes (dest
, type
, 1);
4033 if (cfun
->tail_call_marked
)
4034 /* Function incoming arguments may overlap with sibling call
4035 outgoing arguments and we cannot allow reordering of reads
4036 from function arguments with stores to outgoing arguments
4037 of sibling calls. */
4038 set_mem_alias_set (dest
, 0);
4040 emit_move_insn (dest
, x
);
4043 /* Emit and annotate a single push insn. */
4046 emit_single_push_insn (machine_mode mode
, rtx x
, tree type
)
4048 int delta
, old_delta
= stack_pointer_delta
;
4049 rtx_insn
*prev
= get_last_insn ();
4052 emit_single_push_insn_1 (mode
, x
, type
);
4054 last
= get_last_insn ();
4056 /* Notice the common case where we emitted exactly one insn. */
4057 if (PREV_INSN (last
) == prev
)
4059 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4063 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4064 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4068 /* If reading SIZE bytes from X will end up reading from
4069 Y return the number of bytes that overlap. Return -1
4070 if there is no overlap or -2 if we can't determine
4071 (for example when X and Y have different base registers). */
4074 memory_load_overlap (rtx x
, rtx y
, HOST_WIDE_INT size
)
4076 rtx tmp
= plus_constant (Pmode
, x
, size
);
4077 rtx sub
= simplify_gen_binary (MINUS
, Pmode
, tmp
, y
);
4079 if (!CONST_INT_P (sub
))
4082 HOST_WIDE_INT val
= INTVAL (sub
);
4084 return IN_RANGE (val
, 1, size
) ? val
: -1;
4087 /* Generate code to push X onto the stack, assuming it has mode MODE and
4089 MODE is redundant except when X is a CONST_INT (since they don't
4091 SIZE is an rtx for the size of data to be copied (in bytes),
4092 needed only if X is BLKmode.
4093 Return true if successful. May return false if asked to push a
4094 partial argument during a sibcall optimization (as specified by
4095 SIBCALL_P) and the incoming and outgoing pointers cannot be shown
4098 ALIGN (in bits) is maximum alignment we can assume.
4100 If PARTIAL and REG are both nonzero, then copy that many of the first
4101 bytes of X into registers starting with REG, and push the rest of X.
4102 The amount of space pushed is decreased by PARTIAL bytes.
4103 REG must be a hard register in this case.
4104 If REG is zero but PARTIAL is not, take any all others actions for an
4105 argument partially in registers, but do not actually load any
4108 EXTRA is the amount in bytes of extra space to leave next to this arg.
4109 This is ignored if an argument block has already been allocated.
4111 On a machine that lacks real push insns, ARGS_ADDR is the address of
4112 the bottom of the argument block for this call. We use indexing off there
4113 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4114 argument block has not been preallocated.
4116 ARGS_SO_FAR is the size of args previously pushed for this call.
4118 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4119 for arguments passed in registers. If nonzero, it will be the number
4120 of bytes required. */
4123 emit_push_insn (rtx x
, machine_mode mode
, tree type
, rtx size
,
4124 unsigned int align
, int partial
, rtx reg
, int extra
,
4125 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4126 rtx alignment_pad
, bool sibcall_p
)
4129 enum direction stack_direction
= STACK_GROWS_DOWNWARD
? downward
: upward
;
4131 /* Decide where to pad the argument: `downward' for below,
4132 `upward' for above, or `none' for don't pad it.
4133 Default is below for small data on big-endian machines; else above. */
4134 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4136 /* Invert direction if stack is post-decrement.
4138 if (STACK_PUSH_CODE
== POST_DEC
)
4139 if (where_pad
!= none
)
4140 where_pad
= (where_pad
== downward
? upward
: downward
);
4144 int nregs
= partial
/ UNITS_PER_WORD
;
4145 rtx
*tmp_regs
= NULL
;
4146 int overlapping
= 0;
4149 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4151 /* Copy a block into the stack, entirely or partially. */
4158 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4159 used
= partial
- offset
;
4161 if (mode
!= BLKmode
)
4163 /* A value is to be stored in an insufficiently aligned
4164 stack slot; copy via a suitably aligned slot if
4166 size
= GEN_INT (GET_MODE_SIZE (mode
));
4167 if (!MEM_P (xinner
))
4169 temp
= assign_temp (type
, 1, 1);
4170 emit_move_insn (temp
, xinner
);
4177 /* USED is now the # of bytes we need not copy to the stack
4178 because registers will take care of them. */
4181 xinner
= adjust_address (xinner
, BLKmode
, used
);
4183 /* If the partial register-part of the arg counts in its stack size,
4184 skip the part of stack space corresponding to the registers.
4185 Otherwise, start copying to the beginning of the stack space,
4186 by setting SKIP to 0. */
4187 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4189 #ifdef PUSH_ROUNDING
4190 /* Do it with several push insns if that doesn't take lots of insns
4191 and if there is no difficulty with push insns that skip bytes
4192 on the stack for alignment purposes. */
4195 && CONST_INT_P (size
)
4197 && MEM_ALIGN (xinner
) >= align
4198 && can_move_by_pieces ((unsigned) INTVAL (size
) - used
, align
)
4199 /* Here we avoid the case of a structure whose weak alignment
4200 forces many pushes of a small amount of data,
4201 and such small pushes do rounding that causes trouble. */
4202 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4203 || align
>= BIGGEST_ALIGNMENT
4204 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4205 == (align
/ BITS_PER_UNIT
)))
4206 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4208 /* Push padding now if padding above and stack grows down,
4209 or if padding below and stack grows up.
4210 But if space already allocated, this has already been done. */
4211 if (extra
&& args_addr
== 0
4212 && where_pad
!= none
&& where_pad
!= stack_direction
)
4213 anti_adjust_stack (GEN_INT (extra
));
4215 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4218 #endif /* PUSH_ROUNDING */
4222 /* Otherwise make space on the stack and copy the data
4223 to the address of that space. */
4225 /* Deduct words put into registers from the size we must copy. */
4228 if (CONST_INT_P (size
))
4229 size
= GEN_INT (INTVAL (size
) - used
);
4231 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4232 gen_int_mode (used
, GET_MODE (size
)),
4233 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4236 /* Get the address of the stack space.
4237 In this case, we do not deal with EXTRA separately.
4238 A single stack adjust will do. */
4241 temp
= push_block (size
, extra
, where_pad
== downward
);
4244 else if (CONST_INT_P (args_so_far
))
4245 temp
= memory_address (BLKmode
,
4246 plus_constant (Pmode
, args_addr
,
4247 skip
+ INTVAL (args_so_far
)));
4249 temp
= memory_address (BLKmode
,
4250 plus_constant (Pmode
,
4251 gen_rtx_PLUS (Pmode
,
4256 if (!ACCUMULATE_OUTGOING_ARGS
)
4258 /* If the source is referenced relative to the stack pointer,
4259 copy it to another register to stabilize it. We do not need
4260 to do this if we know that we won't be changing sp. */
4262 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4263 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4264 temp
= copy_to_reg (temp
);
4267 target
= gen_rtx_MEM (BLKmode
, temp
);
4269 /* We do *not* set_mem_attributes here, because incoming arguments
4270 may overlap with sibling call outgoing arguments and we cannot
4271 allow reordering of reads from function arguments with stores
4272 to outgoing arguments of sibling calls. We do, however, want
4273 to record the alignment of the stack slot. */
4274 /* ALIGN may well be better aligned than TYPE, e.g. due to
4275 PARM_BOUNDARY. Assume the caller isn't lying. */
4276 set_mem_align (target
, align
);
4278 /* If part should go in registers and pushing to that part would
4279 overwrite some of the values that need to go into regs, load the
4280 overlapping values into temporary pseudos to be moved into the hard
4281 regs at the end after the stack pushing has completed.
4282 We cannot load them directly into the hard regs here because
4283 they can be clobbered by the block move expansions.
4286 if (partial
> 0 && reg
!= 0 && mode
== BLKmode
4287 && GET_CODE (reg
) != PARALLEL
)
4289 overlapping
= memory_load_overlap (XEXP (x
, 0), temp
, partial
);
4290 if (overlapping
> 0)
4292 gcc_assert (overlapping
% UNITS_PER_WORD
== 0);
4293 overlapping
/= UNITS_PER_WORD
;
4295 tmp_regs
= XALLOCAVEC (rtx
, overlapping
);
4297 for (int i
= 0; i
< overlapping
; i
++)
4298 tmp_regs
[i
] = gen_reg_rtx (word_mode
);
4300 for (int i
= 0; i
< overlapping
; i
++)
4301 emit_move_insn (tmp_regs
[i
],
4302 operand_subword_force (target
, i
, mode
));
4304 else if (overlapping
== -1)
4306 /* Could not determine whether there is overlap.
4307 Fail the sibcall. */
4315 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4318 else if (partial
> 0)
4320 /* Scalar partly in registers. */
4322 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4325 /* # bytes of start of argument
4326 that we must make space for but need not store. */
4327 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4328 int args_offset
= INTVAL (args_so_far
);
4331 /* Push padding now if padding above and stack grows down,
4332 or if padding below and stack grows up.
4333 But if space already allocated, this has already been done. */
4334 if (extra
&& args_addr
== 0
4335 && where_pad
!= none
&& where_pad
!= stack_direction
)
4336 anti_adjust_stack (GEN_INT (extra
));
4338 /* If we make space by pushing it, we might as well push
4339 the real data. Otherwise, we can leave OFFSET nonzero
4340 and leave the space uninitialized. */
4344 /* Now NOT_STACK gets the number of words that we don't need to
4345 allocate on the stack. Convert OFFSET to words too. */
4346 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4347 offset
/= UNITS_PER_WORD
;
4349 /* If the partial register-part of the arg counts in its stack size,
4350 skip the part of stack space corresponding to the registers.
4351 Otherwise, start copying to the beginning of the stack space,
4352 by setting SKIP to 0. */
4353 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4355 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4356 x
= validize_mem (force_const_mem (mode
, x
));
4358 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4359 SUBREGs of such registers are not allowed. */
4360 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4361 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4362 x
= copy_to_reg (x
);
4364 /* Loop over all the words allocated on the stack for this arg. */
4365 /* We can do it by words, because any scalar bigger than a word
4366 has a size a multiple of a word. */
4367 for (i
= size
- 1; i
>= not_stack
; i
--)
4368 if (i
>= not_stack
+ offset
)
4369 if (!emit_push_insn (operand_subword_force (x
, i
, mode
),
4370 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4372 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4374 reg_parm_stack_space
, alignment_pad
, sibcall_p
))
4382 /* Push padding now if padding above and stack grows down,
4383 or if padding below and stack grows up.
4384 But if space already allocated, this has already been done. */
4385 if (extra
&& args_addr
== 0
4386 && where_pad
!= none
&& where_pad
!= stack_direction
)
4387 anti_adjust_stack (GEN_INT (extra
));
4389 #ifdef PUSH_ROUNDING
4390 if (args_addr
== 0 && PUSH_ARGS
)
4391 emit_single_push_insn (mode
, x
, type
);
4395 if (CONST_INT_P (args_so_far
))
4397 = memory_address (mode
,
4398 plus_constant (Pmode
, args_addr
,
4399 INTVAL (args_so_far
)));
4401 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4403 dest
= gen_rtx_MEM (mode
, addr
);
4405 /* We do *not* set_mem_attributes here, because incoming arguments
4406 may overlap with sibling call outgoing arguments and we cannot
4407 allow reordering of reads from function arguments with stores
4408 to outgoing arguments of sibling calls. We do, however, want
4409 to record the alignment of the stack slot. */
4410 /* ALIGN may well be better aligned than TYPE, e.g. due to
4411 PARM_BOUNDARY. Assume the caller isn't lying. */
4412 set_mem_align (dest
, align
);
4414 emit_move_insn (dest
, x
);
4418 /* Move the partial arguments into the registers and any overlapping
4419 values that we moved into the pseudos in tmp_regs. */
4420 if (partial
> 0 && reg
!= 0)
4422 /* Handle calls that pass values in multiple non-contiguous locations.
4423 The Irix 6 ABI has examples of this. */
4424 if (GET_CODE (reg
) == PARALLEL
)
4425 emit_group_load (reg
, x
, type
, -1);
4428 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4429 move_block_to_reg (REGNO (reg
), x
, nregs
- overlapping
, mode
);
4431 for (int i
= 0; i
< overlapping
; i
++)
4432 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
)
4433 + nregs
- overlapping
+ i
),
4439 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4440 anti_adjust_stack (GEN_INT (extra
));
4442 if (alignment_pad
&& args_addr
== 0)
4443 anti_adjust_stack (alignment_pad
);
4448 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4452 get_subtarget (rtx x
)
4456 /* Only registers can be subtargets. */
4458 /* Don't use hard regs to avoid extending their life. */
4459 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4463 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4464 FIELD is a bitfield. Returns true if the optimization was successful,
4465 and there's nothing else to do. */
4468 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4469 unsigned HOST_WIDE_INT bitpos
,
4470 unsigned HOST_WIDE_INT bitregion_start
,
4471 unsigned HOST_WIDE_INT bitregion_end
,
4472 machine_mode mode1
, rtx str_rtx
,
4475 machine_mode str_mode
= GET_MODE (str_rtx
);
4476 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4481 enum tree_code code
;
4483 if (mode1
!= VOIDmode
4484 || bitsize
>= BITS_PER_WORD
4485 || str_bitsize
> BITS_PER_WORD
4486 || TREE_SIDE_EFFECTS (to
)
4487 || TREE_THIS_VOLATILE (to
))
4491 if (TREE_CODE (src
) != SSA_NAME
)
4493 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4496 srcstmt
= get_gimple_for_ssa_name (src
);
4498 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4501 code
= gimple_assign_rhs_code (srcstmt
);
4503 op0
= gimple_assign_rhs1 (srcstmt
);
4505 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4506 to find its initialization. Hopefully the initialization will
4507 be from a bitfield load. */
4508 if (TREE_CODE (op0
) == SSA_NAME
)
4510 gimple
*op0stmt
= get_gimple_for_ssa_name (op0
);
4512 /* We want to eventually have OP0 be the same as TO, which
4513 should be a bitfield. */
4515 || !is_gimple_assign (op0stmt
)
4516 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4518 op0
= gimple_assign_rhs1 (op0stmt
);
4521 op1
= gimple_assign_rhs2 (srcstmt
);
4523 if (!operand_equal_p (to
, op0
, 0))
4526 if (MEM_P (str_rtx
))
4528 unsigned HOST_WIDE_INT offset1
;
4530 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4531 str_mode
= word_mode
;
4532 str_mode
= get_best_mode (bitsize
, bitpos
,
4533 bitregion_start
, bitregion_end
,
4534 MEM_ALIGN (str_rtx
), str_mode
, 0);
4535 if (str_mode
== VOIDmode
)
4537 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4540 bitpos
%= str_bitsize
;
4541 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4542 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4544 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4547 /* If the bit field covers the whole REG/MEM, store_field
4548 will likely generate better code. */
4549 if (bitsize
>= str_bitsize
)
4552 /* We can't handle fields split across multiple entities. */
4553 if (bitpos
+ bitsize
> str_bitsize
)
4556 if (BYTES_BIG_ENDIAN
)
4557 bitpos
= str_bitsize
- bitpos
- bitsize
;
4563 /* For now, just optimize the case of the topmost bitfield
4564 where we don't need to do any masking and also
4565 1 bit bitfields where xor can be used.
4566 We might win by one instruction for the other bitfields
4567 too if insv/extv instructions aren't used, so that
4568 can be added later. */
4569 if (bitpos
+ bitsize
!= str_bitsize
4570 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4573 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4574 value
= convert_modes (str_mode
,
4575 TYPE_MODE (TREE_TYPE (op1
)), value
,
4576 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4578 /* We may be accessing data outside the field, which means
4579 we can alias adjacent data. */
4580 if (MEM_P (str_rtx
))
4582 str_rtx
= shallow_copy_rtx (str_rtx
);
4583 set_mem_alias_set (str_rtx
, 0);
4584 set_mem_expr (str_rtx
, 0);
4587 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4588 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4590 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4593 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4594 result
= expand_binop (str_mode
, binop
, str_rtx
,
4595 value
, str_rtx
, 1, OPTAB_WIDEN
);
4596 if (result
!= str_rtx
)
4597 emit_move_insn (str_rtx
, result
);
4602 if (TREE_CODE (op1
) != INTEGER_CST
)
4604 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4605 value
= convert_modes (str_mode
,
4606 TYPE_MODE (TREE_TYPE (op1
)), value
,
4607 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4609 /* We may be accessing data outside the field, which means
4610 we can alias adjacent data. */
4611 if (MEM_P (str_rtx
))
4613 str_rtx
= shallow_copy_rtx (str_rtx
);
4614 set_mem_alias_set (str_rtx
, 0);
4615 set_mem_expr (str_rtx
, 0);
4618 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4619 if (bitpos
+ bitsize
!= str_bitsize
)
4621 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4623 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4625 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4626 result
= expand_binop (str_mode
, binop
, str_rtx
,
4627 value
, str_rtx
, 1, OPTAB_WIDEN
);
4628 if (result
!= str_rtx
)
4629 emit_move_insn (str_rtx
, result
);
4639 /* In the C++ memory model, consecutive bit fields in a structure are
4640 considered one memory location.
4642 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4643 returns the bit range of consecutive bits in which this COMPONENT_REF
4644 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4645 and *OFFSET may be adjusted in the process.
4647 If the access does not need to be restricted, 0 is returned in both
4648 *BITSTART and *BITEND. */
4651 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4652 unsigned HOST_WIDE_INT
*bitend
,
4654 HOST_WIDE_INT
*bitpos
,
4657 HOST_WIDE_INT bitoffset
;
4660 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4662 field
= TREE_OPERAND (exp
, 1);
4663 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4664 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4665 need to limit the range we can access. */
4668 *bitstart
= *bitend
= 0;
4672 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4673 part of a larger bit field, then the representative does not serve any
4674 useful purpose. This can occur in Ada. */
4675 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4678 HOST_WIDE_INT rbitsize
, rbitpos
;
4682 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4683 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4684 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4686 *bitstart
= *bitend
= 0;
4691 /* Compute the adjustment to bitpos from the offset of the field
4692 relative to the representative. DECL_FIELD_OFFSET of field and
4693 repr are the same by construction if they are not constants,
4694 see finish_bitfield_layout. */
4695 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4696 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4697 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4698 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4701 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4702 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4704 /* If the adjustment is larger than bitpos, we would have a negative bit
4705 position for the lower bound and this may wreak havoc later. Adjust
4706 offset and bitpos to make the lower bound non-negative in that case. */
4707 if (bitoffset
> *bitpos
)
4709 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4710 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4713 if (*offset
== NULL_TREE
)
4714 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4717 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4721 *bitstart
= *bitpos
- bitoffset
;
4723 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4726 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4727 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4728 DECL_RTL was not set yet, return NORTL. */
4731 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4733 if (TREE_CODE (addr
) != ADDR_EXPR
)
4736 tree base
= TREE_OPERAND (addr
, 0);
4739 || TREE_ADDRESSABLE (base
)
4740 || DECL_MODE (base
) == BLKmode
)
4743 if (!DECL_RTL_SET_P (base
))
4746 return (!MEM_P (DECL_RTL (base
)));
4749 /* Returns true if the MEM_REF REF refers to an object that does not
4750 reside in memory and has non-BLKmode. */
4753 mem_ref_refers_to_non_mem_p (tree ref
)
4755 tree base
= TREE_OPERAND (ref
, 0);
4756 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4759 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4760 is true, try generating a nontemporal store. */
4763 expand_assignment (tree to
, tree from
, bool nontemporal
)
4769 enum insn_code icode
;
4771 /* Don't crash if the lhs of the assignment was erroneous. */
4772 if (TREE_CODE (to
) == ERROR_MARK
)
4774 expand_normal (from
);
4778 /* Optimize away no-op moves without side-effects. */
4779 if (operand_equal_p (to
, from
, 0))
4782 /* Handle misaligned stores. */
4783 mode
= TYPE_MODE (TREE_TYPE (to
));
4784 if ((TREE_CODE (to
) == MEM_REF
4785 || TREE_CODE (to
) == TARGET_MEM_REF
)
4787 && !mem_ref_refers_to_non_mem_p (to
)
4788 && ((align
= get_object_alignment (to
))
4789 < GET_MODE_ALIGNMENT (mode
))
4790 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4791 != CODE_FOR_nothing
)
4792 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4796 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4797 reg
= force_not_mem (reg
);
4798 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4800 if (icode
!= CODE_FOR_nothing
)
4802 struct expand_operand ops
[2];
4804 create_fixed_operand (&ops
[0], mem
);
4805 create_input_operand (&ops
[1], reg
, mode
);
4806 /* The movmisalign<mode> pattern cannot fail, else the assignment
4807 would silently be omitted. */
4808 expand_insn (icode
, 2, ops
);
4811 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
);
4815 /* Assignment of a structure component needs special treatment
4816 if the structure component's rtx is not simply a MEM.
4817 Assignment of an array element at a constant index, and assignment of
4818 an array element in an unaligned packed structure field, has the same
4819 problem. Same for (partially) storing into a non-memory object. */
4820 if (handled_component_p (to
)
4821 || (TREE_CODE (to
) == MEM_REF
4822 && mem_ref_refers_to_non_mem_p (to
))
4823 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4826 HOST_WIDE_INT bitsize
, bitpos
;
4827 unsigned HOST_WIDE_INT bitregion_start
= 0;
4828 unsigned HOST_WIDE_INT bitregion_end
= 0;
4835 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4836 &unsignedp
, &volatilep
, true);
4838 /* Make sure bitpos is not negative, it can wreak havoc later. */
4841 gcc_assert (offset
== NULL_TREE
);
4842 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4843 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4844 bitpos
&= BITS_PER_UNIT
- 1;
4847 if (TREE_CODE (to
) == COMPONENT_REF
4848 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4849 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4850 /* The C++ memory model naturally applies to byte-aligned fields.
4851 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
4852 BITSIZE are not byte-aligned, there is no need to limit the range
4853 we can access. This can occur with packed structures in Ada. */
4854 else if (bitsize
> 0
4855 && bitsize
% BITS_PER_UNIT
== 0
4856 && bitpos
% BITS_PER_UNIT
== 0)
4858 bitregion_start
= bitpos
;
4859 bitregion_end
= bitpos
+ bitsize
- 1;
4862 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4864 /* If the field has a mode, we want to access it in the
4865 field's mode, not the computed mode.
4866 If a MEM has VOIDmode (external with incomplete type),
4867 use BLKmode for it instead. */
4870 if (mode1
!= VOIDmode
)
4871 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4872 else if (GET_MODE (to_rtx
) == VOIDmode
)
4873 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4878 machine_mode address_mode
;
4881 if (!MEM_P (to_rtx
))
4883 /* We can get constant negative offsets into arrays with broken
4884 user code. Translate this to a trap instead of ICEing. */
4885 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4886 expand_builtin_trap ();
4887 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4890 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4891 address_mode
= get_address_mode (to_rtx
);
4892 if (GET_MODE (offset_rtx
) != address_mode
)
4894 /* We cannot be sure that the RTL in offset_rtx is valid outside
4895 of a memory address context, so force it into a register
4896 before attempting to convert it to the desired mode. */
4897 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
4898 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4901 /* If we have an expression in OFFSET_RTX and a non-zero
4902 byte offset in BITPOS, adding the byte offset before the
4903 OFFSET_RTX results in better intermediate code, which makes
4904 later rtl optimization passes perform better.
4906 We prefer intermediate code like this:
4908 r124:DI=r123:DI+0x18
4913 r124:DI=r123:DI+0x10
4914 [r124:DI+0x8]=r121:DI
4916 This is only done for aligned data values, as these can
4917 be expected to result in single move instructions. */
4918 if (mode1
!= VOIDmode
4921 && (bitpos
% bitsize
) == 0
4922 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4923 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
4925 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4926 bitregion_start
= 0;
4927 if (bitregion_end
>= (unsigned HOST_WIDE_INT
) bitpos
)
4928 bitregion_end
-= bitpos
;
4932 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4933 highest_pow2_factor_for_target (to
,
4937 /* No action is needed if the target is not a memory and the field
4938 lies completely outside that target. This can occur if the source
4939 code contains an out-of-bounds access to a small array. */
4941 && GET_MODE (to_rtx
) != BLKmode
4942 && (unsigned HOST_WIDE_INT
) bitpos
4943 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4945 expand_normal (from
);
4948 /* Handle expand_expr of a complex value returning a CONCAT. */
4949 else if (GET_CODE (to_rtx
) == CONCAT
)
4951 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4952 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4954 && bitsize
== mode_bitsize
)
4955 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4956 else if (bitsize
== mode_bitsize
/ 2
4957 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4958 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4960 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4961 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4962 bitregion_start
, bitregion_end
,
4964 get_alias_set (to
), nontemporal
);
4965 else if (bitpos
>= mode_bitsize
/ 2)
4966 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4967 bitpos
- mode_bitsize
/ 2,
4968 bitregion_start
, bitregion_end
,
4970 get_alias_set (to
), nontemporal
);
4971 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4974 result
= expand_normal (from
);
4975 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4976 TYPE_MODE (TREE_TYPE (from
)), 0);
4977 emit_move_insn (XEXP (to_rtx
, 0),
4978 read_complex_part (from_rtx
, false));
4979 emit_move_insn (XEXP (to_rtx
, 1),
4980 read_complex_part (from_rtx
, true));
4984 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4985 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4986 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4987 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4988 result
= store_field (temp
, bitsize
, bitpos
,
4989 bitregion_start
, bitregion_end
,
4991 get_alias_set (to
), nontemporal
);
4992 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4993 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
5000 /* If the field is at offset zero, we could have been given the
5001 DECL_RTX of the parent struct. Don't munge it. */
5002 to_rtx
= shallow_copy_rtx (to_rtx
);
5003 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
5005 MEM_VOLATILE_P (to_rtx
) = 1;
5008 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
5009 bitregion_start
, bitregion_end
,
5014 result
= store_field (to_rtx
, bitsize
, bitpos
,
5015 bitregion_start
, bitregion_end
,
5017 get_alias_set (to
), nontemporal
);
5021 preserve_temp_slots (result
);
5026 /* If the rhs is a function call and its value is not an aggregate,
5027 call the function before we start to compute the lhs.
5028 This is needed for correct code for cases such as
5029 val = setjmp (buf) on machines where reference to val
5030 requires loading up part of an address in a separate insn.
5032 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
5033 since it might be a promoted variable where the zero- or sign- extension
5034 needs to be done. Handling this in the normal way is safe because no
5035 computation is done before the call. The same is true for SSA names. */
5036 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
5037 && COMPLETE_TYPE_P (TREE_TYPE (from
))
5038 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
5039 && ! (((TREE_CODE (to
) == VAR_DECL
5040 || TREE_CODE (to
) == PARM_DECL
5041 || TREE_CODE (to
) == RESULT_DECL
)
5042 && REG_P (DECL_RTL (to
)))
5043 || TREE_CODE (to
) == SSA_NAME
))
5049 value
= expand_normal (from
);
5051 /* Split value and bounds to store them separately. */
5052 chkp_split_slot (value
, &value
, &bounds
);
5055 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5057 /* Handle calls that return values in multiple non-contiguous locations.
5058 The Irix 6 ABI has examples of this. */
5059 if (GET_CODE (to_rtx
) == PARALLEL
)
5061 if (GET_CODE (value
) == PARALLEL
)
5062 emit_group_move (to_rtx
, value
);
5064 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5065 int_size_in_bytes (TREE_TYPE (from
)));
5067 else if (GET_CODE (value
) == PARALLEL
)
5068 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5069 int_size_in_bytes (TREE_TYPE (from
)));
5070 else if (GET_MODE (to_rtx
) == BLKmode
)
5072 /* Handle calls that return BLKmode values in registers. */
5074 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5076 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5080 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5081 value
= convert_memory_address_addr_space
5082 (GET_MODE (to_rtx
), value
,
5083 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5085 emit_move_insn (to_rtx
, value
);
5088 /* Store bounds if required. */
5090 && (BOUNDED_P (to
) || chkp_type_has_pointer (TREE_TYPE (to
))))
5092 gcc_assert (MEM_P (to_rtx
));
5093 chkp_emit_bounds_store (bounds
, value
, to_rtx
);
5096 preserve_temp_slots (to_rtx
);
5101 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5102 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5104 /* Don't move directly into a return register. */
5105 if (TREE_CODE (to
) == RESULT_DECL
5106 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5112 /* If the source is itself a return value, it still is in a pseudo at
5113 this point so we can move it back to the return register directly. */
5115 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5116 && TREE_CODE (from
) != CALL_EXPR
)
5117 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5119 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5121 /* Handle calls that return values in multiple non-contiguous locations.
5122 The Irix 6 ABI has examples of this. */
5123 if (GET_CODE (to_rtx
) == PARALLEL
)
5125 if (GET_CODE (temp
) == PARALLEL
)
5126 emit_group_move (to_rtx
, temp
);
5128 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5129 int_size_in_bytes (TREE_TYPE (from
)));
5132 emit_move_insn (to_rtx
, temp
);
5134 preserve_temp_slots (to_rtx
);
5139 /* In case we are returning the contents of an object which overlaps
5140 the place the value is being stored, use a safe function when copying
5141 a value through a pointer into a structure value return block. */
5142 if (TREE_CODE (to
) == RESULT_DECL
5143 && TREE_CODE (from
) == INDIRECT_REF
5144 && ADDR_SPACE_GENERIC_P
5145 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5146 && refs_may_alias_p (to
, from
)
5147 && cfun
->returns_struct
5148 && !cfun
->returns_pcc_struct
)
5153 size
= expr_size (from
);
5154 from_rtx
= expand_normal (from
);
5156 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5157 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5158 XEXP (from_rtx
, 0), Pmode
,
5159 convert_to_mode (TYPE_MODE (sizetype
),
5160 size
, TYPE_UNSIGNED (sizetype
)),
5161 TYPE_MODE (sizetype
));
5163 preserve_temp_slots (to_rtx
);
5168 /* Compute FROM and store the value in the rtx we got. */
5171 result
= store_expr_with_bounds (from
, to_rtx
, 0, nontemporal
, to
);
5172 preserve_temp_slots (result
);
5177 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5178 succeeded, false otherwise. */
5181 emit_storent_insn (rtx to
, rtx from
)
5183 struct expand_operand ops
[2];
5184 machine_mode mode
= GET_MODE (to
);
5185 enum insn_code code
= optab_handler (storent_optab
, mode
);
5187 if (code
== CODE_FOR_nothing
)
5190 create_fixed_operand (&ops
[0], to
);
5191 create_input_operand (&ops
[1], from
, mode
);
5192 return maybe_expand_insn (code
, 2, ops
);
5195 /* Generate code for computing expression EXP,
5196 and storing the value into TARGET.
5198 If the mode is BLKmode then we may return TARGET itself.
5199 It turns out that in BLKmode it doesn't cause a problem.
5200 because C has no operators that could combine two different
5201 assignments into the same BLKmode object with different values
5202 with no sequence point. Will other languages need this to
5205 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5206 stack, and block moves may need to be treated specially.
5208 If NONTEMPORAL is true, try using a nontemporal store instruction.
5210 If BTARGET is not NULL then computed bounds of EXP are
5211 associated with BTARGET. */
5214 store_expr_with_bounds (tree exp
, rtx target
, int call_param_p
,
5215 bool nontemporal
, tree btarget
)
5218 rtx alt_rtl
= NULL_RTX
;
5219 location_t loc
= curr_insn_location ();
5221 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5223 /* C++ can generate ?: expressions with a throw expression in one
5224 branch and an rvalue in the other. Here, we resolve attempts to
5225 store the throw expression's nonexistent result. */
5226 gcc_assert (!call_param_p
);
5227 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5230 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5232 /* Perform first part of compound expression, then assign from second
5234 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5235 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5236 return store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
,
5237 call_param_p
, nontemporal
, btarget
);
5239 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5241 /* For conditional expression, get safe form of the target. Then
5242 test the condition, doing the appropriate assignment on either
5243 side. This avoids the creation of unnecessary temporaries.
5244 For non-BLKmode, it is more efficient not to do this. */
5246 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
5248 do_pending_stack_adjust ();
5250 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5251 store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5252 nontemporal
, btarget
);
5253 emit_jump_insn (targetm
.gen_jump (lab2
));
5256 store_expr_with_bounds (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5257 nontemporal
, btarget
);
5263 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5264 /* If this is a scalar in a register that is stored in a wider mode
5265 than the declared mode, compute the result into its declared mode
5266 and then convert to the wider mode. Our value is the computed
5269 rtx inner_target
= 0;
5271 /* We can do the conversion inside EXP, which will often result
5272 in some optimizations. Do the conversion in two steps: first
5273 change the signedness, if needed, then the extend. But don't
5274 do this if the type of EXP is a subtype of something else
5275 since then the conversion might involve more than just
5276 converting modes. */
5277 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5278 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5279 && GET_MODE_PRECISION (GET_MODE (target
))
5280 == TYPE_PRECISION (TREE_TYPE (exp
)))
5282 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
5283 TYPE_UNSIGNED (TREE_TYPE (exp
))))
5285 /* Some types, e.g. Fortran's logical*4, won't have a signed
5286 version, so use the mode instead. */
5288 = (signed_or_unsigned_type_for
5289 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
5291 ntype
= lang_hooks
.types
.type_for_mode
5292 (TYPE_MODE (TREE_TYPE (exp
)),
5293 SUBREG_PROMOTED_SIGN (target
));
5295 exp
= fold_convert_loc (loc
, ntype
, exp
);
5298 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5299 (GET_MODE (SUBREG_REG (target
)),
5300 SUBREG_PROMOTED_SIGN (target
)),
5303 inner_target
= SUBREG_REG (target
);
5306 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5307 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5309 /* Handle bounds returned by call. */
5310 if (TREE_CODE (exp
) == CALL_EXPR
)
5313 chkp_split_slot (temp
, &temp
, &bounds
);
5314 if (bounds
&& btarget
)
5316 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5317 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5318 chkp_set_rtl_bounds (btarget
, tmp
);
5322 /* If TEMP is a VOIDmode constant, use convert_modes to make
5323 sure that we properly convert it. */
5324 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5326 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5327 temp
, SUBREG_PROMOTED_SIGN (target
));
5328 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5329 GET_MODE (target
), temp
,
5330 SUBREG_PROMOTED_SIGN (target
));
5333 convert_move (SUBREG_REG (target
), temp
,
5334 SUBREG_PROMOTED_SIGN (target
));
5338 else if ((TREE_CODE (exp
) == STRING_CST
5339 || (TREE_CODE (exp
) == MEM_REF
5340 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5341 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5343 && integer_zerop (TREE_OPERAND (exp
, 1))))
5344 && !nontemporal
&& !call_param_p
5347 /* Optimize initialization of an array with a STRING_CST. */
5348 HOST_WIDE_INT exp_len
, str_copy_len
;
5350 tree str
= TREE_CODE (exp
) == STRING_CST
5351 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5353 exp_len
= int_expr_size (exp
);
5357 if (TREE_STRING_LENGTH (str
) <= 0)
5360 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5361 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5364 str_copy_len
= TREE_STRING_LENGTH (str
);
5365 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5366 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5368 str_copy_len
+= STORE_MAX_PIECES
- 1;
5369 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5371 str_copy_len
= MIN (str_copy_len
, exp_len
);
5372 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5373 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5374 MEM_ALIGN (target
), false))
5379 dest_mem
= store_by_pieces (dest_mem
,
5380 str_copy_len
, builtin_strncpy_read_str
,
5382 TREE_STRING_POINTER (str
)),
5383 MEM_ALIGN (target
), false,
5384 exp_len
> str_copy_len
? 1 : 0);
5385 if (exp_len
> str_copy_len
)
5386 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5387 GEN_INT (exp_len
- str_copy_len
),
5396 /* If we want to use a nontemporal store, force the value to
5398 tmp_target
= nontemporal
? NULL_RTX
: target
;
5399 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5401 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5404 /* Handle bounds returned by call. */
5405 if (TREE_CODE (exp
) == CALL_EXPR
)
5408 chkp_split_slot (temp
, &temp
, &bounds
);
5409 if (bounds
&& btarget
)
5411 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5412 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5413 chkp_set_rtl_bounds (btarget
, tmp
);
5418 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5419 the same as that of TARGET, adjust the constant. This is needed, for
5420 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5421 only a word-sized value. */
5422 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5423 && TREE_CODE (exp
) != ERROR_MARK
5424 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5425 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5426 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5428 /* If value was not generated in the target, store it there.
5429 Convert the value to TARGET's type first if necessary and emit the
5430 pending incrementations that have been queued when expanding EXP.
5431 Note that we cannot emit the whole queue blindly because this will
5432 effectively disable the POST_INC optimization later.
5434 If TEMP and TARGET compare equal according to rtx_equal_p, but
5435 one or both of them are volatile memory refs, we have to distinguish
5437 - expand_expr has used TARGET. In this case, we must not generate
5438 another copy. This can be detected by TARGET being equal according
5440 - expand_expr has not used TARGET - that means that the source just
5441 happens to have the same RTX form. Since temp will have been created
5442 by expand_expr, it will compare unequal according to == .
5443 We must generate a copy in this case, to reach the correct number
5444 of volatile memory references. */
5446 if ((! rtx_equal_p (temp
, target
)
5447 || (temp
!= target
&& (side_effects_p (temp
)
5448 || side_effects_p (target
))))
5449 && TREE_CODE (exp
) != ERROR_MARK
5450 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5451 but TARGET is not valid memory reference, TEMP will differ
5452 from TARGET although it is really the same location. */
5454 && rtx_equal_p (alt_rtl
, target
)
5455 && !side_effects_p (alt_rtl
)
5456 && !side_effects_p (target
))
5457 /* If there's nothing to copy, don't bother. Don't call
5458 expr_size unless necessary, because some front-ends (C++)
5459 expr_size-hook must not be given objects that are not
5460 supposed to be bit-copied or bit-initialized. */
5461 && expr_size (exp
) != const0_rtx
)
5463 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5465 if (GET_MODE (target
) == BLKmode
)
5467 /* Handle calls that return BLKmode values in registers. */
5468 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5469 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5471 store_bit_field (target
,
5472 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5473 0, 0, 0, GET_MODE (temp
), temp
);
5476 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5479 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5481 /* Handle copying a string constant into an array. The string
5482 constant may be shorter than the array. So copy just the string's
5483 actual length, and clear the rest. First get the size of the data
5484 type of the string, which is actually the size of the target. */
5485 rtx size
= expr_size (exp
);
5487 if (CONST_INT_P (size
)
5488 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5489 emit_block_move (target
, temp
, size
,
5491 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5494 machine_mode pointer_mode
5495 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5496 machine_mode address_mode
= get_address_mode (target
);
5498 /* Compute the size of the data to copy from the string. */
5500 = size_binop_loc (loc
, MIN_EXPR
,
5501 make_tree (sizetype
, size
),
5502 size_int (TREE_STRING_LENGTH (exp
)));
5504 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5506 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5507 rtx_code_label
*label
= 0;
5509 /* Copy that much. */
5510 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5511 TYPE_UNSIGNED (sizetype
));
5512 emit_block_move (target
, temp
, copy_size_rtx
,
5514 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5516 /* Figure out how much is left in TARGET that we have to clear.
5517 Do all calculations in pointer_mode. */
5518 if (CONST_INT_P (copy_size_rtx
))
5520 size
= plus_constant (address_mode
, size
,
5521 -INTVAL (copy_size_rtx
));
5522 target
= adjust_address (target
, BLKmode
,
5523 INTVAL (copy_size_rtx
));
5527 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5528 copy_size_rtx
, NULL_RTX
, 0,
5531 if (GET_MODE (copy_size_rtx
) != address_mode
)
5532 copy_size_rtx
= convert_to_mode (address_mode
,
5534 TYPE_UNSIGNED (sizetype
));
5536 target
= offset_address (target
, copy_size_rtx
,
5537 highest_pow2_factor (copy_size
));
5538 label
= gen_label_rtx ();
5539 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5540 GET_MODE (size
), 0, label
);
5543 if (size
!= const0_rtx
)
5544 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5550 /* Handle calls that return values in multiple non-contiguous locations.
5551 The Irix 6 ABI has examples of this. */
5552 else if (GET_CODE (target
) == PARALLEL
)
5554 if (GET_CODE (temp
) == PARALLEL
)
5555 emit_group_move (target
, temp
);
5557 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5558 int_size_in_bytes (TREE_TYPE (exp
)));
5560 else if (GET_CODE (temp
) == PARALLEL
)
5561 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5562 int_size_in_bytes (TREE_TYPE (exp
)));
5563 else if (GET_MODE (temp
) == BLKmode
)
5564 emit_block_move (target
, temp
, expr_size (exp
),
5566 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5567 /* If we emit a nontemporal store, there is nothing else to do. */
5568 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5572 temp
= force_operand (temp
, target
);
5574 emit_move_insn (target
, temp
);
5581 /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
5583 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5585 return store_expr_with_bounds (exp
, target
, call_param_p
, nontemporal
, NULL
);
5588 /* Return true if field F of structure TYPE is a flexible array. */
5591 flexible_array_member_p (const_tree f
, const_tree type
)
5596 return (DECL_CHAIN (f
) == NULL
5597 && TREE_CODE (tf
) == ARRAY_TYPE
5599 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5600 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5601 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5602 && int_size_in_bytes (type
) >= 0);
5605 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5606 must have in order for it to completely initialize a value of type TYPE.
5607 Return -1 if the number isn't known.
5609 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5611 static HOST_WIDE_INT
5612 count_type_elements (const_tree type
, bool for_ctor_p
)
5614 switch (TREE_CODE (type
))
5620 nelts
= array_type_nelts (type
);
5621 if (nelts
&& tree_fits_uhwi_p (nelts
))
5623 unsigned HOST_WIDE_INT n
;
5625 n
= tree_to_uhwi (nelts
) + 1;
5626 if (n
== 0 || for_ctor_p
)
5629 return n
* count_type_elements (TREE_TYPE (type
), false);
5631 return for_ctor_p
? -1 : 1;
5636 unsigned HOST_WIDE_INT n
;
5640 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5641 if (TREE_CODE (f
) == FIELD_DECL
)
5644 n
+= count_type_elements (TREE_TYPE (f
), false);
5645 else if (!flexible_array_member_p (f
, type
))
5646 /* Don't count flexible arrays, which are not supposed
5647 to be initialized. */
5655 case QUAL_UNION_TYPE
:
5660 gcc_assert (!for_ctor_p
);
5661 /* Estimate the number of scalars in each field and pick the
5662 maximum. Other estimates would do instead; the idea is simply
5663 to make sure that the estimate is not sensitive to the ordering
5666 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5667 if (TREE_CODE (f
) == FIELD_DECL
)
5669 m
= count_type_elements (TREE_TYPE (f
), false);
5670 /* If the field doesn't span the whole union, add an extra
5671 scalar for the rest. */
5672 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5673 TYPE_SIZE (type
)) != 1)
5685 return TYPE_VECTOR_SUBPARTS (type
);
5689 case FIXED_POINT_TYPE
:
5694 case REFERENCE_TYPE
:
5710 /* Helper for categorize_ctor_elements. Identical interface. */
5713 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5714 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5716 unsigned HOST_WIDE_INT idx
;
5717 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5718 tree value
, purpose
, elt_type
;
5720 /* Whether CTOR is a valid constant initializer, in accordance with what
5721 initializer_constant_valid_p does. If inferred from the constructor
5722 elements, true until proven otherwise. */
5723 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5724 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5729 elt_type
= NULL_TREE
;
5731 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5733 HOST_WIDE_INT mult
= 1;
5735 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5737 tree lo_index
= TREE_OPERAND (purpose
, 0);
5738 tree hi_index
= TREE_OPERAND (purpose
, 1);
5740 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5741 mult
= (tree_to_uhwi (hi_index
)
5742 - tree_to_uhwi (lo_index
) + 1);
5745 elt_type
= TREE_TYPE (value
);
5747 switch (TREE_CODE (value
))
5751 HOST_WIDE_INT nz
= 0, ic
= 0;
5753 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5756 nz_elts
+= mult
* nz
;
5757 init_elts
+= mult
* ic
;
5759 if (const_from_elts_p
&& const_p
)
5760 const_p
= const_elt_p
;
5767 if (!initializer_zerop (value
))
5773 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5774 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5778 if (!initializer_zerop (TREE_REALPART (value
)))
5780 if (!initializer_zerop (TREE_IMAGPART (value
)))
5788 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5790 tree v
= VECTOR_CST_ELT (value
, i
);
5791 if (!initializer_zerop (v
))
5800 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5801 nz_elts
+= mult
* tc
;
5802 init_elts
+= mult
* tc
;
5804 if (const_from_elts_p
&& const_p
)
5805 const_p
= initializer_constant_valid_p (value
, elt_type
)
5812 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5813 num_fields
, elt_type
))
5814 *p_complete
= false;
5816 *p_nz_elts
+= nz_elts
;
5817 *p_init_elts
+= init_elts
;
5822 /* Examine CTOR to discover:
5823 * how many scalar fields are set to nonzero values,
5824 and place it in *P_NZ_ELTS;
5825 * how many scalar fields in total are in CTOR,
5826 and place it in *P_ELT_COUNT.
5827 * whether the constructor is complete -- in the sense that every
5828 meaningful byte is explicitly given a value --
5829 and place it in *P_COMPLETE.
5831 Return whether or not CTOR is a valid static constant initializer, the same
5832 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5835 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5836 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5842 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5845 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5846 of which had type LAST_TYPE. Each element was itself a complete
5847 initializer, in the sense that every meaningful byte was explicitly
5848 given a value. Return true if the same is true for the constructor
5852 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5853 const_tree last_type
)
5855 if (TREE_CODE (type
) == UNION_TYPE
5856 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5861 gcc_assert (num_elts
== 1 && last_type
);
5863 /* ??? We could look at each element of the union, and find the
5864 largest element. Which would avoid comparing the size of the
5865 initialized element against any tail padding in the union.
5866 Doesn't seem worth the effort... */
5867 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5870 return count_type_elements (type
, true) == num_elts
;
5873 /* Return 1 if EXP contains mostly (3/4) zeros. */
5876 mostly_zeros_p (const_tree exp
)
5878 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5880 HOST_WIDE_INT nz_elts
, init_elts
;
5883 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5884 return !complete_p
|| nz_elts
< init_elts
/ 4;
5887 return initializer_zerop (exp
);
5890 /* Return 1 if EXP contains all zeros. */
5893 all_zeros_p (const_tree exp
)
5895 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5897 HOST_WIDE_INT nz_elts
, init_elts
;
5900 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5901 return nz_elts
== 0;
5904 return initializer_zerop (exp
);
5907 /* Helper function for store_constructor.
5908 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5909 CLEARED is as for store_constructor.
5910 ALIAS_SET is the alias set to use for any stores.
5912 This provides a recursive shortcut back to store_constructor when it isn't
5913 necessary to go through store_field. This is so that we can pass through
5914 the cleared field to let store_constructor know that we may not have to
5915 clear a substructure if the outer structure has already been cleared. */
5918 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5919 HOST_WIDE_INT bitpos
, machine_mode mode
,
5920 tree exp
, int cleared
, alias_set_type alias_set
)
5922 if (TREE_CODE (exp
) == CONSTRUCTOR
5923 /* We can only call store_constructor recursively if the size and
5924 bit position are on a byte boundary. */
5925 && bitpos
% BITS_PER_UNIT
== 0
5926 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5927 /* If we have a nonzero bitpos for a register target, then we just
5928 let store_field do the bitfield handling. This is unlikely to
5929 generate unnecessary clear instructions anyways. */
5930 && (bitpos
== 0 || MEM_P (target
)))
5934 = adjust_address (target
,
5935 GET_MODE (target
) == BLKmode
5937 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5938 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5941 /* Update the alias set, if required. */
5942 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5943 && MEM_ALIAS_SET (target
) != 0)
5945 target
= copy_rtx (target
);
5946 set_mem_alias_set (target
, alias_set
);
5949 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5952 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5956 /* Returns the number of FIELD_DECLs in TYPE. */
5959 fields_length (const_tree type
)
5961 tree t
= TYPE_FIELDS (type
);
5964 for (; t
; t
= DECL_CHAIN (t
))
5965 if (TREE_CODE (t
) == FIELD_DECL
)
5972 /* Store the value of constructor EXP into the rtx TARGET.
5973 TARGET is either a REG or a MEM; we know it cannot conflict, since
5974 safe_from_p has been called.
5975 CLEARED is true if TARGET is known to have been zero'd.
5976 SIZE is the number of bytes of TARGET we are allowed to modify: this
5977 may not be the same as the size of EXP if we are assigning to a field
5978 which has been packed to exclude padding bits. */
5981 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5983 tree type
= TREE_TYPE (exp
);
5984 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5986 switch (TREE_CODE (type
))
5990 case QUAL_UNION_TYPE
:
5992 unsigned HOST_WIDE_INT idx
;
5995 /* If size is zero or the target is already cleared, do nothing. */
5996 if (size
== 0 || cleared
)
5998 /* We either clear the aggregate or indicate the value is dead. */
5999 else if ((TREE_CODE (type
) == UNION_TYPE
6000 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
6001 && ! CONSTRUCTOR_ELTS (exp
))
6002 /* If the constructor is empty, clear the union. */
6004 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
6008 /* If we are building a static constructor into a register,
6009 set the initial value as zero so we can fold the value into
6010 a constant. But if more than one register is involved,
6011 this probably loses. */
6012 else if (REG_P (target
) && TREE_STATIC (exp
)
6013 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
6015 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6019 /* If the constructor has fewer fields than the structure or
6020 if we are initializing the structure to mostly zeros, clear
6021 the whole structure first. Don't do this if TARGET is a
6022 register whose mode size isn't equal to SIZE since
6023 clear_storage can't handle this case. */
6025 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
6026 != fields_length (type
))
6027 || mostly_zeros_p (exp
))
6029 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
6032 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6036 if (REG_P (target
) && !cleared
)
6037 emit_clobber (target
);
6039 /* Store each element of the constructor into the
6040 corresponding field of TARGET. */
6041 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
6044 HOST_WIDE_INT bitsize
;
6045 HOST_WIDE_INT bitpos
= 0;
6047 rtx to_rtx
= target
;
6049 /* Just ignore missing fields. We cleared the whole
6050 structure, above, if any fields are missing. */
6054 if (cleared
&& initializer_zerop (value
))
6057 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
6058 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
6062 mode
= DECL_MODE (field
);
6063 if (DECL_BIT_FIELD (field
))
6066 offset
= DECL_FIELD_OFFSET (field
);
6067 if (tree_fits_shwi_p (offset
)
6068 && tree_fits_shwi_p (bit_position (field
)))
6070 bitpos
= int_bit_position (field
);
6074 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
6078 machine_mode address_mode
;
6082 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
6083 make_tree (TREE_TYPE (exp
),
6086 offset_rtx
= expand_normal (offset
);
6087 gcc_assert (MEM_P (to_rtx
));
6089 address_mode
= get_address_mode (to_rtx
);
6090 if (GET_MODE (offset_rtx
) != address_mode
)
6091 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6093 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6094 highest_pow2_factor (offset
));
6097 /* If this initializes a field that is smaller than a
6098 word, at the start of a word, try to widen it to a full
6099 word. This special case allows us to output C++ member
6100 function initializations in a form that the optimizers
6102 if (WORD_REGISTER_OPERATIONS
6104 && bitsize
< BITS_PER_WORD
6105 && bitpos
% BITS_PER_WORD
== 0
6106 && GET_MODE_CLASS (mode
) == MODE_INT
6107 && TREE_CODE (value
) == INTEGER_CST
6109 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6111 tree type
= TREE_TYPE (value
);
6113 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6115 type
= lang_hooks
.types
.type_for_mode
6116 (word_mode
, TYPE_UNSIGNED (type
));
6117 value
= fold_convert (type
, value
);
6120 if (BYTES_BIG_ENDIAN
)
6122 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6123 build_int_cst (type
,
6124 BITS_PER_WORD
- bitsize
));
6125 bitsize
= BITS_PER_WORD
;
6129 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6130 && DECL_NONADDRESSABLE_P (field
))
6132 to_rtx
= copy_rtx (to_rtx
);
6133 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6136 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6138 get_alias_set (TREE_TYPE (field
)));
6145 unsigned HOST_WIDE_INT i
;
6148 tree elttype
= TREE_TYPE (type
);
6150 HOST_WIDE_INT minelt
= 0;
6151 HOST_WIDE_INT maxelt
= 0;
6153 domain
= TYPE_DOMAIN (type
);
6154 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6155 && TYPE_MAX_VALUE (domain
)
6156 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6157 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6159 /* If we have constant bounds for the range of the type, get them. */
6162 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6163 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6166 /* If the constructor has fewer elements than the array, clear
6167 the whole array first. Similarly if this is static
6168 constructor of a non-BLKmode object. */
6171 else if (REG_P (target
) && TREE_STATIC (exp
))
6175 unsigned HOST_WIDE_INT idx
;
6177 HOST_WIDE_INT count
= 0, zero_count
= 0;
6178 need_to_clear
= ! const_bounds_p
;
6180 /* This loop is a more accurate version of the loop in
6181 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6182 is also needed to check for missing elements. */
6183 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6185 HOST_WIDE_INT this_node_count
;
6190 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6192 tree lo_index
= TREE_OPERAND (index
, 0);
6193 tree hi_index
= TREE_OPERAND (index
, 1);
6195 if (! tree_fits_uhwi_p (lo_index
)
6196 || ! tree_fits_uhwi_p (hi_index
))
6202 this_node_count
= (tree_to_uhwi (hi_index
)
6203 - tree_to_uhwi (lo_index
) + 1);
6206 this_node_count
= 1;
6208 count
+= this_node_count
;
6209 if (mostly_zeros_p (value
))
6210 zero_count
+= this_node_count
;
6213 /* Clear the entire array first if there are any missing
6214 elements, or if the incidence of zero elements is >=
6217 && (count
< maxelt
- minelt
+ 1
6218 || 4 * zero_count
>= 3 * count
))
6222 if (need_to_clear
&& size
> 0)
6225 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6227 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6231 if (!cleared
&& REG_P (target
))
6232 /* Inform later passes that the old value is dead. */
6233 emit_clobber (target
);
6235 /* Store each element of the constructor into the
6236 corresponding element of TARGET, determined by counting the
6238 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6241 HOST_WIDE_INT bitsize
;
6242 HOST_WIDE_INT bitpos
;
6243 rtx xtarget
= target
;
6245 if (cleared
&& initializer_zerop (value
))
6248 mode
= TYPE_MODE (elttype
);
6249 if (mode
== BLKmode
)
6250 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6251 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6254 bitsize
= GET_MODE_BITSIZE (mode
);
6256 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6258 tree lo_index
= TREE_OPERAND (index
, 0);
6259 tree hi_index
= TREE_OPERAND (index
, 1);
6260 rtx index_r
, pos_rtx
;
6261 HOST_WIDE_INT lo
, hi
, count
;
6264 /* If the range is constant and "small", unroll the loop. */
6266 && tree_fits_shwi_p (lo_index
)
6267 && tree_fits_shwi_p (hi_index
)
6268 && (lo
= tree_to_shwi (lo_index
),
6269 hi
= tree_to_shwi (hi_index
),
6270 count
= hi
- lo
+ 1,
6273 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6274 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6277 lo
-= minelt
; hi
-= minelt
;
6278 for (; lo
<= hi
; lo
++)
6280 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6283 && !MEM_KEEP_ALIAS_SET_P (target
)
6284 && TREE_CODE (type
) == ARRAY_TYPE
6285 && TYPE_NONALIASED_COMPONENT (type
))
6287 target
= copy_rtx (target
);
6288 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6291 store_constructor_field
6292 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6293 get_alias_set (elttype
));
6298 rtx_code_label
*loop_start
= gen_label_rtx ();
6299 rtx_code_label
*loop_end
= gen_label_rtx ();
6302 expand_normal (hi_index
);
6304 index
= build_decl (EXPR_LOCATION (exp
),
6305 VAR_DECL
, NULL_TREE
, domain
);
6306 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6307 SET_DECL_RTL (index
, index_r
);
6308 store_expr (lo_index
, index_r
, 0, false);
6310 /* Build the head of the loop. */
6311 do_pending_stack_adjust ();
6312 emit_label (loop_start
);
6314 /* Assign value to element index. */
6316 fold_convert (ssizetype
,
6317 fold_build2 (MINUS_EXPR
,
6320 TYPE_MIN_VALUE (domain
)));
6323 size_binop (MULT_EXPR
, position
,
6324 fold_convert (ssizetype
,
6325 TYPE_SIZE_UNIT (elttype
)));
6327 pos_rtx
= expand_normal (position
);
6328 xtarget
= offset_address (target
, pos_rtx
,
6329 highest_pow2_factor (position
));
6330 xtarget
= adjust_address (xtarget
, mode
, 0);
6331 if (TREE_CODE (value
) == CONSTRUCTOR
)
6332 store_constructor (value
, xtarget
, cleared
,
6333 bitsize
/ BITS_PER_UNIT
);
6335 store_expr (value
, xtarget
, 0, false);
6337 /* Generate a conditional jump to exit the loop. */
6338 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6340 jumpif (exit_cond
, loop_end
, -1);
6342 /* Update the loop counter, and jump to the head of
6344 expand_assignment (index
,
6345 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6346 index
, integer_one_node
),
6349 emit_jump (loop_start
);
6351 /* Build the end of the loop. */
6352 emit_label (loop_end
);
6355 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6356 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6361 index
= ssize_int (1);
6364 index
= fold_convert (ssizetype
,
6365 fold_build2 (MINUS_EXPR
,
6368 TYPE_MIN_VALUE (domain
)));
6371 size_binop (MULT_EXPR
, index
,
6372 fold_convert (ssizetype
,
6373 TYPE_SIZE_UNIT (elttype
)));
6374 xtarget
= offset_address (target
,
6375 expand_normal (position
),
6376 highest_pow2_factor (position
));
6377 xtarget
= adjust_address (xtarget
, mode
, 0);
6378 store_expr (value
, xtarget
, 0, false);
6383 bitpos
= ((tree_to_shwi (index
) - minelt
)
6384 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6386 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6388 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6389 && TREE_CODE (type
) == ARRAY_TYPE
6390 && TYPE_NONALIASED_COMPONENT (type
))
6392 target
= copy_rtx (target
);
6393 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6395 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6396 cleared
, get_alias_set (elttype
));
6404 unsigned HOST_WIDE_INT idx
;
6405 constructor_elt
*ce
;
6408 int icode
= CODE_FOR_nothing
;
6409 tree elttype
= TREE_TYPE (type
);
6410 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6411 machine_mode eltmode
= TYPE_MODE (elttype
);
6412 HOST_WIDE_INT bitsize
;
6413 HOST_WIDE_INT bitpos
;
6414 rtvec vector
= NULL
;
6416 alias_set_type alias
;
6418 gcc_assert (eltmode
!= BLKmode
);
6420 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6421 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6423 machine_mode mode
= GET_MODE (target
);
6425 icode
= (int) optab_handler (vec_init_optab
, mode
);
6426 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6427 if (icode
!= CODE_FOR_nothing
)
6431 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6432 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6434 icode
= CODE_FOR_nothing
;
6438 if (icode
!= CODE_FOR_nothing
)
6442 vector
= rtvec_alloc (n_elts
);
6443 for (i
= 0; i
< n_elts
; i
++)
6444 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6448 /* If the constructor has fewer elements than the vector,
6449 clear the whole array first. Similarly if this is static
6450 constructor of a non-BLKmode object. */
6453 else if (REG_P (target
) && TREE_STATIC (exp
))
6457 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6460 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6462 int n_elts_here
= tree_to_uhwi
6463 (int_const_binop (TRUNC_DIV_EXPR
,
6464 TYPE_SIZE (TREE_TYPE (value
)),
6465 TYPE_SIZE (elttype
)));
6467 count
+= n_elts_here
;
6468 if (mostly_zeros_p (value
))
6469 zero_count
+= n_elts_here
;
6472 /* Clear the entire vector first if there are any missing elements,
6473 or if the incidence of zero elements is >= 75%. */
6474 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6477 if (need_to_clear
&& size
> 0 && !vector
)
6480 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6482 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6486 /* Inform later passes that the old value is dead. */
6487 if (!cleared
&& !vector
&& REG_P (target
))
6488 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6491 alias
= MEM_ALIAS_SET (target
);
6493 alias
= get_alias_set (elttype
);
6495 /* Store each element of the constructor into the corresponding
6496 element of TARGET, determined by counting the elements. */
6497 for (idx
= 0, i
= 0;
6498 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6499 idx
++, i
+= bitsize
/ elt_size
)
6501 HOST_WIDE_INT eltpos
;
6502 tree value
= ce
->value
;
6504 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6505 if (cleared
&& initializer_zerop (value
))
6509 eltpos
= tree_to_uhwi (ce
->index
);
6515 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6517 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6518 RTVEC_ELT (vector
, eltpos
)
6519 = expand_normal (value
);
6523 machine_mode value_mode
=
6524 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6525 ? TYPE_MODE (TREE_TYPE (value
))
6527 bitpos
= eltpos
* elt_size
;
6528 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6529 value
, cleared
, alias
);
6534 emit_insn (GEN_FCN (icode
)
6536 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6545 /* Store the value of EXP (an expression tree)
6546 into a subfield of TARGET which has mode MODE and occupies
6547 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6548 If MODE is VOIDmode, it means that we are storing into a bit-field.
6550 BITREGION_START is bitpos of the first bitfield in this region.
6551 BITREGION_END is the bitpos of the ending bitfield in this region.
6552 These two fields are 0, if the C++ memory model does not apply,
6553 or we are not interested in keeping track of bitfield regions.
6555 Always return const0_rtx unless we have something particular to
6558 ALIAS_SET is the alias set for the destination. This value will
6559 (in general) be different from that for TARGET, since TARGET is a
6560 reference to the containing structure.
6562 If NONTEMPORAL is true, try generating a nontemporal store. */
6565 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6566 unsigned HOST_WIDE_INT bitregion_start
,
6567 unsigned HOST_WIDE_INT bitregion_end
,
6568 machine_mode mode
, tree exp
,
6569 alias_set_type alias_set
, bool nontemporal
)
6571 if (TREE_CODE (exp
) == ERROR_MARK
)
6574 /* If we have nothing to store, do nothing unless the expression has
6577 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6579 if (GET_CODE (target
) == CONCAT
)
6581 /* We're storing into a struct containing a single __complex. */
6583 gcc_assert (!bitpos
);
6584 return store_expr (exp
, target
, 0, nontemporal
);
6587 /* If the structure is in a register or if the component
6588 is a bit field, we cannot use addressing to access it.
6589 Use bit-field techniques or SUBREG to store in it. */
6591 if (mode
== VOIDmode
6592 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6593 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6594 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6596 || GET_CODE (target
) == SUBREG
6597 /* If the field isn't aligned enough to store as an ordinary memref,
6598 store it as a bit field. */
6600 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6601 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6602 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6603 || (bitpos
% BITS_PER_UNIT
!= 0)))
6604 || (bitsize
>= 0 && mode
!= BLKmode
6605 && GET_MODE_BITSIZE (mode
) > bitsize
)
6606 /* If the RHS and field are a constant size and the size of the
6607 RHS isn't the same size as the bitfield, we must use bitfield
6610 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6611 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0
6612 /* Except for initialization of full bytes from a CONSTRUCTOR, which
6613 we will handle specially below. */
6614 && !(TREE_CODE (exp
) == CONSTRUCTOR
6615 && bitsize
% BITS_PER_UNIT
== 0))
6616 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6617 decl we must use bitfield operations. */
6619 && TREE_CODE (exp
) == MEM_REF
6620 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6621 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6622 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6623 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6628 /* Using bitwise copy is not safe for TREE_ADDRESSABLE types. */
6629 gcc_assert (!TREE_ADDRESSABLE (TREE_TYPE (exp
)));
6631 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6632 implies a mask operation. If the precision is the same size as
6633 the field we're storing into, that mask is redundant. This is
6634 particularly common with bit field assignments generated by the
6636 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6639 tree type
= TREE_TYPE (exp
);
6640 if (INTEGRAL_TYPE_P (type
)
6641 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6642 && bitsize
== TYPE_PRECISION (type
))
6644 tree op
= gimple_assign_rhs1 (nop_def
);
6645 type
= TREE_TYPE (op
);
6646 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6651 temp
= expand_normal (exp
);
6653 /* If BITSIZE is narrower than the size of the type of EXP
6654 we will be narrowing TEMP. Normally, what's wanted are the
6655 low-order bits. However, if EXP's type is a record and this is
6656 big-endian machine, we want the upper BITSIZE bits. */
6657 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6658 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6659 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6660 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6661 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6664 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6665 if (mode
!= VOIDmode
&& mode
!= BLKmode
6666 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6667 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6669 /* If TEMP is not a PARALLEL (see below) and its mode and that of TARGET
6670 are both BLKmode, both must be in memory and BITPOS must be aligned
6671 on a byte boundary. If so, we simply do a block copy. Likewise for
6672 a BLKmode-like TARGET. */
6673 if (GET_CODE (temp
) != PARALLEL
6674 && GET_MODE (temp
) == BLKmode
6675 && (GET_MODE (target
) == BLKmode
6677 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6678 && (bitpos
% BITS_PER_UNIT
) == 0
6679 && (bitsize
% BITS_PER_UNIT
) == 0)))
6681 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6682 && (bitpos
% BITS_PER_UNIT
) == 0);
6684 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6685 emit_block_move (target
, temp
,
6686 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6693 /* Handle calls that return values in multiple non-contiguous locations.
6694 The Irix 6 ABI has examples of this. */
6695 if (GET_CODE (temp
) == PARALLEL
)
6697 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6699 if (mode
== BLKmode
|| mode
== VOIDmode
)
6700 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6701 temp_target
= gen_reg_rtx (mode
);
6702 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6705 else if (mode
== BLKmode
)
6707 /* Handle calls that return BLKmode values in registers. */
6708 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6710 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6711 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6716 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6718 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6719 temp_target
= gen_reg_rtx (mode
);
6721 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6722 temp_target
, mode
, mode
);
6727 /* Store the value in the bitfield. */
6728 store_bit_field (target
, bitsize
, bitpos
,
6729 bitregion_start
, bitregion_end
,
6736 /* Now build a reference to just the desired component. */
6737 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6739 if (to_rtx
== target
)
6740 to_rtx
= copy_rtx (to_rtx
);
6742 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6743 set_mem_alias_set (to_rtx
, alias_set
);
6745 /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
6746 into a target smaller than its type; handle that case now. */
6747 if (TREE_CODE (exp
) == CONSTRUCTOR
&& bitsize
>= 0)
6749 gcc_assert (bitsize
% BITS_PER_UNIT
== 0);
6750 store_constructor (exp
, to_rtx
, 0, bitsize
/BITS_PER_UNIT
);
6754 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6758 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6759 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6760 codes and find the ultimate containing object, which we return.
6762 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6763 bit position, and *PUNSIGNEDP to the signedness of the field.
6764 If the position of the field is variable, we store a tree
6765 giving the variable offset (in units) in *POFFSET.
6766 This offset is in addition to the bit position.
6767 If the position is not variable, we store 0 in *POFFSET.
6769 If any of the extraction expressions is volatile,
6770 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6772 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6773 Otherwise, it is a mode that can be used to access the field.
6775 If the field describes a variable-sized object, *PMODE is set to
6776 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6777 this case, but the address of the object can be found.
6779 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6780 look through nodes that serve as markers of a greater alignment than
6781 the one that can be deduced from the expression. These nodes make it
6782 possible for front-ends to prevent temporaries from being created by
6783 the middle-end on alignment considerations. For that purpose, the
6784 normal operating mode at high-level is to always pass FALSE so that
6785 the ultimate containing object is really returned; moreover, the
6786 associated predicate handled_component_p will always return TRUE
6787 on these nodes, thus indicating that they are essentially handled
6788 by get_inner_reference. TRUE should only be passed when the caller
6789 is scanning the expression in order to build another representation
6790 and specifically knows how to handle these nodes; as such, this is
6791 the normal operating mode in the RTL expanders. */
6794 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6795 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6796 machine_mode
*pmode
, int *punsignedp
,
6797 int *pvolatilep
, bool keep_aligning
)
6800 machine_mode mode
= VOIDmode
;
6801 bool blkmode_bitfield
= false;
6802 tree offset
= size_zero_node
;
6803 offset_int bit_offset
= 0;
6805 /* First get the mode, signedness, and size. We do this from just the
6806 outermost expression. */
6808 if (TREE_CODE (exp
) == COMPONENT_REF
)
6810 tree field
= TREE_OPERAND (exp
, 1);
6811 size_tree
= DECL_SIZE (field
);
6812 if (flag_strict_volatile_bitfields
> 0
6813 && TREE_THIS_VOLATILE (exp
)
6814 && DECL_BIT_FIELD_TYPE (field
)
6815 && DECL_MODE (field
) != BLKmode
)
6816 /* Volatile bitfields should be accessed in the mode of the
6817 field's type, not the mode computed based on the bit
6819 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6820 else if (!DECL_BIT_FIELD (field
))
6821 mode
= DECL_MODE (field
);
6822 else if (DECL_MODE (field
) == BLKmode
)
6823 blkmode_bitfield
= true;
6825 *punsignedp
= DECL_UNSIGNED (field
);
6827 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6829 size_tree
= TREE_OPERAND (exp
, 1);
6830 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6831 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6833 /* For vector types, with the correct size of access, use the mode of
6835 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6836 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6837 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6838 mode
= TYPE_MODE (TREE_TYPE (exp
));
6842 mode
= TYPE_MODE (TREE_TYPE (exp
));
6843 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6845 if (mode
== BLKmode
)
6846 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6848 *pbitsize
= GET_MODE_BITSIZE (mode
);
6853 if (! tree_fits_uhwi_p (size_tree
))
6854 mode
= BLKmode
, *pbitsize
= -1;
6856 *pbitsize
= tree_to_uhwi (size_tree
);
6859 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6860 and find the ultimate containing object. */
6863 switch (TREE_CODE (exp
))
6866 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
6871 tree field
= TREE_OPERAND (exp
, 1);
6872 tree this_offset
= component_ref_field_offset (exp
);
6874 /* If this field hasn't been filled in yet, don't go past it.
6875 This should only happen when folding expressions made during
6876 type construction. */
6877 if (this_offset
== 0)
6880 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6881 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
6883 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6888 case ARRAY_RANGE_REF
:
6890 tree index
= TREE_OPERAND (exp
, 1);
6891 tree low_bound
= array_ref_low_bound (exp
);
6892 tree unit_size
= array_ref_element_size (exp
);
6894 /* We assume all arrays have sizes that are a multiple of a byte.
6895 First subtract the lower bound, if any, in the type of the
6896 index, then convert to sizetype and multiply by the size of
6897 the array element. */
6898 if (! integer_zerop (low_bound
))
6899 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6902 offset
= size_binop (PLUS_EXPR
, offset
,
6903 size_binop (MULT_EXPR
,
6904 fold_convert (sizetype
, index
),
6913 bit_offset
+= *pbitsize
;
6916 case VIEW_CONVERT_EXPR
:
6917 if (keep_aligning
&& STRICT_ALIGNMENT
6918 && (TYPE_ALIGN (TREE_TYPE (exp
))
6919 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6920 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6921 < BIGGEST_ALIGNMENT
)
6922 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6923 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6928 /* Hand back the decl for MEM[&decl, off]. */
6929 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6931 tree off
= TREE_OPERAND (exp
, 1);
6932 if (!integer_zerop (off
))
6934 offset_int boff
, coff
= mem_ref_offset (exp
);
6935 boff
= wi::lshift (coff
, LOG2_BITS_PER_UNIT
);
6938 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6946 /* If any reference in the chain is volatile, the effect is volatile. */
6947 if (TREE_THIS_VOLATILE (exp
))
6950 exp
= TREE_OPERAND (exp
, 0);
6954 /* If OFFSET is constant, see if we can return the whole thing as a
6955 constant bit position. Make sure to handle overflow during
6957 if (TREE_CODE (offset
) == INTEGER_CST
)
6959 offset_int tem
= wi::sext (wi::to_offset (offset
),
6960 TYPE_PRECISION (sizetype
));
6961 tem
= wi::lshift (tem
, LOG2_BITS_PER_UNIT
);
6963 if (wi::fits_shwi_p (tem
))
6965 *pbitpos
= tem
.to_shwi ();
6966 *poffset
= offset
= NULL_TREE
;
6970 /* Otherwise, split it up. */
6973 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6974 if (wi::neg_p (bit_offset
) || !wi::fits_shwi_p (bit_offset
))
6976 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
6977 offset_int tem
= bit_offset
.and_not (mask
);
6978 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6979 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6981 tem
= wi::arshift (tem
, LOG2_BITS_PER_UNIT
);
6982 offset
= size_binop (PLUS_EXPR
, offset
,
6983 wide_int_to_tree (sizetype
, tem
));
6986 *pbitpos
= bit_offset
.to_shwi ();
6990 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6991 if (mode
== VOIDmode
6993 && (*pbitpos
% BITS_PER_UNIT
) == 0
6994 && (*pbitsize
% BITS_PER_UNIT
) == 0)
7002 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7004 static unsigned HOST_WIDE_INT
7005 target_align (const_tree target
)
7007 /* We might have a chain of nested references with intermediate misaligning
7008 bitfields components, so need to recurse to find out. */
7010 unsigned HOST_WIDE_INT this_align
, outer_align
;
7012 switch (TREE_CODE (target
))
7018 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7019 outer_align
= target_align (TREE_OPERAND (target
, 0));
7020 return MIN (this_align
, outer_align
);
7023 case ARRAY_RANGE_REF
:
7024 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7025 outer_align
= target_align (TREE_OPERAND (target
, 0));
7026 return MIN (this_align
, outer_align
);
7029 case NON_LVALUE_EXPR
:
7030 case VIEW_CONVERT_EXPR
:
7031 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7032 outer_align
= target_align (TREE_OPERAND (target
, 0));
7033 return MAX (this_align
, outer_align
);
7036 return TYPE_ALIGN (TREE_TYPE (target
));
7041 /* Given an rtx VALUE that may contain additions and multiplications, return
7042 an equivalent value that just refers to a register, memory, or constant.
7043 This is done by generating instructions to perform the arithmetic and
7044 returning a pseudo-register containing the value.
7046 The returned value may be a REG, SUBREG, MEM or constant. */
7049 force_operand (rtx value
, rtx target
)
7052 /* Use subtarget as the target for operand 0 of a binary operation. */
7053 rtx subtarget
= get_subtarget (target
);
7054 enum rtx_code code
= GET_CODE (value
);
7056 /* Check for subreg applied to an expression produced by loop optimizer. */
7058 && !REG_P (SUBREG_REG (value
))
7059 && !MEM_P (SUBREG_REG (value
)))
7062 = simplify_gen_subreg (GET_MODE (value
),
7063 force_reg (GET_MODE (SUBREG_REG (value
)),
7064 force_operand (SUBREG_REG (value
),
7066 GET_MODE (SUBREG_REG (value
)),
7067 SUBREG_BYTE (value
));
7068 code
= GET_CODE (value
);
7071 /* Check for a PIC address load. */
7072 if ((code
== PLUS
|| code
== MINUS
)
7073 && XEXP (value
, 0) == pic_offset_table_rtx
7074 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7075 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7076 || GET_CODE (XEXP (value
, 1)) == CONST
))
7079 subtarget
= gen_reg_rtx (GET_MODE (value
));
7080 emit_move_insn (subtarget
, value
);
7084 if (ARITHMETIC_P (value
))
7086 op2
= XEXP (value
, 1);
7087 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7089 if (code
== MINUS
&& CONST_INT_P (op2
))
7092 op2
= negate_rtx (GET_MODE (value
), op2
);
7095 /* Check for an addition with OP2 a constant integer and our first
7096 operand a PLUS of a virtual register and something else. In that
7097 case, we want to emit the sum of the virtual register and the
7098 constant first and then add the other value. This allows virtual
7099 register instantiation to simply modify the constant rather than
7100 creating another one around this addition. */
7101 if (code
== PLUS
&& CONST_INT_P (op2
)
7102 && GET_CODE (XEXP (value
, 0)) == PLUS
7103 && REG_P (XEXP (XEXP (value
, 0), 0))
7104 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7105 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7107 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7108 XEXP (XEXP (value
, 0), 0), op2
,
7109 subtarget
, 0, OPTAB_LIB_WIDEN
);
7110 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7111 force_operand (XEXP (XEXP (value
,
7113 target
, 0, OPTAB_LIB_WIDEN
);
7116 op1
= force_operand (XEXP (value
, 0), subtarget
);
7117 op2
= force_operand (op2
, NULL_RTX
);
7121 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7123 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7124 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7125 target
, 1, OPTAB_LIB_WIDEN
);
7127 return expand_divmod (0,
7128 FLOAT_MODE_P (GET_MODE (value
))
7129 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7130 GET_MODE (value
), op1
, op2
, target
, 0);
7132 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7135 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7138 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7141 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7142 target
, 0, OPTAB_LIB_WIDEN
);
7144 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7145 target
, 1, OPTAB_LIB_WIDEN
);
7148 if (UNARY_P (value
))
7151 target
= gen_reg_rtx (GET_MODE (value
));
7152 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7159 case FLOAT_TRUNCATE
:
7160 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7165 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7169 case UNSIGNED_FLOAT
:
7170 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7174 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7178 #ifdef INSN_SCHEDULING
7179 /* On machines that have insn scheduling, we want all memory reference to be
7180 explicit, so we need to deal with such paradoxical SUBREGs. */
7181 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7183 = simplify_gen_subreg (GET_MODE (value
),
7184 force_reg (GET_MODE (SUBREG_REG (value
)),
7185 force_operand (SUBREG_REG (value
),
7187 GET_MODE (SUBREG_REG (value
)),
7188 SUBREG_BYTE (value
));
7194 /* Subroutine of expand_expr: return nonzero iff there is no way that
7195 EXP can reference X, which is being modified. TOP_P is nonzero if this
7196 call is going to be used to determine whether we need a temporary
7197 for EXP, as opposed to a recursive call to this function.
7199 It is always safe for this routine to return zero since it merely
7200 searches for optimization opportunities. */
7203 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7209 /* If EXP has varying size, we MUST use a target since we currently
7210 have no way of allocating temporaries of variable size
7211 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7212 So we assume here that something at a higher level has prevented a
7213 clash. This is somewhat bogus, but the best we can do. Only
7214 do this when X is BLKmode and when we are at the top level. */
7215 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7216 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7217 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7218 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7219 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7221 && GET_MODE (x
) == BLKmode
)
7222 /* If X is in the outgoing argument area, it is always safe. */
7224 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7225 || (GET_CODE (XEXP (x
, 0)) == PLUS
7226 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7229 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7230 find the underlying pseudo. */
7231 if (GET_CODE (x
) == SUBREG
)
7234 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7238 /* Now look at our tree code and possibly recurse. */
7239 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7241 case tcc_declaration
:
7242 exp_rtl
= DECL_RTL_IF_SET (exp
);
7248 case tcc_exceptional
:
7249 if (TREE_CODE (exp
) == TREE_LIST
)
7253 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7255 exp
= TREE_CHAIN (exp
);
7258 if (TREE_CODE (exp
) != TREE_LIST
)
7259 return safe_from_p (x
, exp
, 0);
7262 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7264 constructor_elt
*ce
;
7265 unsigned HOST_WIDE_INT idx
;
7267 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7268 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7269 || !safe_from_p (x
, ce
->value
, 0))
7273 else if (TREE_CODE (exp
) == ERROR_MARK
)
7274 return 1; /* An already-visited SAVE_EXPR? */
7279 /* The only case we look at here is the DECL_INITIAL inside a
7281 return (TREE_CODE (exp
) != DECL_EXPR
7282 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7283 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7284 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7287 case tcc_comparison
:
7288 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7293 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7295 case tcc_expression
:
7298 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7299 the expression. If it is set, we conflict iff we are that rtx or
7300 both are in memory. Otherwise, we check all operands of the
7301 expression recursively. */
7303 switch (TREE_CODE (exp
))
7306 /* If the operand is static or we are static, we can't conflict.
7307 Likewise if we don't conflict with the operand at all. */
7308 if (staticp (TREE_OPERAND (exp
, 0))
7309 || TREE_STATIC (exp
)
7310 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7313 /* Otherwise, the only way this can conflict is if we are taking
7314 the address of a DECL a that address if part of X, which is
7316 exp
= TREE_OPERAND (exp
, 0);
7319 if (!DECL_RTL_SET_P (exp
)
7320 || !MEM_P (DECL_RTL (exp
)))
7323 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7329 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7330 get_alias_set (exp
)))
7335 /* Assume that the call will clobber all hard registers and
7337 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7342 case WITH_CLEANUP_EXPR
:
7343 case CLEANUP_POINT_EXPR
:
7344 /* Lowered by gimplify.c. */
7348 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7354 /* If we have an rtx, we do not need to scan our operands. */
7358 nops
= TREE_OPERAND_LENGTH (exp
);
7359 for (i
= 0; i
< nops
; i
++)
7360 if (TREE_OPERAND (exp
, i
) != 0
7361 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7367 /* Should never get a type here. */
7371 /* If we have an rtl, find any enclosed object. Then see if we conflict
7375 if (GET_CODE (exp_rtl
) == SUBREG
)
7377 exp_rtl
= SUBREG_REG (exp_rtl
);
7379 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7383 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7384 are memory and they conflict. */
7385 return ! (rtx_equal_p (x
, exp_rtl
)
7386 || (MEM_P (x
) && MEM_P (exp_rtl
)
7387 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7390 /* If we reach here, it is safe. */
7395 /* Return the highest power of two that EXP is known to be a multiple of.
7396 This is used in updating alignment of MEMs in array references. */
7398 unsigned HOST_WIDE_INT
7399 highest_pow2_factor (const_tree exp
)
7401 unsigned HOST_WIDE_INT ret
;
7402 int trailing_zeros
= tree_ctz (exp
);
7403 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7404 return BIGGEST_ALIGNMENT
;
7405 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7406 if (ret
> BIGGEST_ALIGNMENT
)
7407 return BIGGEST_ALIGNMENT
;
7411 /* Similar, except that the alignment requirements of TARGET are
7412 taken into account. Assume it is at least as aligned as its
7413 type, unless it is a COMPONENT_REF in which case the layout of
7414 the structure gives the alignment. */
7416 static unsigned HOST_WIDE_INT
7417 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7419 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7420 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7422 return MAX (factor
, talign
);
7425 /* Convert the tree comparison code TCODE to the rtl one where the
7426 signedness is UNSIGNEDP. */
7428 static enum rtx_code
7429 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7441 code
= unsignedp
? LTU
: LT
;
7444 code
= unsignedp
? LEU
: LE
;
7447 code
= unsignedp
? GTU
: GT
;
7450 code
= unsignedp
? GEU
: GE
;
7452 case UNORDERED_EXPR
:
7483 /* Subroutine of expand_expr. Expand the two operands of a binary
7484 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7485 The value may be stored in TARGET if TARGET is nonzero. The
7486 MODIFIER argument is as documented by expand_expr. */
7489 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7490 enum expand_modifier modifier
)
7492 if (! safe_from_p (target
, exp1
, 1))
7494 if (operand_equal_p (exp0
, exp1
, 0))
7496 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7497 *op1
= copy_rtx (*op0
);
7501 /* If we need to preserve evaluation order, copy exp0 into its own
7502 temporary variable so that it can't be clobbered by exp1. */
7503 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7504 exp0
= save_expr (exp0
);
7505 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7506 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7511 /* Return a MEM that contains constant EXP. DEFER is as for
7512 output_constant_def and MODIFIER is as for expand_expr. */
7515 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7519 mem
= output_constant_def (exp
, defer
);
7520 if (modifier
!= EXPAND_INITIALIZER
)
7521 mem
= use_anchored_address (mem
);
7525 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7526 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7529 expand_expr_addr_expr_1 (tree exp
, rtx target
, machine_mode tmode
,
7530 enum expand_modifier modifier
, addr_space_t as
)
7532 rtx result
, subtarget
;
7534 HOST_WIDE_INT bitsize
, bitpos
;
7535 int volatilep
, unsignedp
;
7538 /* If we are taking the address of a constant and are at the top level,
7539 we have to use output_constant_def since we can't call force_const_mem
7541 /* ??? This should be considered a front-end bug. We should not be
7542 generating ADDR_EXPR of something that isn't an LVALUE. The only
7543 exception here is STRING_CST. */
7544 if (CONSTANT_CLASS_P (exp
))
7546 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7547 if (modifier
< EXPAND_SUM
)
7548 result
= force_operand (result
, target
);
7552 /* Everything must be something allowed by is_gimple_addressable. */
7553 switch (TREE_CODE (exp
))
7556 /* This case will happen via recursion for &a->b. */
7557 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7561 tree tem
= TREE_OPERAND (exp
, 0);
7562 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7563 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7564 return expand_expr (tem
, target
, tmode
, modifier
);
7568 /* Expand the initializer like constants above. */
7569 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7571 if (modifier
< EXPAND_SUM
)
7572 result
= force_operand (result
, target
);
7576 /* The real part of the complex number is always first, therefore
7577 the address is the same as the address of the parent object. */
7580 inner
= TREE_OPERAND (exp
, 0);
7584 /* The imaginary part of the complex number is always second.
7585 The expression is therefore always offset by the size of the
7588 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7589 inner
= TREE_OPERAND (exp
, 0);
7592 case COMPOUND_LITERAL_EXPR
:
7593 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
7594 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
7595 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
7596 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
7597 the initializers aren't gimplified. */
7598 if (COMPOUND_LITERAL_EXPR_DECL (exp
)
7599 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp
)))
7600 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7601 target
, tmode
, modifier
, as
);
7604 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7605 expand_expr, as that can have various side effects; LABEL_DECLs for
7606 example, may not have their DECL_RTL set yet. Expand the rtl of
7607 CONSTRUCTORs too, which should yield a memory reference for the
7608 constructor's contents. Assume language specific tree nodes can
7609 be expanded in some interesting way. */
7610 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7612 || TREE_CODE (exp
) == CONSTRUCTOR
7613 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7615 result
= expand_expr (exp
, target
, tmode
,
7616 modifier
== EXPAND_INITIALIZER
7617 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7619 /* If the DECL isn't in memory, then the DECL wasn't properly
7620 marked TREE_ADDRESSABLE, which will be either a front-end
7621 or a tree optimizer bug. */
7623 gcc_assert (MEM_P (result
));
7624 result
= XEXP (result
, 0);
7626 /* ??? Is this needed anymore? */
7628 TREE_USED (exp
) = 1;
7630 if (modifier
!= EXPAND_INITIALIZER
7631 && modifier
!= EXPAND_CONST_ADDRESS
7632 && modifier
!= EXPAND_SUM
)
7633 result
= force_operand (result
, target
);
7637 /* Pass FALSE as the last argument to get_inner_reference although
7638 we are expanding to RTL. The rationale is that we know how to
7639 handle "aligning nodes" here: we can just bypass them because
7640 they won't change the final object whose address will be returned
7641 (they actually exist only for that purpose). */
7642 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7643 &mode1
, &unsignedp
, &volatilep
, false);
7647 /* We must have made progress. */
7648 gcc_assert (inner
!= exp
);
7650 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7651 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7652 inner alignment, force the inner to be sufficiently aligned. */
7653 if (CONSTANT_CLASS_P (inner
)
7654 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7656 inner
= copy_node (inner
);
7657 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7658 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7659 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7661 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7667 if (modifier
!= EXPAND_NORMAL
)
7668 result
= force_operand (result
, NULL
);
7669 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7670 modifier
== EXPAND_INITIALIZER
7671 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7673 /* expand_expr is allowed to return an object in a mode other
7674 than TMODE. If it did, we need to convert. */
7675 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7676 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7677 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7678 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7679 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7681 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7682 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7685 subtarget
= bitpos
? NULL_RTX
: target
;
7686 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7687 1, OPTAB_LIB_WIDEN
);
7693 /* Someone beforehand should have rejected taking the address
7694 of such an object. */
7695 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7697 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7698 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7699 if (modifier
< EXPAND_SUM
)
7700 result
= force_operand (result
, target
);
7706 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7707 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7710 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
7711 enum expand_modifier modifier
)
7713 addr_space_t as
= ADDR_SPACE_GENERIC
;
7714 machine_mode address_mode
= Pmode
;
7715 machine_mode pointer_mode
= ptr_mode
;
7719 /* Target mode of VOIDmode says "whatever's natural". */
7720 if (tmode
== VOIDmode
)
7721 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7723 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7725 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7726 address_mode
= targetm
.addr_space
.address_mode (as
);
7727 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7730 /* We can get called with some Weird Things if the user does silliness
7731 like "(short) &a". In that case, convert_memory_address won't do
7732 the right thing, so ignore the given target mode. */
7733 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7734 tmode
= address_mode
;
7736 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7737 tmode
, modifier
, as
);
7739 /* Despite expand_expr claims concerning ignoring TMODE when not
7740 strictly convenient, stuff breaks if we don't honor it. Note
7741 that combined with the above, we only do this for pointer modes. */
7742 rmode
= GET_MODE (result
);
7743 if (rmode
== VOIDmode
)
7746 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7751 /* Generate code for computing CONSTRUCTOR EXP.
7752 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7753 is TRUE, instead of creating a temporary variable in memory
7754 NULL is returned and the caller needs to handle it differently. */
7757 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7758 bool avoid_temp_mem
)
7760 tree type
= TREE_TYPE (exp
);
7761 machine_mode mode
= TYPE_MODE (type
);
7763 /* Try to avoid creating a temporary at all. This is possible
7764 if all of the initializer is zero.
7765 FIXME: try to handle all [0..255] initializers we can handle
7767 if (TREE_STATIC (exp
)
7768 && !TREE_ADDRESSABLE (exp
)
7769 && target
!= 0 && mode
== BLKmode
7770 && all_zeros_p (exp
))
7772 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7776 /* All elts simple constants => refer to a constant in memory. But
7777 if this is a non-BLKmode mode, let it store a field at a time
7778 since that should make a CONST_INT, CONST_WIDE_INT or
7779 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7780 use, it is best to store directly into the target unless the type
7781 is large enough that memcpy will be used. If we are making an
7782 initializer and all operands are constant, put it in memory as
7785 FIXME: Avoid trying to fill vector constructors piece-meal.
7786 Output them with output_constant_def below unless we're sure
7787 they're zeros. This should go away when vector initializers
7788 are treated like VECTOR_CST instead of arrays. */
7789 if ((TREE_STATIC (exp
)
7790 && ((mode
== BLKmode
7791 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7792 || TREE_ADDRESSABLE (exp
)
7793 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7794 && (! can_move_by_pieces
7795 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7797 && ! mostly_zeros_p (exp
))))
7798 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7799 && TREE_CONSTANT (exp
)))
7806 constructor
= expand_expr_constant (exp
, 1, modifier
);
7808 if (modifier
!= EXPAND_CONST_ADDRESS
7809 && modifier
!= EXPAND_INITIALIZER
7810 && modifier
!= EXPAND_SUM
)
7811 constructor
= validize_mem (constructor
);
7816 /* Handle calls that pass values in multiple non-contiguous
7817 locations. The Irix 6 ABI has examples of this. */
7818 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7819 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7824 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7827 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7832 /* expand_expr: generate code for computing expression EXP.
7833 An rtx for the computed value is returned. The value is never null.
7834 In the case of a void EXP, const0_rtx is returned.
7836 The value may be stored in TARGET if TARGET is nonzero.
7837 TARGET is just a suggestion; callers must assume that
7838 the rtx returned may not be the same as TARGET.
7840 If TARGET is CONST0_RTX, it means that the value will be ignored.
7842 If TMODE is not VOIDmode, it suggests generating the
7843 result in mode TMODE. But this is done only when convenient.
7844 Otherwise, TMODE is ignored and the value generated in its natural mode.
7845 TMODE is just a suggestion; callers must assume that
7846 the rtx returned may not have mode TMODE.
7848 Note that TARGET may have neither TMODE nor MODE. In that case, it
7849 probably will not be used.
7851 If MODIFIER is EXPAND_SUM then when EXP is an addition
7852 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7853 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7854 products as above, or REG or MEM, or constant.
7855 Ordinarily in such cases we would output mul or add instructions
7856 and then return a pseudo reg containing the sum.
7858 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7859 it also marks a label as absolutely required (it can't be dead).
7860 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7861 This is used for outputting expressions used in initializers.
7863 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7864 with a constant address even if that address is not normally legitimate.
7865 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7867 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7868 a call parameter. Such targets require special care as we haven't yet
7869 marked TARGET so that it's safe from being trashed by libcalls. We
7870 don't want to use TARGET for anything but the final result;
7871 Intermediate values must go elsewhere. Additionally, calls to
7872 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7874 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7875 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7876 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7877 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7880 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7881 In this case, we don't adjust a returned MEM rtx that wouldn't be
7882 sufficiently aligned for its mode; instead, it's up to the caller
7883 to deal with it afterwards. This is used to make sure that unaligned
7884 base objects for which out-of-bounds accesses are supported, for
7885 example record types with trailing arrays, aren't realigned behind
7886 the back of the caller.
7887 The normal operating mode is to pass FALSE for this parameter. */
7890 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
7891 enum expand_modifier modifier
, rtx
*alt_rtl
,
7892 bool inner_reference_p
)
7896 /* Handle ERROR_MARK before anybody tries to access its type. */
7897 if (TREE_CODE (exp
) == ERROR_MARK
7898 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7900 ret
= CONST0_RTX (tmode
);
7901 return ret
? ret
: const0_rtx
;
7904 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
7909 /* Try to expand the conditional expression which is represented by
7910 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
7911 return the rtl reg which represents the result. Otherwise return
7915 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7916 tree treeop1 ATTRIBUTE_UNUSED
,
7917 tree treeop2 ATTRIBUTE_UNUSED
)
7920 rtx op00
, op01
, op1
, op2
;
7921 enum rtx_code comparison_code
;
7922 machine_mode comparison_mode
;
7925 tree type
= TREE_TYPE (treeop1
);
7926 int unsignedp
= TYPE_UNSIGNED (type
);
7927 machine_mode mode
= TYPE_MODE (type
);
7928 machine_mode orig_mode
= mode
;
7930 /* If we cannot do a conditional move on the mode, try doing it
7931 with the promoted mode. */
7932 if (!can_conditionally_move_p (mode
))
7934 mode
= promote_mode (type
, mode
, &unsignedp
);
7935 if (!can_conditionally_move_p (mode
))
7937 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7940 temp
= assign_temp (type
, 0, 1);
7943 expand_operands (treeop1
, treeop2
,
7944 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7946 if (TREE_CODE (treeop0
) == SSA_NAME
7947 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7949 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7950 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7951 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7952 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7953 comparison_mode
= TYPE_MODE (type
);
7954 unsignedp
= TYPE_UNSIGNED (type
);
7955 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7957 else if (COMPARISON_CLASS_P (treeop0
))
7959 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7960 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7961 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7962 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7963 unsignedp
= TYPE_UNSIGNED (type
);
7964 comparison_mode
= TYPE_MODE (type
);
7965 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7969 op00
= expand_normal (treeop0
);
7971 comparison_code
= NE
;
7972 comparison_mode
= GET_MODE (op00
);
7973 if (comparison_mode
== VOIDmode
)
7974 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7977 if (GET_MODE (op1
) != mode
)
7978 op1
= gen_lowpart (mode
, op1
);
7980 if (GET_MODE (op2
) != mode
)
7981 op2
= gen_lowpart (mode
, op2
);
7983 /* Try to emit the conditional move. */
7984 insn
= emit_conditional_move (temp
, comparison_code
,
7985 op00
, op01
, comparison_mode
,
7989 /* If we could do the conditional move, emit the sequence,
7993 rtx_insn
*seq
= get_insns ();
7996 return convert_modes (orig_mode
, mode
, temp
, 0);
7999 /* Otherwise discard the sequence and fall back to code with
8006 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
8007 enum expand_modifier modifier
)
8009 rtx op0
, op1
, op2
, temp
;
8010 rtx_code_label
*lab
;
8014 enum tree_code code
= ops
->code
;
8016 rtx subtarget
, original_target
;
8018 bool reduce_bit_field
;
8019 location_t loc
= ops
->location
;
8020 tree treeop0
, treeop1
, treeop2
;
8021 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8022 ? reduce_to_bit_field_precision ((expr), \
8028 mode
= TYPE_MODE (type
);
8029 unsignedp
= TYPE_UNSIGNED (type
);
8035 /* We should be called only on simple (binary or unary) expressions,
8036 exactly those that are valid in gimple expressions that aren't
8037 GIMPLE_SINGLE_RHS (or invalid). */
8038 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8039 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8040 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8042 ignore
= (target
== const0_rtx
8043 || ((CONVERT_EXPR_CODE_P (code
)
8044 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8045 && TREE_CODE (type
) == VOID_TYPE
));
8047 /* We should be called only if we need the result. */
8048 gcc_assert (!ignore
);
8050 /* An operation in what may be a bit-field type needs the
8051 result to be reduced to the precision of the bit-field type,
8052 which is narrower than that of the type's mode. */
8053 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8054 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8056 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8059 /* Use subtarget as the target for operand 0 of a binary operation. */
8060 subtarget
= get_subtarget (target
);
8061 original_target
= target
;
8065 case NON_LVALUE_EXPR
:
8068 if (treeop0
== error_mark_node
)
8071 if (TREE_CODE (type
) == UNION_TYPE
)
8073 tree valtype
= TREE_TYPE (treeop0
);
8075 /* If both input and output are BLKmode, this conversion isn't doing
8076 anything except possibly changing memory attribute. */
8077 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8079 rtx result
= expand_expr (treeop0
, target
, tmode
,
8082 result
= copy_rtx (result
);
8083 set_mem_attributes (result
, type
, 0);
8089 if (TYPE_MODE (type
) != BLKmode
)
8090 target
= gen_reg_rtx (TYPE_MODE (type
));
8092 target
= assign_temp (type
, 1, 1);
8096 /* Store data into beginning of memory target. */
8097 store_expr (treeop0
,
8098 adjust_address (target
, TYPE_MODE (valtype
), 0),
8099 modifier
== EXPAND_STACK_PARM
,
8104 gcc_assert (REG_P (target
));
8106 /* Store this field into a union of the proper type. */
8107 store_field (target
,
8108 MIN ((int_size_in_bytes (TREE_TYPE
8111 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8112 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8115 /* Return the entire union. */
8119 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8121 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8124 /* If the signedness of the conversion differs and OP0 is
8125 a promoted SUBREG, clear that indication since we now
8126 have to do the proper extension. */
8127 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8128 && GET_CODE (op0
) == SUBREG
)
8129 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8131 return REDUCE_BIT_FIELD (op0
);
8134 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8135 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8136 if (GET_MODE (op0
) == mode
)
8139 /* If OP0 is a constant, just convert it into the proper mode. */
8140 else if (CONSTANT_P (op0
))
8142 tree inner_type
= TREE_TYPE (treeop0
);
8143 machine_mode inner_mode
= GET_MODE (op0
);
8145 if (inner_mode
== VOIDmode
)
8146 inner_mode
= TYPE_MODE (inner_type
);
8148 if (modifier
== EXPAND_INITIALIZER
)
8149 op0
= lowpart_subreg (mode
, op0
, inner_mode
);
8151 op0
= convert_modes (mode
, inner_mode
, op0
,
8152 TYPE_UNSIGNED (inner_type
));
8155 else if (modifier
== EXPAND_INITIALIZER
)
8156 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8158 else if (target
== 0)
8159 op0
= convert_to_mode (mode
, op0
,
8160 TYPE_UNSIGNED (TREE_TYPE
8164 convert_move (target
, op0
,
8165 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8169 return REDUCE_BIT_FIELD (op0
);
8171 case ADDR_SPACE_CONVERT_EXPR
:
8173 tree treeop0_type
= TREE_TYPE (treeop0
);
8175 gcc_assert (POINTER_TYPE_P (type
));
8176 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8178 addr_space_t as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8179 addr_space_t as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8181 /* Conversions between pointers to the same address space should
8182 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8183 gcc_assert (as_to
!= as_from
);
8185 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8187 /* Ask target code to handle conversion between pointers
8188 to overlapping address spaces. */
8189 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8190 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8192 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8196 /* For disjoint address spaces, converting anything but a null
8197 pointer invokes undefined behaviour. We truncate or extend the
8198 value as if we'd converted via integers, which handles 0 as
8199 required, and all others as the programmer likely expects. */
8200 #ifndef POINTERS_EXTEND_UNSIGNED
8201 const int POINTERS_EXTEND_UNSIGNED
= 1;
8203 op0
= convert_modes (mode
, TYPE_MODE (treeop0_type
),
8204 op0
, POINTERS_EXTEND_UNSIGNED
);
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
;
8515 gimple
*def0
, *def2
;
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
)));
8863 /* If this is a fixed-point operation, then we cannot use the code
8864 below because "expand_shift" doesn't support sat/no-sat fixed-point
8866 if (ALL_FIXED_POINT_MODE_P (mode
))
8869 if (! safe_from_p (subtarget
, treeop1
, 1))
8871 if (modifier
== EXPAND_STACK_PARM
)
8873 op0
= expand_expr (treeop0
, subtarget
,
8874 VOIDmode
, EXPAND_NORMAL
);
8876 /* Left shift optimization when shifting across word_size boundary.
8878 If mode == GET_MODE_WIDER_MODE (word_mode), then normally there isn't
8879 native instruction to support this wide mode left shift. Given below
8882 Type A = (Type) B << C
8885 | dest_high | dest_low |
8889 If the shift amount C caused we shift B to across the word size
8890 boundary, i.e part of B shifted into high half of destination
8891 register, and part of B remains in the low half, then GCC will use
8892 the following left shift expand logic:
8894 1. Initialize dest_low to B.
8895 2. Initialize every bit of dest_high to the sign bit of B.
8896 3. Logic left shift dest_low by C bit to finalize dest_low.
8897 The value of dest_low before this shift is kept in a temp D.
8898 4. Logic left shift dest_high by C.
8899 5. Logic right shift D by (word_size - C).
8900 6. Or the result of 4 and 5 to finalize dest_high.
8902 While, by checking gimple statements, if operand B is coming from
8903 signed extension, then we can simplify above expand logic into:
8905 1. dest_high = src_low >> (word_size - C).
8906 2. dest_low = src_low << C.
8908 We can use one arithmetic right shift to finish all the purpose of
8909 steps 2, 4, 5, 6, thus we reduce the steps needed from 6 into 2. */
8912 if (code
== LSHIFT_EXPR
8916 && mode
== GET_MODE_WIDER_MODE (word_mode
)
8917 && GET_MODE_SIZE (mode
) == 2 * GET_MODE_SIZE (word_mode
)
8918 && TREE_CONSTANT (treeop1
)
8919 && TREE_CODE (treeop0
) == SSA_NAME
)
8921 gimple
*def
= SSA_NAME_DEF_STMT (treeop0
);
8922 if (is_gimple_assign (def
)
8923 && gimple_assign_rhs_code (def
) == NOP_EXPR
)
8925 machine_mode rmode
= TYPE_MODE
8926 (TREE_TYPE (gimple_assign_rhs1 (def
)));
8928 if (GET_MODE_SIZE (rmode
) < GET_MODE_SIZE (mode
)
8929 && TREE_INT_CST_LOW (treeop1
) < GET_MODE_BITSIZE (word_mode
)
8930 && ((TREE_INT_CST_LOW (treeop1
) + GET_MODE_BITSIZE (rmode
))
8931 >= GET_MODE_BITSIZE (word_mode
)))
8933 rtx_insn
*seq
, *seq_old
;
8934 unsigned int high_off
= subreg_highpart_offset (word_mode
,
8936 rtx low
= lowpart_subreg (word_mode
, op0
, mode
);
8937 rtx dest_low
= lowpart_subreg (word_mode
, target
, mode
);
8938 rtx dest_high
= simplify_gen_subreg (word_mode
, target
,
8940 HOST_WIDE_INT ramount
= (BITS_PER_WORD
8941 - TREE_INT_CST_LOW (treeop1
));
8942 tree rshift
= build_int_cst (TREE_TYPE (treeop1
), ramount
);
8945 /* dest_high = src_low >> (word_size - C). */
8946 temp
= expand_variable_shift (RSHIFT_EXPR
, word_mode
, low
,
8947 rshift
, dest_high
, unsignedp
);
8948 if (temp
!= dest_high
)
8949 emit_move_insn (dest_high
, temp
);
8951 /* dest_low = src_low << C. */
8952 temp
= expand_variable_shift (LSHIFT_EXPR
, word_mode
, low
,
8953 treeop1
, dest_low
, unsignedp
);
8954 if (temp
!= dest_low
)
8955 emit_move_insn (dest_low
, temp
);
8961 if (have_insn_for (ASHIFT
, mode
))
8963 bool speed_p
= optimize_insn_for_speed_p ();
8965 rtx ret_old
= expand_variable_shift (code
, mode
, op0
,
8969 seq_old
= get_insns ();
8971 if (seq_cost (seq
, speed_p
)
8972 >= seq_cost (seq_old
, speed_p
))
8983 if (temp
== NULL_RTX
)
8984 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8986 if (code
== LSHIFT_EXPR
)
8987 temp
= REDUCE_BIT_FIELD (temp
);
8991 /* Could determine the answer when only additive constants differ. Also,
8992 the addition of one can be handled by changing the condition. */
8999 case UNORDERED_EXPR
:
9008 temp
= do_store_flag (ops
,
9009 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
9010 tmode
!= VOIDmode
? tmode
: mode
);
9014 /* Use a compare and a jump for BLKmode comparisons, or for function
9015 type comparisons is have_canonicalize_funcptr_for_compare. */
9018 || modifier
== EXPAND_STACK_PARM
9019 || ! safe_from_p (target
, treeop0
, 1)
9020 || ! safe_from_p (target
, treeop1
, 1)
9021 /* Make sure we don't have a hard reg (such as function's return
9022 value) live across basic blocks, if not optimizing. */
9023 || (!optimize
&& REG_P (target
)
9024 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
9025 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
9027 emit_move_insn (target
, const0_rtx
);
9029 rtx_code_label
*lab1
= gen_label_rtx ();
9030 jumpifnot_1 (code
, treeop0
, treeop1
, lab1
, -1);
9032 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
9033 emit_move_insn (target
, constm1_rtx
);
9035 emit_move_insn (target
, const1_rtx
);
9041 /* Get the rtx code of the operands. */
9042 op0
= expand_normal (treeop0
);
9043 op1
= expand_normal (treeop1
);
9046 target
= gen_reg_rtx (TYPE_MODE (type
));
9048 /* If target overlaps with op1, then either we need to force
9049 op1 into a pseudo (if target also overlaps with op0),
9050 or write the complex parts in reverse order. */
9051 switch (GET_CODE (target
))
9054 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
9056 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
9058 complex_expr_force_op1
:
9059 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
9060 emit_move_insn (temp
, op1
);
9064 complex_expr_swap_order
:
9065 /* Move the imaginary (op1) and real (op0) parts to their
9067 write_complex_part (target
, op1
, true);
9068 write_complex_part (target
, op0
, false);
9074 temp
= adjust_address_nv (target
,
9075 GET_MODE_INNER (GET_MODE (target
)), 0);
9076 if (reg_overlap_mentioned_p (temp
, op1
))
9078 machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
9079 temp
= adjust_address_nv (target
, imode
,
9080 GET_MODE_SIZE (imode
));
9081 if (reg_overlap_mentioned_p (temp
, op0
))
9082 goto complex_expr_force_op1
;
9083 goto complex_expr_swap_order
;
9087 if (reg_overlap_mentioned_p (target
, op1
))
9089 if (reg_overlap_mentioned_p (target
, op0
))
9090 goto complex_expr_force_op1
;
9091 goto complex_expr_swap_order
;
9096 /* Move the real (op0) and imaginary (op1) parts to their location. */
9097 write_complex_part (target
, op0
, false);
9098 write_complex_part (target
, op1
, true);
9102 case WIDEN_SUM_EXPR
:
9104 tree oprnd0
= treeop0
;
9105 tree oprnd1
= treeop1
;
9107 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9108 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9113 case REDUC_MAX_EXPR
:
9114 case REDUC_MIN_EXPR
:
9115 case REDUC_PLUS_EXPR
:
9117 op0
= expand_normal (treeop0
);
9118 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9119 machine_mode vec_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9121 if (optab_handler (this_optab
, vec_mode
) != CODE_FOR_nothing
)
9123 struct expand_operand ops
[2];
9124 enum insn_code icode
= optab_handler (this_optab
, vec_mode
);
9126 create_output_operand (&ops
[0], target
, mode
);
9127 create_input_operand (&ops
[1], op0
, vec_mode
);
9128 if (maybe_expand_insn (icode
, 2, ops
))
9130 target
= ops
[0].value
;
9131 if (GET_MODE (target
) != mode
)
9132 return gen_lowpart (tmode
, target
);
9136 /* Fall back to optab with vector result, and then extract scalar. */
9137 this_optab
= scalar_reduc_to_vector (this_optab
, type
);
9138 temp
= expand_unop (vec_mode
, this_optab
, op0
, NULL_RTX
, unsignedp
);
9140 /* The tree code produces a scalar result, but (somewhat by convention)
9141 the optab produces a vector with the result in element 0 if
9142 little-endian, or element N-1 if big-endian. So pull the scalar
9143 result out of that element. */
9144 int index
= BYTES_BIG_ENDIAN
? GET_MODE_NUNITS (vec_mode
) - 1 : 0;
9145 int bitsize
= GET_MODE_UNIT_BITSIZE (vec_mode
);
9146 temp
= extract_bit_field (temp
, bitsize
, bitsize
* index
, unsignedp
,
9147 target
, mode
, mode
);
9152 case VEC_UNPACK_HI_EXPR
:
9153 case VEC_UNPACK_LO_EXPR
:
9155 op0
= expand_normal (treeop0
);
9156 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9162 case VEC_UNPACK_FLOAT_HI_EXPR
:
9163 case VEC_UNPACK_FLOAT_LO_EXPR
:
9165 op0
= expand_normal (treeop0
);
9166 /* The signedness is determined from input operand. */
9167 temp
= expand_widen_pattern_expr
9168 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9169 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9175 case VEC_WIDEN_MULT_HI_EXPR
:
9176 case VEC_WIDEN_MULT_LO_EXPR
:
9177 case VEC_WIDEN_MULT_EVEN_EXPR
:
9178 case VEC_WIDEN_MULT_ODD_EXPR
:
9179 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9180 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9181 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9182 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9184 gcc_assert (target
);
9187 case VEC_PACK_TRUNC_EXPR
:
9188 case VEC_PACK_SAT_EXPR
:
9189 case VEC_PACK_FIX_TRUNC_EXPR
:
9190 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9194 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9195 op2
= expand_normal (treeop2
);
9197 /* Careful here: if the target doesn't support integral vector modes,
9198 a constant selection vector could wind up smooshed into a normal
9199 integral constant. */
9200 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9202 tree sel_type
= TREE_TYPE (treeop2
);
9204 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9205 TYPE_VECTOR_SUBPARTS (sel_type
));
9206 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9207 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9208 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9211 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9213 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9219 tree oprnd0
= treeop0
;
9220 tree oprnd1
= treeop1
;
9221 tree oprnd2
= treeop2
;
9224 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9225 op2
= expand_normal (oprnd2
);
9226 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9233 tree oprnd0
= treeop0
;
9234 tree oprnd1
= treeop1
;
9235 tree oprnd2
= treeop2
;
9238 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9239 op2
= expand_normal (oprnd2
);
9240 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9245 case REALIGN_LOAD_EXPR
:
9247 tree oprnd0
= treeop0
;
9248 tree oprnd1
= treeop1
;
9249 tree oprnd2
= treeop2
;
9252 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9253 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9254 op2
= expand_normal (oprnd2
);
9255 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9263 /* A COND_EXPR with its type being VOID_TYPE represents a
9264 conditional jump and is handled in
9265 expand_gimple_cond_expr. */
9266 gcc_assert (!VOID_TYPE_P (type
));
9268 /* Note that COND_EXPRs whose type is a structure or union
9269 are required to be constructed to contain assignments of
9270 a temporary variable, so that we can evaluate them here
9271 for side effect only. If type is void, we must do likewise. */
9273 gcc_assert (!TREE_ADDRESSABLE (type
)
9275 && TREE_TYPE (treeop1
) != void_type_node
9276 && TREE_TYPE (treeop2
) != void_type_node
);
9278 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9282 /* If we are not to produce a result, we have no target. Otherwise,
9283 if a target was specified use it; it will not be used as an
9284 intermediate target unless it is safe. If no target, use a
9287 if (modifier
!= EXPAND_STACK_PARM
9289 && safe_from_p (original_target
, treeop0
, 1)
9290 && GET_MODE (original_target
) == mode
9291 && !MEM_P (original_target
))
9292 temp
= original_target
;
9294 temp
= assign_temp (type
, 0, 1);
9296 do_pending_stack_adjust ();
9298 rtx_code_label
*lab0
= gen_label_rtx ();
9299 rtx_code_label
*lab1
= gen_label_rtx ();
9300 jumpifnot (treeop0
, lab0
, -1);
9301 store_expr (treeop1
, temp
,
9302 modifier
== EXPAND_STACK_PARM
,
9305 emit_jump_insn (targetm
.gen_jump (lab1
));
9308 store_expr (treeop2
, temp
,
9309 modifier
== EXPAND_STACK_PARM
,
9318 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9325 /* Here to do an ordinary binary operator. */
9327 expand_operands (treeop0
, treeop1
,
9328 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9330 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9332 if (modifier
== EXPAND_STACK_PARM
)
9334 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9335 unsignedp
, OPTAB_LIB_WIDEN
);
9337 /* Bitwise operations do not need bitfield reduction as we expect their
9338 operands being properly truncated. */
9339 if (code
== BIT_XOR_EXPR
9340 || code
== BIT_AND_EXPR
9341 || code
== BIT_IOR_EXPR
)
9343 return REDUCE_BIT_FIELD (temp
);
9345 #undef REDUCE_BIT_FIELD
9348 /* Return TRUE if expression STMT is suitable for replacement.
9349 Never consider memory loads as replaceable, because those don't ever lead
9350 into constant expressions. */
9353 stmt_is_replaceable_p (gimple
*stmt
)
9355 if (ssa_is_replaceable_p (stmt
))
9357 /* Don't move around loads. */
9358 if (!gimple_assign_single_p (stmt
)
9359 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9366 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
9367 enum expand_modifier modifier
, rtx
*alt_rtl
,
9368 bool inner_reference_p
)
9370 rtx op0
, op1
, temp
, decl_rtl
;
9373 machine_mode mode
, dmode
;
9374 enum tree_code code
= TREE_CODE (exp
);
9375 rtx subtarget
, original_target
;
9378 bool reduce_bit_field
;
9379 location_t loc
= EXPR_LOCATION (exp
);
9380 struct separate_ops ops
;
9381 tree treeop0
, treeop1
, treeop2
;
9382 tree ssa_name
= NULL_TREE
;
9385 type
= TREE_TYPE (exp
);
9386 mode
= TYPE_MODE (type
);
9387 unsignedp
= TYPE_UNSIGNED (type
);
9389 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9390 if (!VL_EXP_CLASS_P (exp
))
9391 switch (TREE_CODE_LENGTH (code
))
9394 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9395 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9396 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9406 ignore
= (target
== const0_rtx
9407 || ((CONVERT_EXPR_CODE_P (code
)
9408 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9409 && TREE_CODE (type
) == VOID_TYPE
));
9411 /* An operation in what may be a bit-field type needs the
9412 result to be reduced to the precision of the bit-field type,
9413 which is narrower than that of the type's mode. */
9414 reduce_bit_field
= (!ignore
9415 && INTEGRAL_TYPE_P (type
)
9416 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9418 /* If we are going to ignore this result, we need only do something
9419 if there is a side-effect somewhere in the expression. If there
9420 is, short-circuit the most common cases here. Note that we must
9421 not call expand_expr with anything but const0_rtx in case this
9422 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9426 if (! TREE_SIDE_EFFECTS (exp
))
9429 /* Ensure we reference a volatile object even if value is ignored, but
9430 don't do this if all we are doing is taking its address. */
9431 if (TREE_THIS_VOLATILE (exp
)
9432 && TREE_CODE (exp
) != FUNCTION_DECL
9433 && mode
!= VOIDmode
&& mode
!= BLKmode
9434 && modifier
!= EXPAND_CONST_ADDRESS
)
9436 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9442 if (TREE_CODE_CLASS (code
) == tcc_unary
9443 || code
== BIT_FIELD_REF
9444 || code
== COMPONENT_REF
9445 || code
== INDIRECT_REF
)
9446 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9449 else if (TREE_CODE_CLASS (code
) == tcc_binary
9450 || TREE_CODE_CLASS (code
) == tcc_comparison
9451 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9453 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9454 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9461 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9464 /* Use subtarget as the target for operand 0 of a binary operation. */
9465 subtarget
= get_subtarget (target
);
9466 original_target
= target
;
9472 tree function
= decl_function_context (exp
);
9474 temp
= label_rtx (exp
);
9475 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9477 if (function
!= current_function_decl
9479 LABEL_REF_NONLOCAL_P (temp
) = 1;
9481 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9486 /* ??? ivopts calls expander, without any preparation from
9487 out-of-ssa. So fake instructions as if this was an access to the
9488 base variable. This unnecessarily allocates a pseudo, see how we can
9489 reuse it, if partition base vars have it set already. */
9490 if (!currently_expanding_to_rtl
)
9492 tree var
= SSA_NAME_VAR (exp
);
9493 if (var
&& DECL_RTL_SET_P (var
))
9494 return DECL_RTL (var
);
9495 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9496 LAST_VIRTUAL_REGISTER
+ 1);
9499 g
= get_gimple_for_ssa_name (exp
);
9500 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9502 && modifier
== EXPAND_INITIALIZER
9503 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9504 && (optimize
|| !SSA_NAME_VAR (exp
)
9505 || DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9506 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9507 g
= SSA_NAME_DEF_STMT (exp
);
9511 location_t saved_loc
= curr_insn_location ();
9512 location_t loc
= gimple_location (g
);
9513 if (loc
!= UNKNOWN_LOCATION
)
9514 set_curr_insn_location (loc
);
9515 ops
.code
= gimple_assign_rhs_code (g
);
9516 switch (get_gimple_rhs_class (ops
.code
))
9518 case GIMPLE_TERNARY_RHS
:
9519 ops
.op2
= gimple_assign_rhs3 (g
);
9521 case GIMPLE_BINARY_RHS
:
9522 ops
.op1
= gimple_assign_rhs2 (g
);
9524 /* Try to expand conditonal compare. */
9525 if (targetm
.gen_ccmp_first
)
9527 gcc_checking_assert (targetm
.gen_ccmp_next
!= NULL
);
9528 r
= expand_ccmp_expr (g
);
9533 case GIMPLE_UNARY_RHS
:
9534 ops
.op0
= gimple_assign_rhs1 (g
);
9535 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9537 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9539 case GIMPLE_SINGLE_RHS
:
9541 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9542 tmode
, modifier
, NULL
, inner_reference_p
);
9548 set_curr_insn_location (saved_loc
);
9549 if (REG_P (r
) && !REG_EXPR (r
))
9550 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9555 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9556 exp
= SSA_NAME_VAR (ssa_name
);
9557 goto expand_decl_rtl
;
9561 /* If a static var's type was incomplete when the decl was written,
9562 but the type is complete now, lay out the decl now. */
9563 if (DECL_SIZE (exp
) == 0
9564 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9565 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9566 layout_decl (exp
, 0);
9568 /* ... fall through ... */
9572 decl_rtl
= DECL_RTL (exp
);
9574 gcc_assert (decl_rtl
);
9575 decl_rtl
= copy_rtx (decl_rtl
);
9576 /* Record writes to register variables. */
9577 if (modifier
== EXPAND_WRITE
9579 && HARD_REGISTER_P (decl_rtl
))
9580 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9581 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9583 /* Ensure variable marked as used even if it doesn't go through
9584 a parser. If it hasn't be used yet, write out an external
9587 TREE_USED (exp
) = 1;
9589 /* Show we haven't gotten RTL for this yet. */
9592 /* Variables inherited from containing functions should have
9593 been lowered by this point. */
9595 context
= decl_function_context (exp
);
9597 || SCOPE_FILE_SCOPE_P (context
)
9598 || context
== current_function_decl
9599 || TREE_STATIC (exp
)
9600 || DECL_EXTERNAL (exp
)
9601 /* ??? C++ creates functions that are not TREE_STATIC. */
9602 || TREE_CODE (exp
) == FUNCTION_DECL
);
9604 /* This is the case of an array whose size is to be determined
9605 from its initializer, while the initializer is still being parsed.
9606 ??? We aren't parsing while expanding anymore. */
9608 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9609 temp
= validize_mem (decl_rtl
);
9611 /* If DECL_RTL is memory, we are in the normal case and the
9612 address is not valid, get the address into a register. */
9614 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9617 *alt_rtl
= decl_rtl
;
9618 decl_rtl
= use_anchored_address (decl_rtl
);
9619 if (modifier
!= EXPAND_CONST_ADDRESS
9620 && modifier
!= EXPAND_SUM
9621 && !memory_address_addr_space_p (exp
? DECL_MODE (exp
)
9622 : GET_MODE (decl_rtl
),
9624 MEM_ADDR_SPACE (decl_rtl
)))
9625 temp
= replace_equiv_address (decl_rtl
,
9626 copy_rtx (XEXP (decl_rtl
, 0)));
9629 /* If we got something, return it. But first, set the alignment
9630 if the address is a register. */
9633 if (exp
&& MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9634 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9640 dmode
= DECL_MODE (exp
);
9642 dmode
= TYPE_MODE (TREE_TYPE (ssa_name
));
9644 /* If the mode of DECL_RTL does not match that of the decl,
9645 there are two cases: we are dealing with a BLKmode value
9646 that is returned in a register, or we are dealing with
9647 a promoted value. In the latter case, return a SUBREG
9648 of the wanted mode, but mark it so that we know that it
9649 was already extended. */
9650 if (REG_P (decl_rtl
)
9652 && GET_MODE (decl_rtl
) != dmode
)
9656 /* Get the signedness to be used for this variable. Ensure we get
9657 the same mode we got when the variable was declared. */
9658 if (code
!= SSA_NAME
)
9659 pmode
= promote_decl_mode (exp
, &unsignedp
);
9660 else if ((g
= SSA_NAME_DEF_STMT (ssa_name
))
9661 && gimple_code (g
) == GIMPLE_CALL
9662 && !gimple_call_internal_p (g
))
9663 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9664 gimple_call_fntype (g
),
9667 pmode
= promote_ssa_mode (ssa_name
, &unsignedp
);
9668 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9670 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9671 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9672 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9679 /* Given that TYPE_PRECISION (type) is not always equal to
9680 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9681 the former to the latter according to the signedness of the
9683 temp
= immed_wide_int_const (wide_int::from
9685 GET_MODE_PRECISION (TYPE_MODE (type
)),
9692 tree tmp
= NULL_TREE
;
9693 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9694 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9695 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9696 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9697 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9698 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9699 return const_vector_from_tree (exp
);
9700 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9702 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9704 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9708 vec
<constructor_elt
, va_gc
> *v
;
9710 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9711 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9712 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9713 tmp
= build_constructor (type
, v
);
9715 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9720 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9723 /* If optimized, generate immediate CONST_DOUBLE
9724 which will be turned into memory by reload if necessary.
9726 We used to force a register so that loop.c could see it. But
9727 this does not allow gen_* patterns to perform optimizations with
9728 the constants. It also produces two insns in cases like "x = 1.0;".
9729 On most machines, floating-point constants are not permitted in
9730 many insns, so we'd end up copying it to a register in any case.
9732 Now, we do the copying in expand_binop, if appropriate. */
9733 return const_double_from_real_value (TREE_REAL_CST (exp
),
9734 TYPE_MODE (TREE_TYPE (exp
)));
9737 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9738 TYPE_MODE (TREE_TYPE (exp
)));
9741 /* Handle evaluating a complex constant in a CONCAT target. */
9742 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9744 machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9747 rtarg
= XEXP (original_target
, 0);
9748 itarg
= XEXP (original_target
, 1);
9750 /* Move the real and imaginary parts separately. */
9751 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9752 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9755 emit_move_insn (rtarg
, op0
);
9757 emit_move_insn (itarg
, op1
);
9759 return original_target
;
9762 /* ... fall through ... */
9765 temp
= expand_expr_constant (exp
, 1, modifier
);
9767 /* temp contains a constant address.
9768 On RISC machines where a constant address isn't valid,
9769 make some insns to get that address into a register. */
9770 if (modifier
!= EXPAND_CONST_ADDRESS
9771 && modifier
!= EXPAND_INITIALIZER
9772 && modifier
!= EXPAND_SUM
9773 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9774 MEM_ADDR_SPACE (temp
)))
9775 return replace_equiv_address (temp
,
9776 copy_rtx (XEXP (temp
, 0)));
9782 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
9785 if (!SAVE_EXPR_RESOLVED_P (exp
))
9787 /* We can indeed still hit this case, typically via builtin
9788 expanders calling save_expr immediately before expanding
9789 something. Assume this means that we only have to deal
9790 with non-BLKmode values. */
9791 gcc_assert (GET_MODE (ret
) != BLKmode
);
9793 val
= build_decl (curr_insn_location (),
9794 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9795 DECL_ARTIFICIAL (val
) = 1;
9796 DECL_IGNORED_P (val
) = 1;
9798 TREE_OPERAND (exp
, 0) = treeop0
;
9799 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9801 if (!CONSTANT_P (ret
))
9802 ret
= copy_to_reg (ret
);
9803 SET_DECL_RTL (val
, ret
);
9811 /* If we don't need the result, just ensure we evaluate any
9815 unsigned HOST_WIDE_INT idx
;
9818 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9819 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9824 return expand_constructor (exp
, target
, modifier
, false);
9826 case TARGET_MEM_REF
:
9829 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9830 enum insn_code icode
;
9833 op0
= addr_for_mem_ref (exp
, as
, true);
9834 op0
= memory_address_addr_space (mode
, op0
, as
);
9835 temp
= gen_rtx_MEM (mode
, op0
);
9836 set_mem_attributes (temp
, exp
, 0);
9837 set_mem_addr_space (temp
, as
);
9838 align
= get_object_alignment (exp
);
9839 if (modifier
!= EXPAND_WRITE
9840 && modifier
!= EXPAND_MEMORY
9842 && align
< GET_MODE_ALIGNMENT (mode
)
9843 /* If the target does not have special handling for unaligned
9844 loads of mode then it can use regular moves for them. */
9845 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9846 != CODE_FOR_nothing
))
9848 struct expand_operand ops
[2];
9850 /* We've already validated the memory, and we're creating a
9851 new pseudo destination. The predicates really can't fail,
9852 nor can the generator. */
9853 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9854 create_fixed_operand (&ops
[1], temp
);
9855 expand_insn (icode
, 2, ops
);
9856 temp
= ops
[0].value
;
9864 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9865 machine_mode address_mode
;
9866 tree base
= TREE_OPERAND (exp
, 0);
9868 enum insn_code icode
;
9870 /* Handle expansion of non-aliased memory with non-BLKmode. That
9871 might end up in a register. */
9872 if (mem_ref_refers_to_non_mem_p (exp
))
9874 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
9875 base
= TREE_OPERAND (base
, 0);
9877 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9878 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9879 == tree_to_uhwi (TYPE_SIZE (type
))))
9880 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9881 target
, tmode
, modifier
);
9882 if (TYPE_MODE (type
) == BLKmode
)
9884 temp
= assign_stack_temp (DECL_MODE (base
),
9885 GET_MODE_SIZE (DECL_MODE (base
)));
9886 store_expr (base
, temp
, 0, false);
9887 temp
= adjust_address (temp
, BLKmode
, offset
);
9888 set_mem_size (temp
, int_size_in_bytes (type
));
9891 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9892 bitsize_int (offset
* BITS_PER_UNIT
));
9893 return expand_expr (exp
, target
, tmode
, modifier
);
9895 address_mode
= targetm
.addr_space
.address_mode (as
);
9896 base
= TREE_OPERAND (exp
, 0);
9897 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9899 tree mask
= gimple_assign_rhs2 (def_stmt
);
9900 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9901 gimple_assign_rhs1 (def_stmt
), mask
);
9902 TREE_OPERAND (exp
, 0) = base
;
9904 align
= get_object_alignment (exp
);
9905 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9906 op0
= memory_address_addr_space (mode
, op0
, as
);
9907 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9909 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
9910 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9911 op0
= memory_address_addr_space (mode
, op0
, as
);
9913 temp
= gen_rtx_MEM (mode
, op0
);
9914 set_mem_attributes (temp
, exp
, 0);
9915 set_mem_addr_space (temp
, as
);
9916 if (TREE_THIS_VOLATILE (exp
))
9917 MEM_VOLATILE_P (temp
) = 1;
9918 if (modifier
!= EXPAND_WRITE
9919 && modifier
!= EXPAND_MEMORY
9920 && !inner_reference_p
9922 && align
< GET_MODE_ALIGNMENT (mode
))
9924 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9925 != CODE_FOR_nothing
)
9927 struct expand_operand ops
[2];
9929 /* We've already validated the memory, and we're creating a
9930 new pseudo destination. The predicates really can't fail,
9931 nor can the generator. */
9932 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9933 create_fixed_operand (&ops
[1], temp
);
9934 expand_insn (icode
, 2, ops
);
9935 temp
= ops
[0].value
;
9937 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9938 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9939 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9940 (modifier
== EXPAND_STACK_PARM
9941 ? NULL_RTX
: target
),
9950 tree array
= treeop0
;
9951 tree index
= treeop1
;
9954 /* Fold an expression like: "foo"[2].
9955 This is not done in fold so it won't happen inside &.
9956 Don't fold if this is for wide characters since it's too
9957 difficult to do correctly and this is a very rare case. */
9959 if (modifier
!= EXPAND_CONST_ADDRESS
9960 && modifier
!= EXPAND_INITIALIZER
9961 && modifier
!= EXPAND_MEMORY
)
9963 tree t
= fold_read_from_constant_string (exp
);
9966 return expand_expr (t
, target
, tmode
, modifier
);
9969 /* If this is a constant index into a constant array,
9970 just get the value from the array. Handle both the cases when
9971 we have an explicit constructor and when our operand is a variable
9972 that was declared const. */
9974 if (modifier
!= EXPAND_CONST_ADDRESS
9975 && modifier
!= EXPAND_INITIALIZER
9976 && modifier
!= EXPAND_MEMORY
9977 && TREE_CODE (array
) == CONSTRUCTOR
9978 && ! TREE_SIDE_EFFECTS (array
)
9979 && TREE_CODE (index
) == INTEGER_CST
)
9981 unsigned HOST_WIDE_INT ix
;
9984 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9986 if (tree_int_cst_equal (field
, index
))
9988 if (!TREE_SIDE_EFFECTS (value
))
9989 return expand_expr (fold (value
), target
, tmode
, modifier
);
9994 else if (optimize
>= 1
9995 && modifier
!= EXPAND_CONST_ADDRESS
9996 && modifier
!= EXPAND_INITIALIZER
9997 && modifier
!= EXPAND_MEMORY
9998 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9999 && TREE_CODE (index
) == INTEGER_CST
10000 && (TREE_CODE (array
) == VAR_DECL
10001 || TREE_CODE (array
) == CONST_DECL
)
10002 && (init
= ctor_for_folding (array
)) != error_mark_node
)
10004 if (init
== NULL_TREE
)
10006 tree value
= build_zero_cst (type
);
10007 if (TREE_CODE (value
) == CONSTRUCTOR
)
10009 /* If VALUE is a CONSTRUCTOR, this optimization is only
10010 useful if this doesn't store the CONSTRUCTOR into
10011 memory. If it does, it is more efficient to just
10012 load the data from the array directly. */
10013 rtx ret
= expand_constructor (value
, target
,
10015 if (ret
== NULL_RTX
)
10020 return expand_expr (value
, target
, tmode
, modifier
);
10022 else if (TREE_CODE (init
) == CONSTRUCTOR
)
10024 unsigned HOST_WIDE_INT ix
;
10027 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
10029 if (tree_int_cst_equal (field
, index
))
10031 if (TREE_SIDE_EFFECTS (value
))
10034 if (TREE_CODE (value
) == CONSTRUCTOR
)
10036 /* If VALUE is a CONSTRUCTOR, this
10037 optimization is only useful if
10038 this doesn't store the CONSTRUCTOR
10039 into memory. If it does, it is more
10040 efficient to just load the data from
10041 the array directly. */
10042 rtx ret
= expand_constructor (value
, target
,
10044 if (ret
== NULL_RTX
)
10049 expand_expr (fold (value
), target
, tmode
, modifier
);
10052 else if (TREE_CODE (init
) == STRING_CST
)
10054 tree low_bound
= array_ref_low_bound (exp
);
10055 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
10057 /* Optimize the special case of a zero lower bound.
10059 We convert the lower bound to sizetype to avoid problems
10060 with constant folding. E.g. suppose the lower bound is
10061 1 and its mode is QI. Without the conversion
10062 (ARRAY + (INDEX - (unsigned char)1))
10064 (ARRAY + (-(unsigned char)1) + INDEX)
10066 (ARRAY + 255 + INDEX). Oops! */
10067 if (!integer_zerop (low_bound
))
10068 index1
= size_diffop_loc (loc
, index1
,
10069 fold_convert_loc (loc
, sizetype
,
10072 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
10074 tree type
= TREE_TYPE (TREE_TYPE (init
));
10075 machine_mode mode
= TYPE_MODE (type
);
10077 if (GET_MODE_CLASS (mode
) == MODE_INT
10078 && GET_MODE_SIZE (mode
) == 1)
10079 return gen_int_mode (TREE_STRING_POINTER (init
)
10080 [TREE_INT_CST_LOW (index1
)],
10086 goto normal_inner_ref
;
10088 case COMPONENT_REF
:
10089 /* If the operand is a CONSTRUCTOR, we can just extract the
10090 appropriate field if it is present. */
10091 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
10093 unsigned HOST_WIDE_INT idx
;
10096 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
10098 if (field
== treeop1
10099 /* We can normally use the value of the field in the
10100 CONSTRUCTOR. However, if this is a bitfield in
10101 an integral mode that we can fit in a HOST_WIDE_INT,
10102 we must mask only the number of bits in the bitfield,
10103 since this is done implicitly by the constructor. If
10104 the bitfield does not meet either of those conditions,
10105 we can't do this optimization. */
10106 && (! DECL_BIT_FIELD (field
)
10107 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
10108 && (GET_MODE_PRECISION (DECL_MODE (field
))
10109 <= HOST_BITS_PER_WIDE_INT
))))
10111 if (DECL_BIT_FIELD (field
)
10112 && modifier
== EXPAND_STACK_PARM
)
10114 op0
= expand_expr (value
, target
, tmode
, modifier
);
10115 if (DECL_BIT_FIELD (field
))
10117 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
10118 machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
10120 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
10122 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
10124 op0
= expand_and (imode
, op0
, op1
, target
);
10128 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10130 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10132 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10140 goto normal_inner_ref
;
10142 case BIT_FIELD_REF
:
10143 case ARRAY_RANGE_REF
:
10146 machine_mode mode1
, mode2
;
10147 HOST_WIDE_INT bitsize
, bitpos
;
10149 int volatilep
= 0, must_force_mem
;
10150 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
10151 &mode1
, &unsignedp
, &volatilep
, true);
10152 rtx orig_op0
, memloc
;
10153 bool clear_mem_expr
= false;
10155 /* If we got back the original object, something is wrong. Perhaps
10156 we are evaluating an expression too early. In any event, don't
10157 infinitely recurse. */
10158 gcc_assert (tem
!= exp
);
10160 /* If TEM's type is a union of variable size, pass TARGET to the inner
10161 computation, since it will need a temporary and TARGET is known
10162 to have to do. This occurs in unchecked conversion in Ada. */
10164 = expand_expr_real (tem
,
10165 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10166 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10167 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10169 && modifier
!= EXPAND_STACK_PARM
10170 ? target
: NULL_RTX
),
10172 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10175 /* If the field has a mode, we want to access it in the
10176 field's mode, not the computed mode.
10177 If a MEM has VOIDmode (external with incomplete type),
10178 use BLKmode for it instead. */
10181 if (mode1
!= VOIDmode
)
10182 op0
= adjust_address (op0
, mode1
, 0);
10183 else if (GET_MODE (op0
) == VOIDmode
)
10184 op0
= adjust_address (op0
, BLKmode
, 0);
10188 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10190 /* If we have either an offset, a BLKmode result, or a reference
10191 outside the underlying object, we must force it to memory.
10192 Such a case can occur in Ada if we have unchecked conversion
10193 of an expression from a scalar type to an aggregate type or
10194 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10195 passed a partially uninitialized object or a view-conversion
10196 to a larger size. */
10197 must_force_mem
= (offset
10198 || mode1
== BLKmode
10199 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10201 /* Handle CONCAT first. */
10202 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10205 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
10208 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10211 op0
= XEXP (op0
, 0);
10212 mode2
= GET_MODE (op0
);
10214 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10215 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10219 op0
= XEXP (op0
, 1);
10221 mode2
= GET_MODE (op0
);
10224 /* Otherwise force into memory. */
10225 must_force_mem
= 1;
10228 /* If this is a constant, put it in a register if it is a legitimate
10229 constant and we don't need a memory reference. */
10230 if (CONSTANT_P (op0
)
10231 && mode2
!= BLKmode
10232 && targetm
.legitimate_constant_p (mode2
, op0
)
10233 && !must_force_mem
)
10234 op0
= force_reg (mode2
, op0
);
10236 /* Otherwise, if this is a constant, try to force it to the constant
10237 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10238 is a legitimate constant. */
10239 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10240 op0
= validize_mem (memloc
);
10242 /* Otherwise, if this is a constant or the object is not in memory
10243 and need be, put it there. */
10244 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10246 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10247 emit_move_insn (memloc
, op0
);
10249 clear_mem_expr
= true;
10254 machine_mode address_mode
;
10255 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10258 gcc_assert (MEM_P (op0
));
10260 address_mode
= get_address_mode (op0
);
10261 if (GET_MODE (offset_rtx
) != address_mode
)
10263 /* We cannot be sure that the RTL in offset_rtx is valid outside
10264 of a memory address context, so force it into a register
10265 before attempting to convert it to the desired mode. */
10266 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
10267 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10270 /* See the comment in expand_assignment for the rationale. */
10271 if (mode1
!= VOIDmode
10274 && (bitpos
% bitsize
) == 0
10275 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10276 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10278 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10282 op0
= offset_address (op0
, offset_rtx
,
10283 highest_pow2_factor (offset
));
10286 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10287 record its alignment as BIGGEST_ALIGNMENT. */
10288 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10289 && is_aligning_offset (offset
, tem
))
10290 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10292 /* Don't forget about volatility even if this is a bitfield. */
10293 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10295 if (op0
== orig_op0
)
10296 op0
= copy_rtx (op0
);
10298 MEM_VOLATILE_P (op0
) = 1;
10301 /* In cases where an aligned union has an unaligned object
10302 as a field, we might be extracting a BLKmode value from
10303 an integer-mode (e.g., SImode) object. Handle this case
10304 by doing the extract into an object as wide as the field
10305 (which we know to be the width of a basic mode), then
10306 storing into memory, and changing the mode to BLKmode. */
10307 if (mode1
== VOIDmode
10308 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10309 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10310 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10311 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10312 && modifier
!= EXPAND_CONST_ADDRESS
10313 && modifier
!= EXPAND_INITIALIZER
10314 && modifier
!= EXPAND_MEMORY
)
10315 /* If the bitfield is volatile and the bitsize
10316 is narrower than the access size of the bitfield,
10317 we need to extract bitfields from the access. */
10318 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10319 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10320 && mode1
!= BLKmode
10321 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10322 /* If the field isn't aligned enough to fetch as a memref,
10323 fetch it as a bit field. */
10324 || (mode1
!= BLKmode
10325 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10326 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10328 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10329 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10330 && modifier
!= EXPAND_MEMORY
10331 && ((modifier
== EXPAND_CONST_ADDRESS
10332 || modifier
== EXPAND_INITIALIZER
)
10334 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10335 || (bitpos
% BITS_PER_UNIT
!= 0)))
10336 /* If the type and the field are a constant size and the
10337 size of the type isn't the same size as the bitfield,
10338 we must use bitfield operations. */
10340 && TYPE_SIZE (TREE_TYPE (exp
))
10341 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10342 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10345 machine_mode ext_mode
= mode
;
10347 if (ext_mode
== BLKmode
10348 && ! (target
!= 0 && MEM_P (op0
)
10350 && bitpos
% BITS_PER_UNIT
== 0))
10351 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10353 if (ext_mode
== BLKmode
)
10356 target
= assign_temp (type
, 1, 1);
10358 /* ??? Unlike the similar test a few lines below, this one is
10359 very likely obsolete. */
10363 /* In this case, BITPOS must start at a byte boundary and
10364 TARGET, if specified, must be a MEM. */
10365 gcc_assert (MEM_P (op0
)
10366 && (!target
|| MEM_P (target
))
10367 && !(bitpos
% BITS_PER_UNIT
));
10369 emit_block_move (target
,
10370 adjust_address (op0
, VOIDmode
,
10371 bitpos
/ BITS_PER_UNIT
),
10372 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10374 (modifier
== EXPAND_STACK_PARM
10375 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10380 /* If we have nothing to extract, the result will be 0 for targets
10381 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10382 return 0 for the sake of consistency, as reading a zero-sized
10383 bitfield is valid in Ada and the value is fully specified. */
10387 op0
= validize_mem (op0
);
10389 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10390 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10392 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10393 (modifier
== EXPAND_STACK_PARM
10394 ? NULL_RTX
: target
),
10395 ext_mode
, ext_mode
);
10397 /* If the result is a record type and BITSIZE is narrower than
10398 the mode of OP0, an integral mode, and this is a big endian
10399 machine, we must put the field into the high-order bits. */
10400 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10401 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10402 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10403 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10404 GET_MODE_BITSIZE (GET_MODE (op0
))
10405 - bitsize
, op0
, 1);
10407 /* If the result type is BLKmode, store the data into a temporary
10408 of the appropriate type, but with the mode corresponding to the
10409 mode for the data we have (op0's mode). */
10410 if (mode
== BLKmode
)
10413 = assign_stack_temp_for_type (ext_mode
,
10414 GET_MODE_BITSIZE (ext_mode
),
10416 emit_move_insn (new_rtx
, op0
);
10417 op0
= copy_rtx (new_rtx
);
10418 PUT_MODE (op0
, BLKmode
);
10424 /* If the result is BLKmode, use that to access the object
10426 if (mode
== BLKmode
)
10429 /* Get a reference to just this component. */
10430 if (modifier
== EXPAND_CONST_ADDRESS
10431 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10432 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10434 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10436 if (op0
== orig_op0
)
10437 op0
= copy_rtx (op0
);
10439 set_mem_attributes (op0
, exp
, 0);
10441 if (REG_P (XEXP (op0
, 0)))
10442 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10444 /* If op0 is a temporary because the original expressions was forced
10445 to memory, clear MEM_EXPR so that the original expression cannot
10446 be marked as addressable through MEM_EXPR of the temporary. */
10447 if (clear_mem_expr
)
10448 set_mem_expr (op0
, NULL_TREE
);
10450 MEM_VOLATILE_P (op0
) |= volatilep
;
10451 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10452 || modifier
== EXPAND_CONST_ADDRESS
10453 || modifier
== EXPAND_INITIALIZER
)
10457 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10459 convert_move (target
, op0
, unsignedp
);
10464 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10467 /* All valid uses of __builtin_va_arg_pack () are removed during
10469 if (CALL_EXPR_VA_ARG_PACK (exp
))
10470 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10472 tree fndecl
= get_callee_fndecl (exp
), attr
;
10475 && (attr
= lookup_attribute ("error",
10476 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10477 error ("%Kcall to %qs declared with attribute error: %s",
10478 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10479 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10481 && (attr
= lookup_attribute ("warning",
10482 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10483 warning_at (tree_nonartificial_location (exp
),
10484 0, "%Kcall to %qs declared with attribute warning: %s",
10485 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10486 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10488 /* Check for a built-in function. */
10489 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10491 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10492 if (CALL_WITH_BOUNDS_P (exp
))
10493 return expand_builtin_with_bounds (exp
, target
, subtarget
,
10496 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10499 return expand_call (exp
, target
, ignore
);
10501 case VIEW_CONVERT_EXPR
:
10504 /* If we are converting to BLKmode, try to avoid an intermediate
10505 temporary by fetching an inner memory reference. */
10506 if (mode
== BLKmode
10507 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10508 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10509 && handled_component_p (treeop0
))
10511 machine_mode mode1
;
10512 HOST_WIDE_INT bitsize
, bitpos
;
10517 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10518 &offset
, &mode1
, &unsignedp
, &volatilep
,
10522 /* ??? We should work harder and deal with non-zero offsets. */
10524 && (bitpos
% BITS_PER_UNIT
) == 0
10526 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10528 /* See the normal_inner_ref case for the rationale. */
10530 = expand_expr_real (tem
,
10531 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10532 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10534 && modifier
!= EXPAND_STACK_PARM
10535 ? target
: NULL_RTX
),
10537 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10540 if (MEM_P (orig_op0
))
10544 /* Get a reference to just this component. */
10545 if (modifier
== EXPAND_CONST_ADDRESS
10546 || modifier
== EXPAND_SUM
10547 || modifier
== EXPAND_INITIALIZER
)
10548 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10550 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10552 if (op0
== orig_op0
)
10553 op0
= copy_rtx (op0
);
10555 set_mem_attributes (op0
, treeop0
, 0);
10556 if (REG_P (XEXP (op0
, 0)))
10557 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10559 MEM_VOLATILE_P (op0
) |= volatilep
;
10565 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10566 NULL
, inner_reference_p
);
10568 /* If the input and output modes are both the same, we are done. */
10569 if (mode
== GET_MODE (op0
))
10571 /* If neither mode is BLKmode, and both modes are the same size
10572 then we can use gen_lowpart. */
10573 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10574 && (GET_MODE_PRECISION (mode
)
10575 == GET_MODE_PRECISION (GET_MODE (op0
)))
10576 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10578 if (GET_CODE (op0
) == SUBREG
)
10579 op0
= force_reg (GET_MODE (op0
), op0
);
10580 temp
= gen_lowpart_common (mode
, op0
);
10585 if (!REG_P (op0
) && !MEM_P (op0
))
10586 op0
= force_reg (GET_MODE (op0
), op0
);
10587 op0
= gen_lowpart (mode
, op0
);
10590 /* If both types are integral, convert from one mode to the other. */
10591 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10592 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10593 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10594 /* If the output type is a bit-field type, do an extraction. */
10595 else if (reduce_bit_field
)
10596 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10597 TYPE_UNSIGNED (type
), NULL_RTX
,
10599 /* As a last resort, spill op0 to memory, and reload it in a
10601 else if (!MEM_P (op0
))
10603 /* If the operand is not a MEM, force it into memory. Since we
10604 are going to be changing the mode of the MEM, don't call
10605 force_const_mem for constants because we don't allow pool
10606 constants to change mode. */
10607 tree inner_type
= TREE_TYPE (treeop0
);
10609 gcc_assert (!TREE_ADDRESSABLE (exp
));
10611 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10613 = assign_stack_temp_for_type
10614 (TYPE_MODE (inner_type
),
10615 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10617 emit_move_insn (target
, op0
);
10621 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10622 output type is such that the operand is known to be aligned, indicate
10623 that it is. Otherwise, we need only be concerned about alignment for
10624 non-BLKmode results. */
10627 enum insn_code icode
;
10629 if (TYPE_ALIGN_OK (type
))
10631 /* ??? Copying the MEM without substantially changing it might
10632 run afoul of the code handling volatile memory references in
10633 store_expr, which assumes that TARGET is returned unmodified
10634 if it has been used. */
10635 op0
= copy_rtx (op0
);
10636 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10638 else if (modifier
!= EXPAND_WRITE
10639 && modifier
!= EXPAND_MEMORY
10640 && !inner_reference_p
10642 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10644 /* If the target does have special handling for unaligned
10645 loads of mode then use them. */
10646 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10647 != CODE_FOR_nothing
)
10651 op0
= adjust_address (op0
, mode
, 0);
10652 /* We've already validated the memory, and we're creating a
10653 new pseudo destination. The predicates really can't
10655 reg
= gen_reg_rtx (mode
);
10657 /* Nor can the insn generator. */
10658 rtx_insn
*insn
= GEN_FCN (icode
) (reg
, op0
);
10662 else if (STRICT_ALIGNMENT
)
10664 tree inner_type
= TREE_TYPE (treeop0
);
10665 HOST_WIDE_INT temp_size
10666 = MAX (int_size_in_bytes (inner_type
),
10667 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10669 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10670 rtx new_with_op0_mode
10671 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10673 gcc_assert (!TREE_ADDRESSABLE (exp
));
10675 if (GET_MODE (op0
) == BLKmode
)
10676 emit_block_move (new_with_op0_mode
, op0
,
10677 GEN_INT (GET_MODE_SIZE (mode
)),
10678 (modifier
== EXPAND_STACK_PARM
10679 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10681 emit_move_insn (new_with_op0_mode
, op0
);
10687 op0
= adjust_address (op0
, mode
, 0);
10694 tree lhs
= treeop0
;
10695 tree rhs
= treeop1
;
10696 gcc_assert (ignore
);
10698 /* Check for |= or &= of a bitfield of size one into another bitfield
10699 of size 1. In this case, (unless we need the result of the
10700 assignment) we can do this more efficiently with a
10701 test followed by an assignment, if necessary.
10703 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10704 things change so we do, this code should be enhanced to
10706 if (TREE_CODE (lhs
) == COMPONENT_REF
10707 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10708 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10709 && TREE_OPERAND (rhs
, 0) == lhs
10710 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10711 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10712 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10714 rtx_code_label
*label
= gen_label_rtx ();
10715 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10716 do_jump (TREE_OPERAND (rhs
, 1),
10718 value
? 0 : label
, -1);
10719 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10721 do_pending_stack_adjust ();
10722 emit_label (label
);
10726 expand_assignment (lhs
, rhs
, false);
10731 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10733 case REALPART_EXPR
:
10734 op0
= expand_normal (treeop0
);
10735 return read_complex_part (op0
, false);
10737 case IMAGPART_EXPR
:
10738 op0
= expand_normal (treeop0
);
10739 return read_complex_part (op0
, true);
10746 /* Expanded in cfgexpand.c. */
10747 gcc_unreachable ();
10749 case TRY_CATCH_EXPR
:
10751 case EH_FILTER_EXPR
:
10752 case TRY_FINALLY_EXPR
:
10753 /* Lowered by tree-eh.c. */
10754 gcc_unreachable ();
10756 case WITH_CLEANUP_EXPR
:
10757 case CLEANUP_POINT_EXPR
:
10759 case CASE_LABEL_EXPR
:
10764 case COMPOUND_EXPR
:
10765 case PREINCREMENT_EXPR
:
10766 case PREDECREMENT_EXPR
:
10767 case POSTINCREMENT_EXPR
:
10768 case POSTDECREMENT_EXPR
:
10771 case COMPOUND_LITERAL_EXPR
:
10772 /* Lowered by gimplify.c. */
10773 gcc_unreachable ();
10776 /* Function descriptors are not valid except for as
10777 initialization constants, and should not be expanded. */
10778 gcc_unreachable ();
10780 case WITH_SIZE_EXPR
:
10781 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10782 have pulled out the size to use in whatever context it needed. */
10783 return expand_expr_real (treeop0
, original_target
, tmode
,
10784 modifier
, alt_rtl
, inner_reference_p
);
10787 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10791 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10792 signedness of TYPE), possibly returning the result in TARGET. */
10794 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10796 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10797 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10799 /* For constant values, reduce using build_int_cst_type. */
10800 if (CONST_INT_P (exp
))
10802 HOST_WIDE_INT value
= INTVAL (exp
);
10803 tree t
= build_int_cst_type (type
, value
);
10804 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10806 else if (TYPE_UNSIGNED (type
))
10808 machine_mode mode
= GET_MODE (exp
);
10809 rtx mask
= immed_wide_int_const
10810 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
10811 return expand_and (mode
, exp
, mask
, target
);
10815 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10816 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10817 exp
, count
, target
, 0);
10818 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10819 exp
, count
, target
, 0);
10823 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10824 when applied to the address of EXP produces an address known to be
10825 aligned more than BIGGEST_ALIGNMENT. */
10828 is_aligning_offset (const_tree offset
, const_tree exp
)
10830 /* Strip off any conversions. */
10831 while (CONVERT_EXPR_P (offset
))
10832 offset
= TREE_OPERAND (offset
, 0);
10834 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10835 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10836 if (TREE_CODE (offset
) != BIT_AND_EXPR
10837 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10838 || compare_tree_int (TREE_OPERAND (offset
, 1),
10839 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10840 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10843 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10844 It must be NEGATE_EXPR. Then strip any more conversions. */
10845 offset
= TREE_OPERAND (offset
, 0);
10846 while (CONVERT_EXPR_P (offset
))
10847 offset
= TREE_OPERAND (offset
, 0);
10849 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10852 offset
= TREE_OPERAND (offset
, 0);
10853 while (CONVERT_EXPR_P (offset
))
10854 offset
= TREE_OPERAND (offset
, 0);
10856 /* This must now be the address of EXP. */
10857 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10860 /* Return the tree node if an ARG corresponds to a string constant or zero
10861 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10862 in bytes within the string that ARG is accessing. The type of the
10863 offset will be `sizetype'. */
10866 string_constant (tree arg
, tree
*ptr_offset
)
10868 tree array
, offset
, lower_bound
;
10871 if (TREE_CODE (arg
) == ADDR_EXPR
)
10873 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10875 *ptr_offset
= size_zero_node
;
10876 return TREE_OPERAND (arg
, 0);
10878 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10880 array
= TREE_OPERAND (arg
, 0);
10881 offset
= size_zero_node
;
10883 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10885 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10886 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10887 if (TREE_CODE (array
) != STRING_CST
10888 && TREE_CODE (array
) != VAR_DECL
)
10891 /* Check if the array has a nonzero lower bound. */
10892 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10893 if (!integer_zerop (lower_bound
))
10895 /* If the offset and base aren't both constants, return 0. */
10896 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10898 if (TREE_CODE (offset
) != INTEGER_CST
)
10900 /* Adjust offset by the lower bound. */
10901 offset
= size_diffop (fold_convert (sizetype
, offset
),
10902 fold_convert (sizetype
, lower_bound
));
10905 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10907 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10908 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10909 if (TREE_CODE (array
) != ADDR_EXPR
)
10911 array
= TREE_OPERAND (array
, 0);
10912 if (TREE_CODE (array
) != STRING_CST
10913 && TREE_CODE (array
) != VAR_DECL
)
10919 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10921 tree arg0
= TREE_OPERAND (arg
, 0);
10922 tree arg1
= TREE_OPERAND (arg
, 1);
10927 if (TREE_CODE (arg0
) == ADDR_EXPR
10928 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10929 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10931 array
= TREE_OPERAND (arg0
, 0);
10934 else if (TREE_CODE (arg1
) == ADDR_EXPR
10935 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10936 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10938 array
= TREE_OPERAND (arg1
, 0);
10947 if (TREE_CODE (array
) == STRING_CST
)
10949 *ptr_offset
= fold_convert (sizetype
, offset
);
10952 else if (TREE_CODE (array
) == VAR_DECL
10953 || TREE_CODE (array
) == CONST_DECL
)
10956 tree init
= ctor_for_folding (array
);
10958 /* Variables initialized to string literals can be handled too. */
10959 if (init
== error_mark_node
10961 || TREE_CODE (init
) != STRING_CST
)
10964 /* Avoid const char foo[4] = "abcde"; */
10965 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10966 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10967 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10968 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10971 /* If variable is bigger than the string literal, OFFSET must be constant
10972 and inside of the bounds of the string literal. */
10973 offset
= fold_convert (sizetype
, offset
);
10974 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10975 && (! tree_fits_uhwi_p (offset
)
10976 || compare_tree_int (offset
, length
) >= 0))
10979 *ptr_offset
= offset
;
10986 /* Generate code to calculate OPS, and exploded expression
10987 using a store-flag instruction and return an rtx for the result.
10988 OPS reflects a comparison.
10990 If TARGET is nonzero, store the result there if convenient.
10992 Return zero if there is no suitable set-flag instruction
10993 available on this machine.
10995 Once expand_expr has been called on the arguments of the comparison,
10996 we are committed to doing the store flag, since it is not safe to
10997 re-evaluate the expression. We emit the store-flag insn by calling
10998 emit_store_flag, but only expand the arguments if we have a reason
10999 to believe that emit_store_flag will be successful. If we think that
11000 it will, but it isn't, we have to simulate the store-flag with a
11001 set/jump/set sequence. */
11004 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
11006 enum rtx_code code
;
11007 tree arg0
, arg1
, type
;
11008 machine_mode operand_mode
;
11011 rtx subtarget
= target
;
11012 location_t loc
= ops
->location
;
11017 /* Don't crash if the comparison was erroneous. */
11018 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
11021 type
= TREE_TYPE (arg0
);
11022 operand_mode
= TYPE_MODE (type
);
11023 unsignedp
= TYPE_UNSIGNED (type
);
11025 /* We won't bother with BLKmode store-flag operations because it would mean
11026 passing a lot of information to emit_store_flag. */
11027 if (operand_mode
== BLKmode
)
11030 /* We won't bother with store-flag operations involving function pointers
11031 when function pointers must be canonicalized before comparisons. */
11032 if (targetm
.have_canonicalize_funcptr_for_compare ()
11033 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
11034 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
11036 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
11037 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
11038 == FUNCTION_TYPE
))))
11044 /* For vector typed comparisons emit code to generate the desired
11045 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
11046 expander for this. */
11047 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
11049 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
11050 tree if_true
= constant_boolean_node (true, ops
->type
);
11051 tree if_false
= constant_boolean_node (false, ops
->type
);
11052 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
11055 /* Get the rtx comparison code to use. We know that EXP is a comparison
11056 operation of some type. Some comparisons against 1 and -1 can be
11057 converted to comparisons with zero. Do so here so that the tests
11058 below will be aware that we have a comparison with zero. These
11059 tests will not catch constants in the first operand, but constants
11060 are rarely passed as the first operand. */
11071 if (integer_onep (arg1
))
11072 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
11074 code
= unsignedp
? LTU
: LT
;
11077 if (! unsignedp
&& integer_all_onesp (arg1
))
11078 arg1
= integer_zero_node
, code
= LT
;
11080 code
= unsignedp
? LEU
: LE
;
11083 if (! unsignedp
&& integer_all_onesp (arg1
))
11084 arg1
= integer_zero_node
, code
= GE
;
11086 code
= unsignedp
? GTU
: GT
;
11089 if (integer_onep (arg1
))
11090 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
11092 code
= unsignedp
? GEU
: GE
;
11095 case UNORDERED_EXPR
:
11121 gcc_unreachable ();
11124 /* Put a constant second. */
11125 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11126 || TREE_CODE (arg0
) == FIXED_CST
)
11128 std::swap (arg0
, arg1
);
11129 code
= swap_condition (code
);
11132 /* If this is an equality or inequality test of a single bit, we can
11133 do this by shifting the bit being tested to the low-order bit and
11134 masking the result with the constant 1. If the condition was EQ,
11135 we xor it with 1. This does not require an scc insn and is faster
11136 than an scc insn even if we have it.
11138 The code to make this transformation was moved into fold_single_bit_test,
11139 so we just call into the folder and expand its result. */
11141 if ((code
== NE
|| code
== EQ
)
11142 && integer_zerop (arg1
)
11143 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11145 gimple
*srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11147 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11149 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11150 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11151 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11152 gimple_assign_rhs1 (srcstmt
),
11153 gimple_assign_rhs2 (srcstmt
));
11154 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11156 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11160 if (! get_subtarget (target
)
11161 || GET_MODE (subtarget
) != operand_mode
)
11164 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11167 target
= gen_reg_rtx (mode
);
11169 /* Try a cstore if possible. */
11170 return emit_store_flag_force (target
, code
, op0
, op1
,
11171 operand_mode
, unsignedp
,
11172 (TYPE_PRECISION (ops
->type
) == 1
11173 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11176 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11177 0 otherwise (i.e. if there is no casesi instruction).
11179 DEFAULT_PROBABILITY is the probability of jumping to the default
11182 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11183 rtx table_label
, rtx default_label
, rtx fallback_label
,
11184 int default_probability
)
11186 struct expand_operand ops
[5];
11187 machine_mode index_mode
= SImode
;
11188 rtx op1
, op2
, index
;
11190 if (! targetm
.have_casesi ())
11193 /* Convert the index to SImode. */
11194 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11196 machine_mode omode
= TYPE_MODE (index_type
);
11197 rtx rangertx
= expand_normal (range
);
11199 /* We must handle the endpoints in the original mode. */
11200 index_expr
= build2 (MINUS_EXPR
, index_type
,
11201 index_expr
, minval
);
11202 minval
= integer_zero_node
;
11203 index
= expand_normal (index_expr
);
11205 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11206 omode
, 1, default_label
,
11207 default_probability
);
11208 /* Now we can safely truncate. */
11209 index
= convert_to_mode (index_mode
, index
, 0);
11213 if (TYPE_MODE (index_type
) != index_mode
)
11215 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11216 index_expr
= fold_convert (index_type
, index_expr
);
11219 index
= expand_normal (index_expr
);
11222 do_pending_stack_adjust ();
11224 op1
= expand_normal (minval
);
11225 op2
= expand_normal (range
);
11227 create_input_operand (&ops
[0], index
, index_mode
);
11228 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11229 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11230 create_fixed_operand (&ops
[3], table_label
);
11231 create_fixed_operand (&ops
[4], (default_label
11233 : fallback_label
));
11234 expand_jump_insn (targetm
.code_for_casesi
, 5, ops
);
11238 /* Attempt to generate a tablejump instruction; same concept. */
11239 /* Subroutine of the next function.
11241 INDEX is the value being switched on, with the lowest value
11242 in the table already subtracted.
11243 MODE is its expected mode (needed if INDEX is constant).
11244 RANGE is the length of the jump table.
11245 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11247 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11248 index value is out of range.
11249 DEFAULT_PROBABILITY is the probability of jumping to
11250 the default label. */
11253 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
11254 rtx default_label
, int default_probability
)
11258 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11259 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11261 /* Do an unsigned comparison (in the proper mode) between the index
11262 expression and the value which represents the length of the range.
11263 Since we just finished subtracting the lower bound of the range
11264 from the index expression, this comparison allows us to simultaneously
11265 check that the original index expression value is both greater than
11266 or equal to the minimum value of the range and less than or equal to
11267 the maximum value of the range. */
11270 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11271 default_label
, default_probability
);
11274 /* If index is in range, it must fit in Pmode.
11275 Convert to Pmode so we can index with it. */
11277 index
= convert_to_mode (Pmode
, index
, 1);
11279 /* Don't let a MEM slip through, because then INDEX that comes
11280 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11281 and break_out_memory_refs will go to work on it and mess it up. */
11282 #ifdef PIC_CASE_VECTOR_ADDRESS
11283 if (flag_pic
&& !REG_P (index
))
11284 index
= copy_to_mode_reg (Pmode
, index
);
11287 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11288 GET_MODE_SIZE, because this indicates how large insns are. The other
11289 uses should all be Pmode, because they are addresses. This code
11290 could fail if addresses and insns are not the same size. */
11291 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11292 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11294 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11295 gen_rtx_LABEL_REF (Pmode
, table_label
));
11297 #ifdef PIC_CASE_VECTOR_ADDRESS
11299 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11302 index
= memory_address (CASE_VECTOR_MODE
, index
);
11303 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11304 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11305 convert_move (temp
, vector
, 0);
11307 emit_jump_insn (targetm
.gen_tablejump (temp
, table_label
));
11309 /* If we are generating PIC code or if the table is PC-relative, the
11310 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11311 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11316 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11317 rtx table_label
, rtx default_label
, int default_probability
)
11321 if (! targetm
.have_tablejump ())
11324 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11325 fold_convert (index_type
, index_expr
),
11326 fold_convert (index_type
, minval
));
11327 index
= expand_normal (index_expr
);
11328 do_pending_stack_adjust ();
11330 do_tablejump (index
, TYPE_MODE (index_type
),
11331 convert_modes (TYPE_MODE (index_type
),
11332 TYPE_MODE (TREE_TYPE (range
)),
11333 expand_normal (range
),
11334 TYPE_UNSIGNED (TREE_TYPE (range
))),
11335 table_label
, default_label
, default_probability
);
11339 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11341 const_vector_from_tree (tree exp
)
11347 machine_mode inner
, mode
;
11349 mode
= TYPE_MODE (TREE_TYPE (exp
));
11351 if (initializer_zerop (exp
))
11352 return CONST0_RTX (mode
);
11354 units
= GET_MODE_NUNITS (mode
);
11355 inner
= GET_MODE_INNER (mode
);
11357 v
= rtvec_alloc (units
);
11359 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11361 elt
= VECTOR_CST_ELT (exp
, i
);
11363 if (TREE_CODE (elt
) == REAL_CST
)
11364 RTVEC_ELT (v
, i
) = const_double_from_real_value (TREE_REAL_CST (elt
),
11366 else if (TREE_CODE (elt
) == FIXED_CST
)
11367 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11370 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11373 return gen_rtx_CONST_VECTOR (mode
, v
);
11376 /* Build a decl for a personality function given a language prefix. */
11379 build_personality_function (const char *lang
)
11381 const char *unwind_and_version
;
11385 switch (targetm_common
.except_unwind_info (&global_options
))
11390 unwind_and_version
= "_sj0";
11394 unwind_and_version
= "_v0";
11397 unwind_and_version
= "_seh0";
11400 gcc_unreachable ();
11403 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11405 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11406 long_long_unsigned_type_node
,
11407 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11408 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11409 get_identifier (name
), type
);
11410 DECL_ARTIFICIAL (decl
) = 1;
11411 DECL_EXTERNAL (decl
) = 1;
11412 TREE_PUBLIC (decl
) = 1;
11414 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11415 are the flags assigned by targetm.encode_section_info. */
11416 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11421 /* Extracts the personality function of DECL and returns the corresponding
11425 get_personality_function (tree decl
)
11427 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11428 enum eh_personality_kind pk
;
11430 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11431 if (pk
== eh_personality_none
)
11435 && pk
== eh_personality_any
)
11436 personality
= lang_hooks
.eh_personality ();
11438 if (pk
== eh_personality_lang
)
11439 gcc_assert (personality
!= NULL_TREE
);
11441 return XEXP (DECL_RTL (personality
), 0);
11444 /* Returns a tree for the size of EXP in bytes. */
11447 tree_expr_size (const_tree exp
)
11450 && DECL_SIZE_UNIT (exp
) != 0)
11451 return DECL_SIZE_UNIT (exp
);
11453 return size_in_bytes (TREE_TYPE (exp
));
11456 /* Return an rtx for the size in bytes of the value of EXP. */
11459 expr_size (tree exp
)
11463 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11464 size
= TREE_OPERAND (exp
, 1);
11467 size
= tree_expr_size (exp
);
11469 gcc_assert (size
== SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, exp
));
11472 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), EXPAND_NORMAL
);
11475 /* Return a wide integer for the size in bytes of the value of EXP, or -1
11476 if the size can vary or is larger than an integer. */
11478 static HOST_WIDE_INT
11479 int_expr_size (tree exp
)
11483 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11484 size
= TREE_OPERAND (exp
, 1);
11487 size
= tree_expr_size (exp
);
11491 if (size
== 0 || !tree_fits_shwi_p (size
))
11494 return tree_to_shwi (size
);
11497 #include "gt-expr.h"