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 /* We allow move between structures of same size but different mode.
5429 If source is in memory and the mode differs, simply change the memory. */
5430 if (GET_MODE (temp
) == BLKmode
&& GET_MODE (target
) != BLKmode
)
5432 gcc_assert (MEM_P (temp
));
5433 temp
= adjust_address_nv (temp
, GET_MODE (target
), 0);
5436 /* If value was not generated in the target, store it there.
5437 Convert the value to TARGET's type first if necessary and emit the
5438 pending incrementations that have been queued when expanding EXP.
5439 Note that we cannot emit the whole queue blindly because this will
5440 effectively disable the POST_INC optimization later.
5442 If TEMP and TARGET compare equal according to rtx_equal_p, but
5443 one or both of them are volatile memory refs, we have to distinguish
5445 - expand_expr has used TARGET. In this case, we must not generate
5446 another copy. This can be detected by TARGET being equal according
5448 - expand_expr has not used TARGET - that means that the source just
5449 happens to have the same RTX form. Since temp will have been created
5450 by expand_expr, it will compare unequal according to == .
5451 We must generate a copy in this case, to reach the correct number
5452 of volatile memory references. */
5454 if ((! rtx_equal_p (temp
, target
)
5455 || (temp
!= target
&& (side_effects_p (temp
)
5456 || side_effects_p (target
))))
5457 && TREE_CODE (exp
) != ERROR_MARK
5458 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5459 but TARGET is not valid memory reference, TEMP will differ
5460 from TARGET although it is really the same location. */
5462 && rtx_equal_p (alt_rtl
, target
)
5463 && !side_effects_p (alt_rtl
)
5464 && !side_effects_p (target
))
5465 /* If there's nothing to copy, don't bother. Don't call
5466 expr_size unless necessary, because some front-ends (C++)
5467 expr_size-hook must not be given objects that are not
5468 supposed to be bit-copied or bit-initialized. */
5469 && expr_size (exp
) != const0_rtx
)
5471 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5473 if (GET_MODE (target
) == BLKmode
)
5475 /* Handle calls that return BLKmode values in registers. */
5476 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5477 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5479 store_bit_field (target
,
5480 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5481 0, 0, 0, GET_MODE (temp
), temp
);
5484 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5487 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5489 /* Handle copying a string constant into an array. The string
5490 constant may be shorter than the array. So copy just the string's
5491 actual length, and clear the rest. First get the size of the data
5492 type of the string, which is actually the size of the target. */
5493 rtx size
= expr_size (exp
);
5495 if (CONST_INT_P (size
)
5496 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5497 emit_block_move (target
, temp
, size
,
5499 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5502 machine_mode pointer_mode
5503 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5504 machine_mode address_mode
= get_address_mode (target
);
5506 /* Compute the size of the data to copy from the string. */
5508 = size_binop_loc (loc
, MIN_EXPR
,
5509 make_tree (sizetype
, size
),
5510 size_int (TREE_STRING_LENGTH (exp
)));
5512 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5514 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5515 rtx_code_label
*label
= 0;
5517 /* Copy that much. */
5518 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5519 TYPE_UNSIGNED (sizetype
));
5520 emit_block_move (target
, temp
, copy_size_rtx
,
5522 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5524 /* Figure out how much is left in TARGET that we have to clear.
5525 Do all calculations in pointer_mode. */
5526 if (CONST_INT_P (copy_size_rtx
))
5528 size
= plus_constant (address_mode
, size
,
5529 -INTVAL (copy_size_rtx
));
5530 target
= adjust_address (target
, BLKmode
,
5531 INTVAL (copy_size_rtx
));
5535 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5536 copy_size_rtx
, NULL_RTX
, 0,
5539 if (GET_MODE (copy_size_rtx
) != address_mode
)
5540 copy_size_rtx
= convert_to_mode (address_mode
,
5542 TYPE_UNSIGNED (sizetype
));
5544 target
= offset_address (target
, copy_size_rtx
,
5545 highest_pow2_factor (copy_size
));
5546 label
= gen_label_rtx ();
5547 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5548 GET_MODE (size
), 0, label
);
5551 if (size
!= const0_rtx
)
5552 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5558 /* Handle calls that return values in multiple non-contiguous locations.
5559 The Irix 6 ABI has examples of this. */
5560 else if (GET_CODE (target
) == PARALLEL
)
5562 if (GET_CODE (temp
) == PARALLEL
)
5563 emit_group_move (target
, temp
);
5565 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5566 int_size_in_bytes (TREE_TYPE (exp
)));
5568 else if (GET_CODE (temp
) == PARALLEL
)
5569 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5570 int_size_in_bytes (TREE_TYPE (exp
)));
5571 else if (GET_MODE (temp
) == BLKmode
)
5572 emit_block_move (target
, temp
, expr_size (exp
),
5574 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5575 /* If we emit a nontemporal store, there is nothing else to do. */
5576 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5580 temp
= force_operand (temp
, target
);
5582 emit_move_insn (target
, temp
);
5589 /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
5591 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5593 return store_expr_with_bounds (exp
, target
, call_param_p
, nontemporal
, NULL
);
5596 /* Return true if field F of structure TYPE is a flexible array. */
5599 flexible_array_member_p (const_tree f
, const_tree type
)
5604 return (DECL_CHAIN (f
) == NULL
5605 && TREE_CODE (tf
) == ARRAY_TYPE
5607 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5608 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5609 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5610 && int_size_in_bytes (type
) >= 0);
5613 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5614 must have in order for it to completely initialize a value of type TYPE.
5615 Return -1 if the number isn't known.
5617 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5619 static HOST_WIDE_INT
5620 count_type_elements (const_tree type
, bool for_ctor_p
)
5622 switch (TREE_CODE (type
))
5628 nelts
= array_type_nelts (type
);
5629 if (nelts
&& tree_fits_uhwi_p (nelts
))
5631 unsigned HOST_WIDE_INT n
;
5633 n
= tree_to_uhwi (nelts
) + 1;
5634 if (n
== 0 || for_ctor_p
)
5637 return n
* count_type_elements (TREE_TYPE (type
), false);
5639 return for_ctor_p
? -1 : 1;
5644 unsigned HOST_WIDE_INT n
;
5648 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5649 if (TREE_CODE (f
) == FIELD_DECL
)
5652 n
+= count_type_elements (TREE_TYPE (f
), false);
5653 else if (!flexible_array_member_p (f
, type
))
5654 /* Don't count flexible arrays, which are not supposed
5655 to be initialized. */
5663 case QUAL_UNION_TYPE
:
5668 gcc_assert (!for_ctor_p
);
5669 /* Estimate the number of scalars in each field and pick the
5670 maximum. Other estimates would do instead; the idea is simply
5671 to make sure that the estimate is not sensitive to the ordering
5674 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5675 if (TREE_CODE (f
) == FIELD_DECL
)
5677 m
= count_type_elements (TREE_TYPE (f
), false);
5678 /* If the field doesn't span the whole union, add an extra
5679 scalar for the rest. */
5680 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5681 TYPE_SIZE (type
)) != 1)
5693 return TYPE_VECTOR_SUBPARTS (type
);
5697 case FIXED_POINT_TYPE
:
5702 case REFERENCE_TYPE
:
5718 /* Helper for categorize_ctor_elements. Identical interface. */
5721 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5722 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5724 unsigned HOST_WIDE_INT idx
;
5725 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5726 tree value
, purpose
, elt_type
;
5728 /* Whether CTOR is a valid constant initializer, in accordance with what
5729 initializer_constant_valid_p does. If inferred from the constructor
5730 elements, true until proven otherwise. */
5731 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5732 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5737 elt_type
= NULL_TREE
;
5739 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5741 HOST_WIDE_INT mult
= 1;
5743 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5745 tree lo_index
= TREE_OPERAND (purpose
, 0);
5746 tree hi_index
= TREE_OPERAND (purpose
, 1);
5748 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5749 mult
= (tree_to_uhwi (hi_index
)
5750 - tree_to_uhwi (lo_index
) + 1);
5753 elt_type
= TREE_TYPE (value
);
5755 switch (TREE_CODE (value
))
5759 HOST_WIDE_INT nz
= 0, ic
= 0;
5761 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5764 nz_elts
+= mult
* nz
;
5765 init_elts
+= mult
* ic
;
5767 if (const_from_elts_p
&& const_p
)
5768 const_p
= const_elt_p
;
5775 if (!initializer_zerop (value
))
5781 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5782 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5786 if (!initializer_zerop (TREE_REALPART (value
)))
5788 if (!initializer_zerop (TREE_IMAGPART (value
)))
5796 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5798 tree v
= VECTOR_CST_ELT (value
, i
);
5799 if (!initializer_zerop (v
))
5808 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5809 nz_elts
+= mult
* tc
;
5810 init_elts
+= mult
* tc
;
5812 if (const_from_elts_p
&& const_p
)
5813 const_p
= initializer_constant_valid_p (value
, elt_type
)
5820 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5821 num_fields
, elt_type
))
5822 *p_complete
= false;
5824 *p_nz_elts
+= nz_elts
;
5825 *p_init_elts
+= init_elts
;
5830 /* Examine CTOR to discover:
5831 * how many scalar fields are set to nonzero values,
5832 and place it in *P_NZ_ELTS;
5833 * how many scalar fields in total are in CTOR,
5834 and place it in *P_ELT_COUNT.
5835 * whether the constructor is complete -- in the sense that every
5836 meaningful byte is explicitly given a value --
5837 and place it in *P_COMPLETE.
5839 Return whether or not CTOR is a valid static constant initializer, the same
5840 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5843 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5844 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5850 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5853 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5854 of which had type LAST_TYPE. Each element was itself a complete
5855 initializer, in the sense that every meaningful byte was explicitly
5856 given a value. Return true if the same is true for the constructor
5860 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5861 const_tree last_type
)
5863 if (TREE_CODE (type
) == UNION_TYPE
5864 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5869 gcc_assert (num_elts
== 1 && last_type
);
5871 /* ??? We could look at each element of the union, and find the
5872 largest element. Which would avoid comparing the size of the
5873 initialized element against any tail padding in the union.
5874 Doesn't seem worth the effort... */
5875 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5878 return count_type_elements (type
, true) == num_elts
;
5881 /* Return 1 if EXP contains mostly (3/4) zeros. */
5884 mostly_zeros_p (const_tree exp
)
5886 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5888 HOST_WIDE_INT nz_elts
, init_elts
;
5891 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5892 return !complete_p
|| nz_elts
< init_elts
/ 4;
5895 return initializer_zerop (exp
);
5898 /* Return 1 if EXP contains all zeros. */
5901 all_zeros_p (const_tree exp
)
5903 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5905 HOST_WIDE_INT nz_elts
, init_elts
;
5908 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5909 return nz_elts
== 0;
5912 return initializer_zerop (exp
);
5915 /* Helper function for store_constructor.
5916 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5917 CLEARED is as for store_constructor.
5918 ALIAS_SET is the alias set to use for any stores.
5920 This provides a recursive shortcut back to store_constructor when it isn't
5921 necessary to go through store_field. This is so that we can pass through
5922 the cleared field to let store_constructor know that we may not have to
5923 clear a substructure if the outer structure has already been cleared. */
5926 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5927 HOST_WIDE_INT bitpos
, machine_mode mode
,
5928 tree exp
, int cleared
, alias_set_type alias_set
)
5930 if (TREE_CODE (exp
) == CONSTRUCTOR
5931 /* We can only call store_constructor recursively if the size and
5932 bit position are on a byte boundary. */
5933 && bitpos
% BITS_PER_UNIT
== 0
5934 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5935 /* If we have a nonzero bitpos for a register target, then we just
5936 let store_field do the bitfield handling. This is unlikely to
5937 generate unnecessary clear instructions anyways. */
5938 && (bitpos
== 0 || MEM_P (target
)))
5942 = adjust_address (target
,
5943 GET_MODE (target
) == BLKmode
5945 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5946 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5949 /* Update the alias set, if required. */
5950 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5951 && MEM_ALIAS_SET (target
) != 0)
5953 target
= copy_rtx (target
);
5954 set_mem_alias_set (target
, alias_set
);
5957 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5960 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5964 /* Returns the number of FIELD_DECLs in TYPE. */
5967 fields_length (const_tree type
)
5969 tree t
= TYPE_FIELDS (type
);
5972 for (; t
; t
= DECL_CHAIN (t
))
5973 if (TREE_CODE (t
) == FIELD_DECL
)
5980 /* Store the value of constructor EXP into the rtx TARGET.
5981 TARGET is either a REG or a MEM; we know it cannot conflict, since
5982 safe_from_p has been called.
5983 CLEARED is true if TARGET is known to have been zero'd.
5984 SIZE is the number of bytes of TARGET we are allowed to modify: this
5985 may not be the same as the size of EXP if we are assigning to a field
5986 which has been packed to exclude padding bits. */
5989 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5991 tree type
= TREE_TYPE (exp
);
5992 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5994 switch (TREE_CODE (type
))
5998 case QUAL_UNION_TYPE
:
6000 unsigned HOST_WIDE_INT idx
;
6003 /* If size is zero or the target is already cleared, do nothing. */
6004 if (size
== 0 || cleared
)
6006 /* We either clear the aggregate or indicate the value is dead. */
6007 else if ((TREE_CODE (type
) == UNION_TYPE
6008 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
6009 && ! CONSTRUCTOR_ELTS (exp
))
6010 /* If the constructor is empty, clear the union. */
6012 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
6016 /* If we are building a static constructor into a register,
6017 set the initial value as zero so we can fold the value into
6018 a constant. But if more than one register is involved,
6019 this probably loses. */
6020 else if (REG_P (target
) && TREE_STATIC (exp
)
6021 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
6023 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6027 /* If the constructor has fewer fields than the structure or
6028 if we are initializing the structure to mostly zeros, clear
6029 the whole structure first. Don't do this if TARGET is a
6030 register whose mode size isn't equal to SIZE since
6031 clear_storage can't handle this case. */
6033 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
6034 != fields_length (type
))
6035 || mostly_zeros_p (exp
))
6037 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
6040 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6044 if (REG_P (target
) && !cleared
)
6045 emit_clobber (target
);
6047 /* Store each element of the constructor into the
6048 corresponding field of TARGET. */
6049 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
6052 HOST_WIDE_INT bitsize
;
6053 HOST_WIDE_INT bitpos
= 0;
6055 rtx to_rtx
= target
;
6057 /* Just ignore missing fields. We cleared the whole
6058 structure, above, if any fields are missing. */
6062 if (cleared
&& initializer_zerop (value
))
6065 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
6066 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
6070 mode
= DECL_MODE (field
);
6071 if (DECL_BIT_FIELD (field
))
6074 offset
= DECL_FIELD_OFFSET (field
);
6075 if (tree_fits_shwi_p (offset
)
6076 && tree_fits_shwi_p (bit_position (field
)))
6078 bitpos
= int_bit_position (field
);
6082 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
6086 machine_mode address_mode
;
6090 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
6091 make_tree (TREE_TYPE (exp
),
6094 offset_rtx
= expand_normal (offset
);
6095 gcc_assert (MEM_P (to_rtx
));
6097 address_mode
= get_address_mode (to_rtx
);
6098 if (GET_MODE (offset_rtx
) != address_mode
)
6099 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6101 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6102 highest_pow2_factor (offset
));
6105 /* If this initializes a field that is smaller than a
6106 word, at the start of a word, try to widen it to a full
6107 word. This special case allows us to output C++ member
6108 function initializations in a form that the optimizers
6110 if (WORD_REGISTER_OPERATIONS
6112 && bitsize
< BITS_PER_WORD
6113 && bitpos
% BITS_PER_WORD
== 0
6114 && GET_MODE_CLASS (mode
) == MODE_INT
6115 && TREE_CODE (value
) == INTEGER_CST
6117 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6119 tree type
= TREE_TYPE (value
);
6121 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6123 type
= lang_hooks
.types
.type_for_mode
6124 (word_mode
, TYPE_UNSIGNED (type
));
6125 value
= fold_convert (type
, value
);
6128 if (BYTES_BIG_ENDIAN
)
6130 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6131 build_int_cst (type
,
6132 BITS_PER_WORD
- bitsize
));
6133 bitsize
= BITS_PER_WORD
;
6137 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6138 && DECL_NONADDRESSABLE_P (field
))
6140 to_rtx
= copy_rtx (to_rtx
);
6141 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6144 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6146 get_alias_set (TREE_TYPE (field
)));
6153 unsigned HOST_WIDE_INT i
;
6156 tree elttype
= TREE_TYPE (type
);
6158 HOST_WIDE_INT minelt
= 0;
6159 HOST_WIDE_INT maxelt
= 0;
6161 domain
= TYPE_DOMAIN (type
);
6162 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6163 && TYPE_MAX_VALUE (domain
)
6164 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6165 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6167 /* If we have constant bounds for the range of the type, get them. */
6170 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6171 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6174 /* If the constructor has fewer elements than the array, clear
6175 the whole array first. Similarly if this is static
6176 constructor of a non-BLKmode object. */
6179 else if (REG_P (target
) && TREE_STATIC (exp
))
6183 unsigned HOST_WIDE_INT idx
;
6185 HOST_WIDE_INT count
= 0, zero_count
= 0;
6186 need_to_clear
= ! const_bounds_p
;
6188 /* This loop is a more accurate version of the loop in
6189 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6190 is also needed to check for missing elements. */
6191 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6193 HOST_WIDE_INT this_node_count
;
6198 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6200 tree lo_index
= TREE_OPERAND (index
, 0);
6201 tree hi_index
= TREE_OPERAND (index
, 1);
6203 if (! tree_fits_uhwi_p (lo_index
)
6204 || ! tree_fits_uhwi_p (hi_index
))
6210 this_node_count
= (tree_to_uhwi (hi_index
)
6211 - tree_to_uhwi (lo_index
) + 1);
6214 this_node_count
= 1;
6216 count
+= this_node_count
;
6217 if (mostly_zeros_p (value
))
6218 zero_count
+= this_node_count
;
6221 /* Clear the entire array first if there are any missing
6222 elements, or if the incidence of zero elements is >=
6225 && (count
< maxelt
- minelt
+ 1
6226 || 4 * zero_count
>= 3 * count
))
6230 if (need_to_clear
&& size
> 0)
6233 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6235 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6239 if (!cleared
&& REG_P (target
))
6240 /* Inform later passes that the old value is dead. */
6241 emit_clobber (target
);
6243 /* Store each element of the constructor into the
6244 corresponding element of TARGET, determined by counting the
6246 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6249 HOST_WIDE_INT bitsize
;
6250 HOST_WIDE_INT bitpos
;
6251 rtx xtarget
= target
;
6253 if (cleared
&& initializer_zerop (value
))
6256 mode
= TYPE_MODE (elttype
);
6257 if (mode
== BLKmode
)
6258 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6259 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6262 bitsize
= GET_MODE_BITSIZE (mode
);
6264 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6266 tree lo_index
= TREE_OPERAND (index
, 0);
6267 tree hi_index
= TREE_OPERAND (index
, 1);
6268 rtx index_r
, pos_rtx
;
6269 HOST_WIDE_INT lo
, hi
, count
;
6272 /* If the range is constant and "small", unroll the loop. */
6274 && tree_fits_shwi_p (lo_index
)
6275 && tree_fits_shwi_p (hi_index
)
6276 && (lo
= tree_to_shwi (lo_index
),
6277 hi
= tree_to_shwi (hi_index
),
6278 count
= hi
- lo
+ 1,
6281 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6282 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6285 lo
-= minelt
; hi
-= minelt
;
6286 for (; lo
<= hi
; lo
++)
6288 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6291 && !MEM_KEEP_ALIAS_SET_P (target
)
6292 && TREE_CODE (type
) == ARRAY_TYPE
6293 && TYPE_NONALIASED_COMPONENT (type
))
6295 target
= copy_rtx (target
);
6296 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6299 store_constructor_field
6300 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6301 get_alias_set (elttype
));
6306 rtx_code_label
*loop_start
= gen_label_rtx ();
6307 rtx_code_label
*loop_end
= gen_label_rtx ();
6310 expand_normal (hi_index
);
6312 index
= build_decl (EXPR_LOCATION (exp
),
6313 VAR_DECL
, NULL_TREE
, domain
);
6314 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6315 SET_DECL_RTL (index
, index_r
);
6316 store_expr (lo_index
, index_r
, 0, false);
6318 /* Build the head of the loop. */
6319 do_pending_stack_adjust ();
6320 emit_label (loop_start
);
6322 /* Assign value to element index. */
6324 fold_convert (ssizetype
,
6325 fold_build2 (MINUS_EXPR
,
6328 TYPE_MIN_VALUE (domain
)));
6331 size_binop (MULT_EXPR
, position
,
6332 fold_convert (ssizetype
,
6333 TYPE_SIZE_UNIT (elttype
)));
6335 pos_rtx
= expand_normal (position
);
6336 xtarget
= offset_address (target
, pos_rtx
,
6337 highest_pow2_factor (position
));
6338 xtarget
= adjust_address (xtarget
, mode
, 0);
6339 if (TREE_CODE (value
) == CONSTRUCTOR
)
6340 store_constructor (value
, xtarget
, cleared
,
6341 bitsize
/ BITS_PER_UNIT
);
6343 store_expr (value
, xtarget
, 0, false);
6345 /* Generate a conditional jump to exit the loop. */
6346 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6348 jumpif (exit_cond
, loop_end
, -1);
6350 /* Update the loop counter, and jump to the head of
6352 expand_assignment (index
,
6353 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6354 index
, integer_one_node
),
6357 emit_jump (loop_start
);
6359 /* Build the end of the loop. */
6360 emit_label (loop_end
);
6363 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6364 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6369 index
= ssize_int (1);
6372 index
= fold_convert (ssizetype
,
6373 fold_build2 (MINUS_EXPR
,
6376 TYPE_MIN_VALUE (domain
)));
6379 size_binop (MULT_EXPR
, index
,
6380 fold_convert (ssizetype
,
6381 TYPE_SIZE_UNIT (elttype
)));
6382 xtarget
= offset_address (target
,
6383 expand_normal (position
),
6384 highest_pow2_factor (position
));
6385 xtarget
= adjust_address (xtarget
, mode
, 0);
6386 store_expr (value
, xtarget
, 0, false);
6391 bitpos
= ((tree_to_shwi (index
) - minelt
)
6392 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6394 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6396 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6397 && TREE_CODE (type
) == ARRAY_TYPE
6398 && TYPE_NONALIASED_COMPONENT (type
))
6400 target
= copy_rtx (target
);
6401 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6403 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6404 cleared
, get_alias_set (elttype
));
6412 unsigned HOST_WIDE_INT idx
;
6413 constructor_elt
*ce
;
6416 int icode
= CODE_FOR_nothing
;
6417 tree elttype
= TREE_TYPE (type
);
6418 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6419 machine_mode eltmode
= TYPE_MODE (elttype
);
6420 HOST_WIDE_INT bitsize
;
6421 HOST_WIDE_INT bitpos
;
6422 rtvec vector
= NULL
;
6424 alias_set_type alias
;
6426 gcc_assert (eltmode
!= BLKmode
);
6428 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6429 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6431 machine_mode mode
= GET_MODE (target
);
6433 icode
= (int) optab_handler (vec_init_optab
, mode
);
6434 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6435 if (icode
!= CODE_FOR_nothing
)
6439 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6440 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6442 icode
= CODE_FOR_nothing
;
6446 if (icode
!= CODE_FOR_nothing
)
6450 vector
= rtvec_alloc (n_elts
);
6451 for (i
= 0; i
< n_elts
; i
++)
6452 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6456 /* If the constructor has fewer elements than the vector,
6457 clear the whole array first. Similarly if this is static
6458 constructor of a non-BLKmode object. */
6461 else if (REG_P (target
) && TREE_STATIC (exp
))
6465 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6468 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6470 int n_elts_here
= tree_to_uhwi
6471 (int_const_binop (TRUNC_DIV_EXPR
,
6472 TYPE_SIZE (TREE_TYPE (value
)),
6473 TYPE_SIZE (elttype
)));
6475 count
+= n_elts_here
;
6476 if (mostly_zeros_p (value
))
6477 zero_count
+= n_elts_here
;
6480 /* Clear the entire vector first if there are any missing elements,
6481 or if the incidence of zero elements is >= 75%. */
6482 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6485 if (need_to_clear
&& size
> 0 && !vector
)
6488 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6490 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6494 /* Inform later passes that the old value is dead. */
6495 if (!cleared
&& !vector
&& REG_P (target
))
6496 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6499 alias
= MEM_ALIAS_SET (target
);
6501 alias
= get_alias_set (elttype
);
6503 /* Store each element of the constructor into the corresponding
6504 element of TARGET, determined by counting the elements. */
6505 for (idx
= 0, i
= 0;
6506 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6507 idx
++, i
+= bitsize
/ elt_size
)
6509 HOST_WIDE_INT eltpos
;
6510 tree value
= ce
->value
;
6512 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6513 if (cleared
&& initializer_zerop (value
))
6517 eltpos
= tree_to_uhwi (ce
->index
);
6523 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6525 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6526 RTVEC_ELT (vector
, eltpos
)
6527 = expand_normal (value
);
6531 machine_mode value_mode
=
6532 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6533 ? TYPE_MODE (TREE_TYPE (value
))
6535 bitpos
= eltpos
* elt_size
;
6536 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6537 value
, cleared
, alias
);
6542 emit_insn (GEN_FCN (icode
)
6544 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6553 /* Store the value of EXP (an expression tree)
6554 into a subfield of TARGET which has mode MODE and occupies
6555 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6556 If MODE is VOIDmode, it means that we are storing into a bit-field.
6558 BITREGION_START is bitpos of the first bitfield in this region.
6559 BITREGION_END is the bitpos of the ending bitfield in this region.
6560 These two fields are 0, if the C++ memory model does not apply,
6561 or we are not interested in keeping track of bitfield regions.
6563 Always return const0_rtx unless we have something particular to
6566 ALIAS_SET is the alias set for the destination. This value will
6567 (in general) be different from that for TARGET, since TARGET is a
6568 reference to the containing structure.
6570 If NONTEMPORAL is true, try generating a nontemporal store. */
6573 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6574 unsigned HOST_WIDE_INT bitregion_start
,
6575 unsigned HOST_WIDE_INT bitregion_end
,
6576 machine_mode mode
, tree exp
,
6577 alias_set_type alias_set
, bool nontemporal
)
6579 if (TREE_CODE (exp
) == ERROR_MARK
)
6582 /* If we have nothing to store, do nothing unless the expression has
6585 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6587 if (GET_CODE (target
) == CONCAT
)
6589 /* We're storing into a struct containing a single __complex. */
6591 gcc_assert (!bitpos
);
6592 return store_expr (exp
, target
, 0, nontemporal
);
6595 /* If the structure is in a register or if the component
6596 is a bit field, we cannot use addressing to access it.
6597 Use bit-field techniques or SUBREG to store in it. */
6599 if (mode
== VOIDmode
6600 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6601 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6602 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6604 || GET_CODE (target
) == SUBREG
6605 /* If the field isn't aligned enough to store as an ordinary memref,
6606 store it as a bit field. */
6608 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6609 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6610 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6611 || (bitpos
% BITS_PER_UNIT
!= 0)))
6612 || (bitsize
>= 0 && mode
!= BLKmode
6613 && GET_MODE_BITSIZE (mode
) > bitsize
)
6614 /* If the RHS and field are a constant size and the size of the
6615 RHS isn't the same size as the bitfield, we must use bitfield
6618 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6619 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0
6620 /* Except for initialization of full bytes from a CONSTRUCTOR, which
6621 we will handle specially below. */
6622 && !(TREE_CODE (exp
) == CONSTRUCTOR
6623 && bitsize
% BITS_PER_UNIT
== 0))
6624 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6625 decl we must use bitfield operations. */
6627 && TREE_CODE (exp
) == MEM_REF
6628 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6629 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6630 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6631 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6636 /* Using bitwise copy is not safe for TREE_ADDRESSABLE types. */
6637 gcc_assert (!TREE_ADDRESSABLE (TREE_TYPE (exp
)));
6639 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6640 implies a mask operation. If the precision is the same size as
6641 the field we're storing into, that mask is redundant. This is
6642 particularly common with bit field assignments generated by the
6644 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6647 tree type
= TREE_TYPE (exp
);
6648 if (INTEGRAL_TYPE_P (type
)
6649 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6650 && bitsize
== TYPE_PRECISION (type
))
6652 tree op
= gimple_assign_rhs1 (nop_def
);
6653 type
= TREE_TYPE (op
);
6654 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6659 temp
= expand_normal (exp
);
6661 /* If BITSIZE is narrower than the size of the type of EXP
6662 we will be narrowing TEMP. Normally, what's wanted are the
6663 low-order bits. However, if EXP's type is a record and this is
6664 big-endian machine, we want the upper BITSIZE bits. */
6665 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6666 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6667 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6668 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6669 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6672 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6673 if (mode
!= VOIDmode
&& mode
!= BLKmode
6674 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6675 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6677 /* If TEMP is not a PARALLEL (see below) and its mode and that of TARGET
6678 are both BLKmode, both must be in memory and BITPOS must be aligned
6679 on a byte boundary. If so, we simply do a block copy. Likewise for
6680 a BLKmode-like TARGET. */
6681 if (GET_CODE (temp
) != PARALLEL
6682 && GET_MODE (temp
) == BLKmode
6683 && (GET_MODE (target
) == BLKmode
6685 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6686 && (bitpos
% BITS_PER_UNIT
) == 0
6687 && (bitsize
% BITS_PER_UNIT
) == 0)))
6689 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6690 && (bitpos
% BITS_PER_UNIT
) == 0);
6692 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6693 emit_block_move (target
, temp
,
6694 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6701 /* Handle calls that return values in multiple non-contiguous locations.
6702 The Irix 6 ABI has examples of this. */
6703 if (GET_CODE (temp
) == PARALLEL
)
6705 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6707 if (mode
== BLKmode
|| mode
== VOIDmode
)
6708 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6709 temp_target
= gen_reg_rtx (mode
);
6710 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6713 else if (mode
== BLKmode
)
6715 /* Handle calls that return BLKmode values in registers. */
6716 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6718 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6719 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6724 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6726 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6727 temp_target
= gen_reg_rtx (mode
);
6729 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6730 temp_target
, mode
, mode
);
6735 /* Store the value in the bitfield. */
6736 store_bit_field (target
, bitsize
, bitpos
,
6737 bitregion_start
, bitregion_end
,
6744 /* Now build a reference to just the desired component. */
6745 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6747 if (to_rtx
== target
)
6748 to_rtx
= copy_rtx (to_rtx
);
6750 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6751 set_mem_alias_set (to_rtx
, alias_set
);
6753 /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
6754 into a target smaller than its type; handle that case now. */
6755 if (TREE_CODE (exp
) == CONSTRUCTOR
&& bitsize
>= 0)
6757 gcc_assert (bitsize
% BITS_PER_UNIT
== 0);
6758 store_constructor (exp
, to_rtx
, 0, bitsize
/BITS_PER_UNIT
);
6762 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6766 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6767 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6768 codes and find the ultimate containing object, which we return.
6770 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6771 bit position, and *PUNSIGNEDP to the signedness of the field.
6772 If the position of the field is variable, we store a tree
6773 giving the variable offset (in units) in *POFFSET.
6774 This offset is in addition to the bit position.
6775 If the position is not variable, we store 0 in *POFFSET.
6777 If any of the extraction expressions is volatile,
6778 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6780 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6781 Otherwise, it is a mode that can be used to access the field.
6783 If the field describes a variable-sized object, *PMODE is set to
6784 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6785 this case, but the address of the object can be found.
6787 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6788 look through nodes that serve as markers of a greater alignment than
6789 the one that can be deduced from the expression. These nodes make it
6790 possible for front-ends to prevent temporaries from being created by
6791 the middle-end on alignment considerations. For that purpose, the
6792 normal operating mode at high-level is to always pass FALSE so that
6793 the ultimate containing object is really returned; moreover, the
6794 associated predicate handled_component_p will always return TRUE
6795 on these nodes, thus indicating that they are essentially handled
6796 by get_inner_reference. TRUE should only be passed when the caller
6797 is scanning the expression in order to build another representation
6798 and specifically knows how to handle these nodes; as such, this is
6799 the normal operating mode in the RTL expanders. */
6802 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6803 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6804 machine_mode
*pmode
, int *punsignedp
,
6805 int *pvolatilep
, bool keep_aligning
)
6808 machine_mode mode
= VOIDmode
;
6809 bool blkmode_bitfield
= false;
6810 tree offset
= size_zero_node
;
6811 offset_int bit_offset
= 0;
6813 /* First get the mode, signedness, and size. We do this from just the
6814 outermost expression. */
6816 if (TREE_CODE (exp
) == COMPONENT_REF
)
6818 tree field
= TREE_OPERAND (exp
, 1);
6819 size_tree
= DECL_SIZE (field
);
6820 if (flag_strict_volatile_bitfields
> 0
6821 && TREE_THIS_VOLATILE (exp
)
6822 && DECL_BIT_FIELD_TYPE (field
)
6823 && DECL_MODE (field
) != BLKmode
)
6824 /* Volatile bitfields should be accessed in the mode of the
6825 field's type, not the mode computed based on the bit
6827 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6828 else if (!DECL_BIT_FIELD (field
))
6829 mode
= DECL_MODE (field
);
6830 else if (DECL_MODE (field
) == BLKmode
)
6831 blkmode_bitfield
= true;
6833 *punsignedp
= DECL_UNSIGNED (field
);
6835 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6837 size_tree
= TREE_OPERAND (exp
, 1);
6838 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6839 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6841 /* For vector types, with the correct size of access, use the mode of
6843 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6844 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6845 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6846 mode
= TYPE_MODE (TREE_TYPE (exp
));
6850 mode
= TYPE_MODE (TREE_TYPE (exp
));
6851 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6853 if (mode
== BLKmode
)
6854 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6856 *pbitsize
= GET_MODE_BITSIZE (mode
);
6861 if (! tree_fits_uhwi_p (size_tree
))
6862 mode
= BLKmode
, *pbitsize
= -1;
6864 *pbitsize
= tree_to_uhwi (size_tree
);
6867 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6868 and find the ultimate containing object. */
6871 switch (TREE_CODE (exp
))
6874 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
6879 tree field
= TREE_OPERAND (exp
, 1);
6880 tree this_offset
= component_ref_field_offset (exp
);
6882 /* If this field hasn't been filled in yet, don't go past it.
6883 This should only happen when folding expressions made during
6884 type construction. */
6885 if (this_offset
== 0)
6888 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6889 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
6891 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6896 case ARRAY_RANGE_REF
:
6898 tree index
= TREE_OPERAND (exp
, 1);
6899 tree low_bound
= array_ref_low_bound (exp
);
6900 tree unit_size
= array_ref_element_size (exp
);
6902 /* We assume all arrays have sizes that are a multiple of a byte.
6903 First subtract the lower bound, if any, in the type of the
6904 index, then convert to sizetype and multiply by the size of
6905 the array element. */
6906 if (! integer_zerop (low_bound
))
6907 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6910 offset
= size_binop (PLUS_EXPR
, offset
,
6911 size_binop (MULT_EXPR
,
6912 fold_convert (sizetype
, index
),
6921 bit_offset
+= *pbitsize
;
6924 case VIEW_CONVERT_EXPR
:
6925 if (keep_aligning
&& STRICT_ALIGNMENT
6926 && (TYPE_ALIGN (TREE_TYPE (exp
))
6927 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6928 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6929 < BIGGEST_ALIGNMENT
)
6930 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6931 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6936 /* Hand back the decl for MEM[&decl, off]. */
6937 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6939 tree off
= TREE_OPERAND (exp
, 1);
6940 if (!integer_zerop (off
))
6942 offset_int boff
, coff
= mem_ref_offset (exp
);
6943 boff
= wi::lshift (coff
, LOG2_BITS_PER_UNIT
);
6946 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6954 /* If any reference in the chain is volatile, the effect is volatile. */
6955 if (TREE_THIS_VOLATILE (exp
))
6958 exp
= TREE_OPERAND (exp
, 0);
6962 /* If OFFSET is constant, see if we can return the whole thing as a
6963 constant bit position. Make sure to handle overflow during
6965 if (TREE_CODE (offset
) == INTEGER_CST
)
6967 offset_int tem
= wi::sext (wi::to_offset (offset
),
6968 TYPE_PRECISION (sizetype
));
6969 tem
= wi::lshift (tem
, LOG2_BITS_PER_UNIT
);
6971 if (wi::fits_shwi_p (tem
))
6973 *pbitpos
= tem
.to_shwi ();
6974 *poffset
= offset
= NULL_TREE
;
6978 /* Otherwise, split it up. */
6981 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6982 if (wi::neg_p (bit_offset
) || !wi::fits_shwi_p (bit_offset
))
6984 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
6985 offset_int tem
= bit_offset
.and_not (mask
);
6986 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6987 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6989 tem
= wi::arshift (tem
, LOG2_BITS_PER_UNIT
);
6990 offset
= size_binop (PLUS_EXPR
, offset
,
6991 wide_int_to_tree (sizetype
, tem
));
6994 *pbitpos
= bit_offset
.to_shwi ();
6998 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6999 if (mode
== VOIDmode
7001 && (*pbitpos
% BITS_PER_UNIT
) == 0
7002 && (*pbitsize
% BITS_PER_UNIT
) == 0)
7010 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7012 static unsigned HOST_WIDE_INT
7013 target_align (const_tree target
)
7015 /* We might have a chain of nested references with intermediate misaligning
7016 bitfields components, so need to recurse to find out. */
7018 unsigned HOST_WIDE_INT this_align
, outer_align
;
7020 switch (TREE_CODE (target
))
7026 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7027 outer_align
= target_align (TREE_OPERAND (target
, 0));
7028 return MIN (this_align
, outer_align
);
7031 case ARRAY_RANGE_REF
:
7032 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7033 outer_align
= target_align (TREE_OPERAND (target
, 0));
7034 return MIN (this_align
, outer_align
);
7037 case NON_LVALUE_EXPR
:
7038 case VIEW_CONVERT_EXPR
:
7039 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7040 outer_align
= target_align (TREE_OPERAND (target
, 0));
7041 return MAX (this_align
, outer_align
);
7044 return TYPE_ALIGN (TREE_TYPE (target
));
7049 /* Given an rtx VALUE that may contain additions and multiplications, return
7050 an equivalent value that just refers to a register, memory, or constant.
7051 This is done by generating instructions to perform the arithmetic and
7052 returning a pseudo-register containing the value.
7054 The returned value may be a REG, SUBREG, MEM or constant. */
7057 force_operand (rtx value
, rtx target
)
7060 /* Use subtarget as the target for operand 0 of a binary operation. */
7061 rtx subtarget
= get_subtarget (target
);
7062 enum rtx_code code
= GET_CODE (value
);
7064 /* Check for subreg applied to an expression produced by loop optimizer. */
7066 && !REG_P (SUBREG_REG (value
))
7067 && !MEM_P (SUBREG_REG (value
)))
7070 = simplify_gen_subreg (GET_MODE (value
),
7071 force_reg (GET_MODE (SUBREG_REG (value
)),
7072 force_operand (SUBREG_REG (value
),
7074 GET_MODE (SUBREG_REG (value
)),
7075 SUBREG_BYTE (value
));
7076 code
= GET_CODE (value
);
7079 /* Check for a PIC address load. */
7080 if ((code
== PLUS
|| code
== MINUS
)
7081 && XEXP (value
, 0) == pic_offset_table_rtx
7082 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7083 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7084 || GET_CODE (XEXP (value
, 1)) == CONST
))
7087 subtarget
= gen_reg_rtx (GET_MODE (value
));
7088 emit_move_insn (subtarget
, value
);
7092 if (ARITHMETIC_P (value
))
7094 op2
= XEXP (value
, 1);
7095 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7097 if (code
== MINUS
&& CONST_INT_P (op2
))
7100 op2
= negate_rtx (GET_MODE (value
), op2
);
7103 /* Check for an addition with OP2 a constant integer and our first
7104 operand a PLUS of a virtual register and something else. In that
7105 case, we want to emit the sum of the virtual register and the
7106 constant first and then add the other value. This allows virtual
7107 register instantiation to simply modify the constant rather than
7108 creating another one around this addition. */
7109 if (code
== PLUS
&& CONST_INT_P (op2
)
7110 && GET_CODE (XEXP (value
, 0)) == PLUS
7111 && REG_P (XEXP (XEXP (value
, 0), 0))
7112 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7113 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7115 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7116 XEXP (XEXP (value
, 0), 0), op2
,
7117 subtarget
, 0, OPTAB_LIB_WIDEN
);
7118 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7119 force_operand (XEXP (XEXP (value
,
7121 target
, 0, OPTAB_LIB_WIDEN
);
7124 op1
= force_operand (XEXP (value
, 0), subtarget
);
7125 op2
= force_operand (op2
, NULL_RTX
);
7129 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7131 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7132 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7133 target
, 1, OPTAB_LIB_WIDEN
);
7135 return expand_divmod (0,
7136 FLOAT_MODE_P (GET_MODE (value
))
7137 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7138 GET_MODE (value
), op1
, op2
, target
, 0);
7140 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7143 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7146 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7149 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7150 target
, 0, OPTAB_LIB_WIDEN
);
7152 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7153 target
, 1, OPTAB_LIB_WIDEN
);
7156 if (UNARY_P (value
))
7159 target
= gen_reg_rtx (GET_MODE (value
));
7160 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7167 case FLOAT_TRUNCATE
:
7168 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7173 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7177 case UNSIGNED_FLOAT
:
7178 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7182 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7186 #ifdef INSN_SCHEDULING
7187 /* On machines that have insn scheduling, we want all memory reference to be
7188 explicit, so we need to deal with such paradoxical SUBREGs. */
7189 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7191 = simplify_gen_subreg (GET_MODE (value
),
7192 force_reg (GET_MODE (SUBREG_REG (value
)),
7193 force_operand (SUBREG_REG (value
),
7195 GET_MODE (SUBREG_REG (value
)),
7196 SUBREG_BYTE (value
));
7202 /* Subroutine of expand_expr: return nonzero iff there is no way that
7203 EXP can reference X, which is being modified. TOP_P is nonzero if this
7204 call is going to be used to determine whether we need a temporary
7205 for EXP, as opposed to a recursive call to this function.
7207 It is always safe for this routine to return zero since it merely
7208 searches for optimization opportunities. */
7211 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7217 /* If EXP has varying size, we MUST use a target since we currently
7218 have no way of allocating temporaries of variable size
7219 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7220 So we assume here that something at a higher level has prevented a
7221 clash. This is somewhat bogus, but the best we can do. Only
7222 do this when X is BLKmode and when we are at the top level. */
7223 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7224 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7225 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7226 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7227 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7229 && GET_MODE (x
) == BLKmode
)
7230 /* If X is in the outgoing argument area, it is always safe. */
7232 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7233 || (GET_CODE (XEXP (x
, 0)) == PLUS
7234 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7237 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7238 find the underlying pseudo. */
7239 if (GET_CODE (x
) == SUBREG
)
7242 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7246 /* Now look at our tree code and possibly recurse. */
7247 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7249 case tcc_declaration
:
7250 exp_rtl
= DECL_RTL_IF_SET (exp
);
7256 case tcc_exceptional
:
7257 if (TREE_CODE (exp
) == TREE_LIST
)
7261 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7263 exp
= TREE_CHAIN (exp
);
7266 if (TREE_CODE (exp
) != TREE_LIST
)
7267 return safe_from_p (x
, exp
, 0);
7270 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7272 constructor_elt
*ce
;
7273 unsigned HOST_WIDE_INT idx
;
7275 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7276 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7277 || !safe_from_p (x
, ce
->value
, 0))
7281 else if (TREE_CODE (exp
) == ERROR_MARK
)
7282 return 1; /* An already-visited SAVE_EXPR? */
7287 /* The only case we look at here is the DECL_INITIAL inside a
7289 return (TREE_CODE (exp
) != DECL_EXPR
7290 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7291 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7292 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7295 case tcc_comparison
:
7296 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7301 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7303 case tcc_expression
:
7306 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7307 the expression. If it is set, we conflict iff we are that rtx or
7308 both are in memory. Otherwise, we check all operands of the
7309 expression recursively. */
7311 switch (TREE_CODE (exp
))
7314 /* If the operand is static or we are static, we can't conflict.
7315 Likewise if we don't conflict with the operand at all. */
7316 if (staticp (TREE_OPERAND (exp
, 0))
7317 || TREE_STATIC (exp
)
7318 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7321 /* Otherwise, the only way this can conflict is if we are taking
7322 the address of a DECL a that address if part of X, which is
7324 exp
= TREE_OPERAND (exp
, 0);
7327 if (!DECL_RTL_SET_P (exp
)
7328 || !MEM_P (DECL_RTL (exp
)))
7331 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7337 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7338 get_alias_set (exp
)))
7343 /* Assume that the call will clobber all hard registers and
7345 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7350 case WITH_CLEANUP_EXPR
:
7351 case CLEANUP_POINT_EXPR
:
7352 /* Lowered by gimplify.c. */
7356 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7362 /* If we have an rtx, we do not need to scan our operands. */
7366 nops
= TREE_OPERAND_LENGTH (exp
);
7367 for (i
= 0; i
< nops
; i
++)
7368 if (TREE_OPERAND (exp
, i
) != 0
7369 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7375 /* Should never get a type here. */
7379 /* If we have an rtl, find any enclosed object. Then see if we conflict
7383 if (GET_CODE (exp_rtl
) == SUBREG
)
7385 exp_rtl
= SUBREG_REG (exp_rtl
);
7387 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7391 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7392 are memory and they conflict. */
7393 return ! (rtx_equal_p (x
, exp_rtl
)
7394 || (MEM_P (x
) && MEM_P (exp_rtl
)
7395 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7398 /* If we reach here, it is safe. */
7403 /* Return the highest power of two that EXP is known to be a multiple of.
7404 This is used in updating alignment of MEMs in array references. */
7406 unsigned HOST_WIDE_INT
7407 highest_pow2_factor (const_tree exp
)
7409 unsigned HOST_WIDE_INT ret
;
7410 int trailing_zeros
= tree_ctz (exp
);
7411 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7412 return BIGGEST_ALIGNMENT
;
7413 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7414 if (ret
> BIGGEST_ALIGNMENT
)
7415 return BIGGEST_ALIGNMENT
;
7419 /* Similar, except that the alignment requirements of TARGET are
7420 taken into account. Assume it is at least as aligned as its
7421 type, unless it is a COMPONENT_REF in which case the layout of
7422 the structure gives the alignment. */
7424 static unsigned HOST_WIDE_INT
7425 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7427 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7428 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7430 return MAX (factor
, talign
);
7433 /* Convert the tree comparison code TCODE to the rtl one where the
7434 signedness is UNSIGNEDP. */
7436 static enum rtx_code
7437 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7449 code
= unsignedp
? LTU
: LT
;
7452 code
= unsignedp
? LEU
: LE
;
7455 code
= unsignedp
? GTU
: GT
;
7458 code
= unsignedp
? GEU
: GE
;
7460 case UNORDERED_EXPR
:
7491 /* Subroutine of expand_expr. Expand the two operands of a binary
7492 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7493 The value may be stored in TARGET if TARGET is nonzero. The
7494 MODIFIER argument is as documented by expand_expr. */
7497 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7498 enum expand_modifier modifier
)
7500 if (! safe_from_p (target
, exp1
, 1))
7502 if (operand_equal_p (exp0
, exp1
, 0))
7504 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7505 *op1
= copy_rtx (*op0
);
7509 /* If we need to preserve evaluation order, copy exp0 into its own
7510 temporary variable so that it can't be clobbered by exp1. */
7511 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7512 exp0
= save_expr (exp0
);
7513 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7514 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7519 /* Return a MEM that contains constant EXP. DEFER is as for
7520 output_constant_def and MODIFIER is as for expand_expr. */
7523 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7527 mem
= output_constant_def (exp
, defer
);
7528 if (modifier
!= EXPAND_INITIALIZER
)
7529 mem
= use_anchored_address (mem
);
7533 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7534 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7537 expand_expr_addr_expr_1 (tree exp
, rtx target
, machine_mode tmode
,
7538 enum expand_modifier modifier
, addr_space_t as
)
7540 rtx result
, subtarget
;
7542 HOST_WIDE_INT bitsize
, bitpos
;
7543 int volatilep
, unsignedp
;
7546 /* If we are taking the address of a constant and are at the top level,
7547 we have to use output_constant_def since we can't call force_const_mem
7549 /* ??? This should be considered a front-end bug. We should not be
7550 generating ADDR_EXPR of something that isn't an LVALUE. The only
7551 exception here is STRING_CST. */
7552 if (CONSTANT_CLASS_P (exp
))
7554 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7555 if (modifier
< EXPAND_SUM
)
7556 result
= force_operand (result
, target
);
7560 /* Everything must be something allowed by is_gimple_addressable. */
7561 switch (TREE_CODE (exp
))
7564 /* This case will happen via recursion for &a->b. */
7565 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7569 tree tem
= TREE_OPERAND (exp
, 0);
7570 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7571 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7572 return expand_expr (tem
, target
, tmode
, modifier
);
7576 /* Expand the initializer like constants above. */
7577 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7579 if (modifier
< EXPAND_SUM
)
7580 result
= force_operand (result
, target
);
7584 /* The real part of the complex number is always first, therefore
7585 the address is the same as the address of the parent object. */
7588 inner
= TREE_OPERAND (exp
, 0);
7592 /* The imaginary part of the complex number is always second.
7593 The expression is therefore always offset by the size of the
7596 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7597 inner
= TREE_OPERAND (exp
, 0);
7600 case COMPOUND_LITERAL_EXPR
:
7601 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
7602 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
7603 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
7604 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
7605 the initializers aren't gimplified. */
7606 if (COMPOUND_LITERAL_EXPR_DECL (exp
)
7607 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp
)))
7608 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7609 target
, tmode
, modifier
, as
);
7612 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7613 expand_expr, as that can have various side effects; LABEL_DECLs for
7614 example, may not have their DECL_RTL set yet. Expand the rtl of
7615 CONSTRUCTORs too, which should yield a memory reference for the
7616 constructor's contents. Assume language specific tree nodes can
7617 be expanded in some interesting way. */
7618 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7620 || TREE_CODE (exp
) == CONSTRUCTOR
7621 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7623 result
= expand_expr (exp
, target
, tmode
,
7624 modifier
== EXPAND_INITIALIZER
7625 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7627 /* If the DECL isn't in memory, then the DECL wasn't properly
7628 marked TREE_ADDRESSABLE, which will be either a front-end
7629 or a tree optimizer bug. */
7631 gcc_assert (MEM_P (result
));
7632 result
= XEXP (result
, 0);
7634 /* ??? Is this needed anymore? */
7636 TREE_USED (exp
) = 1;
7638 if (modifier
!= EXPAND_INITIALIZER
7639 && modifier
!= EXPAND_CONST_ADDRESS
7640 && modifier
!= EXPAND_SUM
)
7641 result
= force_operand (result
, target
);
7645 /* Pass FALSE as the last argument to get_inner_reference although
7646 we are expanding to RTL. The rationale is that we know how to
7647 handle "aligning nodes" here: we can just bypass them because
7648 they won't change the final object whose address will be returned
7649 (they actually exist only for that purpose). */
7650 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7651 &mode1
, &unsignedp
, &volatilep
, false);
7655 /* We must have made progress. */
7656 gcc_assert (inner
!= exp
);
7658 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7659 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7660 inner alignment, force the inner to be sufficiently aligned. */
7661 if (CONSTANT_CLASS_P (inner
)
7662 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7664 inner
= copy_node (inner
);
7665 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7666 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7667 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7669 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7675 if (modifier
!= EXPAND_NORMAL
)
7676 result
= force_operand (result
, NULL
);
7677 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7678 modifier
== EXPAND_INITIALIZER
7679 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7681 /* expand_expr is allowed to return an object in a mode other
7682 than TMODE. If it did, we need to convert. */
7683 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7684 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7685 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7686 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7687 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7689 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7690 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7693 subtarget
= bitpos
? NULL_RTX
: target
;
7694 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7695 1, OPTAB_LIB_WIDEN
);
7701 /* Someone beforehand should have rejected taking the address
7702 of such an object. */
7703 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7705 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7706 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7707 if (modifier
< EXPAND_SUM
)
7708 result
= force_operand (result
, target
);
7714 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7715 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7718 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
7719 enum expand_modifier modifier
)
7721 addr_space_t as
= ADDR_SPACE_GENERIC
;
7722 machine_mode address_mode
= Pmode
;
7723 machine_mode pointer_mode
= ptr_mode
;
7727 /* Target mode of VOIDmode says "whatever's natural". */
7728 if (tmode
== VOIDmode
)
7729 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7731 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7733 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7734 address_mode
= targetm
.addr_space
.address_mode (as
);
7735 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7738 /* We can get called with some Weird Things if the user does silliness
7739 like "(short) &a". In that case, convert_memory_address won't do
7740 the right thing, so ignore the given target mode. */
7741 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7742 tmode
= address_mode
;
7744 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7745 tmode
, modifier
, as
);
7747 /* Despite expand_expr claims concerning ignoring TMODE when not
7748 strictly convenient, stuff breaks if we don't honor it. Note
7749 that combined with the above, we only do this for pointer modes. */
7750 rmode
= GET_MODE (result
);
7751 if (rmode
== VOIDmode
)
7754 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7759 /* Generate code for computing CONSTRUCTOR EXP.
7760 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7761 is TRUE, instead of creating a temporary variable in memory
7762 NULL is returned and the caller needs to handle it differently. */
7765 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7766 bool avoid_temp_mem
)
7768 tree type
= TREE_TYPE (exp
);
7769 machine_mode mode
= TYPE_MODE (type
);
7771 /* Try to avoid creating a temporary at all. This is possible
7772 if all of the initializer is zero.
7773 FIXME: try to handle all [0..255] initializers we can handle
7775 if (TREE_STATIC (exp
)
7776 && !TREE_ADDRESSABLE (exp
)
7777 && target
!= 0 && mode
== BLKmode
7778 && all_zeros_p (exp
))
7780 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7784 /* All elts simple constants => refer to a constant in memory. But
7785 if this is a non-BLKmode mode, let it store a field at a time
7786 since that should make a CONST_INT, CONST_WIDE_INT or
7787 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7788 use, it is best to store directly into the target unless the type
7789 is large enough that memcpy will be used. If we are making an
7790 initializer and all operands are constant, put it in memory as
7793 FIXME: Avoid trying to fill vector constructors piece-meal.
7794 Output them with output_constant_def below unless we're sure
7795 they're zeros. This should go away when vector initializers
7796 are treated like VECTOR_CST instead of arrays. */
7797 if ((TREE_STATIC (exp
)
7798 && ((mode
== BLKmode
7799 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7800 || TREE_ADDRESSABLE (exp
)
7801 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7802 && (! can_move_by_pieces
7803 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7805 && ! mostly_zeros_p (exp
))))
7806 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7807 && TREE_CONSTANT (exp
)))
7814 constructor
= expand_expr_constant (exp
, 1, modifier
);
7816 if (modifier
!= EXPAND_CONST_ADDRESS
7817 && modifier
!= EXPAND_INITIALIZER
7818 && modifier
!= EXPAND_SUM
)
7819 constructor
= validize_mem (constructor
);
7824 /* Handle calls that pass values in multiple non-contiguous
7825 locations. The Irix 6 ABI has examples of this. */
7826 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7827 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7832 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7835 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7840 /* expand_expr: generate code for computing expression EXP.
7841 An rtx for the computed value is returned. The value is never null.
7842 In the case of a void EXP, const0_rtx is returned.
7844 The value may be stored in TARGET if TARGET is nonzero.
7845 TARGET is just a suggestion; callers must assume that
7846 the rtx returned may not be the same as TARGET.
7848 If TARGET is CONST0_RTX, it means that the value will be ignored.
7850 If TMODE is not VOIDmode, it suggests generating the
7851 result in mode TMODE. But this is done only when convenient.
7852 Otherwise, TMODE is ignored and the value generated in its natural mode.
7853 TMODE is just a suggestion; callers must assume that
7854 the rtx returned may not have mode TMODE.
7856 Note that TARGET may have neither TMODE nor MODE. In that case, it
7857 probably will not be used.
7859 If MODIFIER is EXPAND_SUM then when EXP is an addition
7860 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7861 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7862 products as above, or REG or MEM, or constant.
7863 Ordinarily in such cases we would output mul or add instructions
7864 and then return a pseudo reg containing the sum.
7866 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7867 it also marks a label as absolutely required (it can't be dead).
7868 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7869 This is used for outputting expressions used in initializers.
7871 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7872 with a constant address even if that address is not normally legitimate.
7873 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7875 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7876 a call parameter. Such targets require special care as we haven't yet
7877 marked TARGET so that it's safe from being trashed by libcalls. We
7878 don't want to use TARGET for anything but the final result;
7879 Intermediate values must go elsewhere. Additionally, calls to
7880 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7882 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7883 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7884 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7885 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7888 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7889 In this case, we don't adjust a returned MEM rtx that wouldn't be
7890 sufficiently aligned for its mode; instead, it's up to the caller
7891 to deal with it afterwards. This is used to make sure that unaligned
7892 base objects for which out-of-bounds accesses are supported, for
7893 example record types with trailing arrays, aren't realigned behind
7894 the back of the caller.
7895 The normal operating mode is to pass FALSE for this parameter. */
7898 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
7899 enum expand_modifier modifier
, rtx
*alt_rtl
,
7900 bool inner_reference_p
)
7904 /* Handle ERROR_MARK before anybody tries to access its type. */
7905 if (TREE_CODE (exp
) == ERROR_MARK
7906 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7908 ret
= CONST0_RTX (tmode
);
7909 return ret
? ret
: const0_rtx
;
7912 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
7917 /* Try to expand the conditional expression which is represented by
7918 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
7919 return the rtl reg which represents the result. Otherwise return
7923 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7924 tree treeop1 ATTRIBUTE_UNUSED
,
7925 tree treeop2 ATTRIBUTE_UNUSED
)
7928 rtx op00
, op01
, op1
, op2
;
7929 enum rtx_code comparison_code
;
7930 machine_mode comparison_mode
;
7933 tree type
= TREE_TYPE (treeop1
);
7934 int unsignedp
= TYPE_UNSIGNED (type
);
7935 machine_mode mode
= TYPE_MODE (type
);
7936 machine_mode orig_mode
= mode
;
7938 /* If we cannot do a conditional move on the mode, try doing it
7939 with the promoted mode. */
7940 if (!can_conditionally_move_p (mode
))
7942 mode
= promote_mode (type
, mode
, &unsignedp
);
7943 if (!can_conditionally_move_p (mode
))
7945 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7948 temp
= assign_temp (type
, 0, 1);
7951 expand_operands (treeop1
, treeop2
,
7952 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7954 if (TREE_CODE (treeop0
) == SSA_NAME
7955 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7957 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7958 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7959 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7960 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7961 comparison_mode
= TYPE_MODE (type
);
7962 unsignedp
= TYPE_UNSIGNED (type
);
7963 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7965 else if (COMPARISON_CLASS_P (treeop0
))
7967 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7968 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7969 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7970 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7971 unsignedp
= TYPE_UNSIGNED (type
);
7972 comparison_mode
= TYPE_MODE (type
);
7973 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7977 op00
= expand_normal (treeop0
);
7979 comparison_code
= NE
;
7980 comparison_mode
= GET_MODE (op00
);
7981 if (comparison_mode
== VOIDmode
)
7982 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7985 if (GET_MODE (op1
) != mode
)
7986 op1
= gen_lowpart (mode
, op1
);
7988 if (GET_MODE (op2
) != mode
)
7989 op2
= gen_lowpart (mode
, op2
);
7991 /* Try to emit the conditional move. */
7992 insn
= emit_conditional_move (temp
, comparison_code
,
7993 op00
, op01
, comparison_mode
,
7997 /* If we could do the conditional move, emit the sequence,
8001 rtx_insn
*seq
= get_insns ();
8004 return convert_modes (orig_mode
, mode
, temp
, 0);
8007 /* Otherwise discard the sequence and fall back to code with
8014 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
8015 enum expand_modifier modifier
)
8017 rtx op0
, op1
, op2
, temp
;
8018 rtx_code_label
*lab
;
8022 enum tree_code code
= ops
->code
;
8024 rtx subtarget
, original_target
;
8026 bool reduce_bit_field
;
8027 location_t loc
= ops
->location
;
8028 tree treeop0
, treeop1
, treeop2
;
8029 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8030 ? reduce_to_bit_field_precision ((expr), \
8036 mode
= TYPE_MODE (type
);
8037 unsignedp
= TYPE_UNSIGNED (type
);
8043 /* We should be called only on simple (binary or unary) expressions,
8044 exactly those that are valid in gimple expressions that aren't
8045 GIMPLE_SINGLE_RHS (or invalid). */
8046 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8047 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8048 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8050 ignore
= (target
== const0_rtx
8051 || ((CONVERT_EXPR_CODE_P (code
)
8052 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8053 && TREE_CODE (type
) == VOID_TYPE
));
8055 /* We should be called only if we need the result. */
8056 gcc_assert (!ignore
);
8058 /* An operation in what may be a bit-field type needs the
8059 result to be reduced to the precision of the bit-field type,
8060 which is narrower than that of the type's mode. */
8061 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8062 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8064 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8067 /* Use subtarget as the target for operand 0 of a binary operation. */
8068 subtarget
= get_subtarget (target
);
8069 original_target
= target
;
8073 case NON_LVALUE_EXPR
:
8076 if (treeop0
== error_mark_node
)
8079 if (TREE_CODE (type
) == UNION_TYPE
)
8081 tree valtype
= TREE_TYPE (treeop0
);
8083 /* If both input and output are BLKmode, this conversion isn't doing
8084 anything except possibly changing memory attribute. */
8085 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8087 rtx result
= expand_expr (treeop0
, target
, tmode
,
8090 result
= copy_rtx (result
);
8091 set_mem_attributes (result
, type
, 0);
8097 if (TYPE_MODE (type
) != BLKmode
)
8098 target
= gen_reg_rtx (TYPE_MODE (type
));
8100 target
= assign_temp (type
, 1, 1);
8104 /* Store data into beginning of memory target. */
8105 store_expr (treeop0
,
8106 adjust_address (target
, TYPE_MODE (valtype
), 0),
8107 modifier
== EXPAND_STACK_PARM
,
8112 gcc_assert (REG_P (target
));
8114 /* Store this field into a union of the proper type. */
8115 store_field (target
,
8116 MIN ((int_size_in_bytes (TREE_TYPE
8119 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8120 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8123 /* Return the entire union. */
8127 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8129 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8132 /* If the signedness of the conversion differs and OP0 is
8133 a promoted SUBREG, clear that indication since we now
8134 have to do the proper extension. */
8135 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8136 && GET_CODE (op0
) == SUBREG
)
8137 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8139 return REDUCE_BIT_FIELD (op0
);
8142 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8143 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8144 if (GET_MODE (op0
) == mode
)
8147 /* If OP0 is a constant, just convert it into the proper mode. */
8148 else if (CONSTANT_P (op0
))
8150 tree inner_type
= TREE_TYPE (treeop0
);
8151 machine_mode inner_mode
= GET_MODE (op0
);
8153 if (inner_mode
== VOIDmode
)
8154 inner_mode
= TYPE_MODE (inner_type
);
8156 if (modifier
== EXPAND_INITIALIZER
)
8157 op0
= lowpart_subreg (mode
, op0
, inner_mode
);
8159 op0
= convert_modes (mode
, inner_mode
, op0
,
8160 TYPE_UNSIGNED (inner_type
));
8163 else if (modifier
== EXPAND_INITIALIZER
)
8164 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8166 else if (target
== 0)
8167 op0
= convert_to_mode (mode
, op0
,
8168 TYPE_UNSIGNED (TREE_TYPE
8172 convert_move (target
, op0
,
8173 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8177 return REDUCE_BIT_FIELD (op0
);
8179 case ADDR_SPACE_CONVERT_EXPR
:
8181 tree treeop0_type
= TREE_TYPE (treeop0
);
8183 addr_space_t as_from
;
8185 gcc_assert (POINTER_TYPE_P (type
));
8186 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8188 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8189 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8191 /* Conversions between pointers to the same address space should
8192 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8193 gcc_assert (as_to
!= as_from
);
8195 /* Ask target code to handle conversion between pointers
8196 to overlapping address spaces. */
8197 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8198 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8200 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8201 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8206 /* For disjoint address spaces, converting anything but
8207 a null pointer invokes undefined behaviour. We simply
8208 always return a null pointer here. */
8209 return CONST0_RTX (mode
);
8212 case POINTER_PLUS_EXPR
:
8213 /* Even though the sizetype mode and the pointer's mode can be different
8214 expand is able to handle this correctly and get the correct result out
8215 of the PLUS_EXPR code. */
8216 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8217 if sizetype precision is smaller than pointer precision. */
8218 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8219 treeop1
= fold_convert_loc (loc
, type
,
8220 fold_convert_loc (loc
, ssizetype
,
8222 /* If sizetype precision is larger than pointer precision, truncate the
8223 offset to have matching modes. */
8224 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8225 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8228 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8229 something else, make sure we add the register to the constant and
8230 then to the other thing. This case can occur during strength
8231 reduction and doing it this way will produce better code if the
8232 frame pointer or argument pointer is eliminated.
8234 fold-const.c will ensure that the constant is always in the inner
8235 PLUS_EXPR, so the only case we need to do anything about is if
8236 sp, ap, or fp is our second argument, in which case we must swap
8237 the innermost first argument and our second argument. */
8239 if (TREE_CODE (treeop0
) == PLUS_EXPR
8240 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8241 && TREE_CODE (treeop1
) == VAR_DECL
8242 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8243 || DECL_RTL (treeop1
) == stack_pointer_rtx
8244 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8249 /* If the result is to be ptr_mode and we are adding an integer to
8250 something, we might be forming a constant. So try to use
8251 plus_constant. If it produces a sum and we can't accept it,
8252 use force_operand. This allows P = &ARR[const] to generate
8253 efficient code on machines where a SYMBOL_REF is not a valid
8256 If this is an EXPAND_SUM call, always return the sum. */
8257 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8258 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8260 if (modifier
== EXPAND_STACK_PARM
)
8262 if (TREE_CODE (treeop0
) == INTEGER_CST
8263 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8264 && TREE_CONSTANT (treeop1
))
8268 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
8270 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8272 /* Use wi::shwi to ensure that the constant is
8273 truncated according to the mode of OP1, then sign extended
8274 to a HOST_WIDE_INT. Using the constant directly can result
8275 in non-canonical RTL in a 64x32 cross compile. */
8276 wc
= TREE_INT_CST_LOW (treeop0
);
8278 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8279 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8280 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8281 op1
= force_operand (op1
, target
);
8282 return REDUCE_BIT_FIELD (op1
);
8285 else if (TREE_CODE (treeop1
) == INTEGER_CST
8286 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8287 && TREE_CONSTANT (treeop0
))
8291 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
8293 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8294 (modifier
== EXPAND_INITIALIZER
8295 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8296 if (! CONSTANT_P (op0
))
8298 op1
= expand_expr (treeop1
, NULL_RTX
,
8299 VOIDmode
, modifier
);
8300 /* Return a PLUS if modifier says it's OK. */
8301 if (modifier
== EXPAND_SUM
8302 || modifier
== EXPAND_INITIALIZER
)
8303 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8306 /* Use wi::shwi to ensure that the constant is
8307 truncated according to the mode of OP1, then sign extended
8308 to a HOST_WIDE_INT. Using the constant directly can result
8309 in non-canonical RTL in a 64x32 cross compile. */
8310 wc
= TREE_INT_CST_LOW (treeop1
);
8312 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8313 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8314 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8315 op0
= force_operand (op0
, target
);
8316 return REDUCE_BIT_FIELD (op0
);
8320 /* Use TER to expand pointer addition of a negated value
8321 as pointer subtraction. */
8322 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8323 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8324 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8325 && TREE_CODE (treeop1
) == SSA_NAME
8326 && TYPE_MODE (TREE_TYPE (treeop0
))
8327 == TYPE_MODE (TREE_TYPE (treeop1
)))
8329 gimple
*def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8332 treeop1
= gimple_assign_rhs1 (def
);
8338 /* No sense saving up arithmetic to be done
8339 if it's all in the wrong mode to form part of an address.
8340 And force_operand won't know whether to sign-extend or
8342 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8343 || mode
!= ptr_mode
)
8345 expand_operands (treeop0
, treeop1
,
8346 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8347 if (op0
== const0_rtx
)
8349 if (op1
== const0_rtx
)
8354 expand_operands (treeop0
, treeop1
,
8355 subtarget
, &op0
, &op1
, modifier
);
8356 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8360 /* For initializers, we are allowed to return a MINUS of two
8361 symbolic constants. Here we handle all cases when both operands
8363 /* Handle difference of two symbolic constants,
8364 for the sake of an initializer. */
8365 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8366 && really_constant_p (treeop0
)
8367 && really_constant_p (treeop1
))
8369 expand_operands (treeop0
, treeop1
,
8370 NULL_RTX
, &op0
, &op1
, modifier
);
8372 /* If the last operand is a CONST_INT, use plus_constant of
8373 the negated constant. Else make the MINUS. */
8374 if (CONST_INT_P (op1
))
8375 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8378 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8381 /* No sense saving up arithmetic to be done
8382 if it's all in the wrong mode to form part of an address.
8383 And force_operand won't know whether to sign-extend or
8385 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8386 || mode
!= ptr_mode
)
8389 expand_operands (treeop0
, treeop1
,
8390 subtarget
, &op0
, &op1
, modifier
);
8392 /* Convert A - const to A + (-const). */
8393 if (CONST_INT_P (op1
))
8395 op1
= negate_rtx (mode
, op1
);
8396 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8401 case WIDEN_MULT_PLUS_EXPR
:
8402 case WIDEN_MULT_MINUS_EXPR
:
8403 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8404 op2
= expand_normal (treeop2
);
8405 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8409 case WIDEN_MULT_EXPR
:
8410 /* If first operand is constant, swap them.
8411 Thus the following special case checks need only
8412 check the second operand. */
8413 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8414 std::swap (treeop0
, treeop1
);
8416 /* First, check if we have a multiplication of one signed and one
8417 unsigned operand. */
8418 if (TREE_CODE (treeop1
) != INTEGER_CST
8419 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8420 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8422 machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8423 this_optab
= usmul_widen_optab
;
8424 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8425 != CODE_FOR_nothing
)
8427 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8428 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8431 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8433 /* op0 and op1 might still be constant, despite the above
8434 != INTEGER_CST check. Handle it. */
8435 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8437 op0
= convert_modes (innermode
, mode
, op0
, true);
8438 op1
= convert_modes (innermode
, mode
, op1
, false);
8439 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8440 target
, unsignedp
));
8445 /* Check for a multiplication with matching signedness. */
8446 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8447 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8448 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8449 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8451 tree op0type
= TREE_TYPE (treeop0
);
8452 machine_mode innermode
= TYPE_MODE (op0type
);
8453 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8454 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8455 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8457 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8459 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8460 != CODE_FOR_nothing
)
8462 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8464 /* op0 and op1 might still be constant, despite the above
8465 != INTEGER_CST check. Handle it. */
8466 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8469 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8471 = convert_modes (innermode
, mode
, op1
,
8472 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8473 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8477 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8478 unsignedp
, this_optab
);
8479 return REDUCE_BIT_FIELD (temp
);
8481 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8483 && innermode
== word_mode
)
8486 op0
= expand_normal (treeop0
);
8487 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8488 op1
= convert_modes (innermode
, mode
,
8489 expand_normal (treeop1
),
8490 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8492 op1
= expand_normal (treeop1
);
8493 /* op0 and op1 might still be constant, despite the above
8494 != INTEGER_CST check. Handle it. */
8495 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8496 goto widen_mult_const
;
8497 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8498 unsignedp
, OPTAB_LIB_WIDEN
);
8499 hipart
= gen_highpart (innermode
, temp
);
8500 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8504 emit_move_insn (hipart
, htem
);
8505 return REDUCE_BIT_FIELD (temp
);
8509 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8510 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8511 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8512 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8516 optab opt
= fma_optab
;
8517 gimple
*def0
, *def2
;
8519 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8521 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8523 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8526 gcc_assert (fn
!= NULL_TREE
);
8527 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8528 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8531 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8532 /* The multiplication is commutative - look at its 2nd operand
8533 if the first isn't fed by a negate. */
8536 def0
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8537 /* Swap operands if the 2nd operand is fed by a negate. */
8539 std::swap (treeop0
, treeop1
);
8541 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8546 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8549 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8550 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8553 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8556 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8559 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8562 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8566 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8568 op2
= expand_normal (treeop2
);
8569 op1
= expand_normal (treeop1
);
8571 return expand_ternary_op (TYPE_MODE (type
), opt
,
8572 op0
, op1
, op2
, target
, 0);
8576 /* If this is a fixed-point operation, then we cannot use the code
8577 below because "expand_mult" doesn't support sat/no-sat fixed-point
8579 if (ALL_FIXED_POINT_MODE_P (mode
))
8582 /* If first operand is constant, swap them.
8583 Thus the following special case checks need only
8584 check the second operand. */
8585 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8586 std::swap (treeop0
, treeop1
);
8588 /* Attempt to return something suitable for generating an
8589 indexed address, for machines that support that. */
8591 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8592 && tree_fits_shwi_p (treeop1
))
8594 tree exp1
= treeop1
;
8596 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8600 op0
= force_operand (op0
, NULL_RTX
);
8602 op0
= copy_to_mode_reg (mode
, op0
);
8604 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8605 gen_int_mode (tree_to_shwi (exp1
),
8606 TYPE_MODE (TREE_TYPE (exp1
)))));
8609 if (modifier
== EXPAND_STACK_PARM
)
8612 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8613 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8615 case TRUNC_DIV_EXPR
:
8616 case FLOOR_DIV_EXPR
:
8618 case ROUND_DIV_EXPR
:
8619 case EXACT_DIV_EXPR
:
8620 /* If this is a fixed-point operation, then we cannot use the code
8621 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8623 if (ALL_FIXED_POINT_MODE_P (mode
))
8626 if (modifier
== EXPAND_STACK_PARM
)
8628 /* Possible optimization: compute the dividend with EXPAND_SUM
8629 then if the divisor is constant can optimize the case
8630 where some terms of the dividend have coeffs divisible by it. */
8631 expand_operands (treeop0
, treeop1
,
8632 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8633 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8638 case MULT_HIGHPART_EXPR
:
8639 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8640 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8644 case TRUNC_MOD_EXPR
:
8645 case FLOOR_MOD_EXPR
:
8647 case ROUND_MOD_EXPR
:
8648 if (modifier
== EXPAND_STACK_PARM
)
8650 expand_operands (treeop0
, treeop1
,
8651 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8652 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8654 case FIXED_CONVERT_EXPR
:
8655 op0
= expand_normal (treeop0
);
8656 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8657 target
= gen_reg_rtx (mode
);
8659 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8660 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8661 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8662 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8664 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8667 case FIX_TRUNC_EXPR
:
8668 op0
= expand_normal (treeop0
);
8669 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8670 target
= gen_reg_rtx (mode
);
8671 expand_fix (target
, op0
, unsignedp
);
8675 op0
= expand_normal (treeop0
);
8676 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8677 target
= gen_reg_rtx (mode
);
8678 /* expand_float can't figure out what to do if FROM has VOIDmode.
8679 So give it the correct mode. With -O, cse will optimize this. */
8680 if (GET_MODE (op0
) == VOIDmode
)
8681 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8683 expand_float (target
, op0
,
8684 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8688 op0
= expand_expr (treeop0
, subtarget
,
8689 VOIDmode
, EXPAND_NORMAL
);
8690 if (modifier
== EXPAND_STACK_PARM
)
8692 temp
= expand_unop (mode
,
8693 optab_for_tree_code (NEGATE_EXPR
, type
,
8697 return REDUCE_BIT_FIELD (temp
);
8700 op0
= expand_expr (treeop0
, subtarget
,
8701 VOIDmode
, EXPAND_NORMAL
);
8702 if (modifier
== EXPAND_STACK_PARM
)
8705 /* ABS_EXPR is not valid for complex arguments. */
8706 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8707 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8709 /* Unsigned abs is simply the operand. Testing here means we don't
8710 risk generating incorrect code below. */
8711 if (TYPE_UNSIGNED (type
))
8714 return expand_abs (mode
, op0
, target
, unsignedp
,
8715 safe_from_p (target
, treeop0
, 1));
8719 target
= original_target
;
8721 || modifier
== EXPAND_STACK_PARM
8722 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8723 || GET_MODE (target
) != mode
8725 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8726 target
= gen_reg_rtx (mode
);
8727 expand_operands (treeop0
, treeop1
,
8728 target
, &op0
, &op1
, EXPAND_NORMAL
);
8730 /* First try to do it with a special MIN or MAX instruction.
8731 If that does not win, use a conditional jump to select the proper
8733 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8734 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8739 /* At this point, a MEM target is no longer useful; we will get better
8742 if (! REG_P (target
))
8743 target
= gen_reg_rtx (mode
);
8745 /* If op1 was placed in target, swap op0 and op1. */
8746 if (target
!= op0
&& target
== op1
)
8747 std::swap (op0
, op1
);
8749 /* We generate better code and avoid problems with op1 mentioning
8750 target by forcing op1 into a pseudo if it isn't a constant. */
8751 if (! CONSTANT_P (op1
))
8752 op1
= force_reg (mode
, op1
);
8755 enum rtx_code comparison_code
;
8758 if (code
== MAX_EXPR
)
8759 comparison_code
= unsignedp
? GEU
: GE
;
8761 comparison_code
= unsignedp
? LEU
: LE
;
8763 /* Canonicalize to comparisons against 0. */
8764 if (op1
== const1_rtx
)
8766 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8767 or (a != 0 ? a : 1) for unsigned.
8768 For MIN we are safe converting (a <= 1 ? a : 1)
8769 into (a <= 0 ? a : 1) */
8770 cmpop1
= const0_rtx
;
8771 if (code
== MAX_EXPR
)
8772 comparison_code
= unsignedp
? NE
: GT
;
8774 if (op1
== constm1_rtx
&& !unsignedp
)
8776 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8777 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8778 cmpop1
= const0_rtx
;
8779 if (code
== MIN_EXPR
)
8780 comparison_code
= LT
;
8783 /* Use a conditional move if possible. */
8784 if (can_conditionally_move_p (mode
))
8790 /* Try to emit the conditional move. */
8791 insn
= emit_conditional_move (target
, comparison_code
,
8796 /* If we could do the conditional move, emit the sequence,
8800 rtx_insn
*seq
= get_insns ();
8806 /* Otherwise discard the sequence and fall back to code with
8812 emit_move_insn (target
, op0
);
8814 lab
= gen_label_rtx ();
8815 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8816 unsignedp
, mode
, NULL_RTX
, NULL
, lab
,
8819 emit_move_insn (target
, op1
);
8824 op0
= expand_expr (treeop0
, subtarget
,
8825 VOIDmode
, EXPAND_NORMAL
);
8826 if (modifier
== EXPAND_STACK_PARM
)
8828 /* In case we have to reduce the result to bitfield precision
8829 for unsigned bitfield expand this as XOR with a proper constant
8831 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8833 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
8834 false, GET_MODE_PRECISION (mode
));
8836 temp
= expand_binop (mode
, xor_optab
, op0
,
8837 immed_wide_int_const (mask
, mode
),
8838 target
, 1, OPTAB_LIB_WIDEN
);
8841 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8845 /* ??? Can optimize bitwise operations with one arg constant.
8846 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8847 and (a bitwise1 b) bitwise2 b (etc)
8848 but that is probably not worth while. */
8857 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8858 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8859 == TYPE_PRECISION (type
)));
8865 /* If this is a fixed-point operation, then we cannot use the code
8866 below because "expand_shift" doesn't support sat/no-sat fixed-point
8868 if (ALL_FIXED_POINT_MODE_P (mode
))
8871 if (! safe_from_p (subtarget
, treeop1
, 1))
8873 if (modifier
== EXPAND_STACK_PARM
)
8875 op0
= expand_expr (treeop0
, subtarget
,
8876 VOIDmode
, EXPAND_NORMAL
);
8878 /* Left shift optimization when shifting across word_size boundary.
8880 If mode == GET_MODE_WIDER_MODE (word_mode), then normally there isn't
8881 native instruction to support this wide mode left shift. Given below
8884 Type A = (Type) B << C
8887 | dest_high | dest_low |
8891 If the shift amount C caused we shift B to across the word size
8892 boundary, i.e part of B shifted into high half of destination
8893 register, and part of B remains in the low half, then GCC will use
8894 the following left shift expand logic:
8896 1. Initialize dest_low to B.
8897 2. Initialize every bit of dest_high to the sign bit of B.
8898 3. Logic left shift dest_low by C bit to finalize dest_low.
8899 The value of dest_low before this shift is kept in a temp D.
8900 4. Logic left shift dest_high by C.
8901 5. Logic right shift D by (word_size - C).
8902 6. Or the result of 4 and 5 to finalize dest_high.
8904 While, by checking gimple statements, if operand B is coming from
8905 signed extension, then we can simplify above expand logic into:
8907 1. dest_high = src_low >> (word_size - C).
8908 2. dest_low = src_low << C.
8910 We can use one arithmetic right shift to finish all the purpose of
8911 steps 2, 4, 5, 6, thus we reduce the steps needed from 6 into 2. */
8914 if (code
== LSHIFT_EXPR
8918 && mode
== GET_MODE_WIDER_MODE (word_mode
)
8919 && GET_MODE_SIZE (mode
) == 2 * GET_MODE_SIZE (word_mode
)
8920 && TREE_CONSTANT (treeop1
)
8921 && TREE_CODE (treeop0
) == SSA_NAME
)
8923 gimple
*def
= SSA_NAME_DEF_STMT (treeop0
);
8924 if (is_gimple_assign (def
)
8925 && gimple_assign_rhs_code (def
) == NOP_EXPR
)
8927 machine_mode rmode
= TYPE_MODE
8928 (TREE_TYPE (gimple_assign_rhs1 (def
)));
8930 if (GET_MODE_SIZE (rmode
) < GET_MODE_SIZE (mode
)
8931 && TREE_INT_CST_LOW (treeop1
) < GET_MODE_BITSIZE (word_mode
)
8932 && ((TREE_INT_CST_LOW (treeop1
) + GET_MODE_BITSIZE (rmode
))
8933 >= GET_MODE_BITSIZE (word_mode
)))
8935 rtx_insn
*seq
, *seq_old
;
8936 unsigned int high_off
= subreg_highpart_offset (word_mode
,
8938 rtx low
= lowpart_subreg (word_mode
, op0
, mode
);
8939 rtx dest_low
= lowpart_subreg (word_mode
, target
, mode
);
8940 rtx dest_high
= simplify_gen_subreg (word_mode
, target
,
8942 HOST_WIDE_INT ramount
= (BITS_PER_WORD
8943 - TREE_INT_CST_LOW (treeop1
));
8944 tree rshift
= build_int_cst (TREE_TYPE (treeop1
), ramount
);
8947 /* dest_high = src_low >> (word_size - C). */
8948 temp
= expand_variable_shift (RSHIFT_EXPR
, word_mode
, low
,
8949 rshift
, dest_high
, unsignedp
);
8950 if (temp
!= dest_high
)
8951 emit_move_insn (dest_high
, temp
);
8953 /* dest_low = src_low << C. */
8954 temp
= expand_variable_shift (LSHIFT_EXPR
, word_mode
, low
,
8955 treeop1
, dest_low
, unsignedp
);
8956 if (temp
!= dest_low
)
8957 emit_move_insn (dest_low
, temp
);
8963 if (have_insn_for (ASHIFT
, mode
))
8965 bool speed_p
= optimize_insn_for_speed_p ();
8967 rtx ret_old
= expand_variable_shift (code
, mode
, op0
,
8971 seq_old
= get_insns ();
8973 if (seq_cost (seq
, speed_p
)
8974 >= seq_cost (seq_old
, speed_p
))
8985 if (temp
== NULL_RTX
)
8986 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8988 if (code
== LSHIFT_EXPR
)
8989 temp
= REDUCE_BIT_FIELD (temp
);
8993 /* Could determine the answer when only additive constants differ. Also,
8994 the addition of one can be handled by changing the condition. */
9001 case UNORDERED_EXPR
:
9010 temp
= do_store_flag (ops
,
9011 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
9012 tmode
!= VOIDmode
? tmode
: mode
);
9016 /* Use a compare and a jump for BLKmode comparisons, or for function
9017 type comparisons is have_canonicalize_funcptr_for_compare. */
9020 || modifier
== EXPAND_STACK_PARM
9021 || ! safe_from_p (target
, treeop0
, 1)
9022 || ! safe_from_p (target
, treeop1
, 1)
9023 /* Make sure we don't have a hard reg (such as function's return
9024 value) live across basic blocks, if not optimizing. */
9025 || (!optimize
&& REG_P (target
)
9026 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
9027 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
9029 emit_move_insn (target
, const0_rtx
);
9031 rtx_code_label
*lab1
= gen_label_rtx ();
9032 jumpifnot_1 (code
, treeop0
, treeop1
, lab1
, -1);
9034 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
9035 emit_move_insn (target
, constm1_rtx
);
9037 emit_move_insn (target
, const1_rtx
);
9043 /* Get the rtx code of the operands. */
9044 op0
= expand_normal (treeop0
);
9045 op1
= expand_normal (treeop1
);
9048 target
= gen_reg_rtx (TYPE_MODE (type
));
9050 /* If target overlaps with op1, then either we need to force
9051 op1 into a pseudo (if target also overlaps with op0),
9052 or write the complex parts in reverse order. */
9053 switch (GET_CODE (target
))
9056 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
9058 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
9060 complex_expr_force_op1
:
9061 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
9062 emit_move_insn (temp
, op1
);
9066 complex_expr_swap_order
:
9067 /* Move the imaginary (op1) and real (op0) parts to their
9069 write_complex_part (target
, op1
, true);
9070 write_complex_part (target
, op0
, false);
9076 temp
= adjust_address_nv (target
,
9077 GET_MODE_INNER (GET_MODE (target
)), 0);
9078 if (reg_overlap_mentioned_p (temp
, op1
))
9080 machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
9081 temp
= adjust_address_nv (target
, imode
,
9082 GET_MODE_SIZE (imode
));
9083 if (reg_overlap_mentioned_p (temp
, op0
))
9084 goto complex_expr_force_op1
;
9085 goto complex_expr_swap_order
;
9089 if (reg_overlap_mentioned_p (target
, op1
))
9091 if (reg_overlap_mentioned_p (target
, op0
))
9092 goto complex_expr_force_op1
;
9093 goto complex_expr_swap_order
;
9098 /* Move the real (op0) and imaginary (op1) parts to their location. */
9099 write_complex_part (target
, op0
, false);
9100 write_complex_part (target
, op1
, true);
9104 case WIDEN_SUM_EXPR
:
9106 tree oprnd0
= treeop0
;
9107 tree oprnd1
= treeop1
;
9109 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9110 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9115 case REDUC_MAX_EXPR
:
9116 case REDUC_MIN_EXPR
:
9117 case REDUC_PLUS_EXPR
:
9119 op0
= expand_normal (treeop0
);
9120 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9121 machine_mode vec_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9123 if (optab_handler (this_optab
, vec_mode
) != CODE_FOR_nothing
)
9125 struct expand_operand ops
[2];
9126 enum insn_code icode
= optab_handler (this_optab
, vec_mode
);
9128 create_output_operand (&ops
[0], target
, mode
);
9129 create_input_operand (&ops
[1], op0
, vec_mode
);
9130 if (maybe_expand_insn (icode
, 2, ops
))
9132 target
= ops
[0].value
;
9133 if (GET_MODE (target
) != mode
)
9134 return gen_lowpart (tmode
, target
);
9138 /* Fall back to optab with vector result, and then extract scalar. */
9139 this_optab
= scalar_reduc_to_vector (this_optab
, type
);
9140 temp
= expand_unop (vec_mode
, this_optab
, op0
, NULL_RTX
, unsignedp
);
9142 /* The tree code produces a scalar result, but (somewhat by convention)
9143 the optab produces a vector with the result in element 0 if
9144 little-endian, or element N-1 if big-endian. So pull the scalar
9145 result out of that element. */
9146 int index
= BYTES_BIG_ENDIAN
? GET_MODE_NUNITS (vec_mode
) - 1 : 0;
9147 int bitsize
= GET_MODE_UNIT_BITSIZE (vec_mode
);
9148 temp
= extract_bit_field (temp
, bitsize
, bitsize
* index
, unsignedp
,
9149 target
, mode
, mode
);
9154 case VEC_UNPACK_HI_EXPR
:
9155 case VEC_UNPACK_LO_EXPR
:
9157 op0
= expand_normal (treeop0
);
9158 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9164 case VEC_UNPACK_FLOAT_HI_EXPR
:
9165 case VEC_UNPACK_FLOAT_LO_EXPR
:
9167 op0
= expand_normal (treeop0
);
9168 /* The signedness is determined from input operand. */
9169 temp
= expand_widen_pattern_expr
9170 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9171 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9177 case VEC_WIDEN_MULT_HI_EXPR
:
9178 case VEC_WIDEN_MULT_LO_EXPR
:
9179 case VEC_WIDEN_MULT_EVEN_EXPR
:
9180 case VEC_WIDEN_MULT_ODD_EXPR
:
9181 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9182 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9183 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9184 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9186 gcc_assert (target
);
9189 case VEC_PACK_TRUNC_EXPR
:
9190 case VEC_PACK_SAT_EXPR
:
9191 case VEC_PACK_FIX_TRUNC_EXPR
:
9192 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9196 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9197 op2
= expand_normal (treeop2
);
9199 /* Careful here: if the target doesn't support integral vector modes,
9200 a constant selection vector could wind up smooshed into a normal
9201 integral constant. */
9202 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9204 tree sel_type
= TREE_TYPE (treeop2
);
9206 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9207 TYPE_VECTOR_SUBPARTS (sel_type
));
9208 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9209 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9210 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9213 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9215 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9221 tree oprnd0
= treeop0
;
9222 tree oprnd1
= treeop1
;
9223 tree oprnd2
= treeop2
;
9226 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9227 op2
= expand_normal (oprnd2
);
9228 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9235 tree oprnd0
= treeop0
;
9236 tree oprnd1
= treeop1
;
9237 tree oprnd2
= treeop2
;
9240 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9241 op2
= expand_normal (oprnd2
);
9242 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9247 case REALIGN_LOAD_EXPR
:
9249 tree oprnd0
= treeop0
;
9250 tree oprnd1
= treeop1
;
9251 tree oprnd2
= treeop2
;
9254 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9255 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9256 op2
= expand_normal (oprnd2
);
9257 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9265 /* A COND_EXPR with its type being VOID_TYPE represents a
9266 conditional jump and is handled in
9267 expand_gimple_cond_expr. */
9268 gcc_assert (!VOID_TYPE_P (type
));
9270 /* Note that COND_EXPRs whose type is a structure or union
9271 are required to be constructed to contain assignments of
9272 a temporary variable, so that we can evaluate them here
9273 for side effect only. If type is void, we must do likewise. */
9275 gcc_assert (!TREE_ADDRESSABLE (type
)
9277 && TREE_TYPE (treeop1
) != void_type_node
9278 && TREE_TYPE (treeop2
) != void_type_node
);
9280 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9284 /* If we are not to produce a result, we have no target. Otherwise,
9285 if a target was specified use it; it will not be used as an
9286 intermediate target unless it is safe. If no target, use a
9289 if (modifier
!= EXPAND_STACK_PARM
9291 && safe_from_p (original_target
, treeop0
, 1)
9292 && GET_MODE (original_target
) == mode
9293 && !MEM_P (original_target
))
9294 temp
= original_target
;
9296 temp
= assign_temp (type
, 0, 1);
9298 do_pending_stack_adjust ();
9300 rtx_code_label
*lab0
= gen_label_rtx ();
9301 rtx_code_label
*lab1
= gen_label_rtx ();
9302 jumpifnot (treeop0
, lab0
, -1);
9303 store_expr (treeop1
, temp
,
9304 modifier
== EXPAND_STACK_PARM
,
9307 emit_jump_insn (targetm
.gen_jump (lab1
));
9310 store_expr (treeop2
, temp
,
9311 modifier
== EXPAND_STACK_PARM
,
9320 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9327 /* Here to do an ordinary binary operator. */
9329 expand_operands (treeop0
, treeop1
,
9330 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9332 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9334 if (modifier
== EXPAND_STACK_PARM
)
9336 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9337 unsignedp
, OPTAB_LIB_WIDEN
);
9339 /* Bitwise operations do not need bitfield reduction as we expect their
9340 operands being properly truncated. */
9341 if (code
== BIT_XOR_EXPR
9342 || code
== BIT_AND_EXPR
9343 || code
== BIT_IOR_EXPR
)
9345 return REDUCE_BIT_FIELD (temp
);
9347 #undef REDUCE_BIT_FIELD
9350 /* Return TRUE if expression STMT is suitable for replacement.
9351 Never consider memory loads as replaceable, because those don't ever lead
9352 into constant expressions. */
9355 stmt_is_replaceable_p (gimple
*stmt
)
9357 if (ssa_is_replaceable_p (stmt
))
9359 /* Don't move around loads. */
9360 if (!gimple_assign_single_p (stmt
)
9361 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9368 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
9369 enum expand_modifier modifier
, rtx
*alt_rtl
,
9370 bool inner_reference_p
)
9372 rtx op0
, op1
, temp
, decl_rtl
;
9375 machine_mode mode
, dmode
;
9376 enum tree_code code
= TREE_CODE (exp
);
9377 rtx subtarget
, original_target
;
9380 bool reduce_bit_field
;
9381 location_t loc
= EXPR_LOCATION (exp
);
9382 struct separate_ops ops
;
9383 tree treeop0
, treeop1
, treeop2
;
9384 tree ssa_name
= NULL_TREE
;
9387 type
= TREE_TYPE (exp
);
9388 mode
= TYPE_MODE (type
);
9389 unsignedp
= TYPE_UNSIGNED (type
);
9391 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9392 if (!VL_EXP_CLASS_P (exp
))
9393 switch (TREE_CODE_LENGTH (code
))
9396 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9397 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9398 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9408 ignore
= (target
== const0_rtx
9409 || ((CONVERT_EXPR_CODE_P (code
)
9410 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9411 && TREE_CODE (type
) == VOID_TYPE
));
9413 /* An operation in what may be a bit-field type needs the
9414 result to be reduced to the precision of the bit-field type,
9415 which is narrower than that of the type's mode. */
9416 reduce_bit_field
= (!ignore
9417 && INTEGRAL_TYPE_P (type
)
9418 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9420 /* If we are going to ignore this result, we need only do something
9421 if there is a side-effect somewhere in the expression. If there
9422 is, short-circuit the most common cases here. Note that we must
9423 not call expand_expr with anything but const0_rtx in case this
9424 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9428 if (! TREE_SIDE_EFFECTS (exp
))
9431 /* Ensure we reference a volatile object even if value is ignored, but
9432 don't do this if all we are doing is taking its address. */
9433 if (TREE_THIS_VOLATILE (exp
)
9434 && TREE_CODE (exp
) != FUNCTION_DECL
9435 && mode
!= VOIDmode
&& mode
!= BLKmode
9436 && modifier
!= EXPAND_CONST_ADDRESS
)
9438 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9444 if (TREE_CODE_CLASS (code
) == tcc_unary
9445 || code
== BIT_FIELD_REF
9446 || code
== COMPONENT_REF
9447 || code
== INDIRECT_REF
)
9448 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9451 else if (TREE_CODE_CLASS (code
) == tcc_binary
9452 || TREE_CODE_CLASS (code
) == tcc_comparison
9453 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9455 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9456 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9463 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9466 /* Use subtarget as the target for operand 0 of a binary operation. */
9467 subtarget
= get_subtarget (target
);
9468 original_target
= target
;
9474 tree function
= decl_function_context (exp
);
9476 temp
= label_rtx (exp
);
9477 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9479 if (function
!= current_function_decl
9481 LABEL_REF_NONLOCAL_P (temp
) = 1;
9483 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9488 /* ??? ivopts calls expander, without any preparation from
9489 out-of-ssa. So fake instructions as if this was an access to the
9490 base variable. This unnecessarily allocates a pseudo, see how we can
9491 reuse it, if partition base vars have it set already. */
9492 if (!currently_expanding_to_rtl
)
9494 tree var
= SSA_NAME_VAR (exp
);
9495 if (var
&& DECL_RTL_SET_P (var
))
9496 return DECL_RTL (var
);
9497 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9498 LAST_VIRTUAL_REGISTER
+ 1);
9501 g
= get_gimple_for_ssa_name (exp
);
9502 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9504 && modifier
== EXPAND_INITIALIZER
9505 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9506 && (optimize
|| !SSA_NAME_VAR (exp
)
9507 || DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9508 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9509 g
= SSA_NAME_DEF_STMT (exp
);
9513 location_t saved_loc
= curr_insn_location ();
9514 location_t loc
= gimple_location (g
);
9515 if (loc
!= UNKNOWN_LOCATION
)
9516 set_curr_insn_location (loc
);
9517 ops
.code
= gimple_assign_rhs_code (g
);
9518 switch (get_gimple_rhs_class (ops
.code
))
9520 case GIMPLE_TERNARY_RHS
:
9521 ops
.op2
= gimple_assign_rhs3 (g
);
9523 case GIMPLE_BINARY_RHS
:
9524 ops
.op1
= gimple_assign_rhs2 (g
);
9526 /* Try to expand conditonal compare. */
9527 if (targetm
.gen_ccmp_first
)
9529 gcc_checking_assert (targetm
.gen_ccmp_next
!= NULL
);
9530 r
= expand_ccmp_expr (g
);
9535 case GIMPLE_UNARY_RHS
:
9536 ops
.op0
= gimple_assign_rhs1 (g
);
9537 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9539 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9541 case GIMPLE_SINGLE_RHS
:
9543 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9544 tmode
, modifier
, NULL
, inner_reference_p
);
9550 set_curr_insn_location (saved_loc
);
9551 if (REG_P (r
) && !REG_EXPR (r
))
9552 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9557 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9558 exp
= SSA_NAME_VAR (ssa_name
);
9559 goto expand_decl_rtl
;
9563 /* If a static var's type was incomplete when the decl was written,
9564 but the type is complete now, lay out the decl now. */
9565 if (DECL_SIZE (exp
) == 0
9566 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9567 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9568 layout_decl (exp
, 0);
9570 /* ... fall through ... */
9574 decl_rtl
= DECL_RTL (exp
);
9576 gcc_assert (decl_rtl
);
9577 decl_rtl
= copy_rtx (decl_rtl
);
9578 /* Record writes to register variables. */
9579 if (modifier
== EXPAND_WRITE
9581 && HARD_REGISTER_P (decl_rtl
))
9582 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9583 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9585 /* Ensure variable marked as used even if it doesn't go through
9586 a parser. If it hasn't be used yet, write out an external
9589 TREE_USED (exp
) = 1;
9591 /* Show we haven't gotten RTL for this yet. */
9594 /* Variables inherited from containing functions should have
9595 been lowered by this point. */
9597 context
= decl_function_context (exp
);
9599 || SCOPE_FILE_SCOPE_P (context
)
9600 || context
== current_function_decl
9601 || TREE_STATIC (exp
)
9602 || DECL_EXTERNAL (exp
)
9603 /* ??? C++ creates functions that are not TREE_STATIC. */
9604 || TREE_CODE (exp
) == FUNCTION_DECL
);
9606 /* This is the case of an array whose size is to be determined
9607 from its initializer, while the initializer is still being parsed.
9608 ??? We aren't parsing while expanding anymore. */
9610 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9611 temp
= validize_mem (decl_rtl
);
9613 /* If DECL_RTL is memory, we are in the normal case and the
9614 address is not valid, get the address into a register. */
9616 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9619 *alt_rtl
= decl_rtl
;
9620 decl_rtl
= use_anchored_address (decl_rtl
);
9621 if (modifier
!= EXPAND_CONST_ADDRESS
9622 && modifier
!= EXPAND_SUM
9623 && !memory_address_addr_space_p (exp
? DECL_MODE (exp
)
9624 : GET_MODE (decl_rtl
),
9626 MEM_ADDR_SPACE (decl_rtl
)))
9627 temp
= replace_equiv_address (decl_rtl
,
9628 copy_rtx (XEXP (decl_rtl
, 0)));
9631 /* If we got something, return it. But first, set the alignment
9632 if the address is a register. */
9635 if (exp
&& MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9636 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9642 dmode
= DECL_MODE (exp
);
9644 dmode
= TYPE_MODE (TREE_TYPE (ssa_name
));
9646 /* If the mode of DECL_RTL does not match that of the decl,
9647 there are two cases: we are dealing with a BLKmode value
9648 that is returned in a register, or we are dealing with
9649 a promoted value. In the latter case, return a SUBREG
9650 of the wanted mode, but mark it so that we know that it
9651 was already extended. */
9652 if (REG_P (decl_rtl
)
9654 && GET_MODE (decl_rtl
) != dmode
)
9658 /* Get the signedness to be used for this variable. Ensure we get
9659 the same mode we got when the variable was declared. */
9660 if (code
!= SSA_NAME
)
9661 pmode
= promote_decl_mode (exp
, &unsignedp
);
9662 else if ((g
= SSA_NAME_DEF_STMT (ssa_name
))
9663 && gimple_code (g
) == GIMPLE_CALL
9664 && !gimple_call_internal_p (g
))
9665 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9666 gimple_call_fntype (g
),
9669 pmode
= promote_ssa_mode (ssa_name
, &unsignedp
);
9670 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9672 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9673 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9674 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9681 /* Given that TYPE_PRECISION (type) is not always equal to
9682 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9683 the former to the latter according to the signedness of the
9685 temp
= immed_wide_int_const (wide_int::from
9687 GET_MODE_PRECISION (TYPE_MODE (type
)),
9694 tree tmp
= NULL_TREE
;
9695 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9696 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9697 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9698 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9699 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9700 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9701 return const_vector_from_tree (exp
);
9702 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9704 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9706 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9710 vec
<constructor_elt
, va_gc
> *v
;
9712 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9713 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9714 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9715 tmp
= build_constructor (type
, v
);
9717 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9722 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9725 /* If optimized, generate immediate CONST_DOUBLE
9726 which will be turned into memory by reload if necessary.
9728 We used to force a register so that loop.c could see it. But
9729 this does not allow gen_* patterns to perform optimizations with
9730 the constants. It also produces two insns in cases like "x = 1.0;".
9731 On most machines, floating-point constants are not permitted in
9732 many insns, so we'd end up copying it to a register in any case.
9734 Now, we do the copying in expand_binop, if appropriate. */
9735 return const_double_from_real_value (TREE_REAL_CST (exp
),
9736 TYPE_MODE (TREE_TYPE (exp
)));
9739 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9740 TYPE_MODE (TREE_TYPE (exp
)));
9743 /* Handle evaluating a complex constant in a CONCAT target. */
9744 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9746 machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9749 rtarg
= XEXP (original_target
, 0);
9750 itarg
= XEXP (original_target
, 1);
9752 /* Move the real and imaginary parts separately. */
9753 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9754 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9757 emit_move_insn (rtarg
, op0
);
9759 emit_move_insn (itarg
, op1
);
9761 return original_target
;
9764 /* ... fall through ... */
9767 temp
= expand_expr_constant (exp
, 1, modifier
);
9769 /* temp contains a constant address.
9770 On RISC machines where a constant address isn't valid,
9771 make some insns to get that address into a register. */
9772 if (modifier
!= EXPAND_CONST_ADDRESS
9773 && modifier
!= EXPAND_INITIALIZER
9774 && modifier
!= EXPAND_SUM
9775 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9776 MEM_ADDR_SPACE (temp
)))
9777 return replace_equiv_address (temp
,
9778 copy_rtx (XEXP (temp
, 0)));
9784 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
9787 if (!SAVE_EXPR_RESOLVED_P (exp
))
9789 /* We can indeed still hit this case, typically via builtin
9790 expanders calling save_expr immediately before expanding
9791 something. Assume this means that we only have to deal
9792 with non-BLKmode values. */
9793 gcc_assert (GET_MODE (ret
) != BLKmode
);
9795 val
= build_decl (curr_insn_location (),
9796 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9797 DECL_ARTIFICIAL (val
) = 1;
9798 DECL_IGNORED_P (val
) = 1;
9800 TREE_OPERAND (exp
, 0) = treeop0
;
9801 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9803 if (!CONSTANT_P (ret
))
9804 ret
= copy_to_reg (ret
);
9805 SET_DECL_RTL (val
, ret
);
9813 /* If we don't need the result, just ensure we evaluate any
9817 unsigned HOST_WIDE_INT idx
;
9820 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9821 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9826 return expand_constructor (exp
, target
, modifier
, false);
9828 case TARGET_MEM_REF
:
9831 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9832 enum insn_code icode
;
9835 op0
= addr_for_mem_ref (exp
, as
, true);
9836 op0
= memory_address_addr_space (mode
, op0
, as
);
9837 temp
= gen_rtx_MEM (mode
, op0
);
9838 set_mem_attributes (temp
, exp
, 0);
9839 set_mem_addr_space (temp
, as
);
9840 align
= get_object_alignment (exp
);
9841 if (modifier
!= EXPAND_WRITE
9842 && modifier
!= EXPAND_MEMORY
9844 && align
< GET_MODE_ALIGNMENT (mode
)
9845 /* If the target does not have special handling for unaligned
9846 loads of mode then it can use regular moves for them. */
9847 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9848 != CODE_FOR_nothing
))
9850 struct expand_operand ops
[2];
9852 /* We've already validated the memory, and we're creating a
9853 new pseudo destination. The predicates really can't fail,
9854 nor can the generator. */
9855 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9856 create_fixed_operand (&ops
[1], temp
);
9857 expand_insn (icode
, 2, ops
);
9858 temp
= ops
[0].value
;
9866 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9867 machine_mode address_mode
;
9868 tree base
= TREE_OPERAND (exp
, 0);
9870 enum insn_code icode
;
9872 /* Handle expansion of non-aliased memory with non-BLKmode. That
9873 might end up in a register. */
9874 if (mem_ref_refers_to_non_mem_p (exp
))
9876 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
9877 base
= TREE_OPERAND (base
, 0);
9879 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9880 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9881 == tree_to_uhwi (TYPE_SIZE (type
))))
9882 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9883 target
, tmode
, modifier
);
9884 if (TYPE_MODE (type
) == BLKmode
)
9886 temp
= assign_stack_temp (DECL_MODE (base
),
9887 GET_MODE_SIZE (DECL_MODE (base
)));
9888 store_expr (base
, temp
, 0, false);
9889 temp
= adjust_address (temp
, BLKmode
, offset
);
9890 set_mem_size (temp
, int_size_in_bytes (type
));
9893 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9894 bitsize_int (offset
* BITS_PER_UNIT
));
9895 return expand_expr (exp
, target
, tmode
, modifier
);
9897 address_mode
= targetm
.addr_space
.address_mode (as
);
9898 base
= TREE_OPERAND (exp
, 0);
9899 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9901 tree mask
= gimple_assign_rhs2 (def_stmt
);
9902 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9903 gimple_assign_rhs1 (def_stmt
), mask
);
9904 TREE_OPERAND (exp
, 0) = base
;
9906 align
= get_object_alignment (exp
);
9907 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9908 op0
= memory_address_addr_space (mode
, op0
, as
);
9909 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9911 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
9912 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9913 op0
= memory_address_addr_space (mode
, op0
, as
);
9915 temp
= gen_rtx_MEM (mode
, op0
);
9916 set_mem_attributes (temp
, exp
, 0);
9917 set_mem_addr_space (temp
, as
);
9918 if (TREE_THIS_VOLATILE (exp
))
9919 MEM_VOLATILE_P (temp
) = 1;
9920 if (modifier
!= EXPAND_WRITE
9921 && modifier
!= EXPAND_MEMORY
9922 && !inner_reference_p
9924 && align
< GET_MODE_ALIGNMENT (mode
))
9926 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9927 != CODE_FOR_nothing
)
9929 struct expand_operand ops
[2];
9931 /* We've already validated the memory, and we're creating a
9932 new pseudo destination. The predicates really can't fail,
9933 nor can the generator. */
9934 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9935 create_fixed_operand (&ops
[1], temp
);
9936 expand_insn (icode
, 2, ops
);
9937 temp
= ops
[0].value
;
9939 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9940 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9941 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9942 (modifier
== EXPAND_STACK_PARM
9943 ? NULL_RTX
: target
),
9952 tree array
= treeop0
;
9953 tree index
= treeop1
;
9956 /* Fold an expression like: "foo"[2].
9957 This is not done in fold so it won't happen inside &.
9958 Don't fold if this is for wide characters since it's too
9959 difficult to do correctly and this is a very rare case. */
9961 if (modifier
!= EXPAND_CONST_ADDRESS
9962 && modifier
!= EXPAND_INITIALIZER
9963 && modifier
!= EXPAND_MEMORY
)
9965 tree t
= fold_read_from_constant_string (exp
);
9968 return expand_expr (t
, target
, tmode
, modifier
);
9971 /* If this is a constant index into a constant array,
9972 just get the value from the array. Handle both the cases when
9973 we have an explicit constructor and when our operand is a variable
9974 that was declared const. */
9976 if (modifier
!= EXPAND_CONST_ADDRESS
9977 && modifier
!= EXPAND_INITIALIZER
9978 && modifier
!= EXPAND_MEMORY
9979 && TREE_CODE (array
) == CONSTRUCTOR
9980 && ! TREE_SIDE_EFFECTS (array
)
9981 && TREE_CODE (index
) == INTEGER_CST
)
9983 unsigned HOST_WIDE_INT ix
;
9986 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9988 if (tree_int_cst_equal (field
, index
))
9990 if (!TREE_SIDE_EFFECTS (value
))
9991 return expand_expr (fold (value
), target
, tmode
, modifier
);
9996 else if (optimize
>= 1
9997 && modifier
!= EXPAND_CONST_ADDRESS
9998 && modifier
!= EXPAND_INITIALIZER
9999 && modifier
!= EXPAND_MEMORY
10000 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
10001 && TREE_CODE (index
) == INTEGER_CST
10002 && (TREE_CODE (array
) == VAR_DECL
10003 || TREE_CODE (array
) == CONST_DECL
)
10004 && (init
= ctor_for_folding (array
)) != error_mark_node
)
10006 if (init
== NULL_TREE
)
10008 tree value
= build_zero_cst (type
);
10009 if (TREE_CODE (value
) == CONSTRUCTOR
)
10011 /* If VALUE is a CONSTRUCTOR, this optimization is only
10012 useful if this doesn't store the CONSTRUCTOR into
10013 memory. If it does, it is more efficient to just
10014 load the data from the array directly. */
10015 rtx ret
= expand_constructor (value
, target
,
10017 if (ret
== NULL_RTX
)
10022 return expand_expr (value
, target
, tmode
, modifier
);
10024 else if (TREE_CODE (init
) == CONSTRUCTOR
)
10026 unsigned HOST_WIDE_INT ix
;
10029 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
10031 if (tree_int_cst_equal (field
, index
))
10033 if (TREE_SIDE_EFFECTS (value
))
10036 if (TREE_CODE (value
) == CONSTRUCTOR
)
10038 /* If VALUE is a CONSTRUCTOR, this
10039 optimization is only useful if
10040 this doesn't store the CONSTRUCTOR
10041 into memory. If it does, it is more
10042 efficient to just load the data from
10043 the array directly. */
10044 rtx ret
= expand_constructor (value
, target
,
10046 if (ret
== NULL_RTX
)
10051 expand_expr (fold (value
), target
, tmode
, modifier
);
10054 else if (TREE_CODE (init
) == STRING_CST
)
10056 tree low_bound
= array_ref_low_bound (exp
);
10057 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
10059 /* Optimize the special case of a zero lower bound.
10061 We convert the lower bound to sizetype to avoid problems
10062 with constant folding. E.g. suppose the lower bound is
10063 1 and its mode is QI. Without the conversion
10064 (ARRAY + (INDEX - (unsigned char)1))
10066 (ARRAY + (-(unsigned char)1) + INDEX)
10068 (ARRAY + 255 + INDEX). Oops! */
10069 if (!integer_zerop (low_bound
))
10070 index1
= size_diffop_loc (loc
, index1
,
10071 fold_convert_loc (loc
, sizetype
,
10074 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
10076 tree type
= TREE_TYPE (TREE_TYPE (init
));
10077 machine_mode mode
= TYPE_MODE (type
);
10079 if (GET_MODE_CLASS (mode
) == MODE_INT
10080 && GET_MODE_SIZE (mode
) == 1)
10081 return gen_int_mode (TREE_STRING_POINTER (init
)
10082 [TREE_INT_CST_LOW (index1
)],
10088 goto normal_inner_ref
;
10090 case COMPONENT_REF
:
10091 /* If the operand is a CONSTRUCTOR, we can just extract the
10092 appropriate field if it is present. */
10093 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
10095 unsigned HOST_WIDE_INT idx
;
10098 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
10100 if (field
== treeop1
10101 /* We can normally use the value of the field in the
10102 CONSTRUCTOR. However, if this is a bitfield in
10103 an integral mode that we can fit in a HOST_WIDE_INT,
10104 we must mask only the number of bits in the bitfield,
10105 since this is done implicitly by the constructor. If
10106 the bitfield does not meet either of those conditions,
10107 we can't do this optimization. */
10108 && (! DECL_BIT_FIELD (field
)
10109 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
10110 && (GET_MODE_PRECISION (DECL_MODE (field
))
10111 <= HOST_BITS_PER_WIDE_INT
))))
10113 if (DECL_BIT_FIELD (field
)
10114 && modifier
== EXPAND_STACK_PARM
)
10116 op0
= expand_expr (value
, target
, tmode
, modifier
);
10117 if (DECL_BIT_FIELD (field
))
10119 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
10120 machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
10122 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
10124 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
10126 op0
= expand_and (imode
, op0
, op1
, target
);
10130 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10132 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10134 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10142 goto normal_inner_ref
;
10144 case BIT_FIELD_REF
:
10145 case ARRAY_RANGE_REF
:
10148 machine_mode mode1
, mode2
;
10149 HOST_WIDE_INT bitsize
, bitpos
;
10151 int volatilep
= 0, must_force_mem
;
10152 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
10153 &mode1
, &unsignedp
, &volatilep
, true);
10154 rtx orig_op0
, memloc
;
10155 bool clear_mem_expr
= false;
10157 /* If we got back the original object, something is wrong. Perhaps
10158 we are evaluating an expression too early. In any event, don't
10159 infinitely recurse. */
10160 gcc_assert (tem
!= exp
);
10162 /* If TEM's type is a union of variable size, pass TARGET to the inner
10163 computation, since it will need a temporary and TARGET is known
10164 to have to do. This occurs in unchecked conversion in Ada. */
10166 = expand_expr_real (tem
,
10167 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10168 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10169 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10171 && modifier
!= EXPAND_STACK_PARM
10172 ? target
: NULL_RTX
),
10174 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10177 /* If the field has a mode, we want to access it in the
10178 field's mode, not the computed mode.
10179 If a MEM has VOIDmode (external with incomplete type),
10180 use BLKmode for it instead. */
10183 if (mode1
!= VOIDmode
)
10184 op0
= adjust_address (op0
, mode1
, 0);
10185 else if (GET_MODE (op0
) == VOIDmode
)
10186 op0
= adjust_address (op0
, BLKmode
, 0);
10190 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10192 /* If we have either an offset, a BLKmode result, or a reference
10193 outside the underlying object, we must force it to memory.
10194 Such a case can occur in Ada if we have unchecked conversion
10195 of an expression from a scalar type to an aggregate type or
10196 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10197 passed a partially uninitialized object or a view-conversion
10198 to a larger size. */
10199 must_force_mem
= (offset
10200 || mode1
== BLKmode
10201 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10203 /* Handle CONCAT first. */
10204 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10207 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
10210 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10213 op0
= XEXP (op0
, 0);
10214 mode2
= GET_MODE (op0
);
10216 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10217 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10221 op0
= XEXP (op0
, 1);
10223 mode2
= GET_MODE (op0
);
10226 /* Otherwise force into memory. */
10227 must_force_mem
= 1;
10230 /* If this is a constant, put it in a register if it is a legitimate
10231 constant and we don't need a memory reference. */
10232 if (CONSTANT_P (op0
)
10233 && mode2
!= BLKmode
10234 && targetm
.legitimate_constant_p (mode2
, op0
)
10235 && !must_force_mem
)
10236 op0
= force_reg (mode2
, op0
);
10238 /* Otherwise, if this is a constant, try to force it to the constant
10239 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10240 is a legitimate constant. */
10241 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10242 op0
= validize_mem (memloc
);
10244 /* Otherwise, if this is a constant or the object is not in memory
10245 and need be, put it there. */
10246 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10248 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10249 emit_move_insn (memloc
, op0
);
10251 clear_mem_expr
= true;
10256 machine_mode address_mode
;
10257 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10260 gcc_assert (MEM_P (op0
));
10262 address_mode
= get_address_mode (op0
);
10263 if (GET_MODE (offset_rtx
) != address_mode
)
10265 /* We cannot be sure that the RTL in offset_rtx is valid outside
10266 of a memory address context, so force it into a register
10267 before attempting to convert it to the desired mode. */
10268 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
10269 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10272 /* See the comment in expand_assignment for the rationale. */
10273 if (mode1
!= VOIDmode
10276 && (bitpos
% bitsize
) == 0
10277 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10278 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10280 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10284 op0
= offset_address (op0
, offset_rtx
,
10285 highest_pow2_factor (offset
));
10288 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10289 record its alignment as BIGGEST_ALIGNMENT. */
10290 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10291 && is_aligning_offset (offset
, tem
))
10292 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10294 /* Don't forget about volatility even if this is a bitfield. */
10295 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10297 if (op0
== orig_op0
)
10298 op0
= copy_rtx (op0
);
10300 MEM_VOLATILE_P (op0
) = 1;
10303 /* In cases where an aligned union has an unaligned object
10304 as a field, we might be extracting a BLKmode value from
10305 an integer-mode (e.g., SImode) object. Handle this case
10306 by doing the extract into an object as wide as the field
10307 (which we know to be the width of a basic mode), then
10308 storing into memory, and changing the mode to BLKmode. */
10309 if (mode1
== VOIDmode
10310 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10311 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10312 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10313 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10314 && modifier
!= EXPAND_CONST_ADDRESS
10315 && modifier
!= EXPAND_INITIALIZER
10316 && modifier
!= EXPAND_MEMORY
)
10317 /* If the bitfield is volatile and the bitsize
10318 is narrower than the access size of the bitfield,
10319 we need to extract bitfields from the access. */
10320 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10321 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10322 && mode1
!= BLKmode
10323 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10324 /* If the field isn't aligned enough to fetch as a memref,
10325 fetch it as a bit field. */
10326 || (mode1
!= BLKmode
10327 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10328 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10330 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10331 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10332 && modifier
!= EXPAND_MEMORY
10333 && ((modifier
== EXPAND_CONST_ADDRESS
10334 || modifier
== EXPAND_INITIALIZER
)
10336 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10337 || (bitpos
% BITS_PER_UNIT
!= 0)))
10338 /* If the type and the field are a constant size and the
10339 size of the type isn't the same size as the bitfield,
10340 we must use bitfield operations. */
10342 && TYPE_SIZE (TREE_TYPE (exp
))
10343 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10344 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10347 machine_mode ext_mode
= mode
;
10349 if (ext_mode
== BLKmode
10350 && ! (target
!= 0 && MEM_P (op0
)
10352 && bitpos
% BITS_PER_UNIT
== 0))
10353 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10355 if (ext_mode
== BLKmode
)
10358 target
= assign_temp (type
, 1, 1);
10360 /* ??? Unlike the similar test a few lines below, this one is
10361 very likely obsolete. */
10365 /* In this case, BITPOS must start at a byte boundary and
10366 TARGET, if specified, must be a MEM. */
10367 gcc_assert (MEM_P (op0
)
10368 && (!target
|| MEM_P (target
))
10369 && !(bitpos
% BITS_PER_UNIT
));
10371 emit_block_move (target
,
10372 adjust_address (op0
, VOIDmode
,
10373 bitpos
/ BITS_PER_UNIT
),
10374 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10376 (modifier
== EXPAND_STACK_PARM
10377 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10382 /* If we have nothing to extract, the result will be 0 for targets
10383 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10384 return 0 for the sake of consistency, as reading a zero-sized
10385 bitfield is valid in Ada and the value is fully specified. */
10389 op0
= validize_mem (op0
);
10391 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10392 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10394 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10395 (modifier
== EXPAND_STACK_PARM
10396 ? NULL_RTX
: target
),
10397 ext_mode
, ext_mode
);
10399 /* If the result is a record type and BITSIZE is narrower than
10400 the mode of OP0, an integral mode, and this is a big endian
10401 machine, we must put the field into the high-order bits. */
10402 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10403 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10404 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10405 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10406 GET_MODE_BITSIZE (GET_MODE (op0
))
10407 - bitsize
, op0
, 1);
10409 /* If the result type is BLKmode, store the data into a temporary
10410 of the appropriate type, but with the mode corresponding to the
10411 mode for the data we have (op0's mode). */
10412 if (mode
== BLKmode
)
10415 = assign_stack_temp_for_type (ext_mode
,
10416 GET_MODE_BITSIZE (ext_mode
),
10418 emit_move_insn (new_rtx
, op0
);
10419 op0
= copy_rtx (new_rtx
);
10420 PUT_MODE (op0
, BLKmode
);
10426 /* If the result is BLKmode, use that to access the object
10428 if (mode
== BLKmode
)
10431 /* Get a reference to just this component. */
10432 if (modifier
== EXPAND_CONST_ADDRESS
10433 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10434 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10436 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10438 if (op0
== orig_op0
)
10439 op0
= copy_rtx (op0
);
10441 set_mem_attributes (op0
, exp
, 0);
10443 if (REG_P (XEXP (op0
, 0)))
10444 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10446 /* If op0 is a temporary because the original expressions was forced
10447 to memory, clear MEM_EXPR so that the original expression cannot
10448 be marked as addressable through MEM_EXPR of the temporary. */
10449 if (clear_mem_expr
)
10450 set_mem_expr (op0
, NULL_TREE
);
10452 MEM_VOLATILE_P (op0
) |= volatilep
;
10453 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10454 || modifier
== EXPAND_CONST_ADDRESS
10455 || modifier
== EXPAND_INITIALIZER
)
10459 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10461 convert_move (target
, op0
, unsignedp
);
10466 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10469 /* All valid uses of __builtin_va_arg_pack () are removed during
10471 if (CALL_EXPR_VA_ARG_PACK (exp
))
10472 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10474 tree fndecl
= get_callee_fndecl (exp
), attr
;
10477 && (attr
= lookup_attribute ("error",
10478 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10479 error ("%Kcall to %qs declared with attribute error: %s",
10480 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10481 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10483 && (attr
= lookup_attribute ("warning",
10484 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10485 warning_at (tree_nonartificial_location (exp
),
10486 0, "%Kcall to %qs declared with attribute warning: %s",
10487 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10488 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10490 /* Check for a built-in function. */
10491 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10493 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10494 if (CALL_WITH_BOUNDS_P (exp
))
10495 return expand_builtin_with_bounds (exp
, target
, subtarget
,
10498 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10501 return expand_call (exp
, target
, ignore
);
10503 case VIEW_CONVERT_EXPR
:
10506 /* If we are converting to BLKmode, try to avoid an intermediate
10507 temporary by fetching an inner memory reference. */
10508 if (mode
== BLKmode
10509 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10510 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10511 && handled_component_p (treeop0
))
10513 machine_mode mode1
;
10514 HOST_WIDE_INT bitsize
, bitpos
;
10519 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10520 &offset
, &mode1
, &unsignedp
, &volatilep
,
10524 /* ??? We should work harder and deal with non-zero offsets. */
10526 && (bitpos
% BITS_PER_UNIT
) == 0
10528 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10530 /* See the normal_inner_ref case for the rationale. */
10532 = expand_expr_real (tem
,
10533 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10534 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10536 && modifier
!= EXPAND_STACK_PARM
10537 ? target
: NULL_RTX
),
10539 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10542 if (MEM_P (orig_op0
))
10546 /* Get a reference to just this component. */
10547 if (modifier
== EXPAND_CONST_ADDRESS
10548 || modifier
== EXPAND_SUM
10549 || modifier
== EXPAND_INITIALIZER
)
10550 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10552 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10554 if (op0
== orig_op0
)
10555 op0
= copy_rtx (op0
);
10557 set_mem_attributes (op0
, treeop0
, 0);
10558 if (REG_P (XEXP (op0
, 0)))
10559 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10561 MEM_VOLATILE_P (op0
) |= volatilep
;
10567 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10568 NULL
, inner_reference_p
);
10570 /* If the input and output modes are both the same, we are done. */
10571 if (mode
== GET_MODE (op0
))
10573 /* If neither mode is BLKmode, and both modes are the same size
10574 then we can use gen_lowpart. */
10575 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10576 && (GET_MODE_PRECISION (mode
)
10577 == GET_MODE_PRECISION (GET_MODE (op0
)))
10578 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10580 if (GET_CODE (op0
) == SUBREG
)
10581 op0
= force_reg (GET_MODE (op0
), op0
);
10582 temp
= gen_lowpart_common (mode
, op0
);
10587 if (!REG_P (op0
) && !MEM_P (op0
))
10588 op0
= force_reg (GET_MODE (op0
), op0
);
10589 op0
= gen_lowpart (mode
, op0
);
10592 /* If both types are integral, convert from one mode to the other. */
10593 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10594 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10595 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10596 /* If the output type is a bit-field type, do an extraction. */
10597 else if (reduce_bit_field
)
10598 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10599 TYPE_UNSIGNED (type
), NULL_RTX
,
10601 /* As a last resort, spill op0 to memory, and reload it in a
10603 else if (!MEM_P (op0
))
10605 /* If the operand is not a MEM, force it into memory. Since we
10606 are going to be changing the mode of the MEM, don't call
10607 force_const_mem for constants because we don't allow pool
10608 constants to change mode. */
10609 tree inner_type
= TREE_TYPE (treeop0
);
10611 gcc_assert (!TREE_ADDRESSABLE (exp
));
10613 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10615 = assign_stack_temp_for_type
10616 (TYPE_MODE (inner_type
),
10617 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10619 emit_move_insn (target
, op0
);
10623 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10624 output type is such that the operand is known to be aligned, indicate
10625 that it is. Otherwise, we need only be concerned about alignment for
10626 non-BLKmode results. */
10629 enum insn_code icode
;
10631 if (TYPE_ALIGN_OK (type
))
10633 /* ??? Copying the MEM without substantially changing it might
10634 run afoul of the code handling volatile memory references in
10635 store_expr, which assumes that TARGET is returned unmodified
10636 if it has been used. */
10637 op0
= copy_rtx (op0
);
10638 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10640 else if (modifier
!= EXPAND_WRITE
10641 && modifier
!= EXPAND_MEMORY
10642 && !inner_reference_p
10644 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10646 /* If the target does have special handling for unaligned
10647 loads of mode then use them. */
10648 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10649 != CODE_FOR_nothing
)
10653 op0
= adjust_address (op0
, mode
, 0);
10654 /* We've already validated the memory, and we're creating a
10655 new pseudo destination. The predicates really can't
10657 reg
= gen_reg_rtx (mode
);
10659 /* Nor can the insn generator. */
10660 rtx_insn
*insn
= GEN_FCN (icode
) (reg
, op0
);
10664 else if (STRICT_ALIGNMENT
)
10666 tree inner_type
= TREE_TYPE (treeop0
);
10667 HOST_WIDE_INT temp_size
10668 = MAX (int_size_in_bytes (inner_type
),
10669 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10671 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10672 rtx new_with_op0_mode
10673 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10675 gcc_assert (!TREE_ADDRESSABLE (exp
));
10677 if (GET_MODE (op0
) == BLKmode
)
10678 emit_block_move (new_with_op0_mode
, op0
,
10679 GEN_INT (GET_MODE_SIZE (mode
)),
10680 (modifier
== EXPAND_STACK_PARM
10681 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10683 emit_move_insn (new_with_op0_mode
, op0
);
10689 op0
= adjust_address (op0
, mode
, 0);
10696 tree lhs
= treeop0
;
10697 tree rhs
= treeop1
;
10698 gcc_assert (ignore
);
10700 /* Check for |= or &= of a bitfield of size one into another bitfield
10701 of size 1. In this case, (unless we need the result of the
10702 assignment) we can do this more efficiently with a
10703 test followed by an assignment, if necessary.
10705 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10706 things change so we do, this code should be enhanced to
10708 if (TREE_CODE (lhs
) == COMPONENT_REF
10709 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10710 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10711 && TREE_OPERAND (rhs
, 0) == lhs
10712 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10713 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10714 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10716 rtx_code_label
*label
= gen_label_rtx ();
10717 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10718 do_jump (TREE_OPERAND (rhs
, 1),
10720 value
? 0 : label
, -1);
10721 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10723 do_pending_stack_adjust ();
10724 emit_label (label
);
10728 expand_assignment (lhs
, rhs
, false);
10733 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10735 case REALPART_EXPR
:
10736 op0
= expand_normal (treeop0
);
10737 return read_complex_part (op0
, false);
10739 case IMAGPART_EXPR
:
10740 op0
= expand_normal (treeop0
);
10741 return read_complex_part (op0
, true);
10748 /* Expanded in cfgexpand.c. */
10749 gcc_unreachable ();
10751 case TRY_CATCH_EXPR
:
10753 case EH_FILTER_EXPR
:
10754 case TRY_FINALLY_EXPR
:
10755 /* Lowered by tree-eh.c. */
10756 gcc_unreachable ();
10758 case WITH_CLEANUP_EXPR
:
10759 case CLEANUP_POINT_EXPR
:
10761 case CASE_LABEL_EXPR
:
10766 case COMPOUND_EXPR
:
10767 case PREINCREMENT_EXPR
:
10768 case PREDECREMENT_EXPR
:
10769 case POSTINCREMENT_EXPR
:
10770 case POSTDECREMENT_EXPR
:
10773 case COMPOUND_LITERAL_EXPR
:
10774 /* Lowered by gimplify.c. */
10775 gcc_unreachable ();
10778 /* Function descriptors are not valid except for as
10779 initialization constants, and should not be expanded. */
10780 gcc_unreachable ();
10782 case WITH_SIZE_EXPR
:
10783 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10784 have pulled out the size to use in whatever context it needed. */
10785 return expand_expr_real (treeop0
, original_target
, tmode
,
10786 modifier
, alt_rtl
, inner_reference_p
);
10789 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10793 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10794 signedness of TYPE), possibly returning the result in TARGET. */
10796 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10798 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10799 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10801 /* For constant values, reduce using build_int_cst_type. */
10802 if (CONST_INT_P (exp
))
10804 HOST_WIDE_INT value
= INTVAL (exp
);
10805 tree t
= build_int_cst_type (type
, value
);
10806 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10808 else if (TYPE_UNSIGNED (type
))
10810 machine_mode mode
= GET_MODE (exp
);
10811 rtx mask
= immed_wide_int_const
10812 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
10813 return expand_and (mode
, exp
, mask
, target
);
10817 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10818 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10819 exp
, count
, target
, 0);
10820 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10821 exp
, count
, target
, 0);
10825 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10826 when applied to the address of EXP produces an address known to be
10827 aligned more than BIGGEST_ALIGNMENT. */
10830 is_aligning_offset (const_tree offset
, const_tree exp
)
10832 /* Strip off any conversions. */
10833 while (CONVERT_EXPR_P (offset
))
10834 offset
= TREE_OPERAND (offset
, 0);
10836 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10837 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10838 if (TREE_CODE (offset
) != BIT_AND_EXPR
10839 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10840 || compare_tree_int (TREE_OPERAND (offset
, 1),
10841 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10842 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10845 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10846 It must be NEGATE_EXPR. Then strip any more conversions. */
10847 offset
= TREE_OPERAND (offset
, 0);
10848 while (CONVERT_EXPR_P (offset
))
10849 offset
= TREE_OPERAND (offset
, 0);
10851 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10854 offset
= TREE_OPERAND (offset
, 0);
10855 while (CONVERT_EXPR_P (offset
))
10856 offset
= TREE_OPERAND (offset
, 0);
10858 /* This must now be the address of EXP. */
10859 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10862 /* Return the tree node if an ARG corresponds to a string constant or zero
10863 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10864 in bytes within the string that ARG is accessing. The type of the
10865 offset will be `sizetype'. */
10868 string_constant (tree arg
, tree
*ptr_offset
)
10870 tree array
, offset
, lower_bound
;
10873 if (TREE_CODE (arg
) == ADDR_EXPR
)
10875 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10877 *ptr_offset
= size_zero_node
;
10878 return TREE_OPERAND (arg
, 0);
10880 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10882 array
= TREE_OPERAND (arg
, 0);
10883 offset
= size_zero_node
;
10885 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10887 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10888 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10889 if (TREE_CODE (array
) != STRING_CST
10890 && TREE_CODE (array
) != VAR_DECL
)
10893 /* Check if the array has a nonzero lower bound. */
10894 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10895 if (!integer_zerop (lower_bound
))
10897 /* If the offset and base aren't both constants, return 0. */
10898 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10900 if (TREE_CODE (offset
) != INTEGER_CST
)
10902 /* Adjust offset by the lower bound. */
10903 offset
= size_diffop (fold_convert (sizetype
, offset
),
10904 fold_convert (sizetype
, lower_bound
));
10907 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10909 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10910 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10911 if (TREE_CODE (array
) != ADDR_EXPR
)
10913 array
= TREE_OPERAND (array
, 0);
10914 if (TREE_CODE (array
) != STRING_CST
10915 && TREE_CODE (array
) != VAR_DECL
)
10921 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10923 tree arg0
= TREE_OPERAND (arg
, 0);
10924 tree arg1
= TREE_OPERAND (arg
, 1);
10929 if (TREE_CODE (arg0
) == ADDR_EXPR
10930 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10931 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10933 array
= TREE_OPERAND (arg0
, 0);
10936 else if (TREE_CODE (arg1
) == ADDR_EXPR
10937 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10938 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10940 array
= TREE_OPERAND (arg1
, 0);
10949 if (TREE_CODE (array
) == STRING_CST
)
10951 *ptr_offset
= fold_convert (sizetype
, offset
);
10954 else if (TREE_CODE (array
) == VAR_DECL
10955 || TREE_CODE (array
) == CONST_DECL
)
10958 tree init
= ctor_for_folding (array
);
10960 /* Variables initialized to string literals can be handled too. */
10961 if (init
== error_mark_node
10963 || TREE_CODE (init
) != STRING_CST
)
10966 /* Avoid const char foo[4] = "abcde"; */
10967 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10968 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10969 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10970 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10973 /* If variable is bigger than the string literal, OFFSET must be constant
10974 and inside of the bounds of the string literal. */
10975 offset
= fold_convert (sizetype
, offset
);
10976 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10977 && (! tree_fits_uhwi_p (offset
)
10978 || compare_tree_int (offset
, length
) >= 0))
10981 *ptr_offset
= offset
;
10988 /* Generate code to calculate OPS, and exploded expression
10989 using a store-flag instruction and return an rtx for the result.
10990 OPS reflects a comparison.
10992 If TARGET is nonzero, store the result there if convenient.
10994 Return zero if there is no suitable set-flag instruction
10995 available on this machine.
10997 Once expand_expr has been called on the arguments of the comparison,
10998 we are committed to doing the store flag, since it is not safe to
10999 re-evaluate the expression. We emit the store-flag insn by calling
11000 emit_store_flag, but only expand the arguments if we have a reason
11001 to believe that emit_store_flag will be successful. If we think that
11002 it will, but it isn't, we have to simulate the store-flag with a
11003 set/jump/set sequence. */
11006 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
11008 enum rtx_code code
;
11009 tree arg0
, arg1
, type
;
11010 machine_mode operand_mode
;
11013 rtx subtarget
= target
;
11014 location_t loc
= ops
->location
;
11019 /* Don't crash if the comparison was erroneous. */
11020 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
11023 type
= TREE_TYPE (arg0
);
11024 operand_mode
= TYPE_MODE (type
);
11025 unsignedp
= TYPE_UNSIGNED (type
);
11027 /* We won't bother with BLKmode store-flag operations because it would mean
11028 passing a lot of information to emit_store_flag. */
11029 if (operand_mode
== BLKmode
)
11032 /* We won't bother with store-flag operations involving function pointers
11033 when function pointers must be canonicalized before comparisons. */
11034 if (targetm
.have_canonicalize_funcptr_for_compare ()
11035 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
11036 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
11038 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
11039 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
11040 == FUNCTION_TYPE
))))
11046 /* For vector typed comparisons emit code to generate the desired
11047 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
11048 expander for this. */
11049 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
11051 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
11052 tree if_true
= constant_boolean_node (true, ops
->type
);
11053 tree if_false
= constant_boolean_node (false, ops
->type
);
11054 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
11057 /* Get the rtx comparison code to use. We know that EXP is a comparison
11058 operation of some type. Some comparisons against 1 and -1 can be
11059 converted to comparisons with zero. Do so here so that the tests
11060 below will be aware that we have a comparison with zero. These
11061 tests will not catch constants in the first operand, but constants
11062 are rarely passed as the first operand. */
11073 if (integer_onep (arg1
))
11074 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
11076 code
= unsignedp
? LTU
: LT
;
11079 if (! unsignedp
&& integer_all_onesp (arg1
))
11080 arg1
= integer_zero_node
, code
= LT
;
11082 code
= unsignedp
? LEU
: LE
;
11085 if (! unsignedp
&& integer_all_onesp (arg1
))
11086 arg1
= integer_zero_node
, code
= GE
;
11088 code
= unsignedp
? GTU
: GT
;
11091 if (integer_onep (arg1
))
11092 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
11094 code
= unsignedp
? GEU
: GE
;
11097 case UNORDERED_EXPR
:
11123 gcc_unreachable ();
11126 /* Put a constant second. */
11127 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11128 || TREE_CODE (arg0
) == FIXED_CST
)
11130 std::swap (arg0
, arg1
);
11131 code
= swap_condition (code
);
11134 /* If this is an equality or inequality test of a single bit, we can
11135 do this by shifting the bit being tested to the low-order bit and
11136 masking the result with the constant 1. If the condition was EQ,
11137 we xor it with 1. This does not require an scc insn and is faster
11138 than an scc insn even if we have it.
11140 The code to make this transformation was moved into fold_single_bit_test,
11141 so we just call into the folder and expand its result. */
11143 if ((code
== NE
|| code
== EQ
)
11144 && integer_zerop (arg1
)
11145 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11147 gimple
*srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11149 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11151 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11152 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11153 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11154 gimple_assign_rhs1 (srcstmt
),
11155 gimple_assign_rhs2 (srcstmt
));
11156 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11158 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11162 if (! get_subtarget (target
)
11163 || GET_MODE (subtarget
) != operand_mode
)
11166 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11169 target
= gen_reg_rtx (mode
);
11171 /* Try a cstore if possible. */
11172 return emit_store_flag_force (target
, code
, op0
, op1
,
11173 operand_mode
, unsignedp
,
11174 (TYPE_PRECISION (ops
->type
) == 1
11175 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11178 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11179 0 otherwise (i.e. if there is no casesi instruction).
11181 DEFAULT_PROBABILITY is the probability of jumping to the default
11184 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11185 rtx table_label
, rtx default_label
, rtx fallback_label
,
11186 int default_probability
)
11188 struct expand_operand ops
[5];
11189 machine_mode index_mode
= SImode
;
11190 rtx op1
, op2
, index
;
11192 if (! targetm
.have_casesi ())
11195 /* Convert the index to SImode. */
11196 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11198 machine_mode omode
= TYPE_MODE (index_type
);
11199 rtx rangertx
= expand_normal (range
);
11201 /* We must handle the endpoints in the original mode. */
11202 index_expr
= build2 (MINUS_EXPR
, index_type
,
11203 index_expr
, minval
);
11204 minval
= integer_zero_node
;
11205 index
= expand_normal (index_expr
);
11207 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11208 omode
, 1, default_label
,
11209 default_probability
);
11210 /* Now we can safely truncate. */
11211 index
= convert_to_mode (index_mode
, index
, 0);
11215 if (TYPE_MODE (index_type
) != index_mode
)
11217 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11218 index_expr
= fold_convert (index_type
, index_expr
);
11221 index
= expand_normal (index_expr
);
11224 do_pending_stack_adjust ();
11226 op1
= expand_normal (minval
);
11227 op2
= expand_normal (range
);
11229 create_input_operand (&ops
[0], index
, index_mode
);
11230 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11231 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11232 create_fixed_operand (&ops
[3], table_label
);
11233 create_fixed_operand (&ops
[4], (default_label
11235 : fallback_label
));
11236 expand_jump_insn (targetm
.code_for_casesi
, 5, ops
);
11240 /* Attempt to generate a tablejump instruction; same concept. */
11241 /* Subroutine of the next function.
11243 INDEX is the value being switched on, with the lowest value
11244 in the table already subtracted.
11245 MODE is its expected mode (needed if INDEX is constant).
11246 RANGE is the length of the jump table.
11247 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11249 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11250 index value is out of range.
11251 DEFAULT_PROBABILITY is the probability of jumping to
11252 the default label. */
11255 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
11256 rtx default_label
, int default_probability
)
11260 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11261 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11263 /* Do an unsigned comparison (in the proper mode) between the index
11264 expression and the value which represents the length of the range.
11265 Since we just finished subtracting the lower bound of the range
11266 from the index expression, this comparison allows us to simultaneously
11267 check that the original index expression value is both greater than
11268 or equal to the minimum value of the range and less than or equal to
11269 the maximum value of the range. */
11272 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11273 default_label
, default_probability
);
11276 /* If index is in range, it must fit in Pmode.
11277 Convert to Pmode so we can index with it. */
11279 index
= convert_to_mode (Pmode
, index
, 1);
11281 /* Don't let a MEM slip through, because then INDEX that comes
11282 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11283 and break_out_memory_refs will go to work on it and mess it up. */
11284 #ifdef PIC_CASE_VECTOR_ADDRESS
11285 if (flag_pic
&& !REG_P (index
))
11286 index
= copy_to_mode_reg (Pmode
, index
);
11289 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11290 GET_MODE_SIZE, because this indicates how large insns are. The other
11291 uses should all be Pmode, because they are addresses. This code
11292 could fail if addresses and insns are not the same size. */
11293 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11294 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11296 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11297 gen_rtx_LABEL_REF (Pmode
, table_label
));
11299 #ifdef PIC_CASE_VECTOR_ADDRESS
11301 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11304 index
= memory_address (CASE_VECTOR_MODE
, index
);
11305 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11306 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11307 convert_move (temp
, vector
, 0);
11309 emit_jump_insn (targetm
.gen_tablejump (temp
, table_label
));
11311 /* If we are generating PIC code or if the table is PC-relative, the
11312 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11313 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11318 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11319 rtx table_label
, rtx default_label
, int default_probability
)
11323 if (! targetm
.have_tablejump ())
11326 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11327 fold_convert (index_type
, index_expr
),
11328 fold_convert (index_type
, minval
));
11329 index
= expand_normal (index_expr
);
11330 do_pending_stack_adjust ();
11332 do_tablejump (index
, TYPE_MODE (index_type
),
11333 convert_modes (TYPE_MODE (index_type
),
11334 TYPE_MODE (TREE_TYPE (range
)),
11335 expand_normal (range
),
11336 TYPE_UNSIGNED (TREE_TYPE (range
))),
11337 table_label
, default_label
, default_probability
);
11341 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11343 const_vector_from_tree (tree exp
)
11349 machine_mode inner
, mode
;
11351 mode
= TYPE_MODE (TREE_TYPE (exp
));
11353 if (initializer_zerop (exp
))
11354 return CONST0_RTX (mode
);
11356 units
= GET_MODE_NUNITS (mode
);
11357 inner
= GET_MODE_INNER (mode
);
11359 v
= rtvec_alloc (units
);
11361 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11363 elt
= VECTOR_CST_ELT (exp
, i
);
11365 if (TREE_CODE (elt
) == REAL_CST
)
11366 RTVEC_ELT (v
, i
) = const_double_from_real_value (TREE_REAL_CST (elt
),
11368 else if (TREE_CODE (elt
) == FIXED_CST
)
11369 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11372 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11375 return gen_rtx_CONST_VECTOR (mode
, v
);
11378 /* Build a decl for a personality function given a language prefix. */
11381 build_personality_function (const char *lang
)
11383 const char *unwind_and_version
;
11387 switch (targetm_common
.except_unwind_info (&global_options
))
11392 unwind_and_version
= "_sj0";
11396 unwind_and_version
= "_v0";
11399 unwind_and_version
= "_seh0";
11402 gcc_unreachable ();
11405 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11407 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11408 long_long_unsigned_type_node
,
11409 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11410 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11411 get_identifier (name
), type
);
11412 DECL_ARTIFICIAL (decl
) = 1;
11413 DECL_EXTERNAL (decl
) = 1;
11414 TREE_PUBLIC (decl
) = 1;
11416 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11417 are the flags assigned by targetm.encode_section_info. */
11418 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11423 /* Extracts the personality function of DECL and returns the corresponding
11427 get_personality_function (tree decl
)
11429 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11430 enum eh_personality_kind pk
;
11432 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11433 if (pk
== eh_personality_none
)
11437 && pk
== eh_personality_any
)
11438 personality
= lang_hooks
.eh_personality ();
11440 if (pk
== eh_personality_lang
)
11441 gcc_assert (personality
!= NULL_TREE
);
11443 return XEXP (DECL_RTL (personality
), 0);
11446 /* Returns a tree for the size of EXP in bytes. */
11449 tree_expr_size (const_tree exp
)
11452 && DECL_SIZE_UNIT (exp
) != 0)
11453 return DECL_SIZE_UNIT (exp
);
11455 return size_in_bytes (TREE_TYPE (exp
));
11458 /* Return an rtx for the size in bytes of the value of EXP. */
11461 expr_size (tree exp
)
11465 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11466 size
= TREE_OPERAND (exp
, 1);
11469 size
= tree_expr_size (exp
);
11471 gcc_assert (size
== SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, exp
));
11474 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), EXPAND_NORMAL
);
11477 /* Return a wide integer for the size in bytes of the value of EXP, or -1
11478 if the size can vary or is larger than an integer. */
11480 static HOST_WIDE_INT
11481 int_expr_size (tree exp
)
11485 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11486 size
= TREE_OPERAND (exp
, 1);
11489 size
= tree_expr_size (exp
);
11493 if (size
== 0 || !tree_fits_shwi_p (size
))
11496 return tree_to_shwi (size
);
11499 #include "gt-expr.h"