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
;
3630 int oldcost
, newcost
;
3631 bool speed
= optimize_insn_for_speed_p ();
3633 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3635 if (targetm
.legitimate_constant_p (dstmode
, y
))
3636 oldcost
= set_src_cost (y
, orig_srcmode
, speed
);
3638 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), dstmode
, speed
);
3640 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3641 srcmode
!= orig_srcmode
;
3642 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3646 rtx_insn
*last_insn
;
3648 /* Skip if the target can't extend this way. */
3649 ic
= can_extend_p (dstmode
, srcmode
, 0);
3650 if (ic
== CODE_FOR_nothing
)
3653 /* Skip if the narrowed value isn't exact. */
3654 if (! exact_real_truncate (srcmode
, &r
))
3657 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3659 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3661 /* Skip if the target needs extra instructions to perform
3663 if (!insn_operand_matches (ic
, 1, trunc_y
))
3665 /* This is valid, but may not be cheaper than the original. */
3666 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3668 if (oldcost
< newcost
)
3671 else if (float_extend_from_mem
[dstmode
][srcmode
])
3673 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3674 /* This is valid, but may not be cheaper than the original. */
3675 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3677 if (oldcost
< newcost
)
3679 trunc_y
= validize_mem (trunc_y
);
3684 /* For CSE's benefit, force the compressed constant pool entry
3685 into a new pseudo. This constant may be used in different modes,
3686 and if not, combine will put things back together for us. */
3687 trunc_y
= force_reg (srcmode
, trunc_y
);
3689 /* If x is a hard register, perform the extension into a pseudo,
3690 so that e.g. stack realignment code is aware of it. */
3692 if (REG_P (x
) && HARD_REGISTER_P (x
))
3693 target
= gen_reg_rtx (dstmode
);
3695 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
3696 last_insn
= get_last_insn ();
3699 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3702 return emit_move_insn (x
, target
);
3709 /* Pushing data onto the stack. */
3711 /* Push a block of length SIZE (perhaps variable)
3712 and return an rtx to address the beginning of the block.
3713 The value may be virtual_outgoing_args_rtx.
3715 EXTRA is the number of bytes of padding to push in addition to SIZE.
3716 BELOW nonzero means this padding comes at low addresses;
3717 otherwise, the padding comes at high addresses. */
3720 push_block (rtx size
, int extra
, int below
)
3724 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3725 if (CONSTANT_P (size
))
3726 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3727 else if (REG_P (size
) && extra
== 0)
3728 anti_adjust_stack (size
);
3731 temp
= copy_to_mode_reg (Pmode
, size
);
3733 temp
= expand_binop (Pmode
, add_optab
, temp
,
3734 gen_int_mode (extra
, Pmode
),
3735 temp
, 0, OPTAB_LIB_WIDEN
);
3736 anti_adjust_stack (temp
);
3739 if (STACK_GROWS_DOWNWARD
)
3741 temp
= virtual_outgoing_args_rtx
;
3742 if (extra
!= 0 && below
)
3743 temp
= plus_constant (Pmode
, temp
, extra
);
3747 if (CONST_INT_P (size
))
3748 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3749 -INTVAL (size
) - (below
? 0 : extra
));
3750 else if (extra
!= 0 && !below
)
3751 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3752 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3755 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3756 negate_rtx (Pmode
, size
));
3759 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3762 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3765 mem_autoinc_base (rtx mem
)
3769 rtx addr
= XEXP (mem
, 0);
3770 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3771 return XEXP (addr
, 0);
3776 /* A utility routine used here, in reload, and in try_split. The insns
3777 after PREV up to and including LAST are known to adjust the stack,
3778 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3779 placing notes as appropriate. PREV may be NULL, indicating the
3780 entire insn sequence prior to LAST should be scanned.
3782 The set of allowed stack pointer modifications is small:
3783 (1) One or more auto-inc style memory references (aka pushes),
3784 (2) One or more addition/subtraction with the SP as destination,
3785 (3) A single move insn with the SP as destination,
3786 (4) A call_pop insn,
3787 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3789 Insns in the sequence that do not modify the SP are ignored,
3790 except for noreturn calls.
3792 The return value is the amount of adjustment that can be trivially
3793 verified, via immediate operand or auto-inc. If the adjustment
3794 cannot be trivially extracted, the return value is INT_MIN. */
3797 find_args_size_adjust (rtx_insn
*insn
)
3802 pat
= PATTERN (insn
);
3805 /* Look for a call_pop pattern. */
3808 /* We have to allow non-call_pop patterns for the case
3809 of emit_single_push_insn of a TLS address. */
3810 if (GET_CODE (pat
) != PARALLEL
)
3813 /* All call_pop have a stack pointer adjust in the parallel.
3814 The call itself is always first, and the stack adjust is
3815 usually last, so search from the end. */
3816 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3818 set
= XVECEXP (pat
, 0, i
);
3819 if (GET_CODE (set
) != SET
)
3821 dest
= SET_DEST (set
);
3822 if (dest
== stack_pointer_rtx
)
3825 /* We'd better have found the stack pointer adjust. */
3828 /* Fall through to process the extracted SET and DEST
3829 as if it was a standalone insn. */
3831 else if (GET_CODE (pat
) == SET
)
3833 else if ((set
= single_set (insn
)) != NULL
)
3835 else if (GET_CODE (pat
) == PARALLEL
)
3837 /* ??? Some older ports use a parallel with a stack adjust
3838 and a store for a PUSH_ROUNDING pattern, rather than a
3839 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3840 /* ??? See h8300 and m68k, pushqi1. */
3841 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3843 set
= XVECEXP (pat
, 0, i
);
3844 if (GET_CODE (set
) != SET
)
3846 dest
= SET_DEST (set
);
3847 if (dest
== stack_pointer_rtx
)
3850 /* We do not expect an auto-inc of the sp in the parallel. */
3851 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3852 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3853 != stack_pointer_rtx
);
3861 dest
= SET_DEST (set
);
3863 /* Look for direct modifications of the stack pointer. */
3864 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3866 /* Look for a trivial adjustment, otherwise assume nothing. */
3867 /* Note that the SPU restore_stack_block pattern refers to
3868 the stack pointer in V4SImode. Consider that non-trivial. */
3869 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3870 && GET_CODE (SET_SRC (set
)) == PLUS
3871 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3872 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3873 return INTVAL (XEXP (SET_SRC (set
), 1));
3874 /* ??? Reload can generate no-op moves, which will be cleaned
3875 up later. Recognize it and continue searching. */
3876 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3879 return HOST_WIDE_INT_MIN
;
3885 /* Otherwise only think about autoinc patterns. */
3886 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3889 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3890 != stack_pointer_rtx
);
3892 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3893 mem
= SET_SRC (set
);
3897 addr
= XEXP (mem
, 0);
3898 switch (GET_CODE (addr
))
3902 return GET_MODE_SIZE (GET_MODE (mem
));
3905 return -GET_MODE_SIZE (GET_MODE (mem
));
3908 addr
= XEXP (addr
, 1);
3909 gcc_assert (GET_CODE (addr
) == PLUS
);
3910 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3911 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3912 return INTVAL (XEXP (addr
, 1));
3920 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
, int end_args_size
)
3922 int args_size
= end_args_size
;
3923 bool saw_unknown
= false;
3926 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3928 HOST_WIDE_INT this_delta
;
3930 if (!NONDEBUG_INSN_P (insn
))
3933 this_delta
= find_args_size_adjust (insn
);
3934 if (this_delta
== 0)
3937 || ACCUMULATE_OUTGOING_ARGS
3938 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3942 gcc_assert (!saw_unknown
);
3943 if (this_delta
== HOST_WIDE_INT_MIN
)
3946 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3947 if (STACK_GROWS_DOWNWARD
)
3948 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3950 args_size
-= this_delta
;
3953 return saw_unknown
? INT_MIN
: args_size
;
3956 #ifdef PUSH_ROUNDING
3957 /* Emit single push insn. */
3960 emit_single_push_insn_1 (machine_mode mode
, rtx x
, tree type
)
3963 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3965 enum insn_code icode
;
3967 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3968 /* If there is push pattern, use it. Otherwise try old way of throwing
3969 MEM representing push operation to move expander. */
3970 icode
= optab_handler (push_optab
, mode
);
3971 if (icode
!= CODE_FOR_nothing
)
3973 struct expand_operand ops
[1];
3975 create_input_operand (&ops
[0], x
, mode
);
3976 if (maybe_expand_insn (icode
, 1, ops
))
3979 if (GET_MODE_SIZE (mode
) == rounded_size
)
3980 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3981 /* If we are to pad downward, adjust the stack pointer first and
3982 then store X into the stack location using an offset. This is
3983 because emit_move_insn does not know how to pad; it does not have
3985 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3987 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3988 HOST_WIDE_INT offset
;
3990 emit_move_insn (stack_pointer_rtx
,
3991 expand_binop (Pmode
,
3992 STACK_GROWS_DOWNWARD
? sub_optab
3995 gen_int_mode (rounded_size
, Pmode
),
3996 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3998 offset
= (HOST_WIDE_INT
) padding_size
;
3999 if (STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_DEC
)
4000 /* We have already decremented the stack pointer, so get the
4002 offset
+= (HOST_WIDE_INT
) rounded_size
;
4004 if (!STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_INC
)
4005 /* We have already incremented the stack pointer, so get the
4007 offset
-= (HOST_WIDE_INT
) rounded_size
;
4009 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4010 gen_int_mode (offset
, Pmode
));
4014 if (STACK_GROWS_DOWNWARD
)
4015 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4016 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4017 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4020 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4021 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4022 gen_int_mode (rounded_size
, Pmode
));
4024 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4027 dest
= gen_rtx_MEM (mode
, dest_addr
);
4031 set_mem_attributes (dest
, type
, 1);
4033 if (cfun
->tail_call_marked
)
4034 /* Function incoming arguments may overlap with sibling call
4035 outgoing arguments and we cannot allow reordering of reads
4036 from function arguments with stores to outgoing arguments
4037 of sibling calls. */
4038 set_mem_alias_set (dest
, 0);
4040 emit_move_insn (dest
, x
);
4043 /* Emit and annotate a single push insn. */
4046 emit_single_push_insn (machine_mode mode
, rtx x
, tree type
)
4048 int delta
, old_delta
= stack_pointer_delta
;
4049 rtx_insn
*prev
= get_last_insn ();
4052 emit_single_push_insn_1 (mode
, x
, type
);
4054 last
= get_last_insn ();
4056 /* Notice the common case where we emitted exactly one insn. */
4057 if (PREV_INSN (last
) == prev
)
4059 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4063 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4064 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4068 /* If reading SIZE bytes from X will end up reading from
4069 Y return the number of bytes that overlap. Return -1
4070 if there is no overlap or -2 if we can't determine
4071 (for example when X and Y have different base registers). */
4074 memory_load_overlap (rtx x
, rtx y
, HOST_WIDE_INT size
)
4076 rtx tmp
= plus_constant (Pmode
, x
, size
);
4077 rtx sub
= simplify_gen_binary (MINUS
, Pmode
, tmp
, y
);
4079 if (!CONST_INT_P (sub
))
4082 HOST_WIDE_INT val
= INTVAL (sub
);
4084 return IN_RANGE (val
, 1, size
) ? val
: -1;
4087 /* Generate code to push X onto the stack, assuming it has mode MODE and
4089 MODE is redundant except when X is a CONST_INT (since they don't
4091 SIZE is an rtx for the size of data to be copied (in bytes),
4092 needed only if X is BLKmode.
4093 Return true if successful. May return false if asked to push a
4094 partial argument during a sibcall optimization (as specified by
4095 SIBCALL_P) and the incoming and outgoing pointers cannot be shown
4098 ALIGN (in bits) is maximum alignment we can assume.
4100 If PARTIAL and REG are both nonzero, then copy that many of the first
4101 bytes of X into registers starting with REG, and push the rest of X.
4102 The amount of space pushed is decreased by PARTIAL bytes.
4103 REG must be a hard register in this case.
4104 If REG is zero but PARTIAL is not, take any all others actions for an
4105 argument partially in registers, but do not actually load any
4108 EXTRA is the amount in bytes of extra space to leave next to this arg.
4109 This is ignored if an argument block has already been allocated.
4111 On a machine that lacks real push insns, ARGS_ADDR is the address of
4112 the bottom of the argument block for this call. We use indexing off there
4113 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4114 argument block has not been preallocated.
4116 ARGS_SO_FAR is the size of args previously pushed for this call.
4118 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4119 for arguments passed in registers. If nonzero, it will be the number
4120 of bytes required. */
4123 emit_push_insn (rtx x
, machine_mode mode
, tree type
, rtx size
,
4124 unsigned int align
, int partial
, rtx reg
, int extra
,
4125 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4126 rtx alignment_pad
, bool sibcall_p
)
4129 enum direction stack_direction
= STACK_GROWS_DOWNWARD
? downward
: upward
;
4131 /* Decide where to pad the argument: `downward' for below,
4132 `upward' for above, or `none' for don't pad it.
4133 Default is below for small data on big-endian machines; else above. */
4134 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4136 /* Invert direction if stack is post-decrement.
4138 if (STACK_PUSH_CODE
== POST_DEC
)
4139 if (where_pad
!= none
)
4140 where_pad
= (where_pad
== downward
? upward
: downward
);
4144 int nregs
= partial
/ UNITS_PER_WORD
;
4145 rtx
*tmp_regs
= NULL
;
4146 int overlapping
= 0;
4149 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4151 /* Copy a block into the stack, entirely or partially. */
4158 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4159 used
= partial
- offset
;
4161 if (mode
!= BLKmode
)
4163 /* A value is to be stored in an insufficiently aligned
4164 stack slot; copy via a suitably aligned slot if
4166 size
= GEN_INT (GET_MODE_SIZE (mode
));
4167 if (!MEM_P (xinner
))
4169 temp
= assign_temp (type
, 1, 1);
4170 emit_move_insn (temp
, xinner
);
4177 /* USED is now the # of bytes we need not copy to the stack
4178 because registers will take care of them. */
4181 xinner
= adjust_address (xinner
, BLKmode
, used
);
4183 /* If the partial register-part of the arg counts in its stack size,
4184 skip the part of stack space corresponding to the registers.
4185 Otherwise, start copying to the beginning of the stack space,
4186 by setting SKIP to 0. */
4187 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4189 #ifdef PUSH_ROUNDING
4190 /* Do it with several push insns if that doesn't take lots of insns
4191 and if there is no difficulty with push insns that skip bytes
4192 on the stack for alignment purposes. */
4195 && CONST_INT_P (size
)
4197 && MEM_ALIGN (xinner
) >= align
4198 && can_move_by_pieces ((unsigned) INTVAL (size
) - used
, align
)
4199 /* Here we avoid the case of a structure whose weak alignment
4200 forces many pushes of a small amount of data,
4201 and such small pushes do rounding that causes trouble. */
4202 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4203 || align
>= BIGGEST_ALIGNMENT
4204 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4205 == (align
/ BITS_PER_UNIT
)))
4206 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4208 /* Push padding now if padding above and stack grows down,
4209 or if padding below and stack grows up.
4210 But if space already allocated, this has already been done. */
4211 if (extra
&& args_addr
== 0
4212 && where_pad
!= none
&& where_pad
!= stack_direction
)
4213 anti_adjust_stack (GEN_INT (extra
));
4215 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4218 #endif /* PUSH_ROUNDING */
4222 /* Otherwise make space on the stack and copy the data
4223 to the address of that space. */
4225 /* Deduct words put into registers from the size we must copy. */
4228 if (CONST_INT_P (size
))
4229 size
= GEN_INT (INTVAL (size
) - used
);
4231 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4232 gen_int_mode (used
, GET_MODE (size
)),
4233 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4236 /* Get the address of the stack space.
4237 In this case, we do not deal with EXTRA separately.
4238 A single stack adjust will do. */
4241 temp
= push_block (size
, extra
, where_pad
== downward
);
4244 else if (CONST_INT_P (args_so_far
))
4245 temp
= memory_address (BLKmode
,
4246 plus_constant (Pmode
, args_addr
,
4247 skip
+ INTVAL (args_so_far
)));
4249 temp
= memory_address (BLKmode
,
4250 plus_constant (Pmode
,
4251 gen_rtx_PLUS (Pmode
,
4256 if (!ACCUMULATE_OUTGOING_ARGS
)
4258 /* If the source is referenced relative to the stack pointer,
4259 copy it to another register to stabilize it. We do not need
4260 to do this if we know that we won't be changing sp. */
4262 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4263 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4264 temp
= copy_to_reg (temp
);
4267 target
= gen_rtx_MEM (BLKmode
, temp
);
4269 /* We do *not* set_mem_attributes here, because incoming arguments
4270 may overlap with sibling call outgoing arguments and we cannot
4271 allow reordering of reads from function arguments with stores
4272 to outgoing arguments of sibling calls. We do, however, want
4273 to record the alignment of the stack slot. */
4274 /* ALIGN may well be better aligned than TYPE, e.g. due to
4275 PARM_BOUNDARY. Assume the caller isn't lying. */
4276 set_mem_align (target
, align
);
4278 /* If part should go in registers and pushing to that part would
4279 overwrite some of the values that need to go into regs, load the
4280 overlapping values into temporary pseudos to be moved into the hard
4281 regs at the end after the stack pushing has completed.
4282 We cannot load them directly into the hard regs here because
4283 they can be clobbered by the block move expansions.
4286 if (partial
> 0 && reg
!= 0 && mode
== BLKmode
4287 && GET_CODE (reg
) != PARALLEL
)
4289 overlapping
= memory_load_overlap (XEXP (x
, 0), temp
, partial
);
4290 if (overlapping
> 0)
4292 gcc_assert (overlapping
% UNITS_PER_WORD
== 0);
4293 overlapping
/= UNITS_PER_WORD
;
4295 tmp_regs
= XALLOCAVEC (rtx
, overlapping
);
4297 for (int i
= 0; i
< overlapping
; i
++)
4298 tmp_regs
[i
] = gen_reg_rtx (word_mode
);
4300 for (int i
= 0; i
< overlapping
; i
++)
4301 emit_move_insn (tmp_regs
[i
],
4302 operand_subword_force (target
, i
, mode
));
4304 else if (overlapping
== -1)
4306 /* Could not determine whether there is overlap.
4307 Fail the sibcall. */
4315 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4318 else if (partial
> 0)
4320 /* Scalar partly in registers. */
4322 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4325 /* # bytes of start of argument
4326 that we must make space for but need not store. */
4327 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4328 int args_offset
= INTVAL (args_so_far
);
4331 /* Push padding now if padding above and stack grows down,
4332 or if padding below and stack grows up.
4333 But if space already allocated, this has already been done. */
4334 if (extra
&& args_addr
== 0
4335 && where_pad
!= none
&& where_pad
!= stack_direction
)
4336 anti_adjust_stack (GEN_INT (extra
));
4338 /* If we make space by pushing it, we might as well push
4339 the real data. Otherwise, we can leave OFFSET nonzero
4340 and leave the space uninitialized. */
4344 /* Now NOT_STACK gets the number of words that we don't need to
4345 allocate on the stack. Convert OFFSET to words too. */
4346 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4347 offset
/= UNITS_PER_WORD
;
4349 /* If the partial register-part of the arg counts in its stack size,
4350 skip the part of stack space corresponding to the registers.
4351 Otherwise, start copying to the beginning of the stack space,
4352 by setting SKIP to 0. */
4353 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4355 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4356 x
= validize_mem (force_const_mem (mode
, x
));
4358 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4359 SUBREGs of such registers are not allowed. */
4360 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4361 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4362 x
= copy_to_reg (x
);
4364 /* Loop over all the words allocated on the stack for this arg. */
4365 /* We can do it by words, because any scalar bigger than a word
4366 has a size a multiple of a word. */
4367 for (i
= size
- 1; i
>= not_stack
; i
--)
4368 if (i
>= not_stack
+ offset
)
4369 if (!emit_push_insn (operand_subword_force (x
, i
, mode
),
4370 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4372 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4374 reg_parm_stack_space
, alignment_pad
, sibcall_p
))
4382 /* Push padding now if padding above and stack grows down,
4383 or if padding below and stack grows up.
4384 But if space already allocated, this has already been done. */
4385 if (extra
&& args_addr
== 0
4386 && where_pad
!= none
&& where_pad
!= stack_direction
)
4387 anti_adjust_stack (GEN_INT (extra
));
4389 #ifdef PUSH_ROUNDING
4390 if (args_addr
== 0 && PUSH_ARGS
)
4391 emit_single_push_insn (mode
, x
, type
);
4395 if (CONST_INT_P (args_so_far
))
4397 = memory_address (mode
,
4398 plus_constant (Pmode
, args_addr
,
4399 INTVAL (args_so_far
)));
4401 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4403 dest
= gen_rtx_MEM (mode
, addr
);
4405 /* We do *not* set_mem_attributes here, because incoming arguments
4406 may overlap with sibling call outgoing arguments and we cannot
4407 allow reordering of reads from function arguments with stores
4408 to outgoing arguments of sibling calls. We do, however, want
4409 to record the alignment of the stack slot. */
4410 /* ALIGN may well be better aligned than TYPE, e.g. due to
4411 PARM_BOUNDARY. Assume the caller isn't lying. */
4412 set_mem_align (dest
, align
);
4414 emit_move_insn (dest
, x
);
4418 /* Move the partial arguments into the registers and any overlapping
4419 values that we moved into the pseudos in tmp_regs. */
4420 if (partial
> 0 && reg
!= 0)
4422 /* Handle calls that pass values in multiple non-contiguous locations.
4423 The Irix 6 ABI has examples of this. */
4424 if (GET_CODE (reg
) == PARALLEL
)
4425 emit_group_load (reg
, x
, type
, -1);
4428 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4429 move_block_to_reg (REGNO (reg
), x
, nregs
- overlapping
, mode
);
4431 for (int i
= 0; i
< overlapping
; i
++)
4432 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
)
4433 + nregs
- overlapping
+ i
),
4439 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4440 anti_adjust_stack (GEN_INT (extra
));
4442 if (alignment_pad
&& args_addr
== 0)
4443 anti_adjust_stack (alignment_pad
);
4448 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4452 get_subtarget (rtx x
)
4456 /* Only registers can be subtargets. */
4458 /* Don't use hard regs to avoid extending their life. */
4459 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4463 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4464 FIELD is a bitfield. Returns true if the optimization was successful,
4465 and there's nothing else to do. */
4468 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4469 unsigned HOST_WIDE_INT bitpos
,
4470 unsigned HOST_WIDE_INT bitregion_start
,
4471 unsigned HOST_WIDE_INT bitregion_end
,
4472 machine_mode mode1
, rtx str_rtx
,
4475 machine_mode str_mode
= GET_MODE (str_rtx
);
4476 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4481 enum tree_code code
;
4483 if (mode1
!= VOIDmode
4484 || bitsize
>= BITS_PER_WORD
4485 || str_bitsize
> BITS_PER_WORD
4486 || TREE_SIDE_EFFECTS (to
)
4487 || TREE_THIS_VOLATILE (to
))
4491 if (TREE_CODE (src
) != SSA_NAME
)
4493 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4496 srcstmt
= get_gimple_for_ssa_name (src
);
4498 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4501 code
= gimple_assign_rhs_code (srcstmt
);
4503 op0
= gimple_assign_rhs1 (srcstmt
);
4505 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4506 to find its initialization. Hopefully the initialization will
4507 be from a bitfield load. */
4508 if (TREE_CODE (op0
) == SSA_NAME
)
4510 gimple
*op0stmt
= get_gimple_for_ssa_name (op0
);
4512 /* We want to eventually have OP0 be the same as TO, which
4513 should be a bitfield. */
4515 || !is_gimple_assign (op0stmt
)
4516 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4518 op0
= gimple_assign_rhs1 (op0stmt
);
4521 op1
= gimple_assign_rhs2 (srcstmt
);
4523 if (!operand_equal_p (to
, op0
, 0))
4526 if (MEM_P (str_rtx
))
4528 unsigned HOST_WIDE_INT offset1
;
4530 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4531 str_mode
= word_mode
;
4532 str_mode
= get_best_mode (bitsize
, bitpos
,
4533 bitregion_start
, bitregion_end
,
4534 MEM_ALIGN (str_rtx
), str_mode
, 0);
4535 if (str_mode
== VOIDmode
)
4537 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4540 bitpos
%= str_bitsize
;
4541 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4542 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4544 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4547 /* If the bit field covers the whole REG/MEM, store_field
4548 will likely generate better code. */
4549 if (bitsize
>= str_bitsize
)
4552 /* We can't handle fields split across multiple entities. */
4553 if (bitpos
+ bitsize
> str_bitsize
)
4556 if (BYTES_BIG_ENDIAN
)
4557 bitpos
= str_bitsize
- bitpos
- bitsize
;
4563 /* For now, just optimize the case of the topmost bitfield
4564 where we don't need to do any masking and also
4565 1 bit bitfields where xor can be used.
4566 We might win by one instruction for the other bitfields
4567 too if insv/extv instructions aren't used, so that
4568 can be added later. */
4569 if (bitpos
+ bitsize
!= str_bitsize
4570 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4573 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4574 value
= convert_modes (str_mode
,
4575 TYPE_MODE (TREE_TYPE (op1
)), value
,
4576 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4578 /* We may be accessing data outside the field, which means
4579 we can alias adjacent data. */
4580 if (MEM_P (str_rtx
))
4582 str_rtx
= shallow_copy_rtx (str_rtx
);
4583 set_mem_alias_set (str_rtx
, 0);
4584 set_mem_expr (str_rtx
, 0);
4587 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4588 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4590 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4593 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4594 result
= expand_binop (str_mode
, binop
, str_rtx
,
4595 value
, str_rtx
, 1, OPTAB_WIDEN
);
4596 if (result
!= str_rtx
)
4597 emit_move_insn (str_rtx
, result
);
4602 if (TREE_CODE (op1
) != INTEGER_CST
)
4604 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4605 value
= convert_modes (str_mode
,
4606 TYPE_MODE (TREE_TYPE (op1
)), value
,
4607 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4609 /* We may be accessing data outside the field, which means
4610 we can alias adjacent data. */
4611 if (MEM_P (str_rtx
))
4613 str_rtx
= shallow_copy_rtx (str_rtx
);
4614 set_mem_alias_set (str_rtx
, 0);
4615 set_mem_expr (str_rtx
, 0);
4618 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4619 if (bitpos
+ bitsize
!= str_bitsize
)
4621 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4623 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4625 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4626 result
= expand_binop (str_mode
, binop
, str_rtx
,
4627 value
, str_rtx
, 1, OPTAB_WIDEN
);
4628 if (result
!= str_rtx
)
4629 emit_move_insn (str_rtx
, result
);
4639 /* In the C++ memory model, consecutive bit fields in a structure are
4640 considered one memory location.
4642 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4643 returns the bit range of consecutive bits in which this COMPONENT_REF
4644 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4645 and *OFFSET may be adjusted in the process.
4647 If the access does not need to be restricted, 0 is returned in both
4648 *BITSTART and *BITEND. */
4651 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4652 unsigned HOST_WIDE_INT
*bitend
,
4654 HOST_WIDE_INT
*bitpos
,
4657 HOST_WIDE_INT bitoffset
;
4660 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4662 field
= TREE_OPERAND (exp
, 1);
4663 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4664 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4665 need to limit the range we can access. */
4668 *bitstart
= *bitend
= 0;
4672 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4673 part of a larger bit field, then the representative does not serve any
4674 useful purpose. This can occur in Ada. */
4675 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4678 HOST_WIDE_INT rbitsize
, rbitpos
;
4682 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4683 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4684 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4686 *bitstart
= *bitend
= 0;
4691 /* Compute the adjustment to bitpos from the offset of the field
4692 relative to the representative. DECL_FIELD_OFFSET of field and
4693 repr are the same by construction if they are not constants,
4694 see finish_bitfield_layout. */
4695 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4696 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4697 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4698 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4701 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4702 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4704 /* If the adjustment is larger than bitpos, we would have a negative bit
4705 position for the lower bound and this may wreak havoc later. Adjust
4706 offset and bitpos to make the lower bound non-negative in that case. */
4707 if (bitoffset
> *bitpos
)
4709 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4710 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4713 if (*offset
== NULL_TREE
)
4714 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4717 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4721 *bitstart
= *bitpos
- bitoffset
;
4723 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4726 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4727 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4728 DECL_RTL was not set yet, return NORTL. */
4731 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4733 if (TREE_CODE (addr
) != ADDR_EXPR
)
4736 tree base
= TREE_OPERAND (addr
, 0);
4739 || TREE_ADDRESSABLE (base
)
4740 || DECL_MODE (base
) == BLKmode
)
4743 if (!DECL_RTL_SET_P (base
))
4746 return (!MEM_P (DECL_RTL (base
)));
4749 /* Returns true if the MEM_REF REF refers to an object that does not
4750 reside in memory and has non-BLKmode. */
4753 mem_ref_refers_to_non_mem_p (tree ref
)
4755 tree base
= TREE_OPERAND (ref
, 0);
4756 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4759 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4760 is true, try generating a nontemporal store. */
4763 expand_assignment (tree to
, tree from
, bool nontemporal
)
4769 enum insn_code icode
;
4771 /* Don't crash if the lhs of the assignment was erroneous. */
4772 if (TREE_CODE (to
) == ERROR_MARK
)
4774 expand_normal (from
);
4778 /* Optimize away no-op moves without side-effects. */
4779 if (operand_equal_p (to
, from
, 0))
4782 /* Handle misaligned stores. */
4783 mode
= TYPE_MODE (TREE_TYPE (to
));
4784 if ((TREE_CODE (to
) == MEM_REF
4785 || TREE_CODE (to
) == TARGET_MEM_REF
)
4787 && !mem_ref_refers_to_non_mem_p (to
)
4788 && ((align
= get_object_alignment (to
))
4789 < GET_MODE_ALIGNMENT (mode
))
4790 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4791 != CODE_FOR_nothing
)
4792 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4796 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4797 reg
= force_not_mem (reg
);
4798 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4800 if (icode
!= CODE_FOR_nothing
)
4802 struct expand_operand ops
[2];
4804 create_fixed_operand (&ops
[0], mem
);
4805 create_input_operand (&ops
[1], reg
, mode
);
4806 /* The movmisalign<mode> pattern cannot fail, else the assignment
4807 would silently be omitted. */
4808 expand_insn (icode
, 2, ops
);
4811 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
);
4815 /* Assignment of a structure component needs special treatment
4816 if the structure component's rtx is not simply a MEM.
4817 Assignment of an array element at a constant index, and assignment of
4818 an array element in an unaligned packed structure field, has the same
4819 problem. Same for (partially) storing into a non-memory object. */
4820 if (handled_component_p (to
)
4821 || (TREE_CODE (to
) == MEM_REF
4822 && mem_ref_refers_to_non_mem_p (to
))
4823 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4826 HOST_WIDE_INT bitsize
, bitpos
;
4827 unsigned HOST_WIDE_INT bitregion_start
= 0;
4828 unsigned HOST_WIDE_INT bitregion_end
= 0;
4835 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4836 &unsignedp
, &volatilep
, true);
4838 /* Make sure bitpos is not negative, it can wreak havoc later. */
4841 gcc_assert (offset
== NULL_TREE
);
4842 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4843 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4844 bitpos
&= BITS_PER_UNIT
- 1;
4847 if (TREE_CODE (to
) == COMPONENT_REF
4848 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4849 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4850 /* The C++ memory model naturally applies to byte-aligned fields.
4851 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
4852 BITSIZE are not byte-aligned, there is no need to limit the range
4853 we can access. This can occur with packed structures in Ada. */
4854 else if (bitsize
> 0
4855 && bitsize
% BITS_PER_UNIT
== 0
4856 && bitpos
% BITS_PER_UNIT
== 0)
4858 bitregion_start
= bitpos
;
4859 bitregion_end
= bitpos
+ bitsize
- 1;
4862 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4864 /* If the field has a mode, we want to access it in the
4865 field's mode, not the computed mode.
4866 If a MEM has VOIDmode (external with incomplete type),
4867 use BLKmode for it instead. */
4870 if (mode1
!= VOIDmode
)
4871 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4872 else if (GET_MODE (to_rtx
) == VOIDmode
)
4873 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4878 machine_mode address_mode
;
4881 if (!MEM_P (to_rtx
))
4883 /* We can get constant negative offsets into arrays with broken
4884 user code. Translate this to a trap instead of ICEing. */
4885 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4886 expand_builtin_trap ();
4887 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4890 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4891 address_mode
= get_address_mode (to_rtx
);
4892 if (GET_MODE (offset_rtx
) != address_mode
)
4894 /* We cannot be sure that the RTL in offset_rtx is valid outside
4895 of a memory address context, so force it into a register
4896 before attempting to convert it to the desired mode. */
4897 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
4898 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4901 /* If we have an expression in OFFSET_RTX and a non-zero
4902 byte offset in BITPOS, adding the byte offset before the
4903 OFFSET_RTX results in better intermediate code, which makes
4904 later rtl optimization passes perform better.
4906 We prefer intermediate code like this:
4908 r124:DI=r123:DI+0x18
4913 r124:DI=r123:DI+0x10
4914 [r124:DI+0x8]=r121:DI
4916 This is only done for aligned data values, as these can
4917 be expected to result in single move instructions. */
4918 if (mode1
!= VOIDmode
4921 && (bitpos
% bitsize
) == 0
4922 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4923 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
4925 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4926 bitregion_start
= 0;
4927 if (bitregion_end
>= (unsigned HOST_WIDE_INT
) bitpos
)
4928 bitregion_end
-= bitpos
;
4932 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4933 highest_pow2_factor_for_target (to
,
4937 /* No action is needed if the target is not a memory and the field
4938 lies completely outside that target. This can occur if the source
4939 code contains an out-of-bounds access to a small array. */
4941 && GET_MODE (to_rtx
) != BLKmode
4942 && (unsigned HOST_WIDE_INT
) bitpos
4943 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4945 expand_normal (from
);
4948 /* Handle expand_expr of a complex value returning a CONCAT. */
4949 else if (GET_CODE (to_rtx
) == CONCAT
)
4951 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4952 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4954 && bitsize
== mode_bitsize
)
4955 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4956 else if (bitsize
== mode_bitsize
/ 2
4957 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4958 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4960 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4961 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4962 bitregion_start
, bitregion_end
,
4964 get_alias_set (to
), nontemporal
);
4965 else if (bitpos
>= mode_bitsize
/ 2)
4966 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4967 bitpos
- mode_bitsize
/ 2,
4968 bitregion_start
, bitregion_end
,
4970 get_alias_set (to
), nontemporal
);
4971 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4974 result
= expand_normal (from
);
4975 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4976 TYPE_MODE (TREE_TYPE (from
)), 0);
4977 emit_move_insn (XEXP (to_rtx
, 0),
4978 read_complex_part (from_rtx
, false));
4979 emit_move_insn (XEXP (to_rtx
, 1),
4980 read_complex_part (from_rtx
, true));
4984 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4985 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4986 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4987 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4988 result
= store_field (temp
, bitsize
, bitpos
,
4989 bitregion_start
, bitregion_end
,
4991 get_alias_set (to
), nontemporal
);
4992 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4993 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
5000 /* If the field is at offset zero, we could have been given the
5001 DECL_RTX of the parent struct. Don't munge it. */
5002 to_rtx
= shallow_copy_rtx (to_rtx
);
5003 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
5005 MEM_VOLATILE_P (to_rtx
) = 1;
5008 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
5009 bitregion_start
, bitregion_end
,
5014 result
= store_field (to_rtx
, bitsize
, bitpos
,
5015 bitregion_start
, bitregion_end
,
5017 get_alias_set (to
), nontemporal
);
5021 preserve_temp_slots (result
);
5026 /* If the rhs is a function call and its value is not an aggregate,
5027 call the function before we start to compute the lhs.
5028 This is needed for correct code for cases such as
5029 val = setjmp (buf) on machines where reference to val
5030 requires loading up part of an address in a separate insn.
5032 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
5033 since it might be a promoted variable where the zero- or sign- extension
5034 needs to be done. Handling this in the normal way is safe because no
5035 computation is done before the call. The same is true for SSA names. */
5036 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
5037 && COMPLETE_TYPE_P (TREE_TYPE (from
))
5038 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
5039 && ! (((TREE_CODE (to
) == VAR_DECL
5040 || TREE_CODE (to
) == PARM_DECL
5041 || TREE_CODE (to
) == RESULT_DECL
)
5042 && REG_P (DECL_RTL (to
)))
5043 || TREE_CODE (to
) == SSA_NAME
))
5049 value
= expand_normal (from
);
5051 /* Split value and bounds to store them separately. */
5052 chkp_split_slot (value
, &value
, &bounds
);
5055 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5057 /* Handle calls that return values in multiple non-contiguous locations.
5058 The Irix 6 ABI has examples of this. */
5059 if (GET_CODE (to_rtx
) == PARALLEL
)
5061 if (GET_CODE (value
) == PARALLEL
)
5062 emit_group_move (to_rtx
, value
);
5064 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5065 int_size_in_bytes (TREE_TYPE (from
)));
5067 else if (GET_CODE (value
) == PARALLEL
)
5068 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5069 int_size_in_bytes (TREE_TYPE (from
)));
5070 else if (GET_MODE (to_rtx
) == BLKmode
)
5072 /* Handle calls that return BLKmode values in registers. */
5074 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5076 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5080 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5081 value
= convert_memory_address_addr_space
5082 (GET_MODE (to_rtx
), value
,
5083 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5085 emit_move_insn (to_rtx
, value
);
5088 /* Store bounds if required. */
5090 && (BOUNDED_P (to
) || chkp_type_has_pointer (TREE_TYPE (to
))))
5092 gcc_assert (MEM_P (to_rtx
));
5093 chkp_emit_bounds_store (bounds
, value
, to_rtx
);
5096 preserve_temp_slots (to_rtx
);
5101 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5102 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5104 /* Don't move directly into a return register. */
5105 if (TREE_CODE (to
) == RESULT_DECL
5106 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5112 /* If the source is itself a return value, it still is in a pseudo at
5113 this point so we can move it back to the return register directly. */
5115 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5116 && TREE_CODE (from
) != CALL_EXPR
)
5117 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5119 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5121 /* Handle calls that return values in multiple non-contiguous locations.
5122 The Irix 6 ABI has examples of this. */
5123 if (GET_CODE (to_rtx
) == PARALLEL
)
5125 if (GET_CODE (temp
) == PARALLEL
)
5126 emit_group_move (to_rtx
, temp
);
5128 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5129 int_size_in_bytes (TREE_TYPE (from
)));
5132 emit_move_insn (to_rtx
, temp
);
5134 preserve_temp_slots (to_rtx
);
5139 /* In case we are returning the contents of an object which overlaps
5140 the place the value is being stored, use a safe function when copying
5141 a value through a pointer into a structure value return block. */
5142 if (TREE_CODE (to
) == RESULT_DECL
5143 && TREE_CODE (from
) == INDIRECT_REF
5144 && ADDR_SPACE_GENERIC_P
5145 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5146 && refs_may_alias_p (to
, from
)
5147 && cfun
->returns_struct
5148 && !cfun
->returns_pcc_struct
)
5153 size
= expr_size (from
);
5154 from_rtx
= expand_normal (from
);
5156 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5157 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5158 XEXP (from_rtx
, 0), Pmode
,
5159 convert_to_mode (TYPE_MODE (sizetype
),
5160 size
, TYPE_UNSIGNED (sizetype
)),
5161 TYPE_MODE (sizetype
));
5163 preserve_temp_slots (to_rtx
);
5168 /* Compute FROM and store the value in the rtx we got. */
5171 result
= store_expr_with_bounds (from
, to_rtx
, 0, nontemporal
, to
);
5172 preserve_temp_slots (result
);
5177 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5178 succeeded, false otherwise. */
5181 emit_storent_insn (rtx to
, rtx from
)
5183 struct expand_operand ops
[2];
5184 machine_mode mode
= GET_MODE (to
);
5185 enum insn_code code
= optab_handler (storent_optab
, mode
);
5187 if (code
== CODE_FOR_nothing
)
5190 create_fixed_operand (&ops
[0], to
);
5191 create_input_operand (&ops
[1], from
, mode
);
5192 return maybe_expand_insn (code
, 2, ops
);
5195 /* Generate code for computing expression EXP,
5196 and storing the value into TARGET.
5198 If the mode is BLKmode then we may return TARGET itself.
5199 It turns out that in BLKmode it doesn't cause a problem.
5200 because C has no operators that could combine two different
5201 assignments into the same BLKmode object with different values
5202 with no sequence point. Will other languages need this to
5205 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5206 stack, and block moves may need to be treated specially.
5208 If NONTEMPORAL is true, try using a nontemporal store instruction.
5210 If BTARGET is not NULL then computed bounds of EXP are
5211 associated with BTARGET. */
5214 store_expr_with_bounds (tree exp
, rtx target
, int call_param_p
,
5215 bool nontemporal
, tree btarget
)
5218 rtx alt_rtl
= NULL_RTX
;
5219 location_t loc
= curr_insn_location ();
5221 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5223 /* C++ can generate ?: expressions with a throw expression in one
5224 branch and an rvalue in the other. Here, we resolve attempts to
5225 store the throw expression's nonexistent result. */
5226 gcc_assert (!call_param_p
);
5227 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5230 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5232 /* Perform first part of compound expression, then assign from second
5234 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5235 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5236 return store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
,
5237 call_param_p
, nontemporal
, btarget
);
5239 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5241 /* For conditional expression, get safe form of the target. Then
5242 test the condition, doing the appropriate assignment on either
5243 side. This avoids the creation of unnecessary temporaries.
5244 For non-BLKmode, it is more efficient not to do this. */
5246 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
5248 do_pending_stack_adjust ();
5250 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5251 store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5252 nontemporal
, btarget
);
5253 emit_jump_insn (targetm
.gen_jump (lab2
));
5256 store_expr_with_bounds (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5257 nontemporal
, btarget
);
5263 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5264 /* If this is a scalar in a register that is stored in a wider mode
5265 than the declared mode, compute the result into its declared mode
5266 and then convert to the wider mode. Our value is the computed
5269 rtx inner_target
= 0;
5271 /* We can do the conversion inside EXP, which will often result
5272 in some optimizations. Do the conversion in two steps: first
5273 change the signedness, if needed, then the extend. But don't
5274 do this if the type of EXP is a subtype of something else
5275 since then the conversion might involve more than just
5276 converting modes. */
5277 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5278 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5279 && GET_MODE_PRECISION (GET_MODE (target
))
5280 == TYPE_PRECISION (TREE_TYPE (exp
)))
5282 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
5283 TYPE_UNSIGNED (TREE_TYPE (exp
))))
5285 /* Some types, e.g. Fortran's logical*4, won't have a signed
5286 version, so use the mode instead. */
5288 = (signed_or_unsigned_type_for
5289 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
5291 ntype
= lang_hooks
.types
.type_for_mode
5292 (TYPE_MODE (TREE_TYPE (exp
)),
5293 SUBREG_PROMOTED_SIGN (target
));
5295 exp
= fold_convert_loc (loc
, ntype
, exp
);
5298 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5299 (GET_MODE (SUBREG_REG (target
)),
5300 SUBREG_PROMOTED_SIGN (target
)),
5303 inner_target
= SUBREG_REG (target
);
5306 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5307 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5309 /* Handle bounds returned by call. */
5310 if (TREE_CODE (exp
) == CALL_EXPR
)
5313 chkp_split_slot (temp
, &temp
, &bounds
);
5314 if (bounds
&& btarget
)
5316 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5317 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5318 chkp_set_rtl_bounds (btarget
, tmp
);
5322 /* If TEMP is a VOIDmode constant, use convert_modes to make
5323 sure that we properly convert it. */
5324 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5326 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5327 temp
, SUBREG_PROMOTED_SIGN (target
));
5328 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5329 GET_MODE (target
), temp
,
5330 SUBREG_PROMOTED_SIGN (target
));
5333 convert_move (SUBREG_REG (target
), temp
,
5334 SUBREG_PROMOTED_SIGN (target
));
5338 else if ((TREE_CODE (exp
) == STRING_CST
5339 || (TREE_CODE (exp
) == MEM_REF
5340 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5341 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5343 && integer_zerop (TREE_OPERAND (exp
, 1))))
5344 && !nontemporal
&& !call_param_p
5347 /* Optimize initialization of an array with a STRING_CST. */
5348 HOST_WIDE_INT exp_len
, str_copy_len
;
5350 tree str
= TREE_CODE (exp
) == STRING_CST
5351 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5353 exp_len
= int_expr_size (exp
);
5357 if (TREE_STRING_LENGTH (str
) <= 0)
5360 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5361 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5364 str_copy_len
= TREE_STRING_LENGTH (str
);
5365 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5366 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5368 str_copy_len
+= STORE_MAX_PIECES
- 1;
5369 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5371 str_copy_len
= MIN (str_copy_len
, exp_len
);
5372 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5373 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5374 MEM_ALIGN (target
), false))
5379 dest_mem
= store_by_pieces (dest_mem
,
5380 str_copy_len
, builtin_strncpy_read_str
,
5382 TREE_STRING_POINTER (str
)),
5383 MEM_ALIGN (target
), false,
5384 exp_len
> str_copy_len
? 1 : 0);
5385 if (exp_len
> str_copy_len
)
5386 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5387 GEN_INT (exp_len
- str_copy_len
),
5396 /* If we want to use a nontemporal store, force the value to
5398 tmp_target
= nontemporal
? NULL_RTX
: target
;
5399 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5401 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5404 /* Handle bounds returned by call. */
5405 if (TREE_CODE (exp
) == CALL_EXPR
)
5408 chkp_split_slot (temp
, &temp
, &bounds
);
5409 if (bounds
&& btarget
)
5411 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5412 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5413 chkp_set_rtl_bounds (btarget
, tmp
);
5418 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5419 the same as that of TARGET, adjust the constant. This is needed, for
5420 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5421 only a word-sized value. */
5422 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5423 && TREE_CODE (exp
) != ERROR_MARK
5424 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5425 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5426 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5428 /* If value was not generated in the target, store it there.
5429 Convert the value to TARGET's type first if necessary and emit the
5430 pending incrementations that have been queued when expanding EXP.
5431 Note that we cannot emit the whole queue blindly because this will
5432 effectively disable the POST_INC optimization later.
5434 If TEMP and TARGET compare equal according to rtx_equal_p, but
5435 one or both of them are volatile memory refs, we have to distinguish
5437 - expand_expr has used TARGET. In this case, we must not generate
5438 another copy. This can be detected by TARGET being equal according
5440 - expand_expr has not used TARGET - that means that the source just
5441 happens to have the same RTX form. Since temp will have been created
5442 by expand_expr, it will compare unequal according to == .
5443 We must generate a copy in this case, to reach the correct number
5444 of volatile memory references. */
5446 if ((! rtx_equal_p (temp
, target
)
5447 || (temp
!= target
&& (side_effects_p (temp
)
5448 || side_effects_p (target
))))
5449 && TREE_CODE (exp
) != ERROR_MARK
5450 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5451 but TARGET is not valid memory reference, TEMP will differ
5452 from TARGET although it is really the same location. */
5454 && rtx_equal_p (alt_rtl
, target
)
5455 && !side_effects_p (alt_rtl
)
5456 && !side_effects_p (target
))
5457 /* If there's nothing to copy, don't bother. Don't call
5458 expr_size unless necessary, because some front-ends (C++)
5459 expr_size-hook must not be given objects that are not
5460 supposed to be bit-copied or bit-initialized. */
5461 && expr_size (exp
) != const0_rtx
)
5463 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5465 if (GET_MODE (target
) == BLKmode
)
5467 /* Handle calls that return BLKmode values in registers. */
5468 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5469 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5471 store_bit_field (target
,
5472 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5473 0, 0, 0, GET_MODE (temp
), temp
);
5476 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5479 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5481 /* Handle copying a string constant into an array. The string
5482 constant may be shorter than the array. So copy just the string's
5483 actual length, and clear the rest. First get the size of the data
5484 type of the string, which is actually the size of the target. */
5485 rtx size
= expr_size (exp
);
5487 if (CONST_INT_P (size
)
5488 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5489 emit_block_move (target
, temp
, size
,
5491 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5494 machine_mode pointer_mode
5495 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5496 machine_mode address_mode
= get_address_mode (target
);
5498 /* Compute the size of the data to copy from the string. */
5500 = size_binop_loc (loc
, MIN_EXPR
,
5501 make_tree (sizetype
, size
),
5502 size_int (TREE_STRING_LENGTH (exp
)));
5504 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5506 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5507 rtx_code_label
*label
= 0;
5509 /* Copy that much. */
5510 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5511 TYPE_UNSIGNED (sizetype
));
5512 emit_block_move (target
, temp
, copy_size_rtx
,
5514 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5516 /* Figure out how much is left in TARGET that we have to clear.
5517 Do all calculations in pointer_mode. */
5518 if (CONST_INT_P (copy_size_rtx
))
5520 size
= plus_constant (address_mode
, size
,
5521 -INTVAL (copy_size_rtx
));
5522 target
= adjust_address (target
, BLKmode
,
5523 INTVAL (copy_size_rtx
));
5527 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5528 copy_size_rtx
, NULL_RTX
, 0,
5531 if (GET_MODE (copy_size_rtx
) != address_mode
)
5532 copy_size_rtx
= convert_to_mode (address_mode
,
5534 TYPE_UNSIGNED (sizetype
));
5536 target
= offset_address (target
, copy_size_rtx
,
5537 highest_pow2_factor (copy_size
));
5538 label
= gen_label_rtx ();
5539 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5540 GET_MODE (size
), 0, label
);
5543 if (size
!= const0_rtx
)
5544 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5550 /* Handle calls that return values in multiple non-contiguous locations.
5551 The Irix 6 ABI has examples of this. */
5552 else if (GET_CODE (target
) == PARALLEL
)
5554 if (GET_CODE (temp
) == PARALLEL
)
5555 emit_group_move (target
, temp
);
5557 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5558 int_size_in_bytes (TREE_TYPE (exp
)));
5560 else if (GET_CODE (temp
) == PARALLEL
)
5561 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5562 int_size_in_bytes (TREE_TYPE (exp
)));
5563 else if (GET_MODE (temp
) == BLKmode
)
5564 emit_block_move (target
, temp
, expr_size (exp
),
5566 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5567 /* If we emit a nontemporal store, there is nothing else to do. */
5568 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5572 temp
= force_operand (temp
, target
);
5574 emit_move_insn (target
, temp
);
5581 /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
5583 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5585 return store_expr_with_bounds (exp
, target
, call_param_p
, nontemporal
, NULL
);
5588 /* Return true if field F of structure TYPE is a flexible array. */
5591 flexible_array_member_p (const_tree f
, const_tree type
)
5596 return (DECL_CHAIN (f
) == NULL
5597 && TREE_CODE (tf
) == ARRAY_TYPE
5599 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5600 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5601 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5602 && int_size_in_bytes (type
) >= 0);
5605 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5606 must have in order for it to completely initialize a value of type TYPE.
5607 Return -1 if the number isn't known.
5609 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5611 static HOST_WIDE_INT
5612 count_type_elements (const_tree type
, bool for_ctor_p
)
5614 switch (TREE_CODE (type
))
5620 nelts
= array_type_nelts (type
);
5621 if (nelts
&& tree_fits_uhwi_p (nelts
))
5623 unsigned HOST_WIDE_INT n
;
5625 n
= tree_to_uhwi (nelts
) + 1;
5626 if (n
== 0 || for_ctor_p
)
5629 return n
* count_type_elements (TREE_TYPE (type
), false);
5631 return for_ctor_p
? -1 : 1;
5636 unsigned HOST_WIDE_INT n
;
5640 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5641 if (TREE_CODE (f
) == FIELD_DECL
)
5644 n
+= count_type_elements (TREE_TYPE (f
), false);
5645 else if (!flexible_array_member_p (f
, type
))
5646 /* Don't count flexible arrays, which are not supposed
5647 to be initialized. */
5655 case QUAL_UNION_TYPE
:
5660 gcc_assert (!for_ctor_p
);
5661 /* Estimate the number of scalars in each field and pick the
5662 maximum. Other estimates would do instead; the idea is simply
5663 to make sure that the estimate is not sensitive to the ordering
5666 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5667 if (TREE_CODE (f
) == FIELD_DECL
)
5669 m
= count_type_elements (TREE_TYPE (f
), false);
5670 /* If the field doesn't span the whole union, add an extra
5671 scalar for the rest. */
5672 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5673 TYPE_SIZE (type
)) != 1)
5685 return TYPE_VECTOR_SUBPARTS (type
);
5689 case FIXED_POINT_TYPE
:
5694 case REFERENCE_TYPE
:
5710 /* Helper for categorize_ctor_elements. Identical interface. */
5713 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5714 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5716 unsigned HOST_WIDE_INT idx
;
5717 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5718 tree value
, purpose
, elt_type
;
5720 /* Whether CTOR is a valid constant initializer, in accordance with what
5721 initializer_constant_valid_p does. If inferred from the constructor
5722 elements, true until proven otherwise. */
5723 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5724 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5729 elt_type
= NULL_TREE
;
5731 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5733 HOST_WIDE_INT mult
= 1;
5735 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5737 tree lo_index
= TREE_OPERAND (purpose
, 0);
5738 tree hi_index
= TREE_OPERAND (purpose
, 1);
5740 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5741 mult
= (tree_to_uhwi (hi_index
)
5742 - tree_to_uhwi (lo_index
) + 1);
5745 elt_type
= TREE_TYPE (value
);
5747 switch (TREE_CODE (value
))
5751 HOST_WIDE_INT nz
= 0, ic
= 0;
5753 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5756 nz_elts
+= mult
* nz
;
5757 init_elts
+= mult
* ic
;
5759 if (const_from_elts_p
&& const_p
)
5760 const_p
= const_elt_p
;
5767 if (!initializer_zerop (value
))
5773 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5774 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5778 if (!initializer_zerop (TREE_REALPART (value
)))
5780 if (!initializer_zerop (TREE_IMAGPART (value
)))
5788 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5790 tree v
= VECTOR_CST_ELT (value
, i
);
5791 if (!initializer_zerop (v
))
5800 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5801 nz_elts
+= mult
* tc
;
5802 init_elts
+= mult
* tc
;
5804 if (const_from_elts_p
&& const_p
)
5805 const_p
= initializer_constant_valid_p (value
, elt_type
)
5812 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5813 num_fields
, elt_type
))
5814 *p_complete
= false;
5816 *p_nz_elts
+= nz_elts
;
5817 *p_init_elts
+= init_elts
;
5822 /* Examine CTOR to discover:
5823 * how many scalar fields are set to nonzero values,
5824 and place it in *P_NZ_ELTS;
5825 * how many scalar fields in total are in CTOR,
5826 and place it in *P_ELT_COUNT.
5827 * whether the constructor is complete -- in the sense that every
5828 meaningful byte is explicitly given a value --
5829 and place it in *P_COMPLETE.
5831 Return whether or not CTOR is a valid static constant initializer, the same
5832 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5835 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5836 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5842 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5845 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5846 of which had type LAST_TYPE. Each element was itself a complete
5847 initializer, in the sense that every meaningful byte was explicitly
5848 given a value. Return true if the same is true for the constructor
5852 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5853 const_tree last_type
)
5855 if (TREE_CODE (type
) == UNION_TYPE
5856 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5861 gcc_assert (num_elts
== 1 && last_type
);
5863 /* ??? We could look at each element of the union, and find the
5864 largest element. Which would avoid comparing the size of the
5865 initialized element against any tail padding in the union.
5866 Doesn't seem worth the effort... */
5867 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5870 return count_type_elements (type
, true) == num_elts
;
5873 /* Return 1 if EXP contains mostly (3/4) zeros. */
5876 mostly_zeros_p (const_tree exp
)
5878 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5880 HOST_WIDE_INT nz_elts
, init_elts
;
5883 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5884 return !complete_p
|| nz_elts
< init_elts
/ 4;
5887 return initializer_zerop (exp
);
5890 /* Return 1 if EXP contains all zeros. */
5893 all_zeros_p (const_tree exp
)
5895 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5897 HOST_WIDE_INT nz_elts
, init_elts
;
5900 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5901 return nz_elts
== 0;
5904 return initializer_zerop (exp
);
5907 /* Helper function for store_constructor.
5908 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5909 CLEARED is as for store_constructor.
5910 ALIAS_SET is the alias set to use for any stores.
5912 This provides a recursive shortcut back to store_constructor when it isn't
5913 necessary to go through store_field. This is so that we can pass through
5914 the cleared field to let store_constructor know that we may not have to
5915 clear a substructure if the outer structure has already been cleared. */
5918 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5919 HOST_WIDE_INT bitpos
, machine_mode mode
,
5920 tree exp
, int cleared
, alias_set_type alias_set
)
5922 if (TREE_CODE (exp
) == CONSTRUCTOR
5923 /* We can only call store_constructor recursively if the size and
5924 bit position are on a byte boundary. */
5925 && bitpos
% BITS_PER_UNIT
== 0
5926 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5927 /* If we have a nonzero bitpos for a register target, then we just
5928 let store_field do the bitfield handling. This is unlikely to
5929 generate unnecessary clear instructions anyways. */
5930 && (bitpos
== 0 || MEM_P (target
)))
5934 = adjust_address (target
,
5935 GET_MODE (target
) == BLKmode
5937 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5938 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5941 /* Update the alias set, if required. */
5942 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5943 && MEM_ALIAS_SET (target
) != 0)
5945 target
= copy_rtx (target
);
5946 set_mem_alias_set (target
, alias_set
);
5949 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5952 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5956 /* Returns the number of FIELD_DECLs in TYPE. */
5959 fields_length (const_tree type
)
5961 tree t
= TYPE_FIELDS (type
);
5964 for (; t
; t
= DECL_CHAIN (t
))
5965 if (TREE_CODE (t
) == FIELD_DECL
)
5972 /* Store the value of constructor EXP into the rtx TARGET.
5973 TARGET is either a REG or a MEM; we know it cannot conflict, since
5974 safe_from_p has been called.
5975 CLEARED is true if TARGET is known to have been zero'd.
5976 SIZE is the number of bytes of TARGET we are allowed to modify: this
5977 may not be the same as the size of EXP if we are assigning to a field
5978 which has been packed to exclude padding bits. */
5981 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5983 tree type
= TREE_TYPE (exp
);
5984 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5986 switch (TREE_CODE (type
))
5990 case QUAL_UNION_TYPE
:
5992 unsigned HOST_WIDE_INT idx
;
5995 /* If size is zero or the target is already cleared, do nothing. */
5996 if (size
== 0 || cleared
)
5998 /* We either clear the aggregate or indicate the value is dead. */
5999 else if ((TREE_CODE (type
) == UNION_TYPE
6000 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
6001 && ! CONSTRUCTOR_ELTS (exp
))
6002 /* If the constructor is empty, clear the union. */
6004 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
6008 /* If we are building a static constructor into a register,
6009 set the initial value as zero so we can fold the value into
6010 a constant. But if more than one register is involved,
6011 this probably loses. */
6012 else if (REG_P (target
) && TREE_STATIC (exp
)
6013 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
6015 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6019 /* If the constructor has fewer fields than the structure or
6020 if we are initializing the structure to mostly zeros, clear
6021 the whole structure first. Don't do this if TARGET is a
6022 register whose mode size isn't equal to SIZE since
6023 clear_storage can't handle this case. */
6025 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
6026 != fields_length (type
))
6027 || mostly_zeros_p (exp
))
6029 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
6032 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6036 if (REG_P (target
) && !cleared
)
6037 emit_clobber (target
);
6039 /* Store each element of the constructor into the
6040 corresponding field of TARGET. */
6041 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
6044 HOST_WIDE_INT bitsize
;
6045 HOST_WIDE_INT bitpos
= 0;
6047 rtx to_rtx
= target
;
6049 /* Just ignore missing fields. We cleared the whole
6050 structure, above, if any fields are missing. */
6054 if (cleared
&& initializer_zerop (value
))
6057 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
6058 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
6062 mode
= DECL_MODE (field
);
6063 if (DECL_BIT_FIELD (field
))
6066 offset
= DECL_FIELD_OFFSET (field
);
6067 if (tree_fits_shwi_p (offset
)
6068 && tree_fits_shwi_p (bit_position (field
)))
6070 bitpos
= int_bit_position (field
);
6074 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
6078 machine_mode address_mode
;
6082 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
6083 make_tree (TREE_TYPE (exp
),
6086 offset_rtx
= expand_normal (offset
);
6087 gcc_assert (MEM_P (to_rtx
));
6089 address_mode
= get_address_mode (to_rtx
);
6090 if (GET_MODE (offset_rtx
) != address_mode
)
6091 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6093 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6094 highest_pow2_factor (offset
));
6097 /* If this initializes a field that is smaller than a
6098 word, at the start of a word, try to widen it to a full
6099 word. This special case allows us to output C++ member
6100 function initializations in a form that the optimizers
6102 if (WORD_REGISTER_OPERATIONS
6104 && bitsize
< BITS_PER_WORD
6105 && bitpos
% BITS_PER_WORD
== 0
6106 && GET_MODE_CLASS (mode
) == MODE_INT
6107 && TREE_CODE (value
) == INTEGER_CST
6109 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6111 tree type
= TREE_TYPE (value
);
6113 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6115 type
= lang_hooks
.types
.type_for_mode
6116 (word_mode
, TYPE_UNSIGNED (type
));
6117 value
= fold_convert (type
, value
);
6120 if (BYTES_BIG_ENDIAN
)
6122 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6123 build_int_cst (type
,
6124 BITS_PER_WORD
- bitsize
));
6125 bitsize
= BITS_PER_WORD
;
6129 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6130 && DECL_NONADDRESSABLE_P (field
))
6132 to_rtx
= copy_rtx (to_rtx
);
6133 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6136 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6138 get_alias_set (TREE_TYPE (field
)));
6145 unsigned HOST_WIDE_INT i
;
6148 tree elttype
= TREE_TYPE (type
);
6150 HOST_WIDE_INT minelt
= 0;
6151 HOST_WIDE_INT maxelt
= 0;
6153 domain
= TYPE_DOMAIN (type
);
6154 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6155 && TYPE_MAX_VALUE (domain
)
6156 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6157 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6159 /* If we have constant bounds for the range of the type, get them. */
6162 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6163 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6166 /* If the constructor has fewer elements than the array, clear
6167 the whole array first. Similarly if this is static
6168 constructor of a non-BLKmode object. */
6171 else if (REG_P (target
) && TREE_STATIC (exp
))
6175 unsigned HOST_WIDE_INT idx
;
6177 HOST_WIDE_INT count
= 0, zero_count
= 0;
6178 need_to_clear
= ! const_bounds_p
;
6180 /* This loop is a more accurate version of the loop in
6181 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6182 is also needed to check for missing elements. */
6183 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6185 HOST_WIDE_INT this_node_count
;
6190 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6192 tree lo_index
= TREE_OPERAND (index
, 0);
6193 tree hi_index
= TREE_OPERAND (index
, 1);
6195 if (! tree_fits_uhwi_p (lo_index
)
6196 || ! tree_fits_uhwi_p (hi_index
))
6202 this_node_count
= (tree_to_uhwi (hi_index
)
6203 - tree_to_uhwi (lo_index
) + 1);
6206 this_node_count
= 1;
6208 count
+= this_node_count
;
6209 if (mostly_zeros_p (value
))
6210 zero_count
+= this_node_count
;
6213 /* Clear the entire array first if there are any missing
6214 elements, or if the incidence of zero elements is >=
6217 && (count
< maxelt
- minelt
+ 1
6218 || 4 * zero_count
>= 3 * count
))
6222 if (need_to_clear
&& size
> 0)
6225 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6227 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6231 if (!cleared
&& REG_P (target
))
6232 /* Inform later passes that the old value is dead. */
6233 emit_clobber (target
);
6235 /* Store each element of the constructor into the
6236 corresponding element of TARGET, determined by counting the
6238 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6241 HOST_WIDE_INT bitsize
;
6242 HOST_WIDE_INT bitpos
;
6243 rtx xtarget
= target
;
6245 if (cleared
&& initializer_zerop (value
))
6248 mode
= TYPE_MODE (elttype
);
6249 if (mode
== BLKmode
)
6250 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6251 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6254 bitsize
= GET_MODE_BITSIZE (mode
);
6256 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6258 tree lo_index
= TREE_OPERAND (index
, 0);
6259 tree hi_index
= TREE_OPERAND (index
, 1);
6260 rtx index_r
, pos_rtx
;
6261 HOST_WIDE_INT lo
, hi
, count
;
6264 /* If the range is constant and "small", unroll the loop. */
6266 && tree_fits_shwi_p (lo_index
)
6267 && tree_fits_shwi_p (hi_index
)
6268 && (lo
= tree_to_shwi (lo_index
),
6269 hi
= tree_to_shwi (hi_index
),
6270 count
= hi
- lo
+ 1,
6273 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6274 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6277 lo
-= minelt
; hi
-= minelt
;
6278 for (; lo
<= hi
; lo
++)
6280 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6283 && !MEM_KEEP_ALIAS_SET_P (target
)
6284 && TREE_CODE (type
) == ARRAY_TYPE
6285 && TYPE_NONALIASED_COMPONENT (type
))
6287 target
= copy_rtx (target
);
6288 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6291 store_constructor_field
6292 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6293 get_alias_set (elttype
));
6298 rtx_code_label
*loop_start
= gen_label_rtx ();
6299 rtx_code_label
*loop_end
= gen_label_rtx ();
6302 expand_normal (hi_index
);
6304 index
= build_decl (EXPR_LOCATION (exp
),
6305 VAR_DECL
, NULL_TREE
, domain
);
6306 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6307 SET_DECL_RTL (index
, index_r
);
6308 store_expr (lo_index
, index_r
, 0, false);
6310 /* Build the head of the loop. */
6311 do_pending_stack_adjust ();
6312 emit_label (loop_start
);
6314 /* Assign value to element index. */
6316 fold_convert (ssizetype
,
6317 fold_build2 (MINUS_EXPR
,
6320 TYPE_MIN_VALUE (domain
)));
6323 size_binop (MULT_EXPR
, position
,
6324 fold_convert (ssizetype
,
6325 TYPE_SIZE_UNIT (elttype
)));
6327 pos_rtx
= expand_normal (position
);
6328 xtarget
= offset_address (target
, pos_rtx
,
6329 highest_pow2_factor (position
));
6330 xtarget
= adjust_address (xtarget
, mode
, 0);
6331 if (TREE_CODE (value
) == CONSTRUCTOR
)
6332 store_constructor (value
, xtarget
, cleared
,
6333 bitsize
/ BITS_PER_UNIT
);
6335 store_expr (value
, xtarget
, 0, false);
6337 /* Generate a conditional jump to exit the loop. */
6338 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6340 jumpif (exit_cond
, loop_end
, -1);
6342 /* Update the loop counter, and jump to the head of
6344 expand_assignment (index
,
6345 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6346 index
, integer_one_node
),
6349 emit_jump (loop_start
);
6351 /* Build the end of the loop. */
6352 emit_label (loop_end
);
6355 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6356 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6361 index
= ssize_int (1);
6364 index
= fold_convert (ssizetype
,
6365 fold_build2 (MINUS_EXPR
,
6368 TYPE_MIN_VALUE (domain
)));
6371 size_binop (MULT_EXPR
, index
,
6372 fold_convert (ssizetype
,
6373 TYPE_SIZE_UNIT (elttype
)));
6374 xtarget
= offset_address (target
,
6375 expand_normal (position
),
6376 highest_pow2_factor (position
));
6377 xtarget
= adjust_address (xtarget
, mode
, 0);
6378 store_expr (value
, xtarget
, 0, false);
6383 bitpos
= ((tree_to_shwi (index
) - minelt
)
6384 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6386 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6388 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6389 && TREE_CODE (type
) == ARRAY_TYPE
6390 && TYPE_NONALIASED_COMPONENT (type
))
6392 target
= copy_rtx (target
);
6393 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6395 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6396 cleared
, get_alias_set (elttype
));
6404 unsigned HOST_WIDE_INT idx
;
6405 constructor_elt
*ce
;
6408 int icode
= CODE_FOR_nothing
;
6409 tree elttype
= TREE_TYPE (type
);
6410 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6411 machine_mode eltmode
= TYPE_MODE (elttype
);
6412 HOST_WIDE_INT bitsize
;
6413 HOST_WIDE_INT bitpos
;
6414 rtvec vector
= NULL
;
6416 alias_set_type alias
;
6418 gcc_assert (eltmode
!= BLKmode
);
6420 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6421 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6423 machine_mode mode
= GET_MODE (target
);
6425 icode
= (int) optab_handler (vec_init_optab
, mode
);
6426 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6427 if (icode
!= CODE_FOR_nothing
)
6431 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6432 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6434 icode
= CODE_FOR_nothing
;
6438 if (icode
!= CODE_FOR_nothing
)
6442 vector
= rtvec_alloc (n_elts
);
6443 for (i
= 0; i
< n_elts
; i
++)
6444 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6448 /* If the constructor has fewer elements than the vector,
6449 clear the whole array first. Similarly if this is static
6450 constructor of a non-BLKmode object. */
6453 else if (REG_P (target
) && TREE_STATIC (exp
))
6457 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6460 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6462 int n_elts_here
= tree_to_uhwi
6463 (int_const_binop (TRUNC_DIV_EXPR
,
6464 TYPE_SIZE (TREE_TYPE (value
)),
6465 TYPE_SIZE (elttype
)));
6467 count
+= n_elts_here
;
6468 if (mostly_zeros_p (value
))
6469 zero_count
+= n_elts_here
;
6472 /* Clear the entire vector first if there are any missing elements,
6473 or if the incidence of zero elements is >= 75%. */
6474 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6477 if (need_to_clear
&& size
> 0 && !vector
)
6480 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6482 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6486 /* Inform later passes that the old value is dead. */
6487 if (!cleared
&& !vector
&& REG_P (target
))
6488 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6491 alias
= MEM_ALIAS_SET (target
);
6493 alias
= get_alias_set (elttype
);
6495 /* Store each element of the constructor into the corresponding
6496 element of TARGET, determined by counting the elements. */
6497 for (idx
= 0, i
= 0;
6498 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6499 idx
++, i
+= bitsize
/ elt_size
)
6501 HOST_WIDE_INT eltpos
;
6502 tree value
= ce
->value
;
6504 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6505 if (cleared
&& initializer_zerop (value
))
6509 eltpos
= tree_to_uhwi (ce
->index
);
6515 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6517 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6518 RTVEC_ELT (vector
, eltpos
)
6519 = expand_normal (value
);
6523 machine_mode value_mode
=
6524 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6525 ? TYPE_MODE (TREE_TYPE (value
))
6527 bitpos
= eltpos
* elt_size
;
6528 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6529 value
, cleared
, alias
);
6534 emit_insn (GEN_FCN (icode
)
6536 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6545 /* Store the value of EXP (an expression tree)
6546 into a subfield of TARGET which has mode MODE and occupies
6547 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6548 If MODE is VOIDmode, it means that we are storing into a bit-field.
6550 BITREGION_START is bitpos of the first bitfield in this region.
6551 BITREGION_END is the bitpos of the ending bitfield in this region.
6552 These two fields are 0, if the C++ memory model does not apply,
6553 or we are not interested in keeping track of bitfield regions.
6555 Always return const0_rtx unless we have something particular to
6558 ALIAS_SET is the alias set for the destination. This value will
6559 (in general) be different from that for TARGET, since TARGET is a
6560 reference to the containing structure.
6562 If NONTEMPORAL is true, try generating a nontemporal store. */
6565 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6566 unsigned HOST_WIDE_INT bitregion_start
,
6567 unsigned HOST_WIDE_INT bitregion_end
,
6568 machine_mode mode
, tree exp
,
6569 alias_set_type alias_set
, bool nontemporal
)
6571 if (TREE_CODE (exp
) == ERROR_MARK
)
6574 /* If we have nothing to store, do nothing unless the expression has
6577 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6579 if (GET_CODE (target
) == CONCAT
)
6581 /* We're storing into a struct containing a single __complex. */
6583 gcc_assert (!bitpos
);
6584 return store_expr (exp
, target
, 0, nontemporal
);
6587 /* If the structure is in a register or if the component
6588 is a bit field, we cannot use addressing to access it.
6589 Use bit-field techniques or SUBREG to store in it. */
6591 if (mode
== VOIDmode
6592 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6593 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6594 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6596 || GET_CODE (target
) == SUBREG
6597 /* If the field isn't aligned enough to store as an ordinary memref,
6598 store it as a bit field. */
6600 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6601 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6602 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6603 || (bitpos
% BITS_PER_UNIT
!= 0)))
6604 || (bitsize
>= 0 && mode
!= BLKmode
6605 && GET_MODE_BITSIZE (mode
) > bitsize
)
6606 /* If the RHS and field are a constant size and the size of the
6607 RHS isn't the same size as the bitfield, we must use bitfield
6610 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6611 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6612 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6613 decl we must use bitfield operations. */
6615 && TREE_CODE (exp
) == MEM_REF
6616 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6617 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6618 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6619 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6624 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6625 implies a mask operation. If the precision is the same size as
6626 the field we're storing into, that mask is redundant. This is
6627 particularly common with bit field assignments generated by the
6629 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6632 tree type
= TREE_TYPE (exp
);
6633 if (INTEGRAL_TYPE_P (type
)
6634 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6635 && bitsize
== TYPE_PRECISION (type
))
6637 tree op
= gimple_assign_rhs1 (nop_def
);
6638 type
= TREE_TYPE (op
);
6639 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6644 temp
= expand_normal (exp
);
6646 /* If BITSIZE is narrower than the size of the type of EXP
6647 we will be narrowing TEMP. Normally, what's wanted are the
6648 low-order bits. However, if EXP's type is a record and this is
6649 big-endian machine, we want the upper BITSIZE bits. */
6650 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6651 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6652 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6653 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6654 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6657 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6658 if (mode
!= VOIDmode
&& mode
!= BLKmode
6659 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6660 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6662 /* If TEMP is not a PARALLEL (see below) and its mode and that of TARGET
6663 are both BLKmode, both must be in memory and BITPOS must be aligned
6664 on a byte boundary. If so, we simply do a block copy. Likewise for
6665 a BLKmode-like TARGET. */
6666 if (GET_CODE (temp
) != PARALLEL
6667 && GET_MODE (temp
) == BLKmode
6668 && (GET_MODE (target
) == BLKmode
6670 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6671 && (bitpos
% BITS_PER_UNIT
) == 0
6672 && (bitsize
% BITS_PER_UNIT
) == 0)))
6674 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6675 && (bitpos
% BITS_PER_UNIT
) == 0);
6677 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6678 emit_block_move (target
, temp
,
6679 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6686 /* Handle calls that return values in multiple non-contiguous locations.
6687 The Irix 6 ABI has examples of this. */
6688 if (GET_CODE (temp
) == PARALLEL
)
6690 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6692 if (mode
== BLKmode
|| mode
== VOIDmode
)
6693 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6694 temp_target
= gen_reg_rtx (mode
);
6695 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6698 else if (mode
== BLKmode
)
6700 /* Handle calls that return BLKmode values in registers. */
6701 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6703 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6704 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6709 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6711 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6712 temp_target
= gen_reg_rtx (mode
);
6714 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6715 temp_target
, mode
, mode
);
6720 /* Store the value in the bitfield. */
6721 store_bit_field (target
, bitsize
, bitpos
,
6722 bitregion_start
, bitregion_end
,
6729 /* Now build a reference to just the desired component. */
6730 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6732 if (to_rtx
== target
)
6733 to_rtx
= copy_rtx (to_rtx
);
6735 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6736 set_mem_alias_set (to_rtx
, alias_set
);
6738 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6742 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6743 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6744 codes and find the ultimate containing object, which we return.
6746 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6747 bit position, and *PUNSIGNEDP to the signedness of the field.
6748 If the position of the field is variable, we store a tree
6749 giving the variable offset (in units) in *POFFSET.
6750 This offset is in addition to the bit position.
6751 If the position is not variable, we store 0 in *POFFSET.
6753 If any of the extraction expressions is volatile,
6754 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6756 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6757 Otherwise, it is a mode that can be used to access the field.
6759 If the field describes a variable-sized object, *PMODE is set to
6760 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6761 this case, but the address of the object can be found.
6763 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6764 look through nodes that serve as markers of a greater alignment than
6765 the one that can be deduced from the expression. These nodes make it
6766 possible for front-ends to prevent temporaries from being created by
6767 the middle-end on alignment considerations. For that purpose, the
6768 normal operating mode at high-level is to always pass FALSE so that
6769 the ultimate containing object is really returned; moreover, the
6770 associated predicate handled_component_p will always return TRUE
6771 on these nodes, thus indicating that they are essentially handled
6772 by get_inner_reference. TRUE should only be passed when the caller
6773 is scanning the expression in order to build another representation
6774 and specifically knows how to handle these nodes; as such, this is
6775 the normal operating mode in the RTL expanders. */
6778 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6779 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6780 machine_mode
*pmode
, int *punsignedp
,
6781 int *pvolatilep
, bool keep_aligning
)
6784 machine_mode mode
= VOIDmode
;
6785 bool blkmode_bitfield
= false;
6786 tree offset
= size_zero_node
;
6787 offset_int bit_offset
= 0;
6789 /* First get the mode, signedness, and size. We do this from just the
6790 outermost expression. */
6792 if (TREE_CODE (exp
) == COMPONENT_REF
)
6794 tree field
= TREE_OPERAND (exp
, 1);
6795 size_tree
= DECL_SIZE (field
);
6796 if (flag_strict_volatile_bitfields
> 0
6797 && TREE_THIS_VOLATILE (exp
)
6798 && DECL_BIT_FIELD_TYPE (field
)
6799 && DECL_MODE (field
) != BLKmode
)
6800 /* Volatile bitfields should be accessed in the mode of the
6801 field's type, not the mode computed based on the bit
6803 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6804 else if (!DECL_BIT_FIELD (field
))
6805 mode
= DECL_MODE (field
);
6806 else if (DECL_MODE (field
) == BLKmode
)
6807 blkmode_bitfield
= true;
6809 *punsignedp
= DECL_UNSIGNED (field
);
6811 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6813 size_tree
= TREE_OPERAND (exp
, 1);
6814 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6815 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6817 /* For vector types, with the correct size of access, use the mode of
6819 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6820 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6821 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6822 mode
= TYPE_MODE (TREE_TYPE (exp
));
6826 mode
= TYPE_MODE (TREE_TYPE (exp
));
6827 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6829 if (mode
== BLKmode
)
6830 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6832 *pbitsize
= GET_MODE_BITSIZE (mode
);
6837 if (! tree_fits_uhwi_p (size_tree
))
6838 mode
= BLKmode
, *pbitsize
= -1;
6840 *pbitsize
= tree_to_uhwi (size_tree
);
6843 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6844 and find the ultimate containing object. */
6847 switch (TREE_CODE (exp
))
6850 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
6855 tree field
= TREE_OPERAND (exp
, 1);
6856 tree this_offset
= component_ref_field_offset (exp
);
6858 /* If this field hasn't been filled in yet, don't go past it.
6859 This should only happen when folding expressions made during
6860 type construction. */
6861 if (this_offset
== 0)
6864 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6865 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
6867 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6872 case ARRAY_RANGE_REF
:
6874 tree index
= TREE_OPERAND (exp
, 1);
6875 tree low_bound
= array_ref_low_bound (exp
);
6876 tree unit_size
= array_ref_element_size (exp
);
6878 /* We assume all arrays have sizes that are a multiple of a byte.
6879 First subtract the lower bound, if any, in the type of the
6880 index, then convert to sizetype and multiply by the size of
6881 the array element. */
6882 if (! integer_zerop (low_bound
))
6883 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6886 offset
= size_binop (PLUS_EXPR
, offset
,
6887 size_binop (MULT_EXPR
,
6888 fold_convert (sizetype
, index
),
6897 bit_offset
+= *pbitsize
;
6900 case VIEW_CONVERT_EXPR
:
6901 if (keep_aligning
&& STRICT_ALIGNMENT
6902 && (TYPE_ALIGN (TREE_TYPE (exp
))
6903 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6904 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6905 < BIGGEST_ALIGNMENT
)
6906 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6907 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6912 /* Hand back the decl for MEM[&decl, off]. */
6913 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6915 tree off
= TREE_OPERAND (exp
, 1);
6916 if (!integer_zerop (off
))
6918 offset_int boff
, coff
= mem_ref_offset (exp
);
6919 boff
= wi::lshift (coff
, LOG2_BITS_PER_UNIT
);
6922 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6930 /* If any reference in the chain is volatile, the effect is volatile. */
6931 if (TREE_THIS_VOLATILE (exp
))
6934 exp
= TREE_OPERAND (exp
, 0);
6938 /* If OFFSET is constant, see if we can return the whole thing as a
6939 constant bit position. Make sure to handle overflow during
6941 if (TREE_CODE (offset
) == INTEGER_CST
)
6943 offset_int tem
= wi::sext (wi::to_offset (offset
),
6944 TYPE_PRECISION (sizetype
));
6945 tem
= wi::lshift (tem
, LOG2_BITS_PER_UNIT
);
6947 if (wi::fits_shwi_p (tem
))
6949 *pbitpos
= tem
.to_shwi ();
6950 *poffset
= offset
= NULL_TREE
;
6954 /* Otherwise, split it up. */
6957 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6958 if (wi::neg_p (bit_offset
) || !wi::fits_shwi_p (bit_offset
))
6960 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
6961 offset_int tem
= bit_offset
.and_not (mask
);
6962 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6963 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6965 tem
= wi::arshift (tem
, LOG2_BITS_PER_UNIT
);
6966 offset
= size_binop (PLUS_EXPR
, offset
,
6967 wide_int_to_tree (sizetype
, tem
));
6970 *pbitpos
= bit_offset
.to_shwi ();
6974 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6975 if (mode
== VOIDmode
6977 && (*pbitpos
% BITS_PER_UNIT
) == 0
6978 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6986 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6988 static unsigned HOST_WIDE_INT
6989 target_align (const_tree target
)
6991 /* We might have a chain of nested references with intermediate misaligning
6992 bitfields components, so need to recurse to find out. */
6994 unsigned HOST_WIDE_INT this_align
, outer_align
;
6996 switch (TREE_CODE (target
))
7002 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7003 outer_align
= target_align (TREE_OPERAND (target
, 0));
7004 return MIN (this_align
, outer_align
);
7007 case ARRAY_RANGE_REF
:
7008 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7009 outer_align
= target_align (TREE_OPERAND (target
, 0));
7010 return MIN (this_align
, outer_align
);
7013 case NON_LVALUE_EXPR
:
7014 case VIEW_CONVERT_EXPR
:
7015 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7016 outer_align
= target_align (TREE_OPERAND (target
, 0));
7017 return MAX (this_align
, outer_align
);
7020 return TYPE_ALIGN (TREE_TYPE (target
));
7025 /* Given an rtx VALUE that may contain additions and multiplications, return
7026 an equivalent value that just refers to a register, memory, or constant.
7027 This is done by generating instructions to perform the arithmetic and
7028 returning a pseudo-register containing the value.
7030 The returned value may be a REG, SUBREG, MEM or constant. */
7033 force_operand (rtx value
, rtx target
)
7036 /* Use subtarget as the target for operand 0 of a binary operation. */
7037 rtx subtarget
= get_subtarget (target
);
7038 enum rtx_code code
= GET_CODE (value
);
7040 /* Check for subreg applied to an expression produced by loop optimizer. */
7042 && !REG_P (SUBREG_REG (value
))
7043 && !MEM_P (SUBREG_REG (value
)))
7046 = simplify_gen_subreg (GET_MODE (value
),
7047 force_reg (GET_MODE (SUBREG_REG (value
)),
7048 force_operand (SUBREG_REG (value
),
7050 GET_MODE (SUBREG_REG (value
)),
7051 SUBREG_BYTE (value
));
7052 code
= GET_CODE (value
);
7055 /* Check for a PIC address load. */
7056 if ((code
== PLUS
|| code
== MINUS
)
7057 && XEXP (value
, 0) == pic_offset_table_rtx
7058 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7059 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7060 || GET_CODE (XEXP (value
, 1)) == CONST
))
7063 subtarget
= gen_reg_rtx (GET_MODE (value
));
7064 emit_move_insn (subtarget
, value
);
7068 if (ARITHMETIC_P (value
))
7070 op2
= XEXP (value
, 1);
7071 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7073 if (code
== MINUS
&& CONST_INT_P (op2
))
7076 op2
= negate_rtx (GET_MODE (value
), op2
);
7079 /* Check for an addition with OP2 a constant integer and our first
7080 operand a PLUS of a virtual register and something else. In that
7081 case, we want to emit the sum of the virtual register and the
7082 constant first and then add the other value. This allows virtual
7083 register instantiation to simply modify the constant rather than
7084 creating another one around this addition. */
7085 if (code
== PLUS
&& CONST_INT_P (op2
)
7086 && GET_CODE (XEXP (value
, 0)) == PLUS
7087 && REG_P (XEXP (XEXP (value
, 0), 0))
7088 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7089 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7091 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7092 XEXP (XEXP (value
, 0), 0), op2
,
7093 subtarget
, 0, OPTAB_LIB_WIDEN
);
7094 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7095 force_operand (XEXP (XEXP (value
,
7097 target
, 0, OPTAB_LIB_WIDEN
);
7100 op1
= force_operand (XEXP (value
, 0), subtarget
);
7101 op2
= force_operand (op2
, NULL_RTX
);
7105 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7107 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7108 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7109 target
, 1, OPTAB_LIB_WIDEN
);
7111 return expand_divmod (0,
7112 FLOAT_MODE_P (GET_MODE (value
))
7113 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7114 GET_MODE (value
), op1
, op2
, target
, 0);
7116 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7119 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7122 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7125 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7126 target
, 0, OPTAB_LIB_WIDEN
);
7128 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7129 target
, 1, OPTAB_LIB_WIDEN
);
7132 if (UNARY_P (value
))
7135 target
= gen_reg_rtx (GET_MODE (value
));
7136 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7143 case FLOAT_TRUNCATE
:
7144 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7149 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7153 case UNSIGNED_FLOAT
:
7154 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7158 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7162 #ifdef INSN_SCHEDULING
7163 /* On machines that have insn scheduling, we want all memory reference to be
7164 explicit, so we need to deal with such paradoxical SUBREGs. */
7165 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7167 = simplify_gen_subreg (GET_MODE (value
),
7168 force_reg (GET_MODE (SUBREG_REG (value
)),
7169 force_operand (SUBREG_REG (value
),
7171 GET_MODE (SUBREG_REG (value
)),
7172 SUBREG_BYTE (value
));
7178 /* Subroutine of expand_expr: return nonzero iff there is no way that
7179 EXP can reference X, which is being modified. TOP_P is nonzero if this
7180 call is going to be used to determine whether we need a temporary
7181 for EXP, as opposed to a recursive call to this function.
7183 It is always safe for this routine to return zero since it merely
7184 searches for optimization opportunities. */
7187 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7193 /* If EXP has varying size, we MUST use a target since we currently
7194 have no way of allocating temporaries of variable size
7195 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7196 So we assume here that something at a higher level has prevented a
7197 clash. This is somewhat bogus, but the best we can do. Only
7198 do this when X is BLKmode and when we are at the top level. */
7199 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7200 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7201 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7202 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7203 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7205 && GET_MODE (x
) == BLKmode
)
7206 /* If X is in the outgoing argument area, it is always safe. */
7208 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7209 || (GET_CODE (XEXP (x
, 0)) == PLUS
7210 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7213 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7214 find the underlying pseudo. */
7215 if (GET_CODE (x
) == SUBREG
)
7218 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7222 /* Now look at our tree code and possibly recurse. */
7223 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7225 case tcc_declaration
:
7226 exp_rtl
= DECL_RTL_IF_SET (exp
);
7232 case tcc_exceptional
:
7233 if (TREE_CODE (exp
) == TREE_LIST
)
7237 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7239 exp
= TREE_CHAIN (exp
);
7242 if (TREE_CODE (exp
) != TREE_LIST
)
7243 return safe_from_p (x
, exp
, 0);
7246 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7248 constructor_elt
*ce
;
7249 unsigned HOST_WIDE_INT idx
;
7251 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7252 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7253 || !safe_from_p (x
, ce
->value
, 0))
7257 else if (TREE_CODE (exp
) == ERROR_MARK
)
7258 return 1; /* An already-visited SAVE_EXPR? */
7263 /* The only case we look at here is the DECL_INITIAL inside a
7265 return (TREE_CODE (exp
) != DECL_EXPR
7266 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7267 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7268 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7271 case tcc_comparison
:
7272 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7277 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7279 case tcc_expression
:
7282 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7283 the expression. If it is set, we conflict iff we are that rtx or
7284 both are in memory. Otherwise, we check all operands of the
7285 expression recursively. */
7287 switch (TREE_CODE (exp
))
7290 /* If the operand is static or we are static, we can't conflict.
7291 Likewise if we don't conflict with the operand at all. */
7292 if (staticp (TREE_OPERAND (exp
, 0))
7293 || TREE_STATIC (exp
)
7294 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7297 /* Otherwise, the only way this can conflict is if we are taking
7298 the address of a DECL a that address if part of X, which is
7300 exp
= TREE_OPERAND (exp
, 0);
7303 if (!DECL_RTL_SET_P (exp
)
7304 || !MEM_P (DECL_RTL (exp
)))
7307 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7313 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7314 get_alias_set (exp
)))
7319 /* Assume that the call will clobber all hard registers and
7321 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7326 case WITH_CLEANUP_EXPR
:
7327 case CLEANUP_POINT_EXPR
:
7328 /* Lowered by gimplify.c. */
7332 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7338 /* If we have an rtx, we do not need to scan our operands. */
7342 nops
= TREE_OPERAND_LENGTH (exp
);
7343 for (i
= 0; i
< nops
; i
++)
7344 if (TREE_OPERAND (exp
, i
) != 0
7345 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7351 /* Should never get a type here. */
7355 /* If we have an rtl, find any enclosed object. Then see if we conflict
7359 if (GET_CODE (exp_rtl
) == SUBREG
)
7361 exp_rtl
= SUBREG_REG (exp_rtl
);
7363 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7367 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7368 are memory and they conflict. */
7369 return ! (rtx_equal_p (x
, exp_rtl
)
7370 || (MEM_P (x
) && MEM_P (exp_rtl
)
7371 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7374 /* If we reach here, it is safe. */
7379 /* Return the highest power of two that EXP is known to be a multiple of.
7380 This is used in updating alignment of MEMs in array references. */
7382 unsigned HOST_WIDE_INT
7383 highest_pow2_factor (const_tree exp
)
7385 unsigned HOST_WIDE_INT ret
;
7386 int trailing_zeros
= tree_ctz (exp
);
7387 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7388 return BIGGEST_ALIGNMENT
;
7389 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7390 if (ret
> BIGGEST_ALIGNMENT
)
7391 return BIGGEST_ALIGNMENT
;
7395 /* Similar, except that the alignment requirements of TARGET are
7396 taken into account. Assume it is at least as aligned as its
7397 type, unless it is a COMPONENT_REF in which case the layout of
7398 the structure gives the alignment. */
7400 static unsigned HOST_WIDE_INT
7401 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7403 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7404 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7406 return MAX (factor
, talign
);
7409 /* Convert the tree comparison code TCODE to the rtl one where the
7410 signedness is UNSIGNEDP. */
7412 static enum rtx_code
7413 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7425 code
= unsignedp
? LTU
: LT
;
7428 code
= unsignedp
? LEU
: LE
;
7431 code
= unsignedp
? GTU
: GT
;
7434 code
= unsignedp
? GEU
: GE
;
7436 case UNORDERED_EXPR
:
7467 /* Subroutine of expand_expr. Expand the two operands of a binary
7468 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7469 The value may be stored in TARGET if TARGET is nonzero. The
7470 MODIFIER argument is as documented by expand_expr. */
7473 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7474 enum expand_modifier modifier
)
7476 if (! safe_from_p (target
, exp1
, 1))
7478 if (operand_equal_p (exp0
, exp1
, 0))
7480 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7481 *op1
= copy_rtx (*op0
);
7485 /* If we need to preserve evaluation order, copy exp0 into its own
7486 temporary variable so that it can't be clobbered by exp1. */
7487 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7488 exp0
= save_expr (exp0
);
7489 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7490 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7495 /* Return a MEM that contains constant EXP. DEFER is as for
7496 output_constant_def and MODIFIER is as for expand_expr. */
7499 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7503 mem
= output_constant_def (exp
, defer
);
7504 if (modifier
!= EXPAND_INITIALIZER
)
7505 mem
= use_anchored_address (mem
);
7509 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7510 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7513 expand_expr_addr_expr_1 (tree exp
, rtx target
, machine_mode tmode
,
7514 enum expand_modifier modifier
, addr_space_t as
)
7516 rtx result
, subtarget
;
7518 HOST_WIDE_INT bitsize
, bitpos
;
7519 int volatilep
, unsignedp
;
7522 /* If we are taking the address of a constant and are at the top level,
7523 we have to use output_constant_def since we can't call force_const_mem
7525 /* ??? This should be considered a front-end bug. We should not be
7526 generating ADDR_EXPR of something that isn't an LVALUE. The only
7527 exception here is STRING_CST. */
7528 if (CONSTANT_CLASS_P (exp
))
7530 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7531 if (modifier
< EXPAND_SUM
)
7532 result
= force_operand (result
, target
);
7536 /* Everything must be something allowed by is_gimple_addressable. */
7537 switch (TREE_CODE (exp
))
7540 /* This case will happen via recursion for &a->b. */
7541 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7545 tree tem
= TREE_OPERAND (exp
, 0);
7546 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7547 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7548 return expand_expr (tem
, target
, tmode
, modifier
);
7552 /* Expand the initializer like constants above. */
7553 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7555 if (modifier
< EXPAND_SUM
)
7556 result
= force_operand (result
, target
);
7560 /* The real part of the complex number is always first, therefore
7561 the address is the same as the address of the parent object. */
7564 inner
= TREE_OPERAND (exp
, 0);
7568 /* The imaginary part of the complex number is always second.
7569 The expression is therefore always offset by the size of the
7572 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7573 inner
= TREE_OPERAND (exp
, 0);
7576 case COMPOUND_LITERAL_EXPR
:
7577 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
7578 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
7579 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
7580 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
7581 the initializers aren't gimplified. */
7582 if (COMPOUND_LITERAL_EXPR_DECL (exp
)
7583 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp
)))
7584 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7585 target
, tmode
, modifier
, as
);
7588 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7589 expand_expr, as that can have various side effects; LABEL_DECLs for
7590 example, may not have their DECL_RTL set yet. Expand the rtl of
7591 CONSTRUCTORs too, which should yield a memory reference for the
7592 constructor's contents. Assume language specific tree nodes can
7593 be expanded in some interesting way. */
7594 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7596 || TREE_CODE (exp
) == CONSTRUCTOR
7597 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7599 result
= expand_expr (exp
, target
, tmode
,
7600 modifier
== EXPAND_INITIALIZER
7601 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7603 /* If the DECL isn't in memory, then the DECL wasn't properly
7604 marked TREE_ADDRESSABLE, which will be either a front-end
7605 or a tree optimizer bug. */
7607 gcc_assert (MEM_P (result
));
7608 result
= XEXP (result
, 0);
7610 /* ??? Is this needed anymore? */
7612 TREE_USED (exp
) = 1;
7614 if (modifier
!= EXPAND_INITIALIZER
7615 && modifier
!= EXPAND_CONST_ADDRESS
7616 && modifier
!= EXPAND_SUM
)
7617 result
= force_operand (result
, target
);
7621 /* Pass FALSE as the last argument to get_inner_reference although
7622 we are expanding to RTL. The rationale is that we know how to
7623 handle "aligning nodes" here: we can just bypass them because
7624 they won't change the final object whose address will be returned
7625 (they actually exist only for that purpose). */
7626 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7627 &mode1
, &unsignedp
, &volatilep
, false);
7631 /* We must have made progress. */
7632 gcc_assert (inner
!= exp
);
7634 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7635 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7636 inner alignment, force the inner to be sufficiently aligned. */
7637 if (CONSTANT_CLASS_P (inner
)
7638 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7640 inner
= copy_node (inner
);
7641 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7642 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7643 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7645 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7651 if (modifier
!= EXPAND_NORMAL
)
7652 result
= force_operand (result
, NULL
);
7653 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7654 modifier
== EXPAND_INITIALIZER
7655 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7657 /* expand_expr is allowed to return an object in a mode other
7658 than TMODE. If it did, we need to convert. */
7659 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7660 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7661 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7662 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7663 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7665 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7666 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7669 subtarget
= bitpos
? NULL_RTX
: target
;
7670 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7671 1, OPTAB_LIB_WIDEN
);
7677 /* Someone beforehand should have rejected taking the address
7678 of such an object. */
7679 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7681 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7682 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7683 if (modifier
< EXPAND_SUM
)
7684 result
= force_operand (result
, target
);
7690 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7691 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7694 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
7695 enum expand_modifier modifier
)
7697 addr_space_t as
= ADDR_SPACE_GENERIC
;
7698 machine_mode address_mode
= Pmode
;
7699 machine_mode pointer_mode
= ptr_mode
;
7703 /* Target mode of VOIDmode says "whatever's natural". */
7704 if (tmode
== VOIDmode
)
7705 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7707 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7709 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7710 address_mode
= targetm
.addr_space
.address_mode (as
);
7711 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7714 /* We can get called with some Weird Things if the user does silliness
7715 like "(short) &a". In that case, convert_memory_address won't do
7716 the right thing, so ignore the given target mode. */
7717 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7718 tmode
= address_mode
;
7720 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7721 tmode
, modifier
, as
);
7723 /* Despite expand_expr claims concerning ignoring TMODE when not
7724 strictly convenient, stuff breaks if we don't honor it. Note
7725 that combined with the above, we only do this for pointer modes. */
7726 rmode
= GET_MODE (result
);
7727 if (rmode
== VOIDmode
)
7730 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7735 /* Generate code for computing CONSTRUCTOR EXP.
7736 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7737 is TRUE, instead of creating a temporary variable in memory
7738 NULL is returned and the caller needs to handle it differently. */
7741 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7742 bool avoid_temp_mem
)
7744 tree type
= TREE_TYPE (exp
);
7745 machine_mode mode
= TYPE_MODE (type
);
7747 /* Try to avoid creating a temporary at all. This is possible
7748 if all of the initializer is zero.
7749 FIXME: try to handle all [0..255] initializers we can handle
7751 if (TREE_STATIC (exp
)
7752 && !TREE_ADDRESSABLE (exp
)
7753 && target
!= 0 && mode
== BLKmode
7754 && all_zeros_p (exp
))
7756 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7760 /* All elts simple constants => refer to a constant in memory. But
7761 if this is a non-BLKmode mode, let it store a field at a time
7762 since that should make a CONST_INT, CONST_WIDE_INT or
7763 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7764 use, it is best to store directly into the target unless the type
7765 is large enough that memcpy will be used. If we are making an
7766 initializer and all operands are constant, put it in memory as
7769 FIXME: Avoid trying to fill vector constructors piece-meal.
7770 Output them with output_constant_def below unless we're sure
7771 they're zeros. This should go away when vector initializers
7772 are treated like VECTOR_CST instead of arrays. */
7773 if ((TREE_STATIC (exp
)
7774 && ((mode
== BLKmode
7775 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7776 || TREE_ADDRESSABLE (exp
)
7777 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7778 && (! can_move_by_pieces
7779 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7781 && ! mostly_zeros_p (exp
))))
7782 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7783 && TREE_CONSTANT (exp
)))
7790 constructor
= expand_expr_constant (exp
, 1, modifier
);
7792 if (modifier
!= EXPAND_CONST_ADDRESS
7793 && modifier
!= EXPAND_INITIALIZER
7794 && modifier
!= EXPAND_SUM
)
7795 constructor
= validize_mem (constructor
);
7800 /* Handle calls that pass values in multiple non-contiguous
7801 locations. The Irix 6 ABI has examples of this. */
7802 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7803 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7808 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7811 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7816 /* expand_expr: generate code for computing expression EXP.
7817 An rtx for the computed value is returned. The value is never null.
7818 In the case of a void EXP, const0_rtx is returned.
7820 The value may be stored in TARGET if TARGET is nonzero.
7821 TARGET is just a suggestion; callers must assume that
7822 the rtx returned may not be the same as TARGET.
7824 If TARGET is CONST0_RTX, it means that the value will be ignored.
7826 If TMODE is not VOIDmode, it suggests generating the
7827 result in mode TMODE. But this is done only when convenient.
7828 Otherwise, TMODE is ignored and the value generated in its natural mode.
7829 TMODE is just a suggestion; callers must assume that
7830 the rtx returned may not have mode TMODE.
7832 Note that TARGET may have neither TMODE nor MODE. In that case, it
7833 probably will not be used.
7835 If MODIFIER is EXPAND_SUM then when EXP is an addition
7836 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7837 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7838 products as above, or REG or MEM, or constant.
7839 Ordinarily in such cases we would output mul or add instructions
7840 and then return a pseudo reg containing the sum.
7842 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7843 it also marks a label as absolutely required (it can't be dead).
7844 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7845 This is used for outputting expressions used in initializers.
7847 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7848 with a constant address even if that address is not normally legitimate.
7849 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7851 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7852 a call parameter. Such targets require special care as we haven't yet
7853 marked TARGET so that it's safe from being trashed by libcalls. We
7854 don't want to use TARGET for anything but the final result;
7855 Intermediate values must go elsewhere. Additionally, calls to
7856 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7858 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7859 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7860 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7861 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7864 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7865 In this case, we don't adjust a returned MEM rtx that wouldn't be
7866 sufficiently aligned for its mode; instead, it's up to the caller
7867 to deal with it afterwards. This is used to make sure that unaligned
7868 base objects for which out-of-bounds accesses are supported, for
7869 example record types with trailing arrays, aren't realigned behind
7870 the back of the caller.
7871 The normal operating mode is to pass FALSE for this parameter. */
7874 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
7875 enum expand_modifier modifier
, rtx
*alt_rtl
,
7876 bool inner_reference_p
)
7880 /* Handle ERROR_MARK before anybody tries to access its type. */
7881 if (TREE_CODE (exp
) == ERROR_MARK
7882 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7884 ret
= CONST0_RTX (tmode
);
7885 return ret
? ret
: const0_rtx
;
7888 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
7893 /* Try to expand the conditional expression which is represented by
7894 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
7895 return the rtl reg which represents the result. Otherwise return
7899 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7900 tree treeop1 ATTRIBUTE_UNUSED
,
7901 tree treeop2 ATTRIBUTE_UNUSED
)
7904 rtx op00
, op01
, op1
, op2
;
7905 enum rtx_code comparison_code
;
7906 machine_mode comparison_mode
;
7909 tree type
= TREE_TYPE (treeop1
);
7910 int unsignedp
= TYPE_UNSIGNED (type
);
7911 machine_mode mode
= TYPE_MODE (type
);
7912 machine_mode orig_mode
= mode
;
7914 /* If we cannot do a conditional move on the mode, try doing it
7915 with the promoted mode. */
7916 if (!can_conditionally_move_p (mode
))
7918 mode
= promote_mode (type
, mode
, &unsignedp
);
7919 if (!can_conditionally_move_p (mode
))
7921 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7924 temp
= assign_temp (type
, 0, 1);
7927 expand_operands (treeop1
, treeop2
,
7928 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7930 if (TREE_CODE (treeop0
) == SSA_NAME
7931 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7933 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7934 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7935 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7936 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7937 comparison_mode
= TYPE_MODE (type
);
7938 unsignedp
= TYPE_UNSIGNED (type
);
7939 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7941 else if (COMPARISON_CLASS_P (treeop0
))
7943 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7944 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7945 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7946 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7947 unsignedp
= TYPE_UNSIGNED (type
);
7948 comparison_mode
= TYPE_MODE (type
);
7949 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7953 op00
= expand_normal (treeop0
);
7955 comparison_code
= NE
;
7956 comparison_mode
= GET_MODE (op00
);
7957 if (comparison_mode
== VOIDmode
)
7958 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7961 if (GET_MODE (op1
) != mode
)
7962 op1
= gen_lowpart (mode
, op1
);
7964 if (GET_MODE (op2
) != mode
)
7965 op2
= gen_lowpart (mode
, op2
);
7967 /* Try to emit the conditional move. */
7968 insn
= emit_conditional_move (temp
, comparison_code
,
7969 op00
, op01
, comparison_mode
,
7973 /* If we could do the conditional move, emit the sequence,
7977 rtx_insn
*seq
= get_insns ();
7980 return convert_modes (orig_mode
, mode
, temp
, 0);
7983 /* Otherwise discard the sequence and fall back to code with
7990 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
7991 enum expand_modifier modifier
)
7993 rtx op0
, op1
, op2
, temp
;
7994 rtx_code_label
*lab
;
7998 enum tree_code code
= ops
->code
;
8000 rtx subtarget
, original_target
;
8002 bool reduce_bit_field
;
8003 location_t loc
= ops
->location
;
8004 tree treeop0
, treeop1
, treeop2
;
8005 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8006 ? reduce_to_bit_field_precision ((expr), \
8012 mode
= TYPE_MODE (type
);
8013 unsignedp
= TYPE_UNSIGNED (type
);
8019 /* We should be called only on simple (binary or unary) expressions,
8020 exactly those that are valid in gimple expressions that aren't
8021 GIMPLE_SINGLE_RHS (or invalid). */
8022 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8023 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8024 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8026 ignore
= (target
== const0_rtx
8027 || ((CONVERT_EXPR_CODE_P (code
)
8028 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8029 && TREE_CODE (type
) == VOID_TYPE
));
8031 /* We should be called only if we need the result. */
8032 gcc_assert (!ignore
);
8034 /* An operation in what may be a bit-field type needs the
8035 result to be reduced to the precision of the bit-field type,
8036 which is narrower than that of the type's mode. */
8037 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8038 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8040 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8043 /* Use subtarget as the target for operand 0 of a binary operation. */
8044 subtarget
= get_subtarget (target
);
8045 original_target
= target
;
8049 case NON_LVALUE_EXPR
:
8052 if (treeop0
== error_mark_node
)
8055 if (TREE_CODE (type
) == UNION_TYPE
)
8057 tree valtype
= TREE_TYPE (treeop0
);
8059 /* If both input and output are BLKmode, this conversion isn't doing
8060 anything except possibly changing memory attribute. */
8061 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8063 rtx result
= expand_expr (treeop0
, target
, tmode
,
8066 result
= copy_rtx (result
);
8067 set_mem_attributes (result
, type
, 0);
8073 if (TYPE_MODE (type
) != BLKmode
)
8074 target
= gen_reg_rtx (TYPE_MODE (type
));
8076 target
= assign_temp (type
, 1, 1);
8080 /* Store data into beginning of memory target. */
8081 store_expr (treeop0
,
8082 adjust_address (target
, TYPE_MODE (valtype
), 0),
8083 modifier
== EXPAND_STACK_PARM
,
8088 gcc_assert (REG_P (target
));
8090 /* Store this field into a union of the proper type. */
8091 store_field (target
,
8092 MIN ((int_size_in_bytes (TREE_TYPE
8095 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8096 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8099 /* Return the entire union. */
8103 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8105 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8108 /* If the signedness of the conversion differs and OP0 is
8109 a promoted SUBREG, clear that indication since we now
8110 have to do the proper extension. */
8111 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8112 && GET_CODE (op0
) == SUBREG
)
8113 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8115 return REDUCE_BIT_FIELD (op0
);
8118 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8119 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8120 if (GET_MODE (op0
) == mode
)
8123 /* If OP0 is a constant, just convert it into the proper mode. */
8124 else if (CONSTANT_P (op0
))
8126 tree inner_type
= TREE_TYPE (treeop0
);
8127 machine_mode inner_mode
= GET_MODE (op0
);
8129 if (inner_mode
== VOIDmode
)
8130 inner_mode
= TYPE_MODE (inner_type
);
8132 if (modifier
== EXPAND_INITIALIZER
)
8133 op0
= lowpart_subreg (mode
, op0
, inner_mode
);
8135 op0
= convert_modes (mode
, inner_mode
, op0
,
8136 TYPE_UNSIGNED (inner_type
));
8139 else if (modifier
== EXPAND_INITIALIZER
)
8140 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8142 else if (target
== 0)
8143 op0
= convert_to_mode (mode
, op0
,
8144 TYPE_UNSIGNED (TREE_TYPE
8148 convert_move (target
, op0
,
8149 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8153 return REDUCE_BIT_FIELD (op0
);
8155 case ADDR_SPACE_CONVERT_EXPR
:
8157 tree treeop0_type
= TREE_TYPE (treeop0
);
8159 addr_space_t as_from
;
8161 gcc_assert (POINTER_TYPE_P (type
));
8162 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8164 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8165 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8167 /* Conversions between pointers to the same address space should
8168 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8169 gcc_assert (as_to
!= as_from
);
8171 /* Ask target code to handle conversion between pointers
8172 to overlapping address spaces. */
8173 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8174 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8176 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8177 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8182 /* For disjoint address spaces, converting anything but
8183 a null pointer invokes undefined behaviour. We simply
8184 always return a null pointer here. */
8185 return CONST0_RTX (mode
);
8188 case POINTER_PLUS_EXPR
:
8189 /* Even though the sizetype mode and the pointer's mode can be different
8190 expand is able to handle this correctly and get the correct result out
8191 of the PLUS_EXPR code. */
8192 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8193 if sizetype precision is smaller than pointer precision. */
8194 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8195 treeop1
= fold_convert_loc (loc
, type
,
8196 fold_convert_loc (loc
, ssizetype
,
8198 /* If sizetype precision is larger than pointer precision, truncate the
8199 offset to have matching modes. */
8200 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8201 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8204 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8205 something else, make sure we add the register to the constant and
8206 then to the other thing. This case can occur during strength
8207 reduction and doing it this way will produce better code if the
8208 frame pointer or argument pointer is eliminated.
8210 fold-const.c will ensure that the constant is always in the inner
8211 PLUS_EXPR, so the only case we need to do anything about is if
8212 sp, ap, or fp is our second argument, in which case we must swap
8213 the innermost first argument and our second argument. */
8215 if (TREE_CODE (treeop0
) == PLUS_EXPR
8216 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8217 && TREE_CODE (treeop1
) == VAR_DECL
8218 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8219 || DECL_RTL (treeop1
) == stack_pointer_rtx
8220 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8225 /* If the result is to be ptr_mode and we are adding an integer to
8226 something, we might be forming a constant. So try to use
8227 plus_constant. If it produces a sum and we can't accept it,
8228 use force_operand. This allows P = &ARR[const] to generate
8229 efficient code on machines where a SYMBOL_REF is not a valid
8232 If this is an EXPAND_SUM call, always return the sum. */
8233 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8234 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8236 if (modifier
== EXPAND_STACK_PARM
)
8238 if (TREE_CODE (treeop0
) == INTEGER_CST
8239 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8240 && TREE_CONSTANT (treeop1
))
8244 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
8246 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8248 /* Use wi::shwi to ensure that the constant is
8249 truncated according to the mode of OP1, then sign extended
8250 to a HOST_WIDE_INT. Using the constant directly can result
8251 in non-canonical RTL in a 64x32 cross compile. */
8252 wc
= TREE_INT_CST_LOW (treeop0
);
8254 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8255 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8256 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8257 op1
= force_operand (op1
, target
);
8258 return REDUCE_BIT_FIELD (op1
);
8261 else if (TREE_CODE (treeop1
) == INTEGER_CST
8262 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8263 && TREE_CONSTANT (treeop0
))
8267 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
8269 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8270 (modifier
== EXPAND_INITIALIZER
8271 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8272 if (! CONSTANT_P (op0
))
8274 op1
= expand_expr (treeop1
, NULL_RTX
,
8275 VOIDmode
, modifier
);
8276 /* Return a PLUS if modifier says it's OK. */
8277 if (modifier
== EXPAND_SUM
8278 || modifier
== EXPAND_INITIALIZER
)
8279 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8282 /* Use wi::shwi to ensure that the constant is
8283 truncated according to the mode of OP1, then sign extended
8284 to a HOST_WIDE_INT. Using the constant directly can result
8285 in non-canonical RTL in a 64x32 cross compile. */
8286 wc
= TREE_INT_CST_LOW (treeop1
);
8288 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8289 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8290 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8291 op0
= force_operand (op0
, target
);
8292 return REDUCE_BIT_FIELD (op0
);
8296 /* Use TER to expand pointer addition of a negated value
8297 as pointer subtraction. */
8298 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8299 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8300 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8301 && TREE_CODE (treeop1
) == SSA_NAME
8302 && TYPE_MODE (TREE_TYPE (treeop0
))
8303 == TYPE_MODE (TREE_TYPE (treeop1
)))
8305 gimple
*def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8308 treeop1
= gimple_assign_rhs1 (def
);
8314 /* No sense saving up arithmetic to be done
8315 if it's all in the wrong mode to form part of an address.
8316 And force_operand won't know whether to sign-extend or
8318 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8319 || mode
!= ptr_mode
)
8321 expand_operands (treeop0
, treeop1
,
8322 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8323 if (op0
== const0_rtx
)
8325 if (op1
== const0_rtx
)
8330 expand_operands (treeop0
, treeop1
,
8331 subtarget
, &op0
, &op1
, modifier
);
8332 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8336 /* For initializers, we are allowed to return a MINUS of two
8337 symbolic constants. Here we handle all cases when both operands
8339 /* Handle difference of two symbolic constants,
8340 for the sake of an initializer. */
8341 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8342 && really_constant_p (treeop0
)
8343 && really_constant_p (treeop1
))
8345 expand_operands (treeop0
, treeop1
,
8346 NULL_RTX
, &op0
, &op1
, modifier
);
8348 /* If the last operand is a CONST_INT, use plus_constant of
8349 the negated constant. Else make the MINUS. */
8350 if (CONST_INT_P (op1
))
8351 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8354 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8357 /* No sense saving up arithmetic to be done
8358 if it's all in the wrong mode to form part of an address.
8359 And force_operand won't know whether to sign-extend or
8361 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8362 || mode
!= ptr_mode
)
8365 expand_operands (treeop0
, treeop1
,
8366 subtarget
, &op0
, &op1
, modifier
);
8368 /* Convert A - const to A + (-const). */
8369 if (CONST_INT_P (op1
))
8371 op1
= negate_rtx (mode
, op1
);
8372 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8377 case WIDEN_MULT_PLUS_EXPR
:
8378 case WIDEN_MULT_MINUS_EXPR
:
8379 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8380 op2
= expand_normal (treeop2
);
8381 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8385 case WIDEN_MULT_EXPR
:
8386 /* If first operand is constant, swap them.
8387 Thus the following special case checks need only
8388 check the second operand. */
8389 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8390 std::swap (treeop0
, treeop1
);
8392 /* First, check if we have a multiplication of one signed and one
8393 unsigned operand. */
8394 if (TREE_CODE (treeop1
) != INTEGER_CST
8395 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8396 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8398 machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8399 this_optab
= usmul_widen_optab
;
8400 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8401 != CODE_FOR_nothing
)
8403 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8404 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8407 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8409 /* op0 and op1 might still be constant, despite the above
8410 != INTEGER_CST check. Handle it. */
8411 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8413 op0
= convert_modes (innermode
, mode
, op0
, true);
8414 op1
= convert_modes (innermode
, mode
, op1
, false);
8415 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8416 target
, unsignedp
));
8421 /* Check for a multiplication with matching signedness. */
8422 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8423 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8424 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8425 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8427 tree op0type
= TREE_TYPE (treeop0
);
8428 machine_mode innermode
= TYPE_MODE (op0type
);
8429 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8430 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8431 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8433 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8435 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8436 != CODE_FOR_nothing
)
8438 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8440 /* op0 and op1 might still be constant, despite the above
8441 != INTEGER_CST check. Handle it. */
8442 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8445 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8447 = convert_modes (innermode
, mode
, op1
,
8448 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8449 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8453 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8454 unsignedp
, this_optab
);
8455 return REDUCE_BIT_FIELD (temp
);
8457 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8459 && innermode
== word_mode
)
8462 op0
= expand_normal (treeop0
);
8463 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8464 op1
= convert_modes (innermode
, mode
,
8465 expand_normal (treeop1
),
8466 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8468 op1
= expand_normal (treeop1
);
8469 /* op0 and op1 might still be constant, despite the above
8470 != INTEGER_CST check. Handle it. */
8471 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8472 goto widen_mult_const
;
8473 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8474 unsignedp
, OPTAB_LIB_WIDEN
);
8475 hipart
= gen_highpart (innermode
, temp
);
8476 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8480 emit_move_insn (hipart
, htem
);
8481 return REDUCE_BIT_FIELD (temp
);
8485 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8486 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8487 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8488 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8492 optab opt
= fma_optab
;
8493 gimple
*def0
, *def2
;
8495 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8497 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8499 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8502 gcc_assert (fn
!= NULL_TREE
);
8503 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8504 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8507 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8508 /* The multiplication is commutative - look at its 2nd operand
8509 if the first isn't fed by a negate. */
8512 def0
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8513 /* Swap operands if the 2nd operand is fed by a negate. */
8515 std::swap (treeop0
, treeop1
);
8517 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8522 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8525 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8526 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8529 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8532 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8535 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8538 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8542 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8544 op2
= expand_normal (treeop2
);
8545 op1
= expand_normal (treeop1
);
8547 return expand_ternary_op (TYPE_MODE (type
), opt
,
8548 op0
, op1
, op2
, target
, 0);
8552 /* If this is a fixed-point operation, then we cannot use the code
8553 below because "expand_mult" doesn't support sat/no-sat fixed-point
8555 if (ALL_FIXED_POINT_MODE_P (mode
))
8558 /* If first operand is constant, swap them.
8559 Thus the following special case checks need only
8560 check the second operand. */
8561 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8562 std::swap (treeop0
, treeop1
);
8564 /* Attempt to return something suitable for generating an
8565 indexed address, for machines that support that. */
8567 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8568 && tree_fits_shwi_p (treeop1
))
8570 tree exp1
= treeop1
;
8572 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8576 op0
= force_operand (op0
, NULL_RTX
);
8578 op0
= copy_to_mode_reg (mode
, op0
);
8580 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8581 gen_int_mode (tree_to_shwi (exp1
),
8582 TYPE_MODE (TREE_TYPE (exp1
)))));
8585 if (modifier
== EXPAND_STACK_PARM
)
8588 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8589 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8591 case TRUNC_DIV_EXPR
:
8592 case FLOOR_DIV_EXPR
:
8594 case ROUND_DIV_EXPR
:
8595 case EXACT_DIV_EXPR
:
8596 /* If this is a fixed-point operation, then we cannot use the code
8597 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8599 if (ALL_FIXED_POINT_MODE_P (mode
))
8602 if (modifier
== EXPAND_STACK_PARM
)
8604 /* Possible optimization: compute the dividend with EXPAND_SUM
8605 then if the divisor is constant can optimize the case
8606 where some terms of the dividend have coeffs divisible by it. */
8607 expand_operands (treeop0
, treeop1
,
8608 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8609 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8614 case MULT_HIGHPART_EXPR
:
8615 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8616 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8620 case TRUNC_MOD_EXPR
:
8621 case FLOOR_MOD_EXPR
:
8623 case ROUND_MOD_EXPR
:
8624 if (modifier
== EXPAND_STACK_PARM
)
8626 expand_operands (treeop0
, treeop1
,
8627 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8628 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8630 case FIXED_CONVERT_EXPR
:
8631 op0
= expand_normal (treeop0
);
8632 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8633 target
= gen_reg_rtx (mode
);
8635 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8636 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8637 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8638 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8640 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8643 case FIX_TRUNC_EXPR
:
8644 op0
= expand_normal (treeop0
);
8645 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8646 target
= gen_reg_rtx (mode
);
8647 expand_fix (target
, op0
, unsignedp
);
8651 op0
= expand_normal (treeop0
);
8652 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8653 target
= gen_reg_rtx (mode
);
8654 /* expand_float can't figure out what to do if FROM has VOIDmode.
8655 So give it the correct mode. With -O, cse will optimize this. */
8656 if (GET_MODE (op0
) == VOIDmode
)
8657 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8659 expand_float (target
, op0
,
8660 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8664 op0
= expand_expr (treeop0
, subtarget
,
8665 VOIDmode
, EXPAND_NORMAL
);
8666 if (modifier
== EXPAND_STACK_PARM
)
8668 temp
= expand_unop (mode
,
8669 optab_for_tree_code (NEGATE_EXPR
, type
,
8673 return REDUCE_BIT_FIELD (temp
);
8676 op0
= expand_expr (treeop0
, subtarget
,
8677 VOIDmode
, EXPAND_NORMAL
);
8678 if (modifier
== EXPAND_STACK_PARM
)
8681 /* ABS_EXPR is not valid for complex arguments. */
8682 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8683 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8685 /* Unsigned abs is simply the operand. Testing here means we don't
8686 risk generating incorrect code below. */
8687 if (TYPE_UNSIGNED (type
))
8690 return expand_abs (mode
, op0
, target
, unsignedp
,
8691 safe_from_p (target
, treeop0
, 1));
8695 target
= original_target
;
8697 || modifier
== EXPAND_STACK_PARM
8698 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8699 || GET_MODE (target
) != mode
8701 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8702 target
= gen_reg_rtx (mode
);
8703 expand_operands (treeop0
, treeop1
,
8704 target
, &op0
, &op1
, EXPAND_NORMAL
);
8706 /* First try to do it with a special MIN or MAX instruction.
8707 If that does not win, use a conditional jump to select the proper
8709 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8710 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8715 /* At this point, a MEM target is no longer useful; we will get better
8718 if (! REG_P (target
))
8719 target
= gen_reg_rtx (mode
);
8721 /* If op1 was placed in target, swap op0 and op1. */
8722 if (target
!= op0
&& target
== op1
)
8723 std::swap (op0
, op1
);
8725 /* We generate better code and avoid problems with op1 mentioning
8726 target by forcing op1 into a pseudo if it isn't a constant. */
8727 if (! CONSTANT_P (op1
))
8728 op1
= force_reg (mode
, op1
);
8731 enum rtx_code comparison_code
;
8734 if (code
== MAX_EXPR
)
8735 comparison_code
= unsignedp
? GEU
: GE
;
8737 comparison_code
= unsignedp
? LEU
: LE
;
8739 /* Canonicalize to comparisons against 0. */
8740 if (op1
== const1_rtx
)
8742 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8743 or (a != 0 ? a : 1) for unsigned.
8744 For MIN we are safe converting (a <= 1 ? a : 1)
8745 into (a <= 0 ? a : 1) */
8746 cmpop1
= const0_rtx
;
8747 if (code
== MAX_EXPR
)
8748 comparison_code
= unsignedp
? NE
: GT
;
8750 if (op1
== constm1_rtx
&& !unsignedp
)
8752 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8753 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8754 cmpop1
= const0_rtx
;
8755 if (code
== MIN_EXPR
)
8756 comparison_code
= LT
;
8759 /* Use a conditional move if possible. */
8760 if (can_conditionally_move_p (mode
))
8766 /* Try to emit the conditional move. */
8767 insn
= emit_conditional_move (target
, comparison_code
,
8772 /* If we could do the conditional move, emit the sequence,
8776 rtx_insn
*seq
= get_insns ();
8782 /* Otherwise discard the sequence and fall back to code with
8788 emit_move_insn (target
, op0
);
8790 lab
= gen_label_rtx ();
8791 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8792 unsignedp
, mode
, NULL_RTX
, NULL
, lab
,
8795 emit_move_insn (target
, op1
);
8800 op0
= expand_expr (treeop0
, subtarget
,
8801 VOIDmode
, EXPAND_NORMAL
);
8802 if (modifier
== EXPAND_STACK_PARM
)
8804 /* In case we have to reduce the result to bitfield precision
8805 for unsigned bitfield expand this as XOR with a proper constant
8807 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8809 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
8810 false, GET_MODE_PRECISION (mode
));
8812 temp
= expand_binop (mode
, xor_optab
, op0
,
8813 immed_wide_int_const (mask
, mode
),
8814 target
, 1, OPTAB_LIB_WIDEN
);
8817 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8821 /* ??? Can optimize bitwise operations with one arg constant.
8822 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8823 and (a bitwise1 b) bitwise2 b (etc)
8824 but that is probably not worth while. */
8833 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8834 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8835 == TYPE_PRECISION (type
)));
8841 /* If this is a fixed-point operation, then we cannot use the code
8842 below because "expand_shift" doesn't support sat/no-sat fixed-point
8844 if (ALL_FIXED_POINT_MODE_P (mode
))
8847 if (! safe_from_p (subtarget
, treeop1
, 1))
8849 if (modifier
== EXPAND_STACK_PARM
)
8851 op0
= expand_expr (treeop0
, subtarget
,
8852 VOIDmode
, EXPAND_NORMAL
);
8854 /* Left shift optimization when shifting across word_size boundary.
8856 If mode == GET_MODE_WIDER_MODE (word_mode), then normally there isn't
8857 native instruction to support this wide mode left shift. Given below
8860 Type A = (Type) B << C
8863 | dest_high | dest_low |
8867 If the shift amount C caused we shift B to across the word size
8868 boundary, i.e part of B shifted into high half of destination
8869 register, and part of B remains in the low half, then GCC will use
8870 the following left shift expand logic:
8872 1. Initialize dest_low to B.
8873 2. Initialize every bit of dest_high to the sign bit of B.
8874 3. Logic left shift dest_low by C bit to finalize dest_low.
8875 The value of dest_low before this shift is kept in a temp D.
8876 4. Logic left shift dest_high by C.
8877 5. Logic right shift D by (word_size - C).
8878 6. Or the result of 4 and 5 to finalize dest_high.
8880 While, by checking gimple statements, if operand B is coming from
8881 signed extension, then we can simplify above expand logic into:
8883 1. dest_high = src_low >> (word_size - C).
8884 2. dest_low = src_low << C.
8886 We can use one arithmetic right shift to finish all the purpose of
8887 steps 2, 4, 5, 6, thus we reduce the steps needed from 6 into 2. */
8890 if (code
== LSHIFT_EXPR
8894 && mode
== GET_MODE_WIDER_MODE (word_mode
)
8895 && GET_MODE_SIZE (mode
) == 2 * GET_MODE_SIZE (word_mode
)
8896 && TREE_CONSTANT (treeop1
)
8897 && TREE_CODE (treeop0
) == SSA_NAME
)
8899 gimple
*def
= SSA_NAME_DEF_STMT (treeop0
);
8900 if (is_gimple_assign (def
)
8901 && gimple_assign_rhs_code (def
) == NOP_EXPR
)
8903 machine_mode rmode
= TYPE_MODE
8904 (TREE_TYPE (gimple_assign_rhs1 (def
)));
8906 if (GET_MODE_SIZE (rmode
) < GET_MODE_SIZE (mode
)
8907 && TREE_INT_CST_LOW (treeop1
) < GET_MODE_BITSIZE (word_mode
)
8908 && ((TREE_INT_CST_LOW (treeop1
) + GET_MODE_BITSIZE (rmode
))
8909 >= GET_MODE_BITSIZE (word_mode
)))
8911 rtx_insn
*seq
, *seq_old
;
8912 unsigned int high_off
= subreg_highpart_offset (word_mode
,
8914 rtx low
= lowpart_subreg (word_mode
, op0
, mode
);
8915 rtx dest_low
= lowpart_subreg (word_mode
, target
, mode
);
8916 rtx dest_high
= simplify_gen_subreg (word_mode
, target
,
8918 HOST_WIDE_INT ramount
= (BITS_PER_WORD
8919 - TREE_INT_CST_LOW (treeop1
));
8920 tree rshift
= build_int_cst (TREE_TYPE (treeop1
), ramount
);
8923 /* dest_high = src_low >> (word_size - C). */
8924 temp
= expand_variable_shift (RSHIFT_EXPR
, word_mode
, low
,
8925 rshift
, dest_high
, unsignedp
);
8926 if (temp
!= dest_high
)
8927 emit_move_insn (dest_high
, temp
);
8929 /* dest_low = src_low << C. */
8930 temp
= expand_variable_shift (LSHIFT_EXPR
, word_mode
, low
,
8931 treeop1
, dest_low
, unsignedp
);
8932 if (temp
!= dest_low
)
8933 emit_move_insn (dest_low
, temp
);
8939 if (have_insn_for (ASHIFT
, mode
))
8941 bool speed_p
= optimize_insn_for_speed_p ();
8943 rtx ret_old
= expand_variable_shift (code
, mode
, op0
,
8947 seq_old
= get_insns ();
8949 if (seq_cost (seq
, speed_p
)
8950 >= seq_cost (seq_old
, speed_p
))
8961 if (temp
== NULL_RTX
)
8962 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8964 if (code
== LSHIFT_EXPR
)
8965 temp
= REDUCE_BIT_FIELD (temp
);
8969 /* Could determine the answer when only additive constants differ. Also,
8970 the addition of one can be handled by changing the condition. */
8977 case UNORDERED_EXPR
:
8986 temp
= do_store_flag (ops
,
8987 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8988 tmode
!= VOIDmode
? tmode
: mode
);
8992 /* Use a compare and a jump for BLKmode comparisons, or for function
8993 type comparisons is have_canonicalize_funcptr_for_compare. */
8996 || modifier
== EXPAND_STACK_PARM
8997 || ! safe_from_p (target
, treeop0
, 1)
8998 || ! safe_from_p (target
, treeop1
, 1)
8999 /* Make sure we don't have a hard reg (such as function's return
9000 value) live across basic blocks, if not optimizing. */
9001 || (!optimize
&& REG_P (target
)
9002 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
9003 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
9005 emit_move_insn (target
, const0_rtx
);
9007 rtx_code_label
*lab1
= gen_label_rtx ();
9008 jumpifnot_1 (code
, treeop0
, treeop1
, lab1
, -1);
9010 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
9011 emit_move_insn (target
, constm1_rtx
);
9013 emit_move_insn (target
, const1_rtx
);
9019 /* Get the rtx code of the operands. */
9020 op0
= expand_normal (treeop0
);
9021 op1
= expand_normal (treeop1
);
9024 target
= gen_reg_rtx (TYPE_MODE (type
));
9026 /* If target overlaps with op1, then either we need to force
9027 op1 into a pseudo (if target also overlaps with op0),
9028 or write the complex parts in reverse order. */
9029 switch (GET_CODE (target
))
9032 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
9034 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
9036 complex_expr_force_op1
:
9037 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
9038 emit_move_insn (temp
, op1
);
9042 complex_expr_swap_order
:
9043 /* Move the imaginary (op1) and real (op0) parts to their
9045 write_complex_part (target
, op1
, true);
9046 write_complex_part (target
, op0
, false);
9052 temp
= adjust_address_nv (target
,
9053 GET_MODE_INNER (GET_MODE (target
)), 0);
9054 if (reg_overlap_mentioned_p (temp
, op1
))
9056 machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
9057 temp
= adjust_address_nv (target
, imode
,
9058 GET_MODE_SIZE (imode
));
9059 if (reg_overlap_mentioned_p (temp
, op0
))
9060 goto complex_expr_force_op1
;
9061 goto complex_expr_swap_order
;
9065 if (reg_overlap_mentioned_p (target
, op1
))
9067 if (reg_overlap_mentioned_p (target
, op0
))
9068 goto complex_expr_force_op1
;
9069 goto complex_expr_swap_order
;
9074 /* Move the real (op0) and imaginary (op1) parts to their location. */
9075 write_complex_part (target
, op0
, false);
9076 write_complex_part (target
, op1
, true);
9080 case WIDEN_SUM_EXPR
:
9082 tree oprnd0
= treeop0
;
9083 tree oprnd1
= treeop1
;
9085 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9086 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9091 case REDUC_MAX_EXPR
:
9092 case REDUC_MIN_EXPR
:
9093 case REDUC_PLUS_EXPR
:
9095 op0
= expand_normal (treeop0
);
9096 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9097 machine_mode vec_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9099 if (optab_handler (this_optab
, vec_mode
) != CODE_FOR_nothing
)
9101 struct expand_operand ops
[2];
9102 enum insn_code icode
= optab_handler (this_optab
, vec_mode
);
9104 create_output_operand (&ops
[0], target
, mode
);
9105 create_input_operand (&ops
[1], op0
, vec_mode
);
9106 if (maybe_expand_insn (icode
, 2, ops
))
9108 target
= ops
[0].value
;
9109 if (GET_MODE (target
) != mode
)
9110 return gen_lowpart (tmode
, target
);
9114 /* Fall back to optab with vector result, and then extract scalar. */
9115 this_optab
= scalar_reduc_to_vector (this_optab
, type
);
9116 temp
= expand_unop (vec_mode
, this_optab
, op0
, NULL_RTX
, unsignedp
);
9118 /* The tree code produces a scalar result, but (somewhat by convention)
9119 the optab produces a vector with the result in element 0 if
9120 little-endian, or element N-1 if big-endian. So pull the scalar
9121 result out of that element. */
9122 int index
= BYTES_BIG_ENDIAN
? GET_MODE_NUNITS (vec_mode
) - 1 : 0;
9123 int bitsize
= GET_MODE_UNIT_BITSIZE (vec_mode
);
9124 temp
= extract_bit_field (temp
, bitsize
, bitsize
* index
, unsignedp
,
9125 target
, mode
, mode
);
9130 case VEC_UNPACK_HI_EXPR
:
9131 case VEC_UNPACK_LO_EXPR
:
9133 op0
= expand_normal (treeop0
);
9134 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9140 case VEC_UNPACK_FLOAT_HI_EXPR
:
9141 case VEC_UNPACK_FLOAT_LO_EXPR
:
9143 op0
= expand_normal (treeop0
);
9144 /* The signedness is determined from input operand. */
9145 temp
= expand_widen_pattern_expr
9146 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9147 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9153 case VEC_WIDEN_MULT_HI_EXPR
:
9154 case VEC_WIDEN_MULT_LO_EXPR
:
9155 case VEC_WIDEN_MULT_EVEN_EXPR
:
9156 case VEC_WIDEN_MULT_ODD_EXPR
:
9157 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9158 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9159 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9160 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9162 gcc_assert (target
);
9165 case VEC_PACK_TRUNC_EXPR
:
9166 case VEC_PACK_SAT_EXPR
:
9167 case VEC_PACK_FIX_TRUNC_EXPR
:
9168 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9172 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9173 op2
= expand_normal (treeop2
);
9175 /* Careful here: if the target doesn't support integral vector modes,
9176 a constant selection vector could wind up smooshed into a normal
9177 integral constant. */
9178 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9180 tree sel_type
= TREE_TYPE (treeop2
);
9182 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9183 TYPE_VECTOR_SUBPARTS (sel_type
));
9184 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9185 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9186 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9189 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9191 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9197 tree oprnd0
= treeop0
;
9198 tree oprnd1
= treeop1
;
9199 tree oprnd2
= treeop2
;
9202 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9203 op2
= expand_normal (oprnd2
);
9204 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9211 tree oprnd0
= treeop0
;
9212 tree oprnd1
= treeop1
;
9213 tree oprnd2
= treeop2
;
9216 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9217 op2
= expand_normal (oprnd2
);
9218 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9223 case REALIGN_LOAD_EXPR
:
9225 tree oprnd0
= treeop0
;
9226 tree oprnd1
= treeop1
;
9227 tree oprnd2
= treeop2
;
9230 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9231 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9232 op2
= expand_normal (oprnd2
);
9233 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9241 /* A COND_EXPR with its type being VOID_TYPE represents a
9242 conditional jump and is handled in
9243 expand_gimple_cond_expr. */
9244 gcc_assert (!VOID_TYPE_P (type
));
9246 /* Note that COND_EXPRs whose type is a structure or union
9247 are required to be constructed to contain assignments of
9248 a temporary variable, so that we can evaluate them here
9249 for side effect only. If type is void, we must do likewise. */
9251 gcc_assert (!TREE_ADDRESSABLE (type
)
9253 && TREE_TYPE (treeop1
) != void_type_node
9254 && TREE_TYPE (treeop2
) != void_type_node
);
9256 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9260 /* If we are not to produce a result, we have no target. Otherwise,
9261 if a target was specified use it; it will not be used as an
9262 intermediate target unless it is safe. If no target, use a
9265 if (modifier
!= EXPAND_STACK_PARM
9267 && safe_from_p (original_target
, treeop0
, 1)
9268 && GET_MODE (original_target
) == mode
9269 && !MEM_P (original_target
))
9270 temp
= original_target
;
9272 temp
= assign_temp (type
, 0, 1);
9274 do_pending_stack_adjust ();
9276 rtx_code_label
*lab0
= gen_label_rtx ();
9277 rtx_code_label
*lab1
= gen_label_rtx ();
9278 jumpifnot (treeop0
, lab0
, -1);
9279 store_expr (treeop1
, temp
,
9280 modifier
== EXPAND_STACK_PARM
,
9283 emit_jump_insn (targetm
.gen_jump (lab1
));
9286 store_expr (treeop2
, temp
,
9287 modifier
== EXPAND_STACK_PARM
,
9296 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9303 /* Here to do an ordinary binary operator. */
9305 expand_operands (treeop0
, treeop1
,
9306 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9308 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9310 if (modifier
== EXPAND_STACK_PARM
)
9312 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9313 unsignedp
, OPTAB_LIB_WIDEN
);
9315 /* Bitwise operations do not need bitfield reduction as we expect their
9316 operands being properly truncated. */
9317 if (code
== BIT_XOR_EXPR
9318 || code
== BIT_AND_EXPR
9319 || code
== BIT_IOR_EXPR
)
9321 return REDUCE_BIT_FIELD (temp
);
9323 #undef REDUCE_BIT_FIELD
9326 /* Return TRUE if expression STMT is suitable for replacement.
9327 Never consider memory loads as replaceable, because those don't ever lead
9328 into constant expressions. */
9331 stmt_is_replaceable_p (gimple
*stmt
)
9333 if (ssa_is_replaceable_p (stmt
))
9335 /* Don't move around loads. */
9336 if (!gimple_assign_single_p (stmt
)
9337 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9344 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
9345 enum expand_modifier modifier
, rtx
*alt_rtl
,
9346 bool inner_reference_p
)
9348 rtx op0
, op1
, temp
, decl_rtl
;
9351 machine_mode mode
, dmode
;
9352 enum tree_code code
= TREE_CODE (exp
);
9353 rtx subtarget
, original_target
;
9356 bool reduce_bit_field
;
9357 location_t loc
= EXPR_LOCATION (exp
);
9358 struct separate_ops ops
;
9359 tree treeop0
, treeop1
, treeop2
;
9360 tree ssa_name
= NULL_TREE
;
9363 type
= TREE_TYPE (exp
);
9364 mode
= TYPE_MODE (type
);
9365 unsignedp
= TYPE_UNSIGNED (type
);
9367 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9368 if (!VL_EXP_CLASS_P (exp
))
9369 switch (TREE_CODE_LENGTH (code
))
9372 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9373 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9374 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9384 ignore
= (target
== const0_rtx
9385 || ((CONVERT_EXPR_CODE_P (code
)
9386 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9387 && TREE_CODE (type
) == VOID_TYPE
));
9389 /* An operation in what may be a bit-field type needs the
9390 result to be reduced to the precision of the bit-field type,
9391 which is narrower than that of the type's mode. */
9392 reduce_bit_field
= (!ignore
9393 && INTEGRAL_TYPE_P (type
)
9394 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9396 /* If we are going to ignore this result, we need only do something
9397 if there is a side-effect somewhere in the expression. If there
9398 is, short-circuit the most common cases here. Note that we must
9399 not call expand_expr with anything but const0_rtx in case this
9400 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9404 if (! TREE_SIDE_EFFECTS (exp
))
9407 /* Ensure we reference a volatile object even if value is ignored, but
9408 don't do this if all we are doing is taking its address. */
9409 if (TREE_THIS_VOLATILE (exp
)
9410 && TREE_CODE (exp
) != FUNCTION_DECL
9411 && mode
!= VOIDmode
&& mode
!= BLKmode
9412 && modifier
!= EXPAND_CONST_ADDRESS
)
9414 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9420 if (TREE_CODE_CLASS (code
) == tcc_unary
9421 || code
== BIT_FIELD_REF
9422 || code
== COMPONENT_REF
9423 || code
== INDIRECT_REF
)
9424 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9427 else if (TREE_CODE_CLASS (code
) == tcc_binary
9428 || TREE_CODE_CLASS (code
) == tcc_comparison
9429 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9431 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9432 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9439 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9442 /* Use subtarget as the target for operand 0 of a binary operation. */
9443 subtarget
= get_subtarget (target
);
9444 original_target
= target
;
9450 tree function
= decl_function_context (exp
);
9452 temp
= label_rtx (exp
);
9453 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9455 if (function
!= current_function_decl
9457 LABEL_REF_NONLOCAL_P (temp
) = 1;
9459 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9464 /* ??? ivopts calls expander, without any preparation from
9465 out-of-ssa. So fake instructions as if this was an access to the
9466 base variable. This unnecessarily allocates a pseudo, see how we can
9467 reuse it, if partition base vars have it set already. */
9468 if (!currently_expanding_to_rtl
)
9470 tree var
= SSA_NAME_VAR (exp
);
9471 if (var
&& DECL_RTL_SET_P (var
))
9472 return DECL_RTL (var
);
9473 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9474 LAST_VIRTUAL_REGISTER
+ 1);
9477 g
= get_gimple_for_ssa_name (exp
);
9478 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9480 && modifier
== EXPAND_INITIALIZER
9481 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9482 && (optimize
|| !SSA_NAME_VAR (exp
)
9483 || DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9484 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9485 g
= SSA_NAME_DEF_STMT (exp
);
9489 location_t saved_loc
= curr_insn_location ();
9490 location_t loc
= gimple_location (g
);
9491 if (loc
!= UNKNOWN_LOCATION
)
9492 set_curr_insn_location (loc
);
9493 ops
.code
= gimple_assign_rhs_code (g
);
9494 switch (get_gimple_rhs_class (ops
.code
))
9496 case GIMPLE_TERNARY_RHS
:
9497 ops
.op2
= gimple_assign_rhs3 (g
);
9499 case GIMPLE_BINARY_RHS
:
9500 ops
.op1
= gimple_assign_rhs2 (g
);
9502 /* Try to expand conditonal compare. */
9503 if (targetm
.gen_ccmp_first
)
9505 gcc_checking_assert (targetm
.gen_ccmp_next
!= NULL
);
9506 r
= expand_ccmp_expr (g
);
9511 case GIMPLE_UNARY_RHS
:
9512 ops
.op0
= gimple_assign_rhs1 (g
);
9513 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9515 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9517 case GIMPLE_SINGLE_RHS
:
9519 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9520 tmode
, modifier
, NULL
, inner_reference_p
);
9526 set_curr_insn_location (saved_loc
);
9527 if (REG_P (r
) && !REG_EXPR (r
))
9528 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9533 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9534 exp
= SSA_NAME_VAR (ssa_name
);
9535 goto expand_decl_rtl
;
9539 /* If a static var's type was incomplete when the decl was written,
9540 but the type is complete now, lay out the decl now. */
9541 if (DECL_SIZE (exp
) == 0
9542 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9543 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9544 layout_decl (exp
, 0);
9546 /* ... fall through ... */
9550 decl_rtl
= DECL_RTL (exp
);
9552 gcc_assert (decl_rtl
);
9553 decl_rtl
= copy_rtx (decl_rtl
);
9554 /* Record writes to register variables. */
9555 if (modifier
== EXPAND_WRITE
9557 && HARD_REGISTER_P (decl_rtl
))
9558 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9559 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9561 /* Ensure variable marked as used even if it doesn't go through
9562 a parser. If it hasn't be used yet, write out an external
9565 TREE_USED (exp
) = 1;
9567 /* Show we haven't gotten RTL for this yet. */
9570 /* Variables inherited from containing functions should have
9571 been lowered by this point. */
9573 context
= decl_function_context (exp
);
9575 || SCOPE_FILE_SCOPE_P (context
)
9576 || context
== current_function_decl
9577 || TREE_STATIC (exp
)
9578 || DECL_EXTERNAL (exp
)
9579 /* ??? C++ creates functions that are not TREE_STATIC. */
9580 || TREE_CODE (exp
) == FUNCTION_DECL
);
9582 /* This is the case of an array whose size is to be determined
9583 from its initializer, while the initializer is still being parsed.
9584 ??? We aren't parsing while expanding anymore. */
9586 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9587 temp
= validize_mem (decl_rtl
);
9589 /* If DECL_RTL is memory, we are in the normal case and the
9590 address is not valid, get the address into a register. */
9592 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9595 *alt_rtl
= decl_rtl
;
9596 decl_rtl
= use_anchored_address (decl_rtl
);
9597 if (modifier
!= EXPAND_CONST_ADDRESS
9598 && modifier
!= EXPAND_SUM
9599 && !memory_address_addr_space_p (exp
? DECL_MODE (exp
)
9600 : GET_MODE (decl_rtl
),
9602 MEM_ADDR_SPACE (decl_rtl
)))
9603 temp
= replace_equiv_address (decl_rtl
,
9604 copy_rtx (XEXP (decl_rtl
, 0)));
9607 /* If we got something, return it. But first, set the alignment
9608 if the address is a register. */
9611 if (exp
&& MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9612 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9618 dmode
= DECL_MODE (exp
);
9620 dmode
= TYPE_MODE (TREE_TYPE (ssa_name
));
9622 /* If the mode of DECL_RTL does not match that of the decl,
9623 there are two cases: we are dealing with a BLKmode value
9624 that is returned in a register, or we are dealing with
9625 a promoted value. In the latter case, return a SUBREG
9626 of the wanted mode, but mark it so that we know that it
9627 was already extended. */
9628 if (REG_P (decl_rtl
)
9630 && GET_MODE (decl_rtl
) != dmode
)
9634 /* Get the signedness to be used for this variable. Ensure we get
9635 the same mode we got when the variable was declared. */
9636 if (code
!= SSA_NAME
)
9637 pmode
= promote_decl_mode (exp
, &unsignedp
);
9638 else if ((g
= SSA_NAME_DEF_STMT (ssa_name
))
9639 && gimple_code (g
) == GIMPLE_CALL
9640 && !gimple_call_internal_p (g
))
9641 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9642 gimple_call_fntype (g
),
9645 pmode
= promote_ssa_mode (ssa_name
, &unsignedp
);
9646 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9648 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9649 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9650 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9657 /* Given that TYPE_PRECISION (type) is not always equal to
9658 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9659 the former to the latter according to the signedness of the
9661 temp
= immed_wide_int_const (wide_int::from
9663 GET_MODE_PRECISION (TYPE_MODE (type
)),
9670 tree tmp
= NULL_TREE
;
9671 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9672 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9673 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9674 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9675 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9676 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9677 return const_vector_from_tree (exp
);
9678 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9680 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9682 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9686 vec
<constructor_elt
, va_gc
> *v
;
9688 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9689 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9690 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9691 tmp
= build_constructor (type
, v
);
9693 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9698 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9701 /* If optimized, generate immediate CONST_DOUBLE
9702 which will be turned into memory by reload if necessary.
9704 We used to force a register so that loop.c could see it. But
9705 this does not allow gen_* patterns to perform optimizations with
9706 the constants. It also produces two insns in cases like "x = 1.0;".
9707 On most machines, floating-point constants are not permitted in
9708 many insns, so we'd end up copying it to a register in any case.
9710 Now, we do the copying in expand_binop, if appropriate. */
9711 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9712 TYPE_MODE (TREE_TYPE (exp
)));
9715 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9716 TYPE_MODE (TREE_TYPE (exp
)));
9719 /* Handle evaluating a complex constant in a CONCAT target. */
9720 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9722 machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9725 rtarg
= XEXP (original_target
, 0);
9726 itarg
= XEXP (original_target
, 1);
9728 /* Move the real and imaginary parts separately. */
9729 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9730 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9733 emit_move_insn (rtarg
, op0
);
9735 emit_move_insn (itarg
, op1
);
9737 return original_target
;
9740 /* ... fall through ... */
9743 temp
= expand_expr_constant (exp
, 1, modifier
);
9745 /* temp contains a constant address.
9746 On RISC machines where a constant address isn't valid,
9747 make some insns to get that address into a register. */
9748 if (modifier
!= EXPAND_CONST_ADDRESS
9749 && modifier
!= EXPAND_INITIALIZER
9750 && modifier
!= EXPAND_SUM
9751 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9752 MEM_ADDR_SPACE (temp
)))
9753 return replace_equiv_address (temp
,
9754 copy_rtx (XEXP (temp
, 0)));
9760 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
9763 if (!SAVE_EXPR_RESOLVED_P (exp
))
9765 /* We can indeed still hit this case, typically via builtin
9766 expanders calling save_expr immediately before expanding
9767 something. Assume this means that we only have to deal
9768 with non-BLKmode values. */
9769 gcc_assert (GET_MODE (ret
) != BLKmode
);
9771 val
= build_decl (curr_insn_location (),
9772 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9773 DECL_ARTIFICIAL (val
) = 1;
9774 DECL_IGNORED_P (val
) = 1;
9776 TREE_OPERAND (exp
, 0) = treeop0
;
9777 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9779 if (!CONSTANT_P (ret
))
9780 ret
= copy_to_reg (ret
);
9781 SET_DECL_RTL (val
, ret
);
9789 /* If we don't need the result, just ensure we evaluate any
9793 unsigned HOST_WIDE_INT idx
;
9796 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9797 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9802 return expand_constructor (exp
, target
, modifier
, false);
9804 case TARGET_MEM_REF
:
9807 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9808 enum insn_code icode
;
9811 op0
= addr_for_mem_ref (exp
, as
, true);
9812 op0
= memory_address_addr_space (mode
, op0
, as
);
9813 temp
= gen_rtx_MEM (mode
, op0
);
9814 set_mem_attributes (temp
, exp
, 0);
9815 set_mem_addr_space (temp
, as
);
9816 align
= get_object_alignment (exp
);
9817 if (modifier
!= EXPAND_WRITE
9818 && modifier
!= EXPAND_MEMORY
9820 && align
< GET_MODE_ALIGNMENT (mode
)
9821 /* If the target does not have special handling for unaligned
9822 loads of mode then it can use regular moves for them. */
9823 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9824 != CODE_FOR_nothing
))
9826 struct expand_operand ops
[2];
9828 /* We've already validated the memory, and we're creating a
9829 new pseudo destination. The predicates really can't fail,
9830 nor can the generator. */
9831 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9832 create_fixed_operand (&ops
[1], temp
);
9833 expand_insn (icode
, 2, ops
);
9834 temp
= ops
[0].value
;
9842 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9843 machine_mode address_mode
;
9844 tree base
= TREE_OPERAND (exp
, 0);
9846 enum insn_code icode
;
9848 /* Handle expansion of non-aliased memory with non-BLKmode. That
9849 might end up in a register. */
9850 if (mem_ref_refers_to_non_mem_p (exp
))
9852 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
9853 base
= TREE_OPERAND (base
, 0);
9855 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9856 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9857 == tree_to_uhwi (TYPE_SIZE (type
))))
9858 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9859 target
, tmode
, modifier
);
9860 if (TYPE_MODE (type
) == BLKmode
)
9862 temp
= assign_stack_temp (DECL_MODE (base
),
9863 GET_MODE_SIZE (DECL_MODE (base
)));
9864 store_expr (base
, temp
, 0, false);
9865 temp
= adjust_address (temp
, BLKmode
, offset
);
9866 set_mem_size (temp
, int_size_in_bytes (type
));
9869 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9870 bitsize_int (offset
* BITS_PER_UNIT
));
9871 return expand_expr (exp
, target
, tmode
, modifier
);
9873 address_mode
= targetm
.addr_space
.address_mode (as
);
9874 base
= TREE_OPERAND (exp
, 0);
9875 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9877 tree mask
= gimple_assign_rhs2 (def_stmt
);
9878 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9879 gimple_assign_rhs1 (def_stmt
), mask
);
9880 TREE_OPERAND (exp
, 0) = base
;
9882 align
= get_object_alignment (exp
);
9883 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9884 op0
= memory_address_addr_space (mode
, op0
, as
);
9885 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9887 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
9888 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9889 op0
= memory_address_addr_space (mode
, op0
, as
);
9891 temp
= gen_rtx_MEM (mode
, op0
);
9892 set_mem_attributes (temp
, exp
, 0);
9893 set_mem_addr_space (temp
, as
);
9894 if (TREE_THIS_VOLATILE (exp
))
9895 MEM_VOLATILE_P (temp
) = 1;
9896 if (modifier
!= EXPAND_WRITE
9897 && modifier
!= EXPAND_MEMORY
9898 && !inner_reference_p
9900 && align
< GET_MODE_ALIGNMENT (mode
))
9902 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9903 != CODE_FOR_nothing
)
9905 struct expand_operand ops
[2];
9907 /* We've already validated the memory, and we're creating a
9908 new pseudo destination. The predicates really can't fail,
9909 nor can the generator. */
9910 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9911 create_fixed_operand (&ops
[1], temp
);
9912 expand_insn (icode
, 2, ops
);
9913 temp
= ops
[0].value
;
9915 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9916 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9917 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9918 (modifier
== EXPAND_STACK_PARM
9919 ? NULL_RTX
: target
),
9928 tree array
= treeop0
;
9929 tree index
= treeop1
;
9932 /* Fold an expression like: "foo"[2].
9933 This is not done in fold so it won't happen inside &.
9934 Don't fold if this is for wide characters since it's too
9935 difficult to do correctly and this is a very rare case. */
9937 if (modifier
!= EXPAND_CONST_ADDRESS
9938 && modifier
!= EXPAND_INITIALIZER
9939 && modifier
!= EXPAND_MEMORY
)
9941 tree t
= fold_read_from_constant_string (exp
);
9944 return expand_expr (t
, target
, tmode
, modifier
);
9947 /* If this is a constant index into a constant array,
9948 just get the value from the array. Handle both the cases when
9949 we have an explicit constructor and when our operand is a variable
9950 that was declared const. */
9952 if (modifier
!= EXPAND_CONST_ADDRESS
9953 && modifier
!= EXPAND_INITIALIZER
9954 && modifier
!= EXPAND_MEMORY
9955 && TREE_CODE (array
) == CONSTRUCTOR
9956 && ! TREE_SIDE_EFFECTS (array
)
9957 && TREE_CODE (index
) == INTEGER_CST
)
9959 unsigned HOST_WIDE_INT ix
;
9962 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9964 if (tree_int_cst_equal (field
, index
))
9966 if (!TREE_SIDE_EFFECTS (value
))
9967 return expand_expr (fold (value
), target
, tmode
, modifier
);
9972 else if (optimize
>= 1
9973 && modifier
!= EXPAND_CONST_ADDRESS
9974 && modifier
!= EXPAND_INITIALIZER
9975 && modifier
!= EXPAND_MEMORY
9976 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9977 && TREE_CODE (index
) == INTEGER_CST
9978 && (TREE_CODE (array
) == VAR_DECL
9979 || TREE_CODE (array
) == CONST_DECL
)
9980 && (init
= ctor_for_folding (array
)) != error_mark_node
)
9982 if (init
== NULL_TREE
)
9984 tree value
= build_zero_cst (type
);
9985 if (TREE_CODE (value
) == CONSTRUCTOR
)
9987 /* If VALUE is a CONSTRUCTOR, this optimization is only
9988 useful if this doesn't store the CONSTRUCTOR into
9989 memory. If it does, it is more efficient to just
9990 load the data from the array directly. */
9991 rtx ret
= expand_constructor (value
, target
,
9993 if (ret
== NULL_RTX
)
9998 return expand_expr (value
, target
, tmode
, modifier
);
10000 else if (TREE_CODE (init
) == CONSTRUCTOR
)
10002 unsigned HOST_WIDE_INT ix
;
10005 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
10007 if (tree_int_cst_equal (field
, index
))
10009 if (TREE_SIDE_EFFECTS (value
))
10012 if (TREE_CODE (value
) == CONSTRUCTOR
)
10014 /* If VALUE is a CONSTRUCTOR, this
10015 optimization is only useful if
10016 this doesn't store the CONSTRUCTOR
10017 into memory. If it does, it is more
10018 efficient to just load the data from
10019 the array directly. */
10020 rtx ret
= expand_constructor (value
, target
,
10022 if (ret
== NULL_RTX
)
10027 expand_expr (fold (value
), target
, tmode
, modifier
);
10030 else if (TREE_CODE (init
) == STRING_CST
)
10032 tree low_bound
= array_ref_low_bound (exp
);
10033 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
10035 /* Optimize the special case of a zero lower bound.
10037 We convert the lower bound to sizetype to avoid problems
10038 with constant folding. E.g. suppose the lower bound is
10039 1 and its mode is QI. Without the conversion
10040 (ARRAY + (INDEX - (unsigned char)1))
10042 (ARRAY + (-(unsigned char)1) + INDEX)
10044 (ARRAY + 255 + INDEX). Oops! */
10045 if (!integer_zerop (low_bound
))
10046 index1
= size_diffop_loc (loc
, index1
,
10047 fold_convert_loc (loc
, sizetype
,
10050 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
10052 tree type
= TREE_TYPE (TREE_TYPE (init
));
10053 machine_mode mode
= TYPE_MODE (type
);
10055 if (GET_MODE_CLASS (mode
) == MODE_INT
10056 && GET_MODE_SIZE (mode
) == 1)
10057 return gen_int_mode (TREE_STRING_POINTER (init
)
10058 [TREE_INT_CST_LOW (index1
)],
10064 goto normal_inner_ref
;
10066 case COMPONENT_REF
:
10067 /* If the operand is a CONSTRUCTOR, we can just extract the
10068 appropriate field if it is present. */
10069 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
10071 unsigned HOST_WIDE_INT idx
;
10074 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
10076 if (field
== treeop1
10077 /* We can normally use the value of the field in the
10078 CONSTRUCTOR. However, if this is a bitfield in
10079 an integral mode that we can fit in a HOST_WIDE_INT,
10080 we must mask only the number of bits in the bitfield,
10081 since this is done implicitly by the constructor. If
10082 the bitfield does not meet either of those conditions,
10083 we can't do this optimization. */
10084 && (! DECL_BIT_FIELD (field
)
10085 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
10086 && (GET_MODE_PRECISION (DECL_MODE (field
))
10087 <= HOST_BITS_PER_WIDE_INT
))))
10089 if (DECL_BIT_FIELD (field
)
10090 && modifier
== EXPAND_STACK_PARM
)
10092 op0
= expand_expr (value
, target
, tmode
, modifier
);
10093 if (DECL_BIT_FIELD (field
))
10095 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
10096 machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
10098 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
10100 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
10102 op0
= expand_and (imode
, op0
, op1
, target
);
10106 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10108 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10110 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10118 goto normal_inner_ref
;
10120 case BIT_FIELD_REF
:
10121 case ARRAY_RANGE_REF
:
10124 machine_mode mode1
, mode2
;
10125 HOST_WIDE_INT bitsize
, bitpos
;
10127 int volatilep
= 0, must_force_mem
;
10128 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
10129 &mode1
, &unsignedp
, &volatilep
, true);
10130 rtx orig_op0
, memloc
;
10131 bool clear_mem_expr
= false;
10133 /* If we got back the original object, something is wrong. Perhaps
10134 we are evaluating an expression too early. In any event, don't
10135 infinitely recurse. */
10136 gcc_assert (tem
!= exp
);
10138 /* If TEM's type is a union of variable size, pass TARGET to the inner
10139 computation, since it will need a temporary and TARGET is known
10140 to have to do. This occurs in unchecked conversion in Ada. */
10142 = expand_expr_real (tem
,
10143 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10144 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10145 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10147 && modifier
!= EXPAND_STACK_PARM
10148 ? target
: NULL_RTX
),
10150 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10153 /* If the field has a mode, we want to access it in the
10154 field's mode, not the computed mode.
10155 If a MEM has VOIDmode (external with incomplete type),
10156 use BLKmode for it instead. */
10159 if (mode1
!= VOIDmode
)
10160 op0
= adjust_address (op0
, mode1
, 0);
10161 else if (GET_MODE (op0
) == VOIDmode
)
10162 op0
= adjust_address (op0
, BLKmode
, 0);
10166 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10168 /* If we have either an offset, a BLKmode result, or a reference
10169 outside the underlying object, we must force it to memory.
10170 Such a case can occur in Ada if we have unchecked conversion
10171 of an expression from a scalar type to an aggregate type or
10172 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10173 passed a partially uninitialized object or a view-conversion
10174 to a larger size. */
10175 must_force_mem
= (offset
10176 || mode1
== BLKmode
10177 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10179 /* Handle CONCAT first. */
10180 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10183 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
10186 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10189 op0
= XEXP (op0
, 0);
10190 mode2
= GET_MODE (op0
);
10192 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10193 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10197 op0
= XEXP (op0
, 1);
10199 mode2
= GET_MODE (op0
);
10202 /* Otherwise force into memory. */
10203 must_force_mem
= 1;
10206 /* If this is a constant, put it in a register if it is a legitimate
10207 constant and we don't need a memory reference. */
10208 if (CONSTANT_P (op0
)
10209 && mode2
!= BLKmode
10210 && targetm
.legitimate_constant_p (mode2
, op0
)
10211 && !must_force_mem
)
10212 op0
= force_reg (mode2
, op0
);
10214 /* Otherwise, if this is a constant, try to force it to the constant
10215 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10216 is a legitimate constant. */
10217 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10218 op0
= validize_mem (memloc
);
10220 /* Otherwise, if this is a constant or the object is not in memory
10221 and need be, put it there. */
10222 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10224 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10225 emit_move_insn (memloc
, op0
);
10227 clear_mem_expr
= true;
10232 machine_mode address_mode
;
10233 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10236 gcc_assert (MEM_P (op0
));
10238 address_mode
= get_address_mode (op0
);
10239 if (GET_MODE (offset_rtx
) != address_mode
)
10241 /* We cannot be sure that the RTL in offset_rtx is valid outside
10242 of a memory address context, so force it into a register
10243 before attempting to convert it to the desired mode. */
10244 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
10245 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10248 /* See the comment in expand_assignment for the rationale. */
10249 if (mode1
!= VOIDmode
10252 && (bitpos
% bitsize
) == 0
10253 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10254 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10256 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10260 op0
= offset_address (op0
, offset_rtx
,
10261 highest_pow2_factor (offset
));
10264 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10265 record its alignment as BIGGEST_ALIGNMENT. */
10266 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10267 && is_aligning_offset (offset
, tem
))
10268 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10270 /* Don't forget about volatility even if this is a bitfield. */
10271 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10273 if (op0
== orig_op0
)
10274 op0
= copy_rtx (op0
);
10276 MEM_VOLATILE_P (op0
) = 1;
10279 /* In cases where an aligned union has an unaligned object
10280 as a field, we might be extracting a BLKmode value from
10281 an integer-mode (e.g., SImode) object. Handle this case
10282 by doing the extract into an object as wide as the field
10283 (which we know to be the width of a basic mode), then
10284 storing into memory, and changing the mode to BLKmode. */
10285 if (mode1
== VOIDmode
10286 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10287 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10288 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10289 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10290 && modifier
!= EXPAND_CONST_ADDRESS
10291 && modifier
!= EXPAND_INITIALIZER
10292 && modifier
!= EXPAND_MEMORY
)
10293 /* If the bitfield is volatile and the bitsize
10294 is narrower than the access size of the bitfield,
10295 we need to extract bitfields from the access. */
10296 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10297 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10298 && mode1
!= BLKmode
10299 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10300 /* If the field isn't aligned enough to fetch as a memref,
10301 fetch it as a bit field. */
10302 || (mode1
!= BLKmode
10303 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10304 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10306 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10307 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10308 && modifier
!= EXPAND_MEMORY
10309 && ((modifier
== EXPAND_CONST_ADDRESS
10310 || modifier
== EXPAND_INITIALIZER
)
10312 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10313 || (bitpos
% BITS_PER_UNIT
!= 0)))
10314 /* If the type and the field are a constant size and the
10315 size of the type isn't the same size as the bitfield,
10316 we must use bitfield operations. */
10318 && TYPE_SIZE (TREE_TYPE (exp
))
10319 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10320 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10323 machine_mode ext_mode
= mode
;
10325 if (ext_mode
== BLKmode
10326 && ! (target
!= 0 && MEM_P (op0
)
10328 && bitpos
% BITS_PER_UNIT
== 0))
10329 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10331 if (ext_mode
== BLKmode
)
10334 target
= assign_temp (type
, 1, 1);
10336 /* ??? Unlike the similar test a few lines below, this one is
10337 very likely obsolete. */
10341 /* In this case, BITPOS must start at a byte boundary and
10342 TARGET, if specified, must be a MEM. */
10343 gcc_assert (MEM_P (op0
)
10344 && (!target
|| MEM_P (target
))
10345 && !(bitpos
% BITS_PER_UNIT
));
10347 emit_block_move (target
,
10348 adjust_address (op0
, VOIDmode
,
10349 bitpos
/ BITS_PER_UNIT
),
10350 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10352 (modifier
== EXPAND_STACK_PARM
10353 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10358 /* If we have nothing to extract, the result will be 0 for targets
10359 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10360 return 0 for the sake of consistency, as reading a zero-sized
10361 bitfield is valid in Ada and the value is fully specified. */
10365 op0
= validize_mem (op0
);
10367 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10368 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10370 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10371 (modifier
== EXPAND_STACK_PARM
10372 ? NULL_RTX
: target
),
10373 ext_mode
, ext_mode
);
10375 /* If the result is a record type and BITSIZE is narrower than
10376 the mode of OP0, an integral mode, and this is a big endian
10377 machine, we must put the field into the high-order bits. */
10378 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10379 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10380 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10381 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10382 GET_MODE_BITSIZE (GET_MODE (op0
))
10383 - bitsize
, op0
, 1);
10385 /* If the result type is BLKmode, store the data into a temporary
10386 of the appropriate type, but with the mode corresponding to the
10387 mode for the data we have (op0's mode). */
10388 if (mode
== BLKmode
)
10391 = assign_stack_temp_for_type (ext_mode
,
10392 GET_MODE_BITSIZE (ext_mode
),
10394 emit_move_insn (new_rtx
, op0
);
10395 op0
= copy_rtx (new_rtx
);
10396 PUT_MODE (op0
, BLKmode
);
10402 /* If the result is BLKmode, use that to access the object
10404 if (mode
== BLKmode
)
10407 /* Get a reference to just this component. */
10408 if (modifier
== EXPAND_CONST_ADDRESS
10409 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10410 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10412 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10414 if (op0
== orig_op0
)
10415 op0
= copy_rtx (op0
);
10417 set_mem_attributes (op0
, exp
, 0);
10419 if (REG_P (XEXP (op0
, 0)))
10420 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10422 /* If op0 is a temporary because the original expressions was forced
10423 to memory, clear MEM_EXPR so that the original expression cannot
10424 be marked as addressable through MEM_EXPR of the temporary. */
10425 if (clear_mem_expr
)
10426 set_mem_expr (op0
, NULL_TREE
);
10428 MEM_VOLATILE_P (op0
) |= volatilep
;
10429 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10430 || modifier
== EXPAND_CONST_ADDRESS
10431 || modifier
== EXPAND_INITIALIZER
)
10435 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10437 convert_move (target
, op0
, unsignedp
);
10442 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10445 /* All valid uses of __builtin_va_arg_pack () are removed during
10447 if (CALL_EXPR_VA_ARG_PACK (exp
))
10448 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10450 tree fndecl
= get_callee_fndecl (exp
), attr
;
10453 && (attr
= lookup_attribute ("error",
10454 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10455 error ("%Kcall to %qs declared with attribute error: %s",
10456 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10457 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10459 && (attr
= lookup_attribute ("warning",
10460 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10461 warning_at (tree_nonartificial_location (exp
),
10462 0, "%Kcall to %qs declared with attribute warning: %s",
10463 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10464 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10466 /* Check for a built-in function. */
10467 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10469 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10470 if (CALL_WITH_BOUNDS_P (exp
))
10471 return expand_builtin_with_bounds (exp
, target
, subtarget
,
10474 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10477 return expand_call (exp
, target
, ignore
);
10479 case VIEW_CONVERT_EXPR
:
10482 /* If we are converting to BLKmode, try to avoid an intermediate
10483 temporary by fetching an inner memory reference. */
10484 if (mode
== BLKmode
10485 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10486 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10487 && handled_component_p (treeop0
))
10489 machine_mode mode1
;
10490 HOST_WIDE_INT bitsize
, bitpos
;
10495 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10496 &offset
, &mode1
, &unsignedp
, &volatilep
,
10500 /* ??? We should work harder and deal with non-zero offsets. */
10502 && (bitpos
% BITS_PER_UNIT
) == 0
10504 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10506 /* See the normal_inner_ref case for the rationale. */
10508 = expand_expr_real (tem
,
10509 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10510 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10512 && modifier
!= EXPAND_STACK_PARM
10513 ? target
: NULL_RTX
),
10515 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10518 if (MEM_P (orig_op0
))
10522 /* Get a reference to just this component. */
10523 if (modifier
== EXPAND_CONST_ADDRESS
10524 || modifier
== EXPAND_SUM
10525 || modifier
== EXPAND_INITIALIZER
)
10526 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10528 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10530 if (op0
== orig_op0
)
10531 op0
= copy_rtx (op0
);
10533 set_mem_attributes (op0
, treeop0
, 0);
10534 if (REG_P (XEXP (op0
, 0)))
10535 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10537 MEM_VOLATILE_P (op0
) |= volatilep
;
10543 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10544 NULL
, inner_reference_p
);
10546 /* If the input and output modes are both the same, we are done. */
10547 if (mode
== GET_MODE (op0
))
10549 /* If neither mode is BLKmode, and both modes are the same size
10550 then we can use gen_lowpart. */
10551 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10552 && (GET_MODE_PRECISION (mode
)
10553 == GET_MODE_PRECISION (GET_MODE (op0
)))
10554 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10556 if (GET_CODE (op0
) == SUBREG
)
10557 op0
= force_reg (GET_MODE (op0
), op0
);
10558 temp
= gen_lowpart_common (mode
, op0
);
10563 if (!REG_P (op0
) && !MEM_P (op0
))
10564 op0
= force_reg (GET_MODE (op0
), op0
);
10565 op0
= gen_lowpart (mode
, op0
);
10568 /* If both types are integral, convert from one mode to the other. */
10569 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10570 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10571 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10572 /* If the output type is a bit-field type, do an extraction. */
10573 else if (reduce_bit_field
)
10574 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10575 TYPE_UNSIGNED (type
), NULL_RTX
,
10577 /* As a last resort, spill op0 to memory, and reload it in a
10579 else if (!MEM_P (op0
))
10581 /* If the operand is not a MEM, force it into memory. Since we
10582 are going to be changing the mode of the MEM, don't call
10583 force_const_mem for constants because we don't allow pool
10584 constants to change mode. */
10585 tree inner_type
= TREE_TYPE (treeop0
);
10587 gcc_assert (!TREE_ADDRESSABLE (exp
));
10589 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10591 = assign_stack_temp_for_type
10592 (TYPE_MODE (inner_type
),
10593 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10595 emit_move_insn (target
, op0
);
10599 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10600 output type is such that the operand is known to be aligned, indicate
10601 that it is. Otherwise, we need only be concerned about alignment for
10602 non-BLKmode results. */
10605 enum insn_code icode
;
10607 if (TYPE_ALIGN_OK (type
))
10609 /* ??? Copying the MEM without substantially changing it might
10610 run afoul of the code handling volatile memory references in
10611 store_expr, which assumes that TARGET is returned unmodified
10612 if it has been used. */
10613 op0
= copy_rtx (op0
);
10614 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10616 else if (modifier
!= EXPAND_WRITE
10617 && modifier
!= EXPAND_MEMORY
10618 && !inner_reference_p
10620 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10622 /* If the target does have special handling for unaligned
10623 loads of mode then use them. */
10624 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10625 != CODE_FOR_nothing
)
10629 op0
= adjust_address (op0
, mode
, 0);
10630 /* We've already validated the memory, and we're creating a
10631 new pseudo destination. The predicates really can't
10633 reg
= gen_reg_rtx (mode
);
10635 /* Nor can the insn generator. */
10636 rtx_insn
*insn
= GEN_FCN (icode
) (reg
, op0
);
10640 else if (STRICT_ALIGNMENT
)
10642 tree inner_type
= TREE_TYPE (treeop0
);
10643 HOST_WIDE_INT temp_size
10644 = MAX (int_size_in_bytes (inner_type
),
10645 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10647 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10648 rtx new_with_op0_mode
10649 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10651 gcc_assert (!TREE_ADDRESSABLE (exp
));
10653 if (GET_MODE (op0
) == BLKmode
)
10654 emit_block_move (new_with_op0_mode
, op0
,
10655 GEN_INT (GET_MODE_SIZE (mode
)),
10656 (modifier
== EXPAND_STACK_PARM
10657 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10659 emit_move_insn (new_with_op0_mode
, op0
);
10665 op0
= adjust_address (op0
, mode
, 0);
10672 tree lhs
= treeop0
;
10673 tree rhs
= treeop1
;
10674 gcc_assert (ignore
);
10676 /* Check for |= or &= of a bitfield of size one into another bitfield
10677 of size 1. In this case, (unless we need the result of the
10678 assignment) we can do this more efficiently with a
10679 test followed by an assignment, if necessary.
10681 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10682 things change so we do, this code should be enhanced to
10684 if (TREE_CODE (lhs
) == COMPONENT_REF
10685 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10686 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10687 && TREE_OPERAND (rhs
, 0) == lhs
10688 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10689 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10690 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10692 rtx_code_label
*label
= gen_label_rtx ();
10693 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10694 do_jump (TREE_OPERAND (rhs
, 1),
10696 value
? 0 : label
, -1);
10697 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10699 do_pending_stack_adjust ();
10700 emit_label (label
);
10704 expand_assignment (lhs
, rhs
, false);
10709 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10711 case REALPART_EXPR
:
10712 op0
= expand_normal (treeop0
);
10713 return read_complex_part (op0
, false);
10715 case IMAGPART_EXPR
:
10716 op0
= expand_normal (treeop0
);
10717 return read_complex_part (op0
, true);
10724 /* Expanded in cfgexpand.c. */
10725 gcc_unreachable ();
10727 case TRY_CATCH_EXPR
:
10729 case EH_FILTER_EXPR
:
10730 case TRY_FINALLY_EXPR
:
10731 /* Lowered by tree-eh.c. */
10732 gcc_unreachable ();
10734 case WITH_CLEANUP_EXPR
:
10735 case CLEANUP_POINT_EXPR
:
10737 case CASE_LABEL_EXPR
:
10742 case COMPOUND_EXPR
:
10743 case PREINCREMENT_EXPR
:
10744 case PREDECREMENT_EXPR
:
10745 case POSTINCREMENT_EXPR
:
10746 case POSTDECREMENT_EXPR
:
10749 case COMPOUND_LITERAL_EXPR
:
10750 /* Lowered by gimplify.c. */
10751 gcc_unreachable ();
10754 /* Function descriptors are not valid except for as
10755 initialization constants, and should not be expanded. */
10756 gcc_unreachable ();
10758 case WITH_SIZE_EXPR
:
10759 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10760 have pulled out the size to use in whatever context it needed. */
10761 return expand_expr_real (treeop0
, original_target
, tmode
,
10762 modifier
, alt_rtl
, inner_reference_p
);
10765 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10769 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10770 signedness of TYPE), possibly returning the result in TARGET. */
10772 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10774 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10775 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10777 /* For constant values, reduce using build_int_cst_type. */
10778 if (CONST_INT_P (exp
))
10780 HOST_WIDE_INT value
= INTVAL (exp
);
10781 tree t
= build_int_cst_type (type
, value
);
10782 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10784 else if (TYPE_UNSIGNED (type
))
10786 machine_mode mode
= GET_MODE (exp
);
10787 rtx mask
= immed_wide_int_const
10788 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
10789 return expand_and (mode
, exp
, mask
, target
);
10793 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10794 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10795 exp
, count
, target
, 0);
10796 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10797 exp
, count
, target
, 0);
10801 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10802 when applied to the address of EXP produces an address known to be
10803 aligned more than BIGGEST_ALIGNMENT. */
10806 is_aligning_offset (const_tree offset
, const_tree exp
)
10808 /* Strip off any conversions. */
10809 while (CONVERT_EXPR_P (offset
))
10810 offset
= TREE_OPERAND (offset
, 0);
10812 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10813 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10814 if (TREE_CODE (offset
) != BIT_AND_EXPR
10815 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10816 || compare_tree_int (TREE_OPERAND (offset
, 1),
10817 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10818 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10821 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10822 It must be NEGATE_EXPR. Then strip any more conversions. */
10823 offset
= TREE_OPERAND (offset
, 0);
10824 while (CONVERT_EXPR_P (offset
))
10825 offset
= TREE_OPERAND (offset
, 0);
10827 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10830 offset
= TREE_OPERAND (offset
, 0);
10831 while (CONVERT_EXPR_P (offset
))
10832 offset
= TREE_OPERAND (offset
, 0);
10834 /* This must now be the address of EXP. */
10835 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10838 /* Return the tree node if an ARG corresponds to a string constant or zero
10839 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10840 in bytes within the string that ARG is accessing. The type of the
10841 offset will be `sizetype'. */
10844 string_constant (tree arg
, tree
*ptr_offset
)
10846 tree array
, offset
, lower_bound
;
10849 if (TREE_CODE (arg
) == ADDR_EXPR
)
10851 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10853 *ptr_offset
= size_zero_node
;
10854 return TREE_OPERAND (arg
, 0);
10856 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10858 array
= TREE_OPERAND (arg
, 0);
10859 offset
= size_zero_node
;
10861 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10863 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10864 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10865 if (TREE_CODE (array
) != STRING_CST
10866 && TREE_CODE (array
) != VAR_DECL
)
10869 /* Check if the array has a nonzero lower bound. */
10870 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10871 if (!integer_zerop (lower_bound
))
10873 /* If the offset and base aren't both constants, return 0. */
10874 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10876 if (TREE_CODE (offset
) != INTEGER_CST
)
10878 /* Adjust offset by the lower bound. */
10879 offset
= size_diffop (fold_convert (sizetype
, offset
),
10880 fold_convert (sizetype
, lower_bound
));
10883 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10885 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10886 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10887 if (TREE_CODE (array
) != ADDR_EXPR
)
10889 array
= TREE_OPERAND (array
, 0);
10890 if (TREE_CODE (array
) != STRING_CST
10891 && TREE_CODE (array
) != VAR_DECL
)
10897 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10899 tree arg0
= TREE_OPERAND (arg
, 0);
10900 tree arg1
= TREE_OPERAND (arg
, 1);
10905 if (TREE_CODE (arg0
) == ADDR_EXPR
10906 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10907 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10909 array
= TREE_OPERAND (arg0
, 0);
10912 else if (TREE_CODE (arg1
) == ADDR_EXPR
10913 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10914 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10916 array
= TREE_OPERAND (arg1
, 0);
10925 if (TREE_CODE (array
) == STRING_CST
)
10927 *ptr_offset
= fold_convert (sizetype
, offset
);
10930 else if (TREE_CODE (array
) == VAR_DECL
10931 || TREE_CODE (array
) == CONST_DECL
)
10934 tree init
= ctor_for_folding (array
);
10936 /* Variables initialized to string literals can be handled too. */
10937 if (init
== error_mark_node
10939 || TREE_CODE (init
) != STRING_CST
)
10942 /* Avoid const char foo[4] = "abcde"; */
10943 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10944 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10945 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10946 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10949 /* If variable is bigger than the string literal, OFFSET must be constant
10950 and inside of the bounds of the string literal. */
10951 offset
= fold_convert (sizetype
, offset
);
10952 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10953 && (! tree_fits_uhwi_p (offset
)
10954 || compare_tree_int (offset
, length
) >= 0))
10957 *ptr_offset
= offset
;
10964 /* Generate code to calculate OPS, and exploded expression
10965 using a store-flag instruction and return an rtx for the result.
10966 OPS reflects a comparison.
10968 If TARGET is nonzero, store the result there if convenient.
10970 Return zero if there is no suitable set-flag instruction
10971 available on this machine.
10973 Once expand_expr has been called on the arguments of the comparison,
10974 we are committed to doing the store flag, since it is not safe to
10975 re-evaluate the expression. We emit the store-flag insn by calling
10976 emit_store_flag, but only expand the arguments if we have a reason
10977 to believe that emit_store_flag will be successful. If we think that
10978 it will, but it isn't, we have to simulate the store-flag with a
10979 set/jump/set sequence. */
10982 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
10984 enum rtx_code code
;
10985 tree arg0
, arg1
, type
;
10986 machine_mode operand_mode
;
10989 rtx subtarget
= target
;
10990 location_t loc
= ops
->location
;
10995 /* Don't crash if the comparison was erroneous. */
10996 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10999 type
= TREE_TYPE (arg0
);
11000 operand_mode
= TYPE_MODE (type
);
11001 unsignedp
= TYPE_UNSIGNED (type
);
11003 /* We won't bother with BLKmode store-flag operations because it would mean
11004 passing a lot of information to emit_store_flag. */
11005 if (operand_mode
== BLKmode
)
11008 /* We won't bother with store-flag operations involving function pointers
11009 when function pointers must be canonicalized before comparisons. */
11010 if (targetm
.have_canonicalize_funcptr_for_compare ()
11011 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
11012 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
11014 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
11015 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
11016 == FUNCTION_TYPE
))))
11022 /* For vector typed comparisons emit code to generate the desired
11023 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
11024 expander for this. */
11025 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
11027 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
11028 tree if_true
= constant_boolean_node (true, ops
->type
);
11029 tree if_false
= constant_boolean_node (false, ops
->type
);
11030 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
11033 /* Get the rtx comparison code to use. We know that EXP is a comparison
11034 operation of some type. Some comparisons against 1 and -1 can be
11035 converted to comparisons with zero. Do so here so that the tests
11036 below will be aware that we have a comparison with zero. These
11037 tests will not catch constants in the first operand, but constants
11038 are rarely passed as the first operand. */
11049 if (integer_onep (arg1
))
11050 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
11052 code
= unsignedp
? LTU
: LT
;
11055 if (! unsignedp
&& integer_all_onesp (arg1
))
11056 arg1
= integer_zero_node
, code
= LT
;
11058 code
= unsignedp
? LEU
: LE
;
11061 if (! unsignedp
&& integer_all_onesp (arg1
))
11062 arg1
= integer_zero_node
, code
= GE
;
11064 code
= unsignedp
? GTU
: GT
;
11067 if (integer_onep (arg1
))
11068 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
11070 code
= unsignedp
? GEU
: GE
;
11073 case UNORDERED_EXPR
:
11099 gcc_unreachable ();
11102 /* Put a constant second. */
11103 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11104 || TREE_CODE (arg0
) == FIXED_CST
)
11106 std::swap (arg0
, arg1
);
11107 code
= swap_condition (code
);
11110 /* If this is an equality or inequality test of a single bit, we can
11111 do this by shifting the bit being tested to the low-order bit and
11112 masking the result with the constant 1. If the condition was EQ,
11113 we xor it with 1. This does not require an scc insn and is faster
11114 than an scc insn even if we have it.
11116 The code to make this transformation was moved into fold_single_bit_test,
11117 so we just call into the folder and expand its result. */
11119 if ((code
== NE
|| code
== EQ
)
11120 && integer_zerop (arg1
)
11121 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11123 gimple
*srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11125 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11127 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11128 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11129 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11130 gimple_assign_rhs1 (srcstmt
),
11131 gimple_assign_rhs2 (srcstmt
));
11132 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11134 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11138 if (! get_subtarget (target
)
11139 || GET_MODE (subtarget
) != operand_mode
)
11142 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11145 target
= gen_reg_rtx (mode
);
11147 /* Try a cstore if possible. */
11148 return emit_store_flag_force (target
, code
, op0
, op1
,
11149 operand_mode
, unsignedp
,
11150 (TYPE_PRECISION (ops
->type
) == 1
11151 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11154 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11155 0 otherwise (i.e. if there is no casesi instruction).
11157 DEFAULT_PROBABILITY is the probability of jumping to the default
11160 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11161 rtx table_label
, rtx default_label
, rtx fallback_label
,
11162 int default_probability
)
11164 struct expand_operand ops
[5];
11165 machine_mode index_mode
= SImode
;
11166 rtx op1
, op2
, index
;
11168 if (! targetm
.have_casesi ())
11171 /* Convert the index to SImode. */
11172 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11174 machine_mode omode
= TYPE_MODE (index_type
);
11175 rtx rangertx
= expand_normal (range
);
11177 /* We must handle the endpoints in the original mode. */
11178 index_expr
= build2 (MINUS_EXPR
, index_type
,
11179 index_expr
, minval
);
11180 minval
= integer_zero_node
;
11181 index
= expand_normal (index_expr
);
11183 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11184 omode
, 1, default_label
,
11185 default_probability
);
11186 /* Now we can safely truncate. */
11187 index
= convert_to_mode (index_mode
, index
, 0);
11191 if (TYPE_MODE (index_type
) != index_mode
)
11193 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11194 index_expr
= fold_convert (index_type
, index_expr
);
11197 index
= expand_normal (index_expr
);
11200 do_pending_stack_adjust ();
11202 op1
= expand_normal (minval
);
11203 op2
= expand_normal (range
);
11205 create_input_operand (&ops
[0], index
, index_mode
);
11206 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11207 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11208 create_fixed_operand (&ops
[3], table_label
);
11209 create_fixed_operand (&ops
[4], (default_label
11211 : fallback_label
));
11212 expand_jump_insn (targetm
.code_for_casesi
, 5, ops
);
11216 /* Attempt to generate a tablejump instruction; same concept. */
11217 /* Subroutine of the next function.
11219 INDEX is the value being switched on, with the lowest value
11220 in the table already subtracted.
11221 MODE is its expected mode (needed if INDEX is constant).
11222 RANGE is the length of the jump table.
11223 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11225 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11226 index value is out of range.
11227 DEFAULT_PROBABILITY is the probability of jumping to
11228 the default label. */
11231 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
11232 rtx default_label
, int default_probability
)
11236 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11237 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11239 /* Do an unsigned comparison (in the proper mode) between the index
11240 expression and the value which represents the length of the range.
11241 Since we just finished subtracting the lower bound of the range
11242 from the index expression, this comparison allows us to simultaneously
11243 check that the original index expression value is both greater than
11244 or equal to the minimum value of the range and less than or equal to
11245 the maximum value of the range. */
11248 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11249 default_label
, default_probability
);
11252 /* If index is in range, it must fit in Pmode.
11253 Convert to Pmode so we can index with it. */
11255 index
= convert_to_mode (Pmode
, index
, 1);
11257 /* Don't let a MEM slip through, because then INDEX that comes
11258 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11259 and break_out_memory_refs will go to work on it and mess it up. */
11260 #ifdef PIC_CASE_VECTOR_ADDRESS
11261 if (flag_pic
&& !REG_P (index
))
11262 index
= copy_to_mode_reg (Pmode
, index
);
11265 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11266 GET_MODE_SIZE, because this indicates how large insns are. The other
11267 uses should all be Pmode, because they are addresses. This code
11268 could fail if addresses and insns are not the same size. */
11269 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11270 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11272 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11273 gen_rtx_LABEL_REF (Pmode
, table_label
));
11275 #ifdef PIC_CASE_VECTOR_ADDRESS
11277 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11280 index
= memory_address (CASE_VECTOR_MODE
, index
);
11281 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11282 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11283 convert_move (temp
, vector
, 0);
11285 emit_jump_insn (targetm
.gen_tablejump (temp
, table_label
));
11287 /* If we are generating PIC code or if the table is PC-relative, the
11288 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11289 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11294 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11295 rtx table_label
, rtx default_label
, int default_probability
)
11299 if (! targetm
.have_tablejump ())
11302 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11303 fold_convert (index_type
, index_expr
),
11304 fold_convert (index_type
, minval
));
11305 index
= expand_normal (index_expr
);
11306 do_pending_stack_adjust ();
11308 do_tablejump (index
, TYPE_MODE (index_type
),
11309 convert_modes (TYPE_MODE (index_type
),
11310 TYPE_MODE (TREE_TYPE (range
)),
11311 expand_normal (range
),
11312 TYPE_UNSIGNED (TREE_TYPE (range
))),
11313 table_label
, default_label
, default_probability
);
11317 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11319 const_vector_from_tree (tree exp
)
11325 machine_mode inner
, mode
;
11327 mode
= TYPE_MODE (TREE_TYPE (exp
));
11329 if (initializer_zerop (exp
))
11330 return CONST0_RTX (mode
);
11332 units
= GET_MODE_NUNITS (mode
);
11333 inner
= GET_MODE_INNER (mode
);
11335 v
= rtvec_alloc (units
);
11337 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11339 elt
= VECTOR_CST_ELT (exp
, i
);
11341 if (TREE_CODE (elt
) == REAL_CST
)
11342 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11344 else if (TREE_CODE (elt
) == FIXED_CST
)
11345 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11348 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11351 return gen_rtx_CONST_VECTOR (mode
, v
);
11354 /* Build a decl for a personality function given a language prefix. */
11357 build_personality_function (const char *lang
)
11359 const char *unwind_and_version
;
11363 switch (targetm_common
.except_unwind_info (&global_options
))
11368 unwind_and_version
= "_sj0";
11372 unwind_and_version
= "_v0";
11375 unwind_and_version
= "_seh0";
11378 gcc_unreachable ();
11381 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11383 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11384 long_long_unsigned_type_node
,
11385 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11386 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11387 get_identifier (name
), type
);
11388 DECL_ARTIFICIAL (decl
) = 1;
11389 DECL_EXTERNAL (decl
) = 1;
11390 TREE_PUBLIC (decl
) = 1;
11392 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11393 are the flags assigned by targetm.encode_section_info. */
11394 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11399 /* Extracts the personality function of DECL and returns the corresponding
11403 get_personality_function (tree decl
)
11405 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11406 enum eh_personality_kind pk
;
11408 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11409 if (pk
== eh_personality_none
)
11413 && pk
== eh_personality_any
)
11414 personality
= lang_hooks
.eh_personality ();
11416 if (pk
== eh_personality_lang
)
11417 gcc_assert (personality
!= NULL_TREE
);
11419 return XEXP (DECL_RTL (personality
), 0);
11422 /* Returns a tree for the size of EXP in bytes. */
11425 tree_expr_size (const_tree exp
)
11428 && DECL_SIZE_UNIT (exp
) != 0)
11429 return DECL_SIZE_UNIT (exp
);
11431 return size_in_bytes (TREE_TYPE (exp
));
11434 /* Return an rtx for the size in bytes of the value of EXP. */
11437 expr_size (tree exp
)
11441 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11442 size
= TREE_OPERAND (exp
, 1);
11445 size
= tree_expr_size (exp
);
11447 gcc_assert (size
== SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, exp
));
11450 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), EXPAND_NORMAL
);
11453 /* Return a wide integer for the size in bytes of the value of EXP, or -1
11454 if the size can vary or is larger than an integer. */
11456 static HOST_WIDE_INT
11457 int_expr_size (tree exp
)
11461 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11462 size
= TREE_OPERAND (exp
, 1);
11465 size
= tree_expr_size (exp
);
11469 if (size
== 0 || !tree_fits_shwi_p (size
))
11472 return tree_to_shwi (size
);
11475 #include "gt-expr.h"