1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2014 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"
27 #include "stringpool.h"
28 #include "stor-layout.h"
33 #include "hard-reg-set.h"
36 #include "insn-config.h"
37 #include "insn-attr.h"
38 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
44 #include "typeclass.h"
46 #include "langhooks.h"
49 #include "tree-iterator.h"
50 #include "basic-block.h"
51 #include "tree-ssa-alias.h"
52 #include "internal-fn.h"
53 #include "gimple-expr.h"
56 #include "gimple-ssa.h"
58 #include "tree-ssanames.h"
60 #include "common/common-target.h"
63 #include "diagnostic.h"
64 #include "tree-ssa-live.h"
65 #include "tree-outof-ssa.h"
66 #include "target-globals.h"
68 #include "tree-ssa-address.h"
69 #include "cfgexpand.h"
73 #ifndef STACK_PUSH_CODE
74 #ifdef STACK_GROWS_DOWNWARD
75 #define STACK_PUSH_CODE PRE_DEC
77 #define STACK_PUSH_CODE PRE_INC
82 /* If this is nonzero, we do not bother generating VOLATILE
83 around volatile memory references, and we are willing to
84 output indirect addresses. If cse is to follow, we reject
85 indirect addresses so a useful potential cse is generated;
86 if it is used only once, instruction combination will produce
87 the same indirect address eventually. */
90 /* This structure is used by move_by_pieces to describe the move to
92 struct move_by_pieces_d
101 int explicit_inc_from
;
102 unsigned HOST_WIDE_INT len
;
103 HOST_WIDE_INT offset
;
107 /* This structure is used by store_by_pieces to describe the clear to
110 struct store_by_pieces_d
116 unsigned HOST_WIDE_INT len
;
117 HOST_WIDE_INT offset
;
118 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
);
123 static void move_by_pieces_1 (insn_gen_fn
, machine_mode
,
124 struct move_by_pieces_d
*);
125 static bool block_move_libcall_safe_for_call_parm (void);
126 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
,
127 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
128 unsigned HOST_WIDE_INT
);
129 static tree
emit_block_move_libcall_fn (int);
130 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
131 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, enum machine_mode
);
132 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
133 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
134 static void store_by_pieces_2 (insn_gen_fn
, machine_mode
,
135 struct store_by_pieces_d
*);
136 static tree
clear_storage_libcall_fn (int);
137 static rtx_insn
*compress_float_constant (rtx
, rtx
);
138 static rtx
get_subtarget (rtx
);
139 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
140 HOST_WIDE_INT
, enum machine_mode
,
141 tree
, int, alias_set_type
);
142 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
143 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
144 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
145 enum machine_mode
, tree
, alias_set_type
, bool);
147 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
149 static int is_aligning_offset (const_tree
, const_tree
);
150 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
151 enum expand_modifier
);
152 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
153 static rtx
do_store_flag (sepops
, rtx
, enum machine_mode
);
155 static void emit_single_push_insn (enum machine_mode
, rtx
, tree
);
157 static void do_tablejump (rtx
, enum machine_mode
, rtx
, rtx
, rtx
, int);
158 static rtx
const_vector_from_tree (tree
);
159 static void write_complex_part (rtx
, rtx
, bool);
161 /* This macro is used to determine whether move_by_pieces should be called
162 to perform a structure copy. */
163 #ifndef MOVE_BY_PIECES_P
164 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
165 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
166 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
169 /* This macro is used to determine whether clear_by_pieces should be
170 called to clear storage. */
171 #ifndef CLEAR_BY_PIECES_P
172 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
173 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
174 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
177 /* This macro is used to determine whether store_by_pieces should be
178 called to "memset" storage with byte values other than zero. */
179 #ifndef SET_BY_PIECES_P
180 #define SET_BY_PIECES_P(SIZE, ALIGN) \
181 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
182 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
185 /* This macro is used to determine whether store_by_pieces should be
186 called to "memcpy" storage when the source is a constant string. */
187 #ifndef STORE_BY_PIECES_P
188 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
189 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
190 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
193 /* This is run to set up which modes can be used
194 directly in memory and to initialize the block move optab. It is run
195 at the beginning of compilation and when the target is reinitialized. */
198 init_expr_target (void)
201 enum machine_mode mode
;
206 /* Try indexing by frame ptr and try by stack ptr.
207 It is known that on the Convex the stack ptr isn't a valid index.
208 With luck, one or the other is valid on any machine. */
209 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
210 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
212 /* A scratch register we can modify in-place below to avoid
213 useless RTL allocations. */
214 reg
= gen_rtx_REG (VOIDmode
, -1);
216 insn
= rtx_alloc (INSN
);
217 pat
= gen_rtx_SET (VOIDmode
, NULL_RTX
, NULL_RTX
);
218 PATTERN (insn
) = pat
;
220 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
221 mode
= (enum machine_mode
) ((int) mode
+ 1))
225 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
226 PUT_MODE (mem
, mode
);
227 PUT_MODE (mem1
, mode
);
228 PUT_MODE (reg
, mode
);
230 /* See if there is some register that can be used in this mode and
231 directly loaded or stored from memory. */
233 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
234 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
235 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
238 if (! HARD_REGNO_MODE_OK (regno
, mode
))
241 SET_REGNO (reg
, regno
);
244 SET_DEST (pat
) = reg
;
245 if (recog (pat
, insn
, &num_clobbers
) >= 0)
246 direct_load
[(int) mode
] = 1;
248 SET_SRC (pat
) = mem1
;
249 SET_DEST (pat
) = reg
;
250 if (recog (pat
, insn
, &num_clobbers
) >= 0)
251 direct_load
[(int) mode
] = 1;
254 SET_DEST (pat
) = mem
;
255 if (recog (pat
, insn
, &num_clobbers
) >= 0)
256 direct_store
[(int) mode
] = 1;
259 SET_DEST (pat
) = mem1
;
260 if (recog (pat
, insn
, &num_clobbers
) >= 0)
261 direct_store
[(int) mode
] = 1;
265 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
267 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
268 mode
= GET_MODE_WIDER_MODE (mode
))
270 enum machine_mode srcmode
;
271 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
272 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
276 ic
= can_extend_p (mode
, srcmode
, 0);
277 if (ic
== CODE_FOR_nothing
)
280 PUT_MODE (mem
, srcmode
);
282 if (insn_operand_matches (ic
, 1, mem
))
283 float_extend_from_mem
[mode
][srcmode
] = true;
288 /* This is run at the start of compiling a function. */
293 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
296 /* Copy data from FROM to TO, where the machine modes are not the same.
297 Both modes may be integer, or both may be floating, or both may be
299 UNSIGNEDP should be nonzero if FROM is an unsigned type.
300 This causes zero-extension instead of sign-extension. */
303 convert_move (rtx to
, rtx from
, int unsignedp
)
305 enum machine_mode to_mode
= GET_MODE (to
);
306 enum machine_mode from_mode
= GET_MODE (from
);
307 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
308 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
312 /* rtx code for making an equivalent value. */
313 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
314 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
317 gcc_assert (to_real
== from_real
);
318 gcc_assert (to_mode
!= BLKmode
);
319 gcc_assert (from_mode
!= BLKmode
);
321 /* If the source and destination are already the same, then there's
326 /* If FROM is a SUBREG that indicates that we have already done at least
327 the required extension, strip it. We don't handle such SUBREGs as
330 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
331 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
332 >= GET_MODE_PRECISION (to_mode
))
333 && SUBREG_CHECK_PROMOTED_SIGN (from
, unsignedp
))
334 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
336 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
338 if (to_mode
== from_mode
339 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
341 emit_move_insn (to
, from
);
345 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
347 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
349 if (VECTOR_MODE_P (to_mode
))
350 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
352 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
354 emit_move_insn (to
, from
);
358 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
360 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
361 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
371 gcc_assert ((GET_MODE_PRECISION (from_mode
)
372 != GET_MODE_PRECISION (to_mode
))
373 || (DECIMAL_FLOAT_MODE_P (from_mode
)
374 != DECIMAL_FLOAT_MODE_P (to_mode
)));
376 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
377 /* Conversion between decimal float and binary float, same size. */
378 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
379 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
384 /* Try converting directly if the insn is supported. */
386 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
387 if (code
!= CODE_FOR_nothing
)
389 emit_unop_insn (code
, to
, from
,
390 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
394 /* Otherwise use a libcall. */
395 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
397 /* Is this conversion implemented yet? */
398 gcc_assert (libcall
);
401 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
403 insns
= get_insns ();
405 emit_libcall_block (insns
, to
, value
,
406 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
408 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
412 /* Handle pointer conversion. */ /* SPEE 900220. */
413 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
417 if (GET_MODE_PRECISION (from_mode
) > GET_MODE_PRECISION (to_mode
))
424 if (convert_optab_handler (ctab
, to_mode
, from_mode
)
427 emit_unop_insn (convert_optab_handler (ctab
, to_mode
, from_mode
),
433 /* Targets are expected to provide conversion insns between PxImode and
434 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
435 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
437 enum machine_mode full_mode
438 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
440 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
441 != CODE_FOR_nothing
);
443 if (full_mode
!= from_mode
)
444 from
= convert_to_mode (full_mode
, from
, unsignedp
);
445 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
449 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
452 enum machine_mode full_mode
453 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
454 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
455 enum insn_code icode
;
457 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
458 gcc_assert (icode
!= CODE_FOR_nothing
);
460 if (to_mode
== full_mode
)
462 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
466 new_from
= gen_reg_rtx (full_mode
);
467 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
469 /* else proceed to integer conversions below. */
470 from_mode
= full_mode
;
474 /* Make sure both are fixed-point modes or both are not. */
475 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
476 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
477 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
479 /* If we widen from_mode to to_mode and they are in the same class,
480 we won't saturate the result.
481 Otherwise, always saturate the result to play safe. */
482 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
483 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
484 expand_fixed_convert (to
, from
, 0, 0);
486 expand_fixed_convert (to
, from
, 0, 1);
490 /* Now both modes are integers. */
492 /* Handle expanding beyond a word. */
493 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
494 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
501 enum machine_mode lowpart_mode
;
502 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
504 /* Try converting directly if the insn is supported. */
505 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
508 /* If FROM is a SUBREG, put it into a register. Do this
509 so that we always generate the same set of insns for
510 better cse'ing; if an intermediate assignment occurred,
511 we won't be doing the operation directly on the SUBREG. */
512 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
513 from
= force_reg (from_mode
, from
);
514 emit_unop_insn (code
, to
, from
, equiv_code
);
517 /* Next, try converting via full word. */
518 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
519 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
520 != CODE_FOR_nothing
))
522 rtx word_to
= gen_reg_rtx (word_mode
);
525 if (reg_overlap_mentioned_p (to
, from
))
526 from
= force_reg (from_mode
, from
);
529 convert_move (word_to
, from
, unsignedp
);
530 emit_unop_insn (code
, to
, word_to
, equiv_code
);
534 /* No special multiword conversion insn; do it by hand. */
537 /* Since we will turn this into a no conflict block, we must ensure the
538 the source does not overlap the target so force it into an isolated
539 register when maybe so. Likewise for any MEM input, since the
540 conversion sequence might require several references to it and we
541 must ensure we're getting the same value every time. */
543 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
544 from
= force_reg (from_mode
, from
);
546 /* Get a copy of FROM widened to a word, if necessary. */
547 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
548 lowpart_mode
= word_mode
;
550 lowpart_mode
= from_mode
;
552 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
554 lowpart
= gen_lowpart (lowpart_mode
, to
);
555 emit_move_insn (lowpart
, lowfrom
);
557 /* Compute the value to put in each remaining word. */
559 fill_value
= const0_rtx
;
561 fill_value
= emit_store_flag_force (gen_reg_rtx (word_mode
),
562 LT
, lowfrom
, const0_rtx
,
563 lowpart_mode
, 0, -1);
565 /* Fill the remaining words. */
566 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
568 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
569 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
571 gcc_assert (subword
);
573 if (fill_value
!= subword
)
574 emit_move_insn (subword
, fill_value
);
577 insns
= get_insns ();
584 /* Truncating multi-word to a word or less. */
585 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
586 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
589 && ! MEM_VOLATILE_P (from
)
590 && direct_load
[(int) to_mode
]
591 && ! mode_dependent_address_p (XEXP (from
, 0),
592 MEM_ADDR_SPACE (from
)))
594 || GET_CODE (from
) == SUBREG
))
595 from
= force_reg (from_mode
, from
);
596 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
600 /* Now follow all the conversions between integers
601 no more than a word long. */
603 /* For truncation, usually we can just refer to FROM in a narrower mode. */
604 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
605 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
608 && ! MEM_VOLATILE_P (from
)
609 && direct_load
[(int) to_mode
]
610 && ! mode_dependent_address_p (XEXP (from
, 0),
611 MEM_ADDR_SPACE (from
)))
613 || GET_CODE (from
) == SUBREG
))
614 from
= force_reg (from_mode
, from
);
615 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
616 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
617 from
= copy_to_reg (from
);
618 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
622 /* Handle extension. */
623 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
625 /* Convert directly if that works. */
626 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
629 emit_unop_insn (code
, to
, from
, equiv_code
);
634 enum machine_mode intermediate
;
638 /* Search for a mode to convert via. */
639 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
640 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
641 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
643 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
644 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
645 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
646 != CODE_FOR_nothing
))
648 convert_move (to
, convert_to_mode (intermediate
, from
,
649 unsignedp
), unsignedp
);
653 /* No suitable intermediate mode.
654 Generate what we need with shifts. */
655 shift_amount
= (GET_MODE_PRECISION (to_mode
)
656 - GET_MODE_PRECISION (from_mode
));
657 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
658 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
660 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
663 emit_move_insn (to
, tmp
);
668 /* Support special truncate insns for certain modes. */
669 if (convert_optab_handler (trunc_optab
, to_mode
,
670 from_mode
) != CODE_FOR_nothing
)
672 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
677 /* Handle truncation of volatile memrefs, and so on;
678 the things that couldn't be truncated directly,
679 and for which there was no special instruction.
681 ??? Code above formerly short-circuited this, for most integer
682 mode pairs, with a force_reg in from_mode followed by a recursive
683 call to this routine. Appears always to have been wrong. */
684 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
686 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
687 emit_move_insn (to
, temp
);
691 /* Mode combination is not recognized. */
695 /* Return an rtx for a value that would result
696 from converting X to mode MODE.
697 Both X and MODE may be floating, or both integer.
698 UNSIGNEDP is nonzero if X is an unsigned value.
699 This can be done by referring to a part of X in place
700 or by copying to a new temporary with conversion. */
703 convert_to_mode (enum machine_mode mode
, rtx x
, int unsignedp
)
705 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
708 /* Return an rtx for a value that would result
709 from converting X from mode OLDMODE to mode MODE.
710 Both modes may be floating, or both integer.
711 UNSIGNEDP is nonzero if X is an unsigned value.
713 This can be done by referring to a part of X in place
714 or by copying to a new temporary with conversion.
716 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
719 convert_modes (enum machine_mode mode
, enum machine_mode oldmode
, rtx x
, int unsignedp
)
723 /* If FROM is a SUBREG that indicates that we have already done at least
724 the required extension, strip it. */
726 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
727 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
728 && SUBREG_CHECK_PROMOTED_SIGN (x
, unsignedp
))
729 x
= gen_lowpart (mode
, SUBREG_REG (x
));
731 if (GET_MODE (x
) != VOIDmode
)
732 oldmode
= GET_MODE (x
);
737 if (CONST_SCALAR_INT_P (x
) && GET_MODE_CLASS (mode
) == MODE_INT
)
739 /* If the caller did not tell us the old mode, then there is not
740 much to do with respect to canonicalization. We have to
741 assume that all the bits are significant. */
742 if (GET_MODE_CLASS (oldmode
) != MODE_INT
)
743 oldmode
= MAX_MODE_INT
;
744 wide_int w
= wide_int::from (std::make_pair (x
, oldmode
),
745 GET_MODE_PRECISION (mode
),
746 unsignedp
? UNSIGNED
: SIGNED
);
747 return immed_wide_int_const (w
, mode
);
750 /* We can do this with a gen_lowpart if both desired and current modes
751 are integer, and this is either a constant integer, a register, or a
753 if (GET_MODE_CLASS (mode
) == MODE_INT
754 && GET_MODE_CLASS (oldmode
) == MODE_INT
755 && GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
756 && ((MEM_P (x
) && !MEM_VOLATILE_P (x
) && direct_load
[(int) mode
])
758 && (!HARD_REGISTER_P (x
)
759 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
760 && TRULY_NOOP_TRUNCATION_MODES_P (mode
, GET_MODE (x
)))))
762 return gen_lowpart (mode
, x
);
764 /* Converting from integer constant into mode is always equivalent to an
766 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
768 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
769 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
772 temp
= gen_reg_rtx (mode
);
773 convert_move (temp
, x
, unsignedp
);
777 /* Return the largest alignment we can use for doing a move (or store)
778 of MAX_PIECES. ALIGN is the largest alignment we could use. */
781 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
783 enum machine_mode tmode
;
785 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
786 if (align
>= GET_MODE_ALIGNMENT (tmode
))
787 align
= GET_MODE_ALIGNMENT (tmode
);
790 enum machine_mode tmode
, xmode
;
792 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
794 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
795 if (GET_MODE_SIZE (tmode
) > max_pieces
796 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
799 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
805 /* Return the widest integer mode no wider than SIZE. If no such mode
806 can be found, return VOIDmode. */
808 static enum machine_mode
809 widest_int_mode_for_size (unsigned int size
)
811 enum machine_mode tmode
, mode
= VOIDmode
;
813 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
814 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
815 if (GET_MODE_SIZE (tmode
) < size
)
821 /* STORE_MAX_PIECES is the number of bytes at a time that we can
822 store efficiently. Due to internal GCC limitations, this is
823 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
824 for an immediate constant. */
826 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
828 /* Determine whether the LEN bytes can be moved by using several move
829 instructions. Return nonzero if a call to move_by_pieces should
833 can_move_by_pieces (unsigned HOST_WIDE_INT len ATTRIBUTE_UNUSED
,
834 unsigned int align ATTRIBUTE_UNUSED
)
836 return MOVE_BY_PIECES_P (len
, align
);
839 /* Generate several move instructions to copy LEN bytes from block FROM to
840 block TO. (These are MEM rtx's with BLKmode).
842 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
843 used to push FROM to the stack.
845 ALIGN is maximum stack alignment we can assume.
847 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
848 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
852 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
853 unsigned int align
, int endp
)
855 struct move_by_pieces_d data
;
856 enum machine_mode to_addr_mode
;
857 enum machine_mode from_addr_mode
= get_address_mode (from
);
858 rtx to_addr
, from_addr
= XEXP (from
, 0);
859 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
860 enum insn_code icode
;
862 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
865 data
.from_addr
= from_addr
;
868 to_addr_mode
= get_address_mode (to
);
869 to_addr
= XEXP (to
, 0);
872 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
873 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
875 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
879 to_addr_mode
= VOIDmode
;
883 #ifdef STACK_GROWS_DOWNWARD
889 data
.to_addr
= to_addr
;
892 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
893 || GET_CODE (from_addr
) == POST_INC
894 || GET_CODE (from_addr
) == POST_DEC
);
896 data
.explicit_inc_from
= 0;
897 data
.explicit_inc_to
= 0;
898 if (data
.reverse
) data
.offset
= len
;
901 /* If copying requires more than two move insns,
902 copy addresses to registers (to make displacements shorter)
903 and use post-increment if available. */
904 if (!(data
.autinc_from
&& data
.autinc_to
)
905 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
907 /* Find the mode of the largest move...
908 MODE might not be used depending on the definitions of the
909 USE_* macros below. */
910 enum machine_mode mode ATTRIBUTE_UNUSED
911 = widest_int_mode_for_size (max_size
);
913 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
915 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
916 plus_constant (from_addr_mode
,
918 data
.autinc_from
= 1;
919 data
.explicit_inc_from
= -1;
921 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
923 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
924 data
.autinc_from
= 1;
925 data
.explicit_inc_from
= 1;
927 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
928 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
929 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
931 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
932 plus_constant (to_addr_mode
,
935 data
.explicit_inc_to
= -1;
937 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
939 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
941 data
.explicit_inc_to
= 1;
943 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
944 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
947 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
949 /* First move what we can in the largest integer mode, then go to
950 successively smaller modes. */
952 while (max_size
> 1 && data
.len
> 0)
954 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
956 if (mode
== VOIDmode
)
959 icode
= optab_handler (mov_optab
, mode
);
960 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
961 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
963 max_size
= GET_MODE_SIZE (mode
);
966 /* The code above should have handled everything. */
967 gcc_assert (!data
.len
);
973 gcc_assert (!data
.reverse
);
978 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
979 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
981 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
982 plus_constant (to_addr_mode
,
986 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
993 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1001 /* Return number of insns required to move L bytes by pieces.
1002 ALIGN (in bits) is maximum alignment we can assume. */
1004 unsigned HOST_WIDE_INT
1005 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1006 unsigned int max_size
)
1008 unsigned HOST_WIDE_INT n_insns
= 0;
1010 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1012 while (max_size
> 1 && l
> 0)
1014 enum machine_mode mode
;
1015 enum insn_code icode
;
1017 mode
= widest_int_mode_for_size (max_size
);
1019 if (mode
== VOIDmode
)
1022 icode
= optab_handler (mov_optab
, mode
);
1023 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1024 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1026 max_size
= GET_MODE_SIZE (mode
);
1033 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1034 with move instructions for mode MODE. GENFUN is the gen_... function
1035 to make a move insn for that mode. DATA has all the other info. */
1038 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
1039 struct move_by_pieces_d
*data
)
1041 unsigned int size
= GET_MODE_SIZE (mode
);
1042 rtx to1
= NULL_RTX
, from1
;
1044 while (data
->len
>= size
)
1047 data
->offset
-= size
;
1051 if (data
->autinc_to
)
1052 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1055 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1058 if (data
->autinc_from
)
1059 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1062 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1064 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1065 emit_insn (gen_add2_insn (data
->to_addr
,
1066 gen_int_mode (-(HOST_WIDE_INT
) size
,
1067 GET_MODE (data
->to_addr
))));
1068 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1069 emit_insn (gen_add2_insn (data
->from_addr
,
1070 gen_int_mode (-(HOST_WIDE_INT
) size
,
1071 GET_MODE (data
->from_addr
))));
1074 emit_insn ((*genfun
) (to1
, from1
));
1077 #ifdef PUSH_ROUNDING
1078 emit_single_push_insn (mode
, from1
, NULL
);
1084 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1085 emit_insn (gen_add2_insn (data
->to_addr
,
1087 GET_MODE (data
->to_addr
))));
1088 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1089 emit_insn (gen_add2_insn (data
->from_addr
,
1091 GET_MODE (data
->from_addr
))));
1093 if (! data
->reverse
)
1094 data
->offset
+= size
;
1100 /* Emit code to move a block Y to a block X. This may be done with
1101 string-move instructions, with multiple scalar move instructions,
1102 or with a library call.
1104 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1105 SIZE is an rtx that says how long they are.
1106 ALIGN is the maximum alignment we can assume they have.
1107 METHOD describes what kind of copy this is, and what mechanisms may be used.
1108 MIN_SIZE is the minimal size of block to move
1109 MAX_SIZE is the maximal size of block to move, if it can not be represented
1110 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1112 Return the address of the new block, if memcpy is called and returns it,
1116 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1117 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1118 unsigned HOST_WIDE_INT min_size
,
1119 unsigned HOST_WIDE_INT max_size
,
1120 unsigned HOST_WIDE_INT probable_max_size
)
1127 if (CONST_INT_P (size
)
1128 && INTVAL (size
) == 0)
1133 case BLOCK_OP_NORMAL
:
1134 case BLOCK_OP_TAILCALL
:
1135 may_use_call
= true;
1138 case BLOCK_OP_CALL_PARM
:
1139 may_use_call
= block_move_libcall_safe_for_call_parm ();
1141 /* Make inhibit_defer_pop nonzero around the library call
1142 to force it to pop the arguments right away. */
1146 case BLOCK_OP_NO_LIBCALL
:
1147 may_use_call
= false;
1154 gcc_assert (MEM_P (x
) && MEM_P (y
));
1155 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1156 gcc_assert (align
>= BITS_PER_UNIT
);
1158 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1159 block copy is more efficient for other large modes, e.g. DCmode. */
1160 x
= adjust_address (x
, BLKmode
, 0);
1161 y
= adjust_address (y
, BLKmode
, 0);
1163 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1164 can be incorrect is coming from __builtin_memcpy. */
1165 if (CONST_INT_P (size
))
1167 x
= shallow_copy_rtx (x
);
1168 y
= shallow_copy_rtx (y
);
1169 set_mem_size (x
, INTVAL (size
));
1170 set_mem_size (y
, INTVAL (size
));
1173 if (CONST_INT_P (size
) && MOVE_BY_PIECES_P (INTVAL (size
), align
))
1174 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1175 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1176 expected_align
, expected_size
,
1177 min_size
, max_size
, probable_max_size
))
1179 else if (may_use_call
1180 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1181 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1183 /* Since x and y are passed to a libcall, mark the corresponding
1184 tree EXPR as addressable. */
1185 tree y_expr
= MEM_EXPR (y
);
1186 tree x_expr
= MEM_EXPR (x
);
1188 mark_addressable (y_expr
);
1190 mark_addressable (x_expr
);
1191 retval
= emit_block_move_via_libcall (x
, y
, size
,
1192 method
== BLOCK_OP_TAILCALL
);
1196 emit_block_move_via_loop (x
, y
, size
, align
);
1198 if (method
== BLOCK_OP_CALL_PARM
)
1205 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1207 unsigned HOST_WIDE_INT max
, min
= 0;
1208 if (GET_CODE (size
) == CONST_INT
)
1209 min
= max
= UINTVAL (size
);
1211 max
= GET_MODE_MASK (GET_MODE (size
));
1212 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1216 /* A subroutine of emit_block_move. Returns true if calling the
1217 block move libcall will not clobber any parameters which may have
1218 already been placed on the stack. */
1221 block_move_libcall_safe_for_call_parm (void)
1223 #if defined (REG_PARM_STACK_SPACE)
1227 /* If arguments are pushed on the stack, then they're safe. */
1231 /* If registers go on the stack anyway, any argument is sure to clobber
1232 an outgoing argument. */
1233 #if defined (REG_PARM_STACK_SPACE)
1234 fn
= emit_block_move_libcall_fn (false);
1235 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1236 depend on its argument. */
1238 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1239 && REG_PARM_STACK_SPACE (fn
) != 0)
1243 /* If any argument goes in memory, then it might clobber an outgoing
1246 CUMULATIVE_ARGS args_so_far_v
;
1247 cumulative_args_t args_so_far
;
1250 fn
= emit_block_move_libcall_fn (false);
1251 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1252 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1254 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1255 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1257 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1258 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1260 if (!tmp
|| !REG_P (tmp
))
1262 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1264 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1271 /* A subroutine of emit_block_move. Expand a movmem pattern;
1272 return true if successful. */
1275 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1276 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1277 unsigned HOST_WIDE_INT min_size
,
1278 unsigned HOST_WIDE_INT max_size
,
1279 unsigned HOST_WIDE_INT probable_max_size
)
1281 int save_volatile_ok
= volatile_ok
;
1282 enum machine_mode mode
;
1284 if (expected_align
< align
)
1285 expected_align
= align
;
1286 if (expected_size
!= -1)
1288 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1289 expected_size
= probable_max_size
;
1290 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1291 expected_size
= min_size
;
1294 /* Since this is a move insn, we don't care about volatility. */
1297 /* Try the most limited insn first, because there's no point
1298 including more than one in the machine description unless
1299 the more limited one has some advantage. */
1301 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1302 mode
= GET_MODE_WIDER_MODE (mode
))
1304 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1306 if (code
!= CODE_FOR_nothing
1307 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1308 here because if SIZE is less than the mode mask, as it is
1309 returned by the macro, it will definitely be less than the
1310 actual mode mask. Since SIZE is within the Pmode address
1311 space, we limit MODE to Pmode. */
1312 && ((CONST_INT_P (size
)
1313 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1314 <= (GET_MODE_MASK (mode
) >> 1)))
1315 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1316 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1318 struct expand_operand ops
[9];
1321 /* ??? When called via emit_block_move_for_call, it'd be
1322 nice if there were some way to inform the backend, so
1323 that it doesn't fail the expansion because it thinks
1324 emitting the libcall would be more efficient. */
1325 nops
= insn_data
[(int) code
].n_generator_args
;
1326 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1328 create_fixed_operand (&ops
[0], x
);
1329 create_fixed_operand (&ops
[1], y
);
1330 /* The check above guarantees that this size conversion is valid. */
1331 create_convert_operand_to (&ops
[2], size
, mode
, true);
1332 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1335 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1336 create_integer_operand (&ops
[5], expected_size
);
1340 create_integer_operand (&ops
[6], min_size
);
1341 /* If we can not represent the maximal size,
1342 make parameter NULL. */
1343 if ((HOST_WIDE_INT
) max_size
!= -1)
1344 create_integer_operand (&ops
[7], max_size
);
1346 create_fixed_operand (&ops
[7], NULL
);
1350 /* If we can not represent the maximal size,
1351 make parameter NULL. */
1352 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1353 create_integer_operand (&ops
[8], probable_max_size
);
1355 create_fixed_operand (&ops
[8], NULL
);
1357 if (maybe_expand_insn (code
, nops
, ops
))
1359 volatile_ok
= save_volatile_ok
;
1365 volatile_ok
= save_volatile_ok
;
1369 /* A subroutine of emit_block_move. Expand a call to memcpy.
1370 Return the return value from memcpy, 0 otherwise. */
1373 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1375 rtx dst_addr
, src_addr
;
1376 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1377 enum machine_mode size_mode
;
1380 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1381 pseudos. We can then place those new pseudos into a VAR_DECL and
1384 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1385 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1387 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1388 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1390 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1391 src_tree
= make_tree (ptr_type_node
, src_addr
);
1393 size_mode
= TYPE_MODE (sizetype
);
1395 size
= convert_to_mode (size_mode
, size
, 1);
1396 size
= copy_to_mode_reg (size_mode
, size
);
1398 /* It is incorrect to use the libcall calling conventions to call
1399 memcpy in this context. This could be a user call to memcpy and
1400 the user may wish to examine the return value from memcpy. For
1401 targets where libcalls and normal calls have different conventions
1402 for returning pointers, we could end up generating incorrect code. */
1404 size_tree
= make_tree (sizetype
, size
);
1406 fn
= emit_block_move_libcall_fn (true);
1407 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1408 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1410 retval
= expand_normal (call_expr
);
1415 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1416 for the function we use for block copies. */
1418 static GTY(()) tree block_move_fn
;
1421 init_block_move_fn (const char *asmspec
)
1425 tree args
, fn
, attrs
, attr_args
;
1427 fn
= get_identifier ("memcpy");
1428 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1429 const_ptr_type_node
, sizetype
,
1432 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1433 DECL_EXTERNAL (fn
) = 1;
1434 TREE_PUBLIC (fn
) = 1;
1435 DECL_ARTIFICIAL (fn
) = 1;
1436 TREE_NOTHROW (fn
) = 1;
1437 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1438 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1440 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1441 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1443 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1449 set_user_assembler_name (block_move_fn
, asmspec
);
1453 emit_block_move_libcall_fn (int for_call
)
1455 static bool emitted_extern
;
1458 init_block_move_fn (NULL
);
1460 if (for_call
&& !emitted_extern
)
1462 emitted_extern
= true;
1463 make_decl_rtl (block_move_fn
);
1466 return block_move_fn
;
1469 /* A subroutine of emit_block_move. Copy the data via an explicit
1470 loop. This is used only when libcalls are forbidden. */
1471 /* ??? It'd be nice to copy in hunks larger than QImode. */
1474 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1475 unsigned int align ATTRIBUTE_UNUSED
)
1477 rtx_code_label
*cmp_label
, *top_label
;
1478 rtx iter
, x_addr
, y_addr
, tmp
;
1479 enum machine_mode x_addr_mode
= get_address_mode (x
);
1480 enum machine_mode y_addr_mode
= get_address_mode (y
);
1481 enum machine_mode iter_mode
;
1483 iter_mode
= GET_MODE (size
);
1484 if (iter_mode
== VOIDmode
)
1485 iter_mode
= word_mode
;
1487 top_label
= gen_label_rtx ();
1488 cmp_label
= gen_label_rtx ();
1489 iter
= gen_reg_rtx (iter_mode
);
1491 emit_move_insn (iter
, const0_rtx
);
1493 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1494 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1495 do_pending_stack_adjust ();
1497 emit_jump (cmp_label
);
1498 emit_label (top_label
);
1500 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1501 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1503 if (x_addr_mode
!= y_addr_mode
)
1504 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1505 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1507 x
= change_address (x
, QImode
, x_addr
);
1508 y
= change_address (y
, QImode
, y_addr
);
1510 emit_move_insn (x
, y
);
1512 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1513 true, OPTAB_LIB_WIDEN
);
1515 emit_move_insn (iter
, tmp
);
1517 emit_label (cmp_label
);
1519 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1520 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1523 /* Copy all or part of a value X into registers starting at REGNO.
1524 The number of registers to be filled is NREGS. */
1527 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1530 #ifdef HAVE_load_multiple
1538 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1539 x
= validize_mem (force_const_mem (mode
, x
));
1541 /* See if the machine can do this with a load multiple insn. */
1542 #ifdef HAVE_load_multiple
1543 if (HAVE_load_multiple
)
1545 last
= get_last_insn ();
1546 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1554 delete_insns_since (last
);
1558 for (i
= 0; i
< nregs
; i
++)
1559 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1560 operand_subword_force (x
, i
, mode
));
1563 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1564 The number of registers to be filled is NREGS. */
1567 move_block_from_reg (int regno
, rtx x
, int nregs
)
1574 /* See if the machine can do this with a store multiple insn. */
1575 #ifdef HAVE_store_multiple
1576 if (HAVE_store_multiple
)
1578 rtx_insn
*last
= get_last_insn ();
1579 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1587 delete_insns_since (last
);
1591 for (i
= 0; i
< nregs
; i
++)
1593 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1597 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1601 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1602 ORIG, where ORIG is a non-consecutive group of registers represented by
1603 a PARALLEL. The clone is identical to the original except in that the
1604 original set of registers is replaced by a new set of pseudo registers.
1605 The new set has the same modes as the original set. */
1608 gen_group_rtx (rtx orig
)
1613 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1615 length
= XVECLEN (orig
, 0);
1616 tmps
= XALLOCAVEC (rtx
, length
);
1618 /* Skip a NULL entry in first slot. */
1619 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1624 for (; i
< length
; i
++)
1626 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1627 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1629 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1632 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1635 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1636 except that values are placed in TMPS[i], and must later be moved
1637 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1640 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1644 enum machine_mode m
= GET_MODE (orig_src
);
1646 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1649 && !SCALAR_INT_MODE_P (m
)
1650 && !MEM_P (orig_src
)
1651 && GET_CODE (orig_src
) != CONCAT
)
1653 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1654 if (imode
== BLKmode
)
1655 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1657 src
= gen_reg_rtx (imode
);
1658 if (imode
!= BLKmode
)
1659 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1660 emit_move_insn (src
, orig_src
);
1661 /* ...and back again. */
1662 if (imode
!= BLKmode
)
1663 src
= gen_lowpart (imode
, src
);
1664 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1668 /* Check for a NULL entry, used to indicate that the parameter goes
1669 both on the stack and in registers. */
1670 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1675 /* Process the pieces. */
1676 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1678 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1679 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1680 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1683 /* Handle trailing fragments that run over the size of the struct. */
1684 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1686 /* Arrange to shift the fragment to where it belongs.
1687 extract_bit_field loads to the lsb of the reg. */
1689 #ifdef BLOCK_REG_PADDING
1690 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1691 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1696 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1697 bytelen
= ssize
- bytepos
;
1698 gcc_assert (bytelen
> 0);
1701 /* If we won't be loading directly from memory, protect the real source
1702 from strange tricks we might play; but make sure that the source can
1703 be loaded directly into the destination. */
1705 if (!MEM_P (orig_src
)
1706 && (!CONSTANT_P (orig_src
)
1707 || (GET_MODE (orig_src
) != mode
1708 && GET_MODE (orig_src
) != VOIDmode
)))
1710 if (GET_MODE (orig_src
) == VOIDmode
)
1711 src
= gen_reg_rtx (mode
);
1713 src
= gen_reg_rtx (GET_MODE (orig_src
));
1715 emit_move_insn (src
, orig_src
);
1718 /* Optimize the access just a bit. */
1720 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1721 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1722 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1723 && bytelen
== GET_MODE_SIZE (mode
))
1725 tmps
[i
] = gen_reg_rtx (mode
);
1726 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1728 else if (COMPLEX_MODE_P (mode
)
1729 && GET_MODE (src
) == mode
1730 && bytelen
== GET_MODE_SIZE (mode
))
1731 /* Let emit_move_complex do the bulk of the work. */
1733 else if (GET_CODE (src
) == CONCAT
)
1735 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1736 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1738 if ((bytepos
== 0 && bytelen
== slen0
)
1739 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1741 /* The following assumes that the concatenated objects all
1742 have the same size. In this case, a simple calculation
1743 can be used to determine the object and the bit field
1745 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1746 if (! CONSTANT_P (tmps
[i
])
1747 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1748 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1749 (bytepos
% slen0
) * BITS_PER_UNIT
,
1750 1, NULL_RTX
, mode
, mode
);
1756 gcc_assert (!bytepos
);
1757 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1758 emit_move_insn (mem
, src
);
1759 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1760 0, 1, NULL_RTX
, mode
, mode
);
1763 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1764 SIMD register, which is currently broken. While we get GCC
1765 to emit proper RTL for these cases, let's dump to memory. */
1766 else if (VECTOR_MODE_P (GET_MODE (dst
))
1769 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1772 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1773 emit_move_insn (mem
, src
);
1774 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1776 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1777 && XVECLEN (dst
, 0) > 1)
1778 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1779 else if (CONSTANT_P (src
))
1781 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1789 /* TODO: const_wide_int can have sizes other than this... */
1790 gcc_assert (2 * len
== ssize
);
1791 split_double (src
, &first
, &second
);
1798 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1801 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1802 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1806 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1811 /* Emit code to move a block SRC of type TYPE to a block DST,
1812 where DST is non-consecutive registers represented by a PARALLEL.
1813 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1817 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1822 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1823 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1825 /* Copy the extracted pieces into the proper (probable) hard regs. */
1826 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1828 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1831 emit_move_insn (d
, tmps
[i
]);
1835 /* Similar, but load SRC into new pseudos in a format that looks like
1836 PARALLEL. This can later be fed to emit_group_move to get things
1837 in the right place. */
1840 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1845 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1846 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1848 /* Convert the vector to look just like the original PARALLEL, except
1849 with the computed values. */
1850 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1852 rtx e
= XVECEXP (parallel
, 0, i
);
1853 rtx d
= XEXP (e
, 0);
1857 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1858 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1860 RTVEC_ELT (vec
, i
) = e
;
1863 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1866 /* Emit code to move a block SRC to block DST, where SRC and DST are
1867 non-consecutive groups of registers, each represented by a PARALLEL. */
1870 emit_group_move (rtx dst
, rtx src
)
1874 gcc_assert (GET_CODE (src
) == PARALLEL
1875 && GET_CODE (dst
) == PARALLEL
1876 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1878 /* Skip first entry if NULL. */
1879 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1880 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1881 XEXP (XVECEXP (src
, 0, i
), 0));
1884 /* Move a group of registers represented by a PARALLEL into pseudos. */
1887 emit_group_move_into_temps (rtx src
)
1889 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1892 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1894 rtx e
= XVECEXP (src
, 0, i
);
1895 rtx d
= XEXP (e
, 0);
1898 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1899 RTVEC_ELT (vec
, i
) = e
;
1902 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1905 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1906 where SRC is non-consecutive registers represented by a PARALLEL.
1907 SSIZE represents the total size of block ORIG_DST, or -1 if not
1911 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1914 int start
, finish
, i
;
1915 enum machine_mode m
= GET_MODE (orig_dst
);
1917 gcc_assert (GET_CODE (src
) == PARALLEL
);
1919 if (!SCALAR_INT_MODE_P (m
)
1920 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1922 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1923 if (imode
== BLKmode
)
1924 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1926 dst
= gen_reg_rtx (imode
);
1927 emit_group_store (dst
, src
, type
, ssize
);
1928 if (imode
!= BLKmode
)
1929 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1930 emit_move_insn (orig_dst
, dst
);
1934 /* Check for a NULL entry, used to indicate that the parameter goes
1935 both on the stack and in registers. */
1936 if (XEXP (XVECEXP (src
, 0, 0), 0))
1940 finish
= XVECLEN (src
, 0);
1942 tmps
= XALLOCAVEC (rtx
, finish
);
1944 /* Copy the (probable) hard regs into pseudos. */
1945 for (i
= start
; i
< finish
; i
++)
1947 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1948 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1950 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1951 emit_move_insn (tmps
[i
], reg
);
1957 /* If we won't be storing directly into memory, protect the real destination
1958 from strange tricks we might play. */
1960 if (GET_CODE (dst
) == PARALLEL
)
1964 /* We can get a PARALLEL dst if there is a conditional expression in
1965 a return statement. In that case, the dst and src are the same,
1966 so no action is necessary. */
1967 if (rtx_equal_p (dst
, src
))
1970 /* It is unclear if we can ever reach here, but we may as well handle
1971 it. Allocate a temporary, and split this into a store/load to/from
1973 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1974 emit_group_store (temp
, src
, type
, ssize
);
1975 emit_group_load (dst
, temp
, type
, ssize
);
1978 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1980 enum machine_mode outer
= GET_MODE (dst
);
1981 enum machine_mode inner
;
1982 HOST_WIDE_INT bytepos
;
1986 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1987 dst
= gen_reg_rtx (outer
);
1989 /* Make life a bit easier for combine. */
1990 /* If the first element of the vector is the low part
1991 of the destination mode, use a paradoxical subreg to
1992 initialize the destination. */
1995 inner
= GET_MODE (tmps
[start
]);
1996 bytepos
= subreg_lowpart_offset (inner
, outer
);
1997 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1999 temp
= simplify_gen_subreg (outer
, tmps
[start
],
2003 emit_move_insn (dst
, temp
);
2010 /* If the first element wasn't the low part, try the last. */
2012 && start
< finish
- 1)
2014 inner
= GET_MODE (tmps
[finish
- 1]);
2015 bytepos
= subreg_lowpart_offset (inner
, outer
);
2016 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
2018 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
2022 emit_move_insn (dst
, temp
);
2029 /* Otherwise, simply initialize the result to zero. */
2031 emit_move_insn (dst
, CONST0_RTX (outer
));
2034 /* Process the pieces. */
2035 for (i
= start
; i
< finish
; i
++)
2037 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
2038 enum machine_mode mode
= GET_MODE (tmps
[i
]);
2039 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2040 unsigned int adj_bytelen
;
2043 /* Handle trailing fragments that run over the size of the struct. */
2044 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2045 adj_bytelen
= ssize
- bytepos
;
2047 adj_bytelen
= bytelen
;
2049 if (GET_CODE (dst
) == CONCAT
)
2051 if (bytepos
+ adj_bytelen
2052 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2053 dest
= XEXP (dst
, 0);
2054 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2056 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2057 dest
= XEXP (dst
, 1);
2061 enum machine_mode dest_mode
= GET_MODE (dest
);
2062 enum machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2064 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2066 if (GET_MODE_ALIGNMENT (dest_mode
)
2067 >= GET_MODE_ALIGNMENT (tmp_mode
))
2069 dest
= assign_stack_temp (dest_mode
,
2070 GET_MODE_SIZE (dest_mode
));
2071 emit_move_insn (adjust_address (dest
,
2079 dest
= assign_stack_temp (tmp_mode
,
2080 GET_MODE_SIZE (tmp_mode
));
2081 emit_move_insn (dest
, tmps
[i
]);
2082 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2088 /* Handle trailing fragments that run over the size of the struct. */
2089 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2091 /* store_bit_field always takes its value from the lsb.
2092 Move the fragment to the lsb if it's not already there. */
2094 #ifdef BLOCK_REG_PADDING
2095 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2096 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2102 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2103 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2107 /* Make sure not to write past the end of the struct. */
2108 store_bit_field (dest
,
2109 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2110 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
- 1,
2114 /* Optimize the access just a bit. */
2115 else if (MEM_P (dest
)
2116 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2117 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2118 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2119 && bytelen
== GET_MODE_SIZE (mode
))
2120 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2123 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2124 0, 0, mode
, tmps
[i
]);
2127 /* Copy from the pseudo into the (probable) hard reg. */
2128 if (orig_dst
!= dst
)
2129 emit_move_insn (orig_dst
, dst
);
2132 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2133 of the value stored in X. */
2136 maybe_emit_group_store (rtx x
, tree type
)
2138 enum machine_mode mode
= TYPE_MODE (type
);
2139 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2140 if (GET_CODE (x
) == PARALLEL
)
2142 rtx result
= gen_reg_rtx (mode
);
2143 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2149 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2151 This is used on targets that return BLKmode values in registers. */
2154 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2156 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2157 rtx src
= NULL
, dst
= NULL
;
2158 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2159 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2160 enum machine_mode mode
= GET_MODE (srcreg
);
2161 enum machine_mode tmode
= GET_MODE (target
);
2162 enum machine_mode copy_mode
;
2164 /* BLKmode registers created in the back-end shouldn't have survived. */
2165 gcc_assert (mode
!= BLKmode
);
2167 /* If the structure doesn't take up a whole number of words, see whether
2168 SRCREG is padded on the left or on the right. If it's on the left,
2169 set PADDING_CORRECTION to the number of bits to skip.
2171 In most ABIs, the structure will be returned at the least end of
2172 the register, which translates to right padding on little-endian
2173 targets and left padding on big-endian targets. The opposite
2174 holds if the structure is returned at the most significant
2175 end of the register. */
2176 if (bytes
% UNITS_PER_WORD
!= 0
2177 && (targetm
.calls
.return_in_msb (type
)
2179 : BYTES_BIG_ENDIAN
))
2181 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2183 /* We can use a single move if we have an exact mode for the size. */
2184 else if (MEM_P (target
)
2185 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2186 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2187 && bytes
== GET_MODE_SIZE (mode
))
2189 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2193 /* And if we additionally have the same mode for a register. */
2194 else if (REG_P (target
)
2195 && GET_MODE (target
) == mode
2196 && bytes
== GET_MODE_SIZE (mode
))
2198 emit_move_insn (target
, srcreg
);
2202 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2203 into a new pseudo which is a full word. */
2204 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2206 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2210 /* Copy the structure BITSIZE bits at a time. If the target lives in
2211 memory, take care of not reading/writing past its end by selecting
2212 a copy mode suited to BITSIZE. This should always be possible given
2215 If the target lives in register, make sure not to select a copy mode
2216 larger than the mode of the register.
2218 We could probably emit more efficient code for machines which do not use
2219 strict alignment, but it doesn't seem worth the effort at the current
2222 copy_mode
= word_mode
;
2225 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2226 if (mem_mode
!= BLKmode
)
2227 copy_mode
= mem_mode
;
2229 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2232 for (bitpos
= 0, xbitpos
= padding_correction
;
2233 bitpos
< bytes
* BITS_PER_UNIT
;
2234 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2236 /* We need a new source operand each time xbitpos is on a
2237 word boundary and when xbitpos == padding_correction
2238 (the first time through). */
2239 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2240 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2242 /* We need a new destination operand each time bitpos is on
2244 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2246 else if (bitpos
% BITS_PER_WORD
== 0)
2247 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2249 /* Use xbitpos for the source extraction (right justified) and
2250 bitpos for the destination store (left justified). */
2251 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2252 extract_bit_field (src
, bitsize
,
2253 xbitpos
% BITS_PER_WORD
, 1,
2254 NULL_RTX
, copy_mode
, copy_mode
));
2258 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2259 register if it contains any data, otherwise return null.
2261 This is used on targets that return BLKmode values in registers. */
2264 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2267 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2268 unsigned int bitsize
;
2269 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2270 enum machine_mode dst_mode
;
2272 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2274 x
= expand_normal (src
);
2276 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2280 /* If the structure doesn't take up a whole number of words, see
2281 whether the register value should be padded on the left or on
2282 the right. Set PADDING_CORRECTION to the number of padding
2283 bits needed on the left side.
2285 In most ABIs, the structure will be returned at the least end of
2286 the register, which translates to right padding on little-endian
2287 targets and left padding on big-endian targets. The opposite
2288 holds if the structure is returned at the most significant
2289 end of the register. */
2290 if (bytes
% UNITS_PER_WORD
!= 0
2291 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2293 : BYTES_BIG_ENDIAN
))
2294 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2297 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2298 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2299 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2301 /* Copy the structure BITSIZE bits at a time. */
2302 for (bitpos
= 0, xbitpos
= padding_correction
;
2303 bitpos
< bytes
* BITS_PER_UNIT
;
2304 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2306 /* We need a new destination pseudo each time xbitpos is
2307 on a word boundary and when xbitpos == padding_correction
2308 (the first time through). */
2309 if (xbitpos
% BITS_PER_WORD
== 0
2310 || xbitpos
== padding_correction
)
2312 /* Generate an appropriate register. */
2313 dst_word
= gen_reg_rtx (word_mode
);
2314 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2316 /* Clear the destination before we move anything into it. */
2317 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2320 /* We need a new source operand each time bitpos is on a word
2322 if (bitpos
% BITS_PER_WORD
== 0)
2323 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2325 /* Use bitpos for the source extraction (left justified) and
2326 xbitpos for the destination store (right justified). */
2327 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2329 extract_bit_field (src_word
, bitsize
,
2330 bitpos
% BITS_PER_WORD
, 1,
2331 NULL_RTX
, word_mode
, word_mode
));
2334 if (mode
== BLKmode
)
2336 /* Find the smallest integer mode large enough to hold the
2337 entire structure. */
2338 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2340 mode
= GET_MODE_WIDER_MODE (mode
))
2341 /* Have we found a large enough mode? */
2342 if (GET_MODE_SIZE (mode
) >= bytes
)
2345 /* A suitable mode should have been found. */
2346 gcc_assert (mode
!= VOIDmode
);
2349 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2350 dst_mode
= word_mode
;
2353 dst
= gen_reg_rtx (dst_mode
);
2355 for (i
= 0; i
< n_regs
; i
++)
2356 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2358 if (mode
!= dst_mode
)
2359 dst
= gen_lowpart (mode
, dst
);
2364 /* Add a USE expression for REG to the (possibly empty) list pointed
2365 to by CALL_FUSAGE. REG must denote a hard register. */
2368 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2370 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2373 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2376 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
2377 to by CALL_FUSAGE. REG must denote a hard register. */
2380 clobber_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2382 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2385 = gen_rtx_EXPR_LIST (mode
, gen_rtx_CLOBBER (VOIDmode
, reg
), *call_fusage
);
2388 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2389 starting at REGNO. All of these registers must be hard registers. */
2392 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2396 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2398 for (i
= 0; i
< nregs
; i
++)
2399 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2402 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2403 PARALLEL REGS. This is for calls that pass values in multiple
2404 non-contiguous locations. The Irix 6 ABI has examples of this. */
2407 use_group_regs (rtx
*call_fusage
, rtx regs
)
2411 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2413 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2415 /* A NULL entry means the parameter goes both on the stack and in
2416 registers. This can also be a MEM for targets that pass values
2417 partially on the stack and partially in registers. */
2418 if (reg
!= 0 && REG_P (reg
))
2419 use_reg (call_fusage
, reg
);
2423 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2424 assigment and the code of the expresion on the RHS is CODE. Return
2428 get_def_for_expr (tree name
, enum tree_code code
)
2432 if (TREE_CODE (name
) != SSA_NAME
)
2435 def_stmt
= get_gimple_for_ssa_name (name
);
2437 || gimple_assign_rhs_code (def_stmt
) != code
)
2443 #ifdef HAVE_conditional_move
2444 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2445 assigment and the class of the expresion on the RHS is CLASS. Return
2449 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2453 if (TREE_CODE (name
) != SSA_NAME
)
2456 def_stmt
= get_gimple_for_ssa_name (name
);
2458 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2466 /* Determine whether the LEN bytes generated by CONSTFUN can be
2467 stored to memory using several move instructions. CONSTFUNDATA is
2468 a pointer which will be passed as argument in every CONSTFUN call.
2469 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2470 a memset operation and false if it's a copy of a constant string.
2471 Return nonzero if a call to store_by_pieces should succeed. */
2474 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2475 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2476 void *constfundata
, unsigned int align
, bool memsetp
)
2478 unsigned HOST_WIDE_INT l
;
2479 unsigned int max_size
;
2480 HOST_WIDE_INT offset
= 0;
2481 enum machine_mode mode
;
2482 enum insn_code icode
;
2484 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2485 rtx cst ATTRIBUTE_UNUSED
;
2491 ? SET_BY_PIECES_P (len
, align
)
2492 : STORE_BY_PIECES_P (len
, align
)))
2495 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2497 /* We would first store what we can in the largest integer mode, then go to
2498 successively smaller modes. */
2501 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2505 max_size
= STORE_MAX_PIECES
+ 1;
2506 while (max_size
> 1 && l
> 0)
2508 mode
= widest_int_mode_for_size (max_size
);
2510 if (mode
== VOIDmode
)
2513 icode
= optab_handler (mov_optab
, mode
);
2514 if (icode
!= CODE_FOR_nothing
2515 && align
>= GET_MODE_ALIGNMENT (mode
))
2517 unsigned int size
= GET_MODE_SIZE (mode
);
2524 cst
= (*constfun
) (constfundata
, offset
, mode
);
2525 if (!targetm
.legitimate_constant_p (mode
, cst
))
2535 max_size
= GET_MODE_SIZE (mode
);
2538 /* The code above should have handled everything. */
2545 /* Generate several move instructions to store LEN bytes generated by
2546 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2547 pointer which will be passed as argument in every CONSTFUN call.
2548 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2549 a memset operation and false if it's a copy of a constant string.
2550 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2551 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2555 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2556 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2557 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2559 enum machine_mode to_addr_mode
= get_address_mode (to
);
2560 struct store_by_pieces_d data
;
2564 gcc_assert (endp
!= 2);
2569 ? SET_BY_PIECES_P (len
, align
)
2570 : STORE_BY_PIECES_P (len
, align
));
2571 data
.constfun
= constfun
;
2572 data
.constfundata
= constfundata
;
2575 store_by_pieces_1 (&data
, align
);
2580 gcc_assert (!data
.reverse
);
2585 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2586 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2588 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2589 plus_constant (to_addr_mode
,
2593 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2600 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2608 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2609 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2612 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2614 struct store_by_pieces_d data
;
2619 data
.constfun
= clear_by_pieces_1
;
2620 data
.constfundata
= NULL
;
2623 store_by_pieces_1 (&data
, align
);
2626 /* Callback routine for clear_by_pieces.
2627 Return const0_rtx unconditionally. */
2630 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2631 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2632 enum machine_mode mode ATTRIBUTE_UNUSED
)
2637 /* Subroutine of clear_by_pieces and store_by_pieces.
2638 Generate several move instructions to store LEN bytes of block TO. (A MEM
2639 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2642 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2643 unsigned int align ATTRIBUTE_UNUSED
)
2645 enum machine_mode to_addr_mode
= get_address_mode (data
->to
);
2646 rtx to_addr
= XEXP (data
->to
, 0);
2647 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2648 enum insn_code icode
;
2651 data
->to_addr
= to_addr
;
2653 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2654 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2656 data
->explicit_inc_to
= 0;
2658 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2660 data
->offset
= data
->len
;
2662 /* If storing requires more than two move insns,
2663 copy addresses to registers (to make displacements shorter)
2664 and use post-increment if available. */
2665 if (!data
->autinc_to
2666 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2668 /* Determine the main mode we'll be using.
2669 MODE might not be used depending on the definitions of the
2670 USE_* macros below. */
2671 enum machine_mode mode ATTRIBUTE_UNUSED
2672 = widest_int_mode_for_size (max_size
);
2674 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2676 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2677 plus_constant (to_addr_mode
,
2680 data
->autinc_to
= 1;
2681 data
->explicit_inc_to
= -1;
2684 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2685 && ! data
->autinc_to
)
2687 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2688 data
->autinc_to
= 1;
2689 data
->explicit_inc_to
= 1;
2692 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2693 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2696 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2698 /* First store what we can in the largest integer mode, then go to
2699 successively smaller modes. */
2701 while (max_size
> 1 && data
->len
> 0)
2703 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2705 if (mode
== VOIDmode
)
2708 icode
= optab_handler (mov_optab
, mode
);
2709 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2710 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2712 max_size
= GET_MODE_SIZE (mode
);
2715 /* The code above should have handled everything. */
2716 gcc_assert (!data
->len
);
2719 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2720 with move instructions for mode MODE. GENFUN is the gen_... function
2721 to make a move insn for that mode. DATA has all the other info. */
2724 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2725 struct store_by_pieces_d
*data
)
2727 unsigned int size
= GET_MODE_SIZE (mode
);
2730 while (data
->len
>= size
)
2733 data
->offset
-= size
;
2735 if (data
->autinc_to
)
2736 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2739 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2741 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2742 emit_insn (gen_add2_insn (data
->to_addr
,
2743 gen_int_mode (-(HOST_WIDE_INT
) size
,
2744 GET_MODE (data
->to_addr
))));
2746 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2747 emit_insn ((*genfun
) (to1
, cst
));
2749 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2750 emit_insn (gen_add2_insn (data
->to_addr
,
2752 GET_MODE (data
->to_addr
))));
2754 if (! data
->reverse
)
2755 data
->offset
+= size
;
2761 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2762 its length in bytes. */
2765 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2766 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2767 unsigned HOST_WIDE_INT min_size
,
2768 unsigned HOST_WIDE_INT max_size
,
2769 unsigned HOST_WIDE_INT probable_max_size
)
2771 enum machine_mode mode
= GET_MODE (object
);
2774 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2776 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2777 just move a zero. Otherwise, do this a piece at a time. */
2779 && CONST_INT_P (size
)
2780 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2782 rtx zero
= CONST0_RTX (mode
);
2785 emit_move_insn (object
, zero
);
2789 if (COMPLEX_MODE_P (mode
))
2791 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2794 write_complex_part (object
, zero
, 0);
2795 write_complex_part (object
, zero
, 1);
2801 if (size
== const0_rtx
)
2804 align
= MEM_ALIGN (object
);
2806 if (CONST_INT_P (size
)
2807 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2808 clear_by_pieces (object
, INTVAL (size
), align
);
2809 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2810 expected_align
, expected_size
,
2811 min_size
, max_size
, probable_max_size
))
2813 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2814 return set_storage_via_libcall (object
, size
, const0_rtx
,
2815 method
== BLOCK_OP_TAILCALL
);
2823 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2825 unsigned HOST_WIDE_INT max
, min
= 0;
2826 if (GET_CODE (size
) == CONST_INT
)
2827 min
= max
= UINTVAL (size
);
2829 max
= GET_MODE_MASK (GET_MODE (size
));
2830 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2834 /* A subroutine of clear_storage. Expand a call to memset.
2835 Return the return value of memset, 0 otherwise. */
2838 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2840 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2841 enum machine_mode size_mode
;
2844 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2845 place those into new pseudos into a VAR_DECL and use them later. */
2847 object
= copy_addr_to_reg (XEXP (object
, 0));
2849 size_mode
= TYPE_MODE (sizetype
);
2850 size
= convert_to_mode (size_mode
, size
, 1);
2851 size
= copy_to_mode_reg (size_mode
, size
);
2853 /* It is incorrect to use the libcall calling conventions to call
2854 memset in this context. This could be a user call to memset and
2855 the user may wish to examine the return value from memset. For
2856 targets where libcalls and normal calls have different conventions
2857 for returning pointers, we could end up generating incorrect code. */
2859 object_tree
= make_tree (ptr_type_node
, object
);
2860 if (!CONST_INT_P (val
))
2861 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2862 size_tree
= make_tree (sizetype
, size
);
2863 val_tree
= make_tree (integer_type_node
, val
);
2865 fn
= clear_storage_libcall_fn (true);
2866 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2867 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2869 retval
= expand_normal (call_expr
);
2874 /* A subroutine of set_storage_via_libcall. Create the tree node
2875 for the function we use for block clears. */
2877 tree block_clear_fn
;
2880 init_block_clear_fn (const char *asmspec
)
2882 if (!block_clear_fn
)
2886 fn
= get_identifier ("memset");
2887 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2888 integer_type_node
, sizetype
,
2891 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2892 DECL_EXTERNAL (fn
) = 1;
2893 TREE_PUBLIC (fn
) = 1;
2894 DECL_ARTIFICIAL (fn
) = 1;
2895 TREE_NOTHROW (fn
) = 1;
2896 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2897 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2899 block_clear_fn
= fn
;
2903 set_user_assembler_name (block_clear_fn
, asmspec
);
2907 clear_storage_libcall_fn (int for_call
)
2909 static bool emitted_extern
;
2911 if (!block_clear_fn
)
2912 init_block_clear_fn (NULL
);
2914 if (for_call
&& !emitted_extern
)
2916 emitted_extern
= true;
2917 make_decl_rtl (block_clear_fn
);
2920 return block_clear_fn
;
2923 /* Expand a setmem pattern; return true if successful. */
2926 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2927 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2928 unsigned HOST_WIDE_INT min_size
,
2929 unsigned HOST_WIDE_INT max_size
,
2930 unsigned HOST_WIDE_INT probable_max_size
)
2932 /* Try the most limited insn first, because there's no point
2933 including more than one in the machine description unless
2934 the more limited one has some advantage. */
2936 enum machine_mode mode
;
2938 if (expected_align
< align
)
2939 expected_align
= align
;
2940 if (expected_size
!= -1)
2942 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2943 expected_size
= max_size
;
2944 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2945 expected_size
= min_size
;
2948 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2949 mode
= GET_MODE_WIDER_MODE (mode
))
2951 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2953 if (code
!= CODE_FOR_nothing
2954 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2955 here because if SIZE is less than the mode mask, as it is
2956 returned by the macro, it will definitely be less than the
2957 actual mode mask. Since SIZE is within the Pmode address
2958 space, we limit MODE to Pmode. */
2959 && ((CONST_INT_P (size
)
2960 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2961 <= (GET_MODE_MASK (mode
) >> 1)))
2962 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2963 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2965 struct expand_operand ops
[9];
2968 nops
= insn_data
[(int) code
].n_generator_args
;
2969 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2971 create_fixed_operand (&ops
[0], object
);
2972 /* The check above guarantees that this size conversion is valid. */
2973 create_convert_operand_to (&ops
[1], size
, mode
, true);
2974 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2975 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2978 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2979 create_integer_operand (&ops
[5], expected_size
);
2983 create_integer_operand (&ops
[6], min_size
);
2984 /* If we can not represent the maximal size,
2985 make parameter NULL. */
2986 if ((HOST_WIDE_INT
) max_size
!= -1)
2987 create_integer_operand (&ops
[7], max_size
);
2989 create_fixed_operand (&ops
[7], NULL
);
2993 /* If we can not represent the maximal size,
2994 make parameter NULL. */
2995 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2996 create_integer_operand (&ops
[8], probable_max_size
);
2998 create_fixed_operand (&ops
[8], NULL
);
3000 if (maybe_expand_insn (code
, nops
, ops
))
3009 /* Write to one of the components of the complex value CPLX. Write VAL to
3010 the real part if IMAG_P is false, and the imaginary part if its true. */
3013 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
3015 enum machine_mode cmode
;
3016 enum machine_mode imode
;
3019 if (GET_CODE (cplx
) == CONCAT
)
3021 emit_move_insn (XEXP (cplx
, imag_p
), val
);
3025 cmode
= GET_MODE (cplx
);
3026 imode
= GET_MODE_INNER (cmode
);
3027 ibitsize
= GET_MODE_BITSIZE (imode
);
3029 /* For MEMs simplify_gen_subreg may generate an invalid new address
3030 because, e.g., the original address is considered mode-dependent
3031 by the target, which restricts simplify_subreg from invoking
3032 adjust_address_nv. Instead of preparing fallback support for an
3033 invalid address, we call adjust_address_nv directly. */
3036 emit_move_insn (adjust_address_nv (cplx
, imode
,
3037 imag_p
? GET_MODE_SIZE (imode
) : 0),
3042 /* If the sub-object is at least word sized, then we know that subregging
3043 will work. This special case is important, since store_bit_field
3044 wants to operate on integer modes, and there's rarely an OImode to
3045 correspond to TCmode. */
3046 if (ibitsize
>= BITS_PER_WORD
3047 /* For hard regs we have exact predicates. Assume we can split
3048 the original object if it spans an even number of hard regs.
3049 This special case is important for SCmode on 64-bit platforms
3050 where the natural size of floating-point regs is 32-bit. */
3052 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3053 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3055 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3056 imag_p
? GET_MODE_SIZE (imode
) : 0);
3059 emit_move_insn (part
, val
);
3063 /* simplify_gen_subreg may fail for sub-word MEMs. */
3064 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3067 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
3070 /* Extract one of the components of the complex value CPLX. Extract the
3071 real part if IMAG_P is false, and the imaginary part if it's true. */
3074 read_complex_part (rtx cplx
, bool imag_p
)
3076 enum machine_mode cmode
, imode
;
3079 if (GET_CODE (cplx
) == CONCAT
)
3080 return XEXP (cplx
, imag_p
);
3082 cmode
= GET_MODE (cplx
);
3083 imode
= GET_MODE_INNER (cmode
);
3084 ibitsize
= GET_MODE_BITSIZE (imode
);
3086 /* Special case reads from complex constants that got spilled to memory. */
3087 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3089 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3090 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3092 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3093 if (CONSTANT_CLASS_P (part
))
3094 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3098 /* For MEMs simplify_gen_subreg may generate an invalid new address
3099 because, e.g., the original address is considered mode-dependent
3100 by the target, which restricts simplify_subreg from invoking
3101 adjust_address_nv. Instead of preparing fallback support for an
3102 invalid address, we call adjust_address_nv directly. */
3104 return adjust_address_nv (cplx
, imode
,
3105 imag_p
? GET_MODE_SIZE (imode
) : 0);
3107 /* If the sub-object is at least word sized, then we know that subregging
3108 will work. This special case is important, since extract_bit_field
3109 wants to operate on integer modes, and there's rarely an OImode to
3110 correspond to TCmode. */
3111 if (ibitsize
>= BITS_PER_WORD
3112 /* For hard regs we have exact predicates. Assume we can split
3113 the original object if it spans an even number of hard regs.
3114 This special case is important for SCmode on 64-bit platforms
3115 where the natural size of floating-point regs is 32-bit. */
3117 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3118 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3120 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3121 imag_p
? GET_MODE_SIZE (imode
) : 0);
3125 /* simplify_gen_subreg may fail for sub-word MEMs. */
3126 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3129 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3130 true, NULL_RTX
, imode
, imode
);
3133 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3134 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3135 represented in NEW_MODE. If FORCE is true, this will never happen, as
3136 we'll force-create a SUBREG if needed. */
3139 emit_move_change_mode (enum machine_mode new_mode
,
3140 enum machine_mode old_mode
, rtx x
, bool force
)
3144 if (push_operand (x
, GET_MODE (x
)))
3146 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3147 MEM_COPY_ATTRIBUTES (ret
, x
);
3151 /* We don't have to worry about changing the address since the
3152 size in bytes is supposed to be the same. */
3153 if (reload_in_progress
)
3155 /* Copy the MEM to change the mode and move any
3156 substitutions from the old MEM to the new one. */
3157 ret
= adjust_address_nv (x
, new_mode
, 0);
3158 copy_replacements (x
, ret
);
3161 ret
= adjust_address (x
, new_mode
, 0);
3165 /* Note that we do want simplify_subreg's behavior of validating
3166 that the new mode is ok for a hard register. If we were to use
3167 simplify_gen_subreg, we would create the subreg, but would
3168 probably run into the target not being able to implement it. */
3169 /* Except, of course, when FORCE is true, when this is exactly what
3170 we want. Which is needed for CCmodes on some targets. */
3172 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3174 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3180 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3181 an integer mode of the same size as MODE. Returns the instruction
3182 emitted, or NULL if such a move could not be generated. */
3185 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3187 enum machine_mode imode
;
3188 enum insn_code code
;
3190 /* There must exist a mode of the exact size we require. */
3191 imode
= int_mode_for_mode (mode
);
3192 if (imode
== BLKmode
)
3195 /* The target must support moves in this mode. */
3196 code
= optab_handler (mov_optab
, imode
);
3197 if (code
== CODE_FOR_nothing
)
3200 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3203 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3206 return emit_insn (GEN_FCN (code
) (x
, y
));
3209 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3210 Return an equivalent MEM that does not use an auto-increment. */
3213 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3215 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3216 HOST_WIDE_INT adjust
;
3219 adjust
= GET_MODE_SIZE (mode
);
3220 #ifdef PUSH_ROUNDING
3221 adjust
= PUSH_ROUNDING (adjust
);
3223 if (code
== PRE_DEC
|| code
== POST_DEC
)
3225 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3227 rtx expr
= XEXP (XEXP (x
, 0), 1);
3230 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3231 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3232 val
= INTVAL (XEXP (expr
, 1));
3233 if (GET_CODE (expr
) == MINUS
)
3235 gcc_assert (adjust
== val
|| adjust
== -val
);
3239 /* Do not use anti_adjust_stack, since we don't want to update
3240 stack_pointer_delta. */
3241 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3242 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3243 0, OPTAB_LIB_WIDEN
);
3244 if (temp
!= stack_pointer_rtx
)
3245 emit_move_insn (stack_pointer_rtx
, temp
);
3252 temp
= stack_pointer_rtx
;
3257 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3263 return replace_equiv_address (x
, temp
);
3266 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3267 X is known to satisfy push_operand, and MODE is known to be complex.
3268 Returns the last instruction emitted. */
3271 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3273 enum machine_mode submode
= GET_MODE_INNER (mode
);
3276 #ifdef PUSH_ROUNDING
3277 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3279 /* In case we output to the stack, but the size is smaller than the
3280 machine can push exactly, we need to use move instructions. */
3281 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3283 x
= emit_move_resolve_push (mode
, x
);
3284 return emit_move_insn (x
, y
);
3288 /* Note that the real part always precedes the imag part in memory
3289 regardless of machine's endianness. */
3290 switch (GET_CODE (XEXP (x
, 0)))
3304 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3305 read_complex_part (y
, imag_first
));
3306 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3307 read_complex_part (y
, !imag_first
));
3310 /* A subroutine of emit_move_complex. Perform the move from Y to X
3311 via two moves of the parts. Returns the last instruction emitted. */
3314 emit_move_complex_parts (rtx x
, rtx y
)
3316 /* Show the output dies here. This is necessary for SUBREGs
3317 of pseudos since we cannot track their lifetimes correctly;
3318 hard regs shouldn't appear here except as return values. */
3319 if (!reload_completed
&& !reload_in_progress
3320 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3323 write_complex_part (x
, read_complex_part (y
, false), false);
3324 write_complex_part (x
, read_complex_part (y
, true), true);
3326 return get_last_insn ();
3329 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3330 MODE is known to be complex. Returns the last instruction emitted. */
3333 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3337 /* Need to take special care for pushes, to maintain proper ordering
3338 of the data, and possibly extra padding. */
3339 if (push_operand (x
, mode
))
3340 return emit_move_complex_push (mode
, x
, y
);
3342 /* See if we can coerce the target into moving both values at once, except
3343 for floating point where we favor moving as parts if this is easy. */
3344 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3345 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3347 && HARD_REGISTER_P (x
)
3348 && hard_regno_nregs
[REGNO (x
)][mode
] == 1)
3350 && HARD_REGISTER_P (y
)
3351 && hard_regno_nregs
[REGNO (y
)][mode
] == 1))
3353 /* Not possible if the values are inherently not adjacent. */
3354 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3356 /* Is possible if both are registers (or subregs of registers). */
3357 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3359 /* If one of the operands is a memory, and alignment constraints
3360 are friendly enough, we may be able to do combined memory operations.
3361 We do not attempt this if Y is a constant because that combination is
3362 usually better with the by-parts thing below. */
3363 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3364 && (!STRICT_ALIGNMENT
3365 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3374 /* For memory to memory moves, optimal behavior can be had with the
3375 existing block move logic. */
3376 if (MEM_P (x
) && MEM_P (y
))
3378 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3379 BLOCK_OP_NO_LIBCALL
);
3380 return get_last_insn ();
3383 ret
= emit_move_via_integer (mode
, x
, y
, true);
3388 return emit_move_complex_parts (x
, y
);
3391 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3392 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3395 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3399 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3402 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3403 if (code
!= CODE_FOR_nothing
)
3405 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3406 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3407 return emit_insn (GEN_FCN (code
) (x
, y
));
3411 /* Otherwise, find the MODE_INT mode of the same width. */
3412 ret
= emit_move_via_integer (mode
, x
, y
, false);
3413 gcc_assert (ret
!= NULL
);
3417 /* Return true if word I of OP lies entirely in the
3418 undefined bits of a paradoxical subreg. */
3421 undefined_operand_subword_p (const_rtx op
, int i
)
3423 enum machine_mode innermode
, innermostmode
;
3425 if (GET_CODE (op
) != SUBREG
)
3427 innermode
= GET_MODE (op
);
3428 innermostmode
= GET_MODE (SUBREG_REG (op
));
3429 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3430 /* The SUBREG_BYTE represents offset, as if the value were stored in
3431 memory, except for a paradoxical subreg where we define
3432 SUBREG_BYTE to be 0; undo this exception as in
3434 if (SUBREG_BYTE (op
) == 0
3435 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3437 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3438 if (WORDS_BIG_ENDIAN
)
3439 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3440 if (BYTES_BIG_ENDIAN
)
3441 offset
+= difference
% UNITS_PER_WORD
;
3443 if (offset
>= GET_MODE_SIZE (innermostmode
)
3444 || offset
<= -GET_MODE_SIZE (word_mode
))
3449 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3450 MODE is any multi-word or full-word mode that lacks a move_insn
3451 pattern. Note that you will get better code if you define such
3452 patterns, even if they must turn into multiple assembler instructions. */
3455 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3457 rtx_insn
*last_insn
= 0;
3463 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3465 /* If X is a push on the stack, do the push now and replace
3466 X with a reference to the stack pointer. */
3467 if (push_operand (x
, mode
))
3468 x
= emit_move_resolve_push (mode
, x
);
3470 /* If we are in reload, see if either operand is a MEM whose address
3471 is scheduled for replacement. */
3472 if (reload_in_progress
&& MEM_P (x
)
3473 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3474 x
= replace_equiv_address_nv (x
, inner
);
3475 if (reload_in_progress
&& MEM_P (y
)
3476 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3477 y
= replace_equiv_address_nv (y
, inner
);
3481 need_clobber
= false;
3483 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3486 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3489 /* Do not generate code for a move if it would come entirely
3490 from the undefined bits of a paradoxical subreg. */
3491 if (undefined_operand_subword_p (y
, i
))
3494 ypart
= operand_subword (y
, i
, 1, mode
);
3496 /* If we can't get a part of Y, put Y into memory if it is a
3497 constant. Otherwise, force it into a register. Then we must
3498 be able to get a part of Y. */
3499 if (ypart
== 0 && CONSTANT_P (y
))
3501 y
= use_anchored_address (force_const_mem (mode
, y
));
3502 ypart
= operand_subword (y
, i
, 1, mode
);
3504 else if (ypart
== 0)
3505 ypart
= operand_subword_force (y
, i
, mode
);
3507 gcc_assert (xpart
&& ypart
);
3509 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3511 last_insn
= emit_move_insn (xpart
, ypart
);
3517 /* Show the output dies here. This is necessary for SUBREGs
3518 of pseudos since we cannot track their lifetimes correctly;
3519 hard regs shouldn't appear here except as return values.
3520 We never want to emit such a clobber after reload. */
3522 && ! (reload_in_progress
|| reload_completed
)
3523 && need_clobber
!= 0)
3531 /* Low level part of emit_move_insn.
3532 Called just like emit_move_insn, but assumes X and Y
3533 are basically valid. */
3536 emit_move_insn_1 (rtx x
, rtx y
)
3538 enum machine_mode mode
= GET_MODE (x
);
3539 enum insn_code code
;
3541 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3543 code
= optab_handler (mov_optab
, mode
);
3544 if (code
!= CODE_FOR_nothing
)
3545 return emit_insn (GEN_FCN (code
) (x
, y
));
3547 /* Expand complex moves by moving real part and imag part. */
3548 if (COMPLEX_MODE_P (mode
))
3549 return emit_move_complex (mode
, x
, y
);
3551 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3552 || ALL_FIXED_POINT_MODE_P (mode
))
3554 rtx_insn
*result
= emit_move_via_integer (mode
, x
, y
, true);
3556 /* If we can't find an integer mode, use multi words. */
3560 return emit_move_multi_word (mode
, x
, y
);
3563 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3564 return emit_move_ccmode (mode
, x
, y
);
3566 /* Try using a move pattern for the corresponding integer mode. This is
3567 only safe when simplify_subreg can convert MODE constants into integer
3568 constants. At present, it can only do this reliably if the value
3569 fits within a HOST_WIDE_INT. */
3570 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3572 rtx_insn
*ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3576 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3581 return emit_move_multi_word (mode
, x
, y
);
3584 /* Generate code to copy Y into X.
3585 Both Y and X must have the same mode, except that
3586 Y can be a constant with VOIDmode.
3587 This mode cannot be BLKmode; use emit_block_move for that.
3589 Return the last instruction emitted. */
3592 emit_move_insn (rtx x
, rtx y
)
3594 enum machine_mode mode
= GET_MODE (x
);
3595 rtx y_cst
= NULL_RTX
;
3596 rtx_insn
*last_insn
;
3599 gcc_assert (mode
!= BLKmode
3600 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3605 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3606 && (last_insn
= compress_float_constant (x
, y
)))
3611 if (!targetm
.legitimate_constant_p (mode
, y
))
3613 y
= force_const_mem (mode
, y
);
3615 /* If the target's cannot_force_const_mem prevented the spill,
3616 assume that the target's move expanders will also take care
3617 of the non-legitimate constant. */
3621 y
= use_anchored_address (y
);
3625 /* If X or Y are memory references, verify that their addresses are valid
3628 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3630 && ! push_operand (x
, GET_MODE (x
))))
3631 x
= validize_mem (x
);
3634 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3635 MEM_ADDR_SPACE (y
)))
3636 y
= validize_mem (y
);
3638 gcc_assert (mode
!= BLKmode
);
3640 last_insn
= emit_move_insn_1 (x
, y
);
3642 if (y_cst
&& REG_P (x
)
3643 && (set
= single_set (last_insn
)) != NULL_RTX
3644 && SET_DEST (set
) == x
3645 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3646 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3651 /* If Y is representable exactly in a narrower mode, and the target can
3652 perform the extension directly from constant or memory, then emit the
3653 move as an extension. */
3656 compress_float_constant (rtx x
, rtx y
)
3658 enum machine_mode dstmode
= GET_MODE (x
);
3659 enum machine_mode orig_srcmode
= GET_MODE (y
);
3660 enum machine_mode srcmode
;
3662 int oldcost
, newcost
;
3663 bool speed
= optimize_insn_for_speed_p ();
3665 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3667 if (targetm
.legitimate_constant_p (dstmode
, y
))
3668 oldcost
= set_src_cost (y
, speed
);
3670 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3672 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3673 srcmode
!= orig_srcmode
;
3674 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3678 rtx_insn
*last_insn
;
3680 /* Skip if the target can't extend this way. */
3681 ic
= can_extend_p (dstmode
, srcmode
, 0);
3682 if (ic
== CODE_FOR_nothing
)
3685 /* Skip if the narrowed value isn't exact. */
3686 if (! exact_real_truncate (srcmode
, &r
))
3689 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3691 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3693 /* Skip if the target needs extra instructions to perform
3695 if (!insn_operand_matches (ic
, 1, trunc_y
))
3697 /* This is valid, but may not be cheaper than the original. */
3698 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3700 if (oldcost
< newcost
)
3703 else if (float_extend_from_mem
[dstmode
][srcmode
])
3705 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3706 /* This is valid, but may not be cheaper than the original. */
3707 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3709 if (oldcost
< newcost
)
3711 trunc_y
= validize_mem (trunc_y
);
3716 /* For CSE's benefit, force the compressed constant pool entry
3717 into a new pseudo. This constant may be used in different modes,
3718 and if not, combine will put things back together for us. */
3719 trunc_y
= force_reg (srcmode
, trunc_y
);
3721 /* If x is a hard register, perform the extension into a pseudo,
3722 so that e.g. stack realignment code is aware of it. */
3724 if (REG_P (x
) && HARD_REGISTER_P (x
))
3725 target
= gen_reg_rtx (dstmode
);
3727 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
3728 last_insn
= get_last_insn ();
3731 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3734 return emit_move_insn (x
, target
);
3741 /* Pushing data onto the stack. */
3743 /* Push a block of length SIZE (perhaps variable)
3744 and return an rtx to address the beginning of the block.
3745 The value may be virtual_outgoing_args_rtx.
3747 EXTRA is the number of bytes of padding to push in addition to SIZE.
3748 BELOW nonzero means this padding comes at low addresses;
3749 otherwise, the padding comes at high addresses. */
3752 push_block (rtx size
, int extra
, int below
)
3756 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3757 if (CONSTANT_P (size
))
3758 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3759 else if (REG_P (size
) && extra
== 0)
3760 anti_adjust_stack (size
);
3763 temp
= copy_to_mode_reg (Pmode
, size
);
3765 temp
= expand_binop (Pmode
, add_optab
, temp
,
3766 gen_int_mode (extra
, Pmode
),
3767 temp
, 0, OPTAB_LIB_WIDEN
);
3768 anti_adjust_stack (temp
);
3771 #ifndef STACK_GROWS_DOWNWARD
3777 temp
= virtual_outgoing_args_rtx
;
3778 if (extra
!= 0 && below
)
3779 temp
= plus_constant (Pmode
, temp
, extra
);
3783 if (CONST_INT_P (size
))
3784 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3785 -INTVAL (size
) - (below
? 0 : extra
));
3786 else if (extra
!= 0 && !below
)
3787 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3788 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3791 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3792 negate_rtx (Pmode
, size
));
3795 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3798 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3801 mem_autoinc_base (rtx mem
)
3805 rtx addr
= XEXP (mem
, 0);
3806 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3807 return XEXP (addr
, 0);
3812 /* A utility routine used here, in reload, and in try_split. The insns
3813 after PREV up to and including LAST are known to adjust the stack,
3814 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3815 placing notes as appropriate. PREV may be NULL, indicating the
3816 entire insn sequence prior to LAST should be scanned.
3818 The set of allowed stack pointer modifications is small:
3819 (1) One or more auto-inc style memory references (aka pushes),
3820 (2) One or more addition/subtraction with the SP as destination,
3821 (3) A single move insn with the SP as destination,
3822 (4) A call_pop insn,
3823 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3825 Insns in the sequence that do not modify the SP are ignored,
3826 except for noreturn calls.
3828 The return value is the amount of adjustment that can be trivially
3829 verified, via immediate operand or auto-inc. If the adjustment
3830 cannot be trivially extracted, the return value is INT_MIN. */
3833 find_args_size_adjust (rtx insn
)
3838 pat
= PATTERN (insn
);
3841 /* Look for a call_pop pattern. */
3844 /* We have to allow non-call_pop patterns for the case
3845 of emit_single_push_insn of a TLS address. */
3846 if (GET_CODE (pat
) != PARALLEL
)
3849 /* All call_pop have a stack pointer adjust in the parallel.
3850 The call itself is always first, and the stack adjust is
3851 usually last, so search from the end. */
3852 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3854 set
= XVECEXP (pat
, 0, i
);
3855 if (GET_CODE (set
) != SET
)
3857 dest
= SET_DEST (set
);
3858 if (dest
== stack_pointer_rtx
)
3861 /* We'd better have found the stack pointer adjust. */
3864 /* Fall through to process the extracted SET and DEST
3865 as if it was a standalone insn. */
3867 else if (GET_CODE (pat
) == SET
)
3869 else if ((set
= single_set (insn
)) != NULL
)
3871 else if (GET_CODE (pat
) == PARALLEL
)
3873 /* ??? Some older ports use a parallel with a stack adjust
3874 and a store for a PUSH_ROUNDING pattern, rather than a
3875 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3876 /* ??? See h8300 and m68k, pushqi1. */
3877 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3879 set
= XVECEXP (pat
, 0, i
);
3880 if (GET_CODE (set
) != SET
)
3882 dest
= SET_DEST (set
);
3883 if (dest
== stack_pointer_rtx
)
3886 /* We do not expect an auto-inc of the sp in the parallel. */
3887 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3888 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3889 != stack_pointer_rtx
);
3897 dest
= SET_DEST (set
);
3899 /* Look for direct modifications of the stack pointer. */
3900 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3902 /* Look for a trivial adjustment, otherwise assume nothing. */
3903 /* Note that the SPU restore_stack_block pattern refers to
3904 the stack pointer in V4SImode. Consider that non-trivial. */
3905 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3906 && GET_CODE (SET_SRC (set
)) == PLUS
3907 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3908 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3909 return INTVAL (XEXP (SET_SRC (set
), 1));
3910 /* ??? Reload can generate no-op moves, which will be cleaned
3911 up later. Recognize it and continue searching. */
3912 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3915 return HOST_WIDE_INT_MIN
;
3921 /* Otherwise only think about autoinc patterns. */
3922 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3925 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3926 != stack_pointer_rtx
);
3928 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3929 mem
= SET_SRC (set
);
3933 addr
= XEXP (mem
, 0);
3934 switch (GET_CODE (addr
))
3938 return GET_MODE_SIZE (GET_MODE (mem
));
3941 return -GET_MODE_SIZE (GET_MODE (mem
));
3944 addr
= XEXP (addr
, 1);
3945 gcc_assert (GET_CODE (addr
) == PLUS
);
3946 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3947 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3948 return INTVAL (XEXP (addr
, 1));
3956 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
, int end_args_size
)
3958 int args_size
= end_args_size
;
3959 bool saw_unknown
= false;
3962 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3964 HOST_WIDE_INT this_delta
;
3966 if (!NONDEBUG_INSN_P (insn
))
3969 this_delta
= find_args_size_adjust (insn
);
3970 if (this_delta
== 0)
3973 || ACCUMULATE_OUTGOING_ARGS
3974 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3978 gcc_assert (!saw_unknown
);
3979 if (this_delta
== HOST_WIDE_INT_MIN
)
3982 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3983 #ifdef STACK_GROWS_DOWNWARD
3984 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3986 args_size
-= this_delta
;
3989 return saw_unknown
? INT_MIN
: args_size
;
3992 #ifdef PUSH_ROUNDING
3993 /* Emit single push insn. */
3996 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3999 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
4001 enum insn_code icode
;
4003 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
4004 /* If there is push pattern, use it. Otherwise try old way of throwing
4005 MEM representing push operation to move expander. */
4006 icode
= optab_handler (push_optab
, mode
);
4007 if (icode
!= CODE_FOR_nothing
)
4009 struct expand_operand ops
[1];
4011 create_input_operand (&ops
[0], x
, mode
);
4012 if (maybe_expand_insn (icode
, 1, ops
))
4015 if (GET_MODE_SIZE (mode
) == rounded_size
)
4016 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
4017 /* If we are to pad downward, adjust the stack pointer first and
4018 then store X into the stack location using an offset. This is
4019 because emit_move_insn does not know how to pad; it does not have
4021 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
4023 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
4024 HOST_WIDE_INT offset
;
4026 emit_move_insn (stack_pointer_rtx
,
4027 expand_binop (Pmode
,
4028 #ifdef STACK_GROWS_DOWNWARD
4034 gen_int_mode (rounded_size
, Pmode
),
4035 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
4037 offset
= (HOST_WIDE_INT
) padding_size
;
4038 #ifdef STACK_GROWS_DOWNWARD
4039 if (STACK_PUSH_CODE
== POST_DEC
)
4040 /* We have already decremented the stack pointer, so get the
4042 offset
+= (HOST_WIDE_INT
) rounded_size
;
4044 if (STACK_PUSH_CODE
== POST_INC
)
4045 /* We have already incremented the stack pointer, so get the
4047 offset
-= (HOST_WIDE_INT
) rounded_size
;
4049 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4050 gen_int_mode (offset
, Pmode
));
4054 #ifdef STACK_GROWS_DOWNWARD
4055 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4056 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4057 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4060 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4061 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4062 gen_int_mode (rounded_size
, Pmode
));
4064 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4067 dest
= gen_rtx_MEM (mode
, dest_addr
);
4071 set_mem_attributes (dest
, type
, 1);
4073 if (cfun
->tail_call_marked
)
4074 /* Function incoming arguments may overlap with sibling call
4075 outgoing arguments and we cannot allow reordering of reads
4076 from function arguments with stores to outgoing arguments
4077 of sibling calls. */
4078 set_mem_alias_set (dest
, 0);
4080 emit_move_insn (dest
, x
);
4083 /* Emit and annotate a single push insn. */
4086 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
4088 int delta
, old_delta
= stack_pointer_delta
;
4089 rtx_insn
*prev
= get_last_insn ();
4092 emit_single_push_insn_1 (mode
, x
, type
);
4094 last
= get_last_insn ();
4096 /* Notice the common case where we emitted exactly one insn. */
4097 if (PREV_INSN (last
) == prev
)
4099 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4103 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4104 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4108 /* Generate code to push X onto the stack, assuming it has mode MODE and
4110 MODE is redundant except when X is a CONST_INT (since they don't
4112 SIZE is an rtx for the size of data to be copied (in bytes),
4113 needed only if X is BLKmode.
4115 ALIGN (in bits) is maximum alignment we can assume.
4117 If PARTIAL and REG are both nonzero, then copy that many of the first
4118 bytes of X into registers starting with REG, and push the rest of X.
4119 The amount of space pushed is decreased by PARTIAL bytes.
4120 REG must be a hard register in this case.
4121 If REG is zero but PARTIAL is not, take any all others actions for an
4122 argument partially in registers, but do not actually load any
4125 EXTRA is the amount in bytes of extra space to leave next to this arg.
4126 This is ignored if an argument block has already been allocated.
4128 On a machine that lacks real push insns, ARGS_ADDR is the address of
4129 the bottom of the argument block for this call. We use indexing off there
4130 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4131 argument block has not been preallocated.
4133 ARGS_SO_FAR is the size of args previously pushed for this call.
4135 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4136 for arguments passed in registers. If nonzero, it will be the number
4137 of bytes required. */
4140 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
4141 unsigned int align
, int partial
, rtx reg
, int extra
,
4142 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4146 enum direction stack_direction
4147 #ifdef STACK_GROWS_DOWNWARD
4153 /* Decide where to pad the argument: `downward' for below,
4154 `upward' for above, or `none' for don't pad it.
4155 Default is below for small data on big-endian machines; else above. */
4156 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4158 /* Invert direction if stack is post-decrement.
4160 if (STACK_PUSH_CODE
== POST_DEC
)
4161 if (where_pad
!= none
)
4162 where_pad
= (where_pad
== downward
? upward
: downward
);
4167 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4169 /* Copy a block into the stack, entirely or partially. */
4176 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4177 used
= partial
- offset
;
4179 if (mode
!= BLKmode
)
4181 /* A value is to be stored in an insufficiently aligned
4182 stack slot; copy via a suitably aligned slot if
4184 size
= GEN_INT (GET_MODE_SIZE (mode
));
4185 if (!MEM_P (xinner
))
4187 temp
= assign_temp (type
, 1, 1);
4188 emit_move_insn (temp
, xinner
);
4195 /* USED is now the # of bytes we need not copy to the stack
4196 because registers will take care of them. */
4199 xinner
= adjust_address (xinner
, BLKmode
, used
);
4201 /* If the partial register-part of the arg counts in its stack size,
4202 skip the part of stack space corresponding to the registers.
4203 Otherwise, start copying to the beginning of the stack space,
4204 by setting SKIP to 0. */
4205 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4207 #ifdef PUSH_ROUNDING
4208 /* Do it with several push insns if that doesn't take lots of insns
4209 and if there is no difficulty with push insns that skip bytes
4210 on the stack for alignment purposes. */
4213 && CONST_INT_P (size
)
4215 && MEM_ALIGN (xinner
) >= align
4216 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4217 /* Here we avoid the case of a structure whose weak alignment
4218 forces many pushes of a small amount of data,
4219 and such small pushes do rounding that causes trouble. */
4220 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4221 || align
>= BIGGEST_ALIGNMENT
4222 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4223 == (align
/ BITS_PER_UNIT
)))
4224 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4226 /* Push padding now if padding above and stack grows down,
4227 or if padding below and stack grows up.
4228 But if space already allocated, this has already been done. */
4229 if (extra
&& args_addr
== 0
4230 && where_pad
!= none
&& where_pad
!= stack_direction
)
4231 anti_adjust_stack (GEN_INT (extra
));
4233 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4236 #endif /* PUSH_ROUNDING */
4240 /* Otherwise make space on the stack and copy the data
4241 to the address of that space. */
4243 /* Deduct words put into registers from the size we must copy. */
4246 if (CONST_INT_P (size
))
4247 size
= GEN_INT (INTVAL (size
) - used
);
4249 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4250 gen_int_mode (used
, GET_MODE (size
)),
4251 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4254 /* Get the address of the stack space.
4255 In this case, we do not deal with EXTRA separately.
4256 A single stack adjust will do. */
4259 temp
= push_block (size
, extra
, where_pad
== downward
);
4262 else if (CONST_INT_P (args_so_far
))
4263 temp
= memory_address (BLKmode
,
4264 plus_constant (Pmode
, args_addr
,
4265 skip
+ INTVAL (args_so_far
)));
4267 temp
= memory_address (BLKmode
,
4268 plus_constant (Pmode
,
4269 gen_rtx_PLUS (Pmode
,
4274 if (!ACCUMULATE_OUTGOING_ARGS
)
4276 /* If the source is referenced relative to the stack pointer,
4277 copy it to another register to stabilize it. We do not need
4278 to do this if we know that we won't be changing sp. */
4280 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4281 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4282 temp
= copy_to_reg (temp
);
4285 target
= gen_rtx_MEM (BLKmode
, temp
);
4287 /* We do *not* set_mem_attributes here, because incoming arguments
4288 may overlap with sibling call outgoing arguments and we cannot
4289 allow reordering of reads from function arguments with stores
4290 to outgoing arguments of sibling calls. We do, however, want
4291 to record the alignment of the stack slot. */
4292 /* ALIGN may well be better aligned than TYPE, e.g. due to
4293 PARM_BOUNDARY. Assume the caller isn't lying. */
4294 set_mem_align (target
, align
);
4296 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4299 else if (partial
> 0)
4301 /* Scalar partly in registers. */
4303 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4306 /* # bytes of start of argument
4307 that we must make space for but need not store. */
4308 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4309 int args_offset
= INTVAL (args_so_far
);
4312 /* Push padding now if padding above and stack grows down,
4313 or if padding below and stack grows up.
4314 But if space already allocated, this has already been done. */
4315 if (extra
&& args_addr
== 0
4316 && where_pad
!= none
&& where_pad
!= stack_direction
)
4317 anti_adjust_stack (GEN_INT (extra
));
4319 /* If we make space by pushing it, we might as well push
4320 the real data. Otherwise, we can leave OFFSET nonzero
4321 and leave the space uninitialized. */
4325 /* Now NOT_STACK gets the number of words that we don't need to
4326 allocate on the stack. Convert OFFSET to words too. */
4327 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4328 offset
/= UNITS_PER_WORD
;
4330 /* If the partial register-part of the arg counts in its stack size,
4331 skip the part of stack space corresponding to the registers.
4332 Otherwise, start copying to the beginning of the stack space,
4333 by setting SKIP to 0. */
4334 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4336 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4337 x
= validize_mem (force_const_mem (mode
, x
));
4339 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4340 SUBREGs of such registers are not allowed. */
4341 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4342 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4343 x
= copy_to_reg (x
);
4345 /* Loop over all the words allocated on the stack for this arg. */
4346 /* We can do it by words, because any scalar bigger than a word
4347 has a size a multiple of a word. */
4348 for (i
= size
- 1; i
>= not_stack
; i
--)
4349 if (i
>= not_stack
+ offset
)
4350 emit_push_insn (operand_subword_force (x
, i
, mode
),
4351 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4353 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4355 reg_parm_stack_space
, alignment_pad
);
4362 /* Push padding now if padding above and stack grows down,
4363 or if padding below and stack grows up.
4364 But if space already allocated, this has already been done. */
4365 if (extra
&& args_addr
== 0
4366 && where_pad
!= none
&& where_pad
!= stack_direction
)
4367 anti_adjust_stack (GEN_INT (extra
));
4369 #ifdef PUSH_ROUNDING
4370 if (args_addr
== 0 && PUSH_ARGS
)
4371 emit_single_push_insn (mode
, x
, type
);
4375 if (CONST_INT_P (args_so_far
))
4377 = memory_address (mode
,
4378 plus_constant (Pmode
, args_addr
,
4379 INTVAL (args_so_far
)));
4381 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4383 dest
= gen_rtx_MEM (mode
, addr
);
4385 /* We do *not* set_mem_attributes here, because incoming arguments
4386 may overlap with sibling call outgoing arguments and we cannot
4387 allow reordering of reads from function arguments with stores
4388 to outgoing arguments of sibling calls. We do, however, want
4389 to record the alignment of the stack slot. */
4390 /* ALIGN may well be better aligned than TYPE, e.g. due to
4391 PARM_BOUNDARY. Assume the caller isn't lying. */
4392 set_mem_align (dest
, align
);
4394 emit_move_insn (dest
, x
);
4398 /* If part should go in registers, copy that part
4399 into the appropriate registers. Do this now, at the end,
4400 since mem-to-mem copies above may do function calls. */
4401 if (partial
> 0 && reg
!= 0)
4403 /* Handle calls that pass values in multiple non-contiguous locations.
4404 The Irix 6 ABI has examples of this. */
4405 if (GET_CODE (reg
) == PARALLEL
)
4406 emit_group_load (reg
, x
, type
, -1);
4409 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4410 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4414 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4415 anti_adjust_stack (GEN_INT (extra
));
4417 if (alignment_pad
&& args_addr
== 0)
4418 anti_adjust_stack (alignment_pad
);
4421 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4425 get_subtarget (rtx x
)
4429 /* Only registers can be subtargets. */
4431 /* Don't use hard regs to avoid extending their life. */
4432 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4436 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4437 FIELD is a bitfield. Returns true if the optimization was successful,
4438 and there's nothing else to do. */
4441 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4442 unsigned HOST_WIDE_INT bitpos
,
4443 unsigned HOST_WIDE_INT bitregion_start
,
4444 unsigned HOST_WIDE_INT bitregion_end
,
4445 enum machine_mode mode1
, rtx str_rtx
,
4448 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4449 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4454 enum tree_code code
;
4456 if (mode1
!= VOIDmode
4457 || bitsize
>= BITS_PER_WORD
4458 || str_bitsize
> BITS_PER_WORD
4459 || TREE_SIDE_EFFECTS (to
)
4460 || TREE_THIS_VOLATILE (to
))
4464 if (TREE_CODE (src
) != SSA_NAME
)
4466 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4469 srcstmt
= get_gimple_for_ssa_name (src
);
4471 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4474 code
= gimple_assign_rhs_code (srcstmt
);
4476 op0
= gimple_assign_rhs1 (srcstmt
);
4478 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4479 to find its initialization. Hopefully the initialization will
4480 be from a bitfield load. */
4481 if (TREE_CODE (op0
) == SSA_NAME
)
4483 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4485 /* We want to eventually have OP0 be the same as TO, which
4486 should be a bitfield. */
4488 || !is_gimple_assign (op0stmt
)
4489 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4491 op0
= gimple_assign_rhs1 (op0stmt
);
4494 op1
= gimple_assign_rhs2 (srcstmt
);
4496 if (!operand_equal_p (to
, op0
, 0))
4499 if (MEM_P (str_rtx
))
4501 unsigned HOST_WIDE_INT offset1
;
4503 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4504 str_mode
= word_mode
;
4505 str_mode
= get_best_mode (bitsize
, bitpos
,
4506 bitregion_start
, bitregion_end
,
4507 MEM_ALIGN (str_rtx
), str_mode
, 0);
4508 if (str_mode
== VOIDmode
)
4510 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4513 bitpos
%= str_bitsize
;
4514 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4515 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4517 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4520 /* If the bit field covers the whole REG/MEM, store_field
4521 will likely generate better code. */
4522 if (bitsize
>= str_bitsize
)
4525 /* We can't handle fields split across multiple entities. */
4526 if (bitpos
+ bitsize
> str_bitsize
)
4529 if (BYTES_BIG_ENDIAN
)
4530 bitpos
= str_bitsize
- bitpos
- bitsize
;
4536 /* For now, just optimize the case of the topmost bitfield
4537 where we don't need to do any masking and also
4538 1 bit bitfields where xor can be used.
4539 We might win by one instruction for the other bitfields
4540 too if insv/extv instructions aren't used, so that
4541 can be added later. */
4542 if (bitpos
+ bitsize
!= str_bitsize
4543 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4546 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4547 value
= convert_modes (str_mode
,
4548 TYPE_MODE (TREE_TYPE (op1
)), value
,
4549 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4551 /* We may be accessing data outside the field, which means
4552 we can alias adjacent data. */
4553 if (MEM_P (str_rtx
))
4555 str_rtx
= shallow_copy_rtx (str_rtx
);
4556 set_mem_alias_set (str_rtx
, 0);
4557 set_mem_expr (str_rtx
, 0);
4560 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4561 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4563 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4566 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4567 result
= expand_binop (str_mode
, binop
, str_rtx
,
4568 value
, str_rtx
, 1, OPTAB_WIDEN
);
4569 if (result
!= str_rtx
)
4570 emit_move_insn (str_rtx
, result
);
4575 if (TREE_CODE (op1
) != INTEGER_CST
)
4577 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4578 value
= convert_modes (str_mode
,
4579 TYPE_MODE (TREE_TYPE (op1
)), value
,
4580 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4582 /* We may be accessing data outside the field, which means
4583 we can alias adjacent data. */
4584 if (MEM_P (str_rtx
))
4586 str_rtx
= shallow_copy_rtx (str_rtx
);
4587 set_mem_alias_set (str_rtx
, 0);
4588 set_mem_expr (str_rtx
, 0);
4591 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4592 if (bitpos
+ bitsize
!= str_bitsize
)
4594 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4596 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4598 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4599 result
= expand_binop (str_mode
, binop
, str_rtx
,
4600 value
, str_rtx
, 1, OPTAB_WIDEN
);
4601 if (result
!= str_rtx
)
4602 emit_move_insn (str_rtx
, result
);
4612 /* In the C++ memory model, consecutive bit fields in a structure are
4613 considered one memory location.
4615 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4616 returns the bit range of consecutive bits in which this COMPONENT_REF
4617 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4618 and *OFFSET may be adjusted in the process.
4620 If the access does not need to be restricted, 0 is returned in both
4621 *BITSTART and *BITEND. */
4624 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4625 unsigned HOST_WIDE_INT
*bitend
,
4627 HOST_WIDE_INT
*bitpos
,
4630 HOST_WIDE_INT bitoffset
;
4633 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4635 field
= TREE_OPERAND (exp
, 1);
4636 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4637 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4638 need to limit the range we can access. */
4641 *bitstart
= *bitend
= 0;
4645 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4646 part of a larger bit field, then the representative does not serve any
4647 useful purpose. This can occur in Ada. */
4648 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4650 enum machine_mode rmode
;
4651 HOST_WIDE_INT rbitsize
, rbitpos
;
4655 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4656 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4657 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4659 *bitstart
= *bitend
= 0;
4664 /* Compute the adjustment to bitpos from the offset of the field
4665 relative to the representative. DECL_FIELD_OFFSET of field and
4666 repr are the same by construction if they are not constants,
4667 see finish_bitfield_layout. */
4668 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4669 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4670 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4671 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4674 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4675 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4677 /* If the adjustment is larger than bitpos, we would have a negative bit
4678 position for the lower bound and this may wreak havoc later. Adjust
4679 offset and bitpos to make the lower bound non-negative in that case. */
4680 if (bitoffset
> *bitpos
)
4682 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4683 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4686 if (*offset
== NULL_TREE
)
4687 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4690 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4694 *bitstart
= *bitpos
- bitoffset
;
4696 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4699 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4700 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4701 DECL_RTL was not set yet, return NORTL. */
4704 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4706 if (TREE_CODE (addr
) != ADDR_EXPR
)
4709 tree base
= TREE_OPERAND (addr
, 0);
4712 || TREE_ADDRESSABLE (base
)
4713 || DECL_MODE (base
) == BLKmode
)
4716 if (!DECL_RTL_SET_P (base
))
4719 return (!MEM_P (DECL_RTL (base
)));
4722 /* Returns true if the MEM_REF REF refers to an object that does not
4723 reside in memory and has non-BLKmode. */
4726 mem_ref_refers_to_non_mem_p (tree ref
)
4728 tree base
= TREE_OPERAND (ref
, 0);
4729 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4732 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4733 is true, try generating a nontemporal store. */
4736 expand_assignment (tree to
, tree from
, bool nontemporal
)
4740 enum machine_mode mode
;
4742 enum insn_code icode
;
4744 /* Don't crash if the lhs of the assignment was erroneous. */
4745 if (TREE_CODE (to
) == ERROR_MARK
)
4747 expand_normal (from
);
4751 /* Optimize away no-op moves without side-effects. */
4752 if (operand_equal_p (to
, from
, 0))
4755 /* Handle misaligned stores. */
4756 mode
= TYPE_MODE (TREE_TYPE (to
));
4757 if ((TREE_CODE (to
) == MEM_REF
4758 || TREE_CODE (to
) == TARGET_MEM_REF
)
4760 && !mem_ref_refers_to_non_mem_p (to
)
4761 && ((align
= get_object_alignment (to
))
4762 < GET_MODE_ALIGNMENT (mode
))
4763 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4764 != CODE_FOR_nothing
)
4765 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4769 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4770 reg
= force_not_mem (reg
);
4771 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4773 if (icode
!= CODE_FOR_nothing
)
4775 struct expand_operand ops
[2];
4777 create_fixed_operand (&ops
[0], mem
);
4778 create_input_operand (&ops
[1], reg
, mode
);
4779 /* The movmisalign<mode> pattern cannot fail, else the assignment
4780 would silently be omitted. */
4781 expand_insn (icode
, 2, ops
);
4784 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
);
4788 /* Assignment of a structure component needs special treatment
4789 if the structure component's rtx is not simply a MEM.
4790 Assignment of an array element at a constant index, and assignment of
4791 an array element in an unaligned packed structure field, has the same
4792 problem. Same for (partially) storing into a non-memory object. */
4793 if (handled_component_p (to
)
4794 || (TREE_CODE (to
) == MEM_REF
4795 && mem_ref_refers_to_non_mem_p (to
))
4796 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4798 enum machine_mode mode1
;
4799 HOST_WIDE_INT bitsize
, bitpos
;
4800 unsigned HOST_WIDE_INT bitregion_start
= 0;
4801 unsigned HOST_WIDE_INT bitregion_end
= 0;
4808 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4809 &unsignedp
, &volatilep
, true);
4811 /* Make sure bitpos is not negative, it can wreak havoc later. */
4814 gcc_assert (offset
== NULL_TREE
);
4815 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4816 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4817 bitpos
&= BITS_PER_UNIT
- 1;
4820 if (TREE_CODE (to
) == COMPONENT_REF
4821 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4822 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4823 /* The C++ memory model naturally applies to byte-aligned fields.
4824 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
4825 BITSIZE are not byte-aligned, there is no need to limit the range
4826 we can access. This can occur with packed structures in Ada. */
4827 else if (bitsize
> 0
4828 && bitsize
% BITS_PER_UNIT
== 0
4829 && bitpos
% BITS_PER_UNIT
== 0)
4831 bitregion_start
= bitpos
;
4832 bitregion_end
= bitpos
+ bitsize
- 1;
4835 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4837 /* If the field has a mode, we want to access it in the
4838 field's mode, not the computed mode.
4839 If a MEM has VOIDmode (external with incomplete type),
4840 use BLKmode for it instead. */
4843 if (mode1
!= VOIDmode
)
4844 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4845 else if (GET_MODE (to_rtx
) == VOIDmode
)
4846 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4851 enum machine_mode address_mode
;
4854 if (!MEM_P (to_rtx
))
4856 /* We can get constant negative offsets into arrays with broken
4857 user code. Translate this to a trap instead of ICEing. */
4858 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4859 expand_builtin_trap ();
4860 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4863 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4864 address_mode
= get_address_mode (to_rtx
);
4865 if (GET_MODE (offset_rtx
) != address_mode
)
4866 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4868 /* If we have an expression in OFFSET_RTX and a non-zero
4869 byte offset in BITPOS, adding the byte offset before the
4870 OFFSET_RTX results in better intermediate code, which makes
4871 later rtl optimization passes perform better.
4873 We prefer intermediate code like this:
4875 r124:DI=r123:DI+0x18
4880 r124:DI=r123:DI+0x10
4881 [r124:DI+0x8]=r121:DI
4883 This is only done for aligned data values, as these can
4884 be expected to result in single move instructions. */
4885 if (mode1
!= VOIDmode
4888 && (bitpos
% bitsize
) == 0
4889 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4890 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
4892 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4893 bitregion_start
= 0;
4894 if (bitregion_end
>= (unsigned HOST_WIDE_INT
) bitpos
)
4895 bitregion_end
-= bitpos
;
4899 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4900 highest_pow2_factor_for_target (to
,
4904 /* No action is needed if the target is not a memory and the field
4905 lies completely outside that target. This can occur if the source
4906 code contains an out-of-bounds access to a small array. */
4908 && GET_MODE (to_rtx
) != BLKmode
4909 && (unsigned HOST_WIDE_INT
) bitpos
4910 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4912 expand_normal (from
);
4915 /* Handle expand_expr of a complex value returning a CONCAT. */
4916 else if (GET_CODE (to_rtx
) == CONCAT
)
4918 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4919 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4921 && bitsize
== mode_bitsize
)
4922 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4923 else if (bitsize
== mode_bitsize
/ 2
4924 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4925 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4927 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4928 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4929 bitregion_start
, bitregion_end
,
4931 get_alias_set (to
), nontemporal
);
4932 else if (bitpos
>= mode_bitsize
/ 2)
4933 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4934 bitpos
- mode_bitsize
/ 2,
4935 bitregion_start
, bitregion_end
,
4937 get_alias_set (to
), nontemporal
);
4938 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4941 result
= expand_normal (from
);
4942 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4943 TYPE_MODE (TREE_TYPE (from
)), 0);
4944 emit_move_insn (XEXP (to_rtx
, 0),
4945 read_complex_part (from_rtx
, false));
4946 emit_move_insn (XEXP (to_rtx
, 1),
4947 read_complex_part (from_rtx
, true));
4951 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4952 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4953 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4954 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4955 result
= store_field (temp
, bitsize
, bitpos
,
4956 bitregion_start
, bitregion_end
,
4958 get_alias_set (to
), nontemporal
);
4959 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4960 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4967 /* If the field is at offset zero, we could have been given the
4968 DECL_RTX of the parent struct. Don't munge it. */
4969 to_rtx
= shallow_copy_rtx (to_rtx
);
4970 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4972 MEM_VOLATILE_P (to_rtx
) = 1;
4975 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4976 bitregion_start
, bitregion_end
,
4981 result
= store_field (to_rtx
, bitsize
, bitpos
,
4982 bitregion_start
, bitregion_end
,
4984 get_alias_set (to
), nontemporal
);
4988 preserve_temp_slots (result
);
4993 /* If the rhs is a function call and its value is not an aggregate,
4994 call the function before we start to compute the lhs.
4995 This is needed for correct code for cases such as
4996 val = setjmp (buf) on machines where reference to val
4997 requires loading up part of an address in a separate insn.
4999 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
5000 since it might be a promoted variable where the zero- or sign- extension
5001 needs to be done. Handling this in the normal way is safe because no
5002 computation is done before the call. The same is true for SSA names. */
5003 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
5004 && COMPLETE_TYPE_P (TREE_TYPE (from
))
5005 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
5006 && ! (((TREE_CODE (to
) == VAR_DECL
5007 || TREE_CODE (to
) == PARM_DECL
5008 || TREE_CODE (to
) == RESULT_DECL
)
5009 && REG_P (DECL_RTL (to
)))
5010 || TREE_CODE (to
) == SSA_NAME
))
5015 value
= expand_normal (from
);
5017 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5019 /* Handle calls that return values in multiple non-contiguous locations.
5020 The Irix 6 ABI has examples of this. */
5021 if (GET_CODE (to_rtx
) == PARALLEL
)
5023 if (GET_CODE (value
) == PARALLEL
)
5024 emit_group_move (to_rtx
, value
);
5026 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5027 int_size_in_bytes (TREE_TYPE (from
)));
5029 else if (GET_CODE (value
) == PARALLEL
)
5030 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5031 int_size_in_bytes (TREE_TYPE (from
)));
5032 else if (GET_MODE (to_rtx
) == BLKmode
)
5034 /* Handle calls that return BLKmode values in registers. */
5036 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5038 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5042 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5043 value
= convert_memory_address_addr_space
5044 (GET_MODE (to_rtx
), value
,
5045 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5047 emit_move_insn (to_rtx
, value
);
5049 preserve_temp_slots (to_rtx
);
5054 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5055 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5057 /* Don't move directly into a return register. */
5058 if (TREE_CODE (to
) == RESULT_DECL
5059 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5065 /* If the source is itself a return value, it still is in a pseudo at
5066 this point so we can move it back to the return register directly. */
5068 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5069 && TREE_CODE (from
) != CALL_EXPR
)
5070 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5072 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5074 /* Handle calls that return values in multiple non-contiguous locations.
5075 The Irix 6 ABI has examples of this. */
5076 if (GET_CODE (to_rtx
) == PARALLEL
)
5078 if (GET_CODE (temp
) == PARALLEL
)
5079 emit_group_move (to_rtx
, temp
);
5081 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5082 int_size_in_bytes (TREE_TYPE (from
)));
5085 emit_move_insn (to_rtx
, temp
);
5087 preserve_temp_slots (to_rtx
);
5092 /* In case we are returning the contents of an object which overlaps
5093 the place the value is being stored, use a safe function when copying
5094 a value through a pointer into a structure value return block. */
5095 if (TREE_CODE (to
) == RESULT_DECL
5096 && TREE_CODE (from
) == INDIRECT_REF
5097 && ADDR_SPACE_GENERIC_P
5098 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5099 && refs_may_alias_p (to
, from
)
5100 && cfun
->returns_struct
5101 && !cfun
->returns_pcc_struct
)
5106 size
= expr_size (from
);
5107 from_rtx
= expand_normal (from
);
5109 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5110 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5111 XEXP (from_rtx
, 0), Pmode
,
5112 convert_to_mode (TYPE_MODE (sizetype
),
5113 size
, TYPE_UNSIGNED (sizetype
)),
5114 TYPE_MODE (sizetype
));
5116 preserve_temp_slots (to_rtx
);
5121 /* Compute FROM and store the value in the rtx we got. */
5124 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
5125 preserve_temp_slots (result
);
5130 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5131 succeeded, false otherwise. */
5134 emit_storent_insn (rtx to
, rtx from
)
5136 struct expand_operand ops
[2];
5137 enum machine_mode mode
= GET_MODE (to
);
5138 enum insn_code code
= optab_handler (storent_optab
, mode
);
5140 if (code
== CODE_FOR_nothing
)
5143 create_fixed_operand (&ops
[0], to
);
5144 create_input_operand (&ops
[1], from
, mode
);
5145 return maybe_expand_insn (code
, 2, ops
);
5148 /* Generate code for computing expression EXP,
5149 and storing the value into TARGET.
5151 If the mode is BLKmode then we may return TARGET itself.
5152 It turns out that in BLKmode it doesn't cause a problem.
5153 because C has no operators that could combine two different
5154 assignments into the same BLKmode object with different values
5155 with no sequence point. Will other languages need this to
5158 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5159 stack, and block moves may need to be treated specially.
5161 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5164 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5167 rtx alt_rtl
= NULL_RTX
;
5168 location_t loc
= curr_insn_location ();
5170 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5172 /* C++ can generate ?: expressions with a throw expression in one
5173 branch and an rvalue in the other. Here, we resolve attempts to
5174 store the throw expression's nonexistent result. */
5175 gcc_assert (!call_param_p
);
5176 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5179 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5181 /* Perform first part of compound expression, then assign from second
5183 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5184 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5185 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5188 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5190 /* For conditional expression, get safe form of the target. Then
5191 test the condition, doing the appropriate assignment on either
5192 side. This avoids the creation of unnecessary temporaries.
5193 For non-BLKmode, it is more efficient not to do this. */
5195 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
5197 do_pending_stack_adjust ();
5199 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5200 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5202 emit_jump_insn (gen_jump (lab2
));
5205 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5212 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5213 /* If this is a scalar in a register that is stored in a wider mode
5214 than the declared mode, compute the result into its declared mode
5215 and then convert to the wider mode. Our value is the computed
5218 rtx inner_target
= 0;
5220 /* We can do the conversion inside EXP, which will often result
5221 in some optimizations. Do the conversion in two steps: first
5222 change the signedness, if needed, then the extend. But don't
5223 do this if the type of EXP is a subtype of something else
5224 since then the conversion might involve more than just
5225 converting modes. */
5226 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5227 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5228 && GET_MODE_PRECISION (GET_MODE (target
))
5229 == TYPE_PRECISION (TREE_TYPE (exp
)))
5231 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
5232 TYPE_UNSIGNED (TREE_TYPE (exp
))))
5234 /* Some types, e.g. Fortran's logical*4, won't have a signed
5235 version, so use the mode instead. */
5237 = (signed_or_unsigned_type_for
5238 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
5240 ntype
= lang_hooks
.types
.type_for_mode
5241 (TYPE_MODE (TREE_TYPE (exp
)),
5242 SUBREG_PROMOTED_SIGN (target
));
5244 exp
= fold_convert_loc (loc
, ntype
, exp
);
5247 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5248 (GET_MODE (SUBREG_REG (target
)),
5249 SUBREG_PROMOTED_SIGN (target
)),
5252 inner_target
= SUBREG_REG (target
);
5255 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5256 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5258 /* If TEMP is a VOIDmode constant, use convert_modes to make
5259 sure that we properly convert it. */
5260 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5262 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5263 temp
, SUBREG_PROMOTED_SIGN (target
));
5264 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5265 GET_MODE (target
), temp
,
5266 SUBREG_PROMOTED_SIGN (target
));
5269 convert_move (SUBREG_REG (target
), temp
,
5270 SUBREG_PROMOTED_SIGN (target
));
5274 else if ((TREE_CODE (exp
) == STRING_CST
5275 || (TREE_CODE (exp
) == MEM_REF
5276 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5277 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5279 && integer_zerop (TREE_OPERAND (exp
, 1))))
5280 && !nontemporal
&& !call_param_p
5283 /* Optimize initialization of an array with a STRING_CST. */
5284 HOST_WIDE_INT exp_len
, str_copy_len
;
5286 tree str
= TREE_CODE (exp
) == STRING_CST
5287 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5289 exp_len
= int_expr_size (exp
);
5293 if (TREE_STRING_LENGTH (str
) <= 0)
5296 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5297 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5300 str_copy_len
= TREE_STRING_LENGTH (str
);
5301 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5302 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5304 str_copy_len
+= STORE_MAX_PIECES
- 1;
5305 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5307 str_copy_len
= MIN (str_copy_len
, exp_len
);
5308 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5309 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5310 MEM_ALIGN (target
), false))
5315 dest_mem
= store_by_pieces (dest_mem
,
5316 str_copy_len
, builtin_strncpy_read_str
,
5318 TREE_STRING_POINTER (str
)),
5319 MEM_ALIGN (target
), false,
5320 exp_len
> str_copy_len
? 1 : 0);
5321 if (exp_len
> str_copy_len
)
5322 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5323 GEN_INT (exp_len
- str_copy_len
),
5332 /* If we want to use a nontemporal store, force the value to
5334 tmp_target
= nontemporal
? NULL_RTX
: target
;
5335 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5337 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5341 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5342 the same as that of TARGET, adjust the constant. This is needed, for
5343 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5344 only a word-sized value. */
5345 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5346 && TREE_CODE (exp
) != ERROR_MARK
5347 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5348 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5349 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5351 /* If value was not generated in the target, store it there.
5352 Convert the value to TARGET's type first if necessary and emit the
5353 pending incrementations that have been queued when expanding EXP.
5354 Note that we cannot emit the whole queue blindly because this will
5355 effectively disable the POST_INC optimization later.
5357 If TEMP and TARGET compare equal according to rtx_equal_p, but
5358 one or both of them are volatile memory refs, we have to distinguish
5360 - expand_expr has used TARGET. In this case, we must not generate
5361 another copy. This can be detected by TARGET being equal according
5363 - expand_expr has not used TARGET - that means that the source just
5364 happens to have the same RTX form. Since temp will have been created
5365 by expand_expr, it will compare unequal according to == .
5366 We must generate a copy in this case, to reach the correct number
5367 of volatile memory references. */
5369 if ((! rtx_equal_p (temp
, target
)
5370 || (temp
!= target
&& (side_effects_p (temp
)
5371 || side_effects_p (target
))))
5372 && TREE_CODE (exp
) != ERROR_MARK
5373 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5374 but TARGET is not valid memory reference, TEMP will differ
5375 from TARGET although it is really the same location. */
5377 && rtx_equal_p (alt_rtl
, target
)
5378 && !side_effects_p (alt_rtl
)
5379 && !side_effects_p (target
))
5380 /* If there's nothing to copy, don't bother. Don't call
5381 expr_size unless necessary, because some front-ends (C++)
5382 expr_size-hook must not be given objects that are not
5383 supposed to be bit-copied or bit-initialized. */
5384 && expr_size (exp
) != const0_rtx
)
5386 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5388 if (GET_MODE (target
) == BLKmode
)
5390 /* Handle calls that return BLKmode values in registers. */
5391 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5392 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5394 store_bit_field (target
,
5395 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5396 0, 0, 0, GET_MODE (temp
), temp
);
5399 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5402 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5404 /* Handle copying a string constant into an array. The string
5405 constant may be shorter than the array. So copy just the string's
5406 actual length, and clear the rest. First get the size of the data
5407 type of the string, which is actually the size of the target. */
5408 rtx size
= expr_size (exp
);
5410 if (CONST_INT_P (size
)
5411 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5412 emit_block_move (target
, temp
, size
,
5414 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5417 enum machine_mode pointer_mode
5418 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5419 enum machine_mode address_mode
= get_address_mode (target
);
5421 /* Compute the size of the data to copy from the string. */
5423 = size_binop_loc (loc
, MIN_EXPR
,
5424 make_tree (sizetype
, size
),
5425 size_int (TREE_STRING_LENGTH (exp
)));
5427 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5429 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5430 rtx_code_label
*label
= 0;
5432 /* Copy that much. */
5433 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5434 TYPE_UNSIGNED (sizetype
));
5435 emit_block_move (target
, temp
, copy_size_rtx
,
5437 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5439 /* Figure out how much is left in TARGET that we have to clear.
5440 Do all calculations in pointer_mode. */
5441 if (CONST_INT_P (copy_size_rtx
))
5443 size
= plus_constant (address_mode
, size
,
5444 -INTVAL (copy_size_rtx
));
5445 target
= adjust_address (target
, BLKmode
,
5446 INTVAL (copy_size_rtx
));
5450 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5451 copy_size_rtx
, NULL_RTX
, 0,
5454 if (GET_MODE (copy_size_rtx
) != address_mode
)
5455 copy_size_rtx
= convert_to_mode (address_mode
,
5457 TYPE_UNSIGNED (sizetype
));
5459 target
= offset_address (target
, copy_size_rtx
,
5460 highest_pow2_factor (copy_size
));
5461 label
= gen_label_rtx ();
5462 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5463 GET_MODE (size
), 0, label
);
5466 if (size
!= const0_rtx
)
5467 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5473 /* Handle calls that return values in multiple non-contiguous locations.
5474 The Irix 6 ABI has examples of this. */
5475 else if (GET_CODE (target
) == PARALLEL
)
5477 if (GET_CODE (temp
) == PARALLEL
)
5478 emit_group_move (target
, temp
);
5480 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5481 int_size_in_bytes (TREE_TYPE (exp
)));
5483 else if (GET_CODE (temp
) == PARALLEL
)
5484 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5485 int_size_in_bytes (TREE_TYPE (exp
)));
5486 else if (GET_MODE (temp
) == BLKmode
)
5487 emit_block_move (target
, temp
, expr_size (exp
),
5489 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5490 /* If we emit a nontemporal store, there is nothing else to do. */
5491 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5495 temp
= force_operand (temp
, target
);
5497 emit_move_insn (target
, temp
);
5504 /* Return true if field F of structure TYPE is a flexible array. */
5507 flexible_array_member_p (const_tree f
, const_tree type
)
5512 return (DECL_CHAIN (f
) == NULL
5513 && TREE_CODE (tf
) == ARRAY_TYPE
5515 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5516 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5517 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5518 && int_size_in_bytes (type
) >= 0);
5521 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5522 must have in order for it to completely initialize a value of type TYPE.
5523 Return -1 if the number isn't known.
5525 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5527 static HOST_WIDE_INT
5528 count_type_elements (const_tree type
, bool for_ctor_p
)
5530 switch (TREE_CODE (type
))
5536 nelts
= array_type_nelts (type
);
5537 if (nelts
&& tree_fits_uhwi_p (nelts
))
5539 unsigned HOST_WIDE_INT n
;
5541 n
= tree_to_uhwi (nelts
) + 1;
5542 if (n
== 0 || for_ctor_p
)
5545 return n
* count_type_elements (TREE_TYPE (type
), false);
5547 return for_ctor_p
? -1 : 1;
5552 unsigned HOST_WIDE_INT n
;
5556 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5557 if (TREE_CODE (f
) == FIELD_DECL
)
5560 n
+= count_type_elements (TREE_TYPE (f
), false);
5561 else if (!flexible_array_member_p (f
, type
))
5562 /* Don't count flexible arrays, which are not supposed
5563 to be initialized. */
5571 case QUAL_UNION_TYPE
:
5576 gcc_assert (!for_ctor_p
);
5577 /* Estimate the number of scalars in each field and pick the
5578 maximum. Other estimates would do instead; the idea is simply
5579 to make sure that the estimate is not sensitive to the ordering
5582 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5583 if (TREE_CODE (f
) == FIELD_DECL
)
5585 m
= count_type_elements (TREE_TYPE (f
), false);
5586 /* If the field doesn't span the whole union, add an extra
5587 scalar for the rest. */
5588 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5589 TYPE_SIZE (type
)) != 1)
5601 return TYPE_VECTOR_SUBPARTS (type
);
5605 case FIXED_POINT_TYPE
:
5610 case REFERENCE_TYPE
:
5626 /* Helper for categorize_ctor_elements. Identical interface. */
5629 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5630 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5632 unsigned HOST_WIDE_INT idx
;
5633 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5634 tree value
, purpose
, elt_type
;
5636 /* Whether CTOR is a valid constant initializer, in accordance with what
5637 initializer_constant_valid_p does. If inferred from the constructor
5638 elements, true until proven otherwise. */
5639 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5640 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5645 elt_type
= NULL_TREE
;
5647 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5649 HOST_WIDE_INT mult
= 1;
5651 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5653 tree lo_index
= TREE_OPERAND (purpose
, 0);
5654 tree hi_index
= TREE_OPERAND (purpose
, 1);
5656 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5657 mult
= (tree_to_uhwi (hi_index
)
5658 - tree_to_uhwi (lo_index
) + 1);
5661 elt_type
= TREE_TYPE (value
);
5663 switch (TREE_CODE (value
))
5667 HOST_WIDE_INT nz
= 0, ic
= 0;
5669 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5672 nz_elts
+= mult
* nz
;
5673 init_elts
+= mult
* ic
;
5675 if (const_from_elts_p
&& const_p
)
5676 const_p
= const_elt_p
;
5683 if (!initializer_zerop (value
))
5689 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5690 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5694 if (!initializer_zerop (TREE_REALPART (value
)))
5696 if (!initializer_zerop (TREE_IMAGPART (value
)))
5704 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5706 tree v
= VECTOR_CST_ELT (value
, i
);
5707 if (!initializer_zerop (v
))
5716 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5717 nz_elts
+= mult
* tc
;
5718 init_elts
+= mult
* tc
;
5720 if (const_from_elts_p
&& const_p
)
5721 const_p
= initializer_constant_valid_p (value
, elt_type
)
5728 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5729 num_fields
, elt_type
))
5730 *p_complete
= false;
5732 *p_nz_elts
+= nz_elts
;
5733 *p_init_elts
+= init_elts
;
5738 /* Examine CTOR to discover:
5739 * how many scalar fields are set to nonzero values,
5740 and place it in *P_NZ_ELTS;
5741 * how many scalar fields in total are in CTOR,
5742 and place it in *P_ELT_COUNT.
5743 * whether the constructor is complete -- in the sense that every
5744 meaningful byte is explicitly given a value --
5745 and place it in *P_COMPLETE.
5747 Return whether or not CTOR is a valid static constant initializer, the same
5748 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5751 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5752 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5758 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5761 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5762 of which had type LAST_TYPE. Each element was itself a complete
5763 initializer, in the sense that every meaningful byte was explicitly
5764 given a value. Return true if the same is true for the constructor
5768 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5769 const_tree last_type
)
5771 if (TREE_CODE (type
) == UNION_TYPE
5772 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5777 gcc_assert (num_elts
== 1 && last_type
);
5779 /* ??? We could look at each element of the union, and find the
5780 largest element. Which would avoid comparing the size of the
5781 initialized element against any tail padding in the union.
5782 Doesn't seem worth the effort... */
5783 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5786 return count_type_elements (type
, true) == num_elts
;
5789 /* Return 1 if EXP contains mostly (3/4) zeros. */
5792 mostly_zeros_p (const_tree exp
)
5794 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5796 HOST_WIDE_INT nz_elts
, init_elts
;
5799 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5800 return !complete_p
|| nz_elts
< init_elts
/ 4;
5803 return initializer_zerop (exp
);
5806 /* Return 1 if EXP contains all zeros. */
5809 all_zeros_p (const_tree exp
)
5811 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5813 HOST_WIDE_INT nz_elts
, init_elts
;
5816 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5817 return nz_elts
== 0;
5820 return initializer_zerop (exp
);
5823 /* Helper function for store_constructor.
5824 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5825 CLEARED is as for store_constructor.
5826 ALIAS_SET is the alias set to use for any stores.
5828 This provides a recursive shortcut back to store_constructor when it isn't
5829 necessary to go through store_field. This is so that we can pass through
5830 the cleared field to let store_constructor know that we may not have to
5831 clear a substructure if the outer structure has already been cleared. */
5834 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5835 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5836 tree exp
, int cleared
, alias_set_type alias_set
)
5838 if (TREE_CODE (exp
) == CONSTRUCTOR
5839 /* We can only call store_constructor recursively if the size and
5840 bit position are on a byte boundary. */
5841 && bitpos
% BITS_PER_UNIT
== 0
5842 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5843 /* If we have a nonzero bitpos for a register target, then we just
5844 let store_field do the bitfield handling. This is unlikely to
5845 generate unnecessary clear instructions anyways. */
5846 && (bitpos
== 0 || MEM_P (target
)))
5850 = adjust_address (target
,
5851 GET_MODE (target
) == BLKmode
5853 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5854 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5857 /* Update the alias set, if required. */
5858 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5859 && MEM_ALIAS_SET (target
) != 0)
5861 target
= copy_rtx (target
);
5862 set_mem_alias_set (target
, alias_set
);
5865 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5868 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5872 /* Returns the number of FIELD_DECLs in TYPE. */
5875 fields_length (const_tree type
)
5877 tree t
= TYPE_FIELDS (type
);
5880 for (; t
; t
= DECL_CHAIN (t
))
5881 if (TREE_CODE (t
) == FIELD_DECL
)
5888 /* Store the value of constructor EXP into the rtx TARGET.
5889 TARGET is either a REG or a MEM; we know it cannot conflict, since
5890 safe_from_p has been called.
5891 CLEARED is true if TARGET is known to have been zero'd.
5892 SIZE is the number of bytes of TARGET we are allowed to modify: this
5893 may not be the same as the size of EXP if we are assigning to a field
5894 which has been packed to exclude padding bits. */
5897 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5899 tree type
= TREE_TYPE (exp
);
5900 #ifdef WORD_REGISTER_OPERATIONS
5901 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5904 switch (TREE_CODE (type
))
5908 case QUAL_UNION_TYPE
:
5910 unsigned HOST_WIDE_INT idx
;
5913 /* If size is zero or the target is already cleared, do nothing. */
5914 if (size
== 0 || cleared
)
5916 /* We either clear the aggregate or indicate the value is dead. */
5917 else if ((TREE_CODE (type
) == UNION_TYPE
5918 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5919 && ! CONSTRUCTOR_ELTS (exp
))
5920 /* If the constructor is empty, clear the union. */
5922 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5926 /* If we are building a static constructor into a register,
5927 set the initial value as zero so we can fold the value into
5928 a constant. But if more than one register is involved,
5929 this probably loses. */
5930 else if (REG_P (target
) && TREE_STATIC (exp
)
5931 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5933 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5937 /* If the constructor has fewer fields than the structure or
5938 if we are initializing the structure to mostly zeros, clear
5939 the whole structure first. Don't do this if TARGET is a
5940 register whose mode size isn't equal to SIZE since
5941 clear_storage can't handle this case. */
5943 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
5944 != fields_length (type
))
5945 || mostly_zeros_p (exp
))
5947 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5950 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5954 if (REG_P (target
) && !cleared
)
5955 emit_clobber (target
);
5957 /* Store each element of the constructor into the
5958 corresponding field of TARGET. */
5959 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5961 enum machine_mode mode
;
5962 HOST_WIDE_INT bitsize
;
5963 HOST_WIDE_INT bitpos
= 0;
5965 rtx to_rtx
= target
;
5967 /* Just ignore missing fields. We cleared the whole
5968 structure, above, if any fields are missing. */
5972 if (cleared
&& initializer_zerop (value
))
5975 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
5976 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
5980 mode
= DECL_MODE (field
);
5981 if (DECL_BIT_FIELD (field
))
5984 offset
= DECL_FIELD_OFFSET (field
);
5985 if (tree_fits_shwi_p (offset
)
5986 && tree_fits_shwi_p (bit_position (field
)))
5988 bitpos
= int_bit_position (field
);
5992 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
5996 enum machine_mode address_mode
;
6000 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
6001 make_tree (TREE_TYPE (exp
),
6004 offset_rtx
= expand_normal (offset
);
6005 gcc_assert (MEM_P (to_rtx
));
6007 address_mode
= get_address_mode (to_rtx
);
6008 if (GET_MODE (offset_rtx
) != address_mode
)
6009 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6011 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6012 highest_pow2_factor (offset
));
6015 #ifdef WORD_REGISTER_OPERATIONS
6016 /* If this initializes a field that is smaller than a
6017 word, at the start of a word, try to widen it to a full
6018 word. This special case allows us to output C++ member
6019 function initializations in a form that the optimizers
6022 && bitsize
< BITS_PER_WORD
6023 && bitpos
% BITS_PER_WORD
== 0
6024 && GET_MODE_CLASS (mode
) == MODE_INT
6025 && TREE_CODE (value
) == INTEGER_CST
6027 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6029 tree type
= TREE_TYPE (value
);
6031 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6033 type
= lang_hooks
.types
.type_for_mode
6034 (word_mode
, TYPE_UNSIGNED (type
));
6035 value
= fold_convert (type
, value
);
6038 if (BYTES_BIG_ENDIAN
)
6040 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6041 build_int_cst (type
,
6042 BITS_PER_WORD
- bitsize
));
6043 bitsize
= BITS_PER_WORD
;
6048 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6049 && DECL_NONADDRESSABLE_P (field
))
6051 to_rtx
= copy_rtx (to_rtx
);
6052 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6055 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6057 get_alias_set (TREE_TYPE (field
)));
6064 unsigned HOST_WIDE_INT i
;
6067 tree elttype
= TREE_TYPE (type
);
6069 HOST_WIDE_INT minelt
= 0;
6070 HOST_WIDE_INT maxelt
= 0;
6072 domain
= TYPE_DOMAIN (type
);
6073 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6074 && TYPE_MAX_VALUE (domain
)
6075 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6076 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6078 /* If we have constant bounds for the range of the type, get them. */
6081 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6082 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6085 /* If the constructor has fewer elements than the array, clear
6086 the whole array first. Similarly if this is static
6087 constructor of a non-BLKmode object. */
6090 else if (REG_P (target
) && TREE_STATIC (exp
))
6094 unsigned HOST_WIDE_INT idx
;
6096 HOST_WIDE_INT count
= 0, zero_count
= 0;
6097 need_to_clear
= ! const_bounds_p
;
6099 /* This loop is a more accurate version of the loop in
6100 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6101 is also needed to check for missing elements. */
6102 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6104 HOST_WIDE_INT this_node_count
;
6109 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6111 tree lo_index
= TREE_OPERAND (index
, 0);
6112 tree hi_index
= TREE_OPERAND (index
, 1);
6114 if (! tree_fits_uhwi_p (lo_index
)
6115 || ! tree_fits_uhwi_p (hi_index
))
6121 this_node_count
= (tree_to_uhwi (hi_index
)
6122 - tree_to_uhwi (lo_index
) + 1);
6125 this_node_count
= 1;
6127 count
+= this_node_count
;
6128 if (mostly_zeros_p (value
))
6129 zero_count
+= this_node_count
;
6132 /* Clear the entire array first if there are any missing
6133 elements, or if the incidence of zero elements is >=
6136 && (count
< maxelt
- minelt
+ 1
6137 || 4 * zero_count
>= 3 * count
))
6141 if (need_to_clear
&& size
> 0)
6144 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6146 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6150 if (!cleared
&& REG_P (target
))
6151 /* Inform later passes that the old value is dead. */
6152 emit_clobber (target
);
6154 /* Store each element of the constructor into the
6155 corresponding element of TARGET, determined by counting the
6157 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6159 enum machine_mode mode
;
6160 HOST_WIDE_INT bitsize
;
6161 HOST_WIDE_INT bitpos
;
6162 rtx xtarget
= target
;
6164 if (cleared
&& initializer_zerop (value
))
6167 mode
= TYPE_MODE (elttype
);
6168 if (mode
== BLKmode
)
6169 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6170 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6173 bitsize
= GET_MODE_BITSIZE (mode
);
6175 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6177 tree lo_index
= TREE_OPERAND (index
, 0);
6178 tree hi_index
= TREE_OPERAND (index
, 1);
6179 rtx index_r
, pos_rtx
;
6180 HOST_WIDE_INT lo
, hi
, count
;
6183 /* If the range is constant and "small", unroll the loop. */
6185 && tree_fits_shwi_p (lo_index
)
6186 && tree_fits_shwi_p (hi_index
)
6187 && (lo
= tree_to_shwi (lo_index
),
6188 hi
= tree_to_shwi (hi_index
),
6189 count
= hi
- lo
+ 1,
6192 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6193 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6196 lo
-= minelt
; hi
-= minelt
;
6197 for (; lo
<= hi
; lo
++)
6199 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6202 && !MEM_KEEP_ALIAS_SET_P (target
)
6203 && TREE_CODE (type
) == ARRAY_TYPE
6204 && TYPE_NONALIASED_COMPONENT (type
))
6206 target
= copy_rtx (target
);
6207 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6210 store_constructor_field
6211 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6212 get_alias_set (elttype
));
6217 rtx_code_label
*loop_start
= gen_label_rtx ();
6218 rtx_code_label
*loop_end
= gen_label_rtx ();
6221 expand_normal (hi_index
);
6223 index
= build_decl (EXPR_LOCATION (exp
),
6224 VAR_DECL
, NULL_TREE
, domain
);
6225 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6226 SET_DECL_RTL (index
, index_r
);
6227 store_expr (lo_index
, index_r
, 0, false);
6229 /* Build the head of the loop. */
6230 do_pending_stack_adjust ();
6231 emit_label (loop_start
);
6233 /* Assign value to element index. */
6235 fold_convert (ssizetype
,
6236 fold_build2 (MINUS_EXPR
,
6239 TYPE_MIN_VALUE (domain
)));
6242 size_binop (MULT_EXPR
, position
,
6243 fold_convert (ssizetype
,
6244 TYPE_SIZE_UNIT (elttype
)));
6246 pos_rtx
= expand_normal (position
);
6247 xtarget
= offset_address (target
, pos_rtx
,
6248 highest_pow2_factor (position
));
6249 xtarget
= adjust_address (xtarget
, mode
, 0);
6250 if (TREE_CODE (value
) == CONSTRUCTOR
)
6251 store_constructor (value
, xtarget
, cleared
,
6252 bitsize
/ BITS_PER_UNIT
);
6254 store_expr (value
, xtarget
, 0, false);
6256 /* Generate a conditional jump to exit the loop. */
6257 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6259 jumpif (exit_cond
, loop_end
, -1);
6261 /* Update the loop counter, and jump to the head of
6263 expand_assignment (index
,
6264 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6265 index
, integer_one_node
),
6268 emit_jump (loop_start
);
6270 /* Build the end of the loop. */
6271 emit_label (loop_end
);
6274 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6275 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6280 index
= ssize_int (1);
6283 index
= fold_convert (ssizetype
,
6284 fold_build2 (MINUS_EXPR
,
6287 TYPE_MIN_VALUE (domain
)));
6290 size_binop (MULT_EXPR
, index
,
6291 fold_convert (ssizetype
,
6292 TYPE_SIZE_UNIT (elttype
)));
6293 xtarget
= offset_address (target
,
6294 expand_normal (position
),
6295 highest_pow2_factor (position
));
6296 xtarget
= adjust_address (xtarget
, mode
, 0);
6297 store_expr (value
, xtarget
, 0, false);
6302 bitpos
= ((tree_to_shwi (index
) - minelt
)
6303 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6305 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6307 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6308 && TREE_CODE (type
) == ARRAY_TYPE
6309 && TYPE_NONALIASED_COMPONENT (type
))
6311 target
= copy_rtx (target
);
6312 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6314 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6315 cleared
, get_alias_set (elttype
));
6323 unsigned HOST_WIDE_INT idx
;
6324 constructor_elt
*ce
;
6327 int icode
= CODE_FOR_nothing
;
6328 tree elttype
= TREE_TYPE (type
);
6329 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6330 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6331 HOST_WIDE_INT bitsize
;
6332 HOST_WIDE_INT bitpos
;
6333 rtvec vector
= NULL
;
6335 alias_set_type alias
;
6337 gcc_assert (eltmode
!= BLKmode
);
6339 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6340 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6342 enum machine_mode mode
= GET_MODE (target
);
6344 icode
= (int) optab_handler (vec_init_optab
, mode
);
6345 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6346 if (icode
!= CODE_FOR_nothing
)
6350 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6351 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6353 icode
= CODE_FOR_nothing
;
6357 if (icode
!= CODE_FOR_nothing
)
6361 vector
= rtvec_alloc (n_elts
);
6362 for (i
= 0; i
< n_elts
; i
++)
6363 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6367 /* If the constructor has fewer elements than the vector,
6368 clear the whole array first. Similarly if this is static
6369 constructor of a non-BLKmode object. */
6372 else if (REG_P (target
) && TREE_STATIC (exp
))
6376 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6379 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6381 int n_elts_here
= tree_to_uhwi
6382 (int_const_binop (TRUNC_DIV_EXPR
,
6383 TYPE_SIZE (TREE_TYPE (value
)),
6384 TYPE_SIZE (elttype
)));
6386 count
+= n_elts_here
;
6387 if (mostly_zeros_p (value
))
6388 zero_count
+= n_elts_here
;
6391 /* Clear the entire vector first if there are any missing elements,
6392 or if the incidence of zero elements is >= 75%. */
6393 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6396 if (need_to_clear
&& size
> 0 && !vector
)
6399 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6401 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6405 /* Inform later passes that the old value is dead. */
6406 if (!cleared
&& !vector
&& REG_P (target
))
6407 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6410 alias
= MEM_ALIAS_SET (target
);
6412 alias
= get_alias_set (elttype
);
6414 /* Store each element of the constructor into the corresponding
6415 element of TARGET, determined by counting the elements. */
6416 for (idx
= 0, i
= 0;
6417 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6418 idx
++, i
+= bitsize
/ elt_size
)
6420 HOST_WIDE_INT eltpos
;
6421 tree value
= ce
->value
;
6423 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6424 if (cleared
&& initializer_zerop (value
))
6428 eltpos
= tree_to_uhwi (ce
->index
);
6434 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6436 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6437 RTVEC_ELT (vector
, eltpos
)
6438 = expand_normal (value
);
6442 enum machine_mode value_mode
=
6443 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6444 ? TYPE_MODE (TREE_TYPE (value
))
6446 bitpos
= eltpos
* elt_size
;
6447 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6448 value
, cleared
, alias
);
6453 emit_insn (GEN_FCN (icode
)
6455 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6464 /* Store the value of EXP (an expression tree)
6465 into a subfield of TARGET which has mode MODE and occupies
6466 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6467 If MODE is VOIDmode, it means that we are storing into a bit-field.
6469 BITREGION_START is bitpos of the first bitfield in this region.
6470 BITREGION_END is the bitpos of the ending bitfield in this region.
6471 These two fields are 0, if the C++ memory model does not apply,
6472 or we are not interested in keeping track of bitfield regions.
6474 Always return const0_rtx unless we have something particular to
6477 ALIAS_SET is the alias set for the destination. This value will
6478 (in general) be different from that for TARGET, since TARGET is a
6479 reference to the containing structure.
6481 If NONTEMPORAL is true, try generating a nontemporal store. */
6484 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6485 unsigned HOST_WIDE_INT bitregion_start
,
6486 unsigned HOST_WIDE_INT bitregion_end
,
6487 enum machine_mode mode
, tree exp
,
6488 alias_set_type alias_set
, bool nontemporal
)
6490 if (TREE_CODE (exp
) == ERROR_MARK
)
6493 /* If we have nothing to store, do nothing unless the expression has
6496 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6498 if (GET_CODE (target
) == CONCAT
)
6500 /* We're storing into a struct containing a single __complex. */
6502 gcc_assert (!bitpos
);
6503 return store_expr (exp
, target
, 0, nontemporal
);
6506 /* If the structure is in a register or if the component
6507 is a bit field, we cannot use addressing to access it.
6508 Use bit-field techniques or SUBREG to store in it. */
6510 if (mode
== VOIDmode
6511 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6512 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6513 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6515 || GET_CODE (target
) == SUBREG
6516 /* If the field isn't aligned enough to store as an ordinary memref,
6517 store it as a bit field. */
6519 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6520 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6521 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6522 || (bitpos
% BITS_PER_UNIT
!= 0)))
6523 || (bitsize
>= 0 && mode
!= BLKmode
6524 && GET_MODE_BITSIZE (mode
) > bitsize
)
6525 /* If the RHS and field are a constant size and the size of the
6526 RHS isn't the same size as the bitfield, we must use bitfield
6529 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6530 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6531 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6532 decl we must use bitfield operations. */
6534 && TREE_CODE (exp
) == MEM_REF
6535 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6536 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6537 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6538 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6543 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6544 implies a mask operation. If the precision is the same size as
6545 the field we're storing into, that mask is redundant. This is
6546 particularly common with bit field assignments generated by the
6548 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6551 tree type
= TREE_TYPE (exp
);
6552 if (INTEGRAL_TYPE_P (type
)
6553 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6554 && bitsize
== TYPE_PRECISION (type
))
6556 tree op
= gimple_assign_rhs1 (nop_def
);
6557 type
= TREE_TYPE (op
);
6558 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6563 temp
= expand_normal (exp
);
6565 /* If BITSIZE is narrower than the size of the type of EXP
6566 we will be narrowing TEMP. Normally, what's wanted are the
6567 low-order bits. However, if EXP's type is a record and this is
6568 big-endian machine, we want the upper BITSIZE bits. */
6569 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6570 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6571 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6572 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6573 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6576 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6577 if (mode
!= VOIDmode
&& mode
!= BLKmode
6578 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6579 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6581 /* If the modes of TEMP and TARGET are both BLKmode, both
6582 must be in memory and BITPOS must be aligned on a byte
6583 boundary. If so, we simply do a block copy. Likewise
6584 for a BLKmode-like TARGET. */
6585 if (GET_MODE (temp
) == BLKmode
6586 && (GET_MODE (target
) == BLKmode
6588 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6589 && (bitpos
% BITS_PER_UNIT
) == 0
6590 && (bitsize
% BITS_PER_UNIT
) == 0)))
6592 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6593 && (bitpos
% BITS_PER_UNIT
) == 0);
6595 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6596 emit_block_move (target
, temp
,
6597 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6604 /* Handle calls that return values in multiple non-contiguous locations.
6605 The Irix 6 ABI has examples of this. */
6606 if (GET_CODE (temp
) == PARALLEL
)
6608 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6610 if (mode
== BLKmode
|| mode
== VOIDmode
)
6611 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6612 temp_target
= gen_reg_rtx (mode
);
6613 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6616 else if (mode
== BLKmode
)
6618 /* Handle calls that return BLKmode values in registers. */
6619 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6621 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6622 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6627 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6629 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6630 temp_target
= gen_reg_rtx (mode
);
6632 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6633 temp_target
, mode
, mode
);
6638 /* Store the value in the bitfield. */
6639 store_bit_field (target
, bitsize
, bitpos
,
6640 bitregion_start
, bitregion_end
,
6647 /* Now build a reference to just the desired component. */
6648 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6650 if (to_rtx
== target
)
6651 to_rtx
= copy_rtx (to_rtx
);
6653 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6654 set_mem_alias_set (to_rtx
, alias_set
);
6656 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6660 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6661 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6662 codes and find the ultimate containing object, which we return.
6664 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6665 bit position, and *PUNSIGNEDP to the signedness of the field.
6666 If the position of the field is variable, we store a tree
6667 giving the variable offset (in units) in *POFFSET.
6668 This offset is in addition to the bit position.
6669 If the position is not variable, we store 0 in *POFFSET.
6671 If any of the extraction expressions is volatile,
6672 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6674 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6675 Otherwise, it is a mode that can be used to access the field.
6677 If the field describes a variable-sized object, *PMODE is set to
6678 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6679 this case, but the address of the object can be found.
6681 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6682 look through nodes that serve as markers of a greater alignment than
6683 the one that can be deduced from the expression. These nodes make it
6684 possible for front-ends to prevent temporaries from being created by
6685 the middle-end on alignment considerations. For that purpose, the
6686 normal operating mode at high-level is to always pass FALSE so that
6687 the ultimate containing object is really returned; moreover, the
6688 associated predicate handled_component_p will always return TRUE
6689 on these nodes, thus indicating that they are essentially handled
6690 by get_inner_reference. TRUE should only be passed when the caller
6691 is scanning the expression in order to build another representation
6692 and specifically knows how to handle these nodes; as such, this is
6693 the normal operating mode in the RTL expanders. */
6696 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6697 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6698 enum machine_mode
*pmode
, int *punsignedp
,
6699 int *pvolatilep
, bool keep_aligning
)
6702 enum machine_mode mode
= VOIDmode
;
6703 bool blkmode_bitfield
= false;
6704 tree offset
= size_zero_node
;
6705 offset_int bit_offset
= 0;
6707 /* First get the mode, signedness, and size. We do this from just the
6708 outermost expression. */
6710 if (TREE_CODE (exp
) == COMPONENT_REF
)
6712 tree field
= TREE_OPERAND (exp
, 1);
6713 size_tree
= DECL_SIZE (field
);
6714 if (flag_strict_volatile_bitfields
> 0
6715 && TREE_THIS_VOLATILE (exp
)
6716 && DECL_BIT_FIELD_TYPE (field
)
6717 && DECL_MODE (field
) != BLKmode
)
6718 /* Volatile bitfields should be accessed in the mode of the
6719 field's type, not the mode computed based on the bit
6721 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6722 else if (!DECL_BIT_FIELD (field
))
6723 mode
= DECL_MODE (field
);
6724 else if (DECL_MODE (field
) == BLKmode
)
6725 blkmode_bitfield
= true;
6727 *punsignedp
= DECL_UNSIGNED (field
);
6729 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6731 size_tree
= TREE_OPERAND (exp
, 1);
6732 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6733 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6735 /* For vector types, with the correct size of access, use the mode of
6737 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6738 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6739 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6740 mode
= TYPE_MODE (TREE_TYPE (exp
));
6744 mode
= TYPE_MODE (TREE_TYPE (exp
));
6745 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6747 if (mode
== BLKmode
)
6748 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6750 *pbitsize
= GET_MODE_BITSIZE (mode
);
6755 if (! tree_fits_uhwi_p (size_tree
))
6756 mode
= BLKmode
, *pbitsize
= -1;
6758 *pbitsize
= tree_to_uhwi (size_tree
);
6761 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6762 and find the ultimate containing object. */
6765 switch (TREE_CODE (exp
))
6768 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
6773 tree field
= TREE_OPERAND (exp
, 1);
6774 tree this_offset
= component_ref_field_offset (exp
);
6776 /* If this field hasn't been filled in yet, don't go past it.
6777 This should only happen when folding expressions made during
6778 type construction. */
6779 if (this_offset
== 0)
6782 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6783 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
6785 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6790 case ARRAY_RANGE_REF
:
6792 tree index
= TREE_OPERAND (exp
, 1);
6793 tree low_bound
= array_ref_low_bound (exp
);
6794 tree unit_size
= array_ref_element_size (exp
);
6796 /* We assume all arrays have sizes that are a multiple of a byte.
6797 First subtract the lower bound, if any, in the type of the
6798 index, then convert to sizetype and multiply by the size of
6799 the array element. */
6800 if (! integer_zerop (low_bound
))
6801 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6804 offset
= size_binop (PLUS_EXPR
, offset
,
6805 size_binop (MULT_EXPR
,
6806 fold_convert (sizetype
, index
),
6815 bit_offset
+= *pbitsize
;
6818 case VIEW_CONVERT_EXPR
:
6819 if (keep_aligning
&& STRICT_ALIGNMENT
6820 && (TYPE_ALIGN (TREE_TYPE (exp
))
6821 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6822 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6823 < BIGGEST_ALIGNMENT
)
6824 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6825 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6830 /* Hand back the decl for MEM[&decl, off]. */
6831 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6833 tree off
= TREE_OPERAND (exp
, 1);
6834 if (!integer_zerop (off
))
6836 offset_int boff
, coff
= mem_ref_offset (exp
);
6837 boff
= wi::lshift (coff
, LOG2_BITS_PER_UNIT
);
6840 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6848 /* If any reference in the chain is volatile, the effect is volatile. */
6849 if (TREE_THIS_VOLATILE (exp
))
6852 exp
= TREE_OPERAND (exp
, 0);
6856 /* If OFFSET is constant, see if we can return the whole thing as a
6857 constant bit position. Make sure to handle overflow during
6859 if (TREE_CODE (offset
) == INTEGER_CST
)
6861 offset_int tem
= wi::sext (wi::to_offset (offset
),
6862 TYPE_PRECISION (sizetype
));
6863 tem
= wi::lshift (tem
, LOG2_BITS_PER_UNIT
);
6865 if (wi::fits_shwi_p (tem
))
6867 *pbitpos
= tem
.to_shwi ();
6868 *poffset
= offset
= NULL_TREE
;
6872 /* Otherwise, split it up. */
6875 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6876 if (wi::neg_p (bit_offset
))
6878 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
6879 offset_int tem
= bit_offset
.and_not (mask
);
6880 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6881 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6883 tem
= wi::arshift (tem
, LOG2_BITS_PER_UNIT
);
6884 offset
= size_binop (PLUS_EXPR
, offset
,
6885 wide_int_to_tree (sizetype
, tem
));
6888 *pbitpos
= bit_offset
.to_shwi ();
6892 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6893 if (mode
== VOIDmode
6895 && (*pbitpos
% BITS_PER_UNIT
) == 0
6896 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6904 /* Return a tree of sizetype representing the size, in bytes, of the element
6905 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6908 array_ref_element_size (tree exp
)
6910 tree aligned_size
= TREE_OPERAND (exp
, 3);
6911 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6912 location_t loc
= EXPR_LOCATION (exp
);
6914 /* If a size was specified in the ARRAY_REF, it's the size measured
6915 in alignment units of the element type. So multiply by that value. */
6918 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6919 sizetype from another type of the same width and signedness. */
6920 if (TREE_TYPE (aligned_size
) != sizetype
)
6921 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6922 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6923 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6926 /* Otherwise, take the size from that of the element type. Substitute
6927 any PLACEHOLDER_EXPR that we have. */
6929 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6932 /* Return a tree representing the lower bound of the array mentioned in
6933 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6936 array_ref_low_bound (tree exp
)
6938 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6940 /* If a lower bound is specified in EXP, use it. */
6941 if (TREE_OPERAND (exp
, 2))
6942 return TREE_OPERAND (exp
, 2);
6944 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6945 substituting for a PLACEHOLDER_EXPR as needed. */
6946 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6947 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6949 /* Otherwise, return a zero of the appropriate type. */
6950 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6953 /* Returns true if REF is an array reference to an array at the end of
6954 a structure. If this is the case, the array may be allocated larger
6955 than its upper bound implies. */
6958 array_at_struct_end_p (tree ref
)
6960 if (TREE_CODE (ref
) != ARRAY_REF
6961 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6964 while (handled_component_p (ref
))
6966 /* If the reference chain contains a component reference to a
6967 non-union type and there follows another field the reference
6968 is not at the end of a structure. */
6969 if (TREE_CODE (ref
) == COMPONENT_REF
6970 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6972 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6973 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6974 nextf
= DECL_CHAIN (nextf
);
6979 ref
= TREE_OPERAND (ref
, 0);
6982 /* If the reference is based on a declared entity, the size of the array
6983 is constrained by its given domain. */
6990 /* Return a tree representing the upper bound of the array mentioned in
6991 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6994 array_ref_up_bound (tree exp
)
6996 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6998 /* If there is a domain type and it has an upper bound, use it, substituting
6999 for a PLACEHOLDER_EXPR as needed. */
7000 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
7001 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
7003 /* Otherwise fail. */
7007 /* Return a tree representing the offset, in bytes, of the field referenced
7008 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
7011 component_ref_field_offset (tree exp
)
7013 tree aligned_offset
= TREE_OPERAND (exp
, 2);
7014 tree field
= TREE_OPERAND (exp
, 1);
7015 location_t loc
= EXPR_LOCATION (exp
);
7017 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
7018 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
7022 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
7023 sizetype from another type of the same width and signedness. */
7024 if (TREE_TYPE (aligned_offset
) != sizetype
)
7025 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
7026 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
7027 size_int (DECL_OFFSET_ALIGN (field
)
7031 /* Otherwise, take the offset from that of the field. Substitute
7032 any PLACEHOLDER_EXPR that we have. */
7034 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
7037 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7039 static unsigned HOST_WIDE_INT
7040 target_align (const_tree target
)
7042 /* We might have a chain of nested references with intermediate misaligning
7043 bitfields components, so need to recurse to find out. */
7045 unsigned HOST_WIDE_INT this_align
, outer_align
;
7047 switch (TREE_CODE (target
))
7053 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7054 outer_align
= target_align (TREE_OPERAND (target
, 0));
7055 return MIN (this_align
, outer_align
);
7058 case ARRAY_RANGE_REF
:
7059 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7060 outer_align
= target_align (TREE_OPERAND (target
, 0));
7061 return MIN (this_align
, outer_align
);
7064 case NON_LVALUE_EXPR
:
7065 case VIEW_CONVERT_EXPR
:
7066 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7067 outer_align
= target_align (TREE_OPERAND (target
, 0));
7068 return MAX (this_align
, outer_align
);
7071 return TYPE_ALIGN (TREE_TYPE (target
));
7076 /* Given an rtx VALUE that may contain additions and multiplications, return
7077 an equivalent value that just refers to a register, memory, or constant.
7078 This is done by generating instructions to perform the arithmetic and
7079 returning a pseudo-register containing the value.
7081 The returned value may be a REG, SUBREG, MEM or constant. */
7084 force_operand (rtx value
, rtx target
)
7087 /* Use subtarget as the target for operand 0 of a binary operation. */
7088 rtx subtarget
= get_subtarget (target
);
7089 enum rtx_code code
= GET_CODE (value
);
7091 /* Check for subreg applied to an expression produced by loop optimizer. */
7093 && !REG_P (SUBREG_REG (value
))
7094 && !MEM_P (SUBREG_REG (value
)))
7097 = simplify_gen_subreg (GET_MODE (value
),
7098 force_reg (GET_MODE (SUBREG_REG (value
)),
7099 force_operand (SUBREG_REG (value
),
7101 GET_MODE (SUBREG_REG (value
)),
7102 SUBREG_BYTE (value
));
7103 code
= GET_CODE (value
);
7106 /* Check for a PIC address load. */
7107 if ((code
== PLUS
|| code
== MINUS
)
7108 && XEXP (value
, 0) == pic_offset_table_rtx
7109 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7110 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7111 || GET_CODE (XEXP (value
, 1)) == CONST
))
7114 subtarget
= gen_reg_rtx (GET_MODE (value
));
7115 emit_move_insn (subtarget
, value
);
7119 if (ARITHMETIC_P (value
))
7121 op2
= XEXP (value
, 1);
7122 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7124 if (code
== MINUS
&& CONST_INT_P (op2
))
7127 op2
= negate_rtx (GET_MODE (value
), op2
);
7130 /* Check for an addition with OP2 a constant integer and our first
7131 operand a PLUS of a virtual register and something else. In that
7132 case, we want to emit the sum of the virtual register and the
7133 constant first and then add the other value. This allows virtual
7134 register instantiation to simply modify the constant rather than
7135 creating another one around this addition. */
7136 if (code
== PLUS
&& CONST_INT_P (op2
)
7137 && GET_CODE (XEXP (value
, 0)) == PLUS
7138 && REG_P (XEXP (XEXP (value
, 0), 0))
7139 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7140 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7142 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7143 XEXP (XEXP (value
, 0), 0), op2
,
7144 subtarget
, 0, OPTAB_LIB_WIDEN
);
7145 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7146 force_operand (XEXP (XEXP (value
,
7148 target
, 0, OPTAB_LIB_WIDEN
);
7151 op1
= force_operand (XEXP (value
, 0), subtarget
);
7152 op2
= force_operand (op2
, NULL_RTX
);
7156 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7158 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7159 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7160 target
, 1, OPTAB_LIB_WIDEN
);
7162 return expand_divmod (0,
7163 FLOAT_MODE_P (GET_MODE (value
))
7164 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7165 GET_MODE (value
), op1
, op2
, target
, 0);
7167 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7170 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7173 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7176 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7177 target
, 0, OPTAB_LIB_WIDEN
);
7179 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7180 target
, 1, OPTAB_LIB_WIDEN
);
7183 if (UNARY_P (value
))
7186 target
= gen_reg_rtx (GET_MODE (value
));
7187 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7194 case FLOAT_TRUNCATE
:
7195 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7200 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7204 case UNSIGNED_FLOAT
:
7205 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7209 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7213 #ifdef INSN_SCHEDULING
7214 /* On machines that have insn scheduling, we want all memory reference to be
7215 explicit, so we need to deal with such paradoxical SUBREGs. */
7216 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7218 = simplify_gen_subreg (GET_MODE (value
),
7219 force_reg (GET_MODE (SUBREG_REG (value
)),
7220 force_operand (SUBREG_REG (value
),
7222 GET_MODE (SUBREG_REG (value
)),
7223 SUBREG_BYTE (value
));
7229 /* Subroutine of expand_expr: return nonzero iff there is no way that
7230 EXP can reference X, which is being modified. TOP_P is nonzero if this
7231 call is going to be used to determine whether we need a temporary
7232 for EXP, as opposed to a recursive call to this function.
7234 It is always safe for this routine to return zero since it merely
7235 searches for optimization opportunities. */
7238 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7244 /* If EXP has varying size, we MUST use a target since we currently
7245 have no way of allocating temporaries of variable size
7246 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7247 So we assume here that something at a higher level has prevented a
7248 clash. This is somewhat bogus, but the best we can do. Only
7249 do this when X is BLKmode and when we are at the top level. */
7250 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7251 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7252 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7253 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7254 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7256 && GET_MODE (x
) == BLKmode
)
7257 /* If X is in the outgoing argument area, it is always safe. */
7259 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7260 || (GET_CODE (XEXP (x
, 0)) == PLUS
7261 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7264 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7265 find the underlying pseudo. */
7266 if (GET_CODE (x
) == SUBREG
)
7269 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7273 /* Now look at our tree code and possibly recurse. */
7274 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7276 case tcc_declaration
:
7277 exp_rtl
= DECL_RTL_IF_SET (exp
);
7283 case tcc_exceptional
:
7284 if (TREE_CODE (exp
) == TREE_LIST
)
7288 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7290 exp
= TREE_CHAIN (exp
);
7293 if (TREE_CODE (exp
) != TREE_LIST
)
7294 return safe_from_p (x
, exp
, 0);
7297 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7299 constructor_elt
*ce
;
7300 unsigned HOST_WIDE_INT idx
;
7302 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7303 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7304 || !safe_from_p (x
, ce
->value
, 0))
7308 else if (TREE_CODE (exp
) == ERROR_MARK
)
7309 return 1; /* An already-visited SAVE_EXPR? */
7314 /* The only case we look at here is the DECL_INITIAL inside a
7316 return (TREE_CODE (exp
) != DECL_EXPR
7317 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7318 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7319 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7322 case tcc_comparison
:
7323 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7328 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7330 case tcc_expression
:
7333 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7334 the expression. If it is set, we conflict iff we are that rtx or
7335 both are in memory. Otherwise, we check all operands of the
7336 expression recursively. */
7338 switch (TREE_CODE (exp
))
7341 /* If the operand is static or we are static, we can't conflict.
7342 Likewise if we don't conflict with the operand at all. */
7343 if (staticp (TREE_OPERAND (exp
, 0))
7344 || TREE_STATIC (exp
)
7345 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7348 /* Otherwise, the only way this can conflict is if we are taking
7349 the address of a DECL a that address if part of X, which is
7351 exp
= TREE_OPERAND (exp
, 0);
7354 if (!DECL_RTL_SET_P (exp
)
7355 || !MEM_P (DECL_RTL (exp
)))
7358 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7364 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7365 get_alias_set (exp
)))
7370 /* Assume that the call will clobber all hard registers and
7372 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7377 case WITH_CLEANUP_EXPR
:
7378 case CLEANUP_POINT_EXPR
:
7379 /* Lowered by gimplify.c. */
7383 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7389 /* If we have an rtx, we do not need to scan our operands. */
7393 nops
= TREE_OPERAND_LENGTH (exp
);
7394 for (i
= 0; i
< nops
; i
++)
7395 if (TREE_OPERAND (exp
, i
) != 0
7396 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7402 /* Should never get a type here. */
7406 /* If we have an rtl, find any enclosed object. Then see if we conflict
7410 if (GET_CODE (exp_rtl
) == SUBREG
)
7412 exp_rtl
= SUBREG_REG (exp_rtl
);
7414 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7418 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7419 are memory and they conflict. */
7420 return ! (rtx_equal_p (x
, exp_rtl
)
7421 || (MEM_P (x
) && MEM_P (exp_rtl
)
7422 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7425 /* If we reach here, it is safe. */
7430 /* Return the highest power of two that EXP is known to be a multiple of.
7431 This is used in updating alignment of MEMs in array references. */
7433 unsigned HOST_WIDE_INT
7434 highest_pow2_factor (const_tree exp
)
7436 unsigned HOST_WIDE_INT ret
;
7437 int trailing_zeros
= tree_ctz (exp
);
7438 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7439 return BIGGEST_ALIGNMENT
;
7440 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7441 if (ret
> BIGGEST_ALIGNMENT
)
7442 return BIGGEST_ALIGNMENT
;
7446 /* Similar, except that the alignment requirements of TARGET are
7447 taken into account. Assume it is at least as aligned as its
7448 type, unless it is a COMPONENT_REF in which case the layout of
7449 the structure gives the alignment. */
7451 static unsigned HOST_WIDE_INT
7452 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7454 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7455 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7457 return MAX (factor
, talign
);
7460 #ifdef HAVE_conditional_move
7461 /* Convert the tree comparison code TCODE to the rtl one where the
7462 signedness is UNSIGNEDP. */
7464 static enum rtx_code
7465 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7477 code
= unsignedp
? LTU
: LT
;
7480 code
= unsignedp
? LEU
: LE
;
7483 code
= unsignedp
? GTU
: GT
;
7486 code
= unsignedp
? GEU
: GE
;
7488 case UNORDERED_EXPR
:
7520 /* Subroutine of expand_expr. Expand the two operands of a binary
7521 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7522 The value may be stored in TARGET if TARGET is nonzero. The
7523 MODIFIER argument is as documented by expand_expr. */
7526 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7527 enum expand_modifier modifier
)
7529 if (! safe_from_p (target
, exp1
, 1))
7531 if (operand_equal_p (exp0
, exp1
, 0))
7533 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7534 *op1
= copy_rtx (*op0
);
7538 /* If we need to preserve evaluation order, copy exp0 into its own
7539 temporary variable so that it can't be clobbered by exp1. */
7540 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7541 exp0
= save_expr (exp0
);
7542 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7543 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7548 /* Return a MEM that contains constant EXP. DEFER is as for
7549 output_constant_def and MODIFIER is as for expand_expr. */
7552 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7556 mem
= output_constant_def (exp
, defer
);
7557 if (modifier
!= EXPAND_INITIALIZER
)
7558 mem
= use_anchored_address (mem
);
7562 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7563 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7566 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7567 enum expand_modifier modifier
, addr_space_t as
)
7569 rtx result
, subtarget
;
7571 HOST_WIDE_INT bitsize
, bitpos
;
7572 int volatilep
, unsignedp
;
7573 enum machine_mode mode1
;
7575 /* If we are taking the address of a constant and are at the top level,
7576 we have to use output_constant_def since we can't call force_const_mem
7578 /* ??? This should be considered a front-end bug. We should not be
7579 generating ADDR_EXPR of something that isn't an LVALUE. The only
7580 exception here is STRING_CST. */
7581 if (CONSTANT_CLASS_P (exp
))
7583 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7584 if (modifier
< EXPAND_SUM
)
7585 result
= force_operand (result
, target
);
7589 /* Everything must be something allowed by is_gimple_addressable. */
7590 switch (TREE_CODE (exp
))
7593 /* This case will happen via recursion for &a->b. */
7594 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7598 tree tem
= TREE_OPERAND (exp
, 0);
7599 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7600 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7601 return expand_expr (tem
, target
, tmode
, modifier
);
7605 /* Expand the initializer like constants above. */
7606 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7608 if (modifier
< EXPAND_SUM
)
7609 result
= force_operand (result
, target
);
7613 /* The real part of the complex number is always first, therefore
7614 the address is the same as the address of the parent object. */
7617 inner
= TREE_OPERAND (exp
, 0);
7621 /* The imaginary part of the complex number is always second.
7622 The expression is therefore always offset by the size of the
7625 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7626 inner
= TREE_OPERAND (exp
, 0);
7629 case COMPOUND_LITERAL_EXPR
:
7630 /* Allow COMPOUND_LITERAL_EXPR in initializers, if e.g.
7631 rtl_for_decl_init is called on DECL_INITIAL with
7632 COMPOUNT_LITERAL_EXPRs in it, they aren't gimplified. */
7633 if (modifier
== EXPAND_INITIALIZER
7634 && COMPOUND_LITERAL_EXPR_DECL (exp
))
7635 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7636 target
, tmode
, modifier
, as
);
7639 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7640 expand_expr, as that can have various side effects; LABEL_DECLs for
7641 example, may not have their DECL_RTL set yet. Expand the rtl of
7642 CONSTRUCTORs too, which should yield a memory reference for the
7643 constructor's contents. Assume language specific tree nodes can
7644 be expanded in some interesting way. */
7645 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7647 || TREE_CODE (exp
) == CONSTRUCTOR
7648 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7650 result
= expand_expr (exp
, target
, tmode
,
7651 modifier
== EXPAND_INITIALIZER
7652 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7654 /* If the DECL isn't in memory, then the DECL wasn't properly
7655 marked TREE_ADDRESSABLE, which will be either a front-end
7656 or a tree optimizer bug. */
7658 if (TREE_ADDRESSABLE (exp
)
7660 && ! targetm
.calls
.allocate_stack_slots_for_args ())
7662 error ("local frame unavailable (naked function?)");
7666 gcc_assert (MEM_P (result
));
7667 result
= XEXP (result
, 0);
7669 /* ??? Is this needed anymore? */
7671 TREE_USED (exp
) = 1;
7673 if (modifier
!= EXPAND_INITIALIZER
7674 && modifier
!= EXPAND_CONST_ADDRESS
7675 && modifier
!= EXPAND_SUM
)
7676 result
= force_operand (result
, target
);
7680 /* Pass FALSE as the last argument to get_inner_reference although
7681 we are expanding to RTL. The rationale is that we know how to
7682 handle "aligning nodes" here: we can just bypass them because
7683 they won't change the final object whose address will be returned
7684 (they actually exist only for that purpose). */
7685 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7686 &mode1
, &unsignedp
, &volatilep
, false);
7690 /* We must have made progress. */
7691 gcc_assert (inner
!= exp
);
7693 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7694 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7695 inner alignment, force the inner to be sufficiently aligned. */
7696 if (CONSTANT_CLASS_P (inner
)
7697 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7699 inner
= copy_node (inner
);
7700 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7701 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7702 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7704 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7710 if (modifier
!= EXPAND_NORMAL
)
7711 result
= force_operand (result
, NULL
);
7712 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7713 modifier
== EXPAND_INITIALIZER
7714 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7716 /* expand_expr is allowed to return an object in a mode other
7717 than TMODE. If it did, we need to convert. */
7718 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7719 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7720 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7721 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7722 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7724 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7725 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7728 subtarget
= bitpos
? NULL_RTX
: target
;
7729 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7730 1, OPTAB_LIB_WIDEN
);
7736 /* Someone beforehand should have rejected taking the address
7737 of such an object. */
7738 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7740 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7741 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7742 if (modifier
< EXPAND_SUM
)
7743 result
= force_operand (result
, target
);
7749 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7750 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7753 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7754 enum expand_modifier modifier
)
7756 addr_space_t as
= ADDR_SPACE_GENERIC
;
7757 enum machine_mode address_mode
= Pmode
;
7758 enum machine_mode pointer_mode
= ptr_mode
;
7759 enum machine_mode rmode
;
7762 /* Target mode of VOIDmode says "whatever's natural". */
7763 if (tmode
== VOIDmode
)
7764 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7766 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7768 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7769 address_mode
= targetm
.addr_space
.address_mode (as
);
7770 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7773 /* We can get called with some Weird Things if the user does silliness
7774 like "(short) &a". In that case, convert_memory_address won't do
7775 the right thing, so ignore the given target mode. */
7776 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7777 tmode
= address_mode
;
7779 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7780 tmode
, modifier
, as
);
7782 /* Despite expand_expr claims concerning ignoring TMODE when not
7783 strictly convenient, stuff breaks if we don't honor it. Note
7784 that combined with the above, we only do this for pointer modes. */
7785 rmode
= GET_MODE (result
);
7786 if (rmode
== VOIDmode
)
7789 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7794 /* Generate code for computing CONSTRUCTOR EXP.
7795 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7796 is TRUE, instead of creating a temporary variable in memory
7797 NULL is returned and the caller needs to handle it differently. */
7800 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7801 bool avoid_temp_mem
)
7803 tree type
= TREE_TYPE (exp
);
7804 enum machine_mode mode
= TYPE_MODE (type
);
7806 /* Try to avoid creating a temporary at all. This is possible
7807 if all of the initializer is zero.
7808 FIXME: try to handle all [0..255] initializers we can handle
7810 if (TREE_STATIC (exp
)
7811 && !TREE_ADDRESSABLE (exp
)
7812 && target
!= 0 && mode
== BLKmode
7813 && all_zeros_p (exp
))
7815 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7819 /* All elts simple constants => refer to a constant in memory. But
7820 if this is a non-BLKmode mode, let it store a field at a time
7821 since that should make a CONST_INT, CONST_WIDE_INT or
7822 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7823 use, it is best to store directly into the target unless the type
7824 is large enough that memcpy will be used. If we are making an
7825 initializer and all operands are constant, put it in memory as
7828 FIXME: Avoid trying to fill vector constructors piece-meal.
7829 Output them with output_constant_def below unless we're sure
7830 they're zeros. This should go away when vector initializers
7831 are treated like VECTOR_CST instead of arrays. */
7832 if ((TREE_STATIC (exp
)
7833 && ((mode
== BLKmode
7834 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7835 || TREE_ADDRESSABLE (exp
)
7836 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7837 && (! MOVE_BY_PIECES_P
7838 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7840 && ! mostly_zeros_p (exp
))))
7841 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7842 && TREE_CONSTANT (exp
)))
7849 constructor
= expand_expr_constant (exp
, 1, modifier
);
7851 if (modifier
!= EXPAND_CONST_ADDRESS
7852 && modifier
!= EXPAND_INITIALIZER
7853 && modifier
!= EXPAND_SUM
)
7854 constructor
= validize_mem (constructor
);
7859 /* Handle calls that pass values in multiple non-contiguous
7860 locations. The Irix 6 ABI has examples of this. */
7861 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7862 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7867 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7870 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7875 /* expand_expr: generate code for computing expression EXP.
7876 An rtx for the computed value is returned. The value is never null.
7877 In the case of a void EXP, const0_rtx is returned.
7879 The value may be stored in TARGET if TARGET is nonzero.
7880 TARGET is just a suggestion; callers must assume that
7881 the rtx returned may not be the same as TARGET.
7883 If TARGET is CONST0_RTX, it means that the value will be ignored.
7885 If TMODE is not VOIDmode, it suggests generating the
7886 result in mode TMODE. But this is done only when convenient.
7887 Otherwise, TMODE is ignored and the value generated in its natural mode.
7888 TMODE is just a suggestion; callers must assume that
7889 the rtx returned may not have mode TMODE.
7891 Note that TARGET may have neither TMODE nor MODE. In that case, it
7892 probably will not be used.
7894 If MODIFIER is EXPAND_SUM then when EXP is an addition
7895 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7896 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7897 products as above, or REG or MEM, or constant.
7898 Ordinarily in such cases we would output mul or add instructions
7899 and then return a pseudo reg containing the sum.
7901 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7902 it also marks a label as absolutely required (it can't be dead).
7903 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7904 This is used for outputting expressions used in initializers.
7906 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7907 with a constant address even if that address is not normally legitimate.
7908 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7910 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7911 a call parameter. Such targets require special care as we haven't yet
7912 marked TARGET so that it's safe from being trashed by libcalls. We
7913 don't want to use TARGET for anything but the final result;
7914 Intermediate values must go elsewhere. Additionally, calls to
7915 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7917 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7918 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7919 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7920 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7923 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7924 In this case, we don't adjust a returned MEM rtx that wouldn't be
7925 sufficiently aligned for its mode; instead, it's up to the caller
7926 to deal with it afterwards. This is used to make sure that unaligned
7927 base objects for which out-of-bounds accesses are supported, for
7928 example record types with trailing arrays, aren't realigned behind
7929 the back of the caller.
7930 The normal operating mode is to pass FALSE for this parameter. */
7933 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7934 enum expand_modifier modifier
, rtx
*alt_rtl
,
7935 bool inner_reference_p
)
7939 /* Handle ERROR_MARK before anybody tries to access its type. */
7940 if (TREE_CODE (exp
) == ERROR_MARK
7941 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7943 ret
= CONST0_RTX (tmode
);
7944 return ret
? ret
: const0_rtx
;
7947 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
7952 /* Try to expand the conditional expression which is represented by
7953 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7954 return the rtl reg which repsents the result. Otherwise return
7958 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7959 tree treeop1 ATTRIBUTE_UNUSED
,
7960 tree treeop2 ATTRIBUTE_UNUSED
)
7962 #ifdef HAVE_conditional_move
7964 rtx op00
, op01
, op1
, op2
;
7965 enum rtx_code comparison_code
;
7966 enum machine_mode comparison_mode
;
7969 tree type
= TREE_TYPE (treeop1
);
7970 int unsignedp
= TYPE_UNSIGNED (type
);
7971 enum machine_mode mode
= TYPE_MODE (type
);
7972 enum machine_mode orig_mode
= mode
;
7974 /* If we cannot do a conditional move on the mode, try doing it
7975 with the promoted mode. */
7976 if (!can_conditionally_move_p (mode
))
7978 mode
= promote_mode (type
, mode
, &unsignedp
);
7979 if (!can_conditionally_move_p (mode
))
7981 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7984 temp
= assign_temp (type
, 0, 1);
7987 expand_operands (treeop1
, treeop2
,
7988 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7990 if (TREE_CODE (treeop0
) == SSA_NAME
7991 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7993 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7994 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7995 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7996 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7997 comparison_mode
= TYPE_MODE (type
);
7998 unsignedp
= TYPE_UNSIGNED (type
);
7999 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
8001 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
8003 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
8004 enum tree_code cmpcode
= TREE_CODE (treeop0
);
8005 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
8006 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
8007 unsignedp
= TYPE_UNSIGNED (type
);
8008 comparison_mode
= TYPE_MODE (type
);
8009 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
8013 op00
= expand_normal (treeop0
);
8015 comparison_code
= NE
;
8016 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8019 if (GET_MODE (op1
) != mode
)
8020 op1
= gen_lowpart (mode
, op1
);
8022 if (GET_MODE (op2
) != mode
)
8023 op2
= gen_lowpart (mode
, op2
);
8025 /* Try to emit the conditional move. */
8026 insn
= emit_conditional_move (temp
, comparison_code
,
8027 op00
, op01
, comparison_mode
,
8031 /* If we could do the conditional move, emit the sequence,
8035 rtx_insn
*seq
= get_insns ();
8038 return convert_modes (orig_mode
, mode
, temp
, 0);
8041 /* Otherwise discard the sequence and fall back to code with
8049 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
8050 enum expand_modifier modifier
)
8052 rtx op0
, op1
, op2
, temp
;
8055 enum machine_mode mode
;
8056 enum tree_code code
= ops
->code
;
8058 rtx subtarget
, original_target
;
8060 bool reduce_bit_field
;
8061 location_t loc
= ops
->location
;
8062 tree treeop0
, treeop1
, treeop2
;
8063 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8064 ? reduce_to_bit_field_precision ((expr), \
8070 mode
= TYPE_MODE (type
);
8071 unsignedp
= TYPE_UNSIGNED (type
);
8077 /* We should be called only on simple (binary or unary) expressions,
8078 exactly those that are valid in gimple expressions that aren't
8079 GIMPLE_SINGLE_RHS (or invalid). */
8080 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8081 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8082 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8084 ignore
= (target
== const0_rtx
8085 || ((CONVERT_EXPR_CODE_P (code
)
8086 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8087 && TREE_CODE (type
) == VOID_TYPE
));
8089 /* We should be called only if we need the result. */
8090 gcc_assert (!ignore
);
8092 /* An operation in what may be a bit-field type needs the
8093 result to be reduced to the precision of the bit-field type,
8094 which is narrower than that of the type's mode. */
8095 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8096 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8098 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8101 /* Use subtarget as the target for operand 0 of a binary operation. */
8102 subtarget
= get_subtarget (target
);
8103 original_target
= target
;
8107 case NON_LVALUE_EXPR
:
8110 if (treeop0
== error_mark_node
)
8113 if (TREE_CODE (type
) == UNION_TYPE
)
8115 tree valtype
= TREE_TYPE (treeop0
);
8117 /* If both input and output are BLKmode, this conversion isn't doing
8118 anything except possibly changing memory attribute. */
8119 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8121 rtx result
= expand_expr (treeop0
, target
, tmode
,
8124 result
= copy_rtx (result
);
8125 set_mem_attributes (result
, type
, 0);
8131 if (TYPE_MODE (type
) != BLKmode
)
8132 target
= gen_reg_rtx (TYPE_MODE (type
));
8134 target
= assign_temp (type
, 1, 1);
8138 /* Store data into beginning of memory target. */
8139 store_expr (treeop0
,
8140 adjust_address (target
, TYPE_MODE (valtype
), 0),
8141 modifier
== EXPAND_STACK_PARM
,
8146 gcc_assert (REG_P (target
));
8148 /* Store this field into a union of the proper type. */
8149 store_field (target
,
8150 MIN ((int_size_in_bytes (TREE_TYPE
8153 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8154 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8157 /* Return the entire union. */
8161 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8163 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8166 /* If the signedness of the conversion differs and OP0 is
8167 a promoted SUBREG, clear that indication since we now
8168 have to do the proper extension. */
8169 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8170 && GET_CODE (op0
) == SUBREG
)
8171 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8173 return REDUCE_BIT_FIELD (op0
);
8176 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8177 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8178 if (GET_MODE (op0
) == mode
)
8181 /* If OP0 is a constant, just convert it into the proper mode. */
8182 else if (CONSTANT_P (op0
))
8184 tree inner_type
= TREE_TYPE (treeop0
);
8185 enum machine_mode inner_mode
= GET_MODE (op0
);
8187 if (inner_mode
== VOIDmode
)
8188 inner_mode
= TYPE_MODE (inner_type
);
8190 if (modifier
== EXPAND_INITIALIZER
)
8191 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8192 subreg_lowpart_offset (mode
,
8195 op0
= convert_modes (mode
, inner_mode
, op0
,
8196 TYPE_UNSIGNED (inner_type
));
8199 else if (modifier
== EXPAND_INITIALIZER
)
8200 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8202 else if (target
== 0)
8203 op0
= convert_to_mode (mode
, op0
,
8204 TYPE_UNSIGNED (TREE_TYPE
8208 convert_move (target
, op0
,
8209 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8213 return REDUCE_BIT_FIELD (op0
);
8215 case ADDR_SPACE_CONVERT_EXPR
:
8217 tree treeop0_type
= TREE_TYPE (treeop0
);
8219 addr_space_t as_from
;
8221 gcc_assert (POINTER_TYPE_P (type
));
8222 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8224 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8225 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8227 /* Conversions between pointers to the same address space should
8228 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8229 gcc_assert (as_to
!= as_from
);
8231 /* Ask target code to handle conversion between pointers
8232 to overlapping address spaces. */
8233 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8234 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8236 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8237 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8242 /* For disjoint address spaces, converting anything but
8243 a null pointer invokes undefined behaviour. We simply
8244 always return a null pointer here. */
8245 return CONST0_RTX (mode
);
8248 case POINTER_PLUS_EXPR
:
8249 /* Even though the sizetype mode and the pointer's mode can be different
8250 expand is able to handle this correctly and get the correct result out
8251 of the PLUS_EXPR code. */
8252 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8253 if sizetype precision is smaller than pointer precision. */
8254 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8255 treeop1
= fold_convert_loc (loc
, type
,
8256 fold_convert_loc (loc
, ssizetype
,
8258 /* If sizetype precision is larger than pointer precision, truncate the
8259 offset to have matching modes. */
8260 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8261 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8264 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8265 something else, make sure we add the register to the constant and
8266 then to the other thing. This case can occur during strength
8267 reduction and doing it this way will produce better code if the
8268 frame pointer or argument pointer is eliminated.
8270 fold-const.c will ensure that the constant is always in the inner
8271 PLUS_EXPR, so the only case we need to do anything about is if
8272 sp, ap, or fp is our second argument, in which case we must swap
8273 the innermost first argument and our second argument. */
8275 if (TREE_CODE (treeop0
) == PLUS_EXPR
8276 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8277 && TREE_CODE (treeop1
) == VAR_DECL
8278 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8279 || DECL_RTL (treeop1
) == stack_pointer_rtx
8280 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8285 /* If the result is to be ptr_mode and we are adding an integer to
8286 something, we might be forming a constant. So try to use
8287 plus_constant. If it produces a sum and we can't accept it,
8288 use force_operand. This allows P = &ARR[const] to generate
8289 efficient code on machines where a SYMBOL_REF is not a valid
8292 If this is an EXPAND_SUM call, always return the sum. */
8293 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8294 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8296 if (modifier
== EXPAND_STACK_PARM
)
8298 if (TREE_CODE (treeop0
) == INTEGER_CST
8299 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8300 && TREE_CONSTANT (treeop1
))
8304 enum machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
8306 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8308 /* Use wi::shwi to ensure that the constant is
8309 truncated according to the mode of OP1, then sign extended
8310 to a HOST_WIDE_INT. Using the constant directly can result
8311 in non-canonical RTL in a 64x32 cross compile. */
8312 wc
= TREE_INT_CST_LOW (treeop0
);
8314 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8315 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8316 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8317 op1
= force_operand (op1
, target
);
8318 return REDUCE_BIT_FIELD (op1
);
8321 else if (TREE_CODE (treeop1
) == INTEGER_CST
8322 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8323 && TREE_CONSTANT (treeop0
))
8327 enum machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
8329 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8330 (modifier
== EXPAND_INITIALIZER
8331 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8332 if (! CONSTANT_P (op0
))
8334 op1
= expand_expr (treeop1
, NULL_RTX
,
8335 VOIDmode
, modifier
);
8336 /* Return a PLUS if modifier says it's OK. */
8337 if (modifier
== EXPAND_SUM
8338 || modifier
== EXPAND_INITIALIZER
)
8339 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8342 /* Use wi::shwi to ensure that the constant is
8343 truncated according to the mode of OP1, then sign extended
8344 to a HOST_WIDE_INT. Using the constant directly can result
8345 in non-canonical RTL in a 64x32 cross compile. */
8346 wc
= TREE_INT_CST_LOW (treeop1
);
8348 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8349 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8350 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8351 op0
= force_operand (op0
, target
);
8352 return REDUCE_BIT_FIELD (op0
);
8356 /* Use TER to expand pointer addition of a negated value
8357 as pointer subtraction. */
8358 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8359 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8360 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8361 && TREE_CODE (treeop1
) == SSA_NAME
8362 && TYPE_MODE (TREE_TYPE (treeop0
))
8363 == TYPE_MODE (TREE_TYPE (treeop1
)))
8365 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8368 treeop1
= gimple_assign_rhs1 (def
);
8374 /* No sense saving up arithmetic to be done
8375 if it's all in the wrong mode to form part of an address.
8376 And force_operand won't know whether to sign-extend or
8378 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8379 || mode
!= ptr_mode
)
8381 expand_operands (treeop0
, treeop1
,
8382 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8383 if (op0
== const0_rtx
)
8385 if (op1
== const0_rtx
)
8390 expand_operands (treeop0
, treeop1
,
8391 subtarget
, &op0
, &op1
, modifier
);
8392 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8396 /* For initializers, we are allowed to return a MINUS of two
8397 symbolic constants. Here we handle all cases when both operands
8399 /* Handle difference of two symbolic constants,
8400 for the sake of an initializer. */
8401 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8402 && really_constant_p (treeop0
)
8403 && really_constant_p (treeop1
))
8405 expand_operands (treeop0
, treeop1
,
8406 NULL_RTX
, &op0
, &op1
, modifier
);
8408 /* If the last operand is a CONST_INT, use plus_constant of
8409 the negated constant. Else make the MINUS. */
8410 if (CONST_INT_P (op1
))
8411 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8414 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8417 /* No sense saving up arithmetic to be done
8418 if it's all in the wrong mode to form part of an address.
8419 And force_operand won't know whether to sign-extend or
8421 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8422 || mode
!= ptr_mode
)
8425 expand_operands (treeop0
, treeop1
,
8426 subtarget
, &op0
, &op1
, modifier
);
8428 /* Convert A - const to A + (-const). */
8429 if (CONST_INT_P (op1
))
8431 op1
= negate_rtx (mode
, op1
);
8432 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8437 case WIDEN_MULT_PLUS_EXPR
:
8438 case WIDEN_MULT_MINUS_EXPR
:
8439 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8440 op2
= expand_normal (treeop2
);
8441 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8445 case WIDEN_MULT_EXPR
:
8446 /* If first operand is constant, swap them.
8447 Thus the following special case checks need only
8448 check the second operand. */
8449 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8456 /* First, check if we have a multiplication of one signed and one
8457 unsigned operand. */
8458 if (TREE_CODE (treeop1
) != INTEGER_CST
8459 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8460 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8462 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8463 this_optab
= usmul_widen_optab
;
8464 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8465 != CODE_FOR_nothing
)
8467 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8468 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8471 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8473 /* op0 and op1 might still be constant, despite the above
8474 != INTEGER_CST check. Handle it. */
8475 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8477 op0
= convert_modes (innermode
, mode
, op0
, true);
8478 op1
= convert_modes (innermode
, mode
, op1
, false);
8479 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8480 target
, unsignedp
));
8485 /* Check for a multiplication with matching signedness. */
8486 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8487 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8488 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8489 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8491 tree op0type
= TREE_TYPE (treeop0
);
8492 enum machine_mode innermode
= TYPE_MODE (op0type
);
8493 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8494 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8495 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8497 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8499 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8500 != CODE_FOR_nothing
)
8502 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8504 /* op0 and op1 might still be constant, despite the above
8505 != INTEGER_CST check. Handle it. */
8506 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8509 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8511 = convert_modes (innermode
, mode
, op1
,
8512 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8513 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8517 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8518 unsignedp
, this_optab
);
8519 return REDUCE_BIT_FIELD (temp
);
8521 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8523 && innermode
== word_mode
)
8526 op0
= expand_normal (treeop0
);
8527 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8528 op1
= convert_modes (innermode
, mode
,
8529 expand_normal (treeop1
),
8530 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8532 op1
= expand_normal (treeop1
);
8533 /* op0 and op1 might still be constant, despite the above
8534 != INTEGER_CST check. Handle it. */
8535 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8536 goto widen_mult_const
;
8537 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8538 unsignedp
, OPTAB_LIB_WIDEN
);
8539 hipart
= gen_highpart (innermode
, temp
);
8540 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8544 emit_move_insn (hipart
, htem
);
8545 return REDUCE_BIT_FIELD (temp
);
8549 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8550 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8551 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8552 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8556 optab opt
= fma_optab
;
8559 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8561 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8563 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8566 gcc_assert (fn
!= NULL_TREE
);
8567 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8568 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8571 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8572 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8577 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8580 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8581 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8584 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8587 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8590 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8593 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8597 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8599 op2
= expand_normal (treeop2
);
8600 op1
= expand_normal (treeop1
);
8602 return expand_ternary_op (TYPE_MODE (type
), opt
,
8603 op0
, op1
, op2
, target
, 0);
8607 /* If this is a fixed-point operation, then we cannot use the code
8608 below because "expand_mult" doesn't support sat/no-sat fixed-point
8610 if (ALL_FIXED_POINT_MODE_P (mode
))
8613 /* If first operand is constant, swap them.
8614 Thus the following special case checks need only
8615 check the second operand. */
8616 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8623 /* Attempt to return something suitable for generating an
8624 indexed address, for machines that support that. */
8626 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8627 && tree_fits_shwi_p (treeop1
))
8629 tree exp1
= treeop1
;
8631 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8635 op0
= force_operand (op0
, NULL_RTX
);
8637 op0
= copy_to_mode_reg (mode
, op0
);
8639 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8640 gen_int_mode (tree_to_shwi (exp1
),
8641 TYPE_MODE (TREE_TYPE (exp1
)))));
8644 if (modifier
== EXPAND_STACK_PARM
)
8647 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8648 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8650 case TRUNC_DIV_EXPR
:
8651 case FLOOR_DIV_EXPR
:
8653 case ROUND_DIV_EXPR
:
8654 case EXACT_DIV_EXPR
:
8655 /* If this is a fixed-point operation, then we cannot use the code
8656 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8658 if (ALL_FIXED_POINT_MODE_P (mode
))
8661 if (modifier
== EXPAND_STACK_PARM
)
8663 /* Possible optimization: compute the dividend with EXPAND_SUM
8664 then if the divisor is constant can optimize the case
8665 where some terms of the dividend have coeffs divisible by it. */
8666 expand_operands (treeop0
, treeop1
,
8667 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8668 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8673 case MULT_HIGHPART_EXPR
:
8674 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8675 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8679 case TRUNC_MOD_EXPR
:
8680 case FLOOR_MOD_EXPR
:
8682 case ROUND_MOD_EXPR
:
8683 if (modifier
== EXPAND_STACK_PARM
)
8685 expand_operands (treeop0
, treeop1
,
8686 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8687 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8689 case FIXED_CONVERT_EXPR
:
8690 op0
= expand_normal (treeop0
);
8691 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8692 target
= gen_reg_rtx (mode
);
8694 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8695 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8696 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8697 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8699 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8702 case FIX_TRUNC_EXPR
:
8703 op0
= expand_normal (treeop0
);
8704 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8705 target
= gen_reg_rtx (mode
);
8706 expand_fix (target
, op0
, unsignedp
);
8710 op0
= expand_normal (treeop0
);
8711 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8712 target
= gen_reg_rtx (mode
);
8713 /* expand_float can't figure out what to do if FROM has VOIDmode.
8714 So give it the correct mode. With -O, cse will optimize this. */
8715 if (GET_MODE (op0
) == VOIDmode
)
8716 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8718 expand_float (target
, op0
,
8719 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8723 op0
= expand_expr (treeop0
, subtarget
,
8724 VOIDmode
, EXPAND_NORMAL
);
8725 if (modifier
== EXPAND_STACK_PARM
)
8727 temp
= expand_unop (mode
,
8728 optab_for_tree_code (NEGATE_EXPR
, type
,
8732 return REDUCE_BIT_FIELD (temp
);
8735 op0
= expand_expr (treeop0
, subtarget
,
8736 VOIDmode
, EXPAND_NORMAL
);
8737 if (modifier
== EXPAND_STACK_PARM
)
8740 /* ABS_EXPR is not valid for complex arguments. */
8741 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8742 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8744 /* Unsigned abs is simply the operand. Testing here means we don't
8745 risk generating incorrect code below. */
8746 if (TYPE_UNSIGNED (type
))
8749 return expand_abs (mode
, op0
, target
, unsignedp
,
8750 safe_from_p (target
, treeop0
, 1));
8754 target
= original_target
;
8756 || modifier
== EXPAND_STACK_PARM
8757 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8758 || GET_MODE (target
) != mode
8760 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8761 target
= gen_reg_rtx (mode
);
8762 expand_operands (treeop0
, treeop1
,
8763 target
, &op0
, &op1
, EXPAND_NORMAL
);
8765 /* First try to do it with a special MIN or MAX instruction.
8766 If that does not win, use a conditional jump to select the proper
8768 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8769 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8774 /* At this point, a MEM target is no longer useful; we will get better
8777 if (! REG_P (target
))
8778 target
= gen_reg_rtx (mode
);
8780 /* If op1 was placed in target, swap op0 and op1. */
8781 if (target
!= op0
&& target
== op1
)
8788 /* We generate better code and avoid problems with op1 mentioning
8789 target by forcing op1 into a pseudo if it isn't a constant. */
8790 if (! CONSTANT_P (op1
))
8791 op1
= force_reg (mode
, op1
);
8794 enum rtx_code comparison_code
;
8797 if (code
== MAX_EXPR
)
8798 comparison_code
= unsignedp
? GEU
: GE
;
8800 comparison_code
= unsignedp
? LEU
: LE
;
8802 /* Canonicalize to comparisons against 0. */
8803 if (op1
== const1_rtx
)
8805 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8806 or (a != 0 ? a : 1) for unsigned.
8807 For MIN we are safe converting (a <= 1 ? a : 1)
8808 into (a <= 0 ? a : 1) */
8809 cmpop1
= const0_rtx
;
8810 if (code
== MAX_EXPR
)
8811 comparison_code
= unsignedp
? NE
: GT
;
8813 if (op1
== constm1_rtx
&& !unsignedp
)
8815 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8816 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8817 cmpop1
= const0_rtx
;
8818 if (code
== MIN_EXPR
)
8819 comparison_code
= LT
;
8821 #ifdef HAVE_conditional_move
8822 /* Use a conditional move if possible. */
8823 if (can_conditionally_move_p (mode
))
8829 /* Try to emit the conditional move. */
8830 insn
= emit_conditional_move (target
, comparison_code
,
8835 /* If we could do the conditional move, emit the sequence,
8839 rtx_insn
*seq
= get_insns ();
8845 /* Otherwise discard the sequence and fall back to code with
8851 emit_move_insn (target
, op0
);
8853 temp
= gen_label_rtx ();
8854 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8855 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8858 emit_move_insn (target
, op1
);
8863 op0
= expand_expr (treeop0
, subtarget
,
8864 VOIDmode
, EXPAND_NORMAL
);
8865 if (modifier
== EXPAND_STACK_PARM
)
8867 /* In case we have to reduce the result to bitfield precision
8868 for unsigned bitfield expand this as XOR with a proper constant
8870 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8872 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
8873 false, GET_MODE_PRECISION (mode
));
8875 temp
= expand_binop (mode
, xor_optab
, op0
,
8876 immed_wide_int_const (mask
, mode
),
8877 target
, 1, OPTAB_LIB_WIDEN
);
8880 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8884 /* ??? Can optimize bitwise operations with one arg constant.
8885 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8886 and (a bitwise1 b) bitwise2 b (etc)
8887 but that is probably not worth while. */
8896 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8897 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8898 == TYPE_PRECISION (type
)));
8903 /* If this is a fixed-point operation, then we cannot use the code
8904 below because "expand_shift" doesn't support sat/no-sat fixed-point
8906 if (ALL_FIXED_POINT_MODE_P (mode
))
8909 if (! safe_from_p (subtarget
, treeop1
, 1))
8911 if (modifier
== EXPAND_STACK_PARM
)
8913 op0
= expand_expr (treeop0
, subtarget
,
8914 VOIDmode
, EXPAND_NORMAL
);
8915 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8917 if (code
== LSHIFT_EXPR
)
8918 temp
= REDUCE_BIT_FIELD (temp
);
8921 /* Could determine the answer when only additive constants differ. Also,
8922 the addition of one can be handled by changing the condition. */
8929 case UNORDERED_EXPR
:
8937 temp
= do_store_flag (ops
,
8938 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8939 tmode
!= VOIDmode
? tmode
: mode
);
8943 /* Use a compare and a jump for BLKmode comparisons, or for function
8944 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8947 || modifier
== EXPAND_STACK_PARM
8948 || ! safe_from_p (target
, treeop0
, 1)
8949 || ! safe_from_p (target
, treeop1
, 1)
8950 /* Make sure we don't have a hard reg (such as function's return
8951 value) live across basic blocks, if not optimizing. */
8952 || (!optimize
&& REG_P (target
)
8953 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8954 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8956 emit_move_insn (target
, const0_rtx
);
8958 op1
= gen_label_rtx ();
8959 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8961 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8962 emit_move_insn (target
, constm1_rtx
);
8964 emit_move_insn (target
, const1_rtx
);
8970 /* Get the rtx code of the operands. */
8971 op0
= expand_normal (treeop0
);
8972 op1
= expand_normal (treeop1
);
8975 target
= gen_reg_rtx (TYPE_MODE (type
));
8977 /* If target overlaps with op1, then either we need to force
8978 op1 into a pseudo (if target also overlaps with op0),
8979 or write the complex parts in reverse order. */
8980 switch (GET_CODE (target
))
8983 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
8985 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
8987 complex_expr_force_op1
:
8988 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
8989 emit_move_insn (temp
, op1
);
8993 complex_expr_swap_order
:
8994 /* Move the imaginary (op1) and real (op0) parts to their
8996 write_complex_part (target
, op1
, true);
8997 write_complex_part (target
, op0
, false);
9003 temp
= adjust_address_nv (target
,
9004 GET_MODE_INNER (GET_MODE (target
)), 0);
9005 if (reg_overlap_mentioned_p (temp
, op1
))
9007 enum machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
9008 temp
= adjust_address_nv (target
, imode
,
9009 GET_MODE_SIZE (imode
));
9010 if (reg_overlap_mentioned_p (temp
, op0
))
9011 goto complex_expr_force_op1
;
9012 goto complex_expr_swap_order
;
9016 if (reg_overlap_mentioned_p (target
, op1
))
9018 if (reg_overlap_mentioned_p (target
, op0
))
9019 goto complex_expr_force_op1
;
9020 goto complex_expr_swap_order
;
9025 /* Move the real (op0) and imaginary (op1) parts to their location. */
9026 write_complex_part (target
, op0
, false);
9027 write_complex_part (target
, op1
, true);
9031 case WIDEN_SUM_EXPR
:
9033 tree oprnd0
= treeop0
;
9034 tree oprnd1
= treeop1
;
9036 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9037 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9042 case REDUC_MAX_EXPR
:
9043 case REDUC_MIN_EXPR
:
9044 case REDUC_PLUS_EXPR
:
9046 op0
= expand_normal (treeop0
);
9047 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9048 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
9053 case VEC_LSHIFT_EXPR
:
9054 case VEC_RSHIFT_EXPR
:
9056 target
= expand_vec_shift_expr (ops
, target
);
9060 case VEC_UNPACK_HI_EXPR
:
9061 case VEC_UNPACK_LO_EXPR
:
9063 op0
= expand_normal (treeop0
);
9064 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9070 case VEC_UNPACK_FLOAT_HI_EXPR
:
9071 case VEC_UNPACK_FLOAT_LO_EXPR
:
9073 op0
= expand_normal (treeop0
);
9074 /* The signedness is determined from input operand. */
9075 temp
= expand_widen_pattern_expr
9076 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9077 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9083 case VEC_WIDEN_MULT_HI_EXPR
:
9084 case VEC_WIDEN_MULT_LO_EXPR
:
9085 case VEC_WIDEN_MULT_EVEN_EXPR
:
9086 case VEC_WIDEN_MULT_ODD_EXPR
:
9087 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9088 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9089 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9090 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9092 gcc_assert (target
);
9095 case VEC_PACK_TRUNC_EXPR
:
9096 case VEC_PACK_SAT_EXPR
:
9097 case VEC_PACK_FIX_TRUNC_EXPR
:
9098 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9102 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9103 op2
= expand_normal (treeop2
);
9105 /* Careful here: if the target doesn't support integral vector modes,
9106 a constant selection vector could wind up smooshed into a normal
9107 integral constant. */
9108 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9110 tree sel_type
= TREE_TYPE (treeop2
);
9111 enum machine_mode vmode
9112 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9113 TYPE_VECTOR_SUBPARTS (sel_type
));
9114 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9115 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9116 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9119 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9121 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9127 tree oprnd0
= treeop0
;
9128 tree oprnd1
= treeop1
;
9129 tree oprnd2
= treeop2
;
9132 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9133 op2
= expand_normal (oprnd2
);
9134 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9141 tree oprnd0
= treeop0
;
9142 tree oprnd1
= treeop1
;
9143 tree oprnd2
= treeop2
;
9146 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9147 op2
= expand_normal (oprnd2
);
9148 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9153 case REALIGN_LOAD_EXPR
:
9155 tree oprnd0
= treeop0
;
9156 tree oprnd1
= treeop1
;
9157 tree oprnd2
= treeop2
;
9160 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9161 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9162 op2
= expand_normal (oprnd2
);
9163 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9170 /* A COND_EXPR with its type being VOID_TYPE represents a
9171 conditional jump and is handled in
9172 expand_gimple_cond_expr. */
9173 gcc_assert (!VOID_TYPE_P (type
));
9175 /* Note that COND_EXPRs whose type is a structure or union
9176 are required to be constructed to contain assignments of
9177 a temporary variable, so that we can evaluate them here
9178 for side effect only. If type is void, we must do likewise. */
9180 gcc_assert (!TREE_ADDRESSABLE (type
)
9182 && TREE_TYPE (treeop1
) != void_type_node
9183 && TREE_TYPE (treeop2
) != void_type_node
);
9185 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9189 /* If we are not to produce a result, we have no target. Otherwise,
9190 if a target was specified use it; it will not be used as an
9191 intermediate target unless it is safe. If no target, use a
9194 if (modifier
!= EXPAND_STACK_PARM
9196 && safe_from_p (original_target
, treeop0
, 1)
9197 && GET_MODE (original_target
) == mode
9198 && !MEM_P (original_target
))
9199 temp
= original_target
;
9201 temp
= assign_temp (type
, 0, 1);
9203 do_pending_stack_adjust ();
9205 op0
= gen_label_rtx ();
9206 op1
= gen_label_rtx ();
9207 jumpifnot (treeop0
, op0
, -1);
9208 store_expr (treeop1
, temp
,
9209 modifier
== EXPAND_STACK_PARM
,
9212 emit_jump_insn (gen_jump (op1
));
9215 store_expr (treeop2
, temp
,
9216 modifier
== EXPAND_STACK_PARM
,
9224 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9231 /* Here to do an ordinary binary operator. */
9233 expand_operands (treeop0
, treeop1
,
9234 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9236 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9238 if (modifier
== EXPAND_STACK_PARM
)
9240 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9241 unsignedp
, OPTAB_LIB_WIDEN
);
9243 /* Bitwise operations do not need bitfield reduction as we expect their
9244 operands being properly truncated. */
9245 if (code
== BIT_XOR_EXPR
9246 || code
== BIT_AND_EXPR
9247 || code
== BIT_IOR_EXPR
)
9249 return REDUCE_BIT_FIELD (temp
);
9251 #undef REDUCE_BIT_FIELD
9253 /* Return TRUE if value in SSA is zero and sign extended for wider mode MODE
9254 using value range information stored. Return FALSE otherwise.
9256 This is used to check if SUBREG is zero and sign extended and to set
9257 promoted mode SRP_SIGNED_AND_UNSIGNED to SUBREG. */
9260 promoted_for_signed_and_unsigned_p (tree ssa
, enum machine_mode mode
)
9264 if (ssa
== NULL_TREE
9265 || TREE_CODE (ssa
) != SSA_NAME
9266 || !INTEGRAL_TYPE_P (TREE_TYPE (ssa
))
9267 || (TYPE_PRECISION (TREE_TYPE (ssa
)) != GET_MODE_PRECISION (mode
)))
9270 /* Return FALSE if value_range is not recorded for SSA. */
9271 if (get_range_info (ssa
, &min
, &max
) != VR_RANGE
)
9274 /* Return true (to set SRP_SIGNED_AND_UNSIGNED to SUBREG) if MSB of the
9275 smaller mode is not set (i.e. MSB of ssa is not set). */
9276 if (!wi::neg_p (min
, SIGNED
) && !wi::neg_p(max
, SIGNED
))
9283 /* Return TRUE if expression STMT is suitable for replacement.
9284 Never consider memory loads as replaceable, because those don't ever lead
9285 into constant expressions. */
9288 stmt_is_replaceable_p (gimple stmt
)
9290 if (ssa_is_replaceable_p (stmt
))
9292 /* Don't move around loads. */
9293 if (!gimple_assign_single_p (stmt
)
9294 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9301 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9302 enum expand_modifier modifier
, rtx
*alt_rtl
,
9303 bool inner_reference_p
)
9305 rtx op0
, op1
, temp
, decl_rtl
;
9308 enum machine_mode mode
;
9309 enum tree_code code
= TREE_CODE (exp
);
9310 rtx subtarget
, original_target
;
9313 bool reduce_bit_field
;
9314 location_t loc
= EXPR_LOCATION (exp
);
9315 struct separate_ops ops
;
9316 tree treeop0
, treeop1
, treeop2
;
9317 tree ssa_name
= NULL_TREE
;
9320 type
= TREE_TYPE (exp
);
9321 mode
= TYPE_MODE (type
);
9322 unsignedp
= TYPE_UNSIGNED (type
);
9324 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9325 if (!VL_EXP_CLASS_P (exp
))
9326 switch (TREE_CODE_LENGTH (code
))
9329 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9330 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9331 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9341 ignore
= (target
== const0_rtx
9342 || ((CONVERT_EXPR_CODE_P (code
)
9343 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9344 && TREE_CODE (type
) == VOID_TYPE
));
9346 /* An operation in what may be a bit-field type needs the
9347 result to be reduced to the precision of the bit-field type,
9348 which is narrower than that of the type's mode. */
9349 reduce_bit_field
= (!ignore
9350 && INTEGRAL_TYPE_P (type
)
9351 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9353 /* If we are going to ignore this result, we need only do something
9354 if there is a side-effect somewhere in the expression. If there
9355 is, short-circuit the most common cases here. Note that we must
9356 not call expand_expr with anything but const0_rtx in case this
9357 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9361 if (! TREE_SIDE_EFFECTS (exp
))
9364 /* Ensure we reference a volatile object even if value is ignored, but
9365 don't do this if all we are doing is taking its address. */
9366 if (TREE_THIS_VOLATILE (exp
)
9367 && TREE_CODE (exp
) != FUNCTION_DECL
9368 && mode
!= VOIDmode
&& mode
!= BLKmode
9369 && modifier
!= EXPAND_CONST_ADDRESS
)
9371 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9377 if (TREE_CODE_CLASS (code
) == tcc_unary
9378 || code
== BIT_FIELD_REF
9379 || code
== COMPONENT_REF
9380 || code
== INDIRECT_REF
)
9381 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9384 else if (TREE_CODE_CLASS (code
) == tcc_binary
9385 || TREE_CODE_CLASS (code
) == tcc_comparison
9386 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9388 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9389 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9396 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9399 /* Use subtarget as the target for operand 0 of a binary operation. */
9400 subtarget
= get_subtarget (target
);
9401 original_target
= target
;
9407 tree function
= decl_function_context (exp
);
9409 temp
= label_rtx (exp
);
9410 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9412 if (function
!= current_function_decl
9414 LABEL_REF_NONLOCAL_P (temp
) = 1;
9416 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9421 /* ??? ivopts calls expander, without any preparation from
9422 out-of-ssa. So fake instructions as if this was an access to the
9423 base variable. This unnecessarily allocates a pseudo, see how we can
9424 reuse it, if partition base vars have it set already. */
9425 if (!currently_expanding_to_rtl
)
9427 tree var
= SSA_NAME_VAR (exp
);
9428 if (var
&& DECL_RTL_SET_P (var
))
9429 return DECL_RTL (var
);
9430 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9431 LAST_VIRTUAL_REGISTER
+ 1);
9434 g
= get_gimple_for_ssa_name (exp
);
9435 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9437 && modifier
== EXPAND_INITIALIZER
9438 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9439 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9440 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9441 g
= SSA_NAME_DEF_STMT (exp
);
9445 ops
.code
= gimple_assign_rhs_code (g
);
9446 switch (get_gimple_rhs_class (ops
.code
))
9448 case GIMPLE_TERNARY_RHS
:
9449 ops
.op2
= gimple_assign_rhs3 (g
);
9451 case GIMPLE_BINARY_RHS
:
9452 ops
.op1
= gimple_assign_rhs2 (g
);
9454 case GIMPLE_UNARY_RHS
:
9455 ops
.op0
= gimple_assign_rhs1 (g
);
9456 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9457 ops
.location
= gimple_location (g
);
9458 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9460 case GIMPLE_SINGLE_RHS
:
9462 location_t saved_loc
= curr_insn_location ();
9463 set_curr_insn_location (gimple_location (g
));
9464 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9465 tmode
, modifier
, NULL
, inner_reference_p
);
9466 set_curr_insn_location (saved_loc
);
9472 if (REG_P (r
) && !REG_EXPR (r
))
9473 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9478 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9479 exp
= SSA_NAME_VAR (ssa_name
);
9480 goto expand_decl_rtl
;
9484 /* If a static var's type was incomplete when the decl was written,
9485 but the type is complete now, lay out the decl now. */
9486 if (DECL_SIZE (exp
) == 0
9487 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9488 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9489 layout_decl (exp
, 0);
9491 /* ... fall through ... */
9495 decl_rtl
= DECL_RTL (exp
);
9497 gcc_assert (decl_rtl
);
9498 decl_rtl
= copy_rtx (decl_rtl
);
9499 /* Record writes to register variables. */
9500 if (modifier
== EXPAND_WRITE
9502 && HARD_REGISTER_P (decl_rtl
))
9503 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9504 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9506 /* Ensure variable marked as used even if it doesn't go through
9507 a parser. If it hasn't be used yet, write out an external
9509 TREE_USED (exp
) = 1;
9511 /* Show we haven't gotten RTL for this yet. */
9514 /* Variables inherited from containing functions should have
9515 been lowered by this point. */
9516 context
= decl_function_context (exp
);
9517 gcc_assert (SCOPE_FILE_SCOPE_P (context
)
9518 || context
== current_function_decl
9519 || TREE_STATIC (exp
)
9520 || DECL_EXTERNAL (exp
)
9521 /* ??? C++ creates functions that are not TREE_STATIC. */
9522 || TREE_CODE (exp
) == FUNCTION_DECL
);
9524 /* This is the case of an array whose size is to be determined
9525 from its initializer, while the initializer is still being parsed.
9526 ??? We aren't parsing while expanding anymore. */
9528 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9529 temp
= validize_mem (decl_rtl
);
9531 /* If DECL_RTL is memory, we are in the normal case and the
9532 address is not valid, get the address into a register. */
9534 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9537 *alt_rtl
= decl_rtl
;
9538 decl_rtl
= use_anchored_address (decl_rtl
);
9539 if (modifier
!= EXPAND_CONST_ADDRESS
9540 && modifier
!= EXPAND_SUM
9541 && !memory_address_addr_space_p (DECL_MODE (exp
),
9543 MEM_ADDR_SPACE (decl_rtl
)))
9544 temp
= replace_equiv_address (decl_rtl
,
9545 copy_rtx (XEXP (decl_rtl
, 0)));
9548 /* If we got something, return it. But first, set the alignment
9549 if the address is a register. */
9552 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9553 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9558 /* If the mode of DECL_RTL does not match that of the decl,
9559 there are two cases: we are dealing with a BLKmode value
9560 that is returned in a register, or we are dealing with
9561 a promoted value. In the latter case, return a SUBREG
9562 of the wanted mode, but mark it so that we know that it
9563 was already extended. */
9564 if (REG_P (decl_rtl
)
9565 && DECL_MODE (exp
) != BLKmode
9566 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9568 enum machine_mode pmode
;
9570 /* Get the signedness to be used for this variable. Ensure we get
9571 the same mode we got when the variable was declared. */
9572 if (code
== SSA_NAME
9573 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9574 && gimple_code (g
) == GIMPLE_CALL
9575 && !gimple_call_internal_p (g
))
9576 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9577 gimple_call_fntype (g
),
9580 pmode
= promote_decl_mode (exp
, &unsignedp
);
9581 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9583 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9584 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9585 if (promoted_for_signed_and_unsigned_p (ssa_name
, mode
))
9586 SUBREG_PROMOTED_SET (temp
, SRP_SIGNED_AND_UNSIGNED
);
9588 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9595 /* Given that TYPE_PRECISION (type) is not always equal to
9596 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9597 the former to the latter according to the signedness of the
9599 temp
= immed_wide_int_const (wide_int::from
9601 GET_MODE_PRECISION (TYPE_MODE (type
)),
9608 tree tmp
= NULL_TREE
;
9609 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9610 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9611 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9612 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9613 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9614 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9615 return const_vector_from_tree (exp
);
9616 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9618 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9620 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9624 vec
<constructor_elt
, va_gc
> *v
;
9626 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9627 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9628 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9629 tmp
= build_constructor (type
, v
);
9631 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9636 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9639 /* If optimized, generate immediate CONST_DOUBLE
9640 which will be turned into memory by reload if necessary.
9642 We used to force a register so that loop.c could see it. But
9643 this does not allow gen_* patterns to perform optimizations with
9644 the constants. It also produces two insns in cases like "x = 1.0;".
9645 On most machines, floating-point constants are not permitted in
9646 many insns, so we'd end up copying it to a register in any case.
9648 Now, we do the copying in expand_binop, if appropriate. */
9649 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9650 TYPE_MODE (TREE_TYPE (exp
)));
9653 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9654 TYPE_MODE (TREE_TYPE (exp
)));
9657 /* Handle evaluating a complex constant in a CONCAT target. */
9658 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9660 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9663 rtarg
= XEXP (original_target
, 0);
9664 itarg
= XEXP (original_target
, 1);
9666 /* Move the real and imaginary parts separately. */
9667 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9668 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9671 emit_move_insn (rtarg
, op0
);
9673 emit_move_insn (itarg
, op1
);
9675 return original_target
;
9678 /* ... fall through ... */
9681 temp
= expand_expr_constant (exp
, 1, modifier
);
9683 /* temp contains a constant address.
9684 On RISC machines where a constant address isn't valid,
9685 make some insns to get that address into a register. */
9686 if (modifier
!= EXPAND_CONST_ADDRESS
9687 && modifier
!= EXPAND_INITIALIZER
9688 && modifier
!= EXPAND_SUM
9689 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9690 MEM_ADDR_SPACE (temp
)))
9691 return replace_equiv_address (temp
,
9692 copy_rtx (XEXP (temp
, 0)));
9698 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
9701 if (!SAVE_EXPR_RESOLVED_P (exp
))
9703 /* We can indeed still hit this case, typically via builtin
9704 expanders calling save_expr immediately before expanding
9705 something. Assume this means that we only have to deal
9706 with non-BLKmode values. */
9707 gcc_assert (GET_MODE (ret
) != BLKmode
);
9709 val
= build_decl (curr_insn_location (),
9710 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9711 DECL_ARTIFICIAL (val
) = 1;
9712 DECL_IGNORED_P (val
) = 1;
9714 TREE_OPERAND (exp
, 0) = treeop0
;
9715 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9717 if (!CONSTANT_P (ret
))
9718 ret
= copy_to_reg (ret
);
9719 SET_DECL_RTL (val
, ret
);
9727 /* If we don't need the result, just ensure we evaluate any
9731 unsigned HOST_WIDE_INT idx
;
9734 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9735 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9740 return expand_constructor (exp
, target
, modifier
, false);
9742 case TARGET_MEM_REF
:
9745 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9746 enum insn_code icode
;
9749 op0
= addr_for_mem_ref (exp
, as
, true);
9750 op0
= memory_address_addr_space (mode
, op0
, as
);
9751 temp
= gen_rtx_MEM (mode
, op0
);
9752 set_mem_attributes (temp
, exp
, 0);
9753 set_mem_addr_space (temp
, as
);
9754 align
= get_object_alignment (exp
);
9755 if (modifier
!= EXPAND_WRITE
9756 && modifier
!= EXPAND_MEMORY
9758 && align
< GET_MODE_ALIGNMENT (mode
)
9759 /* If the target does not have special handling for unaligned
9760 loads of mode then it can use regular moves for them. */
9761 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9762 != CODE_FOR_nothing
))
9764 struct expand_operand ops
[2];
9766 /* We've already validated the memory, and we're creating a
9767 new pseudo destination. The predicates really can't fail,
9768 nor can the generator. */
9769 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9770 create_fixed_operand (&ops
[1], temp
);
9771 expand_insn (icode
, 2, ops
);
9772 temp
= ops
[0].value
;
9780 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9781 enum machine_mode address_mode
;
9782 tree base
= TREE_OPERAND (exp
, 0);
9784 enum insn_code icode
;
9786 /* Handle expansion of non-aliased memory with non-BLKmode. That
9787 might end up in a register. */
9788 if (mem_ref_refers_to_non_mem_p (exp
))
9790 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
9791 base
= TREE_OPERAND (base
, 0);
9793 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9794 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9795 == tree_to_uhwi (TYPE_SIZE (type
))))
9796 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9797 target
, tmode
, modifier
);
9798 if (TYPE_MODE (type
) == BLKmode
)
9800 temp
= assign_stack_temp (DECL_MODE (base
),
9801 GET_MODE_SIZE (DECL_MODE (base
)));
9802 store_expr (base
, temp
, 0, false);
9803 temp
= adjust_address (temp
, BLKmode
, offset
);
9804 set_mem_size (temp
, int_size_in_bytes (type
));
9807 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9808 bitsize_int (offset
* BITS_PER_UNIT
));
9809 return expand_expr (exp
, target
, tmode
, modifier
);
9811 address_mode
= targetm
.addr_space
.address_mode (as
);
9812 base
= TREE_OPERAND (exp
, 0);
9813 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9815 tree mask
= gimple_assign_rhs2 (def_stmt
);
9816 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9817 gimple_assign_rhs1 (def_stmt
), mask
);
9818 TREE_OPERAND (exp
, 0) = base
;
9820 align
= get_object_alignment (exp
);
9821 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9822 op0
= memory_address_addr_space (mode
, op0
, as
);
9823 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9825 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
9826 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9827 op0
= memory_address_addr_space (mode
, op0
, as
);
9829 temp
= gen_rtx_MEM (mode
, op0
);
9830 set_mem_attributes (temp
, exp
, 0);
9831 set_mem_addr_space (temp
, as
);
9832 if (TREE_THIS_VOLATILE (exp
))
9833 MEM_VOLATILE_P (temp
) = 1;
9834 if (modifier
!= EXPAND_WRITE
9835 && modifier
!= EXPAND_MEMORY
9836 && !inner_reference_p
9838 && align
< GET_MODE_ALIGNMENT (mode
))
9840 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9841 != CODE_FOR_nothing
)
9843 struct expand_operand ops
[2];
9845 /* We've already validated the memory, and we're creating a
9846 new pseudo destination. The predicates really can't fail,
9847 nor can the generator. */
9848 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9849 create_fixed_operand (&ops
[1], temp
);
9850 expand_insn (icode
, 2, ops
);
9851 temp
= ops
[0].value
;
9853 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9854 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9855 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9856 (modifier
== EXPAND_STACK_PARM
9857 ? NULL_RTX
: target
),
9866 tree array
= treeop0
;
9867 tree index
= treeop1
;
9870 /* Fold an expression like: "foo"[2].
9871 This is not done in fold so it won't happen inside &.
9872 Don't fold if this is for wide characters since it's too
9873 difficult to do correctly and this is a very rare case. */
9875 if (modifier
!= EXPAND_CONST_ADDRESS
9876 && modifier
!= EXPAND_INITIALIZER
9877 && modifier
!= EXPAND_MEMORY
)
9879 tree t
= fold_read_from_constant_string (exp
);
9882 return expand_expr (t
, target
, tmode
, modifier
);
9885 /* If this is a constant index into a constant array,
9886 just get the value from the array. Handle both the cases when
9887 we have an explicit constructor and when our operand is a variable
9888 that was declared const. */
9890 if (modifier
!= EXPAND_CONST_ADDRESS
9891 && modifier
!= EXPAND_INITIALIZER
9892 && modifier
!= EXPAND_MEMORY
9893 && TREE_CODE (array
) == CONSTRUCTOR
9894 && ! TREE_SIDE_EFFECTS (array
)
9895 && TREE_CODE (index
) == INTEGER_CST
)
9897 unsigned HOST_WIDE_INT ix
;
9900 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9902 if (tree_int_cst_equal (field
, index
))
9904 if (!TREE_SIDE_EFFECTS (value
))
9905 return expand_expr (fold (value
), target
, tmode
, modifier
);
9910 else if (optimize
>= 1
9911 && modifier
!= EXPAND_CONST_ADDRESS
9912 && modifier
!= EXPAND_INITIALIZER
9913 && modifier
!= EXPAND_MEMORY
9914 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9915 && TREE_CODE (index
) == INTEGER_CST
9916 && (TREE_CODE (array
) == VAR_DECL
9917 || TREE_CODE (array
) == CONST_DECL
)
9918 && (init
= ctor_for_folding (array
)) != error_mark_node
)
9920 if (init
== NULL_TREE
)
9922 tree value
= build_zero_cst (type
);
9923 if (TREE_CODE (value
) == CONSTRUCTOR
)
9925 /* If VALUE is a CONSTRUCTOR, this optimization is only
9926 useful if this doesn't store the CONSTRUCTOR into
9927 memory. If it does, it is more efficient to just
9928 load the data from the array directly. */
9929 rtx ret
= expand_constructor (value
, target
,
9931 if (ret
== NULL_RTX
)
9936 return expand_expr (value
, target
, tmode
, modifier
);
9938 else if (TREE_CODE (init
) == CONSTRUCTOR
)
9940 unsigned HOST_WIDE_INT ix
;
9943 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9945 if (tree_int_cst_equal (field
, index
))
9947 if (TREE_SIDE_EFFECTS (value
))
9950 if (TREE_CODE (value
) == CONSTRUCTOR
)
9952 /* If VALUE is a CONSTRUCTOR, this
9953 optimization is only useful if
9954 this doesn't store the CONSTRUCTOR
9955 into memory. If it does, it is more
9956 efficient to just load the data from
9957 the array directly. */
9958 rtx ret
= expand_constructor (value
, target
,
9960 if (ret
== NULL_RTX
)
9965 expand_expr (fold (value
), target
, tmode
, modifier
);
9968 else if (TREE_CODE (init
) == STRING_CST
)
9970 tree low_bound
= array_ref_low_bound (exp
);
9971 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
9973 /* Optimize the special case of a zero lower bound.
9975 We convert the lower bound to sizetype to avoid problems
9976 with constant folding. E.g. suppose the lower bound is
9977 1 and its mode is QI. Without the conversion
9978 (ARRAY + (INDEX - (unsigned char)1))
9980 (ARRAY + (-(unsigned char)1) + INDEX)
9982 (ARRAY + 255 + INDEX). Oops! */
9983 if (!integer_zerop (low_bound
))
9984 index1
= size_diffop_loc (loc
, index1
,
9985 fold_convert_loc (loc
, sizetype
,
9988 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
9990 tree type
= TREE_TYPE (TREE_TYPE (init
));
9991 enum machine_mode mode
= TYPE_MODE (type
);
9993 if (GET_MODE_CLASS (mode
) == MODE_INT
9994 && GET_MODE_SIZE (mode
) == 1)
9995 return gen_int_mode (TREE_STRING_POINTER (init
)
9996 [TREE_INT_CST_LOW (index1
)],
10002 goto normal_inner_ref
;
10004 case COMPONENT_REF
:
10005 /* If the operand is a CONSTRUCTOR, we can just extract the
10006 appropriate field if it is present. */
10007 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
10009 unsigned HOST_WIDE_INT idx
;
10012 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
10014 if (field
== treeop1
10015 /* We can normally use the value of the field in the
10016 CONSTRUCTOR. However, if this is a bitfield in
10017 an integral mode that we can fit in a HOST_WIDE_INT,
10018 we must mask only the number of bits in the bitfield,
10019 since this is done implicitly by the constructor. If
10020 the bitfield does not meet either of those conditions,
10021 we can't do this optimization. */
10022 && (! DECL_BIT_FIELD (field
)
10023 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
10024 && (GET_MODE_PRECISION (DECL_MODE (field
))
10025 <= HOST_BITS_PER_WIDE_INT
))))
10027 if (DECL_BIT_FIELD (field
)
10028 && modifier
== EXPAND_STACK_PARM
)
10030 op0
= expand_expr (value
, target
, tmode
, modifier
);
10031 if (DECL_BIT_FIELD (field
))
10033 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
10034 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
10036 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
10038 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
10040 op0
= expand_and (imode
, op0
, op1
, target
);
10044 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10046 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10048 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10056 goto normal_inner_ref
;
10058 case BIT_FIELD_REF
:
10059 case ARRAY_RANGE_REF
:
10062 enum machine_mode mode1
, mode2
;
10063 HOST_WIDE_INT bitsize
, bitpos
;
10065 int volatilep
= 0, must_force_mem
;
10066 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
10067 &mode1
, &unsignedp
, &volatilep
, true);
10068 rtx orig_op0
, memloc
;
10069 bool mem_attrs_from_type
= false;
10071 /* If we got back the original object, something is wrong. Perhaps
10072 we are evaluating an expression too early. In any event, don't
10073 infinitely recurse. */
10074 gcc_assert (tem
!= exp
);
10076 /* If TEM's type is a union of variable size, pass TARGET to the inner
10077 computation, since it will need a temporary and TARGET is known
10078 to have to do. This occurs in unchecked conversion in Ada. */
10080 = expand_expr_real (tem
,
10081 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10082 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10083 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10085 && modifier
!= EXPAND_STACK_PARM
10086 ? target
: NULL_RTX
),
10088 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10091 /* If the field has a mode, we want to access it in the
10092 field's mode, not the computed mode.
10093 If a MEM has VOIDmode (external with incomplete type),
10094 use BLKmode for it instead. */
10097 if (mode1
!= VOIDmode
)
10098 op0
= adjust_address (op0
, mode1
, 0);
10099 else if (GET_MODE (op0
) == VOIDmode
)
10100 op0
= adjust_address (op0
, BLKmode
, 0);
10104 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10106 /* If we have either an offset, a BLKmode result, or a reference
10107 outside the underlying object, we must force it to memory.
10108 Such a case can occur in Ada if we have unchecked conversion
10109 of an expression from a scalar type to an aggregate type or
10110 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10111 passed a partially uninitialized object or a view-conversion
10112 to a larger size. */
10113 must_force_mem
= (offset
10114 || mode1
== BLKmode
10115 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10117 /* Handle CONCAT first. */
10118 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10121 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
10124 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10127 op0
= XEXP (op0
, 0);
10128 mode2
= GET_MODE (op0
);
10130 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10131 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10135 op0
= XEXP (op0
, 1);
10137 mode2
= GET_MODE (op0
);
10140 /* Otherwise force into memory. */
10141 must_force_mem
= 1;
10144 /* If this is a constant, put it in a register if it is a legitimate
10145 constant and we don't need a memory reference. */
10146 if (CONSTANT_P (op0
)
10147 && mode2
!= BLKmode
10148 && targetm
.legitimate_constant_p (mode2
, op0
)
10149 && !must_force_mem
)
10150 op0
= force_reg (mode2
, op0
);
10152 /* Otherwise, if this is a constant, try to force it to the constant
10153 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10154 is a legitimate constant. */
10155 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10156 op0
= validize_mem (memloc
);
10158 /* Otherwise, if this is a constant or the object is not in memory
10159 and need be, put it there. */
10160 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10162 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10163 emit_move_insn (memloc
, op0
);
10165 mem_attrs_from_type
= true;
10170 enum machine_mode address_mode
;
10171 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10174 gcc_assert (MEM_P (op0
));
10176 address_mode
= get_address_mode (op0
);
10177 if (GET_MODE (offset_rtx
) != address_mode
)
10178 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10180 /* See the comment in expand_assignment for the rationale. */
10181 if (mode1
!= VOIDmode
10184 && (bitpos
% bitsize
) == 0
10185 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10186 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10188 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10192 op0
= offset_address (op0
, offset_rtx
,
10193 highest_pow2_factor (offset
));
10196 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10197 record its alignment as BIGGEST_ALIGNMENT. */
10198 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10199 && is_aligning_offset (offset
, tem
))
10200 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10202 /* Don't forget about volatility even if this is a bitfield. */
10203 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10205 if (op0
== orig_op0
)
10206 op0
= copy_rtx (op0
);
10208 MEM_VOLATILE_P (op0
) = 1;
10211 /* In cases where an aligned union has an unaligned object
10212 as a field, we might be extracting a BLKmode value from
10213 an integer-mode (e.g., SImode) object. Handle this case
10214 by doing the extract into an object as wide as the field
10215 (which we know to be the width of a basic mode), then
10216 storing into memory, and changing the mode to BLKmode. */
10217 if (mode1
== VOIDmode
10218 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10219 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10220 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10221 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10222 && modifier
!= EXPAND_CONST_ADDRESS
10223 && modifier
!= EXPAND_INITIALIZER
10224 && modifier
!= EXPAND_MEMORY
)
10225 /* If the bitfield is volatile and the bitsize
10226 is narrower than the access size of the bitfield,
10227 we need to extract bitfields from the access. */
10228 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10229 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10230 && mode1
!= BLKmode
10231 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10232 /* If the field isn't aligned enough to fetch as a memref,
10233 fetch it as a bit field. */
10234 || (mode1
!= BLKmode
10235 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10236 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10238 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10239 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10240 && modifier
!= EXPAND_MEMORY
10241 && ((modifier
== EXPAND_CONST_ADDRESS
10242 || modifier
== EXPAND_INITIALIZER
)
10244 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10245 || (bitpos
% BITS_PER_UNIT
!= 0)))
10246 /* If the type and the field are a constant size and the
10247 size of the type isn't the same size as the bitfield,
10248 we must use bitfield operations. */
10250 && TYPE_SIZE (TREE_TYPE (exp
))
10251 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10252 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10255 enum machine_mode ext_mode
= mode
;
10257 if (ext_mode
== BLKmode
10258 && ! (target
!= 0 && MEM_P (op0
)
10260 && bitpos
% BITS_PER_UNIT
== 0))
10261 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10263 if (ext_mode
== BLKmode
)
10266 target
= assign_temp (type
, 1, 1);
10268 /* ??? Unlike the similar test a few lines below, this one is
10269 very likely obsolete. */
10273 /* In this case, BITPOS must start at a byte boundary and
10274 TARGET, if specified, must be a MEM. */
10275 gcc_assert (MEM_P (op0
)
10276 && (!target
|| MEM_P (target
))
10277 && !(bitpos
% BITS_PER_UNIT
));
10279 emit_block_move (target
,
10280 adjust_address (op0
, VOIDmode
,
10281 bitpos
/ BITS_PER_UNIT
),
10282 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10284 (modifier
== EXPAND_STACK_PARM
10285 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10290 /* If we have nothing to extract, the result will be 0 for targets
10291 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10292 return 0 for the sake of consistency, as reading a zero-sized
10293 bitfield is valid in Ada and the value is fully specified. */
10297 op0
= validize_mem (op0
);
10299 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10300 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10302 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10303 (modifier
== EXPAND_STACK_PARM
10304 ? NULL_RTX
: target
),
10305 ext_mode
, ext_mode
);
10307 /* If the result is a record type and BITSIZE is narrower than
10308 the mode of OP0, an integral mode, and this is a big endian
10309 machine, we must put the field into the high-order bits. */
10310 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10311 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10312 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10313 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10314 GET_MODE_BITSIZE (GET_MODE (op0
))
10315 - bitsize
, op0
, 1);
10317 /* If the result type is BLKmode, store the data into a temporary
10318 of the appropriate type, but with the mode corresponding to the
10319 mode for the data we have (op0's mode). */
10320 if (mode
== BLKmode
)
10323 = assign_stack_temp_for_type (ext_mode
,
10324 GET_MODE_BITSIZE (ext_mode
),
10326 emit_move_insn (new_rtx
, op0
);
10327 op0
= copy_rtx (new_rtx
);
10328 PUT_MODE (op0
, BLKmode
);
10334 /* If the result is BLKmode, use that to access the object
10336 if (mode
== BLKmode
)
10339 /* Get a reference to just this component. */
10340 if (modifier
== EXPAND_CONST_ADDRESS
10341 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10342 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10344 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10346 if (op0
== orig_op0
)
10347 op0
= copy_rtx (op0
);
10349 /* If op0 is a temporary because of forcing to memory, pass only the
10350 type to set_mem_attributes so that the original expression is never
10351 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10352 if (mem_attrs_from_type
)
10353 set_mem_attributes (op0
, type
, 0);
10355 set_mem_attributes (op0
, exp
, 0);
10357 if (REG_P (XEXP (op0
, 0)))
10358 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10360 MEM_VOLATILE_P (op0
) |= volatilep
;
10361 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10362 || modifier
== EXPAND_CONST_ADDRESS
10363 || modifier
== EXPAND_INITIALIZER
)
10367 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10369 convert_move (target
, op0
, unsignedp
);
10374 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10377 /* All valid uses of __builtin_va_arg_pack () are removed during
10379 if (CALL_EXPR_VA_ARG_PACK (exp
))
10380 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10382 tree fndecl
= get_callee_fndecl (exp
), attr
;
10385 && (attr
= lookup_attribute ("error",
10386 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10387 error ("%Kcall to %qs declared with attribute error: %s",
10388 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10389 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10391 && (attr
= lookup_attribute ("warning",
10392 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10393 warning_at (tree_nonartificial_location (exp
),
10394 0, "%Kcall to %qs declared with attribute warning: %s",
10395 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10396 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10398 /* Check for a built-in function. */
10399 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10401 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10402 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10405 return expand_call (exp
, target
, ignore
);
10407 case VIEW_CONVERT_EXPR
:
10410 /* If we are converting to BLKmode, try to avoid an intermediate
10411 temporary by fetching an inner memory reference. */
10412 if (mode
== BLKmode
10413 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10414 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10415 && handled_component_p (treeop0
))
10417 enum machine_mode mode1
;
10418 HOST_WIDE_INT bitsize
, bitpos
;
10423 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10424 &offset
, &mode1
, &unsignedp
, &volatilep
,
10428 /* ??? We should work harder and deal with non-zero offsets. */
10430 && (bitpos
% BITS_PER_UNIT
) == 0
10432 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10434 /* See the normal_inner_ref case for the rationale. */
10436 = expand_expr_real (tem
,
10437 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10438 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10440 && modifier
!= EXPAND_STACK_PARM
10441 ? target
: NULL_RTX
),
10443 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10446 if (MEM_P (orig_op0
))
10450 /* Get a reference to just this component. */
10451 if (modifier
== EXPAND_CONST_ADDRESS
10452 || modifier
== EXPAND_SUM
10453 || modifier
== EXPAND_INITIALIZER
)
10454 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10456 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10458 if (op0
== orig_op0
)
10459 op0
= copy_rtx (op0
);
10461 set_mem_attributes (op0
, treeop0
, 0);
10462 if (REG_P (XEXP (op0
, 0)))
10463 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10465 MEM_VOLATILE_P (op0
) |= volatilep
;
10471 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10472 NULL
, inner_reference_p
);
10474 /* If the input and output modes are both the same, we are done. */
10475 if (mode
== GET_MODE (op0
))
10477 /* If neither mode is BLKmode, and both modes are the same size
10478 then we can use gen_lowpart. */
10479 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10480 && (GET_MODE_PRECISION (mode
)
10481 == GET_MODE_PRECISION (GET_MODE (op0
)))
10482 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10484 if (GET_CODE (op0
) == SUBREG
)
10485 op0
= force_reg (GET_MODE (op0
), op0
);
10486 temp
= gen_lowpart_common (mode
, op0
);
10491 if (!REG_P (op0
) && !MEM_P (op0
))
10492 op0
= force_reg (GET_MODE (op0
), op0
);
10493 op0
= gen_lowpart (mode
, op0
);
10496 /* If both types are integral, convert from one mode to the other. */
10497 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10498 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10499 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10500 /* If the output type is a bit-field type, do an extraction. */
10501 else if (reduce_bit_field
)
10502 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10503 TYPE_UNSIGNED (type
), NULL_RTX
,
10505 /* As a last resort, spill op0 to memory, and reload it in a
10507 else if (!MEM_P (op0
))
10509 /* If the operand is not a MEM, force it into memory. Since we
10510 are going to be changing the mode of the MEM, don't call
10511 force_const_mem for constants because we don't allow pool
10512 constants to change mode. */
10513 tree inner_type
= TREE_TYPE (treeop0
);
10515 gcc_assert (!TREE_ADDRESSABLE (exp
));
10517 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10519 = assign_stack_temp_for_type
10520 (TYPE_MODE (inner_type
),
10521 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10523 emit_move_insn (target
, op0
);
10527 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10528 output type is such that the operand is known to be aligned, indicate
10529 that it is. Otherwise, we need only be concerned about alignment for
10530 non-BLKmode results. */
10533 enum insn_code icode
;
10535 if (TYPE_ALIGN_OK (type
))
10537 /* ??? Copying the MEM without substantially changing it might
10538 run afoul of the code handling volatile memory references in
10539 store_expr, which assumes that TARGET is returned unmodified
10540 if it has been used. */
10541 op0
= copy_rtx (op0
);
10542 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10544 else if (modifier
!= EXPAND_WRITE
10545 && modifier
!= EXPAND_MEMORY
10546 && !inner_reference_p
10548 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10550 /* If the target does have special handling for unaligned
10551 loads of mode then use them. */
10552 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10553 != CODE_FOR_nothing
)
10557 op0
= adjust_address (op0
, mode
, 0);
10558 /* We've already validated the memory, and we're creating a
10559 new pseudo destination. The predicates really can't
10561 reg
= gen_reg_rtx (mode
);
10563 /* Nor can the insn generator. */
10564 insn
= GEN_FCN (icode
) (reg
, op0
);
10568 else if (STRICT_ALIGNMENT
)
10570 tree inner_type
= TREE_TYPE (treeop0
);
10571 HOST_WIDE_INT temp_size
10572 = MAX (int_size_in_bytes (inner_type
),
10573 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10575 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10576 rtx new_with_op0_mode
10577 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10579 gcc_assert (!TREE_ADDRESSABLE (exp
));
10581 if (GET_MODE (op0
) == BLKmode
)
10582 emit_block_move (new_with_op0_mode
, op0
,
10583 GEN_INT (GET_MODE_SIZE (mode
)),
10584 (modifier
== EXPAND_STACK_PARM
10585 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10587 emit_move_insn (new_with_op0_mode
, op0
);
10593 op0
= adjust_address (op0
, mode
, 0);
10600 tree lhs
= treeop0
;
10601 tree rhs
= treeop1
;
10602 gcc_assert (ignore
);
10604 /* Check for |= or &= of a bitfield of size one into another bitfield
10605 of size 1. In this case, (unless we need the result of the
10606 assignment) we can do this more efficiently with a
10607 test followed by an assignment, if necessary.
10609 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10610 things change so we do, this code should be enhanced to
10612 if (TREE_CODE (lhs
) == COMPONENT_REF
10613 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10614 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10615 && TREE_OPERAND (rhs
, 0) == lhs
10616 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10617 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10618 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10620 rtx_code_label
*label
= gen_label_rtx ();
10621 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10622 do_jump (TREE_OPERAND (rhs
, 1),
10624 value
? 0 : label
, -1);
10625 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10627 do_pending_stack_adjust ();
10628 emit_label (label
);
10632 expand_assignment (lhs
, rhs
, false);
10637 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10639 case REALPART_EXPR
:
10640 op0
= expand_normal (treeop0
);
10641 return read_complex_part (op0
, false);
10643 case IMAGPART_EXPR
:
10644 op0
= expand_normal (treeop0
);
10645 return read_complex_part (op0
, true);
10652 /* Expanded in cfgexpand.c. */
10653 gcc_unreachable ();
10655 case TRY_CATCH_EXPR
:
10657 case EH_FILTER_EXPR
:
10658 case TRY_FINALLY_EXPR
:
10659 /* Lowered by tree-eh.c. */
10660 gcc_unreachable ();
10662 case WITH_CLEANUP_EXPR
:
10663 case CLEANUP_POINT_EXPR
:
10665 case CASE_LABEL_EXPR
:
10670 case COMPOUND_EXPR
:
10671 case PREINCREMENT_EXPR
:
10672 case PREDECREMENT_EXPR
:
10673 case POSTINCREMENT_EXPR
:
10674 case POSTDECREMENT_EXPR
:
10677 case COMPOUND_LITERAL_EXPR
:
10678 /* Lowered by gimplify.c. */
10679 gcc_unreachable ();
10682 /* Function descriptors are not valid except for as
10683 initialization constants, and should not be expanded. */
10684 gcc_unreachable ();
10686 case WITH_SIZE_EXPR
:
10687 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10688 have pulled out the size to use in whatever context it needed. */
10689 return expand_expr_real (treeop0
, original_target
, tmode
,
10690 modifier
, alt_rtl
, inner_reference_p
);
10693 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10697 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10698 signedness of TYPE), possibly returning the result in TARGET. */
10700 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10702 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10703 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10705 /* For constant values, reduce using build_int_cst_type. */
10706 if (CONST_INT_P (exp
))
10708 HOST_WIDE_INT value
= INTVAL (exp
);
10709 tree t
= build_int_cst_type (type
, value
);
10710 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10712 else if (TYPE_UNSIGNED (type
))
10714 enum machine_mode mode
= GET_MODE (exp
);
10715 rtx mask
= immed_wide_int_const
10716 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
10717 return expand_and (mode
, exp
, mask
, target
);
10721 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10722 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10723 exp
, count
, target
, 0);
10724 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10725 exp
, count
, target
, 0);
10729 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10730 when applied to the address of EXP produces an address known to be
10731 aligned more than BIGGEST_ALIGNMENT. */
10734 is_aligning_offset (const_tree offset
, const_tree exp
)
10736 /* Strip off any conversions. */
10737 while (CONVERT_EXPR_P (offset
))
10738 offset
= TREE_OPERAND (offset
, 0);
10740 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10741 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10742 if (TREE_CODE (offset
) != BIT_AND_EXPR
10743 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10744 || compare_tree_int (TREE_OPERAND (offset
, 1),
10745 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10746 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10749 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10750 It must be NEGATE_EXPR. Then strip any more conversions. */
10751 offset
= TREE_OPERAND (offset
, 0);
10752 while (CONVERT_EXPR_P (offset
))
10753 offset
= TREE_OPERAND (offset
, 0);
10755 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10758 offset
= TREE_OPERAND (offset
, 0);
10759 while (CONVERT_EXPR_P (offset
))
10760 offset
= TREE_OPERAND (offset
, 0);
10762 /* This must now be the address of EXP. */
10763 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10766 /* Return the tree node if an ARG corresponds to a string constant or zero
10767 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10768 in bytes within the string that ARG is accessing. The type of the
10769 offset will be `sizetype'. */
10772 string_constant (tree arg
, tree
*ptr_offset
)
10774 tree array
, offset
, lower_bound
;
10777 if (TREE_CODE (arg
) == ADDR_EXPR
)
10779 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10781 *ptr_offset
= size_zero_node
;
10782 return TREE_OPERAND (arg
, 0);
10784 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10786 array
= TREE_OPERAND (arg
, 0);
10787 offset
= size_zero_node
;
10789 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10791 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10792 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10793 if (TREE_CODE (array
) != STRING_CST
10794 && TREE_CODE (array
) != VAR_DECL
)
10797 /* Check if the array has a nonzero lower bound. */
10798 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10799 if (!integer_zerop (lower_bound
))
10801 /* If the offset and base aren't both constants, return 0. */
10802 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10804 if (TREE_CODE (offset
) != INTEGER_CST
)
10806 /* Adjust offset by the lower bound. */
10807 offset
= size_diffop (fold_convert (sizetype
, offset
),
10808 fold_convert (sizetype
, lower_bound
));
10811 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10813 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10814 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10815 if (TREE_CODE (array
) != ADDR_EXPR
)
10817 array
= TREE_OPERAND (array
, 0);
10818 if (TREE_CODE (array
) != STRING_CST
10819 && TREE_CODE (array
) != VAR_DECL
)
10825 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10827 tree arg0
= TREE_OPERAND (arg
, 0);
10828 tree arg1
= TREE_OPERAND (arg
, 1);
10833 if (TREE_CODE (arg0
) == ADDR_EXPR
10834 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10835 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10837 array
= TREE_OPERAND (arg0
, 0);
10840 else if (TREE_CODE (arg1
) == ADDR_EXPR
10841 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10842 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10844 array
= TREE_OPERAND (arg1
, 0);
10853 if (TREE_CODE (array
) == STRING_CST
)
10855 *ptr_offset
= fold_convert (sizetype
, offset
);
10858 else if (TREE_CODE (array
) == VAR_DECL
10859 || TREE_CODE (array
) == CONST_DECL
)
10862 tree init
= ctor_for_folding (array
);
10864 /* Variables initialized to string literals can be handled too. */
10865 if (init
== error_mark_node
10867 || TREE_CODE (init
) != STRING_CST
)
10870 /* Avoid const char foo[4] = "abcde"; */
10871 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10872 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10873 || (length
= TREE_STRING_LENGTH (init
)) <= 0
10874 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10877 /* If variable is bigger than the string literal, OFFSET must be constant
10878 and inside of the bounds of the string literal. */
10879 offset
= fold_convert (sizetype
, offset
);
10880 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10881 && (! tree_fits_uhwi_p (offset
)
10882 || compare_tree_int (offset
, length
) >= 0))
10885 *ptr_offset
= offset
;
10892 /* Generate code to calculate OPS, and exploded expression
10893 using a store-flag instruction and return an rtx for the result.
10894 OPS reflects a comparison.
10896 If TARGET is nonzero, store the result there if convenient.
10898 Return zero if there is no suitable set-flag instruction
10899 available on this machine.
10901 Once expand_expr has been called on the arguments of the comparison,
10902 we are committed to doing the store flag, since it is not safe to
10903 re-evaluate the expression. We emit the store-flag insn by calling
10904 emit_store_flag, but only expand the arguments if we have a reason
10905 to believe that emit_store_flag will be successful. If we think that
10906 it will, but it isn't, we have to simulate the store-flag with a
10907 set/jump/set sequence. */
10910 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10912 enum rtx_code code
;
10913 tree arg0
, arg1
, type
;
10915 enum machine_mode operand_mode
;
10918 rtx subtarget
= target
;
10919 location_t loc
= ops
->location
;
10924 /* Don't crash if the comparison was erroneous. */
10925 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10928 type
= TREE_TYPE (arg0
);
10929 operand_mode
= TYPE_MODE (type
);
10930 unsignedp
= TYPE_UNSIGNED (type
);
10932 /* We won't bother with BLKmode store-flag operations because it would mean
10933 passing a lot of information to emit_store_flag. */
10934 if (operand_mode
== BLKmode
)
10937 /* We won't bother with store-flag operations involving function pointers
10938 when function pointers must be canonicalized before comparisons. */
10939 #ifdef HAVE_canonicalize_funcptr_for_compare
10940 if (HAVE_canonicalize_funcptr_for_compare
10941 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10942 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10944 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10945 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10946 == FUNCTION_TYPE
))))
10953 /* For vector typed comparisons emit code to generate the desired
10954 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10955 expander for this. */
10956 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10958 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10959 tree if_true
= constant_boolean_node (true, ops
->type
);
10960 tree if_false
= constant_boolean_node (false, ops
->type
);
10961 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10964 /* Get the rtx comparison code to use. We know that EXP is a comparison
10965 operation of some type. Some comparisons against 1 and -1 can be
10966 converted to comparisons with zero. Do so here so that the tests
10967 below will be aware that we have a comparison with zero. These
10968 tests will not catch constants in the first operand, but constants
10969 are rarely passed as the first operand. */
10980 if (integer_onep (arg1
))
10981 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10983 code
= unsignedp
? LTU
: LT
;
10986 if (! unsignedp
&& integer_all_onesp (arg1
))
10987 arg1
= integer_zero_node
, code
= LT
;
10989 code
= unsignedp
? LEU
: LE
;
10992 if (! unsignedp
&& integer_all_onesp (arg1
))
10993 arg1
= integer_zero_node
, code
= GE
;
10995 code
= unsignedp
? GTU
: GT
;
10998 if (integer_onep (arg1
))
10999 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
11001 code
= unsignedp
? GEU
: GE
;
11004 case UNORDERED_EXPR
:
11030 gcc_unreachable ();
11033 /* Put a constant second. */
11034 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11035 || TREE_CODE (arg0
) == FIXED_CST
)
11037 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
11038 code
= swap_condition (code
);
11041 /* If this is an equality or inequality test of a single bit, we can
11042 do this by shifting the bit being tested to the low-order bit and
11043 masking the result with the constant 1. If the condition was EQ,
11044 we xor it with 1. This does not require an scc insn and is faster
11045 than an scc insn even if we have it.
11047 The code to make this transformation was moved into fold_single_bit_test,
11048 so we just call into the folder and expand its result. */
11050 if ((code
== NE
|| code
== EQ
)
11051 && integer_zerop (arg1
)
11052 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11054 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11056 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11058 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11059 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11060 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11061 gimple_assign_rhs1 (srcstmt
),
11062 gimple_assign_rhs2 (srcstmt
));
11063 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11065 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11069 if (! get_subtarget (target
)
11070 || GET_MODE (subtarget
) != operand_mode
)
11073 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11076 target
= gen_reg_rtx (mode
);
11078 /* Try a cstore if possible. */
11079 return emit_store_flag_force (target
, code
, op0
, op1
,
11080 operand_mode
, unsignedp
,
11081 (TYPE_PRECISION (ops
->type
) == 1
11082 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11086 /* Stubs in case we haven't got a casesi insn. */
11087 #ifndef HAVE_casesi
11088 # define HAVE_casesi 0
11089 # define gen_casesi(a, b, c, d, e) (0)
11090 # define CODE_FOR_casesi CODE_FOR_nothing
11093 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11094 0 otherwise (i.e. if there is no casesi instruction).
11096 DEFAULT_PROBABILITY is the probability of jumping to the default
11099 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11100 rtx table_label
, rtx default_label
, rtx fallback_label
,
11101 int default_probability
)
11103 struct expand_operand ops
[5];
11104 enum machine_mode index_mode
= SImode
;
11105 rtx op1
, op2
, index
;
11110 /* Convert the index to SImode. */
11111 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11113 enum machine_mode omode
= TYPE_MODE (index_type
);
11114 rtx rangertx
= expand_normal (range
);
11116 /* We must handle the endpoints in the original mode. */
11117 index_expr
= build2 (MINUS_EXPR
, index_type
,
11118 index_expr
, minval
);
11119 minval
= integer_zero_node
;
11120 index
= expand_normal (index_expr
);
11122 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11123 omode
, 1, default_label
,
11124 default_probability
);
11125 /* Now we can safely truncate. */
11126 index
= convert_to_mode (index_mode
, index
, 0);
11130 if (TYPE_MODE (index_type
) != index_mode
)
11132 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11133 index_expr
= fold_convert (index_type
, index_expr
);
11136 index
= expand_normal (index_expr
);
11139 do_pending_stack_adjust ();
11141 op1
= expand_normal (minval
);
11142 op2
= expand_normal (range
);
11144 create_input_operand (&ops
[0], index
, index_mode
);
11145 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11146 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11147 create_fixed_operand (&ops
[3], table_label
);
11148 create_fixed_operand (&ops
[4], (default_label
11150 : fallback_label
));
11151 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
11155 /* Attempt to generate a tablejump instruction; same concept. */
11156 #ifndef HAVE_tablejump
11157 #define HAVE_tablejump 0
11158 #define gen_tablejump(x, y) (0)
11161 /* Subroutine of the next function.
11163 INDEX is the value being switched on, with the lowest value
11164 in the table already subtracted.
11165 MODE is its expected mode (needed if INDEX is constant).
11166 RANGE is the length of the jump table.
11167 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11169 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11170 index value is out of range.
11171 DEFAULT_PROBABILITY is the probability of jumping to
11172 the default label. */
11175 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
11176 rtx default_label
, int default_probability
)
11180 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11181 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11183 /* Do an unsigned comparison (in the proper mode) between the index
11184 expression and the value which represents the length of the range.
11185 Since we just finished subtracting the lower bound of the range
11186 from the index expression, this comparison allows us to simultaneously
11187 check that the original index expression value is both greater than
11188 or equal to the minimum value of the range and less than or equal to
11189 the maximum value of the range. */
11192 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11193 default_label
, default_probability
);
11196 /* If index is in range, it must fit in Pmode.
11197 Convert to Pmode so we can index with it. */
11199 index
= convert_to_mode (Pmode
, index
, 1);
11201 /* Don't let a MEM slip through, because then INDEX that comes
11202 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11203 and break_out_memory_refs will go to work on it and mess it up. */
11204 #ifdef PIC_CASE_VECTOR_ADDRESS
11205 if (flag_pic
&& !REG_P (index
))
11206 index
= copy_to_mode_reg (Pmode
, index
);
11209 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11210 GET_MODE_SIZE, because this indicates how large insns are. The other
11211 uses should all be Pmode, because they are addresses. This code
11212 could fail if addresses and insns are not the same size. */
11213 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11214 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11216 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11217 gen_rtx_LABEL_REF (Pmode
, table_label
));
11219 #ifdef PIC_CASE_VECTOR_ADDRESS
11221 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11224 index
= memory_address (CASE_VECTOR_MODE
, index
);
11225 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11226 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11227 convert_move (temp
, vector
, 0);
11229 emit_jump_insn (gen_tablejump (temp
, table_label
));
11231 /* If we are generating PIC code or if the table is PC-relative, the
11232 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11233 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11238 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11239 rtx table_label
, rtx default_label
, int default_probability
)
11243 if (! HAVE_tablejump
)
11246 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11247 fold_convert (index_type
, index_expr
),
11248 fold_convert (index_type
, minval
));
11249 index
= expand_normal (index_expr
);
11250 do_pending_stack_adjust ();
11252 do_tablejump (index
, TYPE_MODE (index_type
),
11253 convert_modes (TYPE_MODE (index_type
),
11254 TYPE_MODE (TREE_TYPE (range
)),
11255 expand_normal (range
),
11256 TYPE_UNSIGNED (TREE_TYPE (range
))),
11257 table_label
, default_label
, default_probability
);
11261 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11263 const_vector_from_tree (tree exp
)
11269 enum machine_mode inner
, mode
;
11271 mode
= TYPE_MODE (TREE_TYPE (exp
));
11273 if (initializer_zerop (exp
))
11274 return CONST0_RTX (mode
);
11276 units
= GET_MODE_NUNITS (mode
);
11277 inner
= GET_MODE_INNER (mode
);
11279 v
= rtvec_alloc (units
);
11281 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11283 elt
= VECTOR_CST_ELT (exp
, i
);
11285 if (TREE_CODE (elt
) == REAL_CST
)
11286 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11288 else if (TREE_CODE (elt
) == FIXED_CST
)
11289 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11292 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11295 return gen_rtx_CONST_VECTOR (mode
, v
);
11298 /* Build a decl for a personality function given a language prefix. */
11301 build_personality_function (const char *lang
)
11303 const char *unwind_and_version
;
11307 switch (targetm_common
.except_unwind_info (&global_options
))
11312 unwind_and_version
= "_sj0";
11316 unwind_and_version
= "_v0";
11319 unwind_and_version
= "_seh0";
11322 gcc_unreachable ();
11325 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11327 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11328 long_long_unsigned_type_node
,
11329 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11330 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11331 get_identifier (name
), type
);
11332 DECL_ARTIFICIAL (decl
) = 1;
11333 DECL_EXTERNAL (decl
) = 1;
11334 TREE_PUBLIC (decl
) = 1;
11336 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11337 are the flags assigned by targetm.encode_section_info. */
11338 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11343 /* Extracts the personality function of DECL and returns the corresponding
11347 get_personality_function (tree decl
)
11349 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11350 enum eh_personality_kind pk
;
11352 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11353 if (pk
== eh_personality_none
)
11357 && pk
== eh_personality_any
)
11358 personality
= lang_hooks
.eh_personality ();
11360 if (pk
== eh_personality_lang
)
11361 gcc_assert (personality
!= NULL_TREE
);
11363 return XEXP (DECL_RTL (personality
), 0);
11366 #include "gt-expr.h"