1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
4 2012 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
31 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "insn-attr.h"
36 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
43 #include "typeclass.h"
45 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "tree-pass.h"
50 #include "tree-flow.h"
52 #include "common/common-target.h"
55 #include "diagnostic.h"
56 #include "ssaexpand.h"
57 #include "target-globals.h"
60 /* Decide whether a function's arguments should be processed
61 from first to last or from last to first.
63 They should if the stack and args grow in opposite directions, but
64 only if we have push insns. */
68 #ifndef PUSH_ARGS_REVERSED
69 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
70 #define PUSH_ARGS_REVERSED /* If it's last to first. */
76 #ifndef STACK_PUSH_CODE
77 #ifdef STACK_GROWS_DOWNWARD
78 #define STACK_PUSH_CODE PRE_DEC
80 #define STACK_PUSH_CODE PRE_INC
85 /* If this is nonzero, we do not bother generating VOLATILE
86 around volatile memory references, and we are willing to
87 output indirect addresses. If cse is to follow, we reject
88 indirect addresses so a useful potential cse is generated;
89 if it is used only once, instruction combination will produce
90 the same indirect address eventually. */
93 /* This structure is used by move_by_pieces to describe the move to
95 struct move_by_pieces_d
104 int explicit_inc_from
;
105 unsigned HOST_WIDE_INT len
;
106 HOST_WIDE_INT offset
;
110 /* This structure is used by store_by_pieces to describe the clear to
113 struct store_by_pieces_d
119 unsigned HOST_WIDE_INT len
;
120 HOST_WIDE_INT offset
;
121 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
);
126 static void move_by_pieces_1 (rtx (*) (rtx
, ...), enum machine_mode
,
127 struct move_by_pieces_d
*);
128 static bool block_move_libcall_safe_for_call_parm (void);
129 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
);
130 static tree
emit_block_move_libcall_fn (int);
131 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
132 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, enum machine_mode
);
133 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
134 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
135 static void store_by_pieces_2 (rtx (*) (rtx
, ...), enum machine_mode
,
136 struct store_by_pieces_d
*);
137 static tree
clear_storage_libcall_fn (int);
138 static rtx
compress_float_constant (rtx
, rtx
);
139 static rtx
get_subtarget (rtx
);
140 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
141 HOST_WIDE_INT
, enum machine_mode
,
142 tree
, tree
, int, alias_set_type
);
143 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
144 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
145 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
147 tree
, tree
, alias_set_type
, bool);
149 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
151 static int is_aligning_offset (const_tree
, const_tree
);
152 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
153 enum expand_modifier
);
154 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
155 static rtx
do_store_flag (sepops
, rtx
, enum machine_mode
);
157 static void emit_single_push_insn (enum machine_mode
, rtx
, tree
);
159 static void do_tablejump (rtx
, enum machine_mode
, rtx
, rtx
, rtx
);
160 static rtx
const_vector_from_tree (tree
);
161 static void write_complex_part (rtx
, rtx
, bool);
163 /* This macro is used to determine whether move_by_pieces should be called
164 to perform a structure copy. */
165 #ifndef MOVE_BY_PIECES_P
166 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
167 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
168 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
171 /* This macro is used to determine whether clear_by_pieces should be
172 called to clear storage. */
173 #ifndef CLEAR_BY_PIECES_P
174 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
175 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
176 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
179 /* This macro is used to determine whether store_by_pieces should be
180 called to "memset" storage with byte values other than zero. */
181 #ifndef SET_BY_PIECES_P
182 #define SET_BY_PIECES_P(SIZE, ALIGN) \
183 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
184 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
187 /* This macro is used to determine whether store_by_pieces should be
188 called to "memcpy" storage when the source is a constant string. */
189 #ifndef STORE_BY_PIECES_P
190 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
191 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
192 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
195 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
197 #ifndef SLOW_UNALIGNED_ACCESS
198 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
201 /* This is run to set up which modes can be used
202 directly in memory and to initialize the block move optab. It is run
203 at the beginning of compilation and when the target is reinitialized. */
206 init_expr_target (void)
209 enum machine_mode mode
;
214 /* Try indexing by frame ptr and try by stack ptr.
215 It is known that on the Convex the stack ptr isn't a valid index.
216 With luck, one or the other is valid on any machine. */
217 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
218 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
220 /* A scratch register we can modify in-place below to avoid
221 useless RTL allocations. */
222 reg
= gen_rtx_REG (VOIDmode
, -1);
224 insn
= rtx_alloc (INSN
);
225 pat
= gen_rtx_SET (VOIDmode
, NULL_RTX
, NULL_RTX
);
226 PATTERN (insn
) = pat
;
228 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
229 mode
= (enum machine_mode
) ((int) mode
+ 1))
233 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
234 PUT_MODE (mem
, mode
);
235 PUT_MODE (mem1
, mode
);
236 PUT_MODE (reg
, mode
);
238 /* See if there is some register that can be used in this mode and
239 directly loaded or stored from memory. */
241 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
242 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
243 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
246 if (! HARD_REGNO_MODE_OK (regno
, mode
))
249 SET_REGNO (reg
, regno
);
252 SET_DEST (pat
) = reg
;
253 if (recog (pat
, insn
, &num_clobbers
) >= 0)
254 direct_load
[(int) mode
] = 1;
256 SET_SRC (pat
) = mem1
;
257 SET_DEST (pat
) = reg
;
258 if (recog (pat
, insn
, &num_clobbers
) >= 0)
259 direct_load
[(int) mode
] = 1;
262 SET_DEST (pat
) = mem
;
263 if (recog (pat
, insn
, &num_clobbers
) >= 0)
264 direct_store
[(int) mode
] = 1;
267 SET_DEST (pat
) = mem1
;
268 if (recog (pat
, insn
, &num_clobbers
) >= 0)
269 direct_store
[(int) mode
] = 1;
273 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
275 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
276 mode
= GET_MODE_WIDER_MODE (mode
))
278 enum machine_mode srcmode
;
279 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
280 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
284 ic
= can_extend_p (mode
, srcmode
, 0);
285 if (ic
== CODE_FOR_nothing
)
288 PUT_MODE (mem
, srcmode
);
290 if (insn_operand_matches (ic
, 1, mem
))
291 float_extend_from_mem
[mode
][srcmode
] = true;
296 /* This is run at the start of compiling a function. */
301 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
304 /* Copy data from FROM to TO, where the machine modes are not the same.
305 Both modes may be integer, or both may be floating, or both may be
307 UNSIGNEDP should be nonzero if FROM is an unsigned type.
308 This causes zero-extension instead of sign-extension. */
311 convert_move (rtx to
, rtx from
, int unsignedp
)
313 enum machine_mode to_mode
= GET_MODE (to
);
314 enum machine_mode from_mode
= GET_MODE (from
);
315 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
316 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
320 /* rtx code for making an equivalent value. */
321 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
322 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
325 gcc_assert (to_real
== from_real
);
326 gcc_assert (to_mode
!= BLKmode
);
327 gcc_assert (from_mode
!= BLKmode
);
329 /* If the source and destination are already the same, then there's
334 /* If FROM is a SUBREG that indicates that we have already done at least
335 the required extension, strip it. We don't handle such SUBREGs as
338 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
339 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
340 >= GET_MODE_PRECISION (to_mode
))
341 && SUBREG_PROMOTED_UNSIGNED_P (from
) == unsignedp
)
342 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
344 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
346 if (to_mode
== from_mode
347 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
349 emit_move_insn (to
, from
);
353 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
355 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
357 if (VECTOR_MODE_P (to_mode
))
358 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
360 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
362 emit_move_insn (to
, from
);
366 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
368 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
369 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
378 gcc_assert ((GET_MODE_PRECISION (from_mode
)
379 != GET_MODE_PRECISION (to_mode
))
380 || (DECIMAL_FLOAT_MODE_P (from_mode
)
381 != DECIMAL_FLOAT_MODE_P (to_mode
)));
383 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
384 /* Conversion between decimal float and binary float, same size. */
385 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
386 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
391 /* Try converting directly if the insn is supported. */
393 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
394 if (code
!= CODE_FOR_nothing
)
396 emit_unop_insn (code
, to
, from
,
397 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
401 /* Otherwise use a libcall. */
402 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
404 /* Is this conversion implemented yet? */
405 gcc_assert (libcall
);
408 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
410 insns
= get_insns ();
412 emit_libcall_block (insns
, to
, value
,
413 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
415 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
419 /* Handle pointer conversion. */ /* SPEE 900220. */
420 /* Targets are expected to provide conversion insns between PxImode and
421 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
422 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
424 enum machine_mode full_mode
425 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
427 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
428 != CODE_FOR_nothing
);
430 if (full_mode
!= from_mode
)
431 from
= convert_to_mode (full_mode
, from
, unsignedp
);
432 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
436 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
439 enum machine_mode full_mode
440 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
441 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
442 enum insn_code icode
;
444 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
445 gcc_assert (icode
!= CODE_FOR_nothing
);
447 if (to_mode
== full_mode
)
449 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
453 new_from
= gen_reg_rtx (full_mode
);
454 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
456 /* else proceed to integer conversions below. */
457 from_mode
= full_mode
;
461 /* Make sure both are fixed-point modes or both are not. */
462 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
463 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
464 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
466 /* If we widen from_mode to to_mode and they are in the same class,
467 we won't saturate the result.
468 Otherwise, always saturate the result to play safe. */
469 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
470 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
471 expand_fixed_convert (to
, from
, 0, 0);
473 expand_fixed_convert (to
, from
, 0, 1);
477 /* Now both modes are integers. */
479 /* Handle expanding beyond a word. */
480 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
481 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
488 enum machine_mode lowpart_mode
;
489 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
491 /* Try converting directly if the insn is supported. */
492 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
495 /* If FROM is a SUBREG, put it into a register. Do this
496 so that we always generate the same set of insns for
497 better cse'ing; if an intermediate assignment occurred,
498 we won't be doing the operation directly on the SUBREG. */
499 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
500 from
= force_reg (from_mode
, from
);
501 emit_unop_insn (code
, to
, from
, equiv_code
);
504 /* Next, try converting via full word. */
505 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
506 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
507 != CODE_FOR_nothing
))
509 rtx word_to
= gen_reg_rtx (word_mode
);
512 if (reg_overlap_mentioned_p (to
, from
))
513 from
= force_reg (from_mode
, from
);
516 convert_move (word_to
, from
, unsignedp
);
517 emit_unop_insn (code
, to
, word_to
, equiv_code
);
521 /* No special multiword conversion insn; do it by hand. */
524 /* Since we will turn this into a no conflict block, we must ensure
525 that the source does not overlap the target. */
527 if (reg_overlap_mentioned_p (to
, from
))
528 from
= force_reg (from_mode
, from
);
530 /* Get a copy of FROM widened to a word, if necessary. */
531 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
532 lowpart_mode
= word_mode
;
534 lowpart_mode
= from_mode
;
536 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
538 lowpart
= gen_lowpart (lowpart_mode
, to
);
539 emit_move_insn (lowpart
, lowfrom
);
541 /* Compute the value to put in each remaining word. */
543 fill_value
= const0_rtx
;
545 fill_value
= emit_store_flag (gen_reg_rtx (word_mode
),
546 LT
, lowfrom
, const0_rtx
,
549 /* Fill the remaining words. */
550 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
552 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
553 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
555 gcc_assert (subword
);
557 if (fill_value
!= subword
)
558 emit_move_insn (subword
, fill_value
);
561 insns
= get_insns ();
568 /* Truncating multi-word to a word or less. */
569 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
570 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
573 && ! MEM_VOLATILE_P (from
)
574 && direct_load
[(int) to_mode
]
575 && ! mode_dependent_address_p (XEXP (from
, 0)))
577 || GET_CODE (from
) == SUBREG
))
578 from
= force_reg (from_mode
, from
);
579 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
583 /* Now follow all the conversions between integers
584 no more than a word long. */
586 /* For truncation, usually we can just refer to FROM in a narrower mode. */
587 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
588 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
591 && ! MEM_VOLATILE_P (from
)
592 && direct_load
[(int) to_mode
]
593 && ! mode_dependent_address_p (XEXP (from
, 0)))
595 || GET_CODE (from
) == SUBREG
))
596 from
= force_reg (from_mode
, from
);
597 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
598 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
599 from
= copy_to_reg (from
);
600 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
604 /* Handle extension. */
605 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
607 /* Convert directly if that works. */
608 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
611 emit_unop_insn (code
, to
, from
, equiv_code
);
616 enum machine_mode intermediate
;
620 /* Search for a mode to convert via. */
621 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
622 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
623 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
625 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
626 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
627 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
628 != CODE_FOR_nothing
))
630 convert_move (to
, convert_to_mode (intermediate
, from
,
631 unsignedp
), unsignedp
);
635 /* No suitable intermediate mode.
636 Generate what we need with shifts. */
637 shift_amount
= (GET_MODE_PRECISION (to_mode
)
638 - GET_MODE_PRECISION (from_mode
));
639 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
640 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
642 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
645 emit_move_insn (to
, tmp
);
650 /* Support special truncate insns for certain modes. */
651 if (convert_optab_handler (trunc_optab
, to_mode
,
652 from_mode
) != CODE_FOR_nothing
)
654 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
659 /* Handle truncation of volatile memrefs, and so on;
660 the things that couldn't be truncated directly,
661 and for which there was no special instruction.
663 ??? Code above formerly short-circuited this, for most integer
664 mode pairs, with a force_reg in from_mode followed by a recursive
665 call to this routine. Appears always to have been wrong. */
666 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
668 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
669 emit_move_insn (to
, temp
);
673 /* Mode combination is not recognized. */
677 /* Return an rtx for a value that would result
678 from converting X to mode MODE.
679 Both X and MODE may be floating, or both integer.
680 UNSIGNEDP is nonzero if X is an unsigned value.
681 This can be done by referring to a part of X in place
682 or by copying to a new temporary with conversion. */
685 convert_to_mode (enum machine_mode mode
, rtx x
, int unsignedp
)
687 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
690 /* Return an rtx for a value that would result
691 from converting X from mode OLDMODE to mode MODE.
692 Both modes may be floating, or both integer.
693 UNSIGNEDP is nonzero if X is an unsigned value.
695 This can be done by referring to a part of X in place
696 or by copying to a new temporary with conversion.
698 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
701 convert_modes (enum machine_mode mode
, enum machine_mode oldmode
, rtx x
, int unsignedp
)
705 /* If FROM is a SUBREG that indicates that we have already done at least
706 the required extension, strip it. */
708 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
709 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
710 && SUBREG_PROMOTED_UNSIGNED_P (x
) == unsignedp
)
711 x
= gen_lowpart (mode
, x
);
713 if (GET_MODE (x
) != VOIDmode
)
714 oldmode
= GET_MODE (x
);
719 /* There is one case that we must handle specially: If we are converting
720 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
721 we are to interpret the constant as unsigned, gen_lowpart will do
722 the wrong if the constant appears negative. What we want to do is
723 make the high-order word of the constant zero, not all ones. */
725 if (unsignedp
&& GET_MODE_CLASS (mode
) == MODE_INT
726 && GET_MODE_BITSIZE (mode
) == 2 * HOST_BITS_PER_WIDE_INT
727 && CONST_INT_P (x
) && INTVAL (x
) < 0)
729 double_int val
= uhwi_to_double_int (INTVAL (x
));
731 /* We need to zero extend VAL. */
732 if (oldmode
!= VOIDmode
)
733 val
= double_int_zext (val
, GET_MODE_BITSIZE (oldmode
));
735 return immed_double_int_const (val
, mode
);
738 /* We can do this with a gen_lowpart if both desired and current modes
739 are integer, and this is either a constant integer, a register, or a
740 non-volatile MEM. Except for the constant case where MODE is no
741 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
744 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
)
745 || (GET_MODE_CLASS (mode
) == MODE_INT
746 && GET_MODE_CLASS (oldmode
) == MODE_INT
747 && (GET_CODE (x
) == CONST_DOUBLE
748 || (GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
749 && ((MEM_P (x
) && ! MEM_VOLATILE_P (x
)
750 && direct_load
[(int) mode
])
752 && (! HARD_REGISTER_P (x
)
753 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
754 && TRULY_NOOP_TRUNCATION_MODES_P (mode
,
757 /* ?? If we don't know OLDMODE, we have to assume here that
758 X does not need sign- or zero-extension. This may not be
759 the case, but it's the best we can do. */
760 if (CONST_INT_P (x
) && oldmode
!= VOIDmode
761 && GET_MODE_PRECISION (mode
) > GET_MODE_PRECISION (oldmode
))
763 HOST_WIDE_INT val
= INTVAL (x
);
765 /* We must sign or zero-extend in this case. Start by
766 zero-extending, then sign extend if we need to. */
767 val
&= GET_MODE_MASK (oldmode
);
769 && val_signbit_known_set_p (oldmode
, val
))
770 val
|= ~GET_MODE_MASK (oldmode
);
772 return gen_int_mode (val
, mode
);
775 return gen_lowpart (mode
, x
);
778 /* Converting from integer constant into mode is always equivalent to an
780 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
782 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
783 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
786 temp
= gen_reg_rtx (mode
);
787 convert_move (temp
, x
, unsignedp
);
791 /* Return the largest alignment we can use for doing a move (or store)
792 of MAX_PIECES. ALIGN is the largest alignment we could use. */
795 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
797 enum machine_mode tmode
;
799 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
800 if (align
>= GET_MODE_ALIGNMENT (tmode
))
801 align
= GET_MODE_ALIGNMENT (tmode
);
804 enum machine_mode tmode
, xmode
;
806 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
808 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
809 if (GET_MODE_SIZE (tmode
) > max_pieces
810 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
813 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
819 /* Return the widest integer mode no wider than SIZE. If no such mode
820 can be found, return VOIDmode. */
822 static enum machine_mode
823 widest_int_mode_for_size (unsigned int size
)
825 enum machine_mode tmode
, mode
= VOIDmode
;
827 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
828 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
829 if (GET_MODE_SIZE (tmode
) < size
)
835 /* STORE_MAX_PIECES is the number of bytes at a time that we can
836 store efficiently. Due to internal GCC limitations, this is
837 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
838 for an immediate constant. */
840 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
842 /* Determine whether the LEN bytes can be moved by using several move
843 instructions. Return nonzero if a call to move_by_pieces should
847 can_move_by_pieces (unsigned HOST_WIDE_INT len
,
848 unsigned int align ATTRIBUTE_UNUSED
)
850 return MOVE_BY_PIECES_P (len
, align
);
853 /* Generate several move instructions to copy LEN bytes from block FROM to
854 block TO. (These are MEM rtx's with BLKmode).
856 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
857 used to push FROM to the stack.
859 ALIGN is maximum stack alignment we can assume.
861 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
862 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
866 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
867 unsigned int align
, int endp
)
869 struct move_by_pieces_d data
;
870 enum machine_mode to_addr_mode
, from_addr_mode
871 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (from
));
872 rtx to_addr
, from_addr
= XEXP (from
, 0);
873 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
874 enum insn_code icode
;
876 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
879 data
.from_addr
= from_addr
;
882 to_addr_mode
= targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (to
));
883 to_addr
= XEXP (to
, 0);
886 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
887 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
889 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
893 to_addr_mode
= VOIDmode
;
897 #ifdef STACK_GROWS_DOWNWARD
903 data
.to_addr
= to_addr
;
906 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
907 || GET_CODE (from_addr
) == POST_INC
908 || GET_CODE (from_addr
) == POST_DEC
);
910 data
.explicit_inc_from
= 0;
911 data
.explicit_inc_to
= 0;
912 if (data
.reverse
) data
.offset
= len
;
915 /* If copying requires more than two move insns,
916 copy addresses to registers (to make displacements shorter)
917 and use post-increment if available. */
918 if (!(data
.autinc_from
&& data
.autinc_to
)
919 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
921 /* Find the mode of the largest move...
922 MODE might not be used depending on the definitions of the
923 USE_* macros below. */
924 enum machine_mode mode ATTRIBUTE_UNUSED
925 = widest_int_mode_for_size (max_size
);
927 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
929 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
930 plus_constant (from_addr_mode
,
932 data
.autinc_from
= 1;
933 data
.explicit_inc_from
= -1;
935 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
937 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
938 data
.autinc_from
= 1;
939 data
.explicit_inc_from
= 1;
941 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
942 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
943 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
945 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
946 plus_constant (to_addr_mode
,
949 data
.explicit_inc_to
= -1;
951 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
953 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
955 data
.explicit_inc_to
= 1;
957 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
958 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
961 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
963 /* First move what we can in the largest integer mode, then go to
964 successively smaller modes. */
968 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
970 if (mode
== VOIDmode
)
973 icode
= optab_handler (mov_optab
, mode
);
974 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
975 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
977 max_size
= GET_MODE_SIZE (mode
);
980 /* The code above should have handled everything. */
981 gcc_assert (!data
.len
);
987 gcc_assert (!data
.reverse
);
992 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
993 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
995 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
996 plus_constant (to_addr_mode
,
1000 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
1007 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1015 /* Return number of insns required to move L bytes by pieces.
1016 ALIGN (in bits) is maximum alignment we can assume. */
1018 unsigned HOST_WIDE_INT
1019 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1020 unsigned int max_size
)
1022 unsigned HOST_WIDE_INT n_insns
= 0;
1024 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1026 while (max_size
> 1)
1028 enum machine_mode mode
;
1029 enum insn_code icode
;
1031 mode
= widest_int_mode_for_size (max_size
);
1033 if (mode
== VOIDmode
)
1036 icode
= optab_handler (mov_optab
, mode
);
1037 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1038 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1040 max_size
= GET_MODE_SIZE (mode
);
1047 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1048 with move instructions for mode MODE. GENFUN is the gen_... function
1049 to make a move insn for that mode. DATA has all the other info. */
1052 move_by_pieces_1 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
1053 struct move_by_pieces_d
*data
)
1055 unsigned int size
= GET_MODE_SIZE (mode
);
1056 rtx to1
= NULL_RTX
, from1
;
1058 while (data
->len
>= size
)
1061 data
->offset
-= size
;
1065 if (data
->autinc_to
)
1066 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1069 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1072 if (data
->autinc_from
)
1073 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1076 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1078 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1079 emit_insn (gen_add2_insn (data
->to_addr
,
1080 GEN_INT (-(HOST_WIDE_INT
)size
)));
1081 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1082 emit_insn (gen_add2_insn (data
->from_addr
,
1083 GEN_INT (-(HOST_WIDE_INT
)size
)));
1086 emit_insn ((*genfun
) (to1
, from1
));
1089 #ifdef PUSH_ROUNDING
1090 emit_single_push_insn (mode
, from1
, NULL
);
1096 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1097 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
1098 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1099 emit_insn (gen_add2_insn (data
->from_addr
, GEN_INT (size
)));
1101 if (! data
->reverse
)
1102 data
->offset
+= size
;
1108 /* Emit code to move a block Y to a block X. This may be done with
1109 string-move instructions, with multiple scalar move instructions,
1110 or with a library call.
1112 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1113 SIZE is an rtx that says how long they are.
1114 ALIGN is the maximum alignment we can assume they have.
1115 METHOD describes what kind of copy this is, and what mechanisms may be used.
1117 Return the address of the new block, if memcpy is called and returns it,
1121 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1122 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
1129 if (CONST_INT_P (size
)
1130 && INTVAL (size
) == 0)
1135 case BLOCK_OP_NORMAL
:
1136 case BLOCK_OP_TAILCALL
:
1137 may_use_call
= true;
1140 case BLOCK_OP_CALL_PARM
:
1141 may_use_call
= block_move_libcall_safe_for_call_parm ();
1143 /* Make inhibit_defer_pop nonzero around the library call
1144 to force it to pop the arguments right away. */
1148 case BLOCK_OP_NO_LIBCALL
:
1149 may_use_call
= false;
1156 gcc_assert (MEM_P (x
) && MEM_P (y
));
1157 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1158 gcc_assert (align
>= BITS_PER_UNIT
);
1160 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1161 block copy is more efficient for other large modes, e.g. DCmode. */
1162 x
= adjust_address (x
, BLKmode
, 0);
1163 y
= adjust_address (y
, BLKmode
, 0);
1165 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1166 can be incorrect is coming from __builtin_memcpy. */
1167 if (CONST_INT_P (size
))
1169 x
= shallow_copy_rtx (x
);
1170 y
= shallow_copy_rtx (y
);
1171 set_mem_size (x
, INTVAL (size
));
1172 set_mem_size (y
, INTVAL (size
));
1175 if (CONST_INT_P (size
) && MOVE_BY_PIECES_P (INTVAL (size
), align
))
1176 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1177 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1178 expected_align
, expected_size
))
1180 else if (may_use_call
1181 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1182 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1184 /* Since x and y are passed to a libcall, mark the corresponding
1185 tree EXPR as addressable. */
1186 tree y_expr
= MEM_EXPR (y
);
1187 tree x_expr
= MEM_EXPR (x
);
1189 mark_addressable (y_expr
);
1191 mark_addressable (x_expr
);
1192 retval
= emit_block_move_via_libcall (x
, y
, size
,
1193 method
== BLOCK_OP_TAILCALL
);
1197 emit_block_move_via_loop (x
, y
, size
, align
);
1199 if (method
== BLOCK_OP_CALL_PARM
)
1206 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1208 return emit_block_move_hints (x
, y
, size
, method
, 0, -1);
1211 /* A subroutine of emit_block_move. Returns true if calling the
1212 block move libcall will not clobber any parameters which may have
1213 already been placed on the stack. */
1216 block_move_libcall_safe_for_call_parm (void)
1218 #if defined (REG_PARM_STACK_SPACE)
1222 /* If arguments are pushed on the stack, then they're safe. */
1226 /* If registers go on the stack anyway, any argument is sure to clobber
1227 an outgoing argument. */
1228 #if defined (REG_PARM_STACK_SPACE)
1229 fn
= emit_block_move_libcall_fn (false);
1230 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1231 depend on its argument. */
1233 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1234 && REG_PARM_STACK_SPACE (fn
) != 0)
1238 /* If any argument goes in memory, then it might clobber an outgoing
1241 CUMULATIVE_ARGS args_so_far_v
;
1242 cumulative_args_t args_so_far
;
1245 fn
= emit_block_move_libcall_fn (false);
1246 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1247 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1249 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1250 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1252 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1253 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1255 if (!tmp
|| !REG_P (tmp
))
1257 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1259 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1266 /* A subroutine of emit_block_move. Expand a movmem pattern;
1267 return true if successful. */
1270 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1271 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
1273 int save_volatile_ok
= volatile_ok
;
1274 enum machine_mode mode
;
1276 if (expected_align
< align
)
1277 expected_align
= align
;
1279 /* Since this is a move insn, we don't care about volatility. */
1282 /* Try the most limited insn first, because there's no point
1283 including more than one in the machine description unless
1284 the more limited one has some advantage. */
1286 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1287 mode
= GET_MODE_WIDER_MODE (mode
))
1289 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1291 if (code
!= CODE_FOR_nothing
1292 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1293 here because if SIZE is less than the mode mask, as it is
1294 returned by the macro, it will definitely be less than the
1295 actual mode mask. */
1296 && ((CONST_INT_P (size
)
1297 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1298 <= (GET_MODE_MASK (mode
) >> 1)))
1299 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
1301 struct expand_operand ops
[6];
1304 /* ??? When called via emit_block_move_for_call, it'd be
1305 nice if there were some way to inform the backend, so
1306 that it doesn't fail the expansion because it thinks
1307 emitting the libcall would be more efficient. */
1308 nops
= insn_data
[(int) code
].n_generator_args
;
1309 gcc_assert (nops
== 4 || nops
== 6);
1311 create_fixed_operand (&ops
[0], x
);
1312 create_fixed_operand (&ops
[1], y
);
1313 /* The check above guarantees that this size conversion is valid. */
1314 create_convert_operand_to (&ops
[2], size
, mode
, true);
1315 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1318 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1319 create_integer_operand (&ops
[5], expected_size
);
1321 if (maybe_expand_insn (code
, nops
, ops
))
1323 volatile_ok
= save_volatile_ok
;
1329 volatile_ok
= save_volatile_ok
;
1333 /* A subroutine of emit_block_move. Expand a call to memcpy.
1334 Return the return value from memcpy, 0 otherwise. */
1337 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1339 rtx dst_addr
, src_addr
;
1340 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1341 enum machine_mode size_mode
;
1344 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1345 pseudos. We can then place those new pseudos into a VAR_DECL and
1348 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1349 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1351 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1352 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1354 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1355 src_tree
= make_tree (ptr_type_node
, src_addr
);
1357 size_mode
= TYPE_MODE (sizetype
);
1359 size
= convert_to_mode (size_mode
, size
, 1);
1360 size
= copy_to_mode_reg (size_mode
, size
);
1362 /* It is incorrect to use the libcall calling conventions to call
1363 memcpy in this context. This could be a user call to memcpy and
1364 the user may wish to examine the return value from memcpy. For
1365 targets where libcalls and normal calls have different conventions
1366 for returning pointers, we could end up generating incorrect code. */
1368 size_tree
= make_tree (sizetype
, size
);
1370 fn
= emit_block_move_libcall_fn (true);
1371 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1372 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1374 retval
= expand_normal (call_expr
);
1379 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1380 for the function we use for block copies. */
1382 static GTY(()) tree block_move_fn
;
1385 init_block_move_fn (const char *asmspec
)
1391 fn
= get_identifier ("memcpy");
1392 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1393 const_ptr_type_node
, sizetype
,
1396 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1397 DECL_EXTERNAL (fn
) = 1;
1398 TREE_PUBLIC (fn
) = 1;
1399 DECL_ARTIFICIAL (fn
) = 1;
1400 TREE_NOTHROW (fn
) = 1;
1401 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1402 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1408 set_user_assembler_name (block_move_fn
, asmspec
);
1412 emit_block_move_libcall_fn (int for_call
)
1414 static bool emitted_extern
;
1417 init_block_move_fn (NULL
);
1419 if (for_call
&& !emitted_extern
)
1421 emitted_extern
= true;
1422 make_decl_rtl (block_move_fn
);
1425 return block_move_fn
;
1428 /* A subroutine of emit_block_move. Copy the data via an explicit
1429 loop. This is used only when libcalls are forbidden. */
1430 /* ??? It'd be nice to copy in hunks larger than QImode. */
1433 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1434 unsigned int align ATTRIBUTE_UNUSED
)
1436 rtx cmp_label
, top_label
, iter
, x_addr
, y_addr
, tmp
;
1437 enum machine_mode x_addr_mode
1438 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (x
));
1439 enum machine_mode y_addr_mode
1440 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (y
));
1441 enum machine_mode iter_mode
;
1443 iter_mode
= GET_MODE (size
);
1444 if (iter_mode
== VOIDmode
)
1445 iter_mode
= word_mode
;
1447 top_label
= gen_label_rtx ();
1448 cmp_label
= gen_label_rtx ();
1449 iter
= gen_reg_rtx (iter_mode
);
1451 emit_move_insn (iter
, const0_rtx
);
1453 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1454 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1455 do_pending_stack_adjust ();
1457 emit_jump (cmp_label
);
1458 emit_label (top_label
);
1460 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1461 x_addr
= gen_rtx_PLUS (x_addr_mode
, x_addr
, tmp
);
1463 if (x_addr_mode
!= y_addr_mode
)
1464 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1465 y_addr
= gen_rtx_PLUS (y_addr_mode
, y_addr
, tmp
);
1467 x
= change_address (x
, QImode
, x_addr
);
1468 y
= change_address (y
, QImode
, y_addr
);
1470 emit_move_insn (x
, y
);
1472 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1473 true, OPTAB_LIB_WIDEN
);
1475 emit_move_insn (iter
, tmp
);
1477 emit_label (cmp_label
);
1479 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1483 /* Copy all or part of a value X into registers starting at REGNO.
1484 The number of registers to be filled is NREGS. */
1487 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1490 #ifdef HAVE_load_multiple
1498 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1499 x
= validize_mem (force_const_mem (mode
, x
));
1501 /* See if the machine can do this with a load multiple insn. */
1502 #ifdef HAVE_load_multiple
1503 if (HAVE_load_multiple
)
1505 last
= get_last_insn ();
1506 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1514 delete_insns_since (last
);
1518 for (i
= 0; i
< nregs
; i
++)
1519 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1520 operand_subword_force (x
, i
, mode
));
1523 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1524 The number of registers to be filled is NREGS. */
1527 move_block_from_reg (int regno
, rtx x
, int nregs
)
1534 /* See if the machine can do this with a store multiple insn. */
1535 #ifdef HAVE_store_multiple
1536 if (HAVE_store_multiple
)
1538 rtx last
= get_last_insn ();
1539 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1547 delete_insns_since (last
);
1551 for (i
= 0; i
< nregs
; i
++)
1553 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1557 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1561 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1562 ORIG, where ORIG is a non-consecutive group of registers represented by
1563 a PARALLEL. The clone is identical to the original except in that the
1564 original set of registers is replaced by a new set of pseudo registers.
1565 The new set has the same modes as the original set. */
1568 gen_group_rtx (rtx orig
)
1573 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1575 length
= XVECLEN (orig
, 0);
1576 tmps
= XALLOCAVEC (rtx
, length
);
1578 /* Skip a NULL entry in first slot. */
1579 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1584 for (; i
< length
; i
++)
1586 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1587 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1589 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1592 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1595 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1596 except that values are placed in TMPS[i], and must later be moved
1597 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1600 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1604 enum machine_mode m
= GET_MODE (orig_src
);
1606 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1609 && !SCALAR_INT_MODE_P (m
)
1610 && !MEM_P (orig_src
)
1611 && GET_CODE (orig_src
) != CONCAT
)
1613 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1614 if (imode
== BLKmode
)
1615 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
, 0);
1617 src
= gen_reg_rtx (imode
);
1618 if (imode
!= BLKmode
)
1619 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1620 emit_move_insn (src
, orig_src
);
1621 /* ...and back again. */
1622 if (imode
!= BLKmode
)
1623 src
= gen_lowpart (imode
, src
);
1624 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1628 /* Check for a NULL entry, used to indicate that the parameter goes
1629 both on the stack and in registers. */
1630 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1635 /* Process the pieces. */
1636 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1638 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1639 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1640 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1643 /* Handle trailing fragments that run over the size of the struct. */
1644 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1646 /* Arrange to shift the fragment to where it belongs.
1647 extract_bit_field loads to the lsb of the reg. */
1649 #ifdef BLOCK_REG_PADDING
1650 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1651 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1656 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1657 bytelen
= ssize
- bytepos
;
1658 gcc_assert (bytelen
> 0);
1661 /* If we won't be loading directly from memory, protect the real source
1662 from strange tricks we might play; but make sure that the source can
1663 be loaded directly into the destination. */
1665 if (!MEM_P (orig_src
)
1666 && (!CONSTANT_P (orig_src
)
1667 || (GET_MODE (orig_src
) != mode
1668 && GET_MODE (orig_src
) != VOIDmode
)))
1670 if (GET_MODE (orig_src
) == VOIDmode
)
1671 src
= gen_reg_rtx (mode
);
1673 src
= gen_reg_rtx (GET_MODE (orig_src
));
1675 emit_move_insn (src
, orig_src
);
1678 /* Optimize the access just a bit. */
1680 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1681 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1682 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1683 && bytelen
== GET_MODE_SIZE (mode
))
1685 tmps
[i
] = gen_reg_rtx (mode
);
1686 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1688 else if (COMPLEX_MODE_P (mode
)
1689 && GET_MODE (src
) == mode
1690 && bytelen
== GET_MODE_SIZE (mode
))
1691 /* Let emit_move_complex do the bulk of the work. */
1693 else if (GET_CODE (src
) == CONCAT
)
1695 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1696 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1698 if ((bytepos
== 0 && bytelen
== slen0
)
1699 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1701 /* The following assumes that the concatenated objects all
1702 have the same size. In this case, a simple calculation
1703 can be used to determine the object and the bit field
1705 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1706 if (! CONSTANT_P (tmps
[i
])
1707 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1708 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1709 (bytepos
% slen0
) * BITS_PER_UNIT
,
1710 1, false, NULL_RTX
, mode
, mode
);
1716 gcc_assert (!bytepos
);
1717 mem
= assign_stack_temp (GET_MODE (src
), slen
, 0);
1718 emit_move_insn (mem
, src
);
1719 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1720 0, 1, false, NULL_RTX
, mode
, mode
);
1723 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1724 SIMD register, which is currently broken. While we get GCC
1725 to emit proper RTL for these cases, let's dump to memory. */
1726 else if (VECTOR_MODE_P (GET_MODE (dst
))
1729 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1732 mem
= assign_stack_temp (GET_MODE (src
), slen
, 0);
1733 emit_move_insn (mem
, src
);
1734 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1736 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1737 && XVECLEN (dst
, 0) > 1)
1738 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE(dst
), bytepos
);
1739 else if (CONSTANT_P (src
))
1741 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1749 gcc_assert (2 * len
== ssize
);
1750 split_double (src
, &first
, &second
);
1757 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1760 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1761 bytepos
* BITS_PER_UNIT
, 1, false, NULL_RTX
,
1765 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1770 /* Emit code to move a block SRC of type TYPE to a block DST,
1771 where DST is non-consecutive registers represented by a PARALLEL.
1772 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1776 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1781 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1782 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1784 /* Copy the extracted pieces into the proper (probable) hard regs. */
1785 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1787 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1790 emit_move_insn (d
, tmps
[i
]);
1794 /* Similar, but load SRC into new pseudos in a format that looks like
1795 PARALLEL. This can later be fed to emit_group_move to get things
1796 in the right place. */
1799 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1804 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1805 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1807 /* Convert the vector to look just like the original PARALLEL, except
1808 with the computed values. */
1809 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1811 rtx e
= XVECEXP (parallel
, 0, i
);
1812 rtx d
= XEXP (e
, 0);
1816 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1817 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1819 RTVEC_ELT (vec
, i
) = e
;
1822 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1825 /* Emit code to move a block SRC to block DST, where SRC and DST are
1826 non-consecutive groups of registers, each represented by a PARALLEL. */
1829 emit_group_move (rtx dst
, rtx src
)
1833 gcc_assert (GET_CODE (src
) == PARALLEL
1834 && GET_CODE (dst
) == PARALLEL
1835 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1837 /* Skip first entry if NULL. */
1838 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1839 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1840 XEXP (XVECEXP (src
, 0, i
), 0));
1843 /* Move a group of registers represented by a PARALLEL into pseudos. */
1846 emit_group_move_into_temps (rtx src
)
1848 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1851 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1853 rtx e
= XVECEXP (src
, 0, i
);
1854 rtx d
= XEXP (e
, 0);
1857 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1858 RTVEC_ELT (vec
, i
) = e
;
1861 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1864 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1865 where SRC is non-consecutive registers represented by a PARALLEL.
1866 SSIZE represents the total size of block ORIG_DST, or -1 if not
1870 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1873 int start
, finish
, i
;
1874 enum machine_mode m
= GET_MODE (orig_dst
);
1876 gcc_assert (GET_CODE (src
) == PARALLEL
);
1878 if (!SCALAR_INT_MODE_P (m
)
1879 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1881 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1882 if (imode
== BLKmode
)
1883 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
, 0);
1885 dst
= gen_reg_rtx (imode
);
1886 emit_group_store (dst
, src
, type
, ssize
);
1887 if (imode
!= BLKmode
)
1888 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1889 emit_move_insn (orig_dst
, dst
);
1893 /* Check for a NULL entry, used to indicate that the parameter goes
1894 both on the stack and in registers. */
1895 if (XEXP (XVECEXP (src
, 0, 0), 0))
1899 finish
= XVECLEN (src
, 0);
1901 tmps
= XALLOCAVEC (rtx
, finish
);
1903 /* Copy the (probable) hard regs into pseudos. */
1904 for (i
= start
; i
< finish
; i
++)
1906 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1907 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1909 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1910 emit_move_insn (tmps
[i
], reg
);
1916 /* If we won't be storing directly into memory, protect the real destination
1917 from strange tricks we might play. */
1919 if (GET_CODE (dst
) == PARALLEL
)
1923 /* We can get a PARALLEL dst if there is a conditional expression in
1924 a return statement. In that case, the dst and src are the same,
1925 so no action is necessary. */
1926 if (rtx_equal_p (dst
, src
))
1929 /* It is unclear if we can ever reach here, but we may as well handle
1930 it. Allocate a temporary, and split this into a store/load to/from
1933 temp
= assign_stack_temp (GET_MODE (dst
), ssize
, 0);
1934 emit_group_store (temp
, src
, type
, ssize
);
1935 emit_group_load (dst
, temp
, type
, ssize
);
1938 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1940 enum machine_mode outer
= GET_MODE (dst
);
1941 enum machine_mode inner
;
1942 HOST_WIDE_INT bytepos
;
1946 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1947 dst
= gen_reg_rtx (outer
);
1949 /* Make life a bit easier for combine. */
1950 /* If the first element of the vector is the low part
1951 of the destination mode, use a paradoxical subreg to
1952 initialize the destination. */
1955 inner
= GET_MODE (tmps
[start
]);
1956 bytepos
= subreg_lowpart_offset (inner
, outer
);
1957 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1959 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1963 emit_move_insn (dst
, temp
);
1970 /* If the first element wasn't the low part, try the last. */
1972 && start
< finish
- 1)
1974 inner
= GET_MODE (tmps
[finish
- 1]);
1975 bytepos
= subreg_lowpart_offset (inner
, outer
);
1976 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1978 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1982 emit_move_insn (dst
, temp
);
1989 /* Otherwise, simply initialize the result to zero. */
1991 emit_move_insn (dst
, CONST0_RTX (outer
));
1994 /* Process the pieces. */
1995 for (i
= start
; i
< finish
; i
++)
1997 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
1998 enum machine_mode mode
= GET_MODE (tmps
[i
]);
1999 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2000 unsigned int adj_bytelen
= bytelen
;
2003 /* Handle trailing fragments that run over the size of the struct. */
2004 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2005 adj_bytelen
= ssize
- bytepos
;
2007 if (GET_CODE (dst
) == CONCAT
)
2009 if (bytepos
+ adj_bytelen
2010 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2011 dest
= XEXP (dst
, 0);
2012 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2014 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2015 dest
= XEXP (dst
, 1);
2019 enum machine_mode dest_mode
= GET_MODE (dest
);
2020 enum machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2022 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2024 if (GET_MODE_ALIGNMENT (dest_mode
)
2025 >= GET_MODE_ALIGNMENT (tmp_mode
))
2027 dest
= assign_stack_temp (dest_mode
,
2028 GET_MODE_SIZE (dest_mode
),
2030 emit_move_insn (adjust_address (dest
,
2038 dest
= assign_stack_temp (tmp_mode
,
2039 GET_MODE_SIZE (tmp_mode
),
2041 emit_move_insn (dest
, tmps
[i
]);
2042 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2048 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2050 /* store_bit_field always takes its value from the lsb.
2051 Move the fragment to the lsb if it's not already there. */
2053 #ifdef BLOCK_REG_PADDING
2054 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2055 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2061 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2062 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2065 bytelen
= adj_bytelen
;
2068 /* Optimize the access just a bit. */
2070 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2071 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2072 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2073 && bytelen
== GET_MODE_SIZE (mode
))
2074 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2076 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2077 0, 0, mode
, tmps
[i
]);
2080 /* Copy from the pseudo into the (probable) hard reg. */
2081 if (orig_dst
!= dst
)
2082 emit_move_insn (orig_dst
, dst
);
2085 /* Generate code to copy a BLKmode object of TYPE out of a
2086 set of registers starting with SRCREG into TGTBLK. If TGTBLK
2087 is null, a stack temporary is created. TGTBLK is returned.
2089 The purpose of this routine is to handle functions that return
2090 BLKmode structures in registers. Some machines (the PA for example)
2091 want to return all small structures in registers regardless of the
2092 structure's alignment. */
2095 copy_blkmode_from_reg (rtx tgtblk
, rtx srcreg
, tree type
)
2097 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2098 rtx src
= NULL
, dst
= NULL
;
2099 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2100 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2101 enum machine_mode copy_mode
;
2105 tgtblk
= assign_temp (build_qualified_type (type
,
2107 | TYPE_QUAL_CONST
)),
2109 preserve_temp_slots (tgtblk
);
2112 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2113 into a new pseudo which is a full word. */
2115 if (GET_MODE (srcreg
) != BLKmode
2116 && GET_MODE_SIZE (GET_MODE (srcreg
)) < UNITS_PER_WORD
)
2117 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2119 /* If the structure doesn't take up a whole number of words, see whether
2120 SRCREG is padded on the left or on the right. If it's on the left,
2121 set PADDING_CORRECTION to the number of bits to skip.
2123 In most ABIs, the structure will be returned at the least end of
2124 the register, which translates to right padding on little-endian
2125 targets and left padding on big-endian targets. The opposite
2126 holds if the structure is returned at the most significant
2127 end of the register. */
2128 if (bytes
% UNITS_PER_WORD
!= 0
2129 && (targetm
.calls
.return_in_msb (type
)
2131 : BYTES_BIG_ENDIAN
))
2133 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2135 /* Copy the structure BITSIZE bits at a time. If the target lives in
2136 memory, take care of not reading/writing past its end by selecting
2137 a copy mode suited to BITSIZE. This should always be possible given
2140 We could probably emit more efficient code for machines which do not use
2141 strict alignment, but it doesn't seem worth the effort at the current
2144 copy_mode
= word_mode
;
2147 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2148 if (mem_mode
!= BLKmode
)
2149 copy_mode
= mem_mode
;
2152 for (bitpos
= 0, xbitpos
= padding_correction
;
2153 bitpos
< bytes
* BITS_PER_UNIT
;
2154 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2156 /* We need a new source operand each time xbitpos is on a
2157 word boundary and when xbitpos == padding_correction
2158 (the first time through). */
2159 if (xbitpos
% BITS_PER_WORD
== 0
2160 || xbitpos
== padding_correction
)
2161 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
,
2164 /* We need a new destination operand each time bitpos is on
2166 if (bitpos
% BITS_PER_WORD
== 0)
2167 dst
= operand_subword (tgtblk
, bitpos
/ BITS_PER_WORD
, 1, BLKmode
);
2169 /* Use xbitpos for the source extraction (right justified) and
2170 bitpos for the destination store (left justified). */
2171 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2172 extract_bit_field (src
, bitsize
,
2173 xbitpos
% BITS_PER_WORD
, 1, false,
2174 NULL_RTX
, copy_mode
, copy_mode
));
2180 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2181 register if it contains any data, otherwise return null.
2183 This is used on targets that return BLKmode values in registers. */
2186 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2189 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2190 unsigned int bitsize
;
2191 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2192 enum machine_mode dst_mode
;
2194 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2196 x
= expand_normal (src
);
2198 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2202 /* If the structure doesn't take up a whole number of words, see
2203 whether the register value should be padded on the left or on
2204 the right. Set PADDING_CORRECTION to the number of padding
2205 bits needed on the left side.
2207 In most ABIs, the structure will be returned at the least end of
2208 the register, which translates to right padding on little-endian
2209 targets and left padding on big-endian targets. The opposite
2210 holds if the structure is returned at the most significant
2211 end of the register. */
2212 if (bytes
% UNITS_PER_WORD
!= 0
2213 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2215 : BYTES_BIG_ENDIAN
))
2216 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2219 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2220 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2221 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2223 /* Copy the structure BITSIZE bits at a time. */
2224 for (bitpos
= 0, xbitpos
= padding_correction
;
2225 bitpos
< bytes
* BITS_PER_UNIT
;
2226 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2228 /* We need a new destination pseudo each time xbitpos is
2229 on a word boundary and when xbitpos == padding_correction
2230 (the first time through). */
2231 if (xbitpos
% BITS_PER_WORD
== 0
2232 || xbitpos
== padding_correction
)
2234 /* Generate an appropriate register. */
2235 dst_word
= gen_reg_rtx (word_mode
);
2236 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2238 /* Clear the destination before we move anything into it. */
2239 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2242 /* We need a new source operand each time bitpos is on a word
2244 if (bitpos
% BITS_PER_WORD
== 0)
2245 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2247 /* Use bitpos for the source extraction (left justified) and
2248 xbitpos for the destination store (right justified). */
2249 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2251 extract_bit_field (src_word
, bitsize
,
2252 bitpos
% BITS_PER_WORD
, 1, false,
2253 NULL_RTX
, word_mode
, word_mode
));
2256 if (mode
== BLKmode
)
2258 /* Find the smallest integer mode large enough to hold the
2259 entire structure. */
2260 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2262 mode
= GET_MODE_WIDER_MODE (mode
))
2263 /* Have we found a large enough mode? */
2264 if (GET_MODE_SIZE (mode
) >= bytes
)
2267 /* A suitable mode should have been found. */
2268 gcc_assert (mode
!= VOIDmode
);
2271 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2272 dst_mode
= word_mode
;
2275 dst
= gen_reg_rtx (dst_mode
);
2277 for (i
= 0; i
< n_regs
; i
++)
2278 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2280 if (mode
!= dst_mode
)
2281 dst
= gen_lowpart (mode
, dst
);
2286 /* Add a USE expression for REG to the (possibly empty) list pointed
2287 to by CALL_FUSAGE. REG must denote a hard register. */
2290 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2292 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2295 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2298 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2299 starting at REGNO. All of these registers must be hard registers. */
2302 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2306 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2308 for (i
= 0; i
< nregs
; i
++)
2309 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2312 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2313 PARALLEL REGS. This is for calls that pass values in multiple
2314 non-contiguous locations. The Irix 6 ABI has examples of this. */
2317 use_group_regs (rtx
*call_fusage
, rtx regs
)
2321 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2323 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2325 /* A NULL entry means the parameter goes both on the stack and in
2326 registers. This can also be a MEM for targets that pass values
2327 partially on the stack and partially in registers. */
2328 if (reg
!= 0 && REG_P (reg
))
2329 use_reg (call_fusage
, reg
);
2333 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2334 assigment and the code of the expresion on the RHS is CODE. Return
2338 get_def_for_expr (tree name
, enum tree_code code
)
2342 if (TREE_CODE (name
) != SSA_NAME
)
2345 def_stmt
= get_gimple_for_ssa_name (name
);
2347 || gimple_assign_rhs_code (def_stmt
) != code
)
2353 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2354 assigment and the class of the expresion on the RHS is CLASS. Return
2358 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2362 if (TREE_CODE (name
) != SSA_NAME
)
2365 def_stmt
= get_gimple_for_ssa_name (name
);
2367 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2374 /* Determine whether the LEN bytes generated by CONSTFUN can be
2375 stored to memory using several move instructions. CONSTFUNDATA is
2376 a pointer which will be passed as argument in every CONSTFUN call.
2377 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2378 a memset operation and false if it's a copy of a constant string.
2379 Return nonzero if a call to store_by_pieces should succeed. */
2382 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2383 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2384 void *constfundata
, unsigned int align
, bool memsetp
)
2386 unsigned HOST_WIDE_INT l
;
2387 unsigned int max_size
;
2388 HOST_WIDE_INT offset
= 0;
2389 enum machine_mode mode
;
2390 enum insn_code icode
;
2392 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2393 rtx cst ATTRIBUTE_UNUSED
;
2399 ? SET_BY_PIECES_P (len
, align
)
2400 : STORE_BY_PIECES_P (len
, align
)))
2403 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2405 /* We would first store what we can in the largest integer mode, then go to
2406 successively smaller modes. */
2409 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2413 max_size
= STORE_MAX_PIECES
+ 1;
2414 while (max_size
> 1)
2416 mode
= widest_int_mode_for_size (max_size
);
2418 if (mode
== VOIDmode
)
2421 icode
= optab_handler (mov_optab
, mode
);
2422 if (icode
!= CODE_FOR_nothing
2423 && align
>= GET_MODE_ALIGNMENT (mode
))
2425 unsigned int size
= GET_MODE_SIZE (mode
);
2432 cst
= (*constfun
) (constfundata
, offset
, mode
);
2433 if (!targetm
.legitimate_constant_p (mode
, cst
))
2443 max_size
= GET_MODE_SIZE (mode
);
2446 /* The code above should have handled everything. */
2453 /* Generate several move instructions to store LEN bytes generated by
2454 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2455 pointer which will be passed as argument in every CONSTFUN call.
2456 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2457 a memset operation and false if it's a copy of a constant string.
2458 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2459 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2463 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2464 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2465 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2467 enum machine_mode to_addr_mode
2468 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (to
));
2469 struct store_by_pieces_d data
;
2473 gcc_assert (endp
!= 2);
2478 ? SET_BY_PIECES_P (len
, align
)
2479 : STORE_BY_PIECES_P (len
, align
));
2480 data
.constfun
= constfun
;
2481 data
.constfundata
= constfundata
;
2484 store_by_pieces_1 (&data
, align
);
2489 gcc_assert (!data
.reverse
);
2494 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2495 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2497 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2498 plus_constant (to_addr_mode
,
2502 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2509 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2517 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2518 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2521 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2523 struct store_by_pieces_d data
;
2528 data
.constfun
= clear_by_pieces_1
;
2529 data
.constfundata
= NULL
;
2532 store_by_pieces_1 (&data
, align
);
2535 /* Callback routine for clear_by_pieces.
2536 Return const0_rtx unconditionally. */
2539 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2540 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2541 enum machine_mode mode ATTRIBUTE_UNUSED
)
2546 /* Subroutine of clear_by_pieces and store_by_pieces.
2547 Generate several move instructions to store LEN bytes of block TO. (A MEM
2548 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2551 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2552 unsigned int align ATTRIBUTE_UNUSED
)
2554 enum machine_mode to_addr_mode
2555 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (data
->to
));
2556 rtx to_addr
= XEXP (data
->to
, 0);
2557 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2558 enum insn_code icode
;
2561 data
->to_addr
= to_addr
;
2563 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2564 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2566 data
->explicit_inc_to
= 0;
2568 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2570 data
->offset
= data
->len
;
2572 /* If storing requires more than two move insns,
2573 copy addresses to registers (to make displacements shorter)
2574 and use post-increment if available. */
2575 if (!data
->autinc_to
2576 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2578 /* Determine the main mode we'll be using.
2579 MODE might not be used depending on the definitions of the
2580 USE_* macros below. */
2581 enum machine_mode mode ATTRIBUTE_UNUSED
2582 = widest_int_mode_for_size (max_size
);
2584 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2586 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2587 plus_constant (to_addr_mode
,
2590 data
->autinc_to
= 1;
2591 data
->explicit_inc_to
= -1;
2594 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2595 && ! data
->autinc_to
)
2597 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2598 data
->autinc_to
= 1;
2599 data
->explicit_inc_to
= 1;
2602 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2603 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2606 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2608 /* First store what we can in the largest integer mode, then go to
2609 successively smaller modes. */
2611 while (max_size
> 1)
2613 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2615 if (mode
== VOIDmode
)
2618 icode
= optab_handler (mov_optab
, mode
);
2619 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2620 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2622 max_size
= GET_MODE_SIZE (mode
);
2625 /* The code above should have handled everything. */
2626 gcc_assert (!data
->len
);
2629 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2630 with move instructions for mode MODE. GENFUN is the gen_... function
2631 to make a move insn for that mode. DATA has all the other info. */
2634 store_by_pieces_2 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
2635 struct store_by_pieces_d
*data
)
2637 unsigned int size
= GET_MODE_SIZE (mode
);
2640 while (data
->len
>= size
)
2643 data
->offset
-= size
;
2645 if (data
->autinc_to
)
2646 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2649 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2651 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2652 emit_insn (gen_add2_insn (data
->to_addr
,
2653 GEN_INT (-(HOST_WIDE_INT
) size
)));
2655 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2656 emit_insn ((*genfun
) (to1
, cst
));
2658 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2659 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
2661 if (! data
->reverse
)
2662 data
->offset
+= size
;
2668 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2669 its length in bytes. */
2672 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2673 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2675 enum machine_mode mode
= GET_MODE (object
);
2678 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2680 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2681 just move a zero. Otherwise, do this a piece at a time. */
2683 && CONST_INT_P (size
)
2684 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2686 rtx zero
= CONST0_RTX (mode
);
2689 emit_move_insn (object
, zero
);
2693 if (COMPLEX_MODE_P (mode
))
2695 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2698 write_complex_part (object
, zero
, 0);
2699 write_complex_part (object
, zero
, 1);
2705 if (size
== const0_rtx
)
2708 align
= MEM_ALIGN (object
);
2710 if (CONST_INT_P (size
)
2711 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2712 clear_by_pieces (object
, INTVAL (size
), align
);
2713 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2714 expected_align
, expected_size
))
2716 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2717 return set_storage_via_libcall (object
, size
, const0_rtx
,
2718 method
== BLOCK_OP_TAILCALL
);
2726 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2728 return clear_storage_hints (object
, size
, method
, 0, -1);
2732 /* A subroutine of clear_storage. Expand a call to memset.
2733 Return the return value of memset, 0 otherwise. */
2736 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2738 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2739 enum machine_mode size_mode
;
2742 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2743 place those into new pseudos into a VAR_DECL and use them later. */
2745 object
= copy_addr_to_reg (XEXP (object
, 0));
2747 size_mode
= TYPE_MODE (sizetype
);
2748 size
= convert_to_mode (size_mode
, size
, 1);
2749 size
= copy_to_mode_reg (size_mode
, size
);
2751 /* It is incorrect to use the libcall calling conventions to call
2752 memset in this context. This could be a user call to memset and
2753 the user may wish to examine the return value from memset. For
2754 targets where libcalls and normal calls have different conventions
2755 for returning pointers, we could end up generating incorrect code. */
2757 object_tree
= make_tree (ptr_type_node
, object
);
2758 if (!CONST_INT_P (val
))
2759 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2760 size_tree
= make_tree (sizetype
, size
);
2761 val_tree
= make_tree (integer_type_node
, val
);
2763 fn
= clear_storage_libcall_fn (true);
2764 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2765 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2767 retval
= expand_normal (call_expr
);
2772 /* A subroutine of set_storage_via_libcall. Create the tree node
2773 for the function we use for block clears. */
2775 tree block_clear_fn
;
2778 init_block_clear_fn (const char *asmspec
)
2780 if (!block_clear_fn
)
2784 fn
= get_identifier ("memset");
2785 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2786 integer_type_node
, sizetype
,
2789 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2790 DECL_EXTERNAL (fn
) = 1;
2791 TREE_PUBLIC (fn
) = 1;
2792 DECL_ARTIFICIAL (fn
) = 1;
2793 TREE_NOTHROW (fn
) = 1;
2794 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2795 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2797 block_clear_fn
= fn
;
2801 set_user_assembler_name (block_clear_fn
, asmspec
);
2805 clear_storage_libcall_fn (int for_call
)
2807 static bool emitted_extern
;
2809 if (!block_clear_fn
)
2810 init_block_clear_fn (NULL
);
2812 if (for_call
&& !emitted_extern
)
2814 emitted_extern
= true;
2815 make_decl_rtl (block_clear_fn
);
2818 return block_clear_fn
;
2821 /* Expand a setmem pattern; return true if successful. */
2824 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2825 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2827 /* Try the most limited insn first, because there's no point
2828 including more than one in the machine description unless
2829 the more limited one has some advantage. */
2831 enum machine_mode mode
;
2833 if (expected_align
< align
)
2834 expected_align
= align
;
2836 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2837 mode
= GET_MODE_WIDER_MODE (mode
))
2839 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2841 if (code
!= CODE_FOR_nothing
2842 /* We don't need MODE to be narrower than
2843 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2844 the mode mask, as it is returned by the macro, it will
2845 definitely be less than the actual mode mask. */
2846 && ((CONST_INT_P (size
)
2847 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2848 <= (GET_MODE_MASK (mode
) >> 1)))
2849 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
2851 struct expand_operand ops
[6];
2854 nops
= insn_data
[(int) code
].n_generator_args
;
2855 gcc_assert (nops
== 4 || nops
== 6);
2857 create_fixed_operand (&ops
[0], object
);
2858 /* The check above guarantees that this size conversion is valid. */
2859 create_convert_operand_to (&ops
[1], size
, mode
, true);
2860 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2861 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2864 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2865 create_integer_operand (&ops
[5], expected_size
);
2867 if (maybe_expand_insn (code
, nops
, ops
))
2876 /* Write to one of the components of the complex value CPLX. Write VAL to
2877 the real part if IMAG_P is false, and the imaginary part if its true. */
2880 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2882 enum machine_mode cmode
;
2883 enum machine_mode imode
;
2886 if (GET_CODE (cplx
) == CONCAT
)
2888 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2892 cmode
= GET_MODE (cplx
);
2893 imode
= GET_MODE_INNER (cmode
);
2894 ibitsize
= GET_MODE_BITSIZE (imode
);
2896 /* For MEMs simplify_gen_subreg may generate an invalid new address
2897 because, e.g., the original address is considered mode-dependent
2898 by the target, which restricts simplify_subreg from invoking
2899 adjust_address_nv. Instead of preparing fallback support for an
2900 invalid address, we call adjust_address_nv directly. */
2903 emit_move_insn (adjust_address_nv (cplx
, imode
,
2904 imag_p
? GET_MODE_SIZE (imode
) : 0),
2909 /* If the sub-object is at least word sized, then we know that subregging
2910 will work. This special case is important, since store_bit_field
2911 wants to operate on integer modes, and there's rarely an OImode to
2912 correspond to TCmode. */
2913 if (ibitsize
>= BITS_PER_WORD
2914 /* For hard regs we have exact predicates. Assume we can split
2915 the original object if it spans an even number of hard regs.
2916 This special case is important for SCmode on 64-bit platforms
2917 where the natural size of floating-point regs is 32-bit. */
2919 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2920 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2922 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
2923 imag_p
? GET_MODE_SIZE (imode
) : 0);
2926 emit_move_insn (part
, val
);
2930 /* simplify_gen_subreg may fail for sub-word MEMs. */
2931 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2934 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
2937 /* Extract one of the components of the complex value CPLX. Extract the
2938 real part if IMAG_P is false, and the imaginary part if it's true. */
2941 read_complex_part (rtx cplx
, bool imag_p
)
2943 enum machine_mode cmode
, imode
;
2946 if (GET_CODE (cplx
) == CONCAT
)
2947 return XEXP (cplx
, imag_p
);
2949 cmode
= GET_MODE (cplx
);
2950 imode
= GET_MODE_INNER (cmode
);
2951 ibitsize
= GET_MODE_BITSIZE (imode
);
2953 /* Special case reads from complex constants that got spilled to memory. */
2954 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
2956 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
2957 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
2959 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
2960 if (CONSTANT_CLASS_P (part
))
2961 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
2965 /* For MEMs simplify_gen_subreg may generate an invalid new address
2966 because, e.g., the original address is considered mode-dependent
2967 by the target, which restricts simplify_subreg from invoking
2968 adjust_address_nv. Instead of preparing fallback support for an
2969 invalid address, we call adjust_address_nv directly. */
2971 return adjust_address_nv (cplx
, imode
,
2972 imag_p
? GET_MODE_SIZE (imode
) : 0);
2974 /* If the sub-object is at least word sized, then we know that subregging
2975 will work. This special case is important, since extract_bit_field
2976 wants to operate on integer modes, and there's rarely an OImode to
2977 correspond to TCmode. */
2978 if (ibitsize
>= BITS_PER_WORD
2979 /* For hard regs we have exact predicates. Assume we can split
2980 the original object if it spans an even number of hard regs.
2981 This special case is important for SCmode on 64-bit platforms
2982 where the natural size of floating-point regs is 32-bit. */
2984 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2985 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2987 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
2988 imag_p
? GET_MODE_SIZE (imode
) : 0);
2992 /* simplify_gen_subreg may fail for sub-word MEMs. */
2993 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2996 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
2997 true, false, NULL_RTX
, imode
, imode
);
3000 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3001 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3002 represented in NEW_MODE. If FORCE is true, this will never happen, as
3003 we'll force-create a SUBREG if needed. */
3006 emit_move_change_mode (enum machine_mode new_mode
,
3007 enum machine_mode old_mode
, rtx x
, bool force
)
3011 if (push_operand (x
, GET_MODE (x
)))
3013 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3014 MEM_COPY_ATTRIBUTES (ret
, x
);
3018 /* We don't have to worry about changing the address since the
3019 size in bytes is supposed to be the same. */
3020 if (reload_in_progress
)
3022 /* Copy the MEM to change the mode and move any
3023 substitutions from the old MEM to the new one. */
3024 ret
= adjust_address_nv (x
, new_mode
, 0);
3025 copy_replacements (x
, ret
);
3028 ret
= adjust_address (x
, new_mode
, 0);
3032 /* Note that we do want simplify_subreg's behavior of validating
3033 that the new mode is ok for a hard register. If we were to use
3034 simplify_gen_subreg, we would create the subreg, but would
3035 probably run into the target not being able to implement it. */
3036 /* Except, of course, when FORCE is true, when this is exactly what
3037 we want. Which is needed for CCmodes on some targets. */
3039 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3041 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3047 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3048 an integer mode of the same size as MODE. Returns the instruction
3049 emitted, or NULL if such a move could not be generated. */
3052 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3054 enum machine_mode imode
;
3055 enum insn_code code
;
3057 /* There must exist a mode of the exact size we require. */
3058 imode
= int_mode_for_mode (mode
);
3059 if (imode
== BLKmode
)
3062 /* The target must support moves in this mode. */
3063 code
= optab_handler (mov_optab
, imode
);
3064 if (code
== CODE_FOR_nothing
)
3067 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3070 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3073 return emit_insn (GEN_FCN (code
) (x
, y
));
3076 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3077 Return an equivalent MEM that does not use an auto-increment. */
3080 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3082 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3083 HOST_WIDE_INT adjust
;
3086 adjust
= GET_MODE_SIZE (mode
);
3087 #ifdef PUSH_ROUNDING
3088 adjust
= PUSH_ROUNDING (adjust
);
3090 if (code
== PRE_DEC
|| code
== POST_DEC
)
3092 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3094 rtx expr
= XEXP (XEXP (x
, 0), 1);
3097 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3098 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3099 val
= INTVAL (XEXP (expr
, 1));
3100 if (GET_CODE (expr
) == MINUS
)
3102 gcc_assert (adjust
== val
|| adjust
== -val
);
3106 /* Do not use anti_adjust_stack, since we don't want to update
3107 stack_pointer_delta. */
3108 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3109 GEN_INT (adjust
), stack_pointer_rtx
,
3110 0, OPTAB_LIB_WIDEN
);
3111 if (temp
!= stack_pointer_rtx
)
3112 emit_move_insn (stack_pointer_rtx
, temp
);
3119 temp
= stack_pointer_rtx
;
3124 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3130 return replace_equiv_address (x
, temp
);
3133 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3134 X is known to satisfy push_operand, and MODE is known to be complex.
3135 Returns the last instruction emitted. */
3138 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3140 enum machine_mode submode
= GET_MODE_INNER (mode
);
3143 #ifdef PUSH_ROUNDING
3144 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3146 /* In case we output to the stack, but the size is smaller than the
3147 machine can push exactly, we need to use move instructions. */
3148 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3150 x
= emit_move_resolve_push (mode
, x
);
3151 return emit_move_insn (x
, y
);
3155 /* Note that the real part always precedes the imag part in memory
3156 regardless of machine's endianness. */
3157 switch (GET_CODE (XEXP (x
, 0)))
3171 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3172 read_complex_part (y
, imag_first
));
3173 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3174 read_complex_part (y
, !imag_first
));
3177 /* A subroutine of emit_move_complex. Perform the move from Y to X
3178 via two moves of the parts. Returns the last instruction emitted. */
3181 emit_move_complex_parts (rtx x
, rtx y
)
3183 /* Show the output dies here. This is necessary for SUBREGs
3184 of pseudos since we cannot track their lifetimes correctly;
3185 hard regs shouldn't appear here except as return values. */
3186 if (!reload_completed
&& !reload_in_progress
3187 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3190 write_complex_part (x
, read_complex_part (y
, false), false);
3191 write_complex_part (x
, read_complex_part (y
, true), true);
3193 return get_last_insn ();
3196 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3197 MODE is known to be complex. Returns the last instruction emitted. */
3200 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3204 /* Need to take special care for pushes, to maintain proper ordering
3205 of the data, and possibly extra padding. */
3206 if (push_operand (x
, mode
))
3207 return emit_move_complex_push (mode
, x
, y
);
3209 /* See if we can coerce the target into moving both values at once. */
3211 /* Move floating point as parts. */
3212 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3213 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
)
3215 /* Not possible if the values are inherently not adjacent. */
3216 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3218 /* Is possible if both are registers (or subregs of registers). */
3219 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3221 /* If one of the operands is a memory, and alignment constraints
3222 are friendly enough, we may be able to do combined memory operations.
3223 We do not attempt this if Y is a constant because that combination is
3224 usually better with the by-parts thing below. */
3225 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3226 && (!STRICT_ALIGNMENT
3227 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3236 /* For memory to memory moves, optimal behavior can be had with the
3237 existing block move logic. */
3238 if (MEM_P (x
) && MEM_P (y
))
3240 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3241 BLOCK_OP_NO_LIBCALL
);
3242 return get_last_insn ();
3245 ret
= emit_move_via_integer (mode
, x
, y
, true);
3250 return emit_move_complex_parts (x
, y
);
3253 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3254 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3257 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3261 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3264 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3265 if (code
!= CODE_FOR_nothing
)
3267 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3268 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3269 return emit_insn (GEN_FCN (code
) (x
, y
));
3273 /* Otherwise, find the MODE_INT mode of the same width. */
3274 ret
= emit_move_via_integer (mode
, x
, y
, false);
3275 gcc_assert (ret
!= NULL
);
3279 /* Return true if word I of OP lies entirely in the
3280 undefined bits of a paradoxical subreg. */
3283 undefined_operand_subword_p (const_rtx op
, int i
)
3285 enum machine_mode innermode
, innermostmode
;
3287 if (GET_CODE (op
) != SUBREG
)
3289 innermode
= GET_MODE (op
);
3290 innermostmode
= GET_MODE (SUBREG_REG (op
));
3291 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3292 /* The SUBREG_BYTE represents offset, as if the value were stored in
3293 memory, except for a paradoxical subreg where we define
3294 SUBREG_BYTE to be 0; undo this exception as in
3296 if (SUBREG_BYTE (op
) == 0
3297 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3299 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3300 if (WORDS_BIG_ENDIAN
)
3301 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3302 if (BYTES_BIG_ENDIAN
)
3303 offset
+= difference
% UNITS_PER_WORD
;
3305 if (offset
>= GET_MODE_SIZE (innermostmode
)
3306 || offset
<= -GET_MODE_SIZE (word_mode
))
3311 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3312 MODE is any multi-word or full-word mode that lacks a move_insn
3313 pattern. Note that you will get better code if you define such
3314 patterns, even if they must turn into multiple assembler instructions. */
3317 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3324 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3326 /* If X is a push on the stack, do the push now and replace
3327 X with a reference to the stack pointer. */
3328 if (push_operand (x
, mode
))
3329 x
= emit_move_resolve_push (mode
, x
);
3331 /* If we are in reload, see if either operand is a MEM whose address
3332 is scheduled for replacement. */
3333 if (reload_in_progress
&& MEM_P (x
)
3334 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3335 x
= replace_equiv_address_nv (x
, inner
);
3336 if (reload_in_progress
&& MEM_P (y
)
3337 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3338 y
= replace_equiv_address_nv (y
, inner
);
3342 need_clobber
= false;
3344 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3347 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3350 /* Do not generate code for a move if it would come entirely
3351 from the undefined bits of a paradoxical subreg. */
3352 if (undefined_operand_subword_p (y
, i
))
3355 ypart
= operand_subword (y
, i
, 1, mode
);
3357 /* If we can't get a part of Y, put Y into memory if it is a
3358 constant. Otherwise, force it into a register. Then we must
3359 be able to get a part of Y. */
3360 if (ypart
== 0 && CONSTANT_P (y
))
3362 y
= use_anchored_address (force_const_mem (mode
, y
));
3363 ypart
= operand_subword (y
, i
, 1, mode
);
3365 else if (ypart
== 0)
3366 ypart
= operand_subword_force (y
, i
, mode
);
3368 gcc_assert (xpart
&& ypart
);
3370 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3372 last_insn
= emit_move_insn (xpart
, ypart
);
3378 /* Show the output dies here. This is necessary for SUBREGs
3379 of pseudos since we cannot track their lifetimes correctly;
3380 hard regs shouldn't appear here except as return values.
3381 We never want to emit such a clobber after reload. */
3383 && ! (reload_in_progress
|| reload_completed
)
3384 && need_clobber
!= 0)
3392 /* Low level part of emit_move_insn.
3393 Called just like emit_move_insn, but assumes X and Y
3394 are basically valid. */
3397 emit_move_insn_1 (rtx x
, rtx y
)
3399 enum machine_mode mode
= GET_MODE (x
);
3400 enum insn_code code
;
3402 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3404 code
= optab_handler (mov_optab
, mode
);
3405 if (code
!= CODE_FOR_nothing
)
3406 return emit_insn (GEN_FCN (code
) (x
, y
));
3408 /* Expand complex moves by moving real part and imag part. */
3409 if (COMPLEX_MODE_P (mode
))
3410 return emit_move_complex (mode
, x
, y
);
3412 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3413 || ALL_FIXED_POINT_MODE_P (mode
))
3415 rtx result
= emit_move_via_integer (mode
, x
, y
, true);
3417 /* If we can't find an integer mode, use multi words. */
3421 return emit_move_multi_word (mode
, x
, y
);
3424 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3425 return emit_move_ccmode (mode
, x
, y
);
3427 /* Try using a move pattern for the corresponding integer mode. This is
3428 only safe when simplify_subreg can convert MODE constants into integer
3429 constants. At present, it can only do this reliably if the value
3430 fits within a HOST_WIDE_INT. */
3431 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3433 rtx ret
= emit_move_via_integer (mode
, x
, y
, false);
3438 return emit_move_multi_word (mode
, x
, y
);
3441 /* Generate code to copy Y into X.
3442 Both Y and X must have the same mode, except that
3443 Y can be a constant with VOIDmode.
3444 This mode cannot be BLKmode; use emit_block_move for that.
3446 Return the last instruction emitted. */
3449 emit_move_insn (rtx x
, rtx y
)
3451 enum machine_mode mode
= GET_MODE (x
);
3452 rtx y_cst
= NULL_RTX
;
3455 gcc_assert (mode
!= BLKmode
3456 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3461 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3462 && (last_insn
= compress_float_constant (x
, y
)))
3467 if (!targetm
.legitimate_constant_p (mode
, y
))
3469 y
= force_const_mem (mode
, y
);
3471 /* If the target's cannot_force_const_mem prevented the spill,
3472 assume that the target's move expanders will also take care
3473 of the non-legitimate constant. */
3477 y
= use_anchored_address (y
);
3481 /* If X or Y are memory references, verify that their addresses are valid
3484 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3486 && ! push_operand (x
, GET_MODE (x
))))
3487 x
= validize_mem (x
);
3490 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3491 MEM_ADDR_SPACE (y
)))
3492 y
= validize_mem (y
);
3494 gcc_assert (mode
!= BLKmode
);
3496 last_insn
= emit_move_insn_1 (x
, y
);
3498 if (y_cst
&& REG_P (x
)
3499 && (set
= single_set (last_insn
)) != NULL_RTX
3500 && SET_DEST (set
) == x
3501 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3502 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3507 /* If Y is representable exactly in a narrower mode, and the target can
3508 perform the extension directly from constant or memory, then emit the
3509 move as an extension. */
3512 compress_float_constant (rtx x
, rtx y
)
3514 enum machine_mode dstmode
= GET_MODE (x
);
3515 enum machine_mode orig_srcmode
= GET_MODE (y
);
3516 enum machine_mode srcmode
;
3518 int oldcost
, newcost
;
3519 bool speed
= optimize_insn_for_speed_p ();
3521 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3523 if (targetm
.legitimate_constant_p (dstmode
, y
))
3524 oldcost
= set_src_cost (y
, speed
);
3526 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3528 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3529 srcmode
!= orig_srcmode
;
3530 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3533 rtx trunc_y
, last_insn
;
3535 /* Skip if the target can't extend this way. */
3536 ic
= can_extend_p (dstmode
, srcmode
, 0);
3537 if (ic
== CODE_FOR_nothing
)
3540 /* Skip if the narrowed value isn't exact. */
3541 if (! exact_real_truncate (srcmode
, &r
))
3544 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3546 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3548 /* Skip if the target needs extra instructions to perform
3550 if (!insn_operand_matches (ic
, 1, trunc_y
))
3552 /* This is valid, but may not be cheaper than the original. */
3553 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3555 if (oldcost
< newcost
)
3558 else if (float_extend_from_mem
[dstmode
][srcmode
])
3560 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3561 /* This is valid, but may not be cheaper than the original. */
3562 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3564 if (oldcost
< newcost
)
3566 trunc_y
= validize_mem (trunc_y
);
3571 /* For CSE's benefit, force the compressed constant pool entry
3572 into a new pseudo. This constant may be used in different modes,
3573 and if not, combine will put things back together for us. */
3574 trunc_y
= force_reg (srcmode
, trunc_y
);
3575 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3576 last_insn
= get_last_insn ();
3579 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3587 /* Pushing data onto the stack. */
3589 /* Push a block of length SIZE (perhaps variable)
3590 and return an rtx to address the beginning of the block.
3591 The value may be virtual_outgoing_args_rtx.
3593 EXTRA is the number of bytes of padding to push in addition to SIZE.
3594 BELOW nonzero means this padding comes at low addresses;
3595 otherwise, the padding comes at high addresses. */
3598 push_block (rtx size
, int extra
, int below
)
3602 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3603 if (CONSTANT_P (size
))
3604 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3605 else if (REG_P (size
) && extra
== 0)
3606 anti_adjust_stack (size
);
3609 temp
= copy_to_mode_reg (Pmode
, size
);
3611 temp
= expand_binop (Pmode
, add_optab
, temp
, GEN_INT (extra
),
3612 temp
, 0, OPTAB_LIB_WIDEN
);
3613 anti_adjust_stack (temp
);
3616 #ifndef STACK_GROWS_DOWNWARD
3622 temp
= virtual_outgoing_args_rtx
;
3623 if (extra
!= 0 && below
)
3624 temp
= plus_constant (Pmode
, temp
, extra
);
3628 if (CONST_INT_P (size
))
3629 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3630 -INTVAL (size
) - (below
? 0 : extra
));
3631 else if (extra
!= 0 && !below
)
3632 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3633 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3636 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3637 negate_rtx (Pmode
, size
));
3640 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3643 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3646 mem_autoinc_base (rtx mem
)
3650 rtx addr
= XEXP (mem
, 0);
3651 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3652 return XEXP (addr
, 0);
3657 /* A utility routine used here, in reload, and in try_split. The insns
3658 after PREV up to and including LAST are known to adjust the stack,
3659 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3660 placing notes as appropriate. PREV may be NULL, indicating the
3661 entire insn sequence prior to LAST should be scanned.
3663 The set of allowed stack pointer modifications is small:
3664 (1) One or more auto-inc style memory references (aka pushes),
3665 (2) One or more addition/subtraction with the SP as destination,
3666 (3) A single move insn with the SP as destination,
3667 (4) A call_pop insn,
3668 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3670 Insns in the sequence that do not modify the SP are ignored,
3671 except for noreturn calls.
3673 The return value is the amount of adjustment that can be trivially
3674 verified, via immediate operand or auto-inc. If the adjustment
3675 cannot be trivially extracted, the return value is INT_MIN. */
3678 find_args_size_adjust (rtx insn
)
3683 pat
= PATTERN (insn
);
3686 /* Look for a call_pop pattern. */
3689 /* We have to allow non-call_pop patterns for the case
3690 of emit_single_push_insn of a TLS address. */
3691 if (GET_CODE (pat
) != PARALLEL
)
3694 /* All call_pop have a stack pointer adjust in the parallel.
3695 The call itself is always first, and the stack adjust is
3696 usually last, so search from the end. */
3697 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3699 set
= XVECEXP (pat
, 0, i
);
3700 if (GET_CODE (set
) != SET
)
3702 dest
= SET_DEST (set
);
3703 if (dest
== stack_pointer_rtx
)
3706 /* We'd better have found the stack pointer adjust. */
3709 /* Fall through to process the extracted SET and DEST
3710 as if it was a standalone insn. */
3712 else if (GET_CODE (pat
) == SET
)
3714 else if ((set
= single_set (insn
)) != NULL
)
3716 else if (GET_CODE (pat
) == PARALLEL
)
3718 /* ??? Some older ports use a parallel with a stack adjust
3719 and a store for a PUSH_ROUNDING pattern, rather than a
3720 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3721 /* ??? See h8300 and m68k, pushqi1. */
3722 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3724 set
= XVECEXP (pat
, 0, i
);
3725 if (GET_CODE (set
) != SET
)
3727 dest
= SET_DEST (set
);
3728 if (dest
== stack_pointer_rtx
)
3731 /* We do not expect an auto-inc of the sp in the parallel. */
3732 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3733 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3734 != stack_pointer_rtx
);
3742 dest
= SET_DEST (set
);
3744 /* Look for direct modifications of the stack pointer. */
3745 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3747 /* Look for a trivial adjustment, otherwise assume nothing. */
3748 /* Note that the SPU restore_stack_block pattern refers to
3749 the stack pointer in V4SImode. Consider that non-trivial. */
3750 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3751 && GET_CODE (SET_SRC (set
)) == PLUS
3752 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3753 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3754 return INTVAL (XEXP (SET_SRC (set
), 1));
3755 /* ??? Reload can generate no-op moves, which will be cleaned
3756 up later. Recognize it and continue searching. */
3757 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3760 return HOST_WIDE_INT_MIN
;
3766 /* Otherwise only think about autoinc patterns. */
3767 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3770 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3771 != stack_pointer_rtx
);
3773 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3774 mem
= SET_SRC (set
);
3778 addr
= XEXP (mem
, 0);
3779 switch (GET_CODE (addr
))
3783 return GET_MODE_SIZE (GET_MODE (mem
));
3786 return -GET_MODE_SIZE (GET_MODE (mem
));
3789 addr
= XEXP (addr
, 1);
3790 gcc_assert (GET_CODE (addr
) == PLUS
);
3791 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3792 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3793 return INTVAL (XEXP (addr
, 1));
3801 fixup_args_size_notes (rtx prev
, rtx last
, int end_args_size
)
3803 int args_size
= end_args_size
;
3804 bool saw_unknown
= false;
3807 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3809 HOST_WIDE_INT this_delta
;
3811 if (!NONDEBUG_INSN_P (insn
))
3814 this_delta
= find_args_size_adjust (insn
);
3815 if (this_delta
== 0)
3818 || ACCUMULATE_OUTGOING_ARGS
3819 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3823 gcc_assert (!saw_unknown
);
3824 if (this_delta
== HOST_WIDE_INT_MIN
)
3827 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3828 #ifdef STACK_GROWS_DOWNWARD
3829 this_delta
= -this_delta
;
3831 args_size
-= this_delta
;
3834 return saw_unknown
? INT_MIN
: args_size
;
3837 #ifdef PUSH_ROUNDING
3838 /* Emit single push insn. */
3841 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3844 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3846 enum insn_code icode
;
3848 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3849 /* If there is push pattern, use it. Otherwise try old way of throwing
3850 MEM representing push operation to move expander. */
3851 icode
= optab_handler (push_optab
, mode
);
3852 if (icode
!= CODE_FOR_nothing
)
3854 struct expand_operand ops
[1];
3856 create_input_operand (&ops
[0], x
, mode
);
3857 if (maybe_expand_insn (icode
, 1, ops
))
3860 if (GET_MODE_SIZE (mode
) == rounded_size
)
3861 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3862 /* If we are to pad downward, adjust the stack pointer first and
3863 then store X into the stack location using an offset. This is
3864 because emit_move_insn does not know how to pad; it does not have
3866 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3868 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3869 HOST_WIDE_INT offset
;
3871 emit_move_insn (stack_pointer_rtx
,
3872 expand_binop (Pmode
,
3873 #ifdef STACK_GROWS_DOWNWARD
3879 GEN_INT (rounded_size
),
3880 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3882 offset
= (HOST_WIDE_INT
) padding_size
;
3883 #ifdef STACK_GROWS_DOWNWARD
3884 if (STACK_PUSH_CODE
== POST_DEC
)
3885 /* We have already decremented the stack pointer, so get the
3887 offset
+= (HOST_WIDE_INT
) rounded_size
;
3889 if (STACK_PUSH_CODE
== POST_INC
)
3890 /* We have already incremented the stack pointer, so get the
3892 offset
-= (HOST_WIDE_INT
) rounded_size
;
3894 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
3898 #ifdef STACK_GROWS_DOWNWARD
3899 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3900 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3901 GEN_INT (-(HOST_WIDE_INT
) rounded_size
));
3903 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3904 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3905 GEN_INT (rounded_size
));
3907 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
3910 dest
= gen_rtx_MEM (mode
, dest_addr
);
3914 set_mem_attributes (dest
, type
, 1);
3916 if (flag_optimize_sibling_calls
)
3917 /* Function incoming arguments may overlap with sibling call
3918 outgoing arguments and we cannot allow reordering of reads
3919 from function arguments with stores to outgoing arguments
3920 of sibling calls. */
3921 set_mem_alias_set (dest
, 0);
3923 emit_move_insn (dest
, x
);
3926 /* Emit and annotate a single push insn. */
3929 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
3931 int delta
, old_delta
= stack_pointer_delta
;
3932 rtx prev
= get_last_insn ();
3935 emit_single_push_insn_1 (mode
, x
, type
);
3937 last
= get_last_insn ();
3939 /* Notice the common case where we emitted exactly one insn. */
3940 if (PREV_INSN (last
) == prev
)
3942 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
3946 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
3947 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
3951 /* Generate code to push X onto the stack, assuming it has mode MODE and
3953 MODE is redundant except when X is a CONST_INT (since they don't
3955 SIZE is an rtx for the size of data to be copied (in bytes),
3956 needed only if X is BLKmode.
3958 ALIGN (in bits) is maximum alignment we can assume.
3960 If PARTIAL and REG are both nonzero, then copy that many of the first
3961 bytes of X into registers starting with REG, and push the rest of X.
3962 The amount of space pushed is decreased by PARTIAL bytes.
3963 REG must be a hard register in this case.
3964 If REG is zero but PARTIAL is not, take any all others actions for an
3965 argument partially in registers, but do not actually load any
3968 EXTRA is the amount in bytes of extra space to leave next to this arg.
3969 This is ignored if an argument block has already been allocated.
3971 On a machine that lacks real push insns, ARGS_ADDR is the address of
3972 the bottom of the argument block for this call. We use indexing off there
3973 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3974 argument block has not been preallocated.
3976 ARGS_SO_FAR is the size of args previously pushed for this call.
3978 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3979 for arguments passed in registers. If nonzero, it will be the number
3980 of bytes required. */
3983 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
3984 unsigned int align
, int partial
, rtx reg
, int extra
,
3985 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
3989 enum direction stack_direction
3990 #ifdef STACK_GROWS_DOWNWARD
3996 /* Decide where to pad the argument: `downward' for below,
3997 `upward' for above, or `none' for don't pad it.
3998 Default is below for small data on big-endian machines; else above. */
3999 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4001 /* Invert direction if stack is post-decrement.
4003 if (STACK_PUSH_CODE
== POST_DEC
)
4004 if (where_pad
!= none
)
4005 where_pad
= (where_pad
== downward
? upward
: downward
);
4010 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4012 /* Copy a block into the stack, entirely or partially. */
4019 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4020 used
= partial
- offset
;
4022 if (mode
!= BLKmode
)
4024 /* A value is to be stored in an insufficiently aligned
4025 stack slot; copy via a suitably aligned slot if
4027 size
= GEN_INT (GET_MODE_SIZE (mode
));
4028 if (!MEM_P (xinner
))
4030 temp
= assign_temp (type
, 0, 1, 1);
4031 emit_move_insn (temp
, xinner
);
4038 /* USED is now the # of bytes we need not copy to the stack
4039 because registers will take care of them. */
4042 xinner
= adjust_address (xinner
, BLKmode
, used
);
4044 /* If the partial register-part of the arg counts in its stack size,
4045 skip the part of stack space corresponding to the registers.
4046 Otherwise, start copying to the beginning of the stack space,
4047 by setting SKIP to 0. */
4048 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4050 #ifdef PUSH_ROUNDING
4051 /* Do it with several push insns if that doesn't take lots of insns
4052 and if there is no difficulty with push insns that skip bytes
4053 on the stack for alignment purposes. */
4056 && CONST_INT_P (size
)
4058 && MEM_ALIGN (xinner
) >= align
4059 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4060 /* Here we avoid the case of a structure whose weak alignment
4061 forces many pushes of a small amount of data,
4062 and such small pushes do rounding that causes trouble. */
4063 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4064 || align
>= BIGGEST_ALIGNMENT
4065 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4066 == (align
/ BITS_PER_UNIT
)))
4067 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4069 /* Push padding now if padding above and stack grows down,
4070 or if padding below and stack grows up.
4071 But if space already allocated, this has already been done. */
4072 if (extra
&& args_addr
== 0
4073 && where_pad
!= none
&& where_pad
!= stack_direction
)
4074 anti_adjust_stack (GEN_INT (extra
));
4076 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4079 #endif /* PUSH_ROUNDING */
4083 /* Otherwise make space on the stack and copy the data
4084 to the address of that space. */
4086 /* Deduct words put into registers from the size we must copy. */
4089 if (CONST_INT_P (size
))
4090 size
= GEN_INT (INTVAL (size
) - used
);
4092 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4093 GEN_INT (used
), NULL_RTX
, 0,
4097 /* Get the address of the stack space.
4098 In this case, we do not deal with EXTRA separately.
4099 A single stack adjust will do. */
4102 temp
= push_block (size
, extra
, where_pad
== downward
);
4105 else if (CONST_INT_P (args_so_far
))
4106 temp
= memory_address (BLKmode
,
4107 plus_constant (Pmode
, args_addr
,
4108 skip
+ INTVAL (args_so_far
)));
4110 temp
= memory_address (BLKmode
,
4111 plus_constant (Pmode
,
4112 gen_rtx_PLUS (Pmode
,
4117 if (!ACCUMULATE_OUTGOING_ARGS
)
4119 /* If the source is referenced relative to the stack pointer,
4120 copy it to another register to stabilize it. We do not need
4121 to do this if we know that we won't be changing sp. */
4123 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4124 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4125 temp
= copy_to_reg (temp
);
4128 target
= gen_rtx_MEM (BLKmode
, temp
);
4130 /* We do *not* set_mem_attributes here, because incoming arguments
4131 may overlap with sibling call outgoing arguments and we cannot
4132 allow reordering of reads from function arguments with stores
4133 to outgoing arguments of sibling calls. We do, however, want
4134 to record the alignment of the stack slot. */
4135 /* ALIGN may well be better aligned than TYPE, e.g. due to
4136 PARM_BOUNDARY. Assume the caller isn't lying. */
4137 set_mem_align (target
, align
);
4139 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4142 else if (partial
> 0)
4144 /* Scalar partly in registers. */
4146 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4149 /* # bytes of start of argument
4150 that we must make space for but need not store. */
4151 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4152 int args_offset
= INTVAL (args_so_far
);
4155 /* Push padding now if padding above and stack grows down,
4156 or if padding below and stack grows up.
4157 But if space already allocated, this has already been done. */
4158 if (extra
&& args_addr
== 0
4159 && where_pad
!= none
&& where_pad
!= stack_direction
)
4160 anti_adjust_stack (GEN_INT (extra
));
4162 /* If we make space by pushing it, we might as well push
4163 the real data. Otherwise, we can leave OFFSET nonzero
4164 and leave the space uninitialized. */
4168 /* Now NOT_STACK gets the number of words that we don't need to
4169 allocate on the stack. Convert OFFSET to words too. */
4170 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4171 offset
/= UNITS_PER_WORD
;
4173 /* If the partial register-part of the arg counts in its stack size,
4174 skip the part of stack space corresponding to the registers.
4175 Otherwise, start copying to the beginning of the stack space,
4176 by setting SKIP to 0. */
4177 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4179 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4180 x
= validize_mem (force_const_mem (mode
, x
));
4182 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4183 SUBREGs of such registers are not allowed. */
4184 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4185 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4186 x
= copy_to_reg (x
);
4188 /* Loop over all the words allocated on the stack for this arg. */
4189 /* We can do it by words, because any scalar bigger than a word
4190 has a size a multiple of a word. */
4191 #ifndef PUSH_ARGS_REVERSED
4192 for (i
= not_stack
; i
< size
; i
++)
4194 for (i
= size
- 1; i
>= not_stack
; i
--)
4196 if (i
>= not_stack
+ offset
)
4197 emit_push_insn (operand_subword_force (x
, i
, mode
),
4198 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4200 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4202 reg_parm_stack_space
, alignment_pad
);
4209 /* Push padding now if padding above and stack grows down,
4210 or if padding below and stack grows up.
4211 But if space already allocated, this has already been done. */
4212 if (extra
&& args_addr
== 0
4213 && where_pad
!= none
&& where_pad
!= stack_direction
)
4214 anti_adjust_stack (GEN_INT (extra
));
4216 #ifdef PUSH_ROUNDING
4217 if (args_addr
== 0 && PUSH_ARGS
)
4218 emit_single_push_insn (mode
, x
, type
);
4222 if (CONST_INT_P (args_so_far
))
4224 = memory_address (mode
,
4225 plus_constant (Pmode
, args_addr
,
4226 INTVAL (args_so_far
)));
4228 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4230 dest
= gen_rtx_MEM (mode
, addr
);
4232 /* We do *not* set_mem_attributes here, because incoming arguments
4233 may overlap with sibling call outgoing arguments and we cannot
4234 allow reordering of reads from function arguments with stores
4235 to outgoing arguments of sibling calls. We do, however, want
4236 to record the alignment of the stack slot. */
4237 /* ALIGN may well be better aligned than TYPE, e.g. due to
4238 PARM_BOUNDARY. Assume the caller isn't lying. */
4239 set_mem_align (dest
, align
);
4241 emit_move_insn (dest
, x
);
4245 /* If part should go in registers, copy that part
4246 into the appropriate registers. Do this now, at the end,
4247 since mem-to-mem copies above may do function calls. */
4248 if (partial
> 0 && reg
!= 0)
4250 /* Handle calls that pass values in multiple non-contiguous locations.
4251 The Irix 6 ABI has examples of this. */
4252 if (GET_CODE (reg
) == PARALLEL
)
4253 emit_group_load (reg
, x
, type
, -1);
4256 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4257 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4261 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4262 anti_adjust_stack (GEN_INT (extra
));
4264 if (alignment_pad
&& args_addr
== 0)
4265 anti_adjust_stack (alignment_pad
);
4268 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4272 get_subtarget (rtx x
)
4276 /* Only registers can be subtargets. */
4278 /* Don't use hard regs to avoid extending their life. */
4279 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4283 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4284 FIELD is a bitfield. Returns true if the optimization was successful,
4285 and there's nothing else to do. */
4288 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4289 unsigned HOST_WIDE_INT bitpos
,
4290 unsigned HOST_WIDE_INT bitregion_start
,
4291 unsigned HOST_WIDE_INT bitregion_end
,
4292 enum machine_mode mode1
, rtx str_rtx
,
4295 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4296 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4301 enum tree_code code
;
4303 if (mode1
!= VOIDmode
4304 || bitsize
>= BITS_PER_WORD
4305 || str_bitsize
> BITS_PER_WORD
4306 || TREE_SIDE_EFFECTS (to
)
4307 || TREE_THIS_VOLATILE (to
))
4311 if (TREE_CODE (src
) != SSA_NAME
)
4313 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4316 srcstmt
= get_gimple_for_ssa_name (src
);
4318 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4321 code
= gimple_assign_rhs_code (srcstmt
);
4323 op0
= gimple_assign_rhs1 (srcstmt
);
4325 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4326 to find its initialization. Hopefully the initialization will
4327 be from a bitfield load. */
4328 if (TREE_CODE (op0
) == SSA_NAME
)
4330 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4332 /* We want to eventually have OP0 be the same as TO, which
4333 should be a bitfield. */
4335 || !is_gimple_assign (op0stmt
)
4336 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4338 op0
= gimple_assign_rhs1 (op0stmt
);
4341 op1
= gimple_assign_rhs2 (srcstmt
);
4343 if (!operand_equal_p (to
, op0
, 0))
4346 if (MEM_P (str_rtx
))
4348 unsigned HOST_WIDE_INT offset1
;
4350 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4351 str_mode
= word_mode
;
4352 str_mode
= get_best_mode (bitsize
, bitpos
,
4353 bitregion_start
, bitregion_end
,
4354 MEM_ALIGN (str_rtx
), str_mode
, 0);
4355 if (str_mode
== VOIDmode
)
4357 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4360 bitpos
%= str_bitsize
;
4361 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4362 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4364 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4367 /* If the bit field covers the whole REG/MEM, store_field
4368 will likely generate better code. */
4369 if (bitsize
>= str_bitsize
)
4372 /* We can't handle fields split across multiple entities. */
4373 if (bitpos
+ bitsize
> str_bitsize
)
4376 if (BYTES_BIG_ENDIAN
)
4377 bitpos
= str_bitsize
- bitpos
- bitsize
;
4383 /* For now, just optimize the case of the topmost bitfield
4384 where we don't need to do any masking and also
4385 1 bit bitfields where xor can be used.
4386 We might win by one instruction for the other bitfields
4387 too if insv/extv instructions aren't used, so that
4388 can be added later. */
4389 if (bitpos
+ bitsize
!= str_bitsize
4390 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4393 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4394 value
= convert_modes (str_mode
,
4395 TYPE_MODE (TREE_TYPE (op1
)), value
,
4396 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4398 /* We may be accessing data outside the field, which means
4399 we can alias adjacent data. */
4400 if (MEM_P (str_rtx
))
4402 str_rtx
= shallow_copy_rtx (str_rtx
);
4403 set_mem_alias_set (str_rtx
, 0);
4404 set_mem_expr (str_rtx
, 0);
4407 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4408 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4410 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4413 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4414 result
= expand_binop (str_mode
, binop
, str_rtx
,
4415 value
, str_rtx
, 1, OPTAB_WIDEN
);
4416 if (result
!= str_rtx
)
4417 emit_move_insn (str_rtx
, result
);
4422 if (TREE_CODE (op1
) != INTEGER_CST
)
4424 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4425 value
= convert_modes (str_mode
,
4426 TYPE_MODE (TREE_TYPE (op1
)), value
,
4427 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4429 /* We may be accessing data outside the field, which means
4430 we can alias adjacent data. */
4431 if (MEM_P (str_rtx
))
4433 str_rtx
= shallow_copy_rtx (str_rtx
);
4434 set_mem_alias_set (str_rtx
, 0);
4435 set_mem_expr (str_rtx
, 0);
4438 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4439 if (bitpos
+ bitsize
!= str_bitsize
)
4441 rtx mask
= GEN_INT (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1);
4442 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4444 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4445 result
= expand_binop (str_mode
, binop
, str_rtx
,
4446 value
, str_rtx
, 1, OPTAB_WIDEN
);
4447 if (result
!= str_rtx
)
4448 emit_move_insn (str_rtx
, result
);
4458 /* In the C++ memory model, consecutive bit fields in a structure are
4459 considered one memory location.
4461 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4462 returns the bit range of consecutive bits in which this COMPONENT_REF
4463 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4464 and *OFFSET may be adjusted in the process.
4466 If the access does not need to be restricted, 0 is returned in both
4467 *BITSTART and *BITEND. */
4470 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4471 unsigned HOST_WIDE_INT
*bitend
,
4473 HOST_WIDE_INT
*bitpos
,
4476 HOST_WIDE_INT bitoffset
;
4479 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4481 field
= TREE_OPERAND (exp
, 1);
4482 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4483 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4484 need to limit the range we can access. */
4487 *bitstart
= *bitend
= 0;
4491 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4492 part of a larger bit field, then the representative does not serve any
4493 useful purpose. This can occur in Ada. */
4494 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4496 enum machine_mode rmode
;
4497 HOST_WIDE_INT rbitsize
, rbitpos
;
4501 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4502 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4503 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4505 *bitstart
= *bitend
= 0;
4510 /* Compute the adjustment to bitpos from the offset of the field
4511 relative to the representative. DECL_FIELD_OFFSET of field and
4512 repr are the same by construction if they are not constants,
4513 see finish_bitfield_layout. */
4514 if (host_integerp (DECL_FIELD_OFFSET (field
), 1)
4515 && host_integerp (DECL_FIELD_OFFSET (repr
), 1))
4516 bitoffset
= (tree_low_cst (DECL_FIELD_OFFSET (field
), 1)
4517 - tree_low_cst (DECL_FIELD_OFFSET (repr
), 1)) * BITS_PER_UNIT
;
4520 bitoffset
+= (tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 1)
4521 - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr
), 1));
4523 /* If the adjustment is larger than bitpos, we would have a negative bit
4524 position for the lower bound and this may wreak havoc later. This can
4525 occur only if we have a non-null offset, so adjust offset and bitpos
4526 to make the lower bound non-negative. */
4527 if (bitoffset
> *bitpos
)
4529 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4531 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4532 gcc_assert (*offset
!= NULL_TREE
);
4536 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4540 *bitstart
= *bitpos
- bitoffset
;
4542 *bitend
= *bitstart
+ tree_low_cst (DECL_SIZE (repr
), 1) - 1;
4545 /* Returns true if the MEM_REF REF refers to an object that does not
4546 reside in memory and has non-BLKmode. */
4549 mem_ref_refers_to_non_mem_p (tree ref
)
4551 tree base
= TREE_OPERAND (ref
, 0);
4552 if (TREE_CODE (base
) != ADDR_EXPR
)
4554 base
= TREE_OPERAND (base
, 0);
4555 return (DECL_P (base
)
4556 && !TREE_ADDRESSABLE (base
)
4557 && DECL_MODE (base
) != BLKmode
4558 && DECL_RTL_SET_P (base
)
4559 && !MEM_P (DECL_RTL (base
)));
4562 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4563 is true, try generating a nontemporal store. */
4566 expand_assignment (tree to
, tree from
, bool nontemporal
)
4570 enum machine_mode mode
;
4572 enum insn_code icode
;
4574 /* Don't crash if the lhs of the assignment was erroneous. */
4575 if (TREE_CODE (to
) == ERROR_MARK
)
4577 expand_normal (from
);
4581 /* Optimize away no-op moves without side-effects. */
4582 if (operand_equal_p (to
, from
, 0))
4585 /* Handle misaligned stores. */
4586 mode
= TYPE_MODE (TREE_TYPE (to
));
4587 if ((TREE_CODE (to
) == MEM_REF
4588 || TREE_CODE (to
) == TARGET_MEM_REF
)
4590 && !mem_ref_refers_to_non_mem_p (to
)
4591 && ((align
= get_object_or_type_alignment (to
))
4592 < GET_MODE_ALIGNMENT (mode
))
4593 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4594 != CODE_FOR_nothing
)
4595 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4599 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4600 reg
= force_not_mem (reg
);
4601 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4603 if (icode
!= CODE_FOR_nothing
)
4605 struct expand_operand ops
[2];
4607 create_fixed_operand (&ops
[0], mem
);
4608 create_input_operand (&ops
[1], reg
, mode
);
4609 /* The movmisalign<mode> pattern cannot fail, else the assignment
4610 would silently be omitted. */
4611 expand_insn (icode
, 2, ops
);
4614 store_bit_field (mem
, GET_MODE_BITSIZE (mode
),
4615 0, 0, 0, mode
, reg
);
4619 /* Assignment of a structure component needs special treatment
4620 if the structure component's rtx is not simply a MEM.
4621 Assignment of an array element at a constant index, and assignment of
4622 an array element in an unaligned packed structure field, has the same
4623 problem. Same for (partially) storing into a non-memory object. */
4624 if (handled_component_p (to
)
4625 || (TREE_CODE (to
) == MEM_REF
4626 && mem_ref_refers_to_non_mem_p (to
))
4627 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4629 enum machine_mode mode1
;
4630 HOST_WIDE_INT bitsize
, bitpos
;
4631 unsigned HOST_WIDE_INT bitregion_start
= 0;
4632 unsigned HOST_WIDE_INT bitregion_end
= 0;
4641 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4642 &unsignedp
, &volatilep
, true);
4644 if (TREE_CODE (to
) == COMPONENT_REF
4645 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4646 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4648 /* If we are going to use store_bit_field and extract_bit_field,
4649 make sure to_rtx will be safe for multiple use. */
4650 mode
= TYPE_MODE (TREE_TYPE (tem
));
4651 if (TREE_CODE (tem
) == MEM_REF
4653 && ((align
= get_object_or_type_alignment (tem
))
4654 < GET_MODE_ALIGNMENT (mode
))
4655 && ((icode
= optab_handler (movmisalign_optab
, mode
))
4656 != CODE_FOR_nothing
))
4658 struct expand_operand ops
[2];
4661 to_rtx
= gen_reg_rtx (mode
);
4662 mem
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4664 /* If the misaligned store doesn't overwrite all bits, perform
4665 rmw cycle on MEM. */
4666 if (bitsize
!= GET_MODE_BITSIZE (mode
))
4668 create_input_operand (&ops
[0], to_rtx
, mode
);
4669 create_fixed_operand (&ops
[1], mem
);
4670 /* The movmisalign<mode> pattern cannot fail, else the assignment
4671 would silently be omitted. */
4672 expand_insn (icode
, 2, ops
);
4674 mem
= copy_rtx (mem
);
4680 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4683 /* If the bitfield is volatile, we want to access it in the
4684 field's mode, not the computed mode.
4685 If a MEM has VOIDmode (external with incomplete type),
4686 use BLKmode for it instead. */
4689 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
4690 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4691 else if (GET_MODE (to_rtx
) == VOIDmode
)
4692 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4697 enum machine_mode address_mode
;
4700 if (!MEM_P (to_rtx
))
4702 /* We can get constant negative offsets into arrays with broken
4703 user code. Translate this to a trap instead of ICEing. */
4704 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4705 expand_builtin_trap ();
4706 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4709 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4711 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (to_rtx
));
4712 if (GET_MODE (offset_rtx
) != address_mode
)
4713 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4715 /* A constant address in TO_RTX can have VOIDmode, we must not try
4716 to call force_reg for that case. Avoid that case. */
4718 && GET_MODE (to_rtx
) == BLKmode
4719 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
4721 && (bitpos
% bitsize
) == 0
4722 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4723 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
4725 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4729 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4730 highest_pow2_factor_for_target (to
,
4734 /* No action is needed if the target is not a memory and the field
4735 lies completely outside that target. This can occur if the source
4736 code contains an out-of-bounds access to a small array. */
4738 && GET_MODE (to_rtx
) != BLKmode
4739 && (unsigned HOST_WIDE_INT
) bitpos
4740 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4742 expand_normal (from
);
4745 /* Handle expand_expr of a complex value returning a CONCAT. */
4746 else if (GET_CODE (to_rtx
) == CONCAT
)
4748 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4749 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4751 && bitsize
== mode_bitsize
)
4752 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4753 else if (bitsize
== mode_bitsize
/ 2
4754 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4755 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4757 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4758 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4759 bitregion_start
, bitregion_end
,
4760 mode1
, from
, TREE_TYPE (tem
),
4761 get_alias_set (to
), nontemporal
);
4762 else if (bitpos
>= mode_bitsize
/ 2)
4763 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4764 bitpos
- mode_bitsize
/ 2,
4765 bitregion_start
, bitregion_end
,
4767 TREE_TYPE (tem
), get_alias_set (to
),
4769 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4772 result
= expand_normal (from
);
4773 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4774 TYPE_MODE (TREE_TYPE (from
)), 0);
4775 emit_move_insn (XEXP (to_rtx
, 0),
4776 read_complex_part (from_rtx
, false));
4777 emit_move_insn (XEXP (to_rtx
, 1),
4778 read_complex_part (from_rtx
, true));
4782 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4783 GET_MODE_SIZE (GET_MODE (to_rtx
)),
4785 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4786 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4787 result
= store_field (temp
, bitsize
, bitpos
,
4788 bitregion_start
, bitregion_end
,
4790 TREE_TYPE (tem
), get_alias_set (to
),
4792 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4793 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4800 /* If the field is at offset zero, we could have been given the
4801 DECL_RTX of the parent struct. Don't munge it. */
4802 to_rtx
= shallow_copy_rtx (to_rtx
);
4804 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4806 /* Deal with volatile and readonly fields. The former is only
4807 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4809 MEM_VOLATILE_P (to_rtx
) = 1;
4810 if (component_uses_parent_alias_set (to
))
4811 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
4814 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4815 bitregion_start
, bitregion_end
,
4820 result
= store_field (to_rtx
, bitsize
, bitpos
,
4821 bitregion_start
, bitregion_end
,
4823 TREE_TYPE (tem
), get_alias_set (to
),
4829 struct expand_operand ops
[2];
4831 create_fixed_operand (&ops
[0], mem
);
4832 create_input_operand (&ops
[1], to_rtx
, mode
);
4833 /* The movmisalign<mode> pattern cannot fail, else the assignment
4834 would silently be omitted. */
4835 expand_insn (icode
, 2, ops
);
4839 preserve_temp_slots (result
);
4845 /* If the rhs is a function call and its value is not an aggregate,
4846 call the function before we start to compute the lhs.
4847 This is needed for correct code for cases such as
4848 val = setjmp (buf) on machines where reference to val
4849 requires loading up part of an address in a separate insn.
4851 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4852 since it might be a promoted variable where the zero- or sign- extension
4853 needs to be done. Handling this in the normal way is safe because no
4854 computation is done before the call. The same is true for SSA names. */
4855 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4856 && COMPLETE_TYPE_P (TREE_TYPE (from
))
4857 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4858 && ! (((TREE_CODE (to
) == VAR_DECL
4859 || TREE_CODE (to
) == PARM_DECL
4860 || TREE_CODE (to
) == RESULT_DECL
)
4861 && REG_P (DECL_RTL (to
)))
4862 || TREE_CODE (to
) == SSA_NAME
))
4867 value
= expand_normal (from
);
4869 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4871 /* Handle calls that return values in multiple non-contiguous locations.
4872 The Irix 6 ABI has examples of this. */
4873 if (GET_CODE (to_rtx
) == PARALLEL
)
4874 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
4875 int_size_in_bytes (TREE_TYPE (from
)));
4876 else if (GET_MODE (to_rtx
) == BLKmode
)
4877 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
4880 if (POINTER_TYPE_P (TREE_TYPE (to
)))
4881 value
= convert_memory_address_addr_space
4882 (GET_MODE (to_rtx
), value
,
4883 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
4885 emit_move_insn (to_rtx
, value
);
4887 preserve_temp_slots (to_rtx
);
4893 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4894 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4896 /* Don't move directly into a return register. */
4897 if (TREE_CODE (to
) == RESULT_DECL
4898 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
4903 if (REG_P (to_rtx
) && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
)
4904 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
4906 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
4908 if (GET_CODE (to_rtx
) == PARALLEL
)
4909 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
4910 int_size_in_bytes (TREE_TYPE (from
)));
4912 emit_move_insn (to_rtx
, temp
);
4914 preserve_temp_slots (to_rtx
);
4920 /* In case we are returning the contents of an object which overlaps
4921 the place the value is being stored, use a safe function when copying
4922 a value through a pointer into a structure value return block. */
4923 if (TREE_CODE (to
) == RESULT_DECL
4924 && TREE_CODE (from
) == INDIRECT_REF
4925 && ADDR_SPACE_GENERIC_P
4926 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
4927 && refs_may_alias_p (to
, from
)
4928 && cfun
->returns_struct
4929 && !cfun
->returns_pcc_struct
)
4934 size
= expr_size (from
);
4935 from_rtx
= expand_normal (from
);
4937 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
4938 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
4939 XEXP (from_rtx
, 0), Pmode
,
4940 convert_to_mode (TYPE_MODE (sizetype
),
4941 size
, TYPE_UNSIGNED (sizetype
)),
4942 TYPE_MODE (sizetype
));
4944 preserve_temp_slots (to_rtx
);
4950 /* Compute FROM and store the value in the rtx we got. */
4953 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
4954 preserve_temp_slots (result
);
4960 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
4961 succeeded, false otherwise. */
4964 emit_storent_insn (rtx to
, rtx from
)
4966 struct expand_operand ops
[2];
4967 enum machine_mode mode
= GET_MODE (to
);
4968 enum insn_code code
= optab_handler (storent_optab
, mode
);
4970 if (code
== CODE_FOR_nothing
)
4973 create_fixed_operand (&ops
[0], to
);
4974 create_input_operand (&ops
[1], from
, mode
);
4975 return maybe_expand_insn (code
, 2, ops
);
4978 /* Generate code for computing expression EXP,
4979 and storing the value into TARGET.
4981 If the mode is BLKmode then we may return TARGET itself.
4982 It turns out that in BLKmode it doesn't cause a problem.
4983 because C has no operators that could combine two different
4984 assignments into the same BLKmode object with different values
4985 with no sequence point. Will other languages need this to
4988 If CALL_PARAM_P is nonzero, this is a store into a call param on the
4989 stack, and block moves may need to be treated specially.
4991 If NONTEMPORAL is true, try using a nontemporal store instruction. */
4994 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
4997 rtx alt_rtl
= NULL_RTX
;
4998 location_t loc
= EXPR_LOCATION (exp
);
5000 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5002 /* C++ can generate ?: expressions with a throw expression in one
5003 branch and an rvalue in the other. Here, we resolve attempts to
5004 store the throw expression's nonexistent result. */
5005 gcc_assert (!call_param_p
);
5006 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5009 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5011 /* Perform first part of compound expression, then assign from second
5013 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5014 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5015 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5018 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5020 /* For conditional expression, get safe form of the target. Then
5021 test the condition, doing the appropriate assignment on either
5022 side. This avoids the creation of unnecessary temporaries.
5023 For non-BLKmode, it is more efficient not to do this. */
5025 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
5027 do_pending_stack_adjust ();
5029 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5030 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5032 emit_jump_insn (gen_jump (lab2
));
5035 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5042 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5043 /* If this is a scalar in a register that is stored in a wider mode
5044 than the declared mode, compute the result into its declared mode
5045 and then convert to the wider mode. Our value is the computed
5048 rtx inner_target
= 0;
5050 /* We can do the conversion inside EXP, which will often result
5051 in some optimizations. Do the conversion in two steps: first
5052 change the signedness, if needed, then the extend. But don't
5053 do this if the type of EXP is a subtype of something else
5054 since then the conversion might involve more than just
5055 converting modes. */
5056 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5057 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5058 && GET_MODE_PRECISION (GET_MODE (target
))
5059 == TYPE_PRECISION (TREE_TYPE (exp
)))
5061 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
5062 != SUBREG_PROMOTED_UNSIGNED_P (target
))
5064 /* Some types, e.g. Fortran's logical*4, won't have a signed
5065 version, so use the mode instead. */
5067 = (signed_or_unsigned_type_for
5068 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)));
5070 ntype
= lang_hooks
.types
.type_for_mode
5071 (TYPE_MODE (TREE_TYPE (exp
)),
5072 SUBREG_PROMOTED_UNSIGNED_P (target
));
5074 exp
= fold_convert_loc (loc
, ntype
, exp
);
5077 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5078 (GET_MODE (SUBREG_REG (target
)),
5079 SUBREG_PROMOTED_UNSIGNED_P (target
)),
5082 inner_target
= SUBREG_REG (target
);
5085 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5086 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5088 /* If TEMP is a VOIDmode constant, use convert_modes to make
5089 sure that we properly convert it. */
5090 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5092 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5093 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
5094 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5095 GET_MODE (target
), temp
,
5096 SUBREG_PROMOTED_UNSIGNED_P (target
));
5099 convert_move (SUBREG_REG (target
), temp
,
5100 SUBREG_PROMOTED_UNSIGNED_P (target
));
5104 else if ((TREE_CODE (exp
) == STRING_CST
5105 || (TREE_CODE (exp
) == MEM_REF
5106 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5107 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5109 && integer_zerop (TREE_OPERAND (exp
, 1))))
5110 && !nontemporal
&& !call_param_p
5113 /* Optimize initialization of an array with a STRING_CST. */
5114 HOST_WIDE_INT exp_len
, str_copy_len
;
5116 tree str
= TREE_CODE (exp
) == STRING_CST
5117 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5119 exp_len
= int_expr_size (exp
);
5123 if (TREE_STRING_LENGTH (str
) <= 0)
5126 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5127 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5130 str_copy_len
= TREE_STRING_LENGTH (str
);
5131 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5132 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5134 str_copy_len
+= STORE_MAX_PIECES
- 1;
5135 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5137 str_copy_len
= MIN (str_copy_len
, exp_len
);
5138 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5139 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5140 MEM_ALIGN (target
), false))
5145 dest_mem
= store_by_pieces (dest_mem
,
5146 str_copy_len
, builtin_strncpy_read_str
,
5148 TREE_STRING_POINTER (str
)),
5149 MEM_ALIGN (target
), false,
5150 exp_len
> str_copy_len
? 1 : 0);
5151 if (exp_len
> str_copy_len
)
5152 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5153 GEN_INT (exp_len
- str_copy_len
),
5162 /* If we want to use a nontemporal store, force the value to
5164 tmp_target
= nontemporal
? NULL_RTX
: target
;
5165 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5167 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5171 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5172 the same as that of TARGET, adjust the constant. This is needed, for
5173 example, in case it is a CONST_DOUBLE and we want only a word-sized
5175 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5176 && TREE_CODE (exp
) != ERROR_MARK
5177 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5178 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5179 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5181 /* If value was not generated in the target, store it there.
5182 Convert the value to TARGET's type first if necessary and emit the
5183 pending incrementations that have been queued when expanding EXP.
5184 Note that we cannot emit the whole queue blindly because this will
5185 effectively disable the POST_INC optimization later.
5187 If TEMP and TARGET compare equal according to rtx_equal_p, but
5188 one or both of them are volatile memory refs, we have to distinguish
5190 - expand_expr has used TARGET. In this case, we must not generate
5191 another copy. This can be detected by TARGET being equal according
5193 - expand_expr has not used TARGET - that means that the source just
5194 happens to have the same RTX form. Since temp will have been created
5195 by expand_expr, it will compare unequal according to == .
5196 We must generate a copy in this case, to reach the correct number
5197 of volatile memory references. */
5199 if ((! rtx_equal_p (temp
, target
)
5200 || (temp
!= target
&& (side_effects_p (temp
)
5201 || side_effects_p (target
))))
5202 && TREE_CODE (exp
) != ERROR_MARK
5203 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5204 but TARGET is not valid memory reference, TEMP will differ
5205 from TARGET although it is really the same location. */
5207 && rtx_equal_p (alt_rtl
, target
)
5208 && !side_effects_p (alt_rtl
)
5209 && !side_effects_p (target
))
5210 /* If there's nothing to copy, don't bother. Don't call
5211 expr_size unless necessary, because some front-ends (C++)
5212 expr_size-hook must not be given objects that are not
5213 supposed to be bit-copied or bit-initialized. */
5214 && expr_size (exp
) != const0_rtx
)
5216 if (GET_MODE (temp
) != GET_MODE (target
)
5217 && GET_MODE (temp
) != VOIDmode
)
5219 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
5220 if (GET_MODE (target
) == BLKmode
5221 && GET_MODE (temp
) == BLKmode
)
5222 emit_block_move (target
, temp
, expr_size (exp
),
5224 ? BLOCK_OP_CALL_PARM
5225 : BLOCK_OP_NORMAL
));
5226 else if (GET_MODE (target
) == BLKmode
)
5227 store_bit_field (target
, INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5228 0, 0, 0, GET_MODE (temp
), temp
);
5230 convert_move (target
, temp
, unsignedp
);
5233 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5235 /* Handle copying a string constant into an array. The string
5236 constant may be shorter than the array. So copy just the string's
5237 actual length, and clear the rest. First get the size of the data
5238 type of the string, which is actually the size of the target. */
5239 rtx size
= expr_size (exp
);
5241 if (CONST_INT_P (size
)
5242 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5243 emit_block_move (target
, temp
, size
,
5245 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5248 enum machine_mode pointer_mode
5249 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5250 enum machine_mode address_mode
5251 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (target
));
5253 /* Compute the size of the data to copy from the string. */
5255 = size_binop_loc (loc
, MIN_EXPR
,
5256 make_tree (sizetype
, size
),
5257 size_int (TREE_STRING_LENGTH (exp
)));
5259 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5261 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5264 /* Copy that much. */
5265 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5266 TYPE_UNSIGNED (sizetype
));
5267 emit_block_move (target
, temp
, copy_size_rtx
,
5269 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5271 /* Figure out how much is left in TARGET that we have to clear.
5272 Do all calculations in pointer_mode. */
5273 if (CONST_INT_P (copy_size_rtx
))
5275 size
= plus_constant (address_mode
, size
,
5276 -INTVAL (copy_size_rtx
));
5277 target
= adjust_address (target
, BLKmode
,
5278 INTVAL (copy_size_rtx
));
5282 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5283 copy_size_rtx
, NULL_RTX
, 0,
5286 if (GET_MODE (copy_size_rtx
) != address_mode
)
5287 copy_size_rtx
= convert_to_mode (address_mode
,
5289 TYPE_UNSIGNED (sizetype
));
5291 target
= offset_address (target
, copy_size_rtx
,
5292 highest_pow2_factor (copy_size
));
5293 label
= gen_label_rtx ();
5294 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5295 GET_MODE (size
), 0, label
);
5298 if (size
!= const0_rtx
)
5299 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5305 /* Handle calls that return values in multiple non-contiguous locations.
5306 The Irix 6 ABI has examples of this. */
5307 else if (GET_CODE (target
) == PARALLEL
)
5308 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5309 int_size_in_bytes (TREE_TYPE (exp
)));
5310 else if (GET_MODE (temp
) == BLKmode
)
5311 emit_block_move (target
, temp
, expr_size (exp
),
5313 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5314 else if (nontemporal
5315 && emit_storent_insn (target
, temp
))
5316 /* If we managed to emit a nontemporal store, there is nothing else to
5321 temp
= force_operand (temp
, target
);
5323 emit_move_insn (target
, temp
);
5330 /* Return true if field F of structure TYPE is a flexible array. */
5333 flexible_array_member_p (const_tree f
, const_tree type
)
5338 return (DECL_CHAIN (f
) == NULL
5339 && TREE_CODE (tf
) == ARRAY_TYPE
5341 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5342 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5343 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5344 && int_size_in_bytes (type
) >= 0);
5347 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5348 must have in order for it to completely initialize a value of type TYPE.
5349 Return -1 if the number isn't known.
5351 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5353 static HOST_WIDE_INT
5354 count_type_elements (const_tree type
, bool for_ctor_p
)
5356 switch (TREE_CODE (type
))
5362 nelts
= array_type_nelts (type
);
5363 if (nelts
&& host_integerp (nelts
, 1))
5365 unsigned HOST_WIDE_INT n
;
5367 n
= tree_low_cst (nelts
, 1) + 1;
5368 if (n
== 0 || for_ctor_p
)
5371 return n
* count_type_elements (TREE_TYPE (type
), false);
5373 return for_ctor_p
? -1 : 1;
5378 unsigned HOST_WIDE_INT n
;
5382 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5383 if (TREE_CODE (f
) == FIELD_DECL
)
5386 n
+= count_type_elements (TREE_TYPE (f
), false);
5387 else if (!flexible_array_member_p (f
, type
))
5388 /* Don't count flexible arrays, which are not supposed
5389 to be initialized. */
5397 case QUAL_UNION_TYPE
:
5402 gcc_assert (!for_ctor_p
);
5403 /* Estimate the number of scalars in each field and pick the
5404 maximum. Other estimates would do instead; the idea is simply
5405 to make sure that the estimate is not sensitive to the ordering
5408 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5409 if (TREE_CODE (f
) == FIELD_DECL
)
5411 m
= count_type_elements (TREE_TYPE (f
), false);
5412 /* If the field doesn't span the whole union, add an extra
5413 scalar for the rest. */
5414 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5415 TYPE_SIZE (type
)) != 1)
5427 return TYPE_VECTOR_SUBPARTS (type
);
5431 case FIXED_POINT_TYPE
:
5436 case REFERENCE_TYPE
:
5452 /* Helper for categorize_ctor_elements. Identical interface. */
5455 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5456 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5458 unsigned HOST_WIDE_INT idx
;
5459 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5460 tree value
, purpose
, elt_type
;
5462 /* Whether CTOR is a valid constant initializer, in accordance with what
5463 initializer_constant_valid_p does. If inferred from the constructor
5464 elements, true until proven otherwise. */
5465 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5466 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5471 elt_type
= NULL_TREE
;
5473 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5475 HOST_WIDE_INT mult
= 1;
5477 if (TREE_CODE (purpose
) == RANGE_EXPR
)
5479 tree lo_index
= TREE_OPERAND (purpose
, 0);
5480 tree hi_index
= TREE_OPERAND (purpose
, 1);
5482 if (host_integerp (lo_index
, 1) && host_integerp (hi_index
, 1))
5483 mult
= (tree_low_cst (hi_index
, 1)
5484 - tree_low_cst (lo_index
, 1) + 1);
5487 elt_type
= TREE_TYPE (value
);
5489 switch (TREE_CODE (value
))
5493 HOST_WIDE_INT nz
= 0, ic
= 0;
5495 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5498 nz_elts
+= mult
* nz
;
5499 init_elts
+= mult
* ic
;
5501 if (const_from_elts_p
&& const_p
)
5502 const_p
= const_elt_p
;
5509 if (!initializer_zerop (value
))
5515 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5516 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5520 if (!initializer_zerop (TREE_REALPART (value
)))
5522 if (!initializer_zerop (TREE_IMAGPART (value
)))
5530 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5532 tree v
= VECTOR_CST_ELT (value
, i
);
5533 if (!initializer_zerop (v
))
5542 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5543 nz_elts
+= mult
* tc
;
5544 init_elts
+= mult
* tc
;
5546 if (const_from_elts_p
&& const_p
)
5547 const_p
= initializer_constant_valid_p (value
, elt_type
)
5554 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5555 num_fields
, elt_type
))
5556 *p_complete
= false;
5558 *p_nz_elts
+= nz_elts
;
5559 *p_init_elts
+= init_elts
;
5564 /* Examine CTOR to discover:
5565 * how many scalar fields are set to nonzero values,
5566 and place it in *P_NZ_ELTS;
5567 * how many scalar fields in total are in CTOR,
5568 and place it in *P_ELT_COUNT.
5569 * whether the constructor is complete -- in the sense that every
5570 meaningful byte is explicitly given a value --
5571 and place it in *P_COMPLETE.
5573 Return whether or not CTOR is a valid static constant initializer, the same
5574 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5577 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5578 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5584 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5587 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5588 of which had type LAST_TYPE. Each element was itself a complete
5589 initializer, in the sense that every meaningful byte was explicitly
5590 given a value. Return true if the same is true for the constructor
5594 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5595 const_tree last_type
)
5597 if (TREE_CODE (type
) == UNION_TYPE
5598 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5603 gcc_assert (num_elts
== 1 && last_type
);
5605 /* ??? We could look at each element of the union, and find the
5606 largest element. Which would avoid comparing the size of the
5607 initialized element against any tail padding in the union.
5608 Doesn't seem worth the effort... */
5609 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5612 return count_type_elements (type
, true) == num_elts
;
5615 /* Return 1 if EXP contains mostly (3/4) zeros. */
5618 mostly_zeros_p (const_tree exp
)
5620 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5622 HOST_WIDE_INT nz_elts
, init_elts
;
5625 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5626 return !complete_p
|| nz_elts
< init_elts
/ 4;
5629 return initializer_zerop (exp
);
5632 /* Return 1 if EXP contains all zeros. */
5635 all_zeros_p (const_tree exp
)
5637 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5639 HOST_WIDE_INT nz_elts
, init_elts
;
5642 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5643 return nz_elts
== 0;
5646 return initializer_zerop (exp
);
5649 /* Helper function for store_constructor.
5650 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5651 TYPE is the type of the CONSTRUCTOR, not the element type.
5652 CLEARED is as for store_constructor.
5653 ALIAS_SET is the alias set to use for any stores.
5655 This provides a recursive shortcut back to store_constructor when it isn't
5656 necessary to go through store_field. This is so that we can pass through
5657 the cleared field to let store_constructor know that we may not have to
5658 clear a substructure if the outer structure has already been cleared. */
5661 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5662 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5663 tree exp
, tree type
, int cleared
,
5664 alias_set_type alias_set
)
5666 if (TREE_CODE (exp
) == CONSTRUCTOR
5667 /* We can only call store_constructor recursively if the size and
5668 bit position are on a byte boundary. */
5669 && bitpos
% BITS_PER_UNIT
== 0
5670 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5671 /* If we have a nonzero bitpos for a register target, then we just
5672 let store_field do the bitfield handling. This is unlikely to
5673 generate unnecessary clear instructions anyways. */
5674 && (bitpos
== 0 || MEM_P (target
)))
5678 = adjust_address (target
,
5679 GET_MODE (target
) == BLKmode
5681 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5682 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5685 /* Update the alias set, if required. */
5686 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5687 && MEM_ALIAS_SET (target
) != 0)
5689 target
= copy_rtx (target
);
5690 set_mem_alias_set (target
, alias_set
);
5693 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5696 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, type
, alias_set
,
5700 /* Store the value of constructor EXP into the rtx TARGET.
5701 TARGET is either a REG or a MEM; we know it cannot conflict, since
5702 safe_from_p has been called.
5703 CLEARED is true if TARGET is known to have been zero'd.
5704 SIZE is the number of bytes of TARGET we are allowed to modify: this
5705 may not be the same as the size of EXP if we are assigning to a field
5706 which has been packed to exclude padding bits. */
5709 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5711 tree type
= TREE_TYPE (exp
);
5712 #ifdef WORD_REGISTER_OPERATIONS
5713 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5716 switch (TREE_CODE (type
))
5720 case QUAL_UNION_TYPE
:
5722 unsigned HOST_WIDE_INT idx
;
5725 /* If size is zero or the target is already cleared, do nothing. */
5726 if (size
== 0 || cleared
)
5728 /* We either clear the aggregate or indicate the value is dead. */
5729 else if ((TREE_CODE (type
) == UNION_TYPE
5730 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5731 && ! CONSTRUCTOR_ELTS (exp
))
5732 /* If the constructor is empty, clear the union. */
5734 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5738 /* If we are building a static constructor into a register,
5739 set the initial value as zero so we can fold the value into
5740 a constant. But if more than one register is involved,
5741 this probably loses. */
5742 else if (REG_P (target
) && TREE_STATIC (exp
)
5743 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5745 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5749 /* If the constructor has fewer fields than the structure or
5750 if we are initializing the structure to mostly zeros, clear
5751 the whole structure first. Don't do this if TARGET is a
5752 register whose mode size isn't equal to SIZE since
5753 clear_storage can't handle this case. */
5755 && (((int)VEC_length (constructor_elt
, CONSTRUCTOR_ELTS (exp
))
5756 != fields_length (type
))
5757 || mostly_zeros_p (exp
))
5759 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5762 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5766 if (REG_P (target
) && !cleared
)
5767 emit_clobber (target
);
5769 /* Store each element of the constructor into the
5770 corresponding field of TARGET. */
5771 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5773 enum machine_mode mode
;
5774 HOST_WIDE_INT bitsize
;
5775 HOST_WIDE_INT bitpos
= 0;
5777 rtx to_rtx
= target
;
5779 /* Just ignore missing fields. We cleared the whole
5780 structure, above, if any fields are missing. */
5784 if (cleared
&& initializer_zerop (value
))
5787 if (host_integerp (DECL_SIZE (field
), 1))
5788 bitsize
= tree_low_cst (DECL_SIZE (field
), 1);
5792 mode
= DECL_MODE (field
);
5793 if (DECL_BIT_FIELD (field
))
5796 offset
= DECL_FIELD_OFFSET (field
);
5797 if (host_integerp (offset
, 0)
5798 && host_integerp (bit_position (field
), 0))
5800 bitpos
= int_bit_position (field
);
5804 bitpos
= tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 0);
5808 enum machine_mode address_mode
;
5812 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5813 make_tree (TREE_TYPE (exp
),
5816 offset_rtx
= expand_normal (offset
);
5817 gcc_assert (MEM_P (to_rtx
));
5820 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (to_rtx
));
5821 if (GET_MODE (offset_rtx
) != address_mode
)
5822 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5824 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5825 highest_pow2_factor (offset
));
5828 #ifdef WORD_REGISTER_OPERATIONS
5829 /* If this initializes a field that is smaller than a
5830 word, at the start of a word, try to widen it to a full
5831 word. This special case allows us to output C++ member
5832 function initializations in a form that the optimizers
5835 && bitsize
< BITS_PER_WORD
5836 && bitpos
% BITS_PER_WORD
== 0
5837 && GET_MODE_CLASS (mode
) == MODE_INT
5838 && TREE_CODE (value
) == INTEGER_CST
5840 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
5842 tree type
= TREE_TYPE (value
);
5844 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
5846 type
= lang_hooks
.types
.type_for_mode
5847 (word_mode
, TYPE_UNSIGNED (type
));
5848 value
= fold_convert (type
, value
);
5851 if (BYTES_BIG_ENDIAN
)
5853 = fold_build2 (LSHIFT_EXPR
, type
, value
,
5854 build_int_cst (type
,
5855 BITS_PER_WORD
- bitsize
));
5856 bitsize
= BITS_PER_WORD
;
5861 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
5862 && DECL_NONADDRESSABLE_P (field
))
5864 to_rtx
= copy_rtx (to_rtx
);
5865 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
5868 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
5869 value
, type
, cleared
,
5870 get_alias_set (TREE_TYPE (field
)));
5877 unsigned HOST_WIDE_INT i
;
5880 tree elttype
= TREE_TYPE (type
);
5882 HOST_WIDE_INT minelt
= 0;
5883 HOST_WIDE_INT maxelt
= 0;
5885 domain
= TYPE_DOMAIN (type
);
5886 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
5887 && TYPE_MAX_VALUE (domain
)
5888 && host_integerp (TYPE_MIN_VALUE (domain
), 0)
5889 && host_integerp (TYPE_MAX_VALUE (domain
), 0));
5891 /* If we have constant bounds for the range of the type, get them. */
5894 minelt
= tree_low_cst (TYPE_MIN_VALUE (domain
), 0);
5895 maxelt
= tree_low_cst (TYPE_MAX_VALUE (domain
), 0);
5898 /* If the constructor has fewer elements than the array, clear
5899 the whole array first. Similarly if this is static
5900 constructor of a non-BLKmode object. */
5903 else if (REG_P (target
) && TREE_STATIC (exp
))
5907 unsigned HOST_WIDE_INT idx
;
5909 HOST_WIDE_INT count
= 0, zero_count
= 0;
5910 need_to_clear
= ! const_bounds_p
;
5912 /* This loop is a more accurate version of the loop in
5913 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5914 is also needed to check for missing elements. */
5915 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
5917 HOST_WIDE_INT this_node_count
;
5922 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
5924 tree lo_index
= TREE_OPERAND (index
, 0);
5925 tree hi_index
= TREE_OPERAND (index
, 1);
5927 if (! host_integerp (lo_index
, 1)
5928 || ! host_integerp (hi_index
, 1))
5934 this_node_count
= (tree_low_cst (hi_index
, 1)
5935 - tree_low_cst (lo_index
, 1) + 1);
5938 this_node_count
= 1;
5940 count
+= this_node_count
;
5941 if (mostly_zeros_p (value
))
5942 zero_count
+= this_node_count
;
5945 /* Clear the entire array first if there are any missing
5946 elements, or if the incidence of zero elements is >=
5949 && (count
< maxelt
- minelt
+ 1
5950 || 4 * zero_count
>= 3 * count
))
5954 if (need_to_clear
&& size
> 0)
5957 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5959 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5963 if (!cleared
&& REG_P (target
))
5964 /* Inform later passes that the old value is dead. */
5965 emit_clobber (target
);
5967 /* Store each element of the constructor into the
5968 corresponding element of TARGET, determined by counting the
5970 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
5972 enum machine_mode mode
;
5973 HOST_WIDE_INT bitsize
;
5974 HOST_WIDE_INT bitpos
;
5975 rtx xtarget
= target
;
5977 if (cleared
&& initializer_zerop (value
))
5980 mode
= TYPE_MODE (elttype
);
5981 if (mode
== BLKmode
)
5982 bitsize
= (host_integerp (TYPE_SIZE (elttype
), 1)
5983 ? tree_low_cst (TYPE_SIZE (elttype
), 1)
5986 bitsize
= GET_MODE_BITSIZE (mode
);
5988 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
5990 tree lo_index
= TREE_OPERAND (index
, 0);
5991 tree hi_index
= TREE_OPERAND (index
, 1);
5992 rtx index_r
, pos_rtx
;
5993 HOST_WIDE_INT lo
, hi
, count
;
5996 /* If the range is constant and "small", unroll the loop. */
5998 && host_integerp (lo_index
, 0)
5999 && host_integerp (hi_index
, 0)
6000 && (lo
= tree_low_cst (lo_index
, 0),
6001 hi
= tree_low_cst (hi_index
, 0),
6002 count
= hi
- lo
+ 1,
6005 || (host_integerp (TYPE_SIZE (elttype
), 1)
6006 && (tree_low_cst (TYPE_SIZE (elttype
), 1) * count
6009 lo
-= minelt
; hi
-= minelt
;
6010 for (; lo
<= hi
; lo
++)
6012 bitpos
= lo
* tree_low_cst (TYPE_SIZE (elttype
), 0);
6015 && !MEM_KEEP_ALIAS_SET_P (target
)
6016 && TREE_CODE (type
) == ARRAY_TYPE
6017 && TYPE_NONALIASED_COMPONENT (type
))
6019 target
= copy_rtx (target
);
6020 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6023 store_constructor_field
6024 (target
, bitsize
, bitpos
, mode
, value
, type
, cleared
,
6025 get_alias_set (elttype
));
6030 rtx loop_start
= gen_label_rtx ();
6031 rtx loop_end
= gen_label_rtx ();
6034 expand_normal (hi_index
);
6036 index
= build_decl (EXPR_LOCATION (exp
),
6037 VAR_DECL
, NULL_TREE
, domain
);
6038 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6039 SET_DECL_RTL (index
, index_r
);
6040 store_expr (lo_index
, index_r
, 0, false);
6042 /* Build the head of the loop. */
6043 do_pending_stack_adjust ();
6044 emit_label (loop_start
);
6046 /* Assign value to element index. */
6048 fold_convert (ssizetype
,
6049 fold_build2 (MINUS_EXPR
,
6052 TYPE_MIN_VALUE (domain
)));
6055 size_binop (MULT_EXPR
, position
,
6056 fold_convert (ssizetype
,
6057 TYPE_SIZE_UNIT (elttype
)));
6059 pos_rtx
= expand_normal (position
);
6060 xtarget
= offset_address (target
, pos_rtx
,
6061 highest_pow2_factor (position
));
6062 xtarget
= adjust_address (xtarget
, mode
, 0);
6063 if (TREE_CODE (value
) == CONSTRUCTOR
)
6064 store_constructor (value
, xtarget
, cleared
,
6065 bitsize
/ BITS_PER_UNIT
);
6067 store_expr (value
, xtarget
, 0, false);
6069 /* Generate a conditional jump to exit the loop. */
6070 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6072 jumpif (exit_cond
, loop_end
, -1);
6074 /* Update the loop counter, and jump to the head of
6076 expand_assignment (index
,
6077 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6078 index
, integer_one_node
),
6081 emit_jump (loop_start
);
6083 /* Build the end of the loop. */
6084 emit_label (loop_end
);
6087 else if ((index
!= 0 && ! host_integerp (index
, 0))
6088 || ! host_integerp (TYPE_SIZE (elttype
), 1))
6093 index
= ssize_int (1);
6096 index
= fold_convert (ssizetype
,
6097 fold_build2 (MINUS_EXPR
,
6100 TYPE_MIN_VALUE (domain
)));
6103 size_binop (MULT_EXPR
, index
,
6104 fold_convert (ssizetype
,
6105 TYPE_SIZE_UNIT (elttype
)));
6106 xtarget
= offset_address (target
,
6107 expand_normal (position
),
6108 highest_pow2_factor (position
));
6109 xtarget
= adjust_address (xtarget
, mode
, 0);
6110 store_expr (value
, xtarget
, 0, false);
6115 bitpos
= ((tree_low_cst (index
, 0) - minelt
)
6116 * tree_low_cst (TYPE_SIZE (elttype
), 1));
6118 bitpos
= (i
* tree_low_cst (TYPE_SIZE (elttype
), 1));
6120 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6121 && TREE_CODE (type
) == ARRAY_TYPE
6122 && TYPE_NONALIASED_COMPONENT (type
))
6124 target
= copy_rtx (target
);
6125 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6127 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6128 type
, cleared
, get_alias_set (elttype
));
6136 unsigned HOST_WIDE_INT idx
;
6137 constructor_elt
*ce
;
6141 tree elttype
= TREE_TYPE (type
);
6142 int elt_size
= tree_low_cst (TYPE_SIZE (elttype
), 1);
6143 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6144 HOST_WIDE_INT bitsize
;
6145 HOST_WIDE_INT bitpos
;
6146 rtvec vector
= NULL
;
6148 alias_set_type alias
;
6150 gcc_assert (eltmode
!= BLKmode
);
6152 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6153 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6155 enum machine_mode mode
= GET_MODE (target
);
6157 icode
= (int) optab_handler (vec_init_optab
, mode
);
6158 if (icode
!= CODE_FOR_nothing
)
6162 vector
= rtvec_alloc (n_elts
);
6163 for (i
= 0; i
< n_elts
; i
++)
6164 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6168 /* If the constructor has fewer elements than the vector,
6169 clear the whole array first. Similarly if this is static
6170 constructor of a non-BLKmode object. */
6173 else if (REG_P (target
) && TREE_STATIC (exp
))
6177 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6180 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6182 int n_elts_here
= tree_low_cst
6183 (int_const_binop (TRUNC_DIV_EXPR
,
6184 TYPE_SIZE (TREE_TYPE (value
)),
6185 TYPE_SIZE (elttype
)), 1);
6187 count
+= n_elts_here
;
6188 if (mostly_zeros_p (value
))
6189 zero_count
+= n_elts_here
;
6192 /* Clear the entire vector first if there are any missing elements,
6193 or if the incidence of zero elements is >= 75%. */
6194 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6197 if (need_to_clear
&& size
> 0 && !vector
)
6200 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6202 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6206 /* Inform later passes that the old value is dead. */
6207 if (!cleared
&& !vector
&& REG_P (target
))
6208 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6211 alias
= MEM_ALIAS_SET (target
);
6213 alias
= get_alias_set (elttype
);
6215 /* Store each element of the constructor into the corresponding
6216 element of TARGET, determined by counting the elements. */
6217 for (idx
= 0, i
= 0;
6218 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
);
6219 idx
++, i
+= bitsize
/ elt_size
)
6221 HOST_WIDE_INT eltpos
;
6222 tree value
= ce
->value
;
6224 bitsize
= tree_low_cst (TYPE_SIZE (TREE_TYPE (value
)), 1);
6225 if (cleared
&& initializer_zerop (value
))
6229 eltpos
= tree_low_cst (ce
->index
, 1);
6235 /* Vector CONSTRUCTORs should only be built from smaller
6236 vectors in the case of BLKmode vectors. */
6237 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6238 RTVEC_ELT (vector
, eltpos
)
6239 = expand_normal (value
);
6243 enum machine_mode value_mode
=
6244 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6245 ? TYPE_MODE (TREE_TYPE (value
))
6247 bitpos
= eltpos
* elt_size
;
6248 store_constructor_field (target
, bitsize
, bitpos
,
6249 value_mode
, value
, type
,
6255 emit_insn (GEN_FCN (icode
)
6257 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6266 /* Store the value of EXP (an expression tree)
6267 into a subfield of TARGET which has mode MODE and occupies
6268 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6269 If MODE is VOIDmode, it means that we are storing into a bit-field.
6271 BITREGION_START is bitpos of the first bitfield in this region.
6272 BITREGION_END is the bitpos of the ending bitfield in this region.
6273 These two fields are 0, if the C++ memory model does not apply,
6274 or we are not interested in keeping track of bitfield regions.
6276 Always return const0_rtx unless we have something particular to
6279 TYPE is the type of the underlying object,
6281 ALIAS_SET is the alias set for the destination. This value will
6282 (in general) be different from that for TARGET, since TARGET is a
6283 reference to the containing structure.
6285 If NONTEMPORAL is true, try generating a nontemporal store. */
6288 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6289 unsigned HOST_WIDE_INT bitregion_start
,
6290 unsigned HOST_WIDE_INT bitregion_end
,
6291 enum machine_mode mode
, tree exp
, tree type
,
6292 alias_set_type alias_set
, bool nontemporal
)
6294 if (TREE_CODE (exp
) == ERROR_MARK
)
6297 /* If we have nothing to store, do nothing unless the expression has
6300 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6302 /* If we are storing into an unaligned field of an aligned union that is
6303 in a register, we may have the mode of TARGET being an integer mode but
6304 MODE == BLKmode. In that case, get an aligned object whose size and
6305 alignment are the same as TARGET and store TARGET into it (we can avoid
6306 the store if the field being stored is the entire width of TARGET). Then
6307 call ourselves recursively to store the field into a BLKmode version of
6308 that object. Finally, load from the object into TARGET. This is not
6309 very efficient in general, but should only be slightly more expensive
6310 than the otherwise-required unaligned accesses. Perhaps this can be
6311 cleaned up later. It's tempting to make OBJECT readonly, but it's set
6312 twice, once with emit_move_insn and once via store_field. */
6315 && (REG_P (target
) || GET_CODE (target
) == SUBREG
))
6317 rtx object
= assign_temp (type
, 0, 1, 1);
6318 rtx blk_object
= adjust_address (object
, BLKmode
, 0);
6320 if (bitsize
!= (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (target
)))
6321 emit_move_insn (object
, target
);
6323 store_field (blk_object
, bitsize
, bitpos
,
6324 bitregion_start
, bitregion_end
,
6325 mode
, exp
, type
, MEM_ALIAS_SET (blk_object
), nontemporal
);
6327 emit_move_insn (target
, object
);
6329 /* We want to return the BLKmode version of the data. */
6333 if (GET_CODE (target
) == CONCAT
)
6335 /* We're storing into a struct containing a single __complex. */
6337 gcc_assert (!bitpos
);
6338 return store_expr (exp
, target
, 0, nontemporal
);
6341 /* If the structure is in a register or if the component
6342 is a bit field, we cannot use addressing to access it.
6343 Use bit-field techniques or SUBREG to store in it. */
6345 if (mode
== VOIDmode
6346 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6347 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6348 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6350 || GET_CODE (target
) == SUBREG
6351 /* If the field isn't aligned enough to store as an ordinary memref,
6352 store it as a bit field. */
6354 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6355 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6356 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6357 || (bitpos
% BITS_PER_UNIT
!= 0)))
6358 || (bitsize
>= 0 && mode
!= BLKmode
6359 && GET_MODE_BITSIZE (mode
) > bitsize
)
6360 /* If the RHS and field are a constant size and the size of the
6361 RHS isn't the same size as the bitfield, we must use bitfield
6364 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6365 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6366 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6367 decl we must use bitfield operations. */
6369 && TREE_CODE (exp
) == MEM_REF
6370 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6371 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6372 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6373 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6378 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6379 implies a mask operation. If the precision is the same size as
6380 the field we're storing into, that mask is redundant. This is
6381 particularly common with bit field assignments generated by the
6383 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6386 tree type
= TREE_TYPE (exp
);
6387 if (INTEGRAL_TYPE_P (type
)
6388 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6389 && bitsize
== TYPE_PRECISION (type
))
6391 tree op
= gimple_assign_rhs1 (nop_def
);
6392 type
= TREE_TYPE (op
);
6393 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6398 temp
= expand_normal (exp
);
6400 /* If BITSIZE is narrower than the size of the type of EXP
6401 we will be narrowing TEMP. Normally, what's wanted are the
6402 low-order bits. However, if EXP's type is a record and this is
6403 big-endian machine, we want the upper BITSIZE bits. */
6404 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6405 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6406 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6407 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6408 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6411 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6412 if (mode
!= VOIDmode
&& mode
!= BLKmode
6413 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6414 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6416 /* If the modes of TEMP and TARGET are both BLKmode, both
6417 must be in memory and BITPOS must be aligned on a byte
6418 boundary. If so, we simply do a block copy. Likewise
6419 for a BLKmode-like TARGET. */
6420 if (GET_MODE (temp
) == BLKmode
6421 && (GET_MODE (target
) == BLKmode
6423 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6424 && (bitpos
% BITS_PER_UNIT
) == 0
6425 && (bitsize
% BITS_PER_UNIT
) == 0)))
6427 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6428 && (bitpos
% BITS_PER_UNIT
) == 0);
6430 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6431 emit_block_move (target
, temp
,
6432 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6439 /* Store the value in the bitfield. */
6440 store_bit_field (target
, bitsize
, bitpos
,
6441 bitregion_start
, bitregion_end
,
6448 /* Now build a reference to just the desired component. */
6449 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6451 if (to_rtx
== target
)
6452 to_rtx
= copy_rtx (to_rtx
);
6454 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6455 set_mem_alias_set (to_rtx
, alias_set
);
6457 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6461 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6462 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6463 codes and find the ultimate containing object, which we return.
6465 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6466 bit position, and *PUNSIGNEDP to the signedness of the field.
6467 If the position of the field is variable, we store a tree
6468 giving the variable offset (in units) in *POFFSET.
6469 This offset is in addition to the bit position.
6470 If the position is not variable, we store 0 in *POFFSET.
6472 If any of the extraction expressions is volatile,
6473 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6475 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6476 Otherwise, it is a mode that can be used to access the field.
6478 If the field describes a variable-sized object, *PMODE is set to
6479 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6480 this case, but the address of the object can be found.
6482 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6483 look through nodes that serve as markers of a greater alignment than
6484 the one that can be deduced from the expression. These nodes make it
6485 possible for front-ends to prevent temporaries from being created by
6486 the middle-end on alignment considerations. For that purpose, the
6487 normal operating mode at high-level is to always pass FALSE so that
6488 the ultimate containing object is really returned; moreover, the
6489 associated predicate handled_component_p will always return TRUE
6490 on these nodes, thus indicating that they are essentially handled
6491 by get_inner_reference. TRUE should only be passed when the caller
6492 is scanning the expression in order to build another representation
6493 and specifically knows how to handle these nodes; as such, this is
6494 the normal operating mode in the RTL expanders. */
6497 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6498 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6499 enum machine_mode
*pmode
, int *punsignedp
,
6500 int *pvolatilep
, bool keep_aligning
)
6503 enum machine_mode mode
= VOIDmode
;
6504 bool blkmode_bitfield
= false;
6505 tree offset
= size_zero_node
;
6506 double_int bit_offset
= double_int_zero
;
6508 /* First get the mode, signedness, and size. We do this from just the
6509 outermost expression. */
6511 if (TREE_CODE (exp
) == COMPONENT_REF
)
6513 tree field
= TREE_OPERAND (exp
, 1);
6514 size_tree
= DECL_SIZE (field
);
6515 if (!DECL_BIT_FIELD (field
))
6516 mode
= DECL_MODE (field
);
6517 else if (DECL_MODE (field
) == BLKmode
)
6518 blkmode_bitfield
= true;
6519 else if (TREE_THIS_VOLATILE (exp
)
6520 && flag_strict_volatile_bitfields
> 0)
6521 /* Volatile bitfields should be accessed in the mode of the
6522 field's type, not the mode computed based on the bit
6524 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6526 *punsignedp
= DECL_UNSIGNED (field
);
6528 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6530 size_tree
= TREE_OPERAND (exp
, 1);
6531 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6532 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6534 /* For vector types, with the correct size of access, use the mode of
6536 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6537 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6538 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6539 mode
= TYPE_MODE (TREE_TYPE (exp
));
6543 mode
= TYPE_MODE (TREE_TYPE (exp
));
6544 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6546 if (mode
== BLKmode
)
6547 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6549 *pbitsize
= GET_MODE_BITSIZE (mode
);
6554 if (! host_integerp (size_tree
, 1))
6555 mode
= BLKmode
, *pbitsize
= -1;
6557 *pbitsize
= tree_low_cst (size_tree
, 1);
6560 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6561 and find the ultimate containing object. */
6564 switch (TREE_CODE (exp
))
6568 = double_int_add (bit_offset
,
6569 tree_to_double_int (TREE_OPERAND (exp
, 2)));
6574 tree field
= TREE_OPERAND (exp
, 1);
6575 tree this_offset
= component_ref_field_offset (exp
);
6577 /* If this field hasn't been filled in yet, don't go past it.
6578 This should only happen when folding expressions made during
6579 type construction. */
6580 if (this_offset
== 0)
6583 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6584 bit_offset
= double_int_add (bit_offset
,
6586 (DECL_FIELD_BIT_OFFSET (field
)));
6588 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6593 case ARRAY_RANGE_REF
:
6595 tree index
= TREE_OPERAND (exp
, 1);
6596 tree low_bound
= array_ref_low_bound (exp
);
6597 tree unit_size
= array_ref_element_size (exp
);
6599 /* We assume all arrays have sizes that are a multiple of a byte.
6600 First subtract the lower bound, if any, in the type of the
6601 index, then convert to sizetype and multiply by the size of
6602 the array element. */
6603 if (! integer_zerop (low_bound
))
6604 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6607 offset
= size_binop (PLUS_EXPR
, offset
,
6608 size_binop (MULT_EXPR
,
6609 fold_convert (sizetype
, index
),
6618 bit_offset
= double_int_add (bit_offset
,
6619 uhwi_to_double_int (*pbitsize
));
6622 case VIEW_CONVERT_EXPR
:
6623 if (keep_aligning
&& STRICT_ALIGNMENT
6624 && (TYPE_ALIGN (TREE_TYPE (exp
))
6625 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6626 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6627 < BIGGEST_ALIGNMENT
)
6628 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6629 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6634 /* Hand back the decl for MEM[&decl, off]. */
6635 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6637 tree off
= TREE_OPERAND (exp
, 1);
6638 if (!integer_zerop (off
))
6640 double_int boff
, coff
= mem_ref_offset (exp
);
6641 boff
= double_int_lshift (coff
,
6643 ? 3 : exact_log2 (BITS_PER_UNIT
),
6644 HOST_BITS_PER_DOUBLE_INT
, true);
6645 bit_offset
= double_int_add (bit_offset
, boff
);
6647 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6655 /* If any reference in the chain is volatile, the effect is volatile. */
6656 if (TREE_THIS_VOLATILE (exp
))
6659 exp
= TREE_OPERAND (exp
, 0);
6663 /* If OFFSET is constant, see if we can return the whole thing as a
6664 constant bit position. Make sure to handle overflow during
6666 if (TREE_CODE (offset
) == INTEGER_CST
)
6668 double_int tem
= tree_to_double_int (offset
);
6669 tem
= double_int_sext (tem
, TYPE_PRECISION (sizetype
));
6670 tem
= double_int_lshift (tem
,
6672 ? 3 : exact_log2 (BITS_PER_UNIT
),
6673 HOST_BITS_PER_DOUBLE_INT
, true);
6674 tem
= double_int_add (tem
, bit_offset
);
6675 if (double_int_fits_in_shwi_p (tem
))
6677 *pbitpos
= double_int_to_shwi (tem
);
6678 *poffset
= offset
= NULL_TREE
;
6682 /* Otherwise, split it up. */
6685 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6686 if (double_int_negative_p (bit_offset
))
6689 = double_int_mask (BITS_PER_UNIT
== 8
6690 ? 3 : exact_log2 (BITS_PER_UNIT
));
6691 double_int tem
= double_int_and_not (bit_offset
, mask
);
6692 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6693 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6694 bit_offset
= double_int_sub (bit_offset
, tem
);
6695 tem
= double_int_rshift (tem
,
6697 ? 3 : exact_log2 (BITS_PER_UNIT
),
6698 HOST_BITS_PER_DOUBLE_INT
, true);
6699 offset
= size_binop (PLUS_EXPR
, offset
,
6700 double_int_to_tree (sizetype
, tem
));
6703 *pbitpos
= double_int_to_shwi (bit_offset
);
6707 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6708 if (mode
== VOIDmode
6710 && (*pbitpos
% BITS_PER_UNIT
) == 0
6711 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6719 /* Given an expression EXP that may be a COMPONENT_REF, an ARRAY_REF or an
6720 ARRAY_RANGE_REF, look for whether EXP or any nested component-refs within
6721 EXP is marked as PACKED. */
6724 contains_packed_reference (const_tree exp
)
6726 bool packed_p
= false;
6730 switch (TREE_CODE (exp
))
6734 tree field
= TREE_OPERAND (exp
, 1);
6735 packed_p
= DECL_PACKED (field
)
6736 || TYPE_PACKED (TREE_TYPE (field
))
6737 || TYPE_PACKED (TREE_TYPE (exp
));
6745 case ARRAY_RANGE_REF
:
6748 case VIEW_CONVERT_EXPR
:
6754 exp
= TREE_OPERAND (exp
, 0);
6760 /* Return a tree of sizetype representing the size, in bytes, of the element
6761 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6764 array_ref_element_size (tree exp
)
6766 tree aligned_size
= TREE_OPERAND (exp
, 3);
6767 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6768 location_t loc
= EXPR_LOCATION (exp
);
6770 /* If a size was specified in the ARRAY_REF, it's the size measured
6771 in alignment units of the element type. So multiply by that value. */
6774 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6775 sizetype from another type of the same width and signedness. */
6776 if (TREE_TYPE (aligned_size
) != sizetype
)
6777 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6778 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6779 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6782 /* Otherwise, take the size from that of the element type. Substitute
6783 any PLACEHOLDER_EXPR that we have. */
6785 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6788 /* Return a tree representing the lower bound of the array mentioned in
6789 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6792 array_ref_low_bound (tree exp
)
6794 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6796 /* If a lower bound is specified in EXP, use it. */
6797 if (TREE_OPERAND (exp
, 2))
6798 return TREE_OPERAND (exp
, 2);
6800 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6801 substituting for a PLACEHOLDER_EXPR as needed. */
6802 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6803 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6805 /* Otherwise, return a zero of the appropriate type. */
6806 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6809 /* Returns true if REF is an array reference to an array at the end of
6810 a structure. If this is the case, the array may be allocated larger
6811 than its upper bound implies. */
6814 array_at_struct_end_p (tree ref
)
6816 if (TREE_CODE (ref
) != ARRAY_REF
6817 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6820 while (handled_component_p (ref
))
6822 /* If the reference chain contains a component reference to a
6823 non-union type and there follows another field the reference
6824 is not at the end of a structure. */
6825 if (TREE_CODE (ref
) == COMPONENT_REF
6826 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6828 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6829 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6830 nextf
= DECL_CHAIN (nextf
);
6835 ref
= TREE_OPERAND (ref
, 0);
6838 /* If the reference is based on a declared entity, the size of the array
6839 is constrained by its given domain. */
6846 /* Return a tree representing the upper bound of the array mentioned in
6847 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6850 array_ref_up_bound (tree exp
)
6852 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6854 /* If there is a domain type and it has an upper bound, use it, substituting
6855 for a PLACEHOLDER_EXPR as needed. */
6856 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6857 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6859 /* Otherwise fail. */
6863 /* Return a tree representing the offset, in bytes, of the field referenced
6864 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6867 component_ref_field_offset (tree exp
)
6869 tree aligned_offset
= TREE_OPERAND (exp
, 2);
6870 tree field
= TREE_OPERAND (exp
, 1);
6871 location_t loc
= EXPR_LOCATION (exp
);
6873 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6874 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6878 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6879 sizetype from another type of the same width and signedness. */
6880 if (TREE_TYPE (aligned_offset
) != sizetype
)
6881 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
6882 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
6883 size_int (DECL_OFFSET_ALIGN (field
)
6887 /* Otherwise, take the offset from that of the field. Substitute
6888 any PLACEHOLDER_EXPR that we have. */
6890 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
6893 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6895 static unsigned HOST_WIDE_INT
6896 target_align (const_tree target
)
6898 /* We might have a chain of nested references with intermediate misaligning
6899 bitfields components, so need to recurse to find out. */
6901 unsigned HOST_WIDE_INT this_align
, outer_align
;
6903 switch (TREE_CODE (target
))
6909 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
6910 outer_align
= target_align (TREE_OPERAND (target
, 0));
6911 return MIN (this_align
, outer_align
);
6914 case ARRAY_RANGE_REF
:
6915 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6916 outer_align
= target_align (TREE_OPERAND (target
, 0));
6917 return MIN (this_align
, outer_align
);
6920 case NON_LVALUE_EXPR
:
6921 case VIEW_CONVERT_EXPR
:
6922 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6923 outer_align
= target_align (TREE_OPERAND (target
, 0));
6924 return MAX (this_align
, outer_align
);
6927 return TYPE_ALIGN (TREE_TYPE (target
));
6932 /* Given an rtx VALUE that may contain additions and multiplications, return
6933 an equivalent value that just refers to a register, memory, or constant.
6934 This is done by generating instructions to perform the arithmetic and
6935 returning a pseudo-register containing the value.
6937 The returned value may be a REG, SUBREG, MEM or constant. */
6940 force_operand (rtx value
, rtx target
)
6943 /* Use subtarget as the target for operand 0 of a binary operation. */
6944 rtx subtarget
= get_subtarget (target
);
6945 enum rtx_code code
= GET_CODE (value
);
6947 /* Check for subreg applied to an expression produced by loop optimizer. */
6949 && !REG_P (SUBREG_REG (value
))
6950 && !MEM_P (SUBREG_REG (value
)))
6953 = simplify_gen_subreg (GET_MODE (value
),
6954 force_reg (GET_MODE (SUBREG_REG (value
)),
6955 force_operand (SUBREG_REG (value
),
6957 GET_MODE (SUBREG_REG (value
)),
6958 SUBREG_BYTE (value
));
6959 code
= GET_CODE (value
);
6962 /* Check for a PIC address load. */
6963 if ((code
== PLUS
|| code
== MINUS
)
6964 && XEXP (value
, 0) == pic_offset_table_rtx
6965 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
6966 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
6967 || GET_CODE (XEXP (value
, 1)) == CONST
))
6970 subtarget
= gen_reg_rtx (GET_MODE (value
));
6971 emit_move_insn (subtarget
, value
);
6975 if (ARITHMETIC_P (value
))
6977 op2
= XEXP (value
, 1);
6978 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
6980 if (code
== MINUS
&& CONST_INT_P (op2
))
6983 op2
= negate_rtx (GET_MODE (value
), op2
);
6986 /* Check for an addition with OP2 a constant integer and our first
6987 operand a PLUS of a virtual register and something else. In that
6988 case, we want to emit the sum of the virtual register and the
6989 constant first and then add the other value. This allows virtual
6990 register instantiation to simply modify the constant rather than
6991 creating another one around this addition. */
6992 if (code
== PLUS
&& CONST_INT_P (op2
)
6993 && GET_CODE (XEXP (value
, 0)) == PLUS
6994 && REG_P (XEXP (XEXP (value
, 0), 0))
6995 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
6996 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
6998 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
6999 XEXP (XEXP (value
, 0), 0), op2
,
7000 subtarget
, 0, OPTAB_LIB_WIDEN
);
7001 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7002 force_operand (XEXP (XEXP (value
,
7004 target
, 0, OPTAB_LIB_WIDEN
);
7007 op1
= force_operand (XEXP (value
, 0), subtarget
);
7008 op2
= force_operand (op2
, NULL_RTX
);
7012 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7014 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7015 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7016 target
, 1, OPTAB_LIB_WIDEN
);
7018 return expand_divmod (0,
7019 FLOAT_MODE_P (GET_MODE (value
))
7020 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7021 GET_MODE (value
), op1
, op2
, target
, 0);
7023 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7026 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7029 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7032 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7033 target
, 0, OPTAB_LIB_WIDEN
);
7035 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7036 target
, 1, OPTAB_LIB_WIDEN
);
7039 if (UNARY_P (value
))
7042 target
= gen_reg_rtx (GET_MODE (value
));
7043 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7050 case FLOAT_TRUNCATE
:
7051 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7056 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7060 case UNSIGNED_FLOAT
:
7061 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7065 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7069 #ifdef INSN_SCHEDULING
7070 /* On machines that have insn scheduling, we want all memory reference to be
7071 explicit, so we need to deal with such paradoxical SUBREGs. */
7072 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7074 = simplify_gen_subreg (GET_MODE (value
),
7075 force_reg (GET_MODE (SUBREG_REG (value
)),
7076 force_operand (SUBREG_REG (value
),
7078 GET_MODE (SUBREG_REG (value
)),
7079 SUBREG_BYTE (value
));
7085 /* Subroutine of expand_expr: return nonzero iff there is no way that
7086 EXP can reference X, which is being modified. TOP_P is nonzero if this
7087 call is going to be used to determine whether we need a temporary
7088 for EXP, as opposed to a recursive call to this function.
7090 It is always safe for this routine to return zero since it merely
7091 searches for optimization opportunities. */
7094 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7100 /* If EXP has varying size, we MUST use a target since we currently
7101 have no way of allocating temporaries of variable size
7102 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7103 So we assume here that something at a higher level has prevented a
7104 clash. This is somewhat bogus, but the best we can do. Only
7105 do this when X is BLKmode and when we are at the top level. */
7106 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7107 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7108 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7109 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7110 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7112 && GET_MODE (x
) == BLKmode
)
7113 /* If X is in the outgoing argument area, it is always safe. */
7115 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7116 || (GET_CODE (XEXP (x
, 0)) == PLUS
7117 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7120 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7121 find the underlying pseudo. */
7122 if (GET_CODE (x
) == SUBREG
)
7125 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7129 /* Now look at our tree code and possibly recurse. */
7130 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7132 case tcc_declaration
:
7133 exp_rtl
= DECL_RTL_IF_SET (exp
);
7139 case tcc_exceptional
:
7140 if (TREE_CODE (exp
) == TREE_LIST
)
7144 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7146 exp
= TREE_CHAIN (exp
);
7149 if (TREE_CODE (exp
) != TREE_LIST
)
7150 return safe_from_p (x
, exp
, 0);
7153 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7155 constructor_elt
*ce
;
7156 unsigned HOST_WIDE_INT idx
;
7158 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7159 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7160 || !safe_from_p (x
, ce
->value
, 0))
7164 else if (TREE_CODE (exp
) == ERROR_MARK
)
7165 return 1; /* An already-visited SAVE_EXPR? */
7170 /* The only case we look at here is the DECL_INITIAL inside a
7172 return (TREE_CODE (exp
) != DECL_EXPR
7173 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7174 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7175 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7178 case tcc_comparison
:
7179 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7184 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7186 case tcc_expression
:
7189 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7190 the expression. If it is set, we conflict iff we are that rtx or
7191 both are in memory. Otherwise, we check all operands of the
7192 expression recursively. */
7194 switch (TREE_CODE (exp
))
7197 /* If the operand is static or we are static, we can't conflict.
7198 Likewise if we don't conflict with the operand at all. */
7199 if (staticp (TREE_OPERAND (exp
, 0))
7200 || TREE_STATIC (exp
)
7201 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7204 /* Otherwise, the only way this can conflict is if we are taking
7205 the address of a DECL a that address if part of X, which is
7207 exp
= TREE_OPERAND (exp
, 0);
7210 if (!DECL_RTL_SET_P (exp
)
7211 || !MEM_P (DECL_RTL (exp
)))
7214 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7220 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7221 get_alias_set (exp
)))
7226 /* Assume that the call will clobber all hard registers and
7228 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7233 case WITH_CLEANUP_EXPR
:
7234 case CLEANUP_POINT_EXPR
:
7235 /* Lowered by gimplify.c. */
7239 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7245 /* If we have an rtx, we do not need to scan our operands. */
7249 nops
= TREE_OPERAND_LENGTH (exp
);
7250 for (i
= 0; i
< nops
; i
++)
7251 if (TREE_OPERAND (exp
, i
) != 0
7252 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7258 /* Should never get a type here. */
7262 /* If we have an rtl, find any enclosed object. Then see if we conflict
7266 if (GET_CODE (exp_rtl
) == SUBREG
)
7268 exp_rtl
= SUBREG_REG (exp_rtl
);
7270 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7274 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7275 are memory and they conflict. */
7276 return ! (rtx_equal_p (x
, exp_rtl
)
7277 || (MEM_P (x
) && MEM_P (exp_rtl
)
7278 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7281 /* If we reach here, it is safe. */
7286 /* Return the highest power of two that EXP is known to be a multiple of.
7287 This is used in updating alignment of MEMs in array references. */
7289 unsigned HOST_WIDE_INT
7290 highest_pow2_factor (const_tree exp
)
7292 unsigned HOST_WIDE_INT c0
, c1
;
7294 switch (TREE_CODE (exp
))
7297 /* We can find the lowest bit that's a one. If the low
7298 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
7299 We need to handle this case since we can find it in a COND_EXPR,
7300 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
7301 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
7303 if (TREE_OVERFLOW (exp
))
7304 return BIGGEST_ALIGNMENT
;
7307 /* Note: tree_low_cst is intentionally not used here,
7308 we don't care about the upper bits. */
7309 c0
= TREE_INT_CST_LOW (exp
);
7311 return c0
? c0
: BIGGEST_ALIGNMENT
;
7315 case PLUS_EXPR
: case MINUS_EXPR
: case MIN_EXPR
: case MAX_EXPR
:
7316 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7317 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7318 return MIN (c0
, c1
);
7321 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7322 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7325 case ROUND_DIV_EXPR
: case TRUNC_DIV_EXPR
: case FLOOR_DIV_EXPR
:
7327 if (integer_pow2p (TREE_OPERAND (exp
, 1))
7328 && host_integerp (TREE_OPERAND (exp
, 1), 1))
7330 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7331 c1
= tree_low_cst (TREE_OPERAND (exp
, 1), 1);
7332 return MAX (1, c0
/ c1
);
7337 /* The highest power of two of a bit-and expression is the maximum of
7338 that of its operands. We typically get here for a complex LHS and
7339 a constant negative power of two on the RHS to force an explicit
7340 alignment, so don't bother looking at the LHS. */
7341 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7345 return highest_pow2_factor (TREE_OPERAND (exp
, 0));
7348 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7351 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7352 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 2));
7353 return MIN (c0
, c1
);
7362 /* Similar, except that the alignment requirements of TARGET are
7363 taken into account. Assume it is at least as aligned as its
7364 type, unless it is a COMPONENT_REF in which case the layout of
7365 the structure gives the alignment. */
7367 static unsigned HOST_WIDE_INT
7368 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7370 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7371 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7373 return MAX (factor
, talign
);
7376 /* Convert the tree comparision code TCODE to the rtl one where the
7377 signedness is UNSIGNEDP. */
7379 static enum rtx_code
7380 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7392 code
= unsignedp
? LTU
: LT
;
7395 code
= unsignedp
? LEU
: LE
;
7398 code
= unsignedp
? GTU
: GT
;
7401 code
= unsignedp
? GEU
: GE
;
7403 case UNORDERED_EXPR
:
7434 /* Subroutine of expand_expr. Expand the two operands of a binary
7435 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7436 The value may be stored in TARGET if TARGET is nonzero. The
7437 MODIFIER argument is as documented by expand_expr. */
7440 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7441 enum expand_modifier modifier
)
7443 if (! safe_from_p (target
, exp1
, 1))
7445 if (operand_equal_p (exp0
, exp1
, 0))
7447 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7448 *op1
= copy_rtx (*op0
);
7452 /* If we need to preserve evaluation order, copy exp0 into its own
7453 temporary variable so that it can't be clobbered by exp1. */
7454 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7455 exp0
= save_expr (exp0
);
7456 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7457 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7462 /* Return a MEM that contains constant EXP. DEFER is as for
7463 output_constant_def and MODIFIER is as for expand_expr. */
7466 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7470 mem
= output_constant_def (exp
, defer
);
7471 if (modifier
!= EXPAND_INITIALIZER
)
7472 mem
= use_anchored_address (mem
);
7476 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7477 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7480 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7481 enum expand_modifier modifier
, addr_space_t as
)
7483 rtx result
, subtarget
;
7485 HOST_WIDE_INT bitsize
, bitpos
;
7486 int volatilep
, unsignedp
;
7487 enum machine_mode mode1
;
7489 /* If we are taking the address of a constant and are at the top level,
7490 we have to use output_constant_def since we can't call force_const_mem
7492 /* ??? This should be considered a front-end bug. We should not be
7493 generating ADDR_EXPR of something that isn't an LVALUE. The only
7494 exception here is STRING_CST. */
7495 if (CONSTANT_CLASS_P (exp
))
7497 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7498 if (modifier
< EXPAND_SUM
)
7499 result
= force_operand (result
, target
);
7503 /* Everything must be something allowed by is_gimple_addressable. */
7504 switch (TREE_CODE (exp
))
7507 /* This case will happen via recursion for &a->b. */
7508 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7512 tree tem
= TREE_OPERAND (exp
, 0);
7513 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7514 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7515 return expand_expr (tem
, target
, tmode
, modifier
);
7519 /* Expand the initializer like constants above. */
7520 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7522 if (modifier
< EXPAND_SUM
)
7523 result
= force_operand (result
, target
);
7527 /* The real part of the complex number is always first, therefore
7528 the address is the same as the address of the parent object. */
7531 inner
= TREE_OPERAND (exp
, 0);
7535 /* The imaginary part of the complex number is always second.
7536 The expression is therefore always offset by the size of the
7539 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7540 inner
= TREE_OPERAND (exp
, 0);
7544 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7545 expand_expr, as that can have various side effects; LABEL_DECLs for
7546 example, may not have their DECL_RTL set yet. Expand the rtl of
7547 CONSTRUCTORs too, which should yield a memory reference for the
7548 constructor's contents. Assume language specific tree nodes can
7549 be expanded in some interesting way. */
7550 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7552 || TREE_CODE (exp
) == CONSTRUCTOR
7553 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7555 result
= expand_expr (exp
, target
, tmode
,
7556 modifier
== EXPAND_INITIALIZER
7557 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7559 /* If the DECL isn't in memory, then the DECL wasn't properly
7560 marked TREE_ADDRESSABLE, which will be either a front-end
7561 or a tree optimizer bug. */
7563 if (TREE_ADDRESSABLE (exp
)
7565 && ! targetm
.calls
.allocate_stack_slots_for_args())
7567 error ("local frame unavailable (naked function?)");
7571 gcc_assert (MEM_P (result
));
7572 result
= XEXP (result
, 0);
7574 /* ??? Is this needed anymore? */
7576 TREE_USED (exp
) = 1;
7578 if (modifier
!= EXPAND_INITIALIZER
7579 && modifier
!= EXPAND_CONST_ADDRESS
7580 && modifier
!= EXPAND_SUM
)
7581 result
= force_operand (result
, target
);
7585 /* Pass FALSE as the last argument to get_inner_reference although
7586 we are expanding to RTL. The rationale is that we know how to
7587 handle "aligning nodes" here: we can just bypass them because
7588 they won't change the final object whose address will be returned
7589 (they actually exist only for that purpose). */
7590 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7591 &mode1
, &unsignedp
, &volatilep
, false);
7595 /* We must have made progress. */
7596 gcc_assert (inner
!= exp
);
7598 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7599 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7600 inner alignment, force the inner to be sufficiently aligned. */
7601 if (CONSTANT_CLASS_P (inner
)
7602 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7604 inner
= copy_node (inner
);
7605 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7606 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7607 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7609 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7615 if (modifier
!= EXPAND_NORMAL
)
7616 result
= force_operand (result
, NULL
);
7617 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7618 modifier
== EXPAND_INITIALIZER
7619 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7621 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7622 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7624 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7625 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7628 subtarget
= bitpos
? NULL_RTX
: target
;
7629 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7630 1, OPTAB_LIB_WIDEN
);
7636 /* Someone beforehand should have rejected taking the address
7637 of such an object. */
7638 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7640 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7641 if (modifier
< EXPAND_SUM
)
7642 result
= force_operand (result
, target
);
7648 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7649 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7652 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7653 enum expand_modifier modifier
)
7655 addr_space_t as
= ADDR_SPACE_GENERIC
;
7656 enum machine_mode address_mode
= Pmode
;
7657 enum machine_mode pointer_mode
= ptr_mode
;
7658 enum machine_mode rmode
;
7661 /* Target mode of VOIDmode says "whatever's natural". */
7662 if (tmode
== VOIDmode
)
7663 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7665 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7667 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7668 address_mode
= targetm
.addr_space
.address_mode (as
);
7669 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7672 /* We can get called with some Weird Things if the user does silliness
7673 like "(short) &a". In that case, convert_memory_address won't do
7674 the right thing, so ignore the given target mode. */
7675 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7676 tmode
= address_mode
;
7678 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7679 tmode
, modifier
, as
);
7681 /* Despite expand_expr claims concerning ignoring TMODE when not
7682 strictly convenient, stuff breaks if we don't honor it. Note
7683 that combined with the above, we only do this for pointer modes. */
7684 rmode
= GET_MODE (result
);
7685 if (rmode
== VOIDmode
)
7688 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7693 /* Generate code for computing CONSTRUCTOR EXP.
7694 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7695 is TRUE, instead of creating a temporary variable in memory
7696 NULL is returned and the caller needs to handle it differently. */
7699 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7700 bool avoid_temp_mem
)
7702 tree type
= TREE_TYPE (exp
);
7703 enum machine_mode mode
= TYPE_MODE (type
);
7705 /* Try to avoid creating a temporary at all. This is possible
7706 if all of the initializer is zero.
7707 FIXME: try to handle all [0..255] initializers we can handle
7709 if (TREE_STATIC (exp
)
7710 && !TREE_ADDRESSABLE (exp
)
7711 && target
!= 0 && mode
== BLKmode
7712 && all_zeros_p (exp
))
7714 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7718 /* All elts simple constants => refer to a constant in memory. But
7719 if this is a non-BLKmode mode, let it store a field at a time
7720 since that should make a CONST_INT or CONST_DOUBLE when we
7721 fold. Likewise, if we have a target we can use, it is best to
7722 store directly into the target unless the type is large enough
7723 that memcpy will be used. If we are making an initializer and
7724 all operands are constant, put it in memory as well.
7726 FIXME: Avoid trying to fill vector constructors piece-meal.
7727 Output them with output_constant_def below unless we're sure
7728 they're zeros. This should go away when vector initializers
7729 are treated like VECTOR_CST instead of arrays. */
7730 if ((TREE_STATIC (exp
)
7731 && ((mode
== BLKmode
7732 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7733 || TREE_ADDRESSABLE (exp
)
7734 || (host_integerp (TYPE_SIZE_UNIT (type
), 1)
7735 && (! MOVE_BY_PIECES_P
7736 (tree_low_cst (TYPE_SIZE_UNIT (type
), 1),
7738 && ! mostly_zeros_p (exp
))))
7739 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7740 && TREE_CONSTANT (exp
)))
7747 constructor
= expand_expr_constant (exp
, 1, modifier
);
7749 if (modifier
!= EXPAND_CONST_ADDRESS
7750 && modifier
!= EXPAND_INITIALIZER
7751 && modifier
!= EXPAND_SUM
)
7752 constructor
= validize_mem (constructor
);
7757 /* Handle calls that pass values in multiple non-contiguous
7758 locations. The Irix 6 ABI has examples of this. */
7759 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7760 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7766 = assign_temp (build_qualified_type (type
, (TYPE_QUALS (type
)
7767 | (TREE_READONLY (exp
)
7768 * TYPE_QUAL_CONST
))),
7769 0, TREE_ADDRESSABLE (exp
), 1);
7772 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7777 /* expand_expr: generate code for computing expression EXP.
7778 An rtx for the computed value is returned. The value is never null.
7779 In the case of a void EXP, const0_rtx is returned.
7781 The value may be stored in TARGET if TARGET is nonzero.
7782 TARGET is just a suggestion; callers must assume that
7783 the rtx returned may not be the same as TARGET.
7785 If TARGET is CONST0_RTX, it means that the value will be ignored.
7787 If TMODE is not VOIDmode, it suggests generating the
7788 result in mode TMODE. But this is done only when convenient.
7789 Otherwise, TMODE is ignored and the value generated in its natural mode.
7790 TMODE is just a suggestion; callers must assume that
7791 the rtx returned may not have mode TMODE.
7793 Note that TARGET may have neither TMODE nor MODE. In that case, it
7794 probably will not be used.
7796 If MODIFIER is EXPAND_SUM then when EXP is an addition
7797 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7798 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7799 products as above, or REG or MEM, or constant.
7800 Ordinarily in such cases we would output mul or add instructions
7801 and then return a pseudo reg containing the sum.
7803 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7804 it also marks a label as absolutely required (it can't be dead).
7805 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7806 This is used for outputting expressions used in initializers.
7808 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7809 with a constant address even if that address is not normally legitimate.
7810 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7812 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7813 a call parameter. Such targets require special care as we haven't yet
7814 marked TARGET so that it's safe from being trashed by libcalls. We
7815 don't want to use TARGET for anything but the final result;
7816 Intermediate values must go elsewhere. Additionally, calls to
7817 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7819 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7820 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7821 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7822 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7826 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7827 enum expand_modifier modifier
, rtx
*alt_rtl
)
7831 /* Handle ERROR_MARK before anybody tries to access its type. */
7832 if (TREE_CODE (exp
) == ERROR_MARK
7833 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7835 ret
= CONST0_RTX (tmode
);
7836 return ret
? ret
: const0_rtx
;
7839 /* If this is an expression of some kind and it has an associated line
7840 number, then emit the line number before expanding the expression.
7842 We need to save and restore the file and line information so that
7843 errors discovered during expansion are emitted with the right
7844 information. It would be better of the diagnostic routines
7845 used the file/line information embedded in the tree nodes rather
7847 if (cfun
&& EXPR_HAS_LOCATION (exp
))
7849 location_t saved_location
= input_location
;
7850 location_t saved_curr_loc
= get_curr_insn_source_location ();
7851 tree saved_block
= get_curr_insn_block ();
7852 input_location
= EXPR_LOCATION (exp
);
7853 set_curr_insn_source_location (input_location
);
7855 /* Record where the insns produced belong. */
7856 set_curr_insn_block (TREE_BLOCK (exp
));
7858 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7860 input_location
= saved_location
;
7861 set_curr_insn_block (saved_block
);
7862 set_curr_insn_source_location (saved_curr_loc
);
7866 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7872 /* Try to expand the conditional expression which is represented by
7873 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7874 return the rtl reg which repsents the result. Otherwise return
7878 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7879 tree treeop1 ATTRIBUTE_UNUSED
,
7880 tree treeop2 ATTRIBUTE_UNUSED
)
7882 #ifdef HAVE_conditional_move
7884 rtx op00
, op01
, op1
, op2
;
7885 enum rtx_code comparison_code
;
7886 enum machine_mode comparison_mode
;
7889 tree type
= TREE_TYPE (treeop1
);
7890 int unsignedp
= TYPE_UNSIGNED (type
);
7891 enum machine_mode mode
= TYPE_MODE (type
);
7893 temp
= assign_temp (type
, 0, 0, 1);
7895 /* If we cannot do a conditional move on the mode, try doing it
7896 with the promoted mode. */
7897 if (!can_conditionally_move_p (mode
))
7898 mode
= promote_mode (type
, mode
, &unsignedp
);
7900 if (!can_conditionally_move_p (mode
))
7904 expand_operands (treeop1
, treeop2
,
7905 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7907 if (TREE_CODE (treeop0
) == SSA_NAME
7908 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7910 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7911 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7912 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7913 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7914 comparison_mode
= TYPE_MODE (type
);
7915 unsignedp
= TYPE_UNSIGNED (type
);
7916 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7918 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7920 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7921 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7922 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7923 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7924 unsignedp
= TYPE_UNSIGNED (type
);
7925 comparison_mode
= TYPE_MODE (type
);
7926 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7930 op00
= expand_normal (treeop0
);
7932 comparison_code
= NE
;
7933 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7936 if (GET_MODE (op1
) != mode
)
7937 op1
= gen_lowpart (mode
, op1
);
7939 if (GET_MODE (op2
) != mode
)
7940 op2
= gen_lowpart (mode
, op2
);
7942 /* Try to emit the conditional move. */
7943 insn
= emit_conditional_move (temp
, comparison_code
,
7944 op00
, op01
, comparison_mode
,
7948 /* If we could do the conditional move, emit the sequence,
7952 rtx seq
= get_insns ();
7958 /* Otherwise discard the sequence and fall back to code with
7966 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
7967 enum expand_modifier modifier
)
7969 rtx op0
, op1
, op2
, temp
;
7972 enum machine_mode mode
;
7973 enum tree_code code
= ops
->code
;
7975 rtx subtarget
, original_target
;
7977 bool reduce_bit_field
;
7978 location_t loc
= ops
->location
;
7979 tree treeop0
, treeop1
, treeop2
;
7980 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
7981 ? reduce_to_bit_field_precision ((expr), \
7987 mode
= TYPE_MODE (type
);
7988 unsignedp
= TYPE_UNSIGNED (type
);
7994 /* We should be called only on simple (binary or unary) expressions,
7995 exactly those that are valid in gimple expressions that aren't
7996 GIMPLE_SINGLE_RHS (or invalid). */
7997 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
7998 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
7999 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8001 ignore
= (target
== const0_rtx
8002 || ((CONVERT_EXPR_CODE_P (code
)
8003 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8004 && TREE_CODE (type
) == VOID_TYPE
));
8006 /* We should be called only if we need the result. */
8007 gcc_assert (!ignore
);
8009 /* An operation in what may be a bit-field type needs the
8010 result to be reduced to the precision of the bit-field type,
8011 which is narrower than that of the type's mode. */
8012 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8013 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8015 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8018 /* Use subtarget as the target for operand 0 of a binary operation. */
8019 subtarget
= get_subtarget (target
);
8020 original_target
= target
;
8024 case NON_LVALUE_EXPR
:
8027 if (treeop0
== error_mark_node
)
8030 if (TREE_CODE (type
) == UNION_TYPE
)
8032 tree valtype
= TREE_TYPE (treeop0
);
8034 /* If both input and output are BLKmode, this conversion isn't doing
8035 anything except possibly changing memory attribute. */
8036 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8038 rtx result
= expand_expr (treeop0
, target
, tmode
,
8041 result
= copy_rtx (result
);
8042 set_mem_attributes (result
, type
, 0);
8048 if (TYPE_MODE (type
) != BLKmode
)
8049 target
= gen_reg_rtx (TYPE_MODE (type
));
8051 target
= assign_temp (type
, 0, 1, 1);
8055 /* Store data into beginning of memory target. */
8056 store_expr (treeop0
,
8057 adjust_address (target
, TYPE_MODE (valtype
), 0),
8058 modifier
== EXPAND_STACK_PARM
,
8063 gcc_assert (REG_P (target
));
8065 /* Store this field into a union of the proper type. */
8066 store_field (target
,
8067 MIN ((int_size_in_bytes (TREE_TYPE
8070 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8071 0, 0, 0, TYPE_MODE (valtype
), treeop0
,
8075 /* Return the entire union. */
8079 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8081 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8084 /* If the signedness of the conversion differs and OP0 is
8085 a promoted SUBREG, clear that indication since we now
8086 have to do the proper extension. */
8087 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8088 && GET_CODE (op0
) == SUBREG
)
8089 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8091 return REDUCE_BIT_FIELD (op0
);
8094 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8095 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8096 if (GET_MODE (op0
) == mode
)
8099 /* If OP0 is a constant, just convert it into the proper mode. */
8100 else if (CONSTANT_P (op0
))
8102 tree inner_type
= TREE_TYPE (treeop0
);
8103 enum machine_mode inner_mode
= GET_MODE (op0
);
8105 if (inner_mode
== VOIDmode
)
8106 inner_mode
= TYPE_MODE (inner_type
);
8108 if (modifier
== EXPAND_INITIALIZER
)
8109 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8110 subreg_lowpart_offset (mode
,
8113 op0
= convert_modes (mode
, inner_mode
, op0
,
8114 TYPE_UNSIGNED (inner_type
));
8117 else if (modifier
== EXPAND_INITIALIZER
)
8118 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8120 else if (target
== 0)
8121 op0
= convert_to_mode (mode
, op0
,
8122 TYPE_UNSIGNED (TREE_TYPE
8126 convert_move (target
, op0
,
8127 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8131 return REDUCE_BIT_FIELD (op0
);
8133 case ADDR_SPACE_CONVERT_EXPR
:
8135 tree treeop0_type
= TREE_TYPE (treeop0
);
8137 addr_space_t as_from
;
8139 gcc_assert (POINTER_TYPE_P (type
));
8140 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8142 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8143 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8145 /* Conversions between pointers to the same address space should
8146 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8147 gcc_assert (as_to
!= as_from
);
8149 /* Ask target code to handle conversion between pointers
8150 to overlapping address spaces. */
8151 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8152 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8154 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8155 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8160 /* For disjoint address spaces, converting anything but
8161 a null pointer invokes undefined behaviour. We simply
8162 always return a null pointer here. */
8163 return CONST0_RTX (mode
);
8166 case POINTER_PLUS_EXPR
:
8167 /* Even though the sizetype mode and the pointer's mode can be different
8168 expand is able to handle this correctly and get the correct result out
8169 of the PLUS_EXPR code. */
8170 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8171 if sizetype precision is smaller than pointer precision. */
8172 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8173 treeop1
= fold_convert_loc (loc
, type
,
8174 fold_convert_loc (loc
, ssizetype
,
8176 /* If sizetype precision is larger than pointer precision, truncate the
8177 offset to have matching modes. */
8178 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8179 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8182 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8183 something else, make sure we add the register to the constant and
8184 then to the other thing. This case can occur during strength
8185 reduction and doing it this way will produce better code if the
8186 frame pointer or argument pointer is eliminated.
8188 fold-const.c will ensure that the constant is always in the inner
8189 PLUS_EXPR, so the only case we need to do anything about is if
8190 sp, ap, or fp is our second argument, in which case we must swap
8191 the innermost first argument and our second argument. */
8193 if (TREE_CODE (treeop0
) == PLUS_EXPR
8194 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8195 && TREE_CODE (treeop1
) == VAR_DECL
8196 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8197 || DECL_RTL (treeop1
) == stack_pointer_rtx
8198 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8202 treeop1
= TREE_OPERAND (treeop0
, 0);
8203 TREE_OPERAND (treeop0
, 0) = t
;
8206 /* If the result is to be ptr_mode and we are adding an integer to
8207 something, we might be forming a constant. So try to use
8208 plus_constant. If it produces a sum and we can't accept it,
8209 use force_operand. This allows P = &ARR[const] to generate
8210 efficient code on machines where a SYMBOL_REF is not a valid
8213 If this is an EXPAND_SUM call, always return the sum. */
8214 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8215 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8217 if (modifier
== EXPAND_STACK_PARM
)
8219 if (TREE_CODE (treeop0
) == INTEGER_CST
8220 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8221 && TREE_CONSTANT (treeop1
))
8225 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8227 /* Use immed_double_const to ensure that the constant is
8228 truncated according to the mode of OP1, then sign extended
8229 to a HOST_WIDE_INT. Using the constant directly can result
8230 in non-canonical RTL in a 64x32 cross compile. */
8232 = immed_double_const (TREE_INT_CST_LOW (treeop0
),
8234 TYPE_MODE (TREE_TYPE (treeop1
)));
8235 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8236 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8237 op1
= force_operand (op1
, target
);
8238 return REDUCE_BIT_FIELD (op1
);
8241 else if (TREE_CODE (treeop1
) == INTEGER_CST
8242 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8243 && TREE_CONSTANT (treeop0
))
8247 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8248 (modifier
== EXPAND_INITIALIZER
8249 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8250 if (! CONSTANT_P (op0
))
8252 op1
= expand_expr (treeop1
, NULL_RTX
,
8253 VOIDmode
, modifier
);
8254 /* Return a PLUS if modifier says it's OK. */
8255 if (modifier
== EXPAND_SUM
8256 || modifier
== EXPAND_INITIALIZER
)
8257 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8260 /* Use immed_double_const to ensure that the constant is
8261 truncated according to the mode of OP1, then sign extended
8262 to a HOST_WIDE_INT. Using the constant directly can result
8263 in non-canonical RTL in a 64x32 cross compile. */
8265 = immed_double_const (TREE_INT_CST_LOW (treeop1
),
8267 TYPE_MODE (TREE_TYPE (treeop0
)));
8268 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8269 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8270 op0
= force_operand (op0
, target
);
8271 return REDUCE_BIT_FIELD (op0
);
8275 /* Use TER to expand pointer addition of a negated value
8276 as pointer subtraction. */
8277 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8278 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8279 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8280 && TREE_CODE (treeop1
) == SSA_NAME
8281 && TYPE_MODE (TREE_TYPE (treeop0
))
8282 == TYPE_MODE (TREE_TYPE (treeop1
)))
8284 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8287 treeop1
= gimple_assign_rhs1 (def
);
8293 /* No sense saving up arithmetic to be done
8294 if it's all in the wrong mode to form part of an address.
8295 And force_operand won't know whether to sign-extend or
8297 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8298 || mode
!= ptr_mode
)
8300 expand_operands (treeop0
, treeop1
,
8301 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8302 if (op0
== const0_rtx
)
8304 if (op1
== const0_rtx
)
8309 expand_operands (treeop0
, treeop1
,
8310 subtarget
, &op0
, &op1
, modifier
);
8311 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8315 /* For initializers, we are allowed to return a MINUS of two
8316 symbolic constants. Here we handle all cases when both operands
8318 /* Handle difference of two symbolic constants,
8319 for the sake of an initializer. */
8320 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8321 && really_constant_p (treeop0
)
8322 && really_constant_p (treeop1
))
8324 expand_operands (treeop0
, treeop1
,
8325 NULL_RTX
, &op0
, &op1
, modifier
);
8327 /* If the last operand is a CONST_INT, use plus_constant of
8328 the negated constant. Else make the MINUS. */
8329 if (CONST_INT_P (op1
))
8330 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8333 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8336 /* No sense saving up arithmetic to be done
8337 if it's all in the wrong mode to form part of an address.
8338 And force_operand won't know whether to sign-extend or
8340 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8341 || mode
!= ptr_mode
)
8344 expand_operands (treeop0
, treeop1
,
8345 subtarget
, &op0
, &op1
, modifier
);
8347 /* Convert A - const to A + (-const). */
8348 if (CONST_INT_P (op1
))
8350 op1
= negate_rtx (mode
, op1
);
8351 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8356 case WIDEN_MULT_PLUS_EXPR
:
8357 case WIDEN_MULT_MINUS_EXPR
:
8358 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8359 op2
= expand_normal (treeop2
);
8360 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8364 case WIDEN_MULT_EXPR
:
8365 /* If first operand is constant, swap them.
8366 Thus the following special case checks need only
8367 check the second operand. */
8368 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8375 /* First, check if we have a multiplication of one signed and one
8376 unsigned operand. */
8377 if (TREE_CODE (treeop1
) != INTEGER_CST
8378 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8379 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8381 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8382 this_optab
= usmul_widen_optab
;
8383 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8384 != CODE_FOR_nothing
)
8386 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8387 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8390 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8395 /* Check for a multiplication with matching signedness. */
8396 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8397 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8398 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8399 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8401 tree op0type
= TREE_TYPE (treeop0
);
8402 enum machine_mode innermode
= TYPE_MODE (op0type
);
8403 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8404 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8405 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8407 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8409 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8410 != CODE_FOR_nothing
)
8412 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8414 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8415 unsignedp
, this_optab
);
8416 return REDUCE_BIT_FIELD (temp
);
8418 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8420 && innermode
== word_mode
)
8423 op0
= expand_normal (treeop0
);
8424 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8425 op1
= convert_modes (innermode
, mode
,
8426 expand_normal (treeop1
), unsignedp
);
8428 op1
= expand_normal (treeop1
);
8429 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8430 unsignedp
, OPTAB_LIB_WIDEN
);
8431 hipart
= gen_highpart (innermode
, temp
);
8432 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8436 emit_move_insn (hipart
, htem
);
8437 return REDUCE_BIT_FIELD (temp
);
8441 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8442 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8443 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8444 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8448 optab opt
= fma_optab
;
8451 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8453 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8455 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8458 gcc_assert (fn
!= NULL_TREE
);
8459 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8460 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8463 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8464 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8469 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8472 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8473 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8476 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8479 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8482 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8485 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8489 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8491 op2
= expand_normal (treeop2
);
8492 op1
= expand_normal (treeop1
);
8494 return expand_ternary_op (TYPE_MODE (type
), opt
,
8495 op0
, op1
, op2
, target
, 0);
8499 /* If this is a fixed-point operation, then we cannot use the code
8500 below because "expand_mult" doesn't support sat/no-sat fixed-point
8502 if (ALL_FIXED_POINT_MODE_P (mode
))
8505 /* If first operand is constant, swap them.
8506 Thus the following special case checks need only
8507 check the second operand. */
8508 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8515 /* Attempt to return something suitable for generating an
8516 indexed address, for machines that support that. */
8518 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8519 && host_integerp (treeop1
, 0))
8521 tree exp1
= treeop1
;
8523 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8527 op0
= force_operand (op0
, NULL_RTX
);
8529 op0
= copy_to_mode_reg (mode
, op0
);
8531 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8532 gen_int_mode (tree_low_cst (exp1
, 0),
8533 TYPE_MODE (TREE_TYPE (exp1
)))));
8536 if (modifier
== EXPAND_STACK_PARM
)
8539 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8540 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8542 case TRUNC_DIV_EXPR
:
8543 case FLOOR_DIV_EXPR
:
8545 case ROUND_DIV_EXPR
:
8546 case EXACT_DIV_EXPR
:
8547 /* If this is a fixed-point operation, then we cannot use the code
8548 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8550 if (ALL_FIXED_POINT_MODE_P (mode
))
8553 if (modifier
== EXPAND_STACK_PARM
)
8555 /* Possible optimization: compute the dividend with EXPAND_SUM
8556 then if the divisor is constant can optimize the case
8557 where some terms of the dividend have coeffs divisible by it. */
8558 expand_operands (treeop0
, treeop1
,
8559 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8560 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8565 case TRUNC_MOD_EXPR
:
8566 case FLOOR_MOD_EXPR
:
8568 case ROUND_MOD_EXPR
:
8569 if (modifier
== EXPAND_STACK_PARM
)
8571 expand_operands (treeop0
, treeop1
,
8572 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8573 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8575 case FIXED_CONVERT_EXPR
:
8576 op0
= expand_normal (treeop0
);
8577 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8578 target
= gen_reg_rtx (mode
);
8580 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8581 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8582 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8583 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8585 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8588 case FIX_TRUNC_EXPR
:
8589 op0
= expand_normal (treeop0
);
8590 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8591 target
= gen_reg_rtx (mode
);
8592 expand_fix (target
, op0
, unsignedp
);
8596 op0
= expand_normal (treeop0
);
8597 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8598 target
= gen_reg_rtx (mode
);
8599 /* expand_float can't figure out what to do if FROM has VOIDmode.
8600 So give it the correct mode. With -O, cse will optimize this. */
8601 if (GET_MODE (op0
) == VOIDmode
)
8602 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8604 expand_float (target
, op0
,
8605 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8609 op0
= expand_expr (treeop0
, subtarget
,
8610 VOIDmode
, EXPAND_NORMAL
);
8611 if (modifier
== EXPAND_STACK_PARM
)
8613 temp
= expand_unop (mode
,
8614 optab_for_tree_code (NEGATE_EXPR
, type
,
8618 return REDUCE_BIT_FIELD (temp
);
8621 op0
= expand_expr (treeop0
, subtarget
,
8622 VOIDmode
, EXPAND_NORMAL
);
8623 if (modifier
== EXPAND_STACK_PARM
)
8626 /* ABS_EXPR is not valid for complex arguments. */
8627 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8628 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8630 /* Unsigned abs is simply the operand. Testing here means we don't
8631 risk generating incorrect code below. */
8632 if (TYPE_UNSIGNED (type
))
8635 return expand_abs (mode
, op0
, target
, unsignedp
,
8636 safe_from_p (target
, treeop0
, 1));
8640 target
= original_target
;
8642 || modifier
== EXPAND_STACK_PARM
8643 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8644 || GET_MODE (target
) != mode
8646 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8647 target
= gen_reg_rtx (mode
);
8648 expand_operands (treeop0
, treeop1
,
8649 target
, &op0
, &op1
, EXPAND_NORMAL
);
8651 /* First try to do it with a special MIN or MAX instruction.
8652 If that does not win, use a conditional jump to select the proper
8654 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8655 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8660 /* At this point, a MEM target is no longer useful; we will get better
8663 if (! REG_P (target
))
8664 target
= gen_reg_rtx (mode
);
8666 /* If op1 was placed in target, swap op0 and op1. */
8667 if (target
!= op0
&& target
== op1
)
8674 /* We generate better code and avoid problems with op1 mentioning
8675 target by forcing op1 into a pseudo if it isn't a constant. */
8676 if (! CONSTANT_P (op1
))
8677 op1
= force_reg (mode
, op1
);
8680 enum rtx_code comparison_code
;
8683 if (code
== MAX_EXPR
)
8684 comparison_code
= unsignedp
? GEU
: GE
;
8686 comparison_code
= unsignedp
? LEU
: LE
;
8688 /* Canonicalize to comparisons against 0. */
8689 if (op1
== const1_rtx
)
8691 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8692 or (a != 0 ? a : 1) for unsigned.
8693 For MIN we are safe converting (a <= 1 ? a : 1)
8694 into (a <= 0 ? a : 1) */
8695 cmpop1
= const0_rtx
;
8696 if (code
== MAX_EXPR
)
8697 comparison_code
= unsignedp
? NE
: GT
;
8699 if (op1
== constm1_rtx
&& !unsignedp
)
8701 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8702 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8703 cmpop1
= const0_rtx
;
8704 if (code
== MIN_EXPR
)
8705 comparison_code
= LT
;
8707 #ifdef HAVE_conditional_move
8708 /* Use a conditional move if possible. */
8709 if (can_conditionally_move_p (mode
))
8713 /* ??? Same problem as in expmed.c: emit_conditional_move
8714 forces a stack adjustment via compare_from_rtx, and we
8715 lose the stack adjustment if the sequence we are about
8716 to create is discarded. */
8717 do_pending_stack_adjust ();
8721 /* Try to emit the conditional move. */
8722 insn
= emit_conditional_move (target
, comparison_code
,
8727 /* If we could do the conditional move, emit the sequence,
8731 rtx seq
= get_insns ();
8737 /* Otherwise discard the sequence and fall back to code with
8743 emit_move_insn (target
, op0
);
8745 temp
= gen_label_rtx ();
8746 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8747 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8750 emit_move_insn (target
, op1
);
8755 op0
= expand_expr (treeop0
, subtarget
,
8756 VOIDmode
, EXPAND_NORMAL
);
8757 if (modifier
== EXPAND_STACK_PARM
)
8759 /* In case we have to reduce the result to bitfield precision
8760 for unsigned bitfield expand this as XOR with a proper constant
8762 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8763 temp
= expand_binop (mode
, xor_optab
, op0
,
8764 immed_double_int_const
8765 (double_int_mask (TYPE_PRECISION (type
)), mode
),
8766 target
, 1, OPTAB_LIB_WIDEN
);
8768 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8772 /* ??? Can optimize bitwise operations with one arg constant.
8773 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8774 and (a bitwise1 b) bitwise2 b (etc)
8775 but that is probably not worth while. */
8784 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8785 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8786 == TYPE_PRECISION (type
)));
8791 /* If this is a fixed-point operation, then we cannot use the code
8792 below because "expand_shift" doesn't support sat/no-sat fixed-point
8794 if (ALL_FIXED_POINT_MODE_P (mode
))
8797 if (! safe_from_p (subtarget
, treeop1
, 1))
8799 if (modifier
== EXPAND_STACK_PARM
)
8801 op0
= expand_expr (treeop0
, subtarget
,
8802 VOIDmode
, EXPAND_NORMAL
);
8803 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8805 if (code
== LSHIFT_EXPR
)
8806 temp
= REDUCE_BIT_FIELD (temp
);
8809 /* Could determine the answer when only additive constants differ. Also,
8810 the addition of one can be handled by changing the condition. */
8817 case UNORDERED_EXPR
:
8825 temp
= do_store_flag (ops
,
8826 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8827 tmode
!= VOIDmode
? tmode
: mode
);
8831 /* Use a compare and a jump for BLKmode comparisons, or for function
8832 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8835 || modifier
== EXPAND_STACK_PARM
8836 || ! safe_from_p (target
, treeop0
, 1)
8837 || ! safe_from_p (target
, treeop1
, 1)
8838 /* Make sure we don't have a hard reg (such as function's return
8839 value) live across basic blocks, if not optimizing. */
8840 || (!optimize
&& REG_P (target
)
8841 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8842 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8844 emit_move_insn (target
, const0_rtx
);
8846 op1
= gen_label_rtx ();
8847 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8849 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8850 emit_move_insn (target
, constm1_rtx
);
8852 emit_move_insn (target
, const1_rtx
);
8858 /* Get the rtx code of the operands. */
8859 op0
= expand_normal (treeop0
);
8860 op1
= expand_normal (treeop1
);
8863 target
= gen_reg_rtx (TYPE_MODE (type
));
8865 /* Move the real (op0) and imaginary (op1) parts to their location. */
8866 write_complex_part (target
, op0
, false);
8867 write_complex_part (target
, op1
, true);
8871 case WIDEN_SUM_EXPR
:
8873 tree oprnd0
= treeop0
;
8874 tree oprnd1
= treeop1
;
8876 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8877 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
8882 case REDUC_MAX_EXPR
:
8883 case REDUC_MIN_EXPR
:
8884 case REDUC_PLUS_EXPR
:
8886 op0
= expand_normal (treeop0
);
8887 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8888 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
8893 case VEC_LSHIFT_EXPR
:
8894 case VEC_RSHIFT_EXPR
:
8896 target
= expand_vec_shift_expr (ops
, target
);
8900 case VEC_UNPACK_HI_EXPR
:
8901 case VEC_UNPACK_LO_EXPR
:
8903 op0
= expand_normal (treeop0
);
8904 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
8910 case VEC_UNPACK_FLOAT_HI_EXPR
:
8911 case VEC_UNPACK_FLOAT_LO_EXPR
:
8913 op0
= expand_normal (treeop0
);
8914 /* The signedness is determined from input operand. */
8915 temp
= expand_widen_pattern_expr
8916 (ops
, op0
, NULL_RTX
, NULL_RTX
,
8917 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8923 case VEC_WIDEN_MULT_HI_EXPR
:
8924 case VEC_WIDEN_MULT_LO_EXPR
:
8926 tree oprnd0
= treeop0
;
8927 tree oprnd1
= treeop1
;
8929 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8930 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
8932 gcc_assert (target
);
8936 case VEC_WIDEN_LSHIFT_HI_EXPR
:
8937 case VEC_WIDEN_LSHIFT_LO_EXPR
:
8939 tree oprnd0
= treeop0
;
8940 tree oprnd1
= treeop1
;
8942 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8943 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
8945 gcc_assert (target
);
8949 case VEC_PACK_TRUNC_EXPR
:
8950 case VEC_PACK_SAT_EXPR
:
8951 case VEC_PACK_FIX_TRUNC_EXPR
:
8952 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8956 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
8957 op2
= expand_normal (treeop2
);
8959 /* Careful here: if the target doesn't support integral vector modes,
8960 a constant selection vector could wind up smooshed into a normal
8961 integral constant. */
8962 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
8964 tree sel_type
= TREE_TYPE (treeop2
);
8965 enum machine_mode vmode
8966 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
8967 TYPE_VECTOR_SUBPARTS (sel_type
));
8968 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
8969 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
8970 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
8973 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
8975 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
8981 tree oprnd0
= treeop0
;
8982 tree oprnd1
= treeop1
;
8983 tree oprnd2
= treeop2
;
8986 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8987 op2
= expand_normal (oprnd2
);
8988 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8993 case REALIGN_LOAD_EXPR
:
8995 tree oprnd0
= treeop0
;
8996 tree oprnd1
= treeop1
;
8997 tree oprnd2
= treeop2
;
9000 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9001 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9002 op2
= expand_normal (oprnd2
);
9003 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9010 /* A COND_EXPR with its type being VOID_TYPE represents a
9011 conditional jump and is handled in
9012 expand_gimple_cond_expr. */
9013 gcc_assert (!VOID_TYPE_P (type
));
9015 /* Note that COND_EXPRs whose type is a structure or union
9016 are required to be constructed to contain assignments of
9017 a temporary variable, so that we can evaluate them here
9018 for side effect only. If type is void, we must do likewise. */
9020 gcc_assert (!TREE_ADDRESSABLE (type
)
9022 && TREE_TYPE (treeop1
) != void_type_node
9023 && TREE_TYPE (treeop2
) != void_type_node
);
9025 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9029 /* If we are not to produce a result, we have no target. Otherwise,
9030 if a target was specified use it; it will not be used as an
9031 intermediate target unless it is safe. If no target, use a
9034 if (modifier
!= EXPAND_STACK_PARM
9036 && safe_from_p (original_target
, treeop0
, 1)
9037 && GET_MODE (original_target
) == mode
9038 && !MEM_P (original_target
))
9039 temp
= original_target
;
9041 temp
= assign_temp (type
, 0, 0, 1);
9043 do_pending_stack_adjust ();
9045 op0
= gen_label_rtx ();
9046 op1
= gen_label_rtx ();
9047 jumpifnot (treeop0
, op0
, -1);
9048 store_expr (treeop1
, temp
,
9049 modifier
== EXPAND_STACK_PARM
,
9052 emit_jump_insn (gen_jump (op1
));
9055 store_expr (treeop2
, temp
,
9056 modifier
== EXPAND_STACK_PARM
,
9064 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9071 /* Here to do an ordinary binary operator. */
9073 expand_operands (treeop0
, treeop1
,
9074 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9076 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9078 if (modifier
== EXPAND_STACK_PARM
)
9080 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9081 unsignedp
, OPTAB_LIB_WIDEN
);
9083 /* Bitwise operations do not need bitfield reduction as we expect their
9084 operands being properly truncated. */
9085 if (code
== BIT_XOR_EXPR
9086 || code
== BIT_AND_EXPR
9087 || code
== BIT_IOR_EXPR
)
9089 return REDUCE_BIT_FIELD (temp
);
9091 #undef REDUCE_BIT_FIELD
9094 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9095 enum expand_modifier modifier
, rtx
*alt_rtl
)
9097 rtx op0
, op1
, temp
, decl_rtl
;
9100 enum machine_mode mode
;
9101 enum tree_code code
= TREE_CODE (exp
);
9102 rtx subtarget
, original_target
;
9105 bool reduce_bit_field
;
9106 location_t loc
= EXPR_LOCATION (exp
);
9107 struct separate_ops ops
;
9108 tree treeop0
, treeop1
, treeop2
;
9109 tree ssa_name
= NULL_TREE
;
9112 type
= TREE_TYPE (exp
);
9113 mode
= TYPE_MODE (type
);
9114 unsignedp
= TYPE_UNSIGNED (type
);
9116 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9117 if (!VL_EXP_CLASS_P (exp
))
9118 switch (TREE_CODE_LENGTH (code
))
9121 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9122 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9123 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9133 ignore
= (target
== const0_rtx
9134 || ((CONVERT_EXPR_CODE_P (code
)
9135 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9136 && TREE_CODE (type
) == VOID_TYPE
));
9138 /* An operation in what may be a bit-field type needs the
9139 result to be reduced to the precision of the bit-field type,
9140 which is narrower than that of the type's mode. */
9141 reduce_bit_field
= (!ignore
9142 && INTEGRAL_TYPE_P (type
)
9143 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9145 /* If we are going to ignore this result, we need only do something
9146 if there is a side-effect somewhere in the expression. If there
9147 is, short-circuit the most common cases here. Note that we must
9148 not call expand_expr with anything but const0_rtx in case this
9149 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9153 if (! TREE_SIDE_EFFECTS (exp
))
9156 /* Ensure we reference a volatile object even if value is ignored, but
9157 don't do this if all we are doing is taking its address. */
9158 if (TREE_THIS_VOLATILE (exp
)
9159 && TREE_CODE (exp
) != FUNCTION_DECL
9160 && mode
!= VOIDmode
&& mode
!= BLKmode
9161 && modifier
!= EXPAND_CONST_ADDRESS
)
9163 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9169 if (TREE_CODE_CLASS (code
) == tcc_unary
9170 || code
== COMPONENT_REF
|| code
== INDIRECT_REF
)
9171 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9174 else if (TREE_CODE_CLASS (code
) == tcc_binary
9175 || TREE_CODE_CLASS (code
) == tcc_comparison
9176 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9178 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9179 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9182 else if (code
== BIT_FIELD_REF
)
9184 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9185 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9186 expand_expr (treeop2
, const0_rtx
, VOIDmode
, modifier
);
9193 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9196 /* Use subtarget as the target for operand 0 of a binary operation. */
9197 subtarget
= get_subtarget (target
);
9198 original_target
= target
;
9204 tree function
= decl_function_context (exp
);
9206 temp
= label_rtx (exp
);
9207 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9209 if (function
!= current_function_decl
9211 LABEL_REF_NONLOCAL_P (temp
) = 1;
9213 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9218 /* ??? ivopts calls expander, without any preparation from
9219 out-of-ssa. So fake instructions as if this was an access to the
9220 base variable. This unnecessarily allocates a pseudo, see how we can
9221 reuse it, if partition base vars have it set already. */
9222 if (!currently_expanding_to_rtl
)
9223 return expand_expr_real_1 (SSA_NAME_VAR (exp
), target
, tmode
, modifier
,
9226 g
= get_gimple_for_ssa_name (exp
);
9227 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9229 && modifier
== EXPAND_INITIALIZER
9230 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9231 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9232 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9233 g
= SSA_NAME_DEF_STMT (exp
);
9236 rtx r
= expand_expr_real (gimple_assign_rhs_to_tree (g
), target
,
9237 tmode
, modifier
, NULL
);
9238 if (REG_P (r
) && !REG_EXPR (r
))
9239 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9244 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9245 exp
= SSA_NAME_VAR (ssa_name
);
9246 goto expand_decl_rtl
;
9250 /* If a static var's type was incomplete when the decl was written,
9251 but the type is complete now, lay out the decl now. */
9252 if (DECL_SIZE (exp
) == 0
9253 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9254 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9255 layout_decl (exp
, 0);
9257 /* ... fall through ... */
9261 decl_rtl
= DECL_RTL (exp
);
9263 gcc_assert (decl_rtl
);
9264 decl_rtl
= copy_rtx (decl_rtl
);
9265 /* Record writes to register variables. */
9266 if (modifier
== EXPAND_WRITE
9268 && HARD_REGISTER_P (decl_rtl
))
9269 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9270 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9272 /* Ensure variable marked as used even if it doesn't go through
9273 a parser. If it hasn't be used yet, write out an external
9275 TREE_USED (exp
) = 1;
9277 /* Show we haven't gotten RTL for this yet. */
9280 /* Variables inherited from containing functions should have
9281 been lowered by this point. */
9282 context
= decl_function_context (exp
);
9283 gcc_assert (!context
9284 || context
== current_function_decl
9285 || TREE_STATIC (exp
)
9286 || DECL_EXTERNAL (exp
)
9287 /* ??? C++ creates functions that are not TREE_STATIC. */
9288 || TREE_CODE (exp
) == FUNCTION_DECL
);
9290 /* This is the case of an array whose size is to be determined
9291 from its initializer, while the initializer is still being parsed.
9294 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9295 temp
= validize_mem (decl_rtl
);
9297 /* If DECL_RTL is memory, we are in the normal case and the
9298 address is not valid, get the address into a register. */
9300 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9303 *alt_rtl
= decl_rtl
;
9304 decl_rtl
= use_anchored_address (decl_rtl
);
9305 if (modifier
!= EXPAND_CONST_ADDRESS
9306 && modifier
!= EXPAND_SUM
9307 && !memory_address_addr_space_p (DECL_MODE (exp
),
9309 MEM_ADDR_SPACE (decl_rtl
)))
9310 temp
= replace_equiv_address (decl_rtl
,
9311 copy_rtx (XEXP (decl_rtl
, 0)));
9314 /* If we got something, return it. But first, set the alignment
9315 if the address is a register. */
9318 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9319 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9324 /* If the mode of DECL_RTL does not match that of the decl,
9325 there are two cases: we are dealing with a BLKmode value
9326 that is returned in a register, or we are dealing with
9327 a promoted value. In the latter case, return a SUBREG
9328 of the wanted mode, but mark it so that we know that it
9329 was already extended. */
9330 if (REG_P (decl_rtl
)
9331 && DECL_MODE (exp
) != BLKmode
9332 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9334 enum machine_mode pmode
;
9336 /* Get the signedness to be used for this variable. Ensure we get
9337 the same mode we got when the variable was declared. */
9338 if (code
== SSA_NAME
9339 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9340 && gimple_code (g
) == GIMPLE_CALL
)
9342 gcc_assert (!gimple_call_internal_p (g
));
9343 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9344 gimple_call_fntype (g
),
9348 pmode
= promote_decl_mode (exp
, &unsignedp
);
9349 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9351 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9352 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9353 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
9360 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
9361 TREE_INT_CST_HIGH (exp
), mode
);
9367 tree tmp
= NULL_TREE
;
9368 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9369 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9370 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9371 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9372 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9373 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9374 return const_vector_from_tree (exp
);
9375 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9377 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9379 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9383 VEC(constructor_elt
,gc
) *v
;
9385 v
= VEC_alloc (constructor_elt
, gc
, VECTOR_CST_NELTS (exp
));
9386 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9387 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9388 tmp
= build_constructor (type
, v
);
9390 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9395 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9398 /* If optimized, generate immediate CONST_DOUBLE
9399 which will be turned into memory by reload if necessary.
9401 We used to force a register so that loop.c could see it. But
9402 this does not allow gen_* patterns to perform optimizations with
9403 the constants. It also produces two insns in cases like "x = 1.0;".
9404 On most machines, floating-point constants are not permitted in
9405 many insns, so we'd end up copying it to a register in any case.
9407 Now, we do the copying in expand_binop, if appropriate. */
9408 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9409 TYPE_MODE (TREE_TYPE (exp
)));
9412 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9413 TYPE_MODE (TREE_TYPE (exp
)));
9416 /* Handle evaluating a complex constant in a CONCAT target. */
9417 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9419 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9422 rtarg
= XEXP (original_target
, 0);
9423 itarg
= XEXP (original_target
, 1);
9425 /* Move the real and imaginary parts separately. */
9426 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9427 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9430 emit_move_insn (rtarg
, op0
);
9432 emit_move_insn (itarg
, op1
);
9434 return original_target
;
9437 /* ... fall through ... */
9440 temp
= expand_expr_constant (exp
, 1, modifier
);
9442 /* temp contains a constant address.
9443 On RISC machines where a constant address isn't valid,
9444 make some insns to get that address into a register. */
9445 if (modifier
!= EXPAND_CONST_ADDRESS
9446 && modifier
!= EXPAND_INITIALIZER
9447 && modifier
!= EXPAND_SUM
9448 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9449 MEM_ADDR_SPACE (temp
)))
9450 return replace_equiv_address (temp
,
9451 copy_rtx (XEXP (temp
, 0)));
9457 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
9459 if (!SAVE_EXPR_RESOLVED_P (exp
))
9461 /* We can indeed still hit this case, typically via builtin
9462 expanders calling save_expr immediately before expanding
9463 something. Assume this means that we only have to deal
9464 with non-BLKmode values. */
9465 gcc_assert (GET_MODE (ret
) != BLKmode
);
9467 val
= build_decl (EXPR_LOCATION (exp
),
9468 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9469 DECL_ARTIFICIAL (val
) = 1;
9470 DECL_IGNORED_P (val
) = 1;
9472 TREE_OPERAND (exp
, 0) = treeop0
;
9473 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9475 if (!CONSTANT_P (ret
))
9476 ret
= copy_to_reg (ret
);
9477 SET_DECL_RTL (val
, ret
);
9485 /* If we don't need the result, just ensure we evaluate any
9489 unsigned HOST_WIDE_INT idx
;
9492 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9493 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9498 return expand_constructor (exp
, target
, modifier
, false);
9500 case TARGET_MEM_REF
:
9503 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9504 struct mem_address addr
;
9505 enum insn_code icode
;
9508 get_address_description (exp
, &addr
);
9509 op0
= addr_for_mem_ref (&addr
, as
, true);
9510 op0
= memory_address_addr_space (mode
, op0
, as
);
9511 temp
= gen_rtx_MEM (mode
, op0
);
9512 set_mem_attributes (temp
, exp
, 0);
9513 set_mem_addr_space (temp
, as
);
9514 align
= get_object_or_type_alignment (exp
);
9515 if (modifier
!= EXPAND_WRITE
9517 && align
< GET_MODE_ALIGNMENT (mode
)
9518 /* If the target does not have special handling for unaligned
9519 loads of mode then it can use regular moves for them. */
9520 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9521 != CODE_FOR_nothing
))
9523 struct expand_operand ops
[2];
9525 /* We've already validated the memory, and we're creating a
9526 new pseudo destination. The predicates really can't fail,
9527 nor can the generator. */
9528 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9529 create_fixed_operand (&ops
[1], temp
);
9530 expand_insn (icode
, 2, ops
);
9531 return ops
[0].value
;
9539 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9540 enum machine_mode address_mode
;
9541 tree base
= TREE_OPERAND (exp
, 0);
9543 enum insn_code icode
;
9545 /* Handle expansion of non-aliased memory with non-BLKmode. That
9546 might end up in a register. */
9547 if (mem_ref_refers_to_non_mem_p (exp
))
9549 HOST_WIDE_INT offset
= mem_ref_offset (exp
).low
;
9552 base
= TREE_OPERAND (base
, 0);
9554 && host_integerp (TYPE_SIZE (TREE_TYPE (exp
)), 1)
9555 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9556 == TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp
)))))
9557 return expand_expr (build1 (VIEW_CONVERT_EXPR
,
9558 TREE_TYPE (exp
), base
),
9559 target
, tmode
, modifier
);
9560 bit_offset
= bitsize_int (offset
* BITS_PER_UNIT
);
9561 bftype
= TREE_TYPE (base
);
9562 if (TYPE_MODE (TREE_TYPE (exp
)) != BLKmode
)
9563 bftype
= TREE_TYPE (exp
);
9566 temp
= assign_stack_temp (DECL_MODE (base
),
9567 GET_MODE_SIZE (DECL_MODE (base
)),
9569 store_expr (base
, temp
, 0, false);
9570 temp
= adjust_address (temp
, BLKmode
, offset
);
9571 set_mem_size (temp
, int_size_in_bytes (TREE_TYPE (exp
)));
9574 return expand_expr (build3 (BIT_FIELD_REF
, bftype
,
9576 TYPE_SIZE (TREE_TYPE (exp
)),
9578 target
, tmode
, modifier
);
9580 address_mode
= targetm
.addr_space
.address_mode (as
);
9581 base
= TREE_OPERAND (exp
, 0);
9582 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9584 tree mask
= gimple_assign_rhs2 (def_stmt
);
9585 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9586 gimple_assign_rhs1 (def_stmt
), mask
);
9587 TREE_OPERAND (exp
, 0) = base
;
9589 align
= get_object_or_type_alignment (exp
);
9590 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9591 op0
= memory_address_addr_space (address_mode
, op0
, as
);
9592 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9595 = immed_double_int_const (mem_ref_offset (exp
), address_mode
);
9596 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9598 op0
= memory_address_addr_space (mode
, op0
, as
);
9599 temp
= gen_rtx_MEM (mode
, op0
);
9600 set_mem_attributes (temp
, exp
, 0);
9601 set_mem_addr_space (temp
, as
);
9602 if (TREE_THIS_VOLATILE (exp
))
9603 MEM_VOLATILE_P (temp
) = 1;
9604 if (modifier
!= EXPAND_WRITE
9606 && align
< GET_MODE_ALIGNMENT (mode
))
9608 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9609 != CODE_FOR_nothing
)
9611 struct expand_operand ops
[2];
9613 /* We've already validated the memory, and we're creating a
9614 new pseudo destination. The predicates really can't fail,
9615 nor can the generator. */
9616 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9617 create_fixed_operand (&ops
[1], temp
);
9618 expand_insn (icode
, 2, ops
);
9619 return ops
[0].value
;
9621 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9622 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9623 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9624 true, (modifier
== EXPAND_STACK_PARM
9625 ? NULL_RTX
: target
),
9634 tree array
= treeop0
;
9635 tree index
= treeop1
;
9637 /* Fold an expression like: "foo"[2].
9638 This is not done in fold so it won't happen inside &.
9639 Don't fold if this is for wide characters since it's too
9640 difficult to do correctly and this is a very rare case. */
9642 if (modifier
!= EXPAND_CONST_ADDRESS
9643 && modifier
!= EXPAND_INITIALIZER
9644 && modifier
!= EXPAND_MEMORY
)
9646 tree t
= fold_read_from_constant_string (exp
);
9649 return expand_expr (t
, target
, tmode
, modifier
);
9652 /* If this is a constant index into a constant array,
9653 just get the value from the array. Handle both the cases when
9654 we have an explicit constructor and when our operand is a variable
9655 that was declared const. */
9657 if (modifier
!= EXPAND_CONST_ADDRESS
9658 && modifier
!= EXPAND_INITIALIZER
9659 && modifier
!= EXPAND_MEMORY
9660 && TREE_CODE (array
) == CONSTRUCTOR
9661 && ! TREE_SIDE_EFFECTS (array
)
9662 && TREE_CODE (index
) == INTEGER_CST
)
9664 unsigned HOST_WIDE_INT ix
;
9667 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9669 if (tree_int_cst_equal (field
, index
))
9671 if (!TREE_SIDE_EFFECTS (value
))
9672 return expand_expr (fold (value
), target
, tmode
, modifier
);
9677 else if (optimize
>= 1
9678 && modifier
!= EXPAND_CONST_ADDRESS
9679 && modifier
!= EXPAND_INITIALIZER
9680 && modifier
!= EXPAND_MEMORY
9681 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9682 && TREE_CODE (array
) == VAR_DECL
&& DECL_INITIAL (array
)
9683 && TREE_CODE (DECL_INITIAL (array
)) != ERROR_MARK
9684 && const_value_known_p (array
))
9686 if (TREE_CODE (index
) == INTEGER_CST
)
9688 tree init
= DECL_INITIAL (array
);
9690 if (TREE_CODE (init
) == CONSTRUCTOR
)
9692 unsigned HOST_WIDE_INT ix
;
9695 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9697 if (tree_int_cst_equal (field
, index
))
9699 if (TREE_SIDE_EFFECTS (value
))
9702 if (TREE_CODE (value
) == CONSTRUCTOR
)
9704 /* If VALUE is a CONSTRUCTOR, this
9705 optimization is only useful if
9706 this doesn't store the CONSTRUCTOR
9707 into memory. If it does, it is more
9708 efficient to just load the data from
9709 the array directly. */
9710 rtx ret
= expand_constructor (value
, target
,
9712 if (ret
== NULL_RTX
)
9716 return expand_expr (fold (value
), target
, tmode
,
9720 else if(TREE_CODE (init
) == STRING_CST
)
9722 tree index1
= index
;
9723 tree low_bound
= array_ref_low_bound (exp
);
9724 index1
= fold_convert_loc (loc
, sizetype
,
9727 /* Optimize the special-case of a zero lower bound.
9729 We convert the low_bound to sizetype to avoid some problems
9730 with constant folding. (E.g. suppose the lower bound is 1,
9731 and its mode is QI. Without the conversion,l (ARRAY
9732 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
9733 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
9735 if (! integer_zerop (low_bound
))
9736 index1
= size_diffop_loc (loc
, index1
,
9737 fold_convert_loc (loc
, sizetype
,
9740 if (0 > compare_tree_int (index1
,
9741 TREE_STRING_LENGTH (init
)))
9743 tree type
= TREE_TYPE (TREE_TYPE (init
));
9744 enum machine_mode mode
= TYPE_MODE (type
);
9746 if (GET_MODE_CLASS (mode
) == MODE_INT
9747 && GET_MODE_SIZE (mode
) == 1)
9748 return gen_int_mode (TREE_STRING_POINTER (init
)
9749 [TREE_INT_CST_LOW (index1
)],
9756 goto normal_inner_ref
;
9759 /* If the operand is a CONSTRUCTOR, we can just extract the
9760 appropriate field if it is present. */
9761 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9763 unsigned HOST_WIDE_INT idx
;
9766 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9768 if (field
== treeop1
9769 /* We can normally use the value of the field in the
9770 CONSTRUCTOR. However, if this is a bitfield in
9771 an integral mode that we can fit in a HOST_WIDE_INT,
9772 we must mask only the number of bits in the bitfield,
9773 since this is done implicitly by the constructor. If
9774 the bitfield does not meet either of those conditions,
9775 we can't do this optimization. */
9776 && (! DECL_BIT_FIELD (field
)
9777 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9778 && (GET_MODE_PRECISION (DECL_MODE (field
))
9779 <= HOST_BITS_PER_WIDE_INT
))))
9781 if (DECL_BIT_FIELD (field
)
9782 && modifier
== EXPAND_STACK_PARM
)
9784 op0
= expand_expr (value
, target
, tmode
, modifier
);
9785 if (DECL_BIT_FIELD (field
))
9787 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9788 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9790 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9792 op1
= GEN_INT (((HOST_WIDE_INT
) 1 << bitsize
) - 1);
9793 op0
= expand_and (imode
, op0
, op1
, target
);
9797 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
9799 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
9801 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
9809 goto normal_inner_ref
;
9812 case ARRAY_RANGE_REF
:
9815 enum machine_mode mode1
, mode2
;
9816 HOST_WIDE_INT bitsize
, bitpos
;
9818 int volatilep
= 0, must_force_mem
;
9819 bool packedp
= false;
9820 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
9821 &mode1
, &unsignedp
, &volatilep
, true);
9822 rtx orig_op0
, memloc
;
9823 bool mem_attrs_from_type
= false;
9825 /* If we got back the original object, something is wrong. Perhaps
9826 we are evaluating an expression too early. In any event, don't
9827 infinitely recurse. */
9828 gcc_assert (tem
!= exp
);
9830 if (TYPE_PACKED (TREE_TYPE (TREE_OPERAND (exp
, 0)))
9831 || (TREE_CODE (TREE_OPERAND (exp
, 1)) == FIELD_DECL
9832 && DECL_PACKED (TREE_OPERAND (exp
, 1))))
9835 /* If TEM's type is a union of variable size, pass TARGET to the inner
9836 computation, since it will need a temporary and TARGET is known
9837 to have to do. This occurs in unchecked conversion in Ada. */
9840 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
9841 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
9843 && modifier
!= EXPAND_STACK_PARM
9844 ? target
: NULL_RTX
),
9846 (modifier
== EXPAND_INITIALIZER
9847 || modifier
== EXPAND_CONST_ADDRESS
9848 || modifier
== EXPAND_STACK_PARM
)
9849 ? modifier
: EXPAND_NORMAL
);
9852 /* If the bitfield is volatile, we want to access it in the
9853 field's mode, not the computed mode.
9854 If a MEM has VOIDmode (external with incomplete type),
9855 use BLKmode for it instead. */
9858 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
9859 op0
= adjust_address (op0
, mode1
, 0);
9860 else if (GET_MODE (op0
) == VOIDmode
)
9861 op0
= adjust_address (op0
, BLKmode
, 0);
9865 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
9867 /* If we have either an offset, a BLKmode result, or a reference
9868 outside the underlying object, we must force it to memory.
9869 Such a case can occur in Ada if we have unchecked conversion
9870 of an expression from a scalar type to an aggregate type or
9871 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9872 passed a partially uninitialized object or a view-conversion
9873 to a larger size. */
9874 must_force_mem
= (offset
9876 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
9878 /* Handle CONCAT first. */
9879 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
9882 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
9885 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9888 op0
= XEXP (op0
, 0);
9889 mode2
= GET_MODE (op0
);
9891 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9892 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
9896 op0
= XEXP (op0
, 1);
9898 mode2
= GET_MODE (op0
);
9901 /* Otherwise force into memory. */
9905 /* If this is a constant, put it in a register if it is a legitimate
9906 constant and we don't need a memory reference. */
9907 if (CONSTANT_P (op0
)
9909 && targetm
.legitimate_constant_p (mode2
, op0
)
9911 op0
= force_reg (mode2
, op0
);
9913 /* Otherwise, if this is a constant, try to force it to the constant
9914 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9915 is a legitimate constant. */
9916 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
9917 op0
= validize_mem (memloc
);
9919 /* Otherwise, if this is a constant or the object is not in memory
9920 and need be, put it there. */
9921 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
9923 tree nt
= build_qualified_type (TREE_TYPE (tem
),
9924 (TYPE_QUALS (TREE_TYPE (tem
))
9925 | TYPE_QUAL_CONST
));
9926 memloc
= assign_temp (nt
, 1, 1, 1);
9927 emit_move_insn (memloc
, op0
);
9929 mem_attrs_from_type
= true;
9934 enum machine_mode address_mode
;
9935 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
9938 gcc_assert (MEM_P (op0
));
9941 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (op0
));
9942 if (GET_MODE (offset_rtx
) != address_mode
)
9943 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
9945 if (GET_MODE (op0
) == BLKmode
9946 /* A constant address in OP0 can have VOIDmode, we must
9947 not try to call force_reg in that case. */
9948 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
9950 && (bitpos
% bitsize
) == 0
9951 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
9952 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
9954 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
9958 op0
= offset_address (op0
, offset_rtx
,
9959 highest_pow2_factor (offset
));
9962 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
9963 record its alignment as BIGGEST_ALIGNMENT. */
9964 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
9965 && is_aligning_offset (offset
, tem
))
9966 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
9968 /* Don't forget about volatility even if this is a bitfield. */
9969 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
9971 if (op0
== orig_op0
)
9972 op0
= copy_rtx (op0
);
9974 MEM_VOLATILE_P (op0
) = 1;
9977 /* In cases where an aligned union has an unaligned object
9978 as a field, we might be extracting a BLKmode value from
9979 an integer-mode (e.g., SImode) object. Handle this case
9980 by doing the extract into an object as wide as the field
9981 (which we know to be the width of a basic mode), then
9982 storing into memory, and changing the mode to BLKmode. */
9983 if (mode1
== VOIDmode
9984 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
9985 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
9986 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
9987 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
9988 && modifier
!= EXPAND_CONST_ADDRESS
9989 && modifier
!= EXPAND_INITIALIZER
)
9990 /* If the field is volatile, we always want an aligned
9991 access. Do this in following two situations:
9992 1. the access is not already naturally
9993 aligned, otherwise "normal" (non-bitfield) volatile fields
9994 become non-addressable.
9995 2. the bitsize is narrower than the access size. Need
9996 to extract bitfields from the access. */
9997 || (volatilep
&& flag_strict_volatile_bitfields
> 0
9998 && (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0
9999 || (mode1
!= BLKmode
10000 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)))
10001 /* If the field isn't aligned enough to fetch as a memref,
10002 fetch it as a bit field. */
10003 || (mode1
!= BLKmode
10004 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10005 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10007 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10008 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10009 && ((modifier
== EXPAND_CONST_ADDRESS
10010 || modifier
== EXPAND_INITIALIZER
)
10012 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10013 || (bitpos
% BITS_PER_UNIT
!= 0)))
10014 /* If the type and the field are a constant size and the
10015 size of the type isn't the same size as the bitfield,
10016 we must use bitfield operations. */
10018 && TYPE_SIZE (TREE_TYPE (exp
))
10019 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10020 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10023 enum machine_mode ext_mode
= mode
;
10025 if (ext_mode
== BLKmode
10026 && ! (target
!= 0 && MEM_P (op0
)
10028 && bitpos
% BITS_PER_UNIT
== 0))
10029 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10031 if (ext_mode
== BLKmode
)
10034 target
= assign_temp (type
, 0, 1, 1);
10039 /* In this case, BITPOS must start at a byte boundary and
10040 TARGET, if specified, must be a MEM. */
10041 gcc_assert (MEM_P (op0
)
10042 && (!target
|| MEM_P (target
))
10043 && !(bitpos
% BITS_PER_UNIT
));
10045 emit_block_move (target
,
10046 adjust_address (op0
, VOIDmode
,
10047 bitpos
/ BITS_PER_UNIT
),
10048 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10050 (modifier
== EXPAND_STACK_PARM
10051 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10056 op0
= validize_mem (op0
);
10058 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10059 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10061 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
, packedp
,
10062 (modifier
== EXPAND_STACK_PARM
10063 ? NULL_RTX
: target
),
10064 ext_mode
, ext_mode
);
10066 /* If the result is a record type and BITSIZE is narrower than
10067 the mode of OP0, an integral mode, and this is a big endian
10068 machine, we must put the field into the high-order bits. */
10069 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10070 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10071 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10072 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10073 GET_MODE_BITSIZE (GET_MODE (op0
))
10074 - bitsize
, op0
, 1);
10076 /* If the result type is BLKmode, store the data into a temporary
10077 of the appropriate type, but with the mode corresponding to the
10078 mode for the data we have (op0's mode). It's tempting to make
10079 this a constant type, since we know it's only being stored once,
10080 but that can cause problems if we are taking the address of this
10081 COMPONENT_REF because the MEM of any reference via that address
10082 will have flags corresponding to the type, which will not
10083 necessarily be constant. */
10084 if (mode
== BLKmode
)
10088 new_rtx
= assign_stack_temp_for_type (ext_mode
,
10089 GET_MODE_BITSIZE (ext_mode
),
10091 emit_move_insn (new_rtx
, op0
);
10092 op0
= copy_rtx (new_rtx
);
10093 PUT_MODE (op0
, BLKmode
);
10099 /* If the result is BLKmode, use that to access the object
10101 if (mode
== BLKmode
)
10104 /* Get a reference to just this component. */
10105 if (modifier
== EXPAND_CONST_ADDRESS
10106 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10107 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10109 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10111 if (op0
== orig_op0
)
10112 op0
= copy_rtx (op0
);
10114 /* If op0 is a temporary because of forcing to memory, pass only the
10115 type to set_mem_attributes so that the original expression is never
10116 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10117 if (mem_attrs_from_type
)
10118 set_mem_attributes (op0
, type
, 0);
10120 set_mem_attributes (op0
, exp
, 0);
10122 if (REG_P (XEXP (op0
, 0)))
10123 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10125 MEM_VOLATILE_P (op0
) |= volatilep
;
10126 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10127 || modifier
== EXPAND_CONST_ADDRESS
10128 || modifier
== EXPAND_INITIALIZER
)
10130 else if (target
== 0)
10131 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10133 convert_move (target
, op0
, unsignedp
);
10138 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10141 /* All valid uses of __builtin_va_arg_pack () are removed during
10143 if (CALL_EXPR_VA_ARG_PACK (exp
))
10144 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10146 tree fndecl
= get_callee_fndecl (exp
), attr
;
10149 && (attr
= lookup_attribute ("error",
10150 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10151 error ("%Kcall to %qs declared with attribute error: %s",
10152 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10153 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10155 && (attr
= lookup_attribute ("warning",
10156 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10157 warning_at (tree_nonartificial_location (exp
),
10158 0, "%Kcall to %qs declared with attribute warning: %s",
10159 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10160 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10162 /* Check for a built-in function. */
10163 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10165 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10166 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10169 return expand_call (exp
, target
, ignore
);
10171 case VIEW_CONVERT_EXPR
:
10174 /* If we are converting to BLKmode, try to avoid an intermediate
10175 temporary by fetching an inner memory reference. */
10176 if (mode
== BLKmode
10177 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10178 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10179 && handled_component_p (treeop0
))
10181 enum machine_mode mode1
;
10182 HOST_WIDE_INT bitsize
, bitpos
;
10187 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10188 &offset
, &mode1
, &unsignedp
, &volatilep
,
10192 /* ??? We should work harder and deal with non-zero offsets. */
10194 && (bitpos
% BITS_PER_UNIT
) == 0
10196 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) == 0)
10198 /* See the normal_inner_ref case for the rationale. */
10200 = expand_expr (tem
,
10201 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10202 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10204 && modifier
!= EXPAND_STACK_PARM
10205 ? target
: NULL_RTX
),
10207 (modifier
== EXPAND_INITIALIZER
10208 || modifier
== EXPAND_CONST_ADDRESS
10209 || modifier
== EXPAND_STACK_PARM
)
10210 ? modifier
: EXPAND_NORMAL
);
10212 if (MEM_P (orig_op0
))
10216 /* Get a reference to just this component. */
10217 if (modifier
== EXPAND_CONST_ADDRESS
10218 || modifier
== EXPAND_SUM
10219 || modifier
== EXPAND_INITIALIZER
)
10220 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10222 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10224 if (op0
== orig_op0
)
10225 op0
= copy_rtx (op0
);
10227 set_mem_attributes (op0
, treeop0
, 0);
10228 if (REG_P (XEXP (op0
, 0)))
10229 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10231 MEM_VOLATILE_P (op0
) |= volatilep
;
10237 op0
= expand_expr (treeop0
,
10238 NULL_RTX
, VOIDmode
, modifier
);
10240 /* If the input and output modes are both the same, we are done. */
10241 if (mode
== GET_MODE (op0
))
10243 /* If neither mode is BLKmode, and both modes are the same size
10244 then we can use gen_lowpart. */
10245 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10246 && (GET_MODE_PRECISION (mode
)
10247 == GET_MODE_PRECISION (GET_MODE (op0
)))
10248 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10250 if (GET_CODE (op0
) == SUBREG
)
10251 op0
= force_reg (GET_MODE (op0
), op0
);
10252 temp
= gen_lowpart_common (mode
, op0
);
10257 if (!REG_P (op0
) && !MEM_P (op0
))
10258 op0
= force_reg (GET_MODE (op0
), op0
);
10259 op0
= gen_lowpart (mode
, op0
);
10262 /* If both types are integral, convert from one mode to the other. */
10263 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10264 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10265 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10266 /* As a last resort, spill op0 to memory, and reload it in a
10268 else if (!MEM_P (op0
))
10270 /* If the operand is not a MEM, force it into memory. Since we
10271 are going to be changing the mode of the MEM, don't call
10272 force_const_mem for constants because we don't allow pool
10273 constants to change mode. */
10274 tree inner_type
= TREE_TYPE (treeop0
);
10276 gcc_assert (!TREE_ADDRESSABLE (exp
));
10278 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10280 = assign_stack_temp_for_type
10281 (TYPE_MODE (inner_type
),
10282 GET_MODE_SIZE (TYPE_MODE (inner_type
)), 0, inner_type
);
10284 emit_move_insn (target
, op0
);
10288 /* At this point, OP0 is in the correct mode. If the output type is
10289 such that the operand is known to be aligned, indicate that it is.
10290 Otherwise, we need only be concerned about alignment for non-BLKmode
10294 enum insn_code icode
;
10296 op0
= copy_rtx (op0
);
10298 if (TYPE_ALIGN_OK (type
))
10299 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10300 else if (mode
!= BLKmode
10301 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
)
10302 /* If the target does have special handling for unaligned
10303 loads of mode then use them. */
10304 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10305 != CODE_FOR_nothing
))
10309 op0
= adjust_address (op0
, mode
, 0);
10310 /* We've already validated the memory, and we're creating a
10311 new pseudo destination. The predicates really can't
10313 reg
= gen_reg_rtx (mode
);
10315 /* Nor can the insn generator. */
10316 insn
= GEN_FCN (icode
) (reg
, op0
);
10320 else if (STRICT_ALIGNMENT
10322 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10324 tree inner_type
= TREE_TYPE (treeop0
);
10325 HOST_WIDE_INT temp_size
10326 = MAX (int_size_in_bytes (inner_type
),
10327 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10329 = assign_stack_temp_for_type (mode
, temp_size
, 0, type
);
10330 rtx new_with_op0_mode
10331 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10333 gcc_assert (!TREE_ADDRESSABLE (exp
));
10335 if (GET_MODE (op0
) == BLKmode
)
10336 emit_block_move (new_with_op0_mode
, op0
,
10337 GEN_INT (GET_MODE_SIZE (mode
)),
10338 (modifier
== EXPAND_STACK_PARM
10339 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10341 emit_move_insn (new_with_op0_mode
, op0
);
10346 op0
= adjust_address (op0
, mode
, 0);
10353 tree lhs
= treeop0
;
10354 tree rhs
= treeop1
;
10355 gcc_assert (ignore
);
10357 /* Check for |= or &= of a bitfield of size one into another bitfield
10358 of size 1. In this case, (unless we need the result of the
10359 assignment) we can do this more efficiently with a
10360 test followed by an assignment, if necessary.
10362 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10363 things change so we do, this code should be enhanced to
10365 if (TREE_CODE (lhs
) == COMPONENT_REF
10366 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10367 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10368 && TREE_OPERAND (rhs
, 0) == lhs
10369 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10370 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10371 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10373 rtx label
= gen_label_rtx ();
10374 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10375 do_jump (TREE_OPERAND (rhs
, 1),
10377 value
? 0 : label
, -1);
10378 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10379 MOVE_NONTEMPORAL (exp
));
10380 do_pending_stack_adjust ();
10381 emit_label (label
);
10385 expand_assignment (lhs
, rhs
, MOVE_NONTEMPORAL (exp
));
10390 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10392 case REALPART_EXPR
:
10393 op0
= expand_normal (treeop0
);
10394 return read_complex_part (op0
, false);
10396 case IMAGPART_EXPR
:
10397 op0
= expand_normal (treeop0
);
10398 return read_complex_part (op0
, true);
10405 /* Expanded in cfgexpand.c. */
10406 gcc_unreachable ();
10408 case TRY_CATCH_EXPR
:
10410 case EH_FILTER_EXPR
:
10411 case TRY_FINALLY_EXPR
:
10412 /* Lowered by tree-eh.c. */
10413 gcc_unreachable ();
10415 case WITH_CLEANUP_EXPR
:
10416 case CLEANUP_POINT_EXPR
:
10418 case CASE_LABEL_EXPR
:
10423 case COMPOUND_EXPR
:
10424 case PREINCREMENT_EXPR
:
10425 case PREDECREMENT_EXPR
:
10426 case POSTINCREMENT_EXPR
:
10427 case POSTDECREMENT_EXPR
:
10430 /* Lowered by gimplify.c. */
10431 gcc_unreachable ();
10434 /* Function descriptors are not valid except for as
10435 initialization constants, and should not be expanded. */
10436 gcc_unreachable ();
10438 case WITH_SIZE_EXPR
:
10439 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10440 have pulled out the size to use in whatever context it needed. */
10441 return expand_expr_real (treeop0
, original_target
, tmode
,
10442 modifier
, alt_rtl
);
10444 case COMPOUND_LITERAL_EXPR
:
10446 /* Initialize the anonymous variable declared in the compound
10447 literal, then return the variable. */
10448 tree decl
= COMPOUND_LITERAL_EXPR_DECL (exp
);
10450 /* Create RTL for this variable. */
10451 if (!DECL_RTL_SET_P (decl
))
10453 if (DECL_HARD_REGISTER (decl
))
10454 /* The user specified an assembler name for this variable.
10455 Set that up now. */
10456 rest_of_decl_compilation (decl
, 0, 0);
10458 expand_decl (decl
);
10461 return expand_expr_real (decl
, original_target
, tmode
,
10462 modifier
, alt_rtl
);
10466 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10470 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10471 signedness of TYPE), possibly returning the result in TARGET. */
10473 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10475 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10476 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10478 /* For constant values, reduce using build_int_cst_type. */
10479 if (CONST_INT_P (exp
))
10481 HOST_WIDE_INT value
= INTVAL (exp
);
10482 tree t
= build_int_cst_type (type
, value
);
10483 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10485 else if (TYPE_UNSIGNED (type
))
10487 rtx mask
= immed_double_int_const (double_int_mask (prec
),
10489 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
10493 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10494 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10495 exp
, count
, target
, 0);
10496 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10497 exp
, count
, target
, 0);
10501 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10502 when applied to the address of EXP produces an address known to be
10503 aligned more than BIGGEST_ALIGNMENT. */
10506 is_aligning_offset (const_tree offset
, const_tree exp
)
10508 /* Strip off any conversions. */
10509 while (CONVERT_EXPR_P (offset
))
10510 offset
= TREE_OPERAND (offset
, 0);
10512 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10513 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10514 if (TREE_CODE (offset
) != BIT_AND_EXPR
10515 || !host_integerp (TREE_OPERAND (offset
, 1), 1)
10516 || compare_tree_int (TREE_OPERAND (offset
, 1),
10517 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10518 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset
, 1), 1) + 1) < 0)
10521 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10522 It must be NEGATE_EXPR. Then strip any more conversions. */
10523 offset
= TREE_OPERAND (offset
, 0);
10524 while (CONVERT_EXPR_P (offset
))
10525 offset
= TREE_OPERAND (offset
, 0);
10527 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10530 offset
= TREE_OPERAND (offset
, 0);
10531 while (CONVERT_EXPR_P (offset
))
10532 offset
= TREE_OPERAND (offset
, 0);
10534 /* This must now be the address of EXP. */
10535 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10538 /* Return the tree node if an ARG corresponds to a string constant or zero
10539 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10540 in bytes within the string that ARG is accessing. The type of the
10541 offset will be `sizetype'. */
10544 string_constant (tree arg
, tree
*ptr_offset
)
10546 tree array
, offset
, lower_bound
;
10549 if (TREE_CODE (arg
) == ADDR_EXPR
)
10551 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10553 *ptr_offset
= size_zero_node
;
10554 return TREE_OPERAND (arg
, 0);
10556 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10558 array
= TREE_OPERAND (arg
, 0);
10559 offset
= size_zero_node
;
10561 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10563 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10564 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10565 if (TREE_CODE (array
) != STRING_CST
10566 && TREE_CODE (array
) != VAR_DECL
)
10569 /* Check if the array has a nonzero lower bound. */
10570 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10571 if (!integer_zerop (lower_bound
))
10573 /* If the offset and base aren't both constants, return 0. */
10574 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10576 if (TREE_CODE (offset
) != INTEGER_CST
)
10578 /* Adjust offset by the lower bound. */
10579 offset
= size_diffop (fold_convert (sizetype
, offset
),
10580 fold_convert (sizetype
, lower_bound
));
10583 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10585 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10586 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10587 if (TREE_CODE (array
) != ADDR_EXPR
)
10589 array
= TREE_OPERAND (array
, 0);
10590 if (TREE_CODE (array
) != STRING_CST
10591 && TREE_CODE (array
) != VAR_DECL
)
10597 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10599 tree arg0
= TREE_OPERAND (arg
, 0);
10600 tree arg1
= TREE_OPERAND (arg
, 1);
10605 if (TREE_CODE (arg0
) == ADDR_EXPR
10606 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10607 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10609 array
= TREE_OPERAND (arg0
, 0);
10612 else if (TREE_CODE (arg1
) == ADDR_EXPR
10613 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10614 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10616 array
= TREE_OPERAND (arg1
, 0);
10625 if (TREE_CODE (array
) == STRING_CST
)
10627 *ptr_offset
= fold_convert (sizetype
, offset
);
10630 else if (TREE_CODE (array
) == VAR_DECL
10631 || TREE_CODE (array
) == CONST_DECL
)
10635 /* Variables initialized to string literals can be handled too. */
10636 if (!const_value_known_p (array
)
10637 || !DECL_INITIAL (array
)
10638 || TREE_CODE (DECL_INITIAL (array
)) != STRING_CST
)
10641 /* Avoid const char foo[4] = "abcde"; */
10642 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10643 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10644 || (length
= TREE_STRING_LENGTH (DECL_INITIAL (array
))) <= 0
10645 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10648 /* If variable is bigger than the string literal, OFFSET must be constant
10649 and inside of the bounds of the string literal. */
10650 offset
= fold_convert (sizetype
, offset
);
10651 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10652 && (! host_integerp (offset
, 1)
10653 || compare_tree_int (offset
, length
) >= 0))
10656 *ptr_offset
= offset
;
10657 return DECL_INITIAL (array
);
10663 /* Generate code to calculate OPS, and exploded expression
10664 using a store-flag instruction and return an rtx for the result.
10665 OPS reflects a comparison.
10667 If TARGET is nonzero, store the result there if convenient.
10669 Return zero if there is no suitable set-flag instruction
10670 available on this machine.
10672 Once expand_expr has been called on the arguments of the comparison,
10673 we are committed to doing the store flag, since it is not safe to
10674 re-evaluate the expression. We emit the store-flag insn by calling
10675 emit_store_flag, but only expand the arguments if we have a reason
10676 to believe that emit_store_flag will be successful. If we think that
10677 it will, but it isn't, we have to simulate the store-flag with a
10678 set/jump/set sequence. */
10681 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10683 enum rtx_code code
;
10684 tree arg0
, arg1
, type
;
10686 enum machine_mode operand_mode
;
10689 rtx subtarget
= target
;
10690 location_t loc
= ops
->location
;
10695 /* Don't crash if the comparison was erroneous. */
10696 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10699 type
= TREE_TYPE (arg0
);
10700 operand_mode
= TYPE_MODE (type
);
10701 unsignedp
= TYPE_UNSIGNED (type
);
10703 /* We won't bother with BLKmode store-flag operations because it would mean
10704 passing a lot of information to emit_store_flag. */
10705 if (operand_mode
== BLKmode
)
10708 /* We won't bother with store-flag operations involving function pointers
10709 when function pointers must be canonicalized before comparisons. */
10710 #ifdef HAVE_canonicalize_funcptr_for_compare
10711 if (HAVE_canonicalize_funcptr_for_compare
10712 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10713 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10715 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10716 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10717 == FUNCTION_TYPE
))))
10724 /* For vector typed comparisons emit code to generate the desired
10725 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10726 expander for this. */
10727 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10729 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10730 tree if_true
= constant_boolean_node (true, ops
->type
);
10731 tree if_false
= constant_boolean_node (false, ops
->type
);
10732 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10735 /* For vector typed comparisons emit code to generate the desired
10736 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10737 expander for this. */
10738 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10740 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10741 tree if_true
= constant_boolean_node (true, ops
->type
);
10742 tree if_false
= constant_boolean_node (false, ops
->type
);
10743 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10746 /* Get the rtx comparison code to use. We know that EXP is a comparison
10747 operation of some type. Some comparisons against 1 and -1 can be
10748 converted to comparisons with zero. Do so here so that the tests
10749 below will be aware that we have a comparison with zero. These
10750 tests will not catch constants in the first operand, but constants
10751 are rarely passed as the first operand. */
10762 if (integer_onep (arg1
))
10763 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10765 code
= unsignedp
? LTU
: LT
;
10768 if (! unsignedp
&& integer_all_onesp (arg1
))
10769 arg1
= integer_zero_node
, code
= LT
;
10771 code
= unsignedp
? LEU
: LE
;
10774 if (! unsignedp
&& integer_all_onesp (arg1
))
10775 arg1
= integer_zero_node
, code
= GE
;
10777 code
= unsignedp
? GTU
: GT
;
10780 if (integer_onep (arg1
))
10781 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10783 code
= unsignedp
? GEU
: GE
;
10786 case UNORDERED_EXPR
:
10812 gcc_unreachable ();
10815 /* Put a constant second. */
10816 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
10817 || TREE_CODE (arg0
) == FIXED_CST
)
10819 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
10820 code
= swap_condition (code
);
10823 /* If this is an equality or inequality test of a single bit, we can
10824 do this by shifting the bit being tested to the low-order bit and
10825 masking the result with the constant 1. If the condition was EQ,
10826 we xor it with 1. This does not require an scc insn and is faster
10827 than an scc insn even if we have it.
10829 The code to make this transformation was moved into fold_single_bit_test,
10830 so we just call into the folder and expand its result. */
10832 if ((code
== NE
|| code
== EQ
)
10833 && integer_zerop (arg1
)
10834 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
10836 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
10838 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
10840 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
10841 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10842 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
10843 gimple_assign_rhs1 (srcstmt
),
10844 gimple_assign_rhs2 (srcstmt
));
10845 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
10847 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
10851 if (! get_subtarget (target
)
10852 || GET_MODE (subtarget
) != operand_mode
)
10855 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10858 target
= gen_reg_rtx (mode
);
10860 /* Try a cstore if possible. */
10861 return emit_store_flag_force (target
, code
, op0
, op1
,
10862 operand_mode
, unsignedp
,
10863 (TYPE_PRECISION (ops
->type
) == 1
10864 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
10868 /* Stubs in case we haven't got a casesi insn. */
10869 #ifndef HAVE_casesi
10870 # define HAVE_casesi 0
10871 # define gen_casesi(a, b, c, d, e) (0)
10872 # define CODE_FOR_casesi CODE_FOR_nothing
10875 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10876 0 otherwise (i.e. if there is no casesi instruction). */
10878 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
10879 rtx table_label ATTRIBUTE_UNUSED
, rtx default_label
,
10880 rtx fallback_label ATTRIBUTE_UNUSED
)
10882 struct expand_operand ops
[5];
10883 enum machine_mode index_mode
= SImode
;
10884 rtx op1
, op2
, index
;
10889 /* Convert the index to SImode. */
10890 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
10892 enum machine_mode omode
= TYPE_MODE (index_type
);
10893 rtx rangertx
= expand_normal (range
);
10895 /* We must handle the endpoints in the original mode. */
10896 index_expr
= build2 (MINUS_EXPR
, index_type
,
10897 index_expr
, minval
);
10898 minval
= integer_zero_node
;
10899 index
= expand_normal (index_expr
);
10901 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
10902 omode
, 1, default_label
);
10903 /* Now we can safely truncate. */
10904 index
= convert_to_mode (index_mode
, index
, 0);
10908 if (TYPE_MODE (index_type
) != index_mode
)
10910 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
10911 index_expr
= fold_convert (index_type
, index_expr
);
10914 index
= expand_normal (index_expr
);
10917 do_pending_stack_adjust ();
10919 op1
= expand_normal (minval
);
10920 op2
= expand_normal (range
);
10922 create_input_operand (&ops
[0], index
, index_mode
);
10923 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
10924 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
10925 create_fixed_operand (&ops
[3], table_label
);
10926 create_fixed_operand (&ops
[4], (default_label
10928 : fallback_label
));
10929 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
10933 /* Attempt to generate a tablejump instruction; same concept. */
10934 #ifndef HAVE_tablejump
10935 #define HAVE_tablejump 0
10936 #define gen_tablejump(x, y) (0)
10939 /* Subroutine of the next function.
10941 INDEX is the value being switched on, with the lowest value
10942 in the table already subtracted.
10943 MODE is its expected mode (needed if INDEX is constant).
10944 RANGE is the length of the jump table.
10945 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10947 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10948 index value is out of range. */
10951 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
10956 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
10957 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
10959 /* Do an unsigned comparison (in the proper mode) between the index
10960 expression and the value which represents the length of the range.
10961 Since we just finished subtracting the lower bound of the range
10962 from the index expression, this comparison allows us to simultaneously
10963 check that the original index expression value is both greater than
10964 or equal to the minimum value of the range and less than or equal to
10965 the maximum value of the range. */
10968 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
10971 /* If index is in range, it must fit in Pmode.
10972 Convert to Pmode so we can index with it. */
10974 index
= convert_to_mode (Pmode
, index
, 1);
10976 /* Don't let a MEM slip through, because then INDEX that comes
10977 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
10978 and break_out_memory_refs will go to work on it and mess it up. */
10979 #ifdef PIC_CASE_VECTOR_ADDRESS
10980 if (flag_pic
&& !REG_P (index
))
10981 index
= copy_to_mode_reg (Pmode
, index
);
10984 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
10985 GET_MODE_SIZE, because this indicates how large insns are. The other
10986 uses should all be Pmode, because they are addresses. This code
10987 could fail if addresses and insns are not the same size. */
10988 index
= gen_rtx_PLUS (Pmode
,
10989 gen_rtx_MULT (Pmode
, index
,
10990 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE
))),
10991 gen_rtx_LABEL_REF (Pmode
, table_label
));
10992 #ifdef PIC_CASE_VECTOR_ADDRESS
10994 index
= PIC_CASE_VECTOR_ADDRESS (index
);
10997 index
= memory_address (CASE_VECTOR_MODE
, index
);
10998 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
10999 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11000 convert_move (temp
, vector
, 0);
11002 emit_jump_insn (gen_tablejump (temp
, table_label
));
11004 /* If we are generating PIC code or if the table is PC-relative, the
11005 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11006 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11011 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11012 rtx table_label
, rtx default_label
)
11016 if (! HAVE_tablejump
)
11019 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11020 fold_convert (index_type
, index_expr
),
11021 fold_convert (index_type
, minval
));
11022 index
= expand_normal (index_expr
);
11023 do_pending_stack_adjust ();
11025 do_tablejump (index
, TYPE_MODE (index_type
),
11026 convert_modes (TYPE_MODE (index_type
),
11027 TYPE_MODE (TREE_TYPE (range
)),
11028 expand_normal (range
),
11029 TYPE_UNSIGNED (TREE_TYPE (range
))),
11030 table_label
, default_label
);
11034 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11036 const_vector_from_tree (tree exp
)
11042 enum machine_mode inner
, mode
;
11044 mode
= TYPE_MODE (TREE_TYPE (exp
));
11046 if (initializer_zerop (exp
))
11047 return CONST0_RTX (mode
);
11049 units
= GET_MODE_NUNITS (mode
);
11050 inner
= GET_MODE_INNER (mode
);
11052 v
= rtvec_alloc (units
);
11054 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11056 elt
= VECTOR_CST_ELT (exp
, i
);
11058 if (TREE_CODE (elt
) == REAL_CST
)
11059 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11061 else if (TREE_CODE (elt
) == FIXED_CST
)
11062 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11065 RTVEC_ELT (v
, i
) = immed_double_int_const (tree_to_double_int (elt
),
11069 return gen_rtx_CONST_VECTOR (mode
, v
);
11072 /* Build a decl for a personality function given a language prefix. */
11075 build_personality_function (const char *lang
)
11077 const char *unwind_and_version
;
11081 switch (targetm_common
.except_unwind_info (&global_options
))
11086 unwind_and_version
= "_sj0";
11090 unwind_and_version
= "_v0";
11093 gcc_unreachable ();
11096 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11098 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11099 long_long_unsigned_type_node
,
11100 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11101 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11102 get_identifier (name
), type
);
11103 DECL_ARTIFICIAL (decl
) = 1;
11104 DECL_EXTERNAL (decl
) = 1;
11105 TREE_PUBLIC (decl
) = 1;
11107 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11108 are the flags assigned by targetm.encode_section_info. */
11109 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11114 /* Extracts the personality function of DECL and returns the corresponding
11118 get_personality_function (tree decl
)
11120 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11121 enum eh_personality_kind pk
;
11123 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11124 if (pk
== eh_personality_none
)
11128 && pk
== eh_personality_any
)
11129 personality
= lang_hooks
.eh_personality ();
11131 if (pk
== eh_personality_lang
)
11132 gcc_assert (personality
!= NULL_TREE
);
11134 return XEXP (DECL_RTL (personality
), 0);
11137 #include "gt-expr.h"