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
, len
));
931 data
.autinc_from
= 1;
932 data
.explicit_inc_from
= -1;
934 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
936 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
937 data
.autinc_from
= 1;
938 data
.explicit_inc_from
= 1;
940 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
941 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
942 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
944 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
945 plus_constant (to_addr
, len
));
947 data
.explicit_inc_to
= -1;
949 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
951 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
953 data
.explicit_inc_to
= 1;
955 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
956 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
959 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
961 /* First move what we can in the largest integer mode, then go to
962 successively smaller modes. */
966 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
968 if (mode
== VOIDmode
)
971 icode
= optab_handler (mov_optab
, mode
);
972 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
973 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
975 max_size
= GET_MODE_SIZE (mode
);
978 /* The code above should have handled everything. */
979 gcc_assert (!data
.len
);
985 gcc_assert (!data
.reverse
);
990 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
991 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
993 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
994 plus_constant (data
.to_addr
,
997 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
1004 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1012 /* Return number of insns required to move L bytes by pieces.
1013 ALIGN (in bits) is maximum alignment we can assume. */
1015 unsigned HOST_WIDE_INT
1016 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1017 unsigned int max_size
)
1019 unsigned HOST_WIDE_INT n_insns
= 0;
1021 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1023 while (max_size
> 1)
1025 enum machine_mode mode
;
1026 enum insn_code icode
;
1028 mode
= widest_int_mode_for_size (max_size
);
1030 if (mode
== VOIDmode
)
1033 icode
= optab_handler (mov_optab
, mode
);
1034 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1035 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1037 max_size
= GET_MODE_SIZE (mode
);
1044 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1045 with move instructions for mode MODE. GENFUN is the gen_... function
1046 to make a move insn for that mode. DATA has all the other info. */
1049 move_by_pieces_1 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
1050 struct move_by_pieces_d
*data
)
1052 unsigned int size
= GET_MODE_SIZE (mode
);
1053 rtx to1
= NULL_RTX
, from1
;
1055 while (data
->len
>= size
)
1058 data
->offset
-= size
;
1062 if (data
->autinc_to
)
1063 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1066 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1069 if (data
->autinc_from
)
1070 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1073 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1075 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1076 emit_insn (gen_add2_insn (data
->to_addr
,
1077 GEN_INT (-(HOST_WIDE_INT
)size
)));
1078 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1079 emit_insn (gen_add2_insn (data
->from_addr
,
1080 GEN_INT (-(HOST_WIDE_INT
)size
)));
1083 emit_insn ((*genfun
) (to1
, from1
));
1086 #ifdef PUSH_ROUNDING
1087 emit_single_push_insn (mode
, from1
, NULL
);
1093 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1094 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
1095 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1096 emit_insn (gen_add2_insn (data
->from_addr
, GEN_INT (size
)));
1098 if (! data
->reverse
)
1099 data
->offset
+= size
;
1105 /* Emit code to move a block Y to a block X. This may be done with
1106 string-move instructions, with multiple scalar move instructions,
1107 or with a library call.
1109 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1110 SIZE is an rtx that says how long they are.
1111 ALIGN is the maximum alignment we can assume they have.
1112 METHOD describes what kind of copy this is, and what mechanisms may be used.
1114 Return the address of the new block, if memcpy is called and returns it,
1118 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1119 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
1126 if (CONST_INT_P (size
)
1127 && INTVAL (size
) == 0)
1132 case BLOCK_OP_NORMAL
:
1133 case BLOCK_OP_TAILCALL
:
1134 may_use_call
= true;
1137 case BLOCK_OP_CALL_PARM
:
1138 may_use_call
= block_move_libcall_safe_for_call_parm ();
1140 /* Make inhibit_defer_pop nonzero around the library call
1141 to force it to pop the arguments right away. */
1145 case BLOCK_OP_NO_LIBCALL
:
1146 may_use_call
= false;
1153 gcc_assert (MEM_P (x
) && MEM_P (y
));
1154 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1155 gcc_assert (align
>= BITS_PER_UNIT
);
1157 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1158 block copy is more efficient for other large modes, e.g. DCmode. */
1159 x
= adjust_address (x
, BLKmode
, 0);
1160 y
= adjust_address (y
, BLKmode
, 0);
1162 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1163 can be incorrect is coming from __builtin_memcpy. */
1164 if (CONST_INT_P (size
))
1166 x
= shallow_copy_rtx (x
);
1167 y
= shallow_copy_rtx (y
);
1168 set_mem_size (x
, INTVAL (size
));
1169 set_mem_size (y
, INTVAL (size
));
1172 if (CONST_INT_P (size
) && MOVE_BY_PIECES_P (INTVAL (size
), align
))
1173 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1174 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1175 expected_align
, expected_size
))
1177 else if (may_use_call
1178 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1179 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1181 /* Since x and y are passed to a libcall, mark the corresponding
1182 tree EXPR as addressable. */
1183 tree y_expr
= MEM_EXPR (y
);
1184 tree x_expr
= MEM_EXPR (x
);
1186 mark_addressable (y_expr
);
1188 mark_addressable (x_expr
);
1189 retval
= emit_block_move_via_libcall (x
, y
, size
,
1190 method
== BLOCK_OP_TAILCALL
);
1194 emit_block_move_via_loop (x
, y
, size
, align
);
1196 if (method
== BLOCK_OP_CALL_PARM
)
1203 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1205 return emit_block_move_hints (x
, y
, size
, method
, 0, -1);
1208 /* A subroutine of emit_block_move. Returns true if calling the
1209 block move libcall will not clobber any parameters which may have
1210 already been placed on the stack. */
1213 block_move_libcall_safe_for_call_parm (void)
1215 #if defined (REG_PARM_STACK_SPACE)
1219 /* If arguments are pushed on the stack, then they're safe. */
1223 /* If registers go on the stack anyway, any argument is sure to clobber
1224 an outgoing argument. */
1225 #if defined (REG_PARM_STACK_SPACE)
1226 fn
= emit_block_move_libcall_fn (false);
1227 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1228 depend on its argument. */
1230 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1231 && REG_PARM_STACK_SPACE (fn
) != 0)
1235 /* If any argument goes in memory, then it might clobber an outgoing
1238 CUMULATIVE_ARGS args_so_far_v
;
1239 cumulative_args_t args_so_far
;
1242 fn
= emit_block_move_libcall_fn (false);
1243 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1244 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1246 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1247 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1249 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1250 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1252 if (!tmp
|| !REG_P (tmp
))
1254 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1256 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1263 /* A subroutine of emit_block_move. Expand a movmem pattern;
1264 return true if successful. */
1267 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1268 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
1270 int save_volatile_ok
= volatile_ok
;
1271 enum machine_mode mode
;
1273 if (expected_align
< align
)
1274 expected_align
= align
;
1276 /* Since this is a move insn, we don't care about volatility. */
1279 /* Try the most limited insn first, because there's no point
1280 including more than one in the machine description unless
1281 the more limited one has some advantage. */
1283 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1284 mode
= GET_MODE_WIDER_MODE (mode
))
1286 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1288 if (code
!= CODE_FOR_nothing
1289 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1290 here because if SIZE is less than the mode mask, as it is
1291 returned by the macro, it will definitely be less than the
1292 actual mode mask. */
1293 && ((CONST_INT_P (size
)
1294 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1295 <= (GET_MODE_MASK (mode
) >> 1)))
1296 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
1298 struct expand_operand ops
[6];
1301 /* ??? When called via emit_block_move_for_call, it'd be
1302 nice if there were some way to inform the backend, so
1303 that it doesn't fail the expansion because it thinks
1304 emitting the libcall would be more efficient. */
1305 nops
= insn_data
[(int) code
].n_generator_args
;
1306 gcc_assert (nops
== 4 || nops
== 6);
1308 create_fixed_operand (&ops
[0], x
);
1309 create_fixed_operand (&ops
[1], y
);
1310 /* The check above guarantees that this size conversion is valid. */
1311 create_convert_operand_to (&ops
[2], size
, mode
, true);
1312 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1315 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1316 create_integer_operand (&ops
[5], expected_size
);
1318 if (maybe_expand_insn (code
, nops
, ops
))
1320 volatile_ok
= save_volatile_ok
;
1326 volatile_ok
= save_volatile_ok
;
1330 /* A subroutine of emit_block_move. Expand a call to memcpy.
1331 Return the return value from memcpy, 0 otherwise. */
1334 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1336 rtx dst_addr
, src_addr
;
1337 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1338 enum machine_mode size_mode
;
1341 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1342 pseudos. We can then place those new pseudos into a VAR_DECL and
1345 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1346 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1348 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1349 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1351 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1352 src_tree
= make_tree (ptr_type_node
, src_addr
);
1354 size_mode
= TYPE_MODE (sizetype
);
1356 size
= convert_to_mode (size_mode
, size
, 1);
1357 size
= copy_to_mode_reg (size_mode
, size
);
1359 /* It is incorrect to use the libcall calling conventions to call
1360 memcpy in this context. This could be a user call to memcpy and
1361 the user may wish to examine the return value from memcpy. For
1362 targets where libcalls and normal calls have different conventions
1363 for returning pointers, we could end up generating incorrect code. */
1365 size_tree
= make_tree (sizetype
, size
);
1367 fn
= emit_block_move_libcall_fn (true);
1368 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1369 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1371 retval
= expand_normal (call_expr
);
1376 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1377 for the function we use for block copies. */
1379 static GTY(()) tree block_move_fn
;
1382 init_block_move_fn (const char *asmspec
)
1388 fn
= get_identifier ("memcpy");
1389 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1390 const_ptr_type_node
, sizetype
,
1393 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1394 DECL_EXTERNAL (fn
) = 1;
1395 TREE_PUBLIC (fn
) = 1;
1396 DECL_ARTIFICIAL (fn
) = 1;
1397 TREE_NOTHROW (fn
) = 1;
1398 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1399 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1405 set_user_assembler_name (block_move_fn
, asmspec
);
1409 emit_block_move_libcall_fn (int for_call
)
1411 static bool emitted_extern
;
1414 init_block_move_fn (NULL
);
1416 if (for_call
&& !emitted_extern
)
1418 emitted_extern
= true;
1419 make_decl_rtl (block_move_fn
);
1422 return block_move_fn
;
1425 /* A subroutine of emit_block_move. Copy the data via an explicit
1426 loop. This is used only when libcalls are forbidden. */
1427 /* ??? It'd be nice to copy in hunks larger than QImode. */
1430 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1431 unsigned int align ATTRIBUTE_UNUSED
)
1433 rtx cmp_label
, top_label
, iter
, x_addr
, y_addr
, tmp
;
1434 enum machine_mode x_addr_mode
1435 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (x
));
1436 enum machine_mode y_addr_mode
1437 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (y
));
1438 enum machine_mode iter_mode
;
1440 iter_mode
= GET_MODE (size
);
1441 if (iter_mode
== VOIDmode
)
1442 iter_mode
= word_mode
;
1444 top_label
= gen_label_rtx ();
1445 cmp_label
= gen_label_rtx ();
1446 iter
= gen_reg_rtx (iter_mode
);
1448 emit_move_insn (iter
, const0_rtx
);
1450 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1451 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1452 do_pending_stack_adjust ();
1454 emit_jump (cmp_label
);
1455 emit_label (top_label
);
1457 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1458 x_addr
= gen_rtx_PLUS (x_addr_mode
, x_addr
, tmp
);
1460 if (x_addr_mode
!= y_addr_mode
)
1461 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1462 y_addr
= gen_rtx_PLUS (y_addr_mode
, y_addr
, tmp
);
1464 x
= change_address (x
, QImode
, x_addr
);
1465 y
= change_address (y
, QImode
, y_addr
);
1467 emit_move_insn (x
, y
);
1469 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1470 true, OPTAB_LIB_WIDEN
);
1472 emit_move_insn (iter
, tmp
);
1474 emit_label (cmp_label
);
1476 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1480 /* Copy all or part of a value X into registers starting at REGNO.
1481 The number of registers to be filled is NREGS. */
1484 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1487 #ifdef HAVE_load_multiple
1495 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1496 x
= validize_mem (force_const_mem (mode
, x
));
1498 /* See if the machine can do this with a load multiple insn. */
1499 #ifdef HAVE_load_multiple
1500 if (HAVE_load_multiple
)
1502 last
= get_last_insn ();
1503 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1511 delete_insns_since (last
);
1515 for (i
= 0; i
< nregs
; i
++)
1516 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1517 operand_subword_force (x
, i
, mode
));
1520 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1521 The number of registers to be filled is NREGS. */
1524 move_block_from_reg (int regno
, rtx x
, int nregs
)
1531 /* See if the machine can do this with a store multiple insn. */
1532 #ifdef HAVE_store_multiple
1533 if (HAVE_store_multiple
)
1535 rtx last
= get_last_insn ();
1536 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1544 delete_insns_since (last
);
1548 for (i
= 0; i
< nregs
; i
++)
1550 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1554 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1558 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1559 ORIG, where ORIG is a non-consecutive group of registers represented by
1560 a PARALLEL. The clone is identical to the original except in that the
1561 original set of registers is replaced by a new set of pseudo registers.
1562 The new set has the same modes as the original set. */
1565 gen_group_rtx (rtx orig
)
1570 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1572 length
= XVECLEN (orig
, 0);
1573 tmps
= XALLOCAVEC (rtx
, length
);
1575 /* Skip a NULL entry in first slot. */
1576 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1581 for (; i
< length
; i
++)
1583 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1584 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1586 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1589 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1592 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1593 except that values are placed in TMPS[i], and must later be moved
1594 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1597 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1601 enum machine_mode m
= GET_MODE (orig_src
);
1603 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1606 && !SCALAR_INT_MODE_P (m
)
1607 && !MEM_P (orig_src
)
1608 && GET_CODE (orig_src
) != CONCAT
)
1610 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1611 if (imode
== BLKmode
)
1612 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
, 0);
1614 src
= gen_reg_rtx (imode
);
1615 if (imode
!= BLKmode
)
1616 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1617 emit_move_insn (src
, orig_src
);
1618 /* ...and back again. */
1619 if (imode
!= BLKmode
)
1620 src
= gen_lowpart (imode
, src
);
1621 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1625 /* Check for a NULL entry, used to indicate that the parameter goes
1626 both on the stack and in registers. */
1627 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1632 /* Process the pieces. */
1633 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1635 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1636 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1637 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1640 /* Handle trailing fragments that run over the size of the struct. */
1641 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1643 /* Arrange to shift the fragment to where it belongs.
1644 extract_bit_field loads to the lsb of the reg. */
1646 #ifdef BLOCK_REG_PADDING
1647 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1648 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1653 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1654 bytelen
= ssize
- bytepos
;
1655 gcc_assert (bytelen
> 0);
1658 /* If we won't be loading directly from memory, protect the real source
1659 from strange tricks we might play; but make sure that the source can
1660 be loaded directly into the destination. */
1662 if (!MEM_P (orig_src
)
1663 && (!CONSTANT_P (orig_src
)
1664 || (GET_MODE (orig_src
) != mode
1665 && GET_MODE (orig_src
) != VOIDmode
)))
1667 if (GET_MODE (orig_src
) == VOIDmode
)
1668 src
= gen_reg_rtx (mode
);
1670 src
= gen_reg_rtx (GET_MODE (orig_src
));
1672 emit_move_insn (src
, orig_src
);
1675 /* Optimize the access just a bit. */
1677 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1678 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1679 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1680 && bytelen
== GET_MODE_SIZE (mode
))
1682 tmps
[i
] = gen_reg_rtx (mode
);
1683 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1685 else if (COMPLEX_MODE_P (mode
)
1686 && GET_MODE (src
) == mode
1687 && bytelen
== GET_MODE_SIZE (mode
))
1688 /* Let emit_move_complex do the bulk of the work. */
1690 else if (GET_CODE (src
) == CONCAT
)
1692 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1693 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1695 if ((bytepos
== 0 && bytelen
== slen0
)
1696 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1698 /* The following assumes that the concatenated objects all
1699 have the same size. In this case, a simple calculation
1700 can be used to determine the object and the bit field
1702 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1703 if (! CONSTANT_P (tmps
[i
])
1704 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1705 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1706 (bytepos
% slen0
) * BITS_PER_UNIT
,
1707 1, false, NULL_RTX
, mode
, mode
);
1713 gcc_assert (!bytepos
);
1714 mem
= assign_stack_temp (GET_MODE (src
), slen
, 0);
1715 emit_move_insn (mem
, src
);
1716 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1717 0, 1, false, NULL_RTX
, mode
, mode
);
1720 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1721 SIMD register, which is currently broken. While we get GCC
1722 to emit proper RTL for these cases, let's dump to memory. */
1723 else if (VECTOR_MODE_P (GET_MODE (dst
))
1726 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1729 mem
= assign_stack_temp (GET_MODE (src
), slen
, 0);
1730 emit_move_insn (mem
, src
);
1731 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1733 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1734 && XVECLEN (dst
, 0) > 1)
1735 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE(dst
), bytepos
);
1736 else if (CONSTANT_P (src
))
1738 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1746 gcc_assert (2 * len
== ssize
);
1747 split_double (src
, &first
, &second
);
1754 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1757 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1758 bytepos
* BITS_PER_UNIT
, 1, false, NULL_RTX
,
1762 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1767 /* Emit code to move a block SRC of type TYPE to a block DST,
1768 where DST is non-consecutive registers represented by a PARALLEL.
1769 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1773 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1778 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1779 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1781 /* Copy the extracted pieces into the proper (probable) hard regs. */
1782 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1784 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1787 emit_move_insn (d
, tmps
[i
]);
1791 /* Similar, but load SRC into new pseudos in a format that looks like
1792 PARALLEL. This can later be fed to emit_group_move to get things
1793 in the right place. */
1796 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1801 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1802 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1804 /* Convert the vector to look just like the original PARALLEL, except
1805 with the computed values. */
1806 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1808 rtx e
= XVECEXP (parallel
, 0, i
);
1809 rtx d
= XEXP (e
, 0);
1813 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1814 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1816 RTVEC_ELT (vec
, i
) = e
;
1819 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1822 /* Emit code to move a block SRC to block DST, where SRC and DST are
1823 non-consecutive groups of registers, each represented by a PARALLEL. */
1826 emit_group_move (rtx dst
, rtx src
)
1830 gcc_assert (GET_CODE (src
) == PARALLEL
1831 && GET_CODE (dst
) == PARALLEL
1832 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1834 /* Skip first entry if NULL. */
1835 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1836 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1837 XEXP (XVECEXP (src
, 0, i
), 0));
1840 /* Move a group of registers represented by a PARALLEL into pseudos. */
1843 emit_group_move_into_temps (rtx src
)
1845 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1848 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1850 rtx e
= XVECEXP (src
, 0, i
);
1851 rtx d
= XEXP (e
, 0);
1854 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1855 RTVEC_ELT (vec
, i
) = e
;
1858 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1861 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1862 where SRC is non-consecutive registers represented by a PARALLEL.
1863 SSIZE represents the total size of block ORIG_DST, or -1 if not
1867 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1870 int start
, finish
, i
;
1871 enum machine_mode m
= GET_MODE (orig_dst
);
1873 gcc_assert (GET_CODE (src
) == PARALLEL
);
1875 if (!SCALAR_INT_MODE_P (m
)
1876 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1878 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1879 if (imode
== BLKmode
)
1880 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
, 0);
1882 dst
= gen_reg_rtx (imode
);
1883 emit_group_store (dst
, src
, type
, ssize
);
1884 if (imode
!= BLKmode
)
1885 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1886 emit_move_insn (orig_dst
, dst
);
1890 /* Check for a NULL entry, used to indicate that the parameter goes
1891 both on the stack and in registers. */
1892 if (XEXP (XVECEXP (src
, 0, 0), 0))
1896 finish
= XVECLEN (src
, 0);
1898 tmps
= XALLOCAVEC (rtx
, finish
);
1900 /* Copy the (probable) hard regs into pseudos. */
1901 for (i
= start
; i
< finish
; i
++)
1903 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1904 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1906 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1907 emit_move_insn (tmps
[i
], reg
);
1913 /* If we won't be storing directly into memory, protect the real destination
1914 from strange tricks we might play. */
1916 if (GET_CODE (dst
) == PARALLEL
)
1920 /* We can get a PARALLEL dst if there is a conditional expression in
1921 a return statement. In that case, the dst and src are the same,
1922 so no action is necessary. */
1923 if (rtx_equal_p (dst
, src
))
1926 /* It is unclear if we can ever reach here, but we may as well handle
1927 it. Allocate a temporary, and split this into a store/load to/from
1930 temp
= assign_stack_temp (GET_MODE (dst
), ssize
, 0);
1931 emit_group_store (temp
, src
, type
, ssize
);
1932 emit_group_load (dst
, temp
, type
, ssize
);
1935 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1937 enum machine_mode outer
= GET_MODE (dst
);
1938 enum machine_mode inner
;
1939 HOST_WIDE_INT bytepos
;
1943 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1944 dst
= gen_reg_rtx (outer
);
1946 /* Make life a bit easier for combine. */
1947 /* If the first element of the vector is the low part
1948 of the destination mode, use a paradoxical subreg to
1949 initialize the destination. */
1952 inner
= GET_MODE (tmps
[start
]);
1953 bytepos
= subreg_lowpart_offset (inner
, outer
);
1954 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1956 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1960 emit_move_insn (dst
, temp
);
1967 /* If the first element wasn't the low part, try the last. */
1969 && start
< finish
- 1)
1971 inner
= GET_MODE (tmps
[finish
- 1]);
1972 bytepos
= subreg_lowpart_offset (inner
, outer
);
1973 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1975 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1979 emit_move_insn (dst
, temp
);
1986 /* Otherwise, simply initialize the result to zero. */
1988 emit_move_insn (dst
, CONST0_RTX (outer
));
1991 /* Process the pieces. */
1992 for (i
= start
; i
< finish
; i
++)
1994 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
1995 enum machine_mode mode
= GET_MODE (tmps
[i
]);
1996 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1997 unsigned int adj_bytelen
= bytelen
;
2000 /* Handle trailing fragments that run over the size of the struct. */
2001 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2002 adj_bytelen
= ssize
- bytepos
;
2004 if (GET_CODE (dst
) == CONCAT
)
2006 if (bytepos
+ adj_bytelen
2007 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2008 dest
= XEXP (dst
, 0);
2009 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2011 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2012 dest
= XEXP (dst
, 1);
2016 enum machine_mode dest_mode
= GET_MODE (dest
);
2017 enum machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2019 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2021 if (GET_MODE_ALIGNMENT (dest_mode
)
2022 >= GET_MODE_ALIGNMENT (tmp_mode
))
2024 dest
= assign_stack_temp (dest_mode
,
2025 GET_MODE_SIZE (dest_mode
),
2027 emit_move_insn (adjust_address (dest
,
2035 dest
= assign_stack_temp (tmp_mode
,
2036 GET_MODE_SIZE (tmp_mode
),
2038 emit_move_insn (dest
, tmps
[i
]);
2039 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2045 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2047 /* store_bit_field always takes its value from the lsb.
2048 Move the fragment to the lsb if it's not already there. */
2050 #ifdef BLOCK_REG_PADDING
2051 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2052 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2058 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2059 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2062 bytelen
= adj_bytelen
;
2065 /* Optimize the access just a bit. */
2067 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2068 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2069 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2070 && bytelen
== GET_MODE_SIZE (mode
))
2071 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2073 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2074 0, 0, mode
, tmps
[i
]);
2077 /* Copy from the pseudo into the (probable) hard reg. */
2078 if (orig_dst
!= dst
)
2079 emit_move_insn (orig_dst
, dst
);
2082 /* Generate code to copy a BLKmode object of TYPE out of a
2083 set of registers starting with SRCREG into TGTBLK. If TGTBLK
2084 is null, a stack temporary is created. TGTBLK is returned.
2086 The purpose of this routine is to handle functions that return
2087 BLKmode structures in registers. Some machines (the PA for example)
2088 want to return all small structures in registers regardless of the
2089 structure's alignment. */
2092 copy_blkmode_from_reg (rtx tgtblk
, rtx srcreg
, tree type
)
2094 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2095 rtx src
= NULL
, dst
= NULL
;
2096 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2097 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2098 enum machine_mode copy_mode
;
2102 tgtblk
= assign_temp (build_qualified_type (type
,
2104 | TYPE_QUAL_CONST
)),
2106 preserve_temp_slots (tgtblk
);
2109 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2110 into a new pseudo which is a full word. */
2112 if (GET_MODE (srcreg
) != BLKmode
2113 && GET_MODE_SIZE (GET_MODE (srcreg
)) < UNITS_PER_WORD
)
2114 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2116 /* If the structure doesn't take up a whole number of words, see whether
2117 SRCREG is padded on the left or on the right. If it's on the left,
2118 set PADDING_CORRECTION to the number of bits to skip.
2120 In most ABIs, the structure will be returned at the least end of
2121 the register, which translates to right padding on little-endian
2122 targets and left padding on big-endian targets. The opposite
2123 holds if the structure is returned at the most significant
2124 end of the register. */
2125 if (bytes
% UNITS_PER_WORD
!= 0
2126 && (targetm
.calls
.return_in_msb (type
)
2128 : BYTES_BIG_ENDIAN
))
2130 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2132 /* Copy the structure BITSIZE bits at a time. If the target lives in
2133 memory, take care of not reading/writing past its end by selecting
2134 a copy mode suited to BITSIZE. This should always be possible given
2137 We could probably emit more efficient code for machines which do not use
2138 strict alignment, but it doesn't seem worth the effort at the current
2141 copy_mode
= word_mode
;
2144 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2145 if (mem_mode
!= BLKmode
)
2146 copy_mode
= mem_mode
;
2149 for (bitpos
= 0, xbitpos
= padding_correction
;
2150 bitpos
< bytes
* BITS_PER_UNIT
;
2151 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2153 /* We need a new source operand each time xbitpos is on a
2154 word boundary and when xbitpos == padding_correction
2155 (the first time through). */
2156 if (xbitpos
% BITS_PER_WORD
== 0
2157 || xbitpos
== padding_correction
)
2158 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
,
2161 /* We need a new destination operand each time bitpos is on
2163 if (bitpos
% BITS_PER_WORD
== 0)
2164 dst
= operand_subword (tgtblk
, bitpos
/ BITS_PER_WORD
, 1, BLKmode
);
2166 /* Use xbitpos for the source extraction (right justified) and
2167 bitpos for the destination store (left justified). */
2168 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2169 extract_bit_field (src
, bitsize
,
2170 xbitpos
% BITS_PER_WORD
, 1, false,
2171 NULL_RTX
, copy_mode
, copy_mode
));
2177 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2178 register if it contains any data, otherwise return null.
2180 This is used on targets that return BLKmode values in registers. */
2183 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2186 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2187 unsigned int bitsize
;
2188 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2189 enum machine_mode dst_mode
;
2191 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2193 x
= expand_normal (src
);
2195 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2199 /* If the structure doesn't take up a whole number of words, see
2200 whether the register value should be padded on the left or on
2201 the right. Set PADDING_CORRECTION to the number of padding
2202 bits needed on the left side.
2204 In most ABIs, the structure will be returned at the least end of
2205 the register, which translates to right padding on little-endian
2206 targets and left padding on big-endian targets. The opposite
2207 holds if the structure is returned at the most significant
2208 end of the register. */
2209 if (bytes
% UNITS_PER_WORD
!= 0
2210 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2212 : BYTES_BIG_ENDIAN
))
2213 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2216 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2217 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2218 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2220 /* Copy the structure BITSIZE bits at a time. */
2221 for (bitpos
= 0, xbitpos
= padding_correction
;
2222 bitpos
< bytes
* BITS_PER_UNIT
;
2223 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2225 /* We need a new destination pseudo each time xbitpos is
2226 on a word boundary and when xbitpos == padding_correction
2227 (the first time through). */
2228 if (xbitpos
% BITS_PER_WORD
== 0
2229 || xbitpos
== padding_correction
)
2231 /* Generate an appropriate register. */
2232 dst_word
= gen_reg_rtx (word_mode
);
2233 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2235 /* Clear the destination before we move anything into it. */
2236 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2239 /* We need a new source operand each time bitpos is on a word
2241 if (bitpos
% BITS_PER_WORD
== 0)
2242 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2244 /* Use bitpos for the source extraction (left justified) and
2245 xbitpos for the destination store (right justified). */
2246 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2248 extract_bit_field (src_word
, bitsize
,
2249 bitpos
% BITS_PER_WORD
, 1, false,
2250 NULL_RTX
, word_mode
, word_mode
));
2253 if (mode
== BLKmode
)
2255 /* Find the smallest integer mode large enough to hold the
2256 entire structure. */
2257 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2259 mode
= GET_MODE_WIDER_MODE (mode
))
2260 /* Have we found a large enough mode? */
2261 if (GET_MODE_SIZE (mode
) >= bytes
)
2264 /* A suitable mode should have been found. */
2265 gcc_assert (mode
!= VOIDmode
);
2268 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2269 dst_mode
= word_mode
;
2272 dst
= gen_reg_rtx (dst_mode
);
2274 for (i
= 0; i
< n_regs
; i
++)
2275 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2277 if (mode
!= dst_mode
)
2278 dst
= gen_lowpart (mode
, dst
);
2283 /* Add a USE expression for REG to the (possibly empty) list pointed
2284 to by CALL_FUSAGE. REG must denote a hard register. */
2287 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2289 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2292 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2295 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2296 starting at REGNO. All of these registers must be hard registers. */
2299 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2303 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2305 for (i
= 0; i
< nregs
; i
++)
2306 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2309 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2310 PARALLEL REGS. This is for calls that pass values in multiple
2311 non-contiguous locations. The Irix 6 ABI has examples of this. */
2314 use_group_regs (rtx
*call_fusage
, rtx regs
)
2318 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2320 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2322 /* A NULL entry means the parameter goes both on the stack and in
2323 registers. This can also be a MEM for targets that pass values
2324 partially on the stack and partially in registers. */
2325 if (reg
!= 0 && REG_P (reg
))
2326 use_reg (call_fusage
, reg
);
2330 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2331 assigment and the code of the expresion on the RHS is CODE. Return
2335 get_def_for_expr (tree name
, enum tree_code code
)
2339 if (TREE_CODE (name
) != SSA_NAME
)
2342 def_stmt
= get_gimple_for_ssa_name (name
);
2344 || gimple_assign_rhs_code (def_stmt
) != code
)
2350 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2351 assigment and the class of the expresion on the RHS is CLASS. Return
2355 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2359 if (TREE_CODE (name
) != SSA_NAME
)
2362 def_stmt
= get_gimple_for_ssa_name (name
);
2364 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2371 /* Determine whether the LEN bytes generated by CONSTFUN can be
2372 stored to memory using several move instructions. CONSTFUNDATA is
2373 a pointer which will be passed as argument in every CONSTFUN call.
2374 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2375 a memset operation and false if it's a copy of a constant string.
2376 Return nonzero if a call to store_by_pieces should succeed. */
2379 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2380 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2381 void *constfundata
, unsigned int align
, bool memsetp
)
2383 unsigned HOST_WIDE_INT l
;
2384 unsigned int max_size
;
2385 HOST_WIDE_INT offset
= 0;
2386 enum machine_mode mode
;
2387 enum insn_code icode
;
2389 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2390 rtx cst ATTRIBUTE_UNUSED
;
2396 ? SET_BY_PIECES_P (len
, align
)
2397 : STORE_BY_PIECES_P (len
, align
)))
2400 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2402 /* We would first store what we can in the largest integer mode, then go to
2403 successively smaller modes. */
2406 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2410 max_size
= STORE_MAX_PIECES
+ 1;
2411 while (max_size
> 1)
2413 mode
= widest_int_mode_for_size (max_size
);
2415 if (mode
== VOIDmode
)
2418 icode
= optab_handler (mov_optab
, mode
);
2419 if (icode
!= CODE_FOR_nothing
2420 && align
>= GET_MODE_ALIGNMENT (mode
))
2422 unsigned int size
= GET_MODE_SIZE (mode
);
2429 cst
= (*constfun
) (constfundata
, offset
, mode
);
2430 if (!targetm
.legitimate_constant_p (mode
, cst
))
2440 max_size
= GET_MODE_SIZE (mode
);
2443 /* The code above should have handled everything. */
2450 /* Generate several move instructions to store LEN bytes generated by
2451 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2452 pointer which will be passed as argument in every CONSTFUN call.
2453 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2454 a memset operation and false if it's a copy of a constant string.
2455 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2456 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2460 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2461 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2462 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2464 enum machine_mode to_addr_mode
2465 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (to
));
2466 struct store_by_pieces_d data
;
2470 gcc_assert (endp
!= 2);
2475 ? SET_BY_PIECES_P (len
, align
)
2476 : STORE_BY_PIECES_P (len
, align
));
2477 data
.constfun
= constfun
;
2478 data
.constfundata
= constfundata
;
2481 store_by_pieces_1 (&data
, align
);
2486 gcc_assert (!data
.reverse
);
2491 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2492 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2494 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2495 plus_constant (data
.to_addr
,
2498 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2505 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2513 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2514 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2517 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2519 struct store_by_pieces_d data
;
2524 data
.constfun
= clear_by_pieces_1
;
2525 data
.constfundata
= NULL
;
2528 store_by_pieces_1 (&data
, align
);
2531 /* Callback routine for clear_by_pieces.
2532 Return const0_rtx unconditionally. */
2535 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2536 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2537 enum machine_mode mode ATTRIBUTE_UNUSED
)
2542 /* Subroutine of clear_by_pieces and store_by_pieces.
2543 Generate several move instructions to store LEN bytes of block TO. (A MEM
2544 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2547 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2548 unsigned int align ATTRIBUTE_UNUSED
)
2550 enum machine_mode to_addr_mode
2551 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (data
->to
));
2552 rtx to_addr
= XEXP (data
->to
, 0);
2553 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2554 enum insn_code icode
;
2557 data
->to_addr
= to_addr
;
2559 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2560 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2562 data
->explicit_inc_to
= 0;
2564 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2566 data
->offset
= data
->len
;
2568 /* If storing requires more than two move insns,
2569 copy addresses to registers (to make displacements shorter)
2570 and use post-increment if available. */
2571 if (!data
->autinc_to
2572 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2574 /* Determine the main mode we'll be using.
2575 MODE might not be used depending on the definitions of the
2576 USE_* macros below. */
2577 enum machine_mode mode ATTRIBUTE_UNUSED
2578 = widest_int_mode_for_size (max_size
);
2580 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2582 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2583 plus_constant (to_addr
, data
->len
));
2584 data
->autinc_to
= 1;
2585 data
->explicit_inc_to
= -1;
2588 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2589 && ! data
->autinc_to
)
2591 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2592 data
->autinc_to
= 1;
2593 data
->explicit_inc_to
= 1;
2596 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2597 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2600 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2602 /* First store what we can in the largest integer mode, then go to
2603 successively smaller modes. */
2605 while (max_size
> 1)
2607 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2609 if (mode
== VOIDmode
)
2612 icode
= optab_handler (mov_optab
, mode
);
2613 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2614 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2616 max_size
= GET_MODE_SIZE (mode
);
2619 /* The code above should have handled everything. */
2620 gcc_assert (!data
->len
);
2623 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2624 with move instructions for mode MODE. GENFUN is the gen_... function
2625 to make a move insn for that mode. DATA has all the other info. */
2628 store_by_pieces_2 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
2629 struct store_by_pieces_d
*data
)
2631 unsigned int size
= GET_MODE_SIZE (mode
);
2634 while (data
->len
>= size
)
2637 data
->offset
-= size
;
2639 if (data
->autinc_to
)
2640 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2643 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2645 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2646 emit_insn (gen_add2_insn (data
->to_addr
,
2647 GEN_INT (-(HOST_WIDE_INT
) size
)));
2649 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2650 emit_insn ((*genfun
) (to1
, cst
));
2652 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2653 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
2655 if (! data
->reverse
)
2656 data
->offset
+= size
;
2662 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2663 its length in bytes. */
2666 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2667 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2669 enum machine_mode mode
= GET_MODE (object
);
2672 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2674 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2675 just move a zero. Otherwise, do this a piece at a time. */
2677 && CONST_INT_P (size
)
2678 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2680 rtx zero
= CONST0_RTX (mode
);
2683 emit_move_insn (object
, zero
);
2687 if (COMPLEX_MODE_P (mode
))
2689 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2692 write_complex_part (object
, zero
, 0);
2693 write_complex_part (object
, zero
, 1);
2699 if (size
== const0_rtx
)
2702 align
= MEM_ALIGN (object
);
2704 if (CONST_INT_P (size
)
2705 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2706 clear_by_pieces (object
, INTVAL (size
), align
);
2707 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2708 expected_align
, expected_size
))
2710 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2711 return set_storage_via_libcall (object
, size
, const0_rtx
,
2712 method
== BLOCK_OP_TAILCALL
);
2720 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2722 return clear_storage_hints (object
, size
, method
, 0, -1);
2726 /* A subroutine of clear_storage. Expand a call to memset.
2727 Return the return value of memset, 0 otherwise. */
2730 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2732 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2733 enum machine_mode size_mode
;
2736 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2737 place those into new pseudos into a VAR_DECL and use them later. */
2739 object
= copy_addr_to_reg (XEXP (object
, 0));
2741 size_mode
= TYPE_MODE (sizetype
);
2742 size
= convert_to_mode (size_mode
, size
, 1);
2743 size
= copy_to_mode_reg (size_mode
, size
);
2745 /* It is incorrect to use the libcall calling conventions to call
2746 memset in this context. This could be a user call to memset and
2747 the user may wish to examine the return value from memset. For
2748 targets where libcalls and normal calls have different conventions
2749 for returning pointers, we could end up generating incorrect code. */
2751 object_tree
= make_tree (ptr_type_node
, object
);
2752 if (!CONST_INT_P (val
))
2753 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2754 size_tree
= make_tree (sizetype
, size
);
2755 val_tree
= make_tree (integer_type_node
, val
);
2757 fn
= clear_storage_libcall_fn (true);
2758 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2759 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2761 retval
= expand_normal (call_expr
);
2766 /* A subroutine of set_storage_via_libcall. Create the tree node
2767 for the function we use for block clears. */
2769 tree block_clear_fn
;
2772 init_block_clear_fn (const char *asmspec
)
2774 if (!block_clear_fn
)
2778 fn
= get_identifier ("memset");
2779 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2780 integer_type_node
, sizetype
,
2783 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2784 DECL_EXTERNAL (fn
) = 1;
2785 TREE_PUBLIC (fn
) = 1;
2786 DECL_ARTIFICIAL (fn
) = 1;
2787 TREE_NOTHROW (fn
) = 1;
2788 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2789 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2791 block_clear_fn
= fn
;
2795 set_user_assembler_name (block_clear_fn
, asmspec
);
2799 clear_storage_libcall_fn (int for_call
)
2801 static bool emitted_extern
;
2803 if (!block_clear_fn
)
2804 init_block_clear_fn (NULL
);
2806 if (for_call
&& !emitted_extern
)
2808 emitted_extern
= true;
2809 make_decl_rtl (block_clear_fn
);
2812 return block_clear_fn
;
2815 /* Expand a setmem pattern; return true if successful. */
2818 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2819 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2821 /* Try the most limited insn first, because there's no point
2822 including more than one in the machine description unless
2823 the more limited one has some advantage. */
2825 enum machine_mode mode
;
2827 if (expected_align
< align
)
2828 expected_align
= align
;
2830 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2831 mode
= GET_MODE_WIDER_MODE (mode
))
2833 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2835 if (code
!= CODE_FOR_nothing
2836 /* We don't need MODE to be narrower than
2837 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2838 the mode mask, as it is returned by the macro, it will
2839 definitely be less than the actual mode mask. */
2840 && ((CONST_INT_P (size
)
2841 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2842 <= (GET_MODE_MASK (mode
) >> 1)))
2843 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
2845 struct expand_operand ops
[6];
2848 nops
= insn_data
[(int) code
].n_generator_args
;
2849 gcc_assert (nops
== 4 || nops
== 6);
2851 create_fixed_operand (&ops
[0], object
);
2852 /* The check above guarantees that this size conversion is valid. */
2853 create_convert_operand_to (&ops
[1], size
, mode
, true);
2854 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2855 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2858 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2859 create_integer_operand (&ops
[5], expected_size
);
2861 if (maybe_expand_insn (code
, nops
, ops
))
2870 /* Write to one of the components of the complex value CPLX. Write VAL to
2871 the real part if IMAG_P is false, and the imaginary part if its true. */
2874 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2876 enum machine_mode cmode
;
2877 enum machine_mode imode
;
2880 if (GET_CODE (cplx
) == CONCAT
)
2882 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2886 cmode
= GET_MODE (cplx
);
2887 imode
= GET_MODE_INNER (cmode
);
2888 ibitsize
= GET_MODE_BITSIZE (imode
);
2890 /* For MEMs simplify_gen_subreg may generate an invalid new address
2891 because, e.g., the original address is considered mode-dependent
2892 by the target, which restricts simplify_subreg from invoking
2893 adjust_address_nv. Instead of preparing fallback support for an
2894 invalid address, we call adjust_address_nv directly. */
2897 emit_move_insn (adjust_address_nv (cplx
, imode
,
2898 imag_p
? GET_MODE_SIZE (imode
) : 0),
2903 /* If the sub-object is at least word sized, then we know that subregging
2904 will work. This special case is important, since store_bit_field
2905 wants to operate on integer modes, and there's rarely an OImode to
2906 correspond to TCmode. */
2907 if (ibitsize
>= BITS_PER_WORD
2908 /* For hard regs we have exact predicates. Assume we can split
2909 the original object if it spans an even number of hard regs.
2910 This special case is important for SCmode on 64-bit platforms
2911 where the natural size of floating-point regs is 32-bit. */
2913 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2914 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2916 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
2917 imag_p
? GET_MODE_SIZE (imode
) : 0);
2920 emit_move_insn (part
, val
);
2924 /* simplify_gen_subreg may fail for sub-word MEMs. */
2925 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2928 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
2931 /* Extract one of the components of the complex value CPLX. Extract the
2932 real part if IMAG_P is false, and the imaginary part if it's true. */
2935 read_complex_part (rtx cplx
, bool imag_p
)
2937 enum machine_mode cmode
, imode
;
2940 if (GET_CODE (cplx
) == CONCAT
)
2941 return XEXP (cplx
, imag_p
);
2943 cmode
= GET_MODE (cplx
);
2944 imode
= GET_MODE_INNER (cmode
);
2945 ibitsize
= GET_MODE_BITSIZE (imode
);
2947 /* Special case reads from complex constants that got spilled to memory. */
2948 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
2950 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
2951 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
2953 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
2954 if (CONSTANT_CLASS_P (part
))
2955 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
2959 /* For MEMs simplify_gen_subreg may generate an invalid new address
2960 because, e.g., the original address is considered mode-dependent
2961 by the target, which restricts simplify_subreg from invoking
2962 adjust_address_nv. Instead of preparing fallback support for an
2963 invalid address, we call adjust_address_nv directly. */
2965 return adjust_address_nv (cplx
, imode
,
2966 imag_p
? GET_MODE_SIZE (imode
) : 0);
2968 /* If the sub-object is at least word sized, then we know that subregging
2969 will work. This special case is important, since extract_bit_field
2970 wants to operate on integer modes, and there's rarely an OImode to
2971 correspond to TCmode. */
2972 if (ibitsize
>= BITS_PER_WORD
2973 /* For hard regs we have exact predicates. Assume we can split
2974 the original object if it spans an even number of hard regs.
2975 This special case is important for SCmode on 64-bit platforms
2976 where the natural size of floating-point regs is 32-bit. */
2978 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2979 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2981 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
2982 imag_p
? GET_MODE_SIZE (imode
) : 0);
2986 /* simplify_gen_subreg may fail for sub-word MEMs. */
2987 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2990 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
2991 true, false, NULL_RTX
, imode
, imode
);
2994 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
2995 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
2996 represented in NEW_MODE. If FORCE is true, this will never happen, as
2997 we'll force-create a SUBREG if needed. */
3000 emit_move_change_mode (enum machine_mode new_mode
,
3001 enum machine_mode old_mode
, rtx x
, bool force
)
3005 if (push_operand (x
, GET_MODE (x
)))
3007 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3008 MEM_COPY_ATTRIBUTES (ret
, x
);
3012 /* We don't have to worry about changing the address since the
3013 size in bytes is supposed to be the same. */
3014 if (reload_in_progress
)
3016 /* Copy the MEM to change the mode and move any
3017 substitutions from the old MEM to the new one. */
3018 ret
= adjust_address_nv (x
, new_mode
, 0);
3019 copy_replacements (x
, ret
);
3022 ret
= adjust_address (x
, new_mode
, 0);
3026 /* Note that we do want simplify_subreg's behavior of validating
3027 that the new mode is ok for a hard register. If we were to use
3028 simplify_gen_subreg, we would create the subreg, but would
3029 probably run into the target not being able to implement it. */
3030 /* Except, of course, when FORCE is true, when this is exactly what
3031 we want. Which is needed for CCmodes on some targets. */
3033 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3035 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3041 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3042 an integer mode of the same size as MODE. Returns the instruction
3043 emitted, or NULL if such a move could not be generated. */
3046 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3048 enum machine_mode imode
;
3049 enum insn_code code
;
3051 /* There must exist a mode of the exact size we require. */
3052 imode
= int_mode_for_mode (mode
);
3053 if (imode
== BLKmode
)
3056 /* The target must support moves in this mode. */
3057 code
= optab_handler (mov_optab
, imode
);
3058 if (code
== CODE_FOR_nothing
)
3061 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3064 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3067 return emit_insn (GEN_FCN (code
) (x
, y
));
3070 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3071 Return an equivalent MEM that does not use an auto-increment. */
3074 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3076 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3077 HOST_WIDE_INT adjust
;
3080 adjust
= GET_MODE_SIZE (mode
);
3081 #ifdef PUSH_ROUNDING
3082 adjust
= PUSH_ROUNDING (adjust
);
3084 if (code
== PRE_DEC
|| code
== POST_DEC
)
3086 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3088 rtx expr
= XEXP (XEXP (x
, 0), 1);
3091 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3092 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3093 val
= INTVAL (XEXP (expr
, 1));
3094 if (GET_CODE (expr
) == MINUS
)
3096 gcc_assert (adjust
== val
|| adjust
== -val
);
3100 /* Do not use anti_adjust_stack, since we don't want to update
3101 stack_pointer_delta. */
3102 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3103 GEN_INT (adjust
), stack_pointer_rtx
,
3104 0, OPTAB_LIB_WIDEN
);
3105 if (temp
!= stack_pointer_rtx
)
3106 emit_move_insn (stack_pointer_rtx
, temp
);
3113 temp
= stack_pointer_rtx
;
3118 temp
= plus_constant (stack_pointer_rtx
, -adjust
);
3124 return replace_equiv_address (x
, temp
);
3127 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3128 X is known to satisfy push_operand, and MODE is known to be complex.
3129 Returns the last instruction emitted. */
3132 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3134 enum machine_mode submode
= GET_MODE_INNER (mode
);
3137 #ifdef PUSH_ROUNDING
3138 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3140 /* In case we output to the stack, but the size is smaller than the
3141 machine can push exactly, we need to use move instructions. */
3142 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3144 x
= emit_move_resolve_push (mode
, x
);
3145 return emit_move_insn (x
, y
);
3149 /* Note that the real part always precedes the imag part in memory
3150 regardless of machine's endianness. */
3151 switch (GET_CODE (XEXP (x
, 0)))
3165 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3166 read_complex_part (y
, imag_first
));
3167 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3168 read_complex_part (y
, !imag_first
));
3171 /* A subroutine of emit_move_complex. Perform the move from Y to X
3172 via two moves of the parts. Returns the last instruction emitted. */
3175 emit_move_complex_parts (rtx x
, rtx y
)
3177 /* Show the output dies here. This is necessary for SUBREGs
3178 of pseudos since we cannot track their lifetimes correctly;
3179 hard regs shouldn't appear here except as return values. */
3180 if (!reload_completed
&& !reload_in_progress
3181 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3184 write_complex_part (x
, read_complex_part (y
, false), false);
3185 write_complex_part (x
, read_complex_part (y
, true), true);
3187 return get_last_insn ();
3190 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3191 MODE is known to be complex. Returns the last instruction emitted. */
3194 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3198 /* Need to take special care for pushes, to maintain proper ordering
3199 of the data, and possibly extra padding. */
3200 if (push_operand (x
, mode
))
3201 return emit_move_complex_push (mode
, x
, y
);
3203 /* See if we can coerce the target into moving both values at once. */
3205 /* Move floating point as parts. */
3206 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3207 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
)
3209 /* Not possible if the values are inherently not adjacent. */
3210 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3212 /* Is possible if both are registers (or subregs of registers). */
3213 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3215 /* If one of the operands is a memory, and alignment constraints
3216 are friendly enough, we may be able to do combined memory operations.
3217 We do not attempt this if Y is a constant because that combination is
3218 usually better with the by-parts thing below. */
3219 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3220 && (!STRICT_ALIGNMENT
3221 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3230 /* For memory to memory moves, optimal behavior can be had with the
3231 existing block move logic. */
3232 if (MEM_P (x
) && MEM_P (y
))
3234 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3235 BLOCK_OP_NO_LIBCALL
);
3236 return get_last_insn ();
3239 ret
= emit_move_via_integer (mode
, x
, y
, true);
3244 return emit_move_complex_parts (x
, y
);
3247 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3248 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3251 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3255 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3258 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3259 if (code
!= CODE_FOR_nothing
)
3261 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3262 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3263 return emit_insn (GEN_FCN (code
) (x
, y
));
3267 /* Otherwise, find the MODE_INT mode of the same width. */
3268 ret
= emit_move_via_integer (mode
, x
, y
, false);
3269 gcc_assert (ret
!= NULL
);
3273 /* Return true if word I of OP lies entirely in the
3274 undefined bits of a paradoxical subreg. */
3277 undefined_operand_subword_p (const_rtx op
, int i
)
3279 enum machine_mode innermode
, innermostmode
;
3281 if (GET_CODE (op
) != SUBREG
)
3283 innermode
= GET_MODE (op
);
3284 innermostmode
= GET_MODE (SUBREG_REG (op
));
3285 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3286 /* The SUBREG_BYTE represents offset, as if the value were stored in
3287 memory, except for a paradoxical subreg where we define
3288 SUBREG_BYTE to be 0; undo this exception as in
3290 if (SUBREG_BYTE (op
) == 0
3291 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3293 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3294 if (WORDS_BIG_ENDIAN
)
3295 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3296 if (BYTES_BIG_ENDIAN
)
3297 offset
+= difference
% UNITS_PER_WORD
;
3299 if (offset
>= GET_MODE_SIZE (innermostmode
)
3300 || offset
<= -GET_MODE_SIZE (word_mode
))
3305 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3306 MODE is any multi-word or full-word mode that lacks a move_insn
3307 pattern. Note that you will get better code if you define such
3308 patterns, even if they must turn into multiple assembler instructions. */
3311 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3318 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3320 /* If X is a push on the stack, do the push now and replace
3321 X with a reference to the stack pointer. */
3322 if (push_operand (x
, mode
))
3323 x
= emit_move_resolve_push (mode
, x
);
3325 /* If we are in reload, see if either operand is a MEM whose address
3326 is scheduled for replacement. */
3327 if (reload_in_progress
&& MEM_P (x
)
3328 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3329 x
= replace_equiv_address_nv (x
, inner
);
3330 if (reload_in_progress
&& MEM_P (y
)
3331 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3332 y
= replace_equiv_address_nv (y
, inner
);
3336 need_clobber
= false;
3338 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3341 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3344 /* Do not generate code for a move if it would come entirely
3345 from the undefined bits of a paradoxical subreg. */
3346 if (undefined_operand_subword_p (y
, i
))
3349 ypart
= operand_subword (y
, i
, 1, mode
);
3351 /* If we can't get a part of Y, put Y into memory if it is a
3352 constant. Otherwise, force it into a register. Then we must
3353 be able to get a part of Y. */
3354 if (ypart
== 0 && CONSTANT_P (y
))
3356 y
= use_anchored_address (force_const_mem (mode
, y
));
3357 ypart
= operand_subword (y
, i
, 1, mode
);
3359 else if (ypart
== 0)
3360 ypart
= operand_subword_force (y
, i
, mode
);
3362 gcc_assert (xpart
&& ypart
);
3364 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3366 last_insn
= emit_move_insn (xpart
, ypart
);
3372 /* Show the output dies here. This is necessary for SUBREGs
3373 of pseudos since we cannot track their lifetimes correctly;
3374 hard regs shouldn't appear here except as return values.
3375 We never want to emit such a clobber after reload. */
3377 && ! (reload_in_progress
|| reload_completed
)
3378 && need_clobber
!= 0)
3386 /* Low level part of emit_move_insn.
3387 Called just like emit_move_insn, but assumes X and Y
3388 are basically valid. */
3391 emit_move_insn_1 (rtx x
, rtx y
)
3393 enum machine_mode mode
= GET_MODE (x
);
3394 enum insn_code code
;
3396 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3398 code
= optab_handler (mov_optab
, mode
);
3399 if (code
!= CODE_FOR_nothing
)
3400 return emit_insn (GEN_FCN (code
) (x
, y
));
3402 /* Expand complex moves by moving real part and imag part. */
3403 if (COMPLEX_MODE_P (mode
))
3404 return emit_move_complex (mode
, x
, y
);
3406 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3407 || ALL_FIXED_POINT_MODE_P (mode
))
3409 rtx result
= emit_move_via_integer (mode
, x
, y
, true);
3411 /* If we can't find an integer mode, use multi words. */
3415 return emit_move_multi_word (mode
, x
, y
);
3418 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3419 return emit_move_ccmode (mode
, x
, y
);
3421 /* Try using a move pattern for the corresponding integer mode. This is
3422 only safe when simplify_subreg can convert MODE constants into integer
3423 constants. At present, it can only do this reliably if the value
3424 fits within a HOST_WIDE_INT. */
3425 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3427 rtx ret
= emit_move_via_integer (mode
, x
, y
, false);
3432 return emit_move_multi_word (mode
, x
, y
);
3435 /* Generate code to copy Y into X.
3436 Both Y and X must have the same mode, except that
3437 Y can be a constant with VOIDmode.
3438 This mode cannot be BLKmode; use emit_block_move for that.
3440 Return the last instruction emitted. */
3443 emit_move_insn (rtx x
, rtx y
)
3445 enum machine_mode mode
= GET_MODE (x
);
3446 rtx y_cst
= NULL_RTX
;
3449 gcc_assert (mode
!= BLKmode
3450 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3455 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3456 && (last_insn
= compress_float_constant (x
, y
)))
3461 if (!targetm
.legitimate_constant_p (mode
, y
))
3463 y
= force_const_mem (mode
, y
);
3465 /* If the target's cannot_force_const_mem prevented the spill,
3466 assume that the target's move expanders will also take care
3467 of the non-legitimate constant. */
3471 y
= use_anchored_address (y
);
3475 /* If X or Y are memory references, verify that their addresses are valid
3478 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3480 && ! push_operand (x
, GET_MODE (x
))))
3481 x
= validize_mem (x
);
3484 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3485 MEM_ADDR_SPACE (y
)))
3486 y
= validize_mem (y
);
3488 gcc_assert (mode
!= BLKmode
);
3490 last_insn
= emit_move_insn_1 (x
, y
);
3492 if (y_cst
&& REG_P (x
)
3493 && (set
= single_set (last_insn
)) != NULL_RTX
3494 && SET_DEST (set
) == x
3495 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3496 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3501 /* If Y is representable exactly in a narrower mode, and the target can
3502 perform the extension directly from constant or memory, then emit the
3503 move as an extension. */
3506 compress_float_constant (rtx x
, rtx y
)
3508 enum machine_mode dstmode
= GET_MODE (x
);
3509 enum machine_mode orig_srcmode
= GET_MODE (y
);
3510 enum machine_mode srcmode
;
3512 int oldcost
, newcost
;
3513 bool speed
= optimize_insn_for_speed_p ();
3515 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3517 if (targetm
.legitimate_constant_p (dstmode
, y
))
3518 oldcost
= set_src_cost (y
, speed
);
3520 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3522 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3523 srcmode
!= orig_srcmode
;
3524 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3527 rtx trunc_y
, last_insn
;
3529 /* Skip if the target can't extend this way. */
3530 ic
= can_extend_p (dstmode
, srcmode
, 0);
3531 if (ic
== CODE_FOR_nothing
)
3534 /* Skip if the narrowed value isn't exact. */
3535 if (! exact_real_truncate (srcmode
, &r
))
3538 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3540 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3542 /* Skip if the target needs extra instructions to perform
3544 if (!insn_operand_matches (ic
, 1, trunc_y
))
3546 /* This is valid, but may not be cheaper than the original. */
3547 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3549 if (oldcost
< newcost
)
3552 else if (float_extend_from_mem
[dstmode
][srcmode
])
3554 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3555 /* This is valid, but may not be cheaper than the original. */
3556 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3558 if (oldcost
< newcost
)
3560 trunc_y
= validize_mem (trunc_y
);
3565 /* For CSE's benefit, force the compressed constant pool entry
3566 into a new pseudo. This constant may be used in different modes,
3567 and if not, combine will put things back together for us. */
3568 trunc_y
= force_reg (srcmode
, trunc_y
);
3569 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3570 last_insn
= get_last_insn ();
3573 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3581 /* Pushing data onto the stack. */
3583 /* Push a block of length SIZE (perhaps variable)
3584 and return an rtx to address the beginning of the block.
3585 The value may be virtual_outgoing_args_rtx.
3587 EXTRA is the number of bytes of padding to push in addition to SIZE.
3588 BELOW nonzero means this padding comes at low addresses;
3589 otherwise, the padding comes at high addresses. */
3592 push_block (rtx size
, int extra
, int below
)
3596 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3597 if (CONSTANT_P (size
))
3598 anti_adjust_stack (plus_constant (size
, extra
));
3599 else if (REG_P (size
) && extra
== 0)
3600 anti_adjust_stack (size
);
3603 temp
= copy_to_mode_reg (Pmode
, size
);
3605 temp
= expand_binop (Pmode
, add_optab
, temp
, GEN_INT (extra
),
3606 temp
, 0, OPTAB_LIB_WIDEN
);
3607 anti_adjust_stack (temp
);
3610 #ifndef STACK_GROWS_DOWNWARD
3616 temp
= virtual_outgoing_args_rtx
;
3617 if (extra
!= 0 && below
)
3618 temp
= plus_constant (temp
, extra
);
3622 if (CONST_INT_P (size
))
3623 temp
= plus_constant (virtual_outgoing_args_rtx
,
3624 -INTVAL (size
) - (below
? 0 : extra
));
3625 else if (extra
!= 0 && !below
)
3626 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3627 negate_rtx (Pmode
, plus_constant (size
, extra
)));
3629 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3630 negate_rtx (Pmode
, size
));
3633 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3636 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3639 mem_autoinc_base (rtx mem
)
3643 rtx addr
= XEXP (mem
, 0);
3644 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3645 return XEXP (addr
, 0);
3650 /* A utility routine used here, in reload, and in try_split. The insns
3651 after PREV up to and including LAST are known to adjust the stack,
3652 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3653 placing notes as appropriate. PREV may be NULL, indicating the
3654 entire insn sequence prior to LAST should be scanned.
3656 The set of allowed stack pointer modifications is small:
3657 (1) One or more auto-inc style memory references (aka pushes),
3658 (2) One or more addition/subtraction with the SP as destination,
3659 (3) A single move insn with the SP as destination,
3660 (4) A call_pop insn,
3661 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3663 Insns in the sequence that do not modify the SP are ignored,
3664 except for noreturn calls.
3666 The return value is the amount of adjustment that can be trivially
3667 verified, via immediate operand or auto-inc. If the adjustment
3668 cannot be trivially extracted, the return value is INT_MIN. */
3671 find_args_size_adjust (rtx insn
)
3676 pat
= PATTERN (insn
);
3679 /* Look for a call_pop pattern. */
3682 /* We have to allow non-call_pop patterns for the case
3683 of emit_single_push_insn of a TLS address. */
3684 if (GET_CODE (pat
) != PARALLEL
)
3687 /* All call_pop have a stack pointer adjust in the parallel.
3688 The call itself is always first, and the stack adjust is
3689 usually last, so search from the end. */
3690 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3692 set
= XVECEXP (pat
, 0, i
);
3693 if (GET_CODE (set
) != SET
)
3695 dest
= SET_DEST (set
);
3696 if (dest
== stack_pointer_rtx
)
3699 /* We'd better have found the stack pointer adjust. */
3702 /* Fall through to process the extracted SET and DEST
3703 as if it was a standalone insn. */
3705 else if (GET_CODE (pat
) == SET
)
3707 else if ((set
= single_set (insn
)) != NULL
)
3709 else if (GET_CODE (pat
) == PARALLEL
)
3711 /* ??? Some older ports use a parallel with a stack adjust
3712 and a store for a PUSH_ROUNDING pattern, rather than a
3713 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3714 /* ??? See h8300 and m68k, pushqi1. */
3715 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3717 set
= XVECEXP (pat
, 0, i
);
3718 if (GET_CODE (set
) != SET
)
3720 dest
= SET_DEST (set
);
3721 if (dest
== stack_pointer_rtx
)
3724 /* We do not expect an auto-inc of the sp in the parallel. */
3725 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3726 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3727 != stack_pointer_rtx
);
3735 dest
= SET_DEST (set
);
3737 /* Look for direct modifications of the stack pointer. */
3738 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3740 /* Look for a trivial adjustment, otherwise assume nothing. */
3741 /* Note that the SPU restore_stack_block pattern refers to
3742 the stack pointer in V4SImode. Consider that non-trivial. */
3743 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3744 && GET_CODE (SET_SRC (set
)) == PLUS
3745 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3746 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3747 return INTVAL (XEXP (SET_SRC (set
), 1));
3748 /* ??? Reload can generate no-op moves, which will be cleaned
3749 up later. Recognize it and continue searching. */
3750 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3753 return HOST_WIDE_INT_MIN
;
3759 /* Otherwise only think about autoinc patterns. */
3760 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3763 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3764 != stack_pointer_rtx
);
3766 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3767 mem
= SET_SRC (set
);
3771 addr
= XEXP (mem
, 0);
3772 switch (GET_CODE (addr
))
3776 return GET_MODE_SIZE (GET_MODE (mem
));
3779 return -GET_MODE_SIZE (GET_MODE (mem
));
3782 addr
= XEXP (addr
, 1);
3783 gcc_assert (GET_CODE (addr
) == PLUS
);
3784 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3785 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3786 return INTVAL (XEXP (addr
, 1));
3794 fixup_args_size_notes (rtx prev
, rtx last
, int end_args_size
)
3796 int args_size
= end_args_size
;
3797 bool saw_unknown
= false;
3800 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3802 HOST_WIDE_INT this_delta
;
3804 if (!NONDEBUG_INSN_P (insn
))
3807 this_delta
= find_args_size_adjust (insn
);
3808 if (this_delta
== 0)
3811 || ACCUMULATE_OUTGOING_ARGS
3812 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3816 gcc_assert (!saw_unknown
);
3817 if (this_delta
== HOST_WIDE_INT_MIN
)
3820 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3821 #ifdef STACK_GROWS_DOWNWARD
3822 this_delta
= -this_delta
;
3824 args_size
-= this_delta
;
3827 return saw_unknown
? INT_MIN
: args_size
;
3830 #ifdef PUSH_ROUNDING
3831 /* Emit single push insn. */
3834 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3837 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3839 enum insn_code icode
;
3841 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3842 /* If there is push pattern, use it. Otherwise try old way of throwing
3843 MEM representing push operation to move expander. */
3844 icode
= optab_handler (push_optab
, mode
);
3845 if (icode
!= CODE_FOR_nothing
)
3847 struct expand_operand ops
[1];
3849 create_input_operand (&ops
[0], x
, mode
);
3850 if (maybe_expand_insn (icode
, 1, ops
))
3853 if (GET_MODE_SIZE (mode
) == rounded_size
)
3854 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3855 /* If we are to pad downward, adjust the stack pointer first and
3856 then store X into the stack location using an offset. This is
3857 because emit_move_insn does not know how to pad; it does not have
3859 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3861 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3862 HOST_WIDE_INT offset
;
3864 emit_move_insn (stack_pointer_rtx
,
3865 expand_binop (Pmode
,
3866 #ifdef STACK_GROWS_DOWNWARD
3872 GEN_INT (rounded_size
),
3873 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3875 offset
= (HOST_WIDE_INT
) padding_size
;
3876 #ifdef STACK_GROWS_DOWNWARD
3877 if (STACK_PUSH_CODE
== POST_DEC
)
3878 /* We have already decremented the stack pointer, so get the
3880 offset
+= (HOST_WIDE_INT
) rounded_size
;
3882 if (STACK_PUSH_CODE
== POST_INC
)
3883 /* We have already incremented the stack pointer, so get the
3885 offset
-= (HOST_WIDE_INT
) rounded_size
;
3887 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
3891 #ifdef STACK_GROWS_DOWNWARD
3892 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3893 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3894 GEN_INT (-(HOST_WIDE_INT
) rounded_size
));
3896 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3897 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3898 GEN_INT (rounded_size
));
3900 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
3903 dest
= gen_rtx_MEM (mode
, dest_addr
);
3907 set_mem_attributes (dest
, type
, 1);
3909 if (flag_optimize_sibling_calls
)
3910 /* Function incoming arguments may overlap with sibling call
3911 outgoing arguments and we cannot allow reordering of reads
3912 from function arguments with stores to outgoing arguments
3913 of sibling calls. */
3914 set_mem_alias_set (dest
, 0);
3916 emit_move_insn (dest
, x
);
3919 /* Emit and annotate a single push insn. */
3922 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
3924 int delta
, old_delta
= stack_pointer_delta
;
3925 rtx prev
= get_last_insn ();
3928 emit_single_push_insn_1 (mode
, x
, type
);
3930 last
= get_last_insn ();
3932 /* Notice the common case where we emitted exactly one insn. */
3933 if (PREV_INSN (last
) == prev
)
3935 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
3939 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
3940 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
3944 /* Generate code to push X onto the stack, assuming it has mode MODE and
3946 MODE is redundant except when X is a CONST_INT (since they don't
3948 SIZE is an rtx for the size of data to be copied (in bytes),
3949 needed only if X is BLKmode.
3951 ALIGN (in bits) is maximum alignment we can assume.
3953 If PARTIAL and REG are both nonzero, then copy that many of the first
3954 bytes of X into registers starting with REG, and push the rest of X.
3955 The amount of space pushed is decreased by PARTIAL bytes.
3956 REG must be a hard register in this case.
3957 If REG is zero but PARTIAL is not, take any all others actions for an
3958 argument partially in registers, but do not actually load any
3961 EXTRA is the amount in bytes of extra space to leave next to this arg.
3962 This is ignored if an argument block has already been allocated.
3964 On a machine that lacks real push insns, ARGS_ADDR is the address of
3965 the bottom of the argument block for this call. We use indexing off there
3966 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3967 argument block has not been preallocated.
3969 ARGS_SO_FAR is the size of args previously pushed for this call.
3971 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3972 for arguments passed in registers. If nonzero, it will be the number
3973 of bytes required. */
3976 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
3977 unsigned int align
, int partial
, rtx reg
, int extra
,
3978 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
3982 enum direction stack_direction
3983 #ifdef STACK_GROWS_DOWNWARD
3989 /* Decide where to pad the argument: `downward' for below,
3990 `upward' for above, or `none' for don't pad it.
3991 Default is below for small data on big-endian machines; else above. */
3992 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
3994 /* Invert direction if stack is post-decrement.
3996 if (STACK_PUSH_CODE
== POST_DEC
)
3997 if (where_pad
!= none
)
3998 where_pad
= (where_pad
== downward
? upward
: downward
);
4003 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4005 /* Copy a block into the stack, entirely or partially. */
4012 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4013 used
= partial
- offset
;
4015 if (mode
!= BLKmode
)
4017 /* A value is to be stored in an insufficiently aligned
4018 stack slot; copy via a suitably aligned slot if
4020 size
= GEN_INT (GET_MODE_SIZE (mode
));
4021 if (!MEM_P (xinner
))
4023 temp
= assign_temp (type
, 0, 1, 1);
4024 emit_move_insn (temp
, xinner
);
4031 /* USED is now the # of bytes we need not copy to the stack
4032 because registers will take care of them. */
4035 xinner
= adjust_address (xinner
, BLKmode
, used
);
4037 /* If the partial register-part of the arg counts in its stack size,
4038 skip the part of stack space corresponding to the registers.
4039 Otherwise, start copying to the beginning of the stack space,
4040 by setting SKIP to 0. */
4041 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4043 #ifdef PUSH_ROUNDING
4044 /* Do it with several push insns if that doesn't take lots of insns
4045 and if there is no difficulty with push insns that skip bytes
4046 on the stack for alignment purposes. */
4049 && CONST_INT_P (size
)
4051 && MEM_ALIGN (xinner
) >= align
4052 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4053 /* Here we avoid the case of a structure whose weak alignment
4054 forces many pushes of a small amount of data,
4055 and such small pushes do rounding that causes trouble. */
4056 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4057 || align
>= BIGGEST_ALIGNMENT
4058 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4059 == (align
/ BITS_PER_UNIT
)))
4060 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4062 /* Push padding now if padding above and stack grows down,
4063 or if padding below and stack grows up.
4064 But if space already allocated, this has already been done. */
4065 if (extra
&& args_addr
== 0
4066 && where_pad
!= none
&& where_pad
!= stack_direction
)
4067 anti_adjust_stack (GEN_INT (extra
));
4069 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4072 #endif /* PUSH_ROUNDING */
4076 /* Otherwise make space on the stack and copy the data
4077 to the address of that space. */
4079 /* Deduct words put into registers from the size we must copy. */
4082 if (CONST_INT_P (size
))
4083 size
= GEN_INT (INTVAL (size
) - used
);
4085 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4086 GEN_INT (used
), NULL_RTX
, 0,
4090 /* Get the address of the stack space.
4091 In this case, we do not deal with EXTRA separately.
4092 A single stack adjust will do. */
4095 temp
= push_block (size
, extra
, where_pad
== downward
);
4098 else if (CONST_INT_P (args_so_far
))
4099 temp
= memory_address (BLKmode
,
4100 plus_constant (args_addr
,
4101 skip
+ INTVAL (args_so_far
)));
4103 temp
= memory_address (BLKmode
,
4104 plus_constant (gen_rtx_PLUS (Pmode
,
4109 if (!ACCUMULATE_OUTGOING_ARGS
)
4111 /* If the source is referenced relative to the stack pointer,
4112 copy it to another register to stabilize it. We do not need
4113 to do this if we know that we won't be changing sp. */
4115 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4116 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4117 temp
= copy_to_reg (temp
);
4120 target
= gen_rtx_MEM (BLKmode
, temp
);
4122 /* We do *not* set_mem_attributes here, because incoming arguments
4123 may overlap with sibling call outgoing arguments and we cannot
4124 allow reordering of reads from function arguments with stores
4125 to outgoing arguments of sibling calls. We do, however, want
4126 to record the alignment of the stack slot. */
4127 /* ALIGN may well be better aligned than TYPE, e.g. due to
4128 PARM_BOUNDARY. Assume the caller isn't lying. */
4129 set_mem_align (target
, align
);
4131 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4134 else if (partial
> 0)
4136 /* Scalar partly in registers. */
4138 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4141 /* # bytes of start of argument
4142 that we must make space for but need not store. */
4143 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4144 int args_offset
= INTVAL (args_so_far
);
4147 /* Push padding now if padding above and stack grows down,
4148 or if padding below and stack grows up.
4149 But if space already allocated, this has already been done. */
4150 if (extra
&& args_addr
== 0
4151 && where_pad
!= none
&& where_pad
!= stack_direction
)
4152 anti_adjust_stack (GEN_INT (extra
));
4154 /* If we make space by pushing it, we might as well push
4155 the real data. Otherwise, we can leave OFFSET nonzero
4156 and leave the space uninitialized. */
4160 /* Now NOT_STACK gets the number of words that we don't need to
4161 allocate on the stack. Convert OFFSET to words too. */
4162 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4163 offset
/= UNITS_PER_WORD
;
4165 /* If the partial register-part of the arg counts in its stack size,
4166 skip the part of stack space corresponding to the registers.
4167 Otherwise, start copying to the beginning of the stack space,
4168 by setting SKIP to 0. */
4169 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4171 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4172 x
= validize_mem (force_const_mem (mode
, x
));
4174 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4175 SUBREGs of such registers are not allowed. */
4176 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4177 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4178 x
= copy_to_reg (x
);
4180 /* Loop over all the words allocated on the stack for this arg. */
4181 /* We can do it by words, because any scalar bigger than a word
4182 has a size a multiple of a word. */
4183 #ifndef PUSH_ARGS_REVERSED
4184 for (i
= not_stack
; i
< size
; i
++)
4186 for (i
= size
- 1; i
>= not_stack
; i
--)
4188 if (i
>= not_stack
+ offset
)
4189 emit_push_insn (operand_subword_force (x
, i
, mode
),
4190 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4192 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4194 reg_parm_stack_space
, alignment_pad
);
4201 /* Push padding now if padding above and stack grows down,
4202 or if padding below and stack grows up.
4203 But if space already allocated, this has already been done. */
4204 if (extra
&& args_addr
== 0
4205 && where_pad
!= none
&& where_pad
!= stack_direction
)
4206 anti_adjust_stack (GEN_INT (extra
));
4208 #ifdef PUSH_ROUNDING
4209 if (args_addr
== 0 && PUSH_ARGS
)
4210 emit_single_push_insn (mode
, x
, type
);
4214 if (CONST_INT_P (args_so_far
))
4216 = memory_address (mode
,
4217 plus_constant (args_addr
,
4218 INTVAL (args_so_far
)));
4220 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4222 dest
= gen_rtx_MEM (mode
, addr
);
4224 /* We do *not* set_mem_attributes here, because incoming arguments
4225 may overlap with sibling call outgoing arguments and we cannot
4226 allow reordering of reads from function arguments with stores
4227 to outgoing arguments of sibling calls. We do, however, want
4228 to record the alignment of the stack slot. */
4229 /* ALIGN may well be better aligned than TYPE, e.g. due to
4230 PARM_BOUNDARY. Assume the caller isn't lying. */
4231 set_mem_align (dest
, align
);
4233 emit_move_insn (dest
, x
);
4237 /* If part should go in registers, copy that part
4238 into the appropriate registers. Do this now, at the end,
4239 since mem-to-mem copies above may do function calls. */
4240 if (partial
> 0 && reg
!= 0)
4242 /* Handle calls that pass values in multiple non-contiguous locations.
4243 The Irix 6 ABI has examples of this. */
4244 if (GET_CODE (reg
) == PARALLEL
)
4245 emit_group_load (reg
, x
, type
, -1);
4248 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4249 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4253 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4254 anti_adjust_stack (GEN_INT (extra
));
4256 if (alignment_pad
&& args_addr
== 0)
4257 anti_adjust_stack (alignment_pad
);
4260 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4264 get_subtarget (rtx x
)
4268 /* Only registers can be subtargets. */
4270 /* Don't use hard regs to avoid extending their life. */
4271 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4275 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4276 FIELD is a bitfield. Returns true if the optimization was successful,
4277 and there's nothing else to do. */
4280 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4281 unsigned HOST_WIDE_INT bitpos
,
4282 unsigned HOST_WIDE_INT bitregion_start
,
4283 unsigned HOST_WIDE_INT bitregion_end
,
4284 enum machine_mode mode1
, rtx str_rtx
,
4287 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4288 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4293 enum tree_code code
;
4295 if (mode1
!= VOIDmode
4296 || bitsize
>= BITS_PER_WORD
4297 || str_bitsize
> BITS_PER_WORD
4298 || TREE_SIDE_EFFECTS (to
)
4299 || TREE_THIS_VOLATILE (to
))
4303 if (TREE_CODE (src
) != SSA_NAME
)
4305 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4308 srcstmt
= get_gimple_for_ssa_name (src
);
4310 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4313 code
= gimple_assign_rhs_code (srcstmt
);
4315 op0
= gimple_assign_rhs1 (srcstmt
);
4317 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4318 to find its initialization. Hopefully the initialization will
4319 be from a bitfield load. */
4320 if (TREE_CODE (op0
) == SSA_NAME
)
4322 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4324 /* We want to eventually have OP0 be the same as TO, which
4325 should be a bitfield. */
4327 || !is_gimple_assign (op0stmt
)
4328 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4330 op0
= gimple_assign_rhs1 (op0stmt
);
4333 op1
= gimple_assign_rhs2 (srcstmt
);
4335 if (!operand_equal_p (to
, op0
, 0))
4338 if (MEM_P (str_rtx
))
4340 unsigned HOST_WIDE_INT offset1
;
4342 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4343 str_mode
= word_mode
;
4344 str_mode
= get_best_mode (bitsize
, bitpos
,
4345 bitregion_start
, bitregion_end
,
4346 MEM_ALIGN (str_rtx
), str_mode
, 0);
4347 if (str_mode
== VOIDmode
)
4349 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4352 bitpos
%= str_bitsize
;
4353 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4354 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4356 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4359 /* If the bit field covers the whole REG/MEM, store_field
4360 will likely generate better code. */
4361 if (bitsize
>= str_bitsize
)
4364 /* We can't handle fields split across multiple entities. */
4365 if (bitpos
+ bitsize
> str_bitsize
)
4368 if (BYTES_BIG_ENDIAN
)
4369 bitpos
= str_bitsize
- bitpos
- bitsize
;
4375 /* For now, just optimize the case of the topmost bitfield
4376 where we don't need to do any masking and also
4377 1 bit bitfields where xor can be used.
4378 We might win by one instruction for the other bitfields
4379 too if insv/extv instructions aren't used, so that
4380 can be added later. */
4381 if (bitpos
+ bitsize
!= str_bitsize
4382 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4385 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4386 value
= convert_modes (str_mode
,
4387 TYPE_MODE (TREE_TYPE (op1
)), value
,
4388 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4390 /* We may be accessing data outside the field, which means
4391 we can alias adjacent data. */
4392 if (MEM_P (str_rtx
))
4394 str_rtx
= shallow_copy_rtx (str_rtx
);
4395 set_mem_alias_set (str_rtx
, 0);
4396 set_mem_expr (str_rtx
, 0);
4399 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4400 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4402 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4405 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4406 result
= expand_binop (str_mode
, binop
, str_rtx
,
4407 value
, str_rtx
, 1, OPTAB_WIDEN
);
4408 if (result
!= str_rtx
)
4409 emit_move_insn (str_rtx
, result
);
4414 if (TREE_CODE (op1
) != INTEGER_CST
)
4416 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4417 value
= convert_modes (str_mode
,
4418 TYPE_MODE (TREE_TYPE (op1
)), value
,
4419 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4421 /* We may be accessing data outside the field, which means
4422 we can alias adjacent data. */
4423 if (MEM_P (str_rtx
))
4425 str_rtx
= shallow_copy_rtx (str_rtx
);
4426 set_mem_alias_set (str_rtx
, 0);
4427 set_mem_expr (str_rtx
, 0);
4430 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4431 if (bitpos
+ bitsize
!= str_bitsize
)
4433 rtx mask
= GEN_INT (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1);
4434 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4436 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4437 result
= expand_binop (str_mode
, binop
, str_rtx
,
4438 value
, str_rtx
, 1, OPTAB_WIDEN
);
4439 if (result
!= str_rtx
)
4440 emit_move_insn (str_rtx
, result
);
4450 /* In the C++ memory model, consecutive bit fields in a structure are
4451 considered one memory location.
4453 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4454 returns the bit range of consecutive bits in which this COMPONENT_REF
4455 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4456 and *OFFSET may be adjusted in the process.
4458 If the access does not need to be restricted, 0 is returned in both
4459 *BITSTART and *BITEND. */
4462 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4463 unsigned HOST_WIDE_INT
*bitend
,
4465 HOST_WIDE_INT
*bitpos
,
4468 HOST_WIDE_INT bitoffset
;
4471 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4473 field
= TREE_OPERAND (exp
, 1);
4474 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4475 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4476 need to limit the range we can access. */
4479 *bitstart
= *bitend
= 0;
4483 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4484 part of a larger bit field, then the representative does not serve any
4485 useful purpose. This can occur in Ada. */
4486 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4488 enum machine_mode rmode
;
4489 HOST_WIDE_INT rbitsize
, rbitpos
;
4493 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4494 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4495 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4497 *bitstart
= *bitend
= 0;
4502 /* Compute the adjustment to bitpos from the offset of the field
4503 relative to the representative. DECL_FIELD_OFFSET of field and
4504 repr are the same by construction if they are not constants,
4505 see finish_bitfield_layout. */
4506 if (host_integerp (DECL_FIELD_OFFSET (field
), 1)
4507 && host_integerp (DECL_FIELD_OFFSET (repr
), 1))
4508 bitoffset
= (tree_low_cst (DECL_FIELD_OFFSET (field
), 1)
4509 - tree_low_cst (DECL_FIELD_OFFSET (repr
), 1)) * BITS_PER_UNIT
;
4512 bitoffset
+= (tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 1)
4513 - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr
), 1));
4515 /* If the adjustment is larger than bitpos, we would have a negative bit
4516 position for the lower bound and this may wreak havoc later. This can
4517 occur only if we have a non-null offset, so adjust offset and bitpos
4518 to make the lower bound non-negative. */
4519 if (bitoffset
> *bitpos
)
4521 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4523 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4524 gcc_assert (*offset
!= NULL_TREE
);
4528 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4532 *bitstart
= *bitpos
- bitoffset
;
4534 *bitend
= *bitstart
+ tree_low_cst (DECL_SIZE (repr
), 1) - 1;
4537 /* Returns true if the MEM_REF REF refers to an object that does not
4538 reside in memory and has non-BLKmode. */
4541 mem_ref_refers_to_non_mem_p (tree ref
)
4543 tree base
= TREE_OPERAND (ref
, 0);
4544 if (TREE_CODE (base
) != ADDR_EXPR
)
4546 base
= TREE_OPERAND (base
, 0);
4547 return (DECL_P (base
)
4548 && !TREE_ADDRESSABLE (base
)
4549 && DECL_MODE (base
) != BLKmode
4550 && DECL_RTL_SET_P (base
)
4551 && !MEM_P (DECL_RTL (base
)));
4554 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4555 is true, try generating a nontemporal store. */
4558 expand_assignment (tree to
, tree from
, bool nontemporal
)
4562 enum machine_mode mode
;
4564 enum insn_code icode
;
4566 /* Don't crash if the lhs of the assignment was erroneous. */
4567 if (TREE_CODE (to
) == ERROR_MARK
)
4569 expand_normal (from
);
4573 /* Optimize away no-op moves without side-effects. */
4574 if (operand_equal_p (to
, from
, 0))
4577 /* Handle misaligned stores. */
4578 mode
= TYPE_MODE (TREE_TYPE (to
));
4579 if ((TREE_CODE (to
) == MEM_REF
4580 || TREE_CODE (to
) == TARGET_MEM_REF
)
4582 && !mem_ref_refers_to_non_mem_p (to
)
4583 && ((align
= get_object_or_type_alignment (to
))
4584 < GET_MODE_ALIGNMENT (mode
))
4585 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4586 != CODE_FOR_nothing
)
4587 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4591 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4592 reg
= force_not_mem (reg
);
4593 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4595 if (icode
!= CODE_FOR_nothing
)
4597 struct expand_operand ops
[2];
4599 create_fixed_operand (&ops
[0], mem
);
4600 create_input_operand (&ops
[1], reg
, mode
);
4601 /* The movmisalign<mode> pattern cannot fail, else the assignment
4602 would silently be omitted. */
4603 expand_insn (icode
, 2, ops
);
4606 store_bit_field (mem
, GET_MODE_BITSIZE (mode
),
4607 0, 0, 0, mode
, reg
);
4611 /* Assignment of a structure component needs special treatment
4612 if the structure component's rtx is not simply a MEM.
4613 Assignment of an array element at a constant index, and assignment of
4614 an array element in an unaligned packed structure field, has the same
4615 problem. Same for (partially) storing into a non-memory object. */
4616 if (handled_component_p (to
)
4617 || (TREE_CODE (to
) == MEM_REF
4618 && mem_ref_refers_to_non_mem_p (to
))
4619 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4621 enum machine_mode mode1
;
4622 HOST_WIDE_INT bitsize
, bitpos
;
4623 unsigned HOST_WIDE_INT bitregion_start
= 0;
4624 unsigned HOST_WIDE_INT bitregion_end
= 0;
4633 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4634 &unsignedp
, &volatilep
, true);
4636 if (TREE_CODE (to
) == COMPONENT_REF
4637 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4638 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4640 /* If we are going to use store_bit_field and extract_bit_field,
4641 make sure to_rtx will be safe for multiple use. */
4642 mode
= TYPE_MODE (TREE_TYPE (tem
));
4643 if (TREE_CODE (tem
) == MEM_REF
4645 && ((align
= get_object_or_type_alignment (tem
))
4646 < GET_MODE_ALIGNMENT (mode
))
4647 && ((icode
= optab_handler (movmisalign_optab
, mode
))
4648 != CODE_FOR_nothing
))
4650 struct expand_operand ops
[2];
4653 to_rtx
= gen_reg_rtx (mode
);
4654 mem
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4656 /* If the misaligned store doesn't overwrite all bits, perform
4657 rmw cycle on MEM. */
4658 if (bitsize
!= GET_MODE_BITSIZE (mode
))
4660 create_input_operand (&ops
[0], to_rtx
, mode
);
4661 create_fixed_operand (&ops
[1], mem
);
4662 /* The movmisalign<mode> pattern cannot fail, else the assignment
4663 would silently be omitted. */
4664 expand_insn (icode
, 2, ops
);
4666 mem
= copy_rtx (mem
);
4672 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4675 /* If the bitfield is volatile, we want to access it in the
4676 field's mode, not the computed mode.
4677 If a MEM has VOIDmode (external with incomplete type),
4678 use BLKmode for it instead. */
4681 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
4682 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4683 else if (GET_MODE (to_rtx
) == VOIDmode
)
4684 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4689 enum machine_mode address_mode
;
4692 if (!MEM_P (to_rtx
))
4694 /* We can get constant negative offsets into arrays with broken
4695 user code. Translate this to a trap instead of ICEing. */
4696 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4697 expand_builtin_trap ();
4698 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4701 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4703 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (to_rtx
));
4704 if (GET_MODE (offset_rtx
) != address_mode
)
4705 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4707 /* A constant address in TO_RTX can have VOIDmode, we must not try
4708 to call force_reg for that case. Avoid that case. */
4710 && GET_MODE (to_rtx
) == BLKmode
4711 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
4713 && (bitpos
% bitsize
) == 0
4714 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4715 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
4717 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4721 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4722 highest_pow2_factor_for_target (to
,
4726 /* No action is needed if the target is not a memory and the field
4727 lies completely outside that target. This can occur if the source
4728 code contains an out-of-bounds access to a small array. */
4730 && GET_MODE (to_rtx
) != BLKmode
4731 && (unsigned HOST_WIDE_INT
) bitpos
4732 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4734 expand_normal (from
);
4737 /* Handle expand_expr of a complex value returning a CONCAT. */
4738 else if (GET_CODE (to_rtx
) == CONCAT
)
4740 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4741 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4743 && bitsize
== mode_bitsize
)
4744 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4745 else if (bitsize
== mode_bitsize
/ 2
4746 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4747 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4749 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4750 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4751 bitregion_start
, bitregion_end
,
4752 mode1
, from
, TREE_TYPE (tem
),
4753 get_alias_set (to
), nontemporal
);
4754 else if (bitpos
>= mode_bitsize
/ 2)
4755 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4756 bitpos
- mode_bitsize
/ 2,
4757 bitregion_start
, bitregion_end
,
4759 TREE_TYPE (tem
), get_alias_set (to
),
4761 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4764 result
= expand_normal (from
);
4765 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4766 TYPE_MODE (TREE_TYPE (from
)), 0);
4767 emit_move_insn (XEXP (to_rtx
, 0),
4768 read_complex_part (from_rtx
, false));
4769 emit_move_insn (XEXP (to_rtx
, 1),
4770 read_complex_part (from_rtx
, true));
4774 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4775 GET_MODE_SIZE (GET_MODE (to_rtx
)),
4777 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4778 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4779 result
= store_field (temp
, bitsize
, bitpos
,
4780 bitregion_start
, bitregion_end
,
4782 TREE_TYPE (tem
), get_alias_set (to
),
4784 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4785 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4792 /* If the field is at offset zero, we could have been given the
4793 DECL_RTX of the parent struct. Don't munge it. */
4794 to_rtx
= shallow_copy_rtx (to_rtx
);
4796 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4798 /* Deal with volatile and readonly fields. The former is only
4799 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4801 MEM_VOLATILE_P (to_rtx
) = 1;
4802 if (component_uses_parent_alias_set (to
))
4803 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
4806 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4807 bitregion_start
, bitregion_end
,
4812 result
= store_field (to_rtx
, bitsize
, bitpos
,
4813 bitregion_start
, bitregion_end
,
4815 TREE_TYPE (tem
), get_alias_set (to
),
4821 struct expand_operand ops
[2];
4823 create_fixed_operand (&ops
[0], mem
);
4824 create_input_operand (&ops
[1], to_rtx
, mode
);
4825 /* The movmisalign<mode> pattern cannot fail, else the assignment
4826 would silently be omitted. */
4827 expand_insn (icode
, 2, ops
);
4831 preserve_temp_slots (result
);
4837 /* If the rhs is a function call and its value is not an aggregate,
4838 call the function before we start to compute the lhs.
4839 This is needed for correct code for cases such as
4840 val = setjmp (buf) on machines where reference to val
4841 requires loading up part of an address in a separate insn.
4843 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4844 since it might be a promoted variable where the zero- or sign- extension
4845 needs to be done. Handling this in the normal way is safe because no
4846 computation is done before the call. The same is true for SSA names. */
4847 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4848 && COMPLETE_TYPE_P (TREE_TYPE (from
))
4849 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4850 && ! (((TREE_CODE (to
) == VAR_DECL
4851 || TREE_CODE (to
) == PARM_DECL
4852 || TREE_CODE (to
) == RESULT_DECL
)
4853 && REG_P (DECL_RTL (to
)))
4854 || TREE_CODE (to
) == SSA_NAME
))
4859 value
= expand_normal (from
);
4861 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4863 /* Handle calls that return values in multiple non-contiguous locations.
4864 The Irix 6 ABI has examples of this. */
4865 if (GET_CODE (to_rtx
) == PARALLEL
)
4866 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
4867 int_size_in_bytes (TREE_TYPE (from
)));
4868 else if (GET_MODE (to_rtx
) == BLKmode
)
4869 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
4872 if (POINTER_TYPE_P (TREE_TYPE (to
)))
4873 value
= convert_memory_address_addr_space
4874 (GET_MODE (to_rtx
), value
,
4875 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
4877 emit_move_insn (to_rtx
, value
);
4879 preserve_temp_slots (to_rtx
);
4885 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4886 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4888 /* Don't move directly into a return register. */
4889 if (TREE_CODE (to
) == RESULT_DECL
4890 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
4895 if (REG_P (to_rtx
) && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
)
4896 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
4898 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
4900 if (GET_CODE (to_rtx
) == PARALLEL
)
4901 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
4902 int_size_in_bytes (TREE_TYPE (from
)));
4904 emit_move_insn (to_rtx
, temp
);
4906 preserve_temp_slots (to_rtx
);
4912 /* In case we are returning the contents of an object which overlaps
4913 the place the value is being stored, use a safe function when copying
4914 a value through a pointer into a structure value return block. */
4915 if (TREE_CODE (to
) == RESULT_DECL
4916 && TREE_CODE (from
) == INDIRECT_REF
4917 && ADDR_SPACE_GENERIC_P
4918 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
4919 && refs_may_alias_p (to
, from
)
4920 && cfun
->returns_struct
4921 && !cfun
->returns_pcc_struct
)
4926 size
= expr_size (from
);
4927 from_rtx
= expand_normal (from
);
4929 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
4930 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
4931 XEXP (from_rtx
, 0), Pmode
,
4932 convert_to_mode (TYPE_MODE (sizetype
),
4933 size
, TYPE_UNSIGNED (sizetype
)),
4934 TYPE_MODE (sizetype
));
4936 preserve_temp_slots (to_rtx
);
4942 /* Compute FROM and store the value in the rtx we got. */
4945 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
4946 preserve_temp_slots (result
);
4952 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
4953 succeeded, false otherwise. */
4956 emit_storent_insn (rtx to
, rtx from
)
4958 struct expand_operand ops
[2];
4959 enum machine_mode mode
= GET_MODE (to
);
4960 enum insn_code code
= optab_handler (storent_optab
, mode
);
4962 if (code
== CODE_FOR_nothing
)
4965 create_fixed_operand (&ops
[0], to
);
4966 create_input_operand (&ops
[1], from
, mode
);
4967 return maybe_expand_insn (code
, 2, ops
);
4970 /* Generate code for computing expression EXP,
4971 and storing the value into TARGET.
4973 If the mode is BLKmode then we may return TARGET itself.
4974 It turns out that in BLKmode it doesn't cause a problem.
4975 because C has no operators that could combine two different
4976 assignments into the same BLKmode object with different values
4977 with no sequence point. Will other languages need this to
4980 If CALL_PARAM_P is nonzero, this is a store into a call param on the
4981 stack, and block moves may need to be treated specially.
4983 If NONTEMPORAL is true, try using a nontemporal store instruction. */
4986 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
4989 rtx alt_rtl
= NULL_RTX
;
4990 location_t loc
= EXPR_LOCATION (exp
);
4992 if (VOID_TYPE_P (TREE_TYPE (exp
)))
4994 /* C++ can generate ?: expressions with a throw expression in one
4995 branch and an rvalue in the other. Here, we resolve attempts to
4996 store the throw expression's nonexistent result. */
4997 gcc_assert (!call_param_p
);
4998 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5001 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5003 /* Perform first part of compound expression, then assign from second
5005 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5006 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5007 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5010 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5012 /* For conditional expression, get safe form of the target. Then
5013 test the condition, doing the appropriate assignment on either
5014 side. This avoids the creation of unnecessary temporaries.
5015 For non-BLKmode, it is more efficient not to do this. */
5017 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
5019 do_pending_stack_adjust ();
5021 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5022 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5024 emit_jump_insn (gen_jump (lab2
));
5027 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5034 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5035 /* If this is a scalar in a register that is stored in a wider mode
5036 than the declared mode, compute the result into its declared mode
5037 and then convert to the wider mode. Our value is the computed
5040 rtx inner_target
= 0;
5042 /* We can do the conversion inside EXP, which will often result
5043 in some optimizations. Do the conversion in two steps: first
5044 change the signedness, if needed, then the extend. But don't
5045 do this if the type of EXP is a subtype of something else
5046 since then the conversion might involve more than just
5047 converting modes. */
5048 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5049 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5050 && GET_MODE_PRECISION (GET_MODE (target
))
5051 == TYPE_PRECISION (TREE_TYPE (exp
)))
5053 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
5054 != SUBREG_PROMOTED_UNSIGNED_P (target
))
5056 /* Some types, e.g. Fortran's logical*4, won't have a signed
5057 version, so use the mode instead. */
5059 = (signed_or_unsigned_type_for
5060 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)));
5062 ntype
= lang_hooks
.types
.type_for_mode
5063 (TYPE_MODE (TREE_TYPE (exp
)),
5064 SUBREG_PROMOTED_UNSIGNED_P (target
));
5066 exp
= fold_convert_loc (loc
, ntype
, exp
);
5069 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5070 (GET_MODE (SUBREG_REG (target
)),
5071 SUBREG_PROMOTED_UNSIGNED_P (target
)),
5074 inner_target
= SUBREG_REG (target
);
5077 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5078 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5080 /* If TEMP is a VOIDmode constant, use convert_modes to make
5081 sure that we properly convert it. */
5082 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5084 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5085 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
5086 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5087 GET_MODE (target
), temp
,
5088 SUBREG_PROMOTED_UNSIGNED_P (target
));
5091 convert_move (SUBREG_REG (target
), temp
,
5092 SUBREG_PROMOTED_UNSIGNED_P (target
));
5096 else if ((TREE_CODE (exp
) == STRING_CST
5097 || (TREE_CODE (exp
) == MEM_REF
5098 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5099 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5101 && integer_zerop (TREE_OPERAND (exp
, 1))))
5102 && !nontemporal
&& !call_param_p
5105 /* Optimize initialization of an array with a STRING_CST. */
5106 HOST_WIDE_INT exp_len
, str_copy_len
;
5108 tree str
= TREE_CODE (exp
) == STRING_CST
5109 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5111 exp_len
= int_expr_size (exp
);
5115 if (TREE_STRING_LENGTH (str
) <= 0)
5118 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5119 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5122 str_copy_len
= TREE_STRING_LENGTH (str
);
5123 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5124 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5126 str_copy_len
+= STORE_MAX_PIECES
- 1;
5127 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5129 str_copy_len
= MIN (str_copy_len
, exp_len
);
5130 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5131 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5132 MEM_ALIGN (target
), false))
5137 dest_mem
= store_by_pieces (dest_mem
,
5138 str_copy_len
, builtin_strncpy_read_str
,
5140 TREE_STRING_POINTER (str
)),
5141 MEM_ALIGN (target
), false,
5142 exp_len
> str_copy_len
? 1 : 0);
5143 if (exp_len
> str_copy_len
)
5144 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5145 GEN_INT (exp_len
- str_copy_len
),
5154 /* If we want to use a nontemporal store, force the value to
5156 tmp_target
= nontemporal
? NULL_RTX
: target
;
5157 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5159 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5163 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5164 the same as that of TARGET, adjust the constant. This is needed, for
5165 example, in case it is a CONST_DOUBLE and we want only a word-sized
5167 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5168 && TREE_CODE (exp
) != ERROR_MARK
5169 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5170 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5171 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5173 /* If value was not generated in the target, store it there.
5174 Convert the value to TARGET's type first if necessary and emit the
5175 pending incrementations that have been queued when expanding EXP.
5176 Note that we cannot emit the whole queue blindly because this will
5177 effectively disable the POST_INC optimization later.
5179 If TEMP and TARGET compare equal according to rtx_equal_p, but
5180 one or both of them are volatile memory refs, we have to distinguish
5182 - expand_expr has used TARGET. In this case, we must not generate
5183 another copy. This can be detected by TARGET being equal according
5185 - expand_expr has not used TARGET - that means that the source just
5186 happens to have the same RTX form. Since temp will have been created
5187 by expand_expr, it will compare unequal according to == .
5188 We must generate a copy in this case, to reach the correct number
5189 of volatile memory references. */
5191 if ((! rtx_equal_p (temp
, target
)
5192 || (temp
!= target
&& (side_effects_p (temp
)
5193 || side_effects_p (target
))))
5194 && TREE_CODE (exp
) != ERROR_MARK
5195 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5196 but TARGET is not valid memory reference, TEMP will differ
5197 from TARGET although it is really the same location. */
5199 && rtx_equal_p (alt_rtl
, target
)
5200 && !side_effects_p (alt_rtl
)
5201 && !side_effects_p (target
))
5202 /* If there's nothing to copy, don't bother. Don't call
5203 expr_size unless necessary, because some front-ends (C++)
5204 expr_size-hook must not be given objects that are not
5205 supposed to be bit-copied or bit-initialized. */
5206 && expr_size (exp
) != const0_rtx
)
5208 if (GET_MODE (temp
) != GET_MODE (target
)
5209 && GET_MODE (temp
) != VOIDmode
)
5211 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
5212 if (GET_MODE (target
) == BLKmode
5213 && GET_MODE (temp
) == BLKmode
)
5214 emit_block_move (target
, temp
, expr_size (exp
),
5216 ? BLOCK_OP_CALL_PARM
5217 : BLOCK_OP_NORMAL
));
5218 else if (GET_MODE (target
) == BLKmode
)
5219 store_bit_field (target
, INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5220 0, 0, 0, GET_MODE (temp
), temp
);
5222 convert_move (target
, temp
, unsignedp
);
5225 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5227 /* Handle copying a string constant into an array. The string
5228 constant may be shorter than the array. So copy just the string's
5229 actual length, and clear the rest. First get the size of the data
5230 type of the string, which is actually the size of the target. */
5231 rtx size
= expr_size (exp
);
5233 if (CONST_INT_P (size
)
5234 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5235 emit_block_move (target
, temp
, size
,
5237 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5240 enum machine_mode pointer_mode
5241 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5242 enum machine_mode address_mode
5243 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (target
));
5245 /* Compute the size of the data to copy from the string. */
5247 = size_binop_loc (loc
, MIN_EXPR
,
5248 make_tree (sizetype
, size
),
5249 size_int (TREE_STRING_LENGTH (exp
)));
5251 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5253 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5256 /* Copy that much. */
5257 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5258 TYPE_UNSIGNED (sizetype
));
5259 emit_block_move (target
, temp
, copy_size_rtx
,
5261 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5263 /* Figure out how much is left in TARGET that we have to clear.
5264 Do all calculations in pointer_mode. */
5265 if (CONST_INT_P (copy_size_rtx
))
5267 size
= plus_constant (size
, -INTVAL (copy_size_rtx
));
5268 target
= adjust_address (target
, BLKmode
,
5269 INTVAL (copy_size_rtx
));
5273 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5274 copy_size_rtx
, NULL_RTX
, 0,
5277 if (GET_MODE (copy_size_rtx
) != address_mode
)
5278 copy_size_rtx
= convert_to_mode (address_mode
,
5280 TYPE_UNSIGNED (sizetype
));
5282 target
= offset_address (target
, copy_size_rtx
,
5283 highest_pow2_factor (copy_size
));
5284 label
= gen_label_rtx ();
5285 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5286 GET_MODE (size
), 0, label
);
5289 if (size
!= const0_rtx
)
5290 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5296 /* Handle calls that return values in multiple non-contiguous locations.
5297 The Irix 6 ABI has examples of this. */
5298 else if (GET_CODE (target
) == PARALLEL
)
5299 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5300 int_size_in_bytes (TREE_TYPE (exp
)));
5301 else if (GET_MODE (temp
) == BLKmode
)
5302 emit_block_move (target
, temp
, expr_size (exp
),
5304 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5305 else if (nontemporal
5306 && emit_storent_insn (target
, temp
))
5307 /* If we managed to emit a nontemporal store, there is nothing else to
5312 temp
= force_operand (temp
, target
);
5314 emit_move_insn (target
, temp
);
5321 /* Return true if field F of structure TYPE is a flexible array. */
5324 flexible_array_member_p (const_tree f
, const_tree type
)
5329 return (DECL_CHAIN (f
) == NULL
5330 && TREE_CODE (tf
) == ARRAY_TYPE
5332 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5333 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5334 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5335 && int_size_in_bytes (type
) >= 0);
5338 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5339 must have in order for it to completely initialize a value of type TYPE.
5340 Return -1 if the number isn't known.
5342 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5344 static HOST_WIDE_INT
5345 count_type_elements (const_tree type
, bool for_ctor_p
)
5347 switch (TREE_CODE (type
))
5353 nelts
= array_type_nelts (type
);
5354 if (nelts
&& host_integerp (nelts
, 1))
5356 unsigned HOST_WIDE_INT n
;
5358 n
= tree_low_cst (nelts
, 1) + 1;
5359 if (n
== 0 || for_ctor_p
)
5362 return n
* count_type_elements (TREE_TYPE (type
), false);
5364 return for_ctor_p
? -1 : 1;
5369 unsigned HOST_WIDE_INT n
;
5373 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5374 if (TREE_CODE (f
) == FIELD_DECL
)
5377 n
+= count_type_elements (TREE_TYPE (f
), false);
5378 else if (!flexible_array_member_p (f
, type
))
5379 /* Don't count flexible arrays, which are not supposed
5380 to be initialized. */
5388 case QUAL_UNION_TYPE
:
5393 gcc_assert (!for_ctor_p
);
5394 /* Estimate the number of scalars in each field and pick the
5395 maximum. Other estimates would do instead; the idea is simply
5396 to make sure that the estimate is not sensitive to the ordering
5399 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5400 if (TREE_CODE (f
) == FIELD_DECL
)
5402 m
= count_type_elements (TREE_TYPE (f
), false);
5403 /* If the field doesn't span the whole union, add an extra
5404 scalar for the rest. */
5405 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5406 TYPE_SIZE (type
)) != 1)
5418 return TYPE_VECTOR_SUBPARTS (type
);
5422 case FIXED_POINT_TYPE
:
5427 case REFERENCE_TYPE
:
5443 /* Helper for categorize_ctor_elements. Identical interface. */
5446 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5447 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5449 unsigned HOST_WIDE_INT idx
;
5450 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5451 tree value
, purpose
, elt_type
;
5453 /* Whether CTOR is a valid constant initializer, in accordance with what
5454 initializer_constant_valid_p does. If inferred from the constructor
5455 elements, true until proven otherwise. */
5456 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5457 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5462 elt_type
= NULL_TREE
;
5464 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5466 HOST_WIDE_INT mult
= 1;
5468 if (TREE_CODE (purpose
) == RANGE_EXPR
)
5470 tree lo_index
= TREE_OPERAND (purpose
, 0);
5471 tree hi_index
= TREE_OPERAND (purpose
, 1);
5473 if (host_integerp (lo_index
, 1) && host_integerp (hi_index
, 1))
5474 mult
= (tree_low_cst (hi_index
, 1)
5475 - tree_low_cst (lo_index
, 1) + 1);
5478 elt_type
= TREE_TYPE (value
);
5480 switch (TREE_CODE (value
))
5484 HOST_WIDE_INT nz
= 0, ic
= 0;
5486 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5489 nz_elts
+= mult
* nz
;
5490 init_elts
+= mult
* ic
;
5492 if (const_from_elts_p
&& const_p
)
5493 const_p
= const_elt_p
;
5500 if (!initializer_zerop (value
))
5506 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5507 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5511 if (!initializer_zerop (TREE_REALPART (value
)))
5513 if (!initializer_zerop (TREE_IMAGPART (value
)))
5521 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5523 tree v
= VECTOR_CST_ELT (value
, i
);
5524 if (!initializer_zerop (v
))
5533 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5534 nz_elts
+= mult
* tc
;
5535 init_elts
+= mult
* tc
;
5537 if (const_from_elts_p
&& const_p
)
5538 const_p
= initializer_constant_valid_p (value
, elt_type
)
5545 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5546 num_fields
, elt_type
))
5547 *p_complete
= false;
5549 *p_nz_elts
+= nz_elts
;
5550 *p_init_elts
+= init_elts
;
5555 /* Examine CTOR to discover:
5556 * how many scalar fields are set to nonzero values,
5557 and place it in *P_NZ_ELTS;
5558 * how many scalar fields in total are in CTOR,
5559 and place it in *P_ELT_COUNT.
5560 * whether the constructor is complete -- in the sense that every
5561 meaningful byte is explicitly given a value --
5562 and place it in *P_COMPLETE.
5564 Return whether or not CTOR is a valid static constant initializer, the same
5565 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5568 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5569 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5575 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5578 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5579 of which had type LAST_TYPE. Each element was itself a complete
5580 initializer, in the sense that every meaningful byte was explicitly
5581 given a value. Return true if the same is true for the constructor
5585 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5586 const_tree last_type
)
5588 if (TREE_CODE (type
) == UNION_TYPE
5589 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5594 gcc_assert (num_elts
== 1 && last_type
);
5596 /* ??? We could look at each element of the union, and find the
5597 largest element. Which would avoid comparing the size of the
5598 initialized element against any tail padding in the union.
5599 Doesn't seem worth the effort... */
5600 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5603 return count_type_elements (type
, true) == num_elts
;
5606 /* Return 1 if EXP contains mostly (3/4) zeros. */
5609 mostly_zeros_p (const_tree exp
)
5611 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5613 HOST_WIDE_INT nz_elts
, init_elts
;
5616 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5617 return !complete_p
|| nz_elts
< init_elts
/ 4;
5620 return initializer_zerop (exp
);
5623 /* Return 1 if EXP contains all zeros. */
5626 all_zeros_p (const_tree exp
)
5628 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5630 HOST_WIDE_INT nz_elts
, init_elts
;
5633 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5634 return nz_elts
== 0;
5637 return initializer_zerop (exp
);
5640 /* Helper function for store_constructor.
5641 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5642 TYPE is the type of the CONSTRUCTOR, not the element type.
5643 CLEARED is as for store_constructor.
5644 ALIAS_SET is the alias set to use for any stores.
5646 This provides a recursive shortcut back to store_constructor when it isn't
5647 necessary to go through store_field. This is so that we can pass through
5648 the cleared field to let store_constructor know that we may not have to
5649 clear a substructure if the outer structure has already been cleared. */
5652 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5653 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5654 tree exp
, tree type
, int cleared
,
5655 alias_set_type alias_set
)
5657 if (TREE_CODE (exp
) == CONSTRUCTOR
5658 /* We can only call store_constructor recursively if the size and
5659 bit position are on a byte boundary. */
5660 && bitpos
% BITS_PER_UNIT
== 0
5661 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5662 /* If we have a nonzero bitpos for a register target, then we just
5663 let store_field do the bitfield handling. This is unlikely to
5664 generate unnecessary clear instructions anyways. */
5665 && (bitpos
== 0 || MEM_P (target
)))
5669 = adjust_address (target
,
5670 GET_MODE (target
) == BLKmode
5672 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5673 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5676 /* Update the alias set, if required. */
5677 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5678 && MEM_ALIAS_SET (target
) != 0)
5680 target
= copy_rtx (target
);
5681 set_mem_alias_set (target
, alias_set
);
5684 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5687 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, type
, alias_set
,
5691 /* Store the value of constructor EXP into the rtx TARGET.
5692 TARGET is either a REG or a MEM; we know it cannot conflict, since
5693 safe_from_p has been called.
5694 CLEARED is true if TARGET is known to have been zero'd.
5695 SIZE is the number of bytes of TARGET we are allowed to modify: this
5696 may not be the same as the size of EXP if we are assigning to a field
5697 which has been packed to exclude padding bits. */
5700 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5702 tree type
= TREE_TYPE (exp
);
5703 #ifdef WORD_REGISTER_OPERATIONS
5704 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5707 switch (TREE_CODE (type
))
5711 case QUAL_UNION_TYPE
:
5713 unsigned HOST_WIDE_INT idx
;
5716 /* If size is zero or the target is already cleared, do nothing. */
5717 if (size
== 0 || cleared
)
5719 /* We either clear the aggregate or indicate the value is dead. */
5720 else if ((TREE_CODE (type
) == UNION_TYPE
5721 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5722 && ! CONSTRUCTOR_ELTS (exp
))
5723 /* If the constructor is empty, clear the union. */
5725 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5729 /* If we are building a static constructor into a register,
5730 set the initial value as zero so we can fold the value into
5731 a constant. But if more than one register is involved,
5732 this probably loses. */
5733 else if (REG_P (target
) && TREE_STATIC (exp
)
5734 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5736 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5740 /* If the constructor has fewer fields than the structure or
5741 if we are initializing the structure to mostly zeros, clear
5742 the whole structure first. Don't do this if TARGET is a
5743 register whose mode size isn't equal to SIZE since
5744 clear_storage can't handle this case. */
5746 && (((int)VEC_length (constructor_elt
, CONSTRUCTOR_ELTS (exp
))
5747 != fields_length (type
))
5748 || mostly_zeros_p (exp
))
5750 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5753 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5757 if (REG_P (target
) && !cleared
)
5758 emit_clobber (target
);
5760 /* Store each element of the constructor into the
5761 corresponding field of TARGET. */
5762 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5764 enum machine_mode mode
;
5765 HOST_WIDE_INT bitsize
;
5766 HOST_WIDE_INT bitpos
= 0;
5768 rtx to_rtx
= target
;
5770 /* Just ignore missing fields. We cleared the whole
5771 structure, above, if any fields are missing. */
5775 if (cleared
&& initializer_zerop (value
))
5778 if (host_integerp (DECL_SIZE (field
), 1))
5779 bitsize
= tree_low_cst (DECL_SIZE (field
), 1);
5783 mode
= DECL_MODE (field
);
5784 if (DECL_BIT_FIELD (field
))
5787 offset
= DECL_FIELD_OFFSET (field
);
5788 if (host_integerp (offset
, 0)
5789 && host_integerp (bit_position (field
), 0))
5791 bitpos
= int_bit_position (field
);
5795 bitpos
= tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 0);
5799 enum machine_mode address_mode
;
5803 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5804 make_tree (TREE_TYPE (exp
),
5807 offset_rtx
= expand_normal (offset
);
5808 gcc_assert (MEM_P (to_rtx
));
5811 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (to_rtx
));
5812 if (GET_MODE (offset_rtx
) != address_mode
)
5813 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5815 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5816 highest_pow2_factor (offset
));
5819 #ifdef WORD_REGISTER_OPERATIONS
5820 /* If this initializes a field that is smaller than a
5821 word, at the start of a word, try to widen it to a full
5822 word. This special case allows us to output C++ member
5823 function initializations in a form that the optimizers
5826 && bitsize
< BITS_PER_WORD
5827 && bitpos
% BITS_PER_WORD
== 0
5828 && GET_MODE_CLASS (mode
) == MODE_INT
5829 && TREE_CODE (value
) == INTEGER_CST
5831 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
5833 tree type
= TREE_TYPE (value
);
5835 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
5837 type
= lang_hooks
.types
.type_for_mode
5838 (word_mode
, TYPE_UNSIGNED (type
));
5839 value
= fold_convert (type
, value
);
5842 if (BYTES_BIG_ENDIAN
)
5844 = fold_build2 (LSHIFT_EXPR
, type
, value
,
5845 build_int_cst (type
,
5846 BITS_PER_WORD
- bitsize
));
5847 bitsize
= BITS_PER_WORD
;
5852 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
5853 && DECL_NONADDRESSABLE_P (field
))
5855 to_rtx
= copy_rtx (to_rtx
);
5856 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
5859 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
5860 value
, type
, cleared
,
5861 get_alias_set (TREE_TYPE (field
)));
5868 unsigned HOST_WIDE_INT i
;
5871 tree elttype
= TREE_TYPE (type
);
5873 HOST_WIDE_INT minelt
= 0;
5874 HOST_WIDE_INT maxelt
= 0;
5876 domain
= TYPE_DOMAIN (type
);
5877 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
5878 && TYPE_MAX_VALUE (domain
)
5879 && host_integerp (TYPE_MIN_VALUE (domain
), 0)
5880 && host_integerp (TYPE_MAX_VALUE (domain
), 0));
5882 /* If we have constant bounds for the range of the type, get them. */
5885 minelt
= tree_low_cst (TYPE_MIN_VALUE (domain
), 0);
5886 maxelt
= tree_low_cst (TYPE_MAX_VALUE (domain
), 0);
5889 /* If the constructor has fewer elements than the array, clear
5890 the whole array first. Similarly if this is static
5891 constructor of a non-BLKmode object. */
5894 else if (REG_P (target
) && TREE_STATIC (exp
))
5898 unsigned HOST_WIDE_INT idx
;
5900 HOST_WIDE_INT count
= 0, zero_count
= 0;
5901 need_to_clear
= ! const_bounds_p
;
5903 /* This loop is a more accurate version of the loop in
5904 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5905 is also needed to check for missing elements. */
5906 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
5908 HOST_WIDE_INT this_node_count
;
5913 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
5915 tree lo_index
= TREE_OPERAND (index
, 0);
5916 tree hi_index
= TREE_OPERAND (index
, 1);
5918 if (! host_integerp (lo_index
, 1)
5919 || ! host_integerp (hi_index
, 1))
5925 this_node_count
= (tree_low_cst (hi_index
, 1)
5926 - tree_low_cst (lo_index
, 1) + 1);
5929 this_node_count
= 1;
5931 count
+= this_node_count
;
5932 if (mostly_zeros_p (value
))
5933 zero_count
+= this_node_count
;
5936 /* Clear the entire array first if there are any missing
5937 elements, or if the incidence of zero elements is >=
5940 && (count
< maxelt
- minelt
+ 1
5941 || 4 * zero_count
>= 3 * count
))
5945 if (need_to_clear
&& size
> 0)
5948 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5950 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5954 if (!cleared
&& REG_P (target
))
5955 /* Inform later passes that the old value is dead. */
5956 emit_clobber (target
);
5958 /* Store each element of the constructor into the
5959 corresponding element of TARGET, determined by counting the
5961 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
5963 enum machine_mode mode
;
5964 HOST_WIDE_INT bitsize
;
5965 HOST_WIDE_INT bitpos
;
5966 rtx xtarget
= target
;
5968 if (cleared
&& initializer_zerop (value
))
5971 mode
= TYPE_MODE (elttype
);
5972 if (mode
== BLKmode
)
5973 bitsize
= (host_integerp (TYPE_SIZE (elttype
), 1)
5974 ? tree_low_cst (TYPE_SIZE (elttype
), 1)
5977 bitsize
= GET_MODE_BITSIZE (mode
);
5979 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
5981 tree lo_index
= TREE_OPERAND (index
, 0);
5982 tree hi_index
= TREE_OPERAND (index
, 1);
5983 rtx index_r
, pos_rtx
;
5984 HOST_WIDE_INT lo
, hi
, count
;
5987 /* If the range is constant and "small", unroll the loop. */
5989 && host_integerp (lo_index
, 0)
5990 && host_integerp (hi_index
, 0)
5991 && (lo
= tree_low_cst (lo_index
, 0),
5992 hi
= tree_low_cst (hi_index
, 0),
5993 count
= hi
- lo
+ 1,
5996 || (host_integerp (TYPE_SIZE (elttype
), 1)
5997 && (tree_low_cst (TYPE_SIZE (elttype
), 1) * count
6000 lo
-= minelt
; hi
-= minelt
;
6001 for (; lo
<= hi
; lo
++)
6003 bitpos
= lo
* tree_low_cst (TYPE_SIZE (elttype
), 0);
6006 && !MEM_KEEP_ALIAS_SET_P (target
)
6007 && TREE_CODE (type
) == ARRAY_TYPE
6008 && TYPE_NONALIASED_COMPONENT (type
))
6010 target
= copy_rtx (target
);
6011 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6014 store_constructor_field
6015 (target
, bitsize
, bitpos
, mode
, value
, type
, cleared
,
6016 get_alias_set (elttype
));
6021 rtx loop_start
= gen_label_rtx ();
6022 rtx loop_end
= gen_label_rtx ();
6025 expand_normal (hi_index
);
6027 index
= build_decl (EXPR_LOCATION (exp
),
6028 VAR_DECL
, NULL_TREE
, domain
);
6029 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6030 SET_DECL_RTL (index
, index_r
);
6031 store_expr (lo_index
, index_r
, 0, false);
6033 /* Build the head of the loop. */
6034 do_pending_stack_adjust ();
6035 emit_label (loop_start
);
6037 /* Assign value to element index. */
6039 fold_convert (ssizetype
,
6040 fold_build2 (MINUS_EXPR
,
6043 TYPE_MIN_VALUE (domain
)));
6046 size_binop (MULT_EXPR
, position
,
6047 fold_convert (ssizetype
,
6048 TYPE_SIZE_UNIT (elttype
)));
6050 pos_rtx
= expand_normal (position
);
6051 xtarget
= offset_address (target
, pos_rtx
,
6052 highest_pow2_factor (position
));
6053 xtarget
= adjust_address (xtarget
, mode
, 0);
6054 if (TREE_CODE (value
) == CONSTRUCTOR
)
6055 store_constructor (value
, xtarget
, cleared
,
6056 bitsize
/ BITS_PER_UNIT
);
6058 store_expr (value
, xtarget
, 0, false);
6060 /* Generate a conditional jump to exit the loop. */
6061 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6063 jumpif (exit_cond
, loop_end
, -1);
6065 /* Update the loop counter, and jump to the head of
6067 expand_assignment (index
,
6068 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6069 index
, integer_one_node
),
6072 emit_jump (loop_start
);
6074 /* Build the end of the loop. */
6075 emit_label (loop_end
);
6078 else if ((index
!= 0 && ! host_integerp (index
, 0))
6079 || ! host_integerp (TYPE_SIZE (elttype
), 1))
6084 index
= ssize_int (1);
6087 index
= fold_convert (ssizetype
,
6088 fold_build2 (MINUS_EXPR
,
6091 TYPE_MIN_VALUE (domain
)));
6094 size_binop (MULT_EXPR
, index
,
6095 fold_convert (ssizetype
,
6096 TYPE_SIZE_UNIT (elttype
)));
6097 xtarget
= offset_address (target
,
6098 expand_normal (position
),
6099 highest_pow2_factor (position
));
6100 xtarget
= adjust_address (xtarget
, mode
, 0);
6101 store_expr (value
, xtarget
, 0, false);
6106 bitpos
= ((tree_low_cst (index
, 0) - minelt
)
6107 * tree_low_cst (TYPE_SIZE (elttype
), 1));
6109 bitpos
= (i
* tree_low_cst (TYPE_SIZE (elttype
), 1));
6111 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6112 && TREE_CODE (type
) == ARRAY_TYPE
6113 && TYPE_NONALIASED_COMPONENT (type
))
6115 target
= copy_rtx (target
);
6116 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6118 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6119 type
, cleared
, get_alias_set (elttype
));
6127 unsigned HOST_WIDE_INT idx
;
6128 constructor_elt
*ce
;
6132 tree elttype
= TREE_TYPE (type
);
6133 int elt_size
= tree_low_cst (TYPE_SIZE (elttype
), 1);
6134 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6135 HOST_WIDE_INT bitsize
;
6136 HOST_WIDE_INT bitpos
;
6137 rtvec vector
= NULL
;
6139 alias_set_type alias
;
6141 gcc_assert (eltmode
!= BLKmode
);
6143 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6144 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6146 enum machine_mode mode
= GET_MODE (target
);
6148 icode
= (int) optab_handler (vec_init_optab
, mode
);
6149 if (icode
!= CODE_FOR_nothing
)
6153 vector
= rtvec_alloc (n_elts
);
6154 for (i
= 0; i
< n_elts
; i
++)
6155 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6159 /* If the constructor has fewer elements than the vector,
6160 clear the whole array first. Similarly if this is static
6161 constructor of a non-BLKmode object. */
6164 else if (REG_P (target
) && TREE_STATIC (exp
))
6168 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6171 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6173 int n_elts_here
= tree_low_cst
6174 (int_const_binop (TRUNC_DIV_EXPR
,
6175 TYPE_SIZE (TREE_TYPE (value
)),
6176 TYPE_SIZE (elttype
)), 1);
6178 count
+= n_elts_here
;
6179 if (mostly_zeros_p (value
))
6180 zero_count
+= n_elts_here
;
6183 /* Clear the entire vector first if there are any missing elements,
6184 or if the incidence of zero elements is >= 75%. */
6185 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6188 if (need_to_clear
&& size
> 0 && !vector
)
6191 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6193 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6197 /* Inform later passes that the old value is dead. */
6198 if (!cleared
&& !vector
&& REG_P (target
))
6199 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6202 alias
= MEM_ALIAS_SET (target
);
6204 alias
= get_alias_set (elttype
);
6206 /* Store each element of the constructor into the corresponding
6207 element of TARGET, determined by counting the elements. */
6208 for (idx
= 0, i
= 0;
6209 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
);
6210 idx
++, i
+= bitsize
/ elt_size
)
6212 HOST_WIDE_INT eltpos
;
6213 tree value
= ce
->value
;
6215 bitsize
= tree_low_cst (TYPE_SIZE (TREE_TYPE (value
)), 1);
6216 if (cleared
&& initializer_zerop (value
))
6220 eltpos
= tree_low_cst (ce
->index
, 1);
6226 /* Vector CONSTRUCTORs should only be built from smaller
6227 vectors in the case of BLKmode vectors. */
6228 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6229 RTVEC_ELT (vector
, eltpos
)
6230 = expand_normal (value
);
6234 enum machine_mode value_mode
=
6235 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6236 ? TYPE_MODE (TREE_TYPE (value
))
6238 bitpos
= eltpos
* elt_size
;
6239 store_constructor_field (target
, bitsize
, bitpos
,
6240 value_mode
, value
, type
,
6246 emit_insn (GEN_FCN (icode
)
6248 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6257 /* Store the value of EXP (an expression tree)
6258 into a subfield of TARGET which has mode MODE and occupies
6259 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6260 If MODE is VOIDmode, it means that we are storing into a bit-field.
6262 BITREGION_START is bitpos of the first bitfield in this region.
6263 BITREGION_END is the bitpos of the ending bitfield in this region.
6264 These two fields are 0, if the C++ memory model does not apply,
6265 or we are not interested in keeping track of bitfield regions.
6267 Always return const0_rtx unless we have something particular to
6270 TYPE is the type of the underlying object,
6272 ALIAS_SET is the alias set for the destination. This value will
6273 (in general) be different from that for TARGET, since TARGET is a
6274 reference to the containing structure.
6276 If NONTEMPORAL is true, try generating a nontemporal store. */
6279 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6280 unsigned HOST_WIDE_INT bitregion_start
,
6281 unsigned HOST_WIDE_INT bitregion_end
,
6282 enum machine_mode mode
, tree exp
, tree type
,
6283 alias_set_type alias_set
, bool nontemporal
)
6285 if (TREE_CODE (exp
) == ERROR_MARK
)
6288 /* If we have nothing to store, do nothing unless the expression has
6291 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6293 /* If we are storing into an unaligned field of an aligned union that is
6294 in a register, we may have the mode of TARGET being an integer mode but
6295 MODE == BLKmode. In that case, get an aligned object whose size and
6296 alignment are the same as TARGET and store TARGET into it (we can avoid
6297 the store if the field being stored is the entire width of TARGET). Then
6298 call ourselves recursively to store the field into a BLKmode version of
6299 that object. Finally, load from the object into TARGET. This is not
6300 very efficient in general, but should only be slightly more expensive
6301 than the otherwise-required unaligned accesses. Perhaps this can be
6302 cleaned up later. It's tempting to make OBJECT readonly, but it's set
6303 twice, once with emit_move_insn and once via store_field. */
6306 && (REG_P (target
) || GET_CODE (target
) == SUBREG
))
6308 rtx object
= assign_temp (type
, 0, 1, 1);
6309 rtx blk_object
= adjust_address (object
, BLKmode
, 0);
6311 if (bitsize
!= (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (target
)))
6312 emit_move_insn (object
, target
);
6314 store_field (blk_object
, bitsize
, bitpos
,
6315 bitregion_start
, bitregion_end
,
6316 mode
, exp
, type
, MEM_ALIAS_SET (blk_object
), nontemporal
);
6318 emit_move_insn (target
, object
);
6320 /* We want to return the BLKmode version of the data. */
6324 if (GET_CODE (target
) == CONCAT
)
6326 /* We're storing into a struct containing a single __complex. */
6328 gcc_assert (!bitpos
);
6329 return store_expr (exp
, target
, 0, nontemporal
);
6332 /* If the structure is in a register or if the component
6333 is a bit field, we cannot use addressing to access it.
6334 Use bit-field techniques or SUBREG to store in it. */
6336 if (mode
== VOIDmode
6337 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6338 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6339 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6341 || GET_CODE (target
) == SUBREG
6342 /* If the field isn't aligned enough to store as an ordinary memref,
6343 store it as a bit field. */
6345 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6346 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6347 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6348 || (bitpos
% BITS_PER_UNIT
!= 0)))
6349 || (bitsize
>= 0 && mode
!= BLKmode
6350 && GET_MODE_BITSIZE (mode
) > bitsize
)
6351 /* If the RHS and field are a constant size and the size of the
6352 RHS isn't the same size as the bitfield, we must use bitfield
6355 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6356 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6357 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6358 decl we must use bitfield operations. */
6360 && TREE_CODE (exp
) == MEM_REF
6361 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6362 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6363 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6364 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6369 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6370 implies a mask operation. If the precision is the same size as
6371 the field we're storing into, that mask is redundant. This is
6372 particularly common with bit field assignments generated by the
6374 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6377 tree type
= TREE_TYPE (exp
);
6378 if (INTEGRAL_TYPE_P (type
)
6379 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6380 && bitsize
== TYPE_PRECISION (type
))
6382 tree op
= gimple_assign_rhs1 (nop_def
);
6383 type
= TREE_TYPE (op
);
6384 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6389 temp
= expand_normal (exp
);
6391 /* If BITSIZE is narrower than the size of the type of EXP
6392 we will be narrowing TEMP. Normally, what's wanted are the
6393 low-order bits. However, if EXP's type is a record and this is
6394 big-endian machine, we want the upper BITSIZE bits. */
6395 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6396 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6397 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6398 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6399 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6402 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6403 if (mode
!= VOIDmode
&& mode
!= BLKmode
6404 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6405 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6407 /* If the modes of TEMP and TARGET are both BLKmode, both
6408 must be in memory and BITPOS must be aligned on a byte
6409 boundary. If so, we simply do a block copy. Likewise
6410 for a BLKmode-like TARGET. */
6411 if (GET_MODE (temp
) == BLKmode
6412 && (GET_MODE (target
) == BLKmode
6414 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6415 && (bitpos
% BITS_PER_UNIT
) == 0
6416 && (bitsize
% BITS_PER_UNIT
) == 0)))
6418 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6419 && (bitpos
% BITS_PER_UNIT
) == 0);
6421 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6422 emit_block_move (target
, temp
,
6423 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6430 /* Store the value in the bitfield. */
6431 store_bit_field (target
, bitsize
, bitpos
,
6432 bitregion_start
, bitregion_end
,
6439 /* Now build a reference to just the desired component. */
6440 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6442 if (to_rtx
== target
)
6443 to_rtx
= copy_rtx (to_rtx
);
6445 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6446 set_mem_alias_set (to_rtx
, alias_set
);
6448 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6452 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6453 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6454 codes and find the ultimate containing object, which we return.
6456 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6457 bit position, and *PUNSIGNEDP to the signedness of the field.
6458 If the position of the field is variable, we store a tree
6459 giving the variable offset (in units) in *POFFSET.
6460 This offset is in addition to the bit position.
6461 If the position is not variable, we store 0 in *POFFSET.
6463 If any of the extraction expressions is volatile,
6464 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6466 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6467 Otherwise, it is a mode that can be used to access the field.
6469 If the field describes a variable-sized object, *PMODE is set to
6470 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6471 this case, but the address of the object can be found.
6473 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6474 look through nodes that serve as markers of a greater alignment than
6475 the one that can be deduced from the expression. These nodes make it
6476 possible for front-ends to prevent temporaries from being created by
6477 the middle-end on alignment considerations. For that purpose, the
6478 normal operating mode at high-level is to always pass FALSE so that
6479 the ultimate containing object is really returned; moreover, the
6480 associated predicate handled_component_p will always return TRUE
6481 on these nodes, thus indicating that they are essentially handled
6482 by get_inner_reference. TRUE should only be passed when the caller
6483 is scanning the expression in order to build another representation
6484 and specifically knows how to handle these nodes; as such, this is
6485 the normal operating mode in the RTL expanders. */
6488 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6489 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6490 enum machine_mode
*pmode
, int *punsignedp
,
6491 int *pvolatilep
, bool keep_aligning
)
6494 enum machine_mode mode
= VOIDmode
;
6495 bool blkmode_bitfield
= false;
6496 tree offset
= size_zero_node
;
6497 double_int bit_offset
= double_int_zero
;
6499 /* First get the mode, signedness, and size. We do this from just the
6500 outermost expression. */
6502 if (TREE_CODE (exp
) == COMPONENT_REF
)
6504 tree field
= TREE_OPERAND (exp
, 1);
6505 size_tree
= DECL_SIZE (field
);
6506 if (!DECL_BIT_FIELD (field
))
6507 mode
= DECL_MODE (field
);
6508 else if (DECL_MODE (field
) == BLKmode
)
6509 blkmode_bitfield
= true;
6510 else if (TREE_THIS_VOLATILE (exp
)
6511 && flag_strict_volatile_bitfields
> 0)
6512 /* Volatile bitfields should be accessed in the mode of the
6513 field's type, not the mode computed based on the bit
6515 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6517 *punsignedp
= DECL_UNSIGNED (field
);
6519 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6521 size_tree
= TREE_OPERAND (exp
, 1);
6522 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6523 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6525 /* For vector types, with the correct size of access, use the mode of
6527 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6528 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6529 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6530 mode
= TYPE_MODE (TREE_TYPE (exp
));
6534 mode
= TYPE_MODE (TREE_TYPE (exp
));
6535 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6537 if (mode
== BLKmode
)
6538 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6540 *pbitsize
= GET_MODE_BITSIZE (mode
);
6545 if (! host_integerp (size_tree
, 1))
6546 mode
= BLKmode
, *pbitsize
= -1;
6548 *pbitsize
= tree_low_cst (size_tree
, 1);
6551 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6552 and find the ultimate containing object. */
6555 switch (TREE_CODE (exp
))
6559 = double_int_add (bit_offset
,
6560 tree_to_double_int (TREE_OPERAND (exp
, 2)));
6565 tree field
= TREE_OPERAND (exp
, 1);
6566 tree this_offset
= component_ref_field_offset (exp
);
6568 /* If this field hasn't been filled in yet, don't go past it.
6569 This should only happen when folding expressions made during
6570 type construction. */
6571 if (this_offset
== 0)
6574 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6575 bit_offset
= double_int_add (bit_offset
,
6577 (DECL_FIELD_BIT_OFFSET (field
)));
6579 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6584 case ARRAY_RANGE_REF
:
6586 tree index
= TREE_OPERAND (exp
, 1);
6587 tree low_bound
= array_ref_low_bound (exp
);
6588 tree unit_size
= array_ref_element_size (exp
);
6590 /* We assume all arrays have sizes that are a multiple of a byte.
6591 First subtract the lower bound, if any, in the type of the
6592 index, then convert to sizetype and multiply by the size of
6593 the array element. */
6594 if (! integer_zerop (low_bound
))
6595 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6598 offset
= size_binop (PLUS_EXPR
, offset
,
6599 size_binop (MULT_EXPR
,
6600 fold_convert (sizetype
, index
),
6609 bit_offset
= double_int_add (bit_offset
,
6610 uhwi_to_double_int (*pbitsize
));
6613 case VIEW_CONVERT_EXPR
:
6614 if (keep_aligning
&& STRICT_ALIGNMENT
6615 && (TYPE_ALIGN (TREE_TYPE (exp
))
6616 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6617 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6618 < BIGGEST_ALIGNMENT
)
6619 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6620 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6625 /* Hand back the decl for MEM[&decl, off]. */
6626 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6628 tree off
= TREE_OPERAND (exp
, 1);
6629 if (!integer_zerop (off
))
6631 double_int boff
, coff
= mem_ref_offset (exp
);
6632 boff
= double_int_lshift (coff
,
6634 ? 3 : exact_log2 (BITS_PER_UNIT
),
6635 HOST_BITS_PER_DOUBLE_INT
, true);
6636 bit_offset
= double_int_add (bit_offset
, boff
);
6638 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6646 /* If any reference in the chain is volatile, the effect is volatile. */
6647 if (TREE_THIS_VOLATILE (exp
))
6650 exp
= TREE_OPERAND (exp
, 0);
6654 /* If OFFSET is constant, see if we can return the whole thing as a
6655 constant bit position. Make sure to handle overflow during
6657 if (TREE_CODE (offset
) == INTEGER_CST
)
6659 double_int tem
= tree_to_double_int (offset
);
6660 tem
= double_int_sext (tem
, TYPE_PRECISION (sizetype
));
6661 tem
= double_int_lshift (tem
,
6663 ? 3 : exact_log2 (BITS_PER_UNIT
),
6664 HOST_BITS_PER_DOUBLE_INT
, true);
6665 tem
= double_int_add (tem
, bit_offset
);
6666 if (double_int_fits_in_shwi_p (tem
))
6668 *pbitpos
= double_int_to_shwi (tem
);
6669 *poffset
= offset
= NULL_TREE
;
6673 /* Otherwise, split it up. */
6676 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6677 if (double_int_negative_p (bit_offset
))
6680 = double_int_mask (BITS_PER_UNIT
== 8
6681 ? 3 : exact_log2 (BITS_PER_UNIT
));
6682 double_int tem
= double_int_and_not (bit_offset
, mask
);
6683 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6684 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6685 bit_offset
= double_int_sub (bit_offset
, tem
);
6686 tem
= double_int_rshift (tem
,
6688 ? 3 : exact_log2 (BITS_PER_UNIT
),
6689 HOST_BITS_PER_DOUBLE_INT
, true);
6690 offset
= size_binop (PLUS_EXPR
, offset
,
6691 double_int_to_tree (sizetype
, tem
));
6694 *pbitpos
= double_int_to_shwi (bit_offset
);
6698 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6699 if (mode
== VOIDmode
6701 && (*pbitpos
% BITS_PER_UNIT
) == 0
6702 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6710 /* Given an expression EXP that may be a COMPONENT_REF, an ARRAY_REF or an
6711 ARRAY_RANGE_REF, look for whether EXP or any nested component-refs within
6712 EXP is marked as PACKED. */
6715 contains_packed_reference (const_tree exp
)
6717 bool packed_p
= false;
6721 switch (TREE_CODE (exp
))
6725 tree field
= TREE_OPERAND (exp
, 1);
6726 packed_p
= DECL_PACKED (field
)
6727 || TYPE_PACKED (TREE_TYPE (field
))
6728 || TYPE_PACKED (TREE_TYPE (exp
));
6736 case ARRAY_RANGE_REF
:
6739 case VIEW_CONVERT_EXPR
:
6745 exp
= TREE_OPERAND (exp
, 0);
6751 /* Return a tree of sizetype representing the size, in bytes, of the element
6752 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6755 array_ref_element_size (tree exp
)
6757 tree aligned_size
= TREE_OPERAND (exp
, 3);
6758 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6759 location_t loc
= EXPR_LOCATION (exp
);
6761 /* If a size was specified in the ARRAY_REF, it's the size measured
6762 in alignment units of the element type. So multiply by that value. */
6765 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6766 sizetype from another type of the same width and signedness. */
6767 if (TREE_TYPE (aligned_size
) != sizetype
)
6768 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6769 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6770 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6773 /* Otherwise, take the size from that of the element type. Substitute
6774 any PLACEHOLDER_EXPR that we have. */
6776 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6779 /* Return a tree representing the lower bound of the array mentioned in
6780 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6783 array_ref_low_bound (tree exp
)
6785 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6787 /* If a lower bound is specified in EXP, use it. */
6788 if (TREE_OPERAND (exp
, 2))
6789 return TREE_OPERAND (exp
, 2);
6791 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6792 substituting for a PLACEHOLDER_EXPR as needed. */
6793 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6794 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6796 /* Otherwise, return a zero of the appropriate type. */
6797 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6800 /* Returns true if REF is an array reference to an array at the end of
6801 a structure. If this is the case, the array may be allocated larger
6802 than its upper bound implies. */
6805 array_at_struct_end_p (tree ref
)
6807 if (TREE_CODE (ref
) != ARRAY_REF
6808 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6811 while (handled_component_p (ref
))
6813 /* If the reference chain contains a component reference to a
6814 non-union type and there follows another field the reference
6815 is not at the end of a structure. */
6816 if (TREE_CODE (ref
) == COMPONENT_REF
6817 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6819 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6820 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6821 nextf
= DECL_CHAIN (nextf
);
6826 ref
= TREE_OPERAND (ref
, 0);
6829 /* If the reference is based on a declared entity, the size of the array
6830 is constrained by its given domain. */
6837 /* Return a tree representing the upper bound of the array mentioned in
6838 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6841 array_ref_up_bound (tree exp
)
6843 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6845 /* If there is a domain type and it has an upper bound, use it, substituting
6846 for a PLACEHOLDER_EXPR as needed. */
6847 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6848 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6850 /* Otherwise fail. */
6854 /* Return a tree representing the offset, in bytes, of the field referenced
6855 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6858 component_ref_field_offset (tree exp
)
6860 tree aligned_offset
= TREE_OPERAND (exp
, 2);
6861 tree field
= TREE_OPERAND (exp
, 1);
6862 location_t loc
= EXPR_LOCATION (exp
);
6864 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6865 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6869 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6870 sizetype from another type of the same width and signedness. */
6871 if (TREE_TYPE (aligned_offset
) != sizetype
)
6872 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
6873 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
6874 size_int (DECL_OFFSET_ALIGN (field
)
6878 /* Otherwise, take the offset from that of the field. Substitute
6879 any PLACEHOLDER_EXPR that we have. */
6881 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
6884 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6886 static unsigned HOST_WIDE_INT
6887 target_align (const_tree target
)
6889 /* We might have a chain of nested references with intermediate misaligning
6890 bitfields components, so need to recurse to find out. */
6892 unsigned HOST_WIDE_INT this_align
, outer_align
;
6894 switch (TREE_CODE (target
))
6900 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
6901 outer_align
= target_align (TREE_OPERAND (target
, 0));
6902 return MIN (this_align
, outer_align
);
6905 case ARRAY_RANGE_REF
:
6906 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6907 outer_align
= target_align (TREE_OPERAND (target
, 0));
6908 return MIN (this_align
, outer_align
);
6911 case NON_LVALUE_EXPR
:
6912 case VIEW_CONVERT_EXPR
:
6913 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6914 outer_align
= target_align (TREE_OPERAND (target
, 0));
6915 return MAX (this_align
, outer_align
);
6918 return TYPE_ALIGN (TREE_TYPE (target
));
6923 /* Given an rtx VALUE that may contain additions and multiplications, return
6924 an equivalent value that just refers to a register, memory, or constant.
6925 This is done by generating instructions to perform the arithmetic and
6926 returning a pseudo-register containing the value.
6928 The returned value may be a REG, SUBREG, MEM or constant. */
6931 force_operand (rtx value
, rtx target
)
6934 /* Use subtarget as the target for operand 0 of a binary operation. */
6935 rtx subtarget
= get_subtarget (target
);
6936 enum rtx_code code
= GET_CODE (value
);
6938 /* Check for subreg applied to an expression produced by loop optimizer. */
6940 && !REG_P (SUBREG_REG (value
))
6941 && !MEM_P (SUBREG_REG (value
)))
6944 = simplify_gen_subreg (GET_MODE (value
),
6945 force_reg (GET_MODE (SUBREG_REG (value
)),
6946 force_operand (SUBREG_REG (value
),
6948 GET_MODE (SUBREG_REG (value
)),
6949 SUBREG_BYTE (value
));
6950 code
= GET_CODE (value
);
6953 /* Check for a PIC address load. */
6954 if ((code
== PLUS
|| code
== MINUS
)
6955 && XEXP (value
, 0) == pic_offset_table_rtx
6956 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
6957 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
6958 || GET_CODE (XEXP (value
, 1)) == CONST
))
6961 subtarget
= gen_reg_rtx (GET_MODE (value
));
6962 emit_move_insn (subtarget
, value
);
6966 if (ARITHMETIC_P (value
))
6968 op2
= XEXP (value
, 1);
6969 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
6971 if (code
== MINUS
&& CONST_INT_P (op2
))
6974 op2
= negate_rtx (GET_MODE (value
), op2
);
6977 /* Check for an addition with OP2 a constant integer and our first
6978 operand a PLUS of a virtual register and something else. In that
6979 case, we want to emit the sum of the virtual register and the
6980 constant first and then add the other value. This allows virtual
6981 register instantiation to simply modify the constant rather than
6982 creating another one around this addition. */
6983 if (code
== PLUS
&& CONST_INT_P (op2
)
6984 && GET_CODE (XEXP (value
, 0)) == PLUS
6985 && REG_P (XEXP (XEXP (value
, 0), 0))
6986 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
6987 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
6989 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
6990 XEXP (XEXP (value
, 0), 0), op2
,
6991 subtarget
, 0, OPTAB_LIB_WIDEN
);
6992 return expand_simple_binop (GET_MODE (value
), code
, temp
,
6993 force_operand (XEXP (XEXP (value
,
6995 target
, 0, OPTAB_LIB_WIDEN
);
6998 op1
= force_operand (XEXP (value
, 0), subtarget
);
6999 op2
= force_operand (op2
, NULL_RTX
);
7003 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7005 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7006 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7007 target
, 1, OPTAB_LIB_WIDEN
);
7009 return expand_divmod (0,
7010 FLOAT_MODE_P (GET_MODE (value
))
7011 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7012 GET_MODE (value
), op1
, op2
, target
, 0);
7014 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7017 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7020 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7023 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7024 target
, 0, OPTAB_LIB_WIDEN
);
7026 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7027 target
, 1, OPTAB_LIB_WIDEN
);
7030 if (UNARY_P (value
))
7033 target
= gen_reg_rtx (GET_MODE (value
));
7034 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7041 case FLOAT_TRUNCATE
:
7042 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7047 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7051 case UNSIGNED_FLOAT
:
7052 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7056 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7060 #ifdef INSN_SCHEDULING
7061 /* On machines that have insn scheduling, we want all memory reference to be
7062 explicit, so we need to deal with such paradoxical SUBREGs. */
7063 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7065 = simplify_gen_subreg (GET_MODE (value
),
7066 force_reg (GET_MODE (SUBREG_REG (value
)),
7067 force_operand (SUBREG_REG (value
),
7069 GET_MODE (SUBREG_REG (value
)),
7070 SUBREG_BYTE (value
));
7076 /* Subroutine of expand_expr: return nonzero iff there is no way that
7077 EXP can reference X, which is being modified. TOP_P is nonzero if this
7078 call is going to be used to determine whether we need a temporary
7079 for EXP, as opposed to a recursive call to this function.
7081 It is always safe for this routine to return zero since it merely
7082 searches for optimization opportunities. */
7085 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7091 /* If EXP has varying size, we MUST use a target since we currently
7092 have no way of allocating temporaries of variable size
7093 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7094 So we assume here that something at a higher level has prevented a
7095 clash. This is somewhat bogus, but the best we can do. Only
7096 do this when X is BLKmode and when we are at the top level. */
7097 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7098 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7099 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7100 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7101 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7103 && GET_MODE (x
) == BLKmode
)
7104 /* If X is in the outgoing argument area, it is always safe. */
7106 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7107 || (GET_CODE (XEXP (x
, 0)) == PLUS
7108 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7111 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7112 find the underlying pseudo. */
7113 if (GET_CODE (x
) == SUBREG
)
7116 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7120 /* Now look at our tree code and possibly recurse. */
7121 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7123 case tcc_declaration
:
7124 exp_rtl
= DECL_RTL_IF_SET (exp
);
7130 case tcc_exceptional
:
7131 if (TREE_CODE (exp
) == TREE_LIST
)
7135 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7137 exp
= TREE_CHAIN (exp
);
7140 if (TREE_CODE (exp
) != TREE_LIST
)
7141 return safe_from_p (x
, exp
, 0);
7144 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7146 constructor_elt
*ce
;
7147 unsigned HOST_WIDE_INT idx
;
7149 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7150 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7151 || !safe_from_p (x
, ce
->value
, 0))
7155 else if (TREE_CODE (exp
) == ERROR_MARK
)
7156 return 1; /* An already-visited SAVE_EXPR? */
7161 /* The only case we look at here is the DECL_INITIAL inside a
7163 return (TREE_CODE (exp
) != DECL_EXPR
7164 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7165 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7166 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7169 case tcc_comparison
:
7170 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7175 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7177 case tcc_expression
:
7180 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7181 the expression. If it is set, we conflict iff we are that rtx or
7182 both are in memory. Otherwise, we check all operands of the
7183 expression recursively. */
7185 switch (TREE_CODE (exp
))
7188 /* If the operand is static or we are static, we can't conflict.
7189 Likewise if we don't conflict with the operand at all. */
7190 if (staticp (TREE_OPERAND (exp
, 0))
7191 || TREE_STATIC (exp
)
7192 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7195 /* Otherwise, the only way this can conflict is if we are taking
7196 the address of a DECL a that address if part of X, which is
7198 exp
= TREE_OPERAND (exp
, 0);
7201 if (!DECL_RTL_SET_P (exp
)
7202 || !MEM_P (DECL_RTL (exp
)))
7205 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7211 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7212 get_alias_set (exp
)))
7217 /* Assume that the call will clobber all hard registers and
7219 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7224 case WITH_CLEANUP_EXPR
:
7225 case CLEANUP_POINT_EXPR
:
7226 /* Lowered by gimplify.c. */
7230 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7236 /* If we have an rtx, we do not need to scan our operands. */
7240 nops
= TREE_OPERAND_LENGTH (exp
);
7241 for (i
= 0; i
< nops
; i
++)
7242 if (TREE_OPERAND (exp
, i
) != 0
7243 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7249 /* Should never get a type here. */
7253 /* If we have an rtl, find any enclosed object. Then see if we conflict
7257 if (GET_CODE (exp_rtl
) == SUBREG
)
7259 exp_rtl
= SUBREG_REG (exp_rtl
);
7261 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7265 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7266 are memory and they conflict. */
7267 return ! (rtx_equal_p (x
, exp_rtl
)
7268 || (MEM_P (x
) && MEM_P (exp_rtl
)
7269 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7272 /* If we reach here, it is safe. */
7277 /* Return the highest power of two that EXP is known to be a multiple of.
7278 This is used in updating alignment of MEMs in array references. */
7280 unsigned HOST_WIDE_INT
7281 highest_pow2_factor (const_tree exp
)
7283 unsigned HOST_WIDE_INT c0
, c1
;
7285 switch (TREE_CODE (exp
))
7288 /* We can find the lowest bit that's a one. If the low
7289 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
7290 We need to handle this case since we can find it in a COND_EXPR,
7291 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
7292 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
7294 if (TREE_OVERFLOW (exp
))
7295 return BIGGEST_ALIGNMENT
;
7298 /* Note: tree_low_cst is intentionally not used here,
7299 we don't care about the upper bits. */
7300 c0
= TREE_INT_CST_LOW (exp
);
7302 return c0
? c0
: BIGGEST_ALIGNMENT
;
7306 case PLUS_EXPR
: case MINUS_EXPR
: case MIN_EXPR
: case MAX_EXPR
:
7307 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7308 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7309 return MIN (c0
, c1
);
7312 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7313 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7316 case ROUND_DIV_EXPR
: case TRUNC_DIV_EXPR
: case FLOOR_DIV_EXPR
:
7318 if (integer_pow2p (TREE_OPERAND (exp
, 1))
7319 && host_integerp (TREE_OPERAND (exp
, 1), 1))
7321 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7322 c1
= tree_low_cst (TREE_OPERAND (exp
, 1), 1);
7323 return MAX (1, c0
/ c1
);
7328 /* The highest power of two of a bit-and expression is the maximum of
7329 that of its operands. We typically get here for a complex LHS and
7330 a constant negative power of two on the RHS to force an explicit
7331 alignment, so don't bother looking at the LHS. */
7332 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7336 return highest_pow2_factor (TREE_OPERAND (exp
, 0));
7339 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7342 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7343 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 2));
7344 return MIN (c0
, c1
);
7353 /* Similar, except that the alignment requirements of TARGET are
7354 taken into account. Assume it is at least as aligned as its
7355 type, unless it is a COMPONENT_REF in which case the layout of
7356 the structure gives the alignment. */
7358 static unsigned HOST_WIDE_INT
7359 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7361 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7362 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7364 return MAX (factor
, talign
);
7367 /* Convert the tree comparision code TCODE to the rtl one where the
7368 signedness is UNSIGNEDP. */
7370 static enum rtx_code
7371 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7383 code
= unsignedp
? LTU
: LT
;
7386 code
= unsignedp
? LEU
: LE
;
7389 code
= unsignedp
? GTU
: GT
;
7392 code
= unsignedp
? GEU
: GE
;
7394 case UNORDERED_EXPR
:
7425 /* Subroutine of expand_expr. Expand the two operands of a binary
7426 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7427 The value may be stored in TARGET if TARGET is nonzero. The
7428 MODIFIER argument is as documented by expand_expr. */
7431 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7432 enum expand_modifier modifier
)
7434 if (! safe_from_p (target
, exp1
, 1))
7436 if (operand_equal_p (exp0
, exp1
, 0))
7438 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7439 *op1
= copy_rtx (*op0
);
7443 /* If we need to preserve evaluation order, copy exp0 into its own
7444 temporary variable so that it can't be clobbered by exp1. */
7445 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7446 exp0
= save_expr (exp0
);
7447 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7448 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7453 /* Return a MEM that contains constant EXP. DEFER is as for
7454 output_constant_def and MODIFIER is as for expand_expr. */
7457 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7461 mem
= output_constant_def (exp
, defer
);
7462 if (modifier
!= EXPAND_INITIALIZER
)
7463 mem
= use_anchored_address (mem
);
7467 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7468 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7471 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7472 enum expand_modifier modifier
, addr_space_t as
)
7474 rtx result
, subtarget
;
7476 HOST_WIDE_INT bitsize
, bitpos
;
7477 int volatilep
, unsignedp
;
7478 enum machine_mode mode1
;
7480 /* If we are taking the address of a constant and are at the top level,
7481 we have to use output_constant_def since we can't call force_const_mem
7483 /* ??? This should be considered a front-end bug. We should not be
7484 generating ADDR_EXPR of something that isn't an LVALUE. The only
7485 exception here is STRING_CST. */
7486 if (CONSTANT_CLASS_P (exp
))
7488 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7489 if (modifier
< EXPAND_SUM
)
7490 result
= force_operand (result
, target
);
7494 /* Everything must be something allowed by is_gimple_addressable. */
7495 switch (TREE_CODE (exp
))
7498 /* This case will happen via recursion for &a->b. */
7499 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7503 tree tem
= TREE_OPERAND (exp
, 0);
7504 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7505 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7506 return expand_expr (tem
, target
, tmode
, modifier
);
7510 /* Expand the initializer like constants above. */
7511 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7513 if (modifier
< EXPAND_SUM
)
7514 result
= force_operand (result
, target
);
7518 /* The real part of the complex number is always first, therefore
7519 the address is the same as the address of the parent object. */
7522 inner
= TREE_OPERAND (exp
, 0);
7526 /* The imaginary part of the complex number is always second.
7527 The expression is therefore always offset by the size of the
7530 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7531 inner
= TREE_OPERAND (exp
, 0);
7535 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7536 expand_expr, as that can have various side effects; LABEL_DECLs for
7537 example, may not have their DECL_RTL set yet. Expand the rtl of
7538 CONSTRUCTORs too, which should yield a memory reference for the
7539 constructor's contents. Assume language specific tree nodes can
7540 be expanded in some interesting way. */
7541 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7543 || TREE_CODE (exp
) == CONSTRUCTOR
7544 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7546 result
= expand_expr (exp
, target
, tmode
,
7547 modifier
== EXPAND_INITIALIZER
7548 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7550 /* If the DECL isn't in memory, then the DECL wasn't properly
7551 marked TREE_ADDRESSABLE, which will be either a front-end
7552 or a tree optimizer bug. */
7554 if (TREE_ADDRESSABLE (exp
)
7556 && ! targetm
.calls
.allocate_stack_slots_for_args())
7558 error ("local frame unavailable (naked function?)");
7562 gcc_assert (MEM_P (result
));
7563 result
= XEXP (result
, 0);
7565 /* ??? Is this needed anymore? */
7567 TREE_USED (exp
) = 1;
7569 if (modifier
!= EXPAND_INITIALIZER
7570 && modifier
!= EXPAND_CONST_ADDRESS
7571 && modifier
!= EXPAND_SUM
)
7572 result
= force_operand (result
, target
);
7576 /* Pass FALSE as the last argument to get_inner_reference although
7577 we are expanding to RTL. The rationale is that we know how to
7578 handle "aligning nodes" here: we can just bypass them because
7579 they won't change the final object whose address will be returned
7580 (they actually exist only for that purpose). */
7581 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7582 &mode1
, &unsignedp
, &volatilep
, false);
7586 /* We must have made progress. */
7587 gcc_assert (inner
!= exp
);
7589 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7590 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7591 inner alignment, force the inner to be sufficiently aligned. */
7592 if (CONSTANT_CLASS_P (inner
)
7593 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7595 inner
= copy_node (inner
);
7596 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7597 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7598 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7600 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7606 if (modifier
!= EXPAND_NORMAL
)
7607 result
= force_operand (result
, NULL
);
7608 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7609 modifier
== EXPAND_INITIALIZER
7610 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7612 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7613 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7615 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7616 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7619 subtarget
= bitpos
? NULL_RTX
: target
;
7620 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7621 1, OPTAB_LIB_WIDEN
);
7627 /* Someone beforehand should have rejected taking the address
7628 of such an object. */
7629 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7631 result
= plus_constant (result
, bitpos
/ BITS_PER_UNIT
);
7632 if (modifier
< EXPAND_SUM
)
7633 result
= force_operand (result
, target
);
7639 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7640 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7643 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7644 enum expand_modifier modifier
)
7646 addr_space_t as
= ADDR_SPACE_GENERIC
;
7647 enum machine_mode address_mode
= Pmode
;
7648 enum machine_mode pointer_mode
= ptr_mode
;
7649 enum machine_mode rmode
;
7652 /* Target mode of VOIDmode says "whatever's natural". */
7653 if (tmode
== VOIDmode
)
7654 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7656 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7658 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7659 address_mode
= targetm
.addr_space
.address_mode (as
);
7660 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7663 /* We can get called with some Weird Things if the user does silliness
7664 like "(short) &a". In that case, convert_memory_address won't do
7665 the right thing, so ignore the given target mode. */
7666 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7667 tmode
= address_mode
;
7669 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7670 tmode
, modifier
, as
);
7672 /* Despite expand_expr claims concerning ignoring TMODE when not
7673 strictly convenient, stuff breaks if we don't honor it. Note
7674 that combined with the above, we only do this for pointer modes. */
7675 rmode
= GET_MODE (result
);
7676 if (rmode
== VOIDmode
)
7679 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7684 /* Generate code for computing CONSTRUCTOR EXP.
7685 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7686 is TRUE, instead of creating a temporary variable in memory
7687 NULL is returned and the caller needs to handle it differently. */
7690 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7691 bool avoid_temp_mem
)
7693 tree type
= TREE_TYPE (exp
);
7694 enum machine_mode mode
= TYPE_MODE (type
);
7696 /* Try to avoid creating a temporary at all. This is possible
7697 if all of the initializer is zero.
7698 FIXME: try to handle all [0..255] initializers we can handle
7700 if (TREE_STATIC (exp
)
7701 && !TREE_ADDRESSABLE (exp
)
7702 && target
!= 0 && mode
== BLKmode
7703 && all_zeros_p (exp
))
7705 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7709 /* All elts simple constants => refer to a constant in memory. But
7710 if this is a non-BLKmode mode, let it store a field at a time
7711 since that should make a CONST_INT or CONST_DOUBLE when we
7712 fold. Likewise, if we have a target we can use, it is best to
7713 store directly into the target unless the type is large enough
7714 that memcpy will be used. If we are making an initializer and
7715 all operands are constant, put it in memory as well.
7717 FIXME: Avoid trying to fill vector constructors piece-meal.
7718 Output them with output_constant_def below unless we're sure
7719 they're zeros. This should go away when vector initializers
7720 are treated like VECTOR_CST instead of arrays. */
7721 if ((TREE_STATIC (exp
)
7722 && ((mode
== BLKmode
7723 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7724 || TREE_ADDRESSABLE (exp
)
7725 || (host_integerp (TYPE_SIZE_UNIT (type
), 1)
7726 && (! MOVE_BY_PIECES_P
7727 (tree_low_cst (TYPE_SIZE_UNIT (type
), 1),
7729 && ! mostly_zeros_p (exp
))))
7730 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7731 && TREE_CONSTANT (exp
)))
7738 constructor
= expand_expr_constant (exp
, 1, modifier
);
7740 if (modifier
!= EXPAND_CONST_ADDRESS
7741 && modifier
!= EXPAND_INITIALIZER
7742 && modifier
!= EXPAND_SUM
)
7743 constructor
= validize_mem (constructor
);
7748 /* Handle calls that pass values in multiple non-contiguous
7749 locations. The Irix 6 ABI has examples of this. */
7750 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7751 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7757 = assign_temp (build_qualified_type (type
, (TYPE_QUALS (type
)
7758 | (TREE_READONLY (exp
)
7759 * TYPE_QUAL_CONST
))),
7760 0, TREE_ADDRESSABLE (exp
), 1);
7763 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7768 /* expand_expr: generate code for computing expression EXP.
7769 An rtx for the computed value is returned. The value is never null.
7770 In the case of a void EXP, const0_rtx is returned.
7772 The value may be stored in TARGET if TARGET is nonzero.
7773 TARGET is just a suggestion; callers must assume that
7774 the rtx returned may not be the same as TARGET.
7776 If TARGET is CONST0_RTX, it means that the value will be ignored.
7778 If TMODE is not VOIDmode, it suggests generating the
7779 result in mode TMODE. But this is done only when convenient.
7780 Otherwise, TMODE is ignored and the value generated in its natural mode.
7781 TMODE is just a suggestion; callers must assume that
7782 the rtx returned may not have mode TMODE.
7784 Note that TARGET may have neither TMODE nor MODE. In that case, it
7785 probably will not be used.
7787 If MODIFIER is EXPAND_SUM then when EXP is an addition
7788 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7789 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7790 products as above, or REG or MEM, or constant.
7791 Ordinarily in such cases we would output mul or add instructions
7792 and then return a pseudo reg containing the sum.
7794 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7795 it also marks a label as absolutely required (it can't be dead).
7796 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7797 This is used for outputting expressions used in initializers.
7799 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7800 with a constant address even if that address is not normally legitimate.
7801 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7803 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7804 a call parameter. Such targets require special care as we haven't yet
7805 marked TARGET so that it's safe from being trashed by libcalls. We
7806 don't want to use TARGET for anything but the final result;
7807 Intermediate values must go elsewhere. Additionally, calls to
7808 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7810 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7811 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7812 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7813 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7817 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7818 enum expand_modifier modifier
, rtx
*alt_rtl
)
7822 /* Handle ERROR_MARK before anybody tries to access its type. */
7823 if (TREE_CODE (exp
) == ERROR_MARK
7824 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7826 ret
= CONST0_RTX (tmode
);
7827 return ret
? ret
: const0_rtx
;
7830 /* If this is an expression of some kind and it has an associated line
7831 number, then emit the line number before expanding the expression.
7833 We need to save and restore the file and line information so that
7834 errors discovered during expansion are emitted with the right
7835 information. It would be better of the diagnostic routines
7836 used the file/line information embedded in the tree nodes rather
7838 if (cfun
&& EXPR_HAS_LOCATION (exp
))
7840 location_t saved_location
= input_location
;
7841 location_t saved_curr_loc
= get_curr_insn_source_location ();
7842 tree saved_block
= get_curr_insn_block ();
7843 input_location
= EXPR_LOCATION (exp
);
7844 set_curr_insn_source_location (input_location
);
7846 /* Record where the insns produced belong. */
7847 set_curr_insn_block (TREE_BLOCK (exp
));
7849 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7851 input_location
= saved_location
;
7852 set_curr_insn_block (saved_block
);
7853 set_curr_insn_source_location (saved_curr_loc
);
7857 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7863 /* Try to expand the conditional expression which is represented by
7864 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7865 return the rtl reg which repsents the result. Otherwise return
7869 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7870 tree treeop1 ATTRIBUTE_UNUSED
,
7871 tree treeop2 ATTRIBUTE_UNUSED
)
7873 #ifdef HAVE_conditional_move
7875 rtx op00
, op01
, op1
, op2
;
7876 enum rtx_code comparison_code
;
7877 enum machine_mode comparison_mode
;
7880 tree type
= TREE_TYPE (treeop1
);
7881 int unsignedp
= TYPE_UNSIGNED (type
);
7882 enum machine_mode mode
= TYPE_MODE (type
);
7884 temp
= assign_temp (type
, 0, 0, 1);
7886 /* If we cannot do a conditional move on the mode, try doing it
7887 with the promoted mode. */
7888 if (!can_conditionally_move_p (mode
))
7889 mode
= promote_mode (type
, mode
, &unsignedp
);
7891 if (!can_conditionally_move_p (mode
))
7895 expand_operands (treeop1
, treeop2
,
7896 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7898 if (TREE_CODE (treeop0
) == SSA_NAME
7899 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7901 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7902 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7903 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7904 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7905 comparison_mode
= TYPE_MODE (type
);
7906 unsignedp
= TYPE_UNSIGNED (type
);
7907 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7909 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7911 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7912 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7913 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7914 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7915 unsignedp
= TYPE_UNSIGNED (type
);
7916 comparison_mode
= TYPE_MODE (type
);
7917 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7921 op00
= expand_normal (treeop0
);
7923 comparison_code
= NE
;
7924 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7927 if (GET_MODE (op1
) != mode
)
7928 op1
= gen_lowpart (mode
, op1
);
7930 if (GET_MODE (op2
) != mode
)
7931 op2
= gen_lowpart (mode
, op2
);
7933 /* Try to emit the conditional move. */
7934 insn
= emit_conditional_move (temp
, comparison_code
,
7935 op00
, op01
, comparison_mode
,
7939 /* If we could do the conditional move, emit the sequence,
7943 rtx seq
= get_insns ();
7949 /* Otherwise discard the sequence and fall back to code with
7957 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
7958 enum expand_modifier modifier
)
7960 rtx op0
, op1
, op2
, temp
;
7963 enum machine_mode mode
;
7964 enum tree_code code
= ops
->code
;
7966 rtx subtarget
, original_target
;
7968 bool reduce_bit_field
;
7969 location_t loc
= ops
->location
;
7970 tree treeop0
, treeop1
, treeop2
;
7971 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
7972 ? reduce_to_bit_field_precision ((expr), \
7978 mode
= TYPE_MODE (type
);
7979 unsignedp
= TYPE_UNSIGNED (type
);
7985 /* We should be called only on simple (binary or unary) expressions,
7986 exactly those that are valid in gimple expressions that aren't
7987 GIMPLE_SINGLE_RHS (or invalid). */
7988 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
7989 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
7990 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
7992 ignore
= (target
== const0_rtx
7993 || ((CONVERT_EXPR_CODE_P (code
)
7994 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
7995 && TREE_CODE (type
) == VOID_TYPE
));
7997 /* We should be called only if we need the result. */
7998 gcc_assert (!ignore
);
8000 /* An operation in what may be a bit-field type needs the
8001 result to be reduced to the precision of the bit-field type,
8002 which is narrower than that of the type's mode. */
8003 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8004 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8006 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8009 /* Use subtarget as the target for operand 0 of a binary operation. */
8010 subtarget
= get_subtarget (target
);
8011 original_target
= target
;
8015 case NON_LVALUE_EXPR
:
8018 if (treeop0
== error_mark_node
)
8021 if (TREE_CODE (type
) == UNION_TYPE
)
8023 tree valtype
= TREE_TYPE (treeop0
);
8025 /* If both input and output are BLKmode, this conversion isn't doing
8026 anything except possibly changing memory attribute. */
8027 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8029 rtx result
= expand_expr (treeop0
, target
, tmode
,
8032 result
= copy_rtx (result
);
8033 set_mem_attributes (result
, type
, 0);
8039 if (TYPE_MODE (type
) != BLKmode
)
8040 target
= gen_reg_rtx (TYPE_MODE (type
));
8042 target
= assign_temp (type
, 0, 1, 1);
8046 /* Store data into beginning of memory target. */
8047 store_expr (treeop0
,
8048 adjust_address (target
, TYPE_MODE (valtype
), 0),
8049 modifier
== EXPAND_STACK_PARM
,
8054 gcc_assert (REG_P (target
));
8056 /* Store this field into a union of the proper type. */
8057 store_field (target
,
8058 MIN ((int_size_in_bytes (TREE_TYPE
8061 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8062 0, 0, 0, TYPE_MODE (valtype
), treeop0
,
8066 /* Return the entire union. */
8070 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8072 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8075 /* If the signedness of the conversion differs and OP0 is
8076 a promoted SUBREG, clear that indication since we now
8077 have to do the proper extension. */
8078 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8079 && GET_CODE (op0
) == SUBREG
)
8080 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8082 return REDUCE_BIT_FIELD (op0
);
8085 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8086 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8087 if (GET_MODE (op0
) == mode
)
8090 /* If OP0 is a constant, just convert it into the proper mode. */
8091 else if (CONSTANT_P (op0
))
8093 tree inner_type
= TREE_TYPE (treeop0
);
8094 enum machine_mode inner_mode
= GET_MODE (op0
);
8096 if (inner_mode
== VOIDmode
)
8097 inner_mode
= TYPE_MODE (inner_type
);
8099 if (modifier
== EXPAND_INITIALIZER
)
8100 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8101 subreg_lowpart_offset (mode
,
8104 op0
= convert_modes (mode
, inner_mode
, op0
,
8105 TYPE_UNSIGNED (inner_type
));
8108 else if (modifier
== EXPAND_INITIALIZER
)
8109 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8111 else if (target
== 0)
8112 op0
= convert_to_mode (mode
, op0
,
8113 TYPE_UNSIGNED (TREE_TYPE
8117 convert_move (target
, op0
,
8118 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8122 return REDUCE_BIT_FIELD (op0
);
8124 case ADDR_SPACE_CONVERT_EXPR
:
8126 tree treeop0_type
= TREE_TYPE (treeop0
);
8128 addr_space_t as_from
;
8130 gcc_assert (POINTER_TYPE_P (type
));
8131 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8133 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8134 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8136 /* Conversions between pointers to the same address space should
8137 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8138 gcc_assert (as_to
!= as_from
);
8140 /* Ask target code to handle conversion between pointers
8141 to overlapping address spaces. */
8142 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8143 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8145 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8146 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8151 /* For disjoint address spaces, converting anything but
8152 a null pointer invokes undefined behaviour. We simply
8153 always return a null pointer here. */
8154 return CONST0_RTX (mode
);
8157 case POINTER_PLUS_EXPR
:
8158 /* Even though the sizetype mode and the pointer's mode can be different
8159 expand is able to handle this correctly and get the correct result out
8160 of the PLUS_EXPR code. */
8161 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8162 if sizetype precision is smaller than pointer precision. */
8163 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8164 treeop1
= fold_convert_loc (loc
, type
,
8165 fold_convert_loc (loc
, ssizetype
,
8167 /* If sizetype precision is larger than pointer precision, truncate the
8168 offset to have matching modes. */
8169 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8170 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8173 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8174 something else, make sure we add the register to the constant and
8175 then to the other thing. This case can occur during strength
8176 reduction and doing it this way will produce better code if the
8177 frame pointer or argument pointer is eliminated.
8179 fold-const.c will ensure that the constant is always in the inner
8180 PLUS_EXPR, so the only case we need to do anything about is if
8181 sp, ap, or fp is our second argument, in which case we must swap
8182 the innermost first argument and our second argument. */
8184 if (TREE_CODE (treeop0
) == PLUS_EXPR
8185 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8186 && TREE_CODE (treeop1
) == VAR_DECL
8187 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8188 || DECL_RTL (treeop1
) == stack_pointer_rtx
8189 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8193 treeop1
= TREE_OPERAND (treeop0
, 0);
8194 TREE_OPERAND (treeop0
, 0) = t
;
8197 /* If the result is to be ptr_mode and we are adding an integer to
8198 something, we might be forming a constant. So try to use
8199 plus_constant. If it produces a sum and we can't accept it,
8200 use force_operand. This allows P = &ARR[const] to generate
8201 efficient code on machines where a SYMBOL_REF is not a valid
8204 If this is an EXPAND_SUM call, always return the sum. */
8205 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8206 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8208 if (modifier
== EXPAND_STACK_PARM
)
8210 if (TREE_CODE (treeop0
) == INTEGER_CST
8211 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8212 && TREE_CONSTANT (treeop1
))
8216 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8218 /* Use immed_double_const to ensure that the constant is
8219 truncated according to the mode of OP1, then sign extended
8220 to a HOST_WIDE_INT. Using the constant directly can result
8221 in non-canonical RTL in a 64x32 cross compile. */
8223 = immed_double_const (TREE_INT_CST_LOW (treeop0
),
8225 TYPE_MODE (TREE_TYPE (treeop1
)));
8226 op1
= plus_constant (op1
, INTVAL (constant_part
));
8227 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8228 op1
= force_operand (op1
, target
);
8229 return REDUCE_BIT_FIELD (op1
);
8232 else if (TREE_CODE (treeop1
) == INTEGER_CST
8233 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8234 && TREE_CONSTANT (treeop0
))
8238 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8239 (modifier
== EXPAND_INITIALIZER
8240 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8241 if (! CONSTANT_P (op0
))
8243 op1
= expand_expr (treeop1
, NULL_RTX
,
8244 VOIDmode
, modifier
);
8245 /* Return a PLUS if modifier says it's OK. */
8246 if (modifier
== EXPAND_SUM
8247 || modifier
== EXPAND_INITIALIZER
)
8248 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8251 /* Use immed_double_const to ensure that the constant is
8252 truncated according to the mode of OP1, then sign extended
8253 to a HOST_WIDE_INT. Using the constant directly can result
8254 in non-canonical RTL in a 64x32 cross compile. */
8256 = immed_double_const (TREE_INT_CST_LOW (treeop1
),
8258 TYPE_MODE (TREE_TYPE (treeop0
)));
8259 op0
= plus_constant (op0
, INTVAL (constant_part
));
8260 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8261 op0
= force_operand (op0
, target
);
8262 return REDUCE_BIT_FIELD (op0
);
8266 /* Use TER to expand pointer addition of a negated value
8267 as pointer subtraction. */
8268 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8269 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8270 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8271 && TREE_CODE (treeop1
) == SSA_NAME
8272 && TYPE_MODE (TREE_TYPE (treeop0
))
8273 == TYPE_MODE (TREE_TYPE (treeop1
)))
8275 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8278 treeop1
= gimple_assign_rhs1 (def
);
8284 /* No sense saving up arithmetic to be done
8285 if it's all in the wrong mode to form part of an address.
8286 And force_operand won't know whether to sign-extend or
8288 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8289 || mode
!= ptr_mode
)
8291 expand_operands (treeop0
, treeop1
,
8292 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8293 if (op0
== const0_rtx
)
8295 if (op1
== const0_rtx
)
8300 expand_operands (treeop0
, treeop1
,
8301 subtarget
, &op0
, &op1
, modifier
);
8302 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8306 /* For initializers, we are allowed to return a MINUS of two
8307 symbolic constants. Here we handle all cases when both operands
8309 /* Handle difference of two symbolic constants,
8310 for the sake of an initializer. */
8311 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8312 && really_constant_p (treeop0
)
8313 && really_constant_p (treeop1
))
8315 expand_operands (treeop0
, treeop1
,
8316 NULL_RTX
, &op0
, &op1
, modifier
);
8318 /* If the last operand is a CONST_INT, use plus_constant of
8319 the negated constant. Else make the MINUS. */
8320 if (CONST_INT_P (op1
))
8321 return REDUCE_BIT_FIELD (plus_constant (op0
, - INTVAL (op1
)));
8323 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8326 /* No sense saving up arithmetic to be done
8327 if it's all in the wrong mode to form part of an address.
8328 And force_operand won't know whether to sign-extend or
8330 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8331 || mode
!= ptr_mode
)
8334 expand_operands (treeop0
, treeop1
,
8335 subtarget
, &op0
, &op1
, modifier
);
8337 /* Convert A - const to A + (-const). */
8338 if (CONST_INT_P (op1
))
8340 op1
= negate_rtx (mode
, op1
);
8341 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8346 case WIDEN_MULT_PLUS_EXPR
:
8347 case WIDEN_MULT_MINUS_EXPR
:
8348 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8349 op2
= expand_normal (treeop2
);
8350 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8354 case WIDEN_MULT_EXPR
:
8355 /* If first operand is constant, swap them.
8356 Thus the following special case checks need only
8357 check the second operand. */
8358 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8365 /* First, check if we have a multiplication of one signed and one
8366 unsigned operand. */
8367 if (TREE_CODE (treeop1
) != INTEGER_CST
8368 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8369 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8371 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8372 this_optab
= usmul_widen_optab
;
8373 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8374 != CODE_FOR_nothing
)
8376 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8377 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8380 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8385 /* Check for a multiplication with matching signedness. */
8386 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8387 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8388 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8389 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8391 tree op0type
= TREE_TYPE (treeop0
);
8392 enum machine_mode innermode
= TYPE_MODE (op0type
);
8393 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8394 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8395 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8397 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8399 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8400 != CODE_FOR_nothing
)
8402 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8404 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8405 unsignedp
, this_optab
);
8406 return REDUCE_BIT_FIELD (temp
);
8408 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8410 && innermode
== word_mode
)
8413 op0
= expand_normal (treeop0
);
8414 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8415 op1
= convert_modes (innermode
, mode
,
8416 expand_normal (treeop1
), unsignedp
);
8418 op1
= expand_normal (treeop1
);
8419 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8420 unsignedp
, OPTAB_LIB_WIDEN
);
8421 hipart
= gen_highpart (innermode
, temp
);
8422 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8426 emit_move_insn (hipart
, htem
);
8427 return REDUCE_BIT_FIELD (temp
);
8431 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8432 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8433 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8434 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8438 optab opt
= fma_optab
;
8441 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8443 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8445 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8448 gcc_assert (fn
!= NULL_TREE
);
8449 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8450 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8453 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8454 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8459 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8462 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8463 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8466 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8469 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8472 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8475 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8479 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8481 op2
= expand_normal (treeop2
);
8482 op1
= expand_normal (treeop1
);
8484 return expand_ternary_op (TYPE_MODE (type
), opt
,
8485 op0
, op1
, op2
, target
, 0);
8489 /* If this is a fixed-point operation, then we cannot use the code
8490 below because "expand_mult" doesn't support sat/no-sat fixed-point
8492 if (ALL_FIXED_POINT_MODE_P (mode
))
8495 /* If first operand is constant, swap them.
8496 Thus the following special case checks need only
8497 check the second operand. */
8498 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8505 /* Attempt to return something suitable for generating an
8506 indexed address, for machines that support that. */
8508 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8509 && host_integerp (treeop1
, 0))
8511 tree exp1
= treeop1
;
8513 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8517 op0
= force_operand (op0
, NULL_RTX
);
8519 op0
= copy_to_mode_reg (mode
, op0
);
8521 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8522 gen_int_mode (tree_low_cst (exp1
, 0),
8523 TYPE_MODE (TREE_TYPE (exp1
)))));
8526 if (modifier
== EXPAND_STACK_PARM
)
8529 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8530 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8532 case TRUNC_DIV_EXPR
:
8533 case FLOOR_DIV_EXPR
:
8535 case ROUND_DIV_EXPR
:
8536 case EXACT_DIV_EXPR
:
8537 /* If this is a fixed-point operation, then we cannot use the code
8538 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8540 if (ALL_FIXED_POINT_MODE_P (mode
))
8543 if (modifier
== EXPAND_STACK_PARM
)
8545 /* Possible optimization: compute the dividend with EXPAND_SUM
8546 then if the divisor is constant can optimize the case
8547 where some terms of the dividend have coeffs divisible by it. */
8548 expand_operands (treeop0
, treeop1
,
8549 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8550 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8555 case TRUNC_MOD_EXPR
:
8556 case FLOOR_MOD_EXPR
:
8558 case ROUND_MOD_EXPR
:
8559 if (modifier
== EXPAND_STACK_PARM
)
8561 expand_operands (treeop0
, treeop1
,
8562 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8563 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8565 case FIXED_CONVERT_EXPR
:
8566 op0
= expand_normal (treeop0
);
8567 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8568 target
= gen_reg_rtx (mode
);
8570 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8571 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8572 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8573 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8575 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8578 case FIX_TRUNC_EXPR
:
8579 op0
= expand_normal (treeop0
);
8580 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8581 target
= gen_reg_rtx (mode
);
8582 expand_fix (target
, op0
, unsignedp
);
8586 op0
= expand_normal (treeop0
);
8587 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8588 target
= gen_reg_rtx (mode
);
8589 /* expand_float can't figure out what to do if FROM has VOIDmode.
8590 So give it the correct mode. With -O, cse will optimize this. */
8591 if (GET_MODE (op0
) == VOIDmode
)
8592 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8594 expand_float (target
, op0
,
8595 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8599 op0
= expand_expr (treeop0
, subtarget
,
8600 VOIDmode
, EXPAND_NORMAL
);
8601 if (modifier
== EXPAND_STACK_PARM
)
8603 temp
= expand_unop (mode
,
8604 optab_for_tree_code (NEGATE_EXPR
, type
,
8608 return REDUCE_BIT_FIELD (temp
);
8611 op0
= expand_expr (treeop0
, subtarget
,
8612 VOIDmode
, EXPAND_NORMAL
);
8613 if (modifier
== EXPAND_STACK_PARM
)
8616 /* ABS_EXPR is not valid for complex arguments. */
8617 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8618 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8620 /* Unsigned abs is simply the operand. Testing here means we don't
8621 risk generating incorrect code below. */
8622 if (TYPE_UNSIGNED (type
))
8625 return expand_abs (mode
, op0
, target
, unsignedp
,
8626 safe_from_p (target
, treeop0
, 1));
8630 target
= original_target
;
8632 || modifier
== EXPAND_STACK_PARM
8633 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8634 || GET_MODE (target
) != mode
8636 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8637 target
= gen_reg_rtx (mode
);
8638 expand_operands (treeop0
, treeop1
,
8639 target
, &op0
, &op1
, EXPAND_NORMAL
);
8641 /* First try to do it with a special MIN or MAX instruction.
8642 If that does not win, use a conditional jump to select the proper
8644 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8645 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8650 /* At this point, a MEM target is no longer useful; we will get better
8653 if (! REG_P (target
))
8654 target
= gen_reg_rtx (mode
);
8656 /* If op1 was placed in target, swap op0 and op1. */
8657 if (target
!= op0
&& target
== op1
)
8664 /* We generate better code and avoid problems with op1 mentioning
8665 target by forcing op1 into a pseudo if it isn't a constant. */
8666 if (! CONSTANT_P (op1
))
8667 op1
= force_reg (mode
, op1
);
8670 enum rtx_code comparison_code
;
8673 if (code
== MAX_EXPR
)
8674 comparison_code
= unsignedp
? GEU
: GE
;
8676 comparison_code
= unsignedp
? LEU
: LE
;
8678 /* Canonicalize to comparisons against 0. */
8679 if (op1
== const1_rtx
)
8681 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8682 or (a != 0 ? a : 1) for unsigned.
8683 For MIN we are safe converting (a <= 1 ? a : 1)
8684 into (a <= 0 ? a : 1) */
8685 cmpop1
= const0_rtx
;
8686 if (code
== MAX_EXPR
)
8687 comparison_code
= unsignedp
? NE
: GT
;
8689 if (op1
== constm1_rtx
&& !unsignedp
)
8691 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8692 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8693 cmpop1
= const0_rtx
;
8694 if (code
== MIN_EXPR
)
8695 comparison_code
= LT
;
8697 #ifdef HAVE_conditional_move
8698 /* Use a conditional move if possible. */
8699 if (can_conditionally_move_p (mode
))
8703 /* ??? Same problem as in expmed.c: emit_conditional_move
8704 forces a stack adjustment via compare_from_rtx, and we
8705 lose the stack adjustment if the sequence we are about
8706 to create is discarded. */
8707 do_pending_stack_adjust ();
8711 /* Try to emit the conditional move. */
8712 insn
= emit_conditional_move (target
, comparison_code
,
8717 /* If we could do the conditional move, emit the sequence,
8721 rtx seq
= get_insns ();
8727 /* Otherwise discard the sequence and fall back to code with
8733 emit_move_insn (target
, op0
);
8735 temp
= gen_label_rtx ();
8736 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8737 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8740 emit_move_insn (target
, op1
);
8745 op0
= expand_expr (treeop0
, subtarget
,
8746 VOIDmode
, EXPAND_NORMAL
);
8747 if (modifier
== EXPAND_STACK_PARM
)
8749 /* In case we have to reduce the result to bitfield precision
8750 for unsigned bitfield expand this as XOR with a proper constant
8752 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8753 temp
= expand_binop (mode
, xor_optab
, op0
,
8754 immed_double_int_const
8755 (double_int_mask (TYPE_PRECISION (type
)), mode
),
8756 target
, 1, OPTAB_LIB_WIDEN
);
8758 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8762 /* ??? Can optimize bitwise operations with one arg constant.
8763 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8764 and (a bitwise1 b) bitwise2 b (etc)
8765 but that is probably not worth while. */
8774 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8775 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8776 == TYPE_PRECISION (type
)));
8781 /* If this is a fixed-point operation, then we cannot use the code
8782 below because "expand_shift" doesn't support sat/no-sat fixed-point
8784 if (ALL_FIXED_POINT_MODE_P (mode
))
8787 if (! safe_from_p (subtarget
, treeop1
, 1))
8789 if (modifier
== EXPAND_STACK_PARM
)
8791 op0
= expand_expr (treeop0
, subtarget
,
8792 VOIDmode
, EXPAND_NORMAL
);
8793 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8795 if (code
== LSHIFT_EXPR
)
8796 temp
= REDUCE_BIT_FIELD (temp
);
8799 /* Could determine the answer when only additive constants differ. Also,
8800 the addition of one can be handled by changing the condition. */
8807 case UNORDERED_EXPR
:
8815 temp
= do_store_flag (ops
,
8816 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8817 tmode
!= VOIDmode
? tmode
: mode
);
8821 /* Use a compare and a jump for BLKmode comparisons, or for function
8822 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8825 || modifier
== EXPAND_STACK_PARM
8826 || ! safe_from_p (target
, treeop0
, 1)
8827 || ! safe_from_p (target
, treeop1
, 1)
8828 /* Make sure we don't have a hard reg (such as function's return
8829 value) live across basic blocks, if not optimizing. */
8830 || (!optimize
&& REG_P (target
)
8831 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8832 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8834 emit_move_insn (target
, const0_rtx
);
8836 op1
= gen_label_rtx ();
8837 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8839 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8840 emit_move_insn (target
, constm1_rtx
);
8842 emit_move_insn (target
, const1_rtx
);
8848 /* Get the rtx code of the operands. */
8849 op0
= expand_normal (treeop0
);
8850 op1
= expand_normal (treeop1
);
8853 target
= gen_reg_rtx (TYPE_MODE (type
));
8855 /* Move the real (op0) and imaginary (op1) parts to their location. */
8856 write_complex_part (target
, op0
, false);
8857 write_complex_part (target
, op1
, true);
8861 case WIDEN_SUM_EXPR
:
8863 tree oprnd0
= treeop0
;
8864 tree oprnd1
= treeop1
;
8866 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8867 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
8872 case REDUC_MAX_EXPR
:
8873 case REDUC_MIN_EXPR
:
8874 case REDUC_PLUS_EXPR
:
8876 op0
= expand_normal (treeop0
);
8877 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8878 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
8883 case VEC_LSHIFT_EXPR
:
8884 case VEC_RSHIFT_EXPR
:
8886 target
= expand_vec_shift_expr (ops
, target
);
8890 case VEC_UNPACK_HI_EXPR
:
8891 case VEC_UNPACK_LO_EXPR
:
8893 op0
= expand_normal (treeop0
);
8894 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
8900 case VEC_UNPACK_FLOAT_HI_EXPR
:
8901 case VEC_UNPACK_FLOAT_LO_EXPR
:
8903 op0
= expand_normal (treeop0
);
8904 /* The signedness is determined from input operand. */
8905 temp
= expand_widen_pattern_expr
8906 (ops
, op0
, NULL_RTX
, NULL_RTX
,
8907 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8913 case VEC_WIDEN_MULT_HI_EXPR
:
8914 case VEC_WIDEN_MULT_LO_EXPR
:
8916 tree oprnd0
= treeop0
;
8917 tree oprnd1
= treeop1
;
8919 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8920 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
8922 gcc_assert (target
);
8926 case VEC_WIDEN_LSHIFT_HI_EXPR
:
8927 case VEC_WIDEN_LSHIFT_LO_EXPR
:
8929 tree oprnd0
= treeop0
;
8930 tree oprnd1
= treeop1
;
8932 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8933 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
8935 gcc_assert (target
);
8939 case VEC_PACK_TRUNC_EXPR
:
8940 case VEC_PACK_SAT_EXPR
:
8941 case VEC_PACK_FIX_TRUNC_EXPR
:
8942 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8946 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
8947 op2
= expand_normal (treeop2
);
8949 /* Careful here: if the target doesn't support integral vector modes,
8950 a constant selection vector could wind up smooshed into a normal
8951 integral constant. */
8952 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
8954 tree sel_type
= TREE_TYPE (treeop2
);
8955 enum machine_mode vmode
8956 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
8957 TYPE_VECTOR_SUBPARTS (sel_type
));
8958 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
8959 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
8960 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
8963 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
8965 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
8971 tree oprnd0
= treeop0
;
8972 tree oprnd1
= treeop1
;
8973 tree oprnd2
= treeop2
;
8976 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8977 op2
= expand_normal (oprnd2
);
8978 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8983 case REALIGN_LOAD_EXPR
:
8985 tree oprnd0
= treeop0
;
8986 tree oprnd1
= treeop1
;
8987 tree oprnd2
= treeop2
;
8990 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8991 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8992 op2
= expand_normal (oprnd2
);
8993 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9000 /* A COND_EXPR with its type being VOID_TYPE represents a
9001 conditional jump and is handled in
9002 expand_gimple_cond_expr. */
9003 gcc_assert (!VOID_TYPE_P (type
));
9005 /* Note that COND_EXPRs whose type is a structure or union
9006 are required to be constructed to contain assignments of
9007 a temporary variable, so that we can evaluate them here
9008 for side effect only. If type is void, we must do likewise. */
9010 gcc_assert (!TREE_ADDRESSABLE (type
)
9012 && TREE_TYPE (treeop1
) != void_type_node
9013 && TREE_TYPE (treeop2
) != void_type_node
);
9015 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9019 /* If we are not to produce a result, we have no target. Otherwise,
9020 if a target was specified use it; it will not be used as an
9021 intermediate target unless it is safe. If no target, use a
9024 if (modifier
!= EXPAND_STACK_PARM
9026 && safe_from_p (original_target
, treeop0
, 1)
9027 && GET_MODE (original_target
) == mode
9028 && !MEM_P (original_target
))
9029 temp
= original_target
;
9031 temp
= assign_temp (type
, 0, 0, 1);
9033 do_pending_stack_adjust ();
9035 op0
= gen_label_rtx ();
9036 op1
= gen_label_rtx ();
9037 jumpifnot (treeop0
, op0
, -1);
9038 store_expr (treeop1
, temp
,
9039 modifier
== EXPAND_STACK_PARM
,
9042 emit_jump_insn (gen_jump (op1
));
9045 store_expr (treeop2
, temp
,
9046 modifier
== EXPAND_STACK_PARM
,
9054 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9061 /* Here to do an ordinary binary operator. */
9063 expand_operands (treeop0
, treeop1
,
9064 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9066 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9068 if (modifier
== EXPAND_STACK_PARM
)
9070 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9071 unsignedp
, OPTAB_LIB_WIDEN
);
9073 /* Bitwise operations do not need bitfield reduction as we expect their
9074 operands being properly truncated. */
9075 if (code
== BIT_XOR_EXPR
9076 || code
== BIT_AND_EXPR
9077 || code
== BIT_IOR_EXPR
)
9079 return REDUCE_BIT_FIELD (temp
);
9081 #undef REDUCE_BIT_FIELD
9084 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9085 enum expand_modifier modifier
, rtx
*alt_rtl
)
9087 rtx op0
, op1
, temp
, decl_rtl
;
9090 enum machine_mode mode
;
9091 enum tree_code code
= TREE_CODE (exp
);
9092 rtx subtarget
, original_target
;
9095 bool reduce_bit_field
;
9096 location_t loc
= EXPR_LOCATION (exp
);
9097 struct separate_ops ops
;
9098 tree treeop0
, treeop1
, treeop2
;
9099 tree ssa_name
= NULL_TREE
;
9102 type
= TREE_TYPE (exp
);
9103 mode
= TYPE_MODE (type
);
9104 unsignedp
= TYPE_UNSIGNED (type
);
9106 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9107 if (!VL_EXP_CLASS_P (exp
))
9108 switch (TREE_CODE_LENGTH (code
))
9111 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9112 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9113 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9123 ignore
= (target
== const0_rtx
9124 || ((CONVERT_EXPR_CODE_P (code
)
9125 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9126 && TREE_CODE (type
) == VOID_TYPE
));
9128 /* An operation in what may be a bit-field type needs the
9129 result to be reduced to the precision of the bit-field type,
9130 which is narrower than that of the type's mode. */
9131 reduce_bit_field
= (!ignore
9132 && INTEGRAL_TYPE_P (type
)
9133 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9135 /* If we are going to ignore this result, we need only do something
9136 if there is a side-effect somewhere in the expression. If there
9137 is, short-circuit the most common cases here. Note that we must
9138 not call expand_expr with anything but const0_rtx in case this
9139 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9143 if (! TREE_SIDE_EFFECTS (exp
))
9146 /* Ensure we reference a volatile object even if value is ignored, but
9147 don't do this if all we are doing is taking its address. */
9148 if (TREE_THIS_VOLATILE (exp
)
9149 && TREE_CODE (exp
) != FUNCTION_DECL
9150 && mode
!= VOIDmode
&& mode
!= BLKmode
9151 && modifier
!= EXPAND_CONST_ADDRESS
)
9153 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9159 if (TREE_CODE_CLASS (code
) == tcc_unary
9160 || code
== COMPONENT_REF
|| code
== INDIRECT_REF
)
9161 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9164 else if (TREE_CODE_CLASS (code
) == tcc_binary
9165 || TREE_CODE_CLASS (code
) == tcc_comparison
9166 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9168 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9169 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9172 else if (code
== BIT_FIELD_REF
)
9174 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9175 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9176 expand_expr (treeop2
, const0_rtx
, VOIDmode
, modifier
);
9183 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9186 /* Use subtarget as the target for operand 0 of a binary operation. */
9187 subtarget
= get_subtarget (target
);
9188 original_target
= target
;
9194 tree function
= decl_function_context (exp
);
9196 temp
= label_rtx (exp
);
9197 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9199 if (function
!= current_function_decl
9201 LABEL_REF_NONLOCAL_P (temp
) = 1;
9203 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9208 /* ??? ivopts calls expander, without any preparation from
9209 out-of-ssa. So fake instructions as if this was an access to the
9210 base variable. This unnecessarily allocates a pseudo, see how we can
9211 reuse it, if partition base vars have it set already. */
9212 if (!currently_expanding_to_rtl
)
9213 return expand_expr_real_1 (SSA_NAME_VAR (exp
), target
, tmode
, modifier
,
9216 g
= get_gimple_for_ssa_name (exp
);
9217 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9219 && modifier
== EXPAND_INITIALIZER
9220 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9221 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9222 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9223 g
= SSA_NAME_DEF_STMT (exp
);
9226 rtx r
= expand_expr_real (gimple_assign_rhs_to_tree (g
), target
,
9227 tmode
, modifier
, NULL
);
9228 if (REG_P (r
) && !REG_EXPR (r
))
9229 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9234 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9235 exp
= SSA_NAME_VAR (ssa_name
);
9236 goto expand_decl_rtl
;
9240 /* If a static var's type was incomplete when the decl was written,
9241 but the type is complete now, lay out the decl now. */
9242 if (DECL_SIZE (exp
) == 0
9243 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9244 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9245 layout_decl (exp
, 0);
9247 /* ... fall through ... */
9251 decl_rtl
= DECL_RTL (exp
);
9253 gcc_assert (decl_rtl
);
9254 decl_rtl
= copy_rtx (decl_rtl
);
9255 /* Record writes to register variables. */
9256 if (modifier
== EXPAND_WRITE
9258 && HARD_REGISTER_P (decl_rtl
))
9259 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9260 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9262 /* Ensure variable marked as used even if it doesn't go through
9263 a parser. If it hasn't be used yet, write out an external
9265 TREE_USED (exp
) = 1;
9267 /* Show we haven't gotten RTL for this yet. */
9270 /* Variables inherited from containing functions should have
9271 been lowered by this point. */
9272 context
= decl_function_context (exp
);
9273 gcc_assert (!context
9274 || context
== current_function_decl
9275 || TREE_STATIC (exp
)
9276 || DECL_EXTERNAL (exp
)
9277 /* ??? C++ creates functions that are not TREE_STATIC. */
9278 || TREE_CODE (exp
) == FUNCTION_DECL
);
9280 /* This is the case of an array whose size is to be determined
9281 from its initializer, while the initializer is still being parsed.
9284 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9285 temp
= validize_mem (decl_rtl
);
9287 /* If DECL_RTL is memory, we are in the normal case and the
9288 address is not valid, get the address into a register. */
9290 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9293 *alt_rtl
= decl_rtl
;
9294 decl_rtl
= use_anchored_address (decl_rtl
);
9295 if (modifier
!= EXPAND_CONST_ADDRESS
9296 && modifier
!= EXPAND_SUM
9297 && !memory_address_addr_space_p (DECL_MODE (exp
),
9299 MEM_ADDR_SPACE (decl_rtl
)))
9300 temp
= replace_equiv_address (decl_rtl
,
9301 copy_rtx (XEXP (decl_rtl
, 0)));
9304 /* If we got something, return it. But first, set the alignment
9305 if the address is a register. */
9308 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9309 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9314 /* If the mode of DECL_RTL does not match that of the decl,
9315 there are two cases: we are dealing with a BLKmode value
9316 that is returned in a register, or we are dealing with
9317 a promoted value. In the latter case, return a SUBREG
9318 of the wanted mode, but mark it so that we know that it
9319 was already extended. */
9320 if (REG_P (decl_rtl
)
9321 && DECL_MODE (exp
) != BLKmode
9322 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9324 enum machine_mode pmode
;
9326 /* Get the signedness to be used for this variable. Ensure we get
9327 the same mode we got when the variable was declared. */
9328 if (code
== SSA_NAME
9329 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9330 && gimple_code (g
) == GIMPLE_CALL
)
9332 gcc_assert (!gimple_call_internal_p (g
));
9333 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9334 gimple_call_fntype (g
),
9338 pmode
= promote_decl_mode (exp
, &unsignedp
);
9339 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9341 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9342 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9343 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
9350 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
9351 TREE_INT_CST_HIGH (exp
), mode
);
9357 tree tmp
= NULL_TREE
;
9358 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9359 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9360 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9361 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9362 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9363 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9364 return const_vector_from_tree (exp
);
9365 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9367 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9369 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9373 VEC(constructor_elt
,gc
) *v
;
9375 v
= VEC_alloc (constructor_elt
, gc
, VECTOR_CST_NELTS (exp
));
9376 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9377 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9378 tmp
= build_constructor (type
, v
);
9380 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9385 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9388 /* If optimized, generate immediate CONST_DOUBLE
9389 which will be turned into memory by reload if necessary.
9391 We used to force a register so that loop.c could see it. But
9392 this does not allow gen_* patterns to perform optimizations with
9393 the constants. It also produces two insns in cases like "x = 1.0;".
9394 On most machines, floating-point constants are not permitted in
9395 many insns, so we'd end up copying it to a register in any case.
9397 Now, we do the copying in expand_binop, if appropriate. */
9398 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9399 TYPE_MODE (TREE_TYPE (exp
)));
9402 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9403 TYPE_MODE (TREE_TYPE (exp
)));
9406 /* Handle evaluating a complex constant in a CONCAT target. */
9407 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9409 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9412 rtarg
= XEXP (original_target
, 0);
9413 itarg
= XEXP (original_target
, 1);
9415 /* Move the real and imaginary parts separately. */
9416 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9417 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9420 emit_move_insn (rtarg
, op0
);
9422 emit_move_insn (itarg
, op1
);
9424 return original_target
;
9427 /* ... fall through ... */
9430 temp
= expand_expr_constant (exp
, 1, modifier
);
9432 /* temp contains a constant address.
9433 On RISC machines where a constant address isn't valid,
9434 make some insns to get that address into a register. */
9435 if (modifier
!= EXPAND_CONST_ADDRESS
9436 && modifier
!= EXPAND_INITIALIZER
9437 && modifier
!= EXPAND_SUM
9438 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9439 MEM_ADDR_SPACE (temp
)))
9440 return replace_equiv_address (temp
,
9441 copy_rtx (XEXP (temp
, 0)));
9447 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
9449 if (!SAVE_EXPR_RESOLVED_P (exp
))
9451 /* We can indeed still hit this case, typically via builtin
9452 expanders calling save_expr immediately before expanding
9453 something. Assume this means that we only have to deal
9454 with non-BLKmode values. */
9455 gcc_assert (GET_MODE (ret
) != BLKmode
);
9457 val
= build_decl (EXPR_LOCATION (exp
),
9458 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9459 DECL_ARTIFICIAL (val
) = 1;
9460 DECL_IGNORED_P (val
) = 1;
9462 TREE_OPERAND (exp
, 0) = treeop0
;
9463 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9465 if (!CONSTANT_P (ret
))
9466 ret
= copy_to_reg (ret
);
9467 SET_DECL_RTL (val
, ret
);
9475 /* If we don't need the result, just ensure we evaluate any
9479 unsigned HOST_WIDE_INT idx
;
9482 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9483 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9488 return expand_constructor (exp
, target
, modifier
, false);
9490 case TARGET_MEM_REF
:
9493 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9494 struct mem_address addr
;
9495 enum insn_code icode
;
9498 get_address_description (exp
, &addr
);
9499 op0
= addr_for_mem_ref (&addr
, as
, true);
9500 op0
= memory_address_addr_space (mode
, op0
, as
);
9501 temp
= gen_rtx_MEM (mode
, op0
);
9502 set_mem_attributes (temp
, exp
, 0);
9503 set_mem_addr_space (temp
, as
);
9504 align
= get_object_or_type_alignment (exp
);
9505 if (modifier
!= EXPAND_WRITE
9507 && align
< GET_MODE_ALIGNMENT (mode
)
9508 /* If the target does not have special handling for unaligned
9509 loads of mode then it can use regular moves for them. */
9510 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9511 != CODE_FOR_nothing
))
9513 struct expand_operand ops
[2];
9515 /* We've already validated the memory, and we're creating a
9516 new pseudo destination. The predicates really can't fail,
9517 nor can the generator. */
9518 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9519 create_fixed_operand (&ops
[1], temp
);
9520 expand_insn (icode
, 2, ops
);
9521 return ops
[0].value
;
9529 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9530 enum machine_mode address_mode
;
9531 tree base
= TREE_OPERAND (exp
, 0);
9533 enum insn_code icode
;
9535 /* Handle expansion of non-aliased memory with non-BLKmode. That
9536 might end up in a register. */
9537 if (mem_ref_refers_to_non_mem_p (exp
))
9539 HOST_WIDE_INT offset
= mem_ref_offset (exp
).low
;
9542 base
= TREE_OPERAND (base
, 0);
9544 && host_integerp (TYPE_SIZE (TREE_TYPE (exp
)), 1)
9545 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9546 == TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp
)))))
9547 return expand_expr (build1 (VIEW_CONVERT_EXPR
,
9548 TREE_TYPE (exp
), base
),
9549 target
, tmode
, modifier
);
9550 bit_offset
= bitsize_int (offset
* BITS_PER_UNIT
);
9551 bftype
= TREE_TYPE (base
);
9552 if (TYPE_MODE (TREE_TYPE (exp
)) != BLKmode
)
9553 bftype
= TREE_TYPE (exp
);
9556 temp
= assign_stack_temp (DECL_MODE (base
),
9557 GET_MODE_SIZE (DECL_MODE (base
)),
9559 store_expr (base
, temp
, 0, false);
9560 temp
= adjust_address (temp
, BLKmode
, offset
);
9561 set_mem_size (temp
, int_size_in_bytes (TREE_TYPE (exp
)));
9564 return expand_expr (build3 (BIT_FIELD_REF
, bftype
,
9566 TYPE_SIZE (TREE_TYPE (exp
)),
9568 target
, tmode
, modifier
);
9570 address_mode
= targetm
.addr_space
.address_mode (as
);
9571 base
= TREE_OPERAND (exp
, 0);
9572 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9574 tree mask
= gimple_assign_rhs2 (def_stmt
);
9575 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9576 gimple_assign_rhs1 (def_stmt
), mask
);
9577 TREE_OPERAND (exp
, 0) = base
;
9579 align
= get_object_or_type_alignment (exp
);
9580 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9581 op0
= memory_address_addr_space (address_mode
, op0
, as
);
9582 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9585 = immed_double_int_const (mem_ref_offset (exp
), address_mode
);
9586 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9588 op0
= memory_address_addr_space (mode
, op0
, as
);
9589 temp
= gen_rtx_MEM (mode
, op0
);
9590 set_mem_attributes (temp
, exp
, 0);
9591 set_mem_addr_space (temp
, as
);
9592 if (TREE_THIS_VOLATILE (exp
))
9593 MEM_VOLATILE_P (temp
) = 1;
9594 if (modifier
!= EXPAND_WRITE
9596 && align
< GET_MODE_ALIGNMENT (mode
))
9598 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9599 != CODE_FOR_nothing
)
9601 struct expand_operand ops
[2];
9603 /* We've already validated the memory, and we're creating a
9604 new pseudo destination. The predicates really can't fail,
9605 nor can the generator. */
9606 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9607 create_fixed_operand (&ops
[1], temp
);
9608 expand_insn (icode
, 2, ops
);
9609 return ops
[0].value
;
9611 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9612 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9613 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9614 true, (modifier
== EXPAND_STACK_PARM
9615 ? NULL_RTX
: target
),
9624 tree array
= treeop0
;
9625 tree index
= treeop1
;
9627 /* Fold an expression like: "foo"[2].
9628 This is not done in fold so it won't happen inside &.
9629 Don't fold if this is for wide characters since it's too
9630 difficult to do correctly and this is a very rare case. */
9632 if (modifier
!= EXPAND_CONST_ADDRESS
9633 && modifier
!= EXPAND_INITIALIZER
9634 && modifier
!= EXPAND_MEMORY
)
9636 tree t
= fold_read_from_constant_string (exp
);
9639 return expand_expr (t
, target
, tmode
, modifier
);
9642 /* If this is a constant index into a constant array,
9643 just get the value from the array. Handle both the cases when
9644 we have an explicit constructor and when our operand is a variable
9645 that was declared const. */
9647 if (modifier
!= EXPAND_CONST_ADDRESS
9648 && modifier
!= EXPAND_INITIALIZER
9649 && modifier
!= EXPAND_MEMORY
9650 && TREE_CODE (array
) == CONSTRUCTOR
9651 && ! TREE_SIDE_EFFECTS (array
)
9652 && TREE_CODE (index
) == INTEGER_CST
)
9654 unsigned HOST_WIDE_INT ix
;
9657 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9659 if (tree_int_cst_equal (field
, index
))
9661 if (!TREE_SIDE_EFFECTS (value
))
9662 return expand_expr (fold (value
), target
, tmode
, modifier
);
9667 else if (optimize
>= 1
9668 && modifier
!= EXPAND_CONST_ADDRESS
9669 && modifier
!= EXPAND_INITIALIZER
9670 && modifier
!= EXPAND_MEMORY
9671 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9672 && TREE_CODE (array
) == VAR_DECL
&& DECL_INITIAL (array
)
9673 && TREE_CODE (DECL_INITIAL (array
)) != ERROR_MARK
9674 && const_value_known_p (array
))
9676 if (TREE_CODE (index
) == INTEGER_CST
)
9678 tree init
= DECL_INITIAL (array
);
9680 if (TREE_CODE (init
) == CONSTRUCTOR
)
9682 unsigned HOST_WIDE_INT ix
;
9685 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9687 if (tree_int_cst_equal (field
, index
))
9689 if (TREE_SIDE_EFFECTS (value
))
9692 if (TREE_CODE (value
) == CONSTRUCTOR
)
9694 /* If VALUE is a CONSTRUCTOR, this
9695 optimization is only useful if
9696 this doesn't store the CONSTRUCTOR
9697 into memory. If it does, it is more
9698 efficient to just load the data from
9699 the array directly. */
9700 rtx ret
= expand_constructor (value
, target
,
9702 if (ret
== NULL_RTX
)
9706 return expand_expr (fold (value
), target
, tmode
,
9710 else if(TREE_CODE (init
) == STRING_CST
)
9712 tree index1
= index
;
9713 tree low_bound
= array_ref_low_bound (exp
);
9714 index1
= fold_convert_loc (loc
, sizetype
,
9717 /* Optimize the special-case of a zero lower bound.
9719 We convert the low_bound to sizetype to avoid some problems
9720 with constant folding. (E.g. suppose the lower bound is 1,
9721 and its mode is QI. Without the conversion,l (ARRAY
9722 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
9723 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
9725 if (! integer_zerop (low_bound
))
9726 index1
= size_diffop_loc (loc
, index1
,
9727 fold_convert_loc (loc
, sizetype
,
9730 if (0 > compare_tree_int (index1
,
9731 TREE_STRING_LENGTH (init
)))
9733 tree type
= TREE_TYPE (TREE_TYPE (init
));
9734 enum machine_mode mode
= TYPE_MODE (type
);
9736 if (GET_MODE_CLASS (mode
) == MODE_INT
9737 && GET_MODE_SIZE (mode
) == 1)
9738 return gen_int_mode (TREE_STRING_POINTER (init
)
9739 [TREE_INT_CST_LOW (index1
)],
9746 goto normal_inner_ref
;
9749 /* If the operand is a CONSTRUCTOR, we can just extract the
9750 appropriate field if it is present. */
9751 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9753 unsigned HOST_WIDE_INT idx
;
9756 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9758 if (field
== treeop1
9759 /* We can normally use the value of the field in the
9760 CONSTRUCTOR. However, if this is a bitfield in
9761 an integral mode that we can fit in a HOST_WIDE_INT,
9762 we must mask only the number of bits in the bitfield,
9763 since this is done implicitly by the constructor. If
9764 the bitfield does not meet either of those conditions,
9765 we can't do this optimization. */
9766 && (! DECL_BIT_FIELD (field
)
9767 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9768 && (GET_MODE_PRECISION (DECL_MODE (field
))
9769 <= HOST_BITS_PER_WIDE_INT
))))
9771 if (DECL_BIT_FIELD (field
)
9772 && modifier
== EXPAND_STACK_PARM
)
9774 op0
= expand_expr (value
, target
, tmode
, modifier
);
9775 if (DECL_BIT_FIELD (field
))
9777 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9778 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9780 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9782 op1
= GEN_INT (((HOST_WIDE_INT
) 1 << bitsize
) - 1);
9783 op0
= expand_and (imode
, op0
, op1
, target
);
9787 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
9789 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
9791 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
9799 goto normal_inner_ref
;
9802 case ARRAY_RANGE_REF
:
9805 enum machine_mode mode1
, mode2
;
9806 HOST_WIDE_INT bitsize
, bitpos
;
9808 int volatilep
= 0, must_force_mem
;
9809 bool packedp
= false;
9810 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
9811 &mode1
, &unsignedp
, &volatilep
, true);
9812 rtx orig_op0
, memloc
;
9813 bool mem_attrs_from_type
= false;
9815 /* If we got back the original object, something is wrong. Perhaps
9816 we are evaluating an expression too early. In any event, don't
9817 infinitely recurse. */
9818 gcc_assert (tem
!= exp
);
9820 if (TYPE_PACKED (TREE_TYPE (TREE_OPERAND (exp
, 0)))
9821 || (TREE_CODE (TREE_OPERAND (exp
, 1)) == FIELD_DECL
9822 && DECL_PACKED (TREE_OPERAND (exp
, 1))))
9825 /* If TEM's type is a union of variable size, pass TARGET to the inner
9826 computation, since it will need a temporary and TARGET is known
9827 to have to do. This occurs in unchecked conversion in Ada. */
9830 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
9831 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
9833 && modifier
!= EXPAND_STACK_PARM
9834 ? target
: NULL_RTX
),
9836 (modifier
== EXPAND_INITIALIZER
9837 || modifier
== EXPAND_CONST_ADDRESS
9838 || modifier
== EXPAND_STACK_PARM
)
9839 ? modifier
: EXPAND_NORMAL
);
9842 /* If the bitfield is volatile, we want to access it in the
9843 field's mode, not the computed mode.
9844 If a MEM has VOIDmode (external with incomplete type),
9845 use BLKmode for it instead. */
9848 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
9849 op0
= adjust_address (op0
, mode1
, 0);
9850 else if (GET_MODE (op0
) == VOIDmode
)
9851 op0
= adjust_address (op0
, BLKmode
, 0);
9855 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
9857 /* If we have either an offset, a BLKmode result, or a reference
9858 outside the underlying object, we must force it to memory.
9859 Such a case can occur in Ada if we have unchecked conversion
9860 of an expression from a scalar type to an aggregate type or
9861 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9862 passed a partially uninitialized object or a view-conversion
9863 to a larger size. */
9864 must_force_mem
= (offset
9866 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
9868 /* Handle CONCAT first. */
9869 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
9872 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
9875 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9878 op0
= XEXP (op0
, 0);
9879 mode2
= GET_MODE (op0
);
9881 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9882 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
9886 op0
= XEXP (op0
, 1);
9888 mode2
= GET_MODE (op0
);
9891 /* Otherwise force into memory. */
9895 /* If this is a constant, put it in a register if it is a legitimate
9896 constant and we don't need a memory reference. */
9897 if (CONSTANT_P (op0
)
9899 && targetm
.legitimate_constant_p (mode2
, op0
)
9901 op0
= force_reg (mode2
, op0
);
9903 /* Otherwise, if this is a constant, try to force it to the constant
9904 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9905 is a legitimate constant. */
9906 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
9907 op0
= validize_mem (memloc
);
9909 /* Otherwise, if this is a constant or the object is not in memory
9910 and need be, put it there. */
9911 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
9913 tree nt
= build_qualified_type (TREE_TYPE (tem
),
9914 (TYPE_QUALS (TREE_TYPE (tem
))
9915 | TYPE_QUAL_CONST
));
9916 memloc
= assign_temp (nt
, 1, 1, 1);
9917 emit_move_insn (memloc
, op0
);
9919 mem_attrs_from_type
= true;
9924 enum machine_mode address_mode
;
9925 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
9928 gcc_assert (MEM_P (op0
));
9931 = targetm
.addr_space
.address_mode (MEM_ADDR_SPACE (op0
));
9932 if (GET_MODE (offset_rtx
) != address_mode
)
9933 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
9935 if (GET_MODE (op0
) == BLKmode
9936 /* A constant address in OP0 can have VOIDmode, we must
9937 not try to call force_reg in that case. */
9938 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
9940 && (bitpos
% bitsize
) == 0
9941 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
9942 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
9944 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
9948 op0
= offset_address (op0
, offset_rtx
,
9949 highest_pow2_factor (offset
));
9952 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
9953 record its alignment as BIGGEST_ALIGNMENT. */
9954 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
9955 && is_aligning_offset (offset
, tem
))
9956 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
9958 /* Don't forget about volatility even if this is a bitfield. */
9959 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
9961 if (op0
== orig_op0
)
9962 op0
= copy_rtx (op0
);
9964 MEM_VOLATILE_P (op0
) = 1;
9967 /* In cases where an aligned union has an unaligned object
9968 as a field, we might be extracting a BLKmode value from
9969 an integer-mode (e.g., SImode) object. Handle this case
9970 by doing the extract into an object as wide as the field
9971 (which we know to be the width of a basic mode), then
9972 storing into memory, and changing the mode to BLKmode. */
9973 if (mode1
== VOIDmode
9974 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
9975 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
9976 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
9977 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
9978 && modifier
!= EXPAND_CONST_ADDRESS
9979 && modifier
!= EXPAND_INITIALIZER
)
9980 /* If the field is volatile, we always want an aligned
9981 access. Do this in following two situations:
9982 1. the access is not already naturally
9983 aligned, otherwise "normal" (non-bitfield) volatile fields
9984 become non-addressable.
9985 2. the bitsize is narrower than the access size. Need
9986 to extract bitfields from the access. */
9987 || (volatilep
&& flag_strict_volatile_bitfields
> 0
9988 && (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0
9989 || (mode1
!= BLKmode
9990 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)))
9991 /* If the field isn't aligned enough to fetch as a memref,
9992 fetch it as a bit field. */
9993 || (mode1
!= BLKmode
9994 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
9995 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
9997 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
9998 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
9999 && ((modifier
== EXPAND_CONST_ADDRESS
10000 || modifier
== EXPAND_INITIALIZER
)
10002 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10003 || (bitpos
% BITS_PER_UNIT
!= 0)))
10004 /* If the type and the field are a constant size and the
10005 size of the type isn't the same size as the bitfield,
10006 we must use bitfield operations. */
10008 && TYPE_SIZE (TREE_TYPE (exp
))
10009 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10010 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10013 enum machine_mode ext_mode
= mode
;
10015 if (ext_mode
== BLKmode
10016 && ! (target
!= 0 && MEM_P (op0
)
10018 && bitpos
% BITS_PER_UNIT
== 0))
10019 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10021 if (ext_mode
== BLKmode
)
10024 target
= assign_temp (type
, 0, 1, 1);
10029 /* In this case, BITPOS must start at a byte boundary and
10030 TARGET, if specified, must be a MEM. */
10031 gcc_assert (MEM_P (op0
)
10032 && (!target
|| MEM_P (target
))
10033 && !(bitpos
% BITS_PER_UNIT
));
10035 emit_block_move (target
,
10036 adjust_address (op0
, VOIDmode
,
10037 bitpos
/ BITS_PER_UNIT
),
10038 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10040 (modifier
== EXPAND_STACK_PARM
10041 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10046 op0
= validize_mem (op0
);
10048 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10049 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10051 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
, packedp
,
10052 (modifier
== EXPAND_STACK_PARM
10053 ? NULL_RTX
: target
),
10054 ext_mode
, ext_mode
);
10056 /* If the result is a record type and BITSIZE is narrower than
10057 the mode of OP0, an integral mode, and this is a big endian
10058 machine, we must put the field into the high-order bits. */
10059 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10060 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10061 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10062 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10063 GET_MODE_BITSIZE (GET_MODE (op0
))
10064 - bitsize
, op0
, 1);
10066 /* If the result type is BLKmode, store the data into a temporary
10067 of the appropriate type, but with the mode corresponding to the
10068 mode for the data we have (op0's mode). It's tempting to make
10069 this a constant type, since we know it's only being stored once,
10070 but that can cause problems if we are taking the address of this
10071 COMPONENT_REF because the MEM of any reference via that address
10072 will have flags corresponding to the type, which will not
10073 necessarily be constant. */
10074 if (mode
== BLKmode
)
10078 new_rtx
= assign_stack_temp_for_type (ext_mode
,
10079 GET_MODE_BITSIZE (ext_mode
),
10081 emit_move_insn (new_rtx
, op0
);
10082 op0
= copy_rtx (new_rtx
);
10083 PUT_MODE (op0
, BLKmode
);
10089 /* If the result is BLKmode, use that to access the object
10091 if (mode
== BLKmode
)
10094 /* Get a reference to just this component. */
10095 if (modifier
== EXPAND_CONST_ADDRESS
10096 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10097 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10099 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10101 if (op0
== orig_op0
)
10102 op0
= copy_rtx (op0
);
10104 /* If op0 is a temporary because of forcing to memory, pass only the
10105 type to set_mem_attributes so that the original expression is never
10106 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10107 if (mem_attrs_from_type
)
10108 set_mem_attributes (op0
, type
, 0);
10110 set_mem_attributes (op0
, exp
, 0);
10112 if (REG_P (XEXP (op0
, 0)))
10113 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10115 MEM_VOLATILE_P (op0
) |= volatilep
;
10116 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10117 || modifier
== EXPAND_CONST_ADDRESS
10118 || modifier
== EXPAND_INITIALIZER
)
10120 else if (target
== 0)
10121 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10123 convert_move (target
, op0
, unsignedp
);
10128 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10131 /* All valid uses of __builtin_va_arg_pack () are removed during
10133 if (CALL_EXPR_VA_ARG_PACK (exp
))
10134 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10136 tree fndecl
= get_callee_fndecl (exp
), attr
;
10139 && (attr
= lookup_attribute ("error",
10140 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10141 error ("%Kcall to %qs declared with attribute error: %s",
10142 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10143 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10145 && (attr
= lookup_attribute ("warning",
10146 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10147 warning_at (tree_nonartificial_location (exp
),
10148 0, "%Kcall to %qs declared with attribute warning: %s",
10149 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10150 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10152 /* Check for a built-in function. */
10153 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10155 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10156 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10159 return expand_call (exp
, target
, ignore
);
10161 case VIEW_CONVERT_EXPR
:
10164 /* If we are converting to BLKmode, try to avoid an intermediate
10165 temporary by fetching an inner memory reference. */
10166 if (mode
== BLKmode
10167 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10168 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10169 && handled_component_p (treeop0
))
10171 enum machine_mode mode1
;
10172 HOST_WIDE_INT bitsize
, bitpos
;
10177 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10178 &offset
, &mode1
, &unsignedp
, &volatilep
,
10182 /* ??? We should work harder and deal with non-zero offsets. */
10184 && (bitpos
% BITS_PER_UNIT
) == 0
10186 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) == 0)
10188 /* See the normal_inner_ref case for the rationale. */
10190 = expand_expr (tem
,
10191 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10192 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10194 && modifier
!= EXPAND_STACK_PARM
10195 ? target
: NULL_RTX
),
10197 (modifier
== EXPAND_INITIALIZER
10198 || modifier
== EXPAND_CONST_ADDRESS
10199 || modifier
== EXPAND_STACK_PARM
)
10200 ? modifier
: EXPAND_NORMAL
);
10202 if (MEM_P (orig_op0
))
10206 /* Get a reference to just this component. */
10207 if (modifier
== EXPAND_CONST_ADDRESS
10208 || modifier
== EXPAND_SUM
10209 || modifier
== EXPAND_INITIALIZER
)
10210 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10212 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10214 if (op0
== orig_op0
)
10215 op0
= copy_rtx (op0
);
10217 set_mem_attributes (op0
, treeop0
, 0);
10218 if (REG_P (XEXP (op0
, 0)))
10219 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10221 MEM_VOLATILE_P (op0
) |= volatilep
;
10227 op0
= expand_expr (treeop0
,
10228 NULL_RTX
, VOIDmode
, modifier
);
10230 /* If the input and output modes are both the same, we are done. */
10231 if (mode
== GET_MODE (op0
))
10233 /* If neither mode is BLKmode, and both modes are the same size
10234 then we can use gen_lowpart. */
10235 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10236 && (GET_MODE_PRECISION (mode
)
10237 == GET_MODE_PRECISION (GET_MODE (op0
)))
10238 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10240 if (GET_CODE (op0
) == SUBREG
)
10241 op0
= force_reg (GET_MODE (op0
), op0
);
10242 temp
= gen_lowpart_common (mode
, op0
);
10247 if (!REG_P (op0
) && !MEM_P (op0
))
10248 op0
= force_reg (GET_MODE (op0
), op0
);
10249 op0
= gen_lowpart (mode
, op0
);
10252 /* If both types are integral, convert from one mode to the other. */
10253 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10254 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10255 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10256 /* As a last resort, spill op0 to memory, and reload it in a
10258 else if (!MEM_P (op0
))
10260 /* If the operand is not a MEM, force it into memory. Since we
10261 are going to be changing the mode of the MEM, don't call
10262 force_const_mem for constants because we don't allow pool
10263 constants to change mode. */
10264 tree inner_type
= TREE_TYPE (treeop0
);
10266 gcc_assert (!TREE_ADDRESSABLE (exp
));
10268 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10270 = assign_stack_temp_for_type
10271 (TYPE_MODE (inner_type
),
10272 GET_MODE_SIZE (TYPE_MODE (inner_type
)), 0, inner_type
);
10274 emit_move_insn (target
, op0
);
10278 /* At this point, OP0 is in the correct mode. If the output type is
10279 such that the operand is known to be aligned, indicate that it is.
10280 Otherwise, we need only be concerned about alignment for non-BLKmode
10284 enum insn_code icode
;
10286 op0
= copy_rtx (op0
);
10288 if (TYPE_ALIGN_OK (type
))
10289 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10290 else if (mode
!= BLKmode
10291 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
)
10292 /* If the target does have special handling for unaligned
10293 loads of mode then use them. */
10294 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10295 != CODE_FOR_nothing
))
10299 op0
= adjust_address (op0
, mode
, 0);
10300 /* We've already validated the memory, and we're creating a
10301 new pseudo destination. The predicates really can't
10303 reg
= gen_reg_rtx (mode
);
10305 /* Nor can the insn generator. */
10306 insn
= GEN_FCN (icode
) (reg
, op0
);
10310 else if (STRICT_ALIGNMENT
10312 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10314 tree inner_type
= TREE_TYPE (treeop0
);
10315 HOST_WIDE_INT temp_size
10316 = MAX (int_size_in_bytes (inner_type
),
10317 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10319 = assign_stack_temp_for_type (mode
, temp_size
, 0, type
);
10320 rtx new_with_op0_mode
10321 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10323 gcc_assert (!TREE_ADDRESSABLE (exp
));
10325 if (GET_MODE (op0
) == BLKmode
)
10326 emit_block_move (new_with_op0_mode
, op0
,
10327 GEN_INT (GET_MODE_SIZE (mode
)),
10328 (modifier
== EXPAND_STACK_PARM
10329 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10331 emit_move_insn (new_with_op0_mode
, op0
);
10336 op0
= adjust_address (op0
, mode
, 0);
10343 tree lhs
= treeop0
;
10344 tree rhs
= treeop1
;
10345 gcc_assert (ignore
);
10347 /* Check for |= or &= of a bitfield of size one into another bitfield
10348 of size 1. In this case, (unless we need the result of the
10349 assignment) we can do this more efficiently with a
10350 test followed by an assignment, if necessary.
10352 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10353 things change so we do, this code should be enhanced to
10355 if (TREE_CODE (lhs
) == COMPONENT_REF
10356 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10357 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10358 && TREE_OPERAND (rhs
, 0) == lhs
10359 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10360 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10361 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10363 rtx label
= gen_label_rtx ();
10364 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10365 do_jump (TREE_OPERAND (rhs
, 1),
10367 value
? 0 : label
, -1);
10368 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10369 MOVE_NONTEMPORAL (exp
));
10370 do_pending_stack_adjust ();
10371 emit_label (label
);
10375 expand_assignment (lhs
, rhs
, MOVE_NONTEMPORAL (exp
));
10380 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10382 case REALPART_EXPR
:
10383 op0
= expand_normal (treeop0
);
10384 return read_complex_part (op0
, false);
10386 case IMAGPART_EXPR
:
10387 op0
= expand_normal (treeop0
);
10388 return read_complex_part (op0
, true);
10395 /* Expanded in cfgexpand.c. */
10396 gcc_unreachable ();
10398 case TRY_CATCH_EXPR
:
10400 case EH_FILTER_EXPR
:
10401 case TRY_FINALLY_EXPR
:
10402 /* Lowered by tree-eh.c. */
10403 gcc_unreachable ();
10405 case WITH_CLEANUP_EXPR
:
10406 case CLEANUP_POINT_EXPR
:
10408 case CASE_LABEL_EXPR
:
10413 case COMPOUND_EXPR
:
10414 case PREINCREMENT_EXPR
:
10415 case PREDECREMENT_EXPR
:
10416 case POSTINCREMENT_EXPR
:
10417 case POSTDECREMENT_EXPR
:
10420 /* Lowered by gimplify.c. */
10421 gcc_unreachable ();
10424 /* Function descriptors are not valid except for as
10425 initialization constants, and should not be expanded. */
10426 gcc_unreachable ();
10428 case WITH_SIZE_EXPR
:
10429 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10430 have pulled out the size to use in whatever context it needed. */
10431 return expand_expr_real (treeop0
, original_target
, tmode
,
10432 modifier
, alt_rtl
);
10434 case COMPOUND_LITERAL_EXPR
:
10436 /* Initialize the anonymous variable declared in the compound
10437 literal, then return the variable. */
10438 tree decl
= COMPOUND_LITERAL_EXPR_DECL (exp
);
10440 /* Create RTL for this variable. */
10441 if (!DECL_RTL_SET_P (decl
))
10443 if (DECL_HARD_REGISTER (decl
))
10444 /* The user specified an assembler name for this variable.
10445 Set that up now. */
10446 rest_of_decl_compilation (decl
, 0, 0);
10448 expand_decl (decl
);
10451 return expand_expr_real (decl
, original_target
, tmode
,
10452 modifier
, alt_rtl
);
10456 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10460 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10461 signedness of TYPE), possibly returning the result in TARGET. */
10463 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10465 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10466 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10468 /* For constant values, reduce using build_int_cst_type. */
10469 if (CONST_INT_P (exp
))
10471 HOST_WIDE_INT value
= INTVAL (exp
);
10472 tree t
= build_int_cst_type (type
, value
);
10473 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10475 else if (TYPE_UNSIGNED (type
))
10477 rtx mask
= immed_double_int_const (double_int_mask (prec
),
10479 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
10483 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10484 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10485 exp
, count
, target
, 0);
10486 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10487 exp
, count
, target
, 0);
10491 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10492 when applied to the address of EXP produces an address known to be
10493 aligned more than BIGGEST_ALIGNMENT. */
10496 is_aligning_offset (const_tree offset
, const_tree exp
)
10498 /* Strip off any conversions. */
10499 while (CONVERT_EXPR_P (offset
))
10500 offset
= TREE_OPERAND (offset
, 0);
10502 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10503 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10504 if (TREE_CODE (offset
) != BIT_AND_EXPR
10505 || !host_integerp (TREE_OPERAND (offset
, 1), 1)
10506 || compare_tree_int (TREE_OPERAND (offset
, 1),
10507 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10508 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset
, 1), 1) + 1) < 0)
10511 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10512 It must be NEGATE_EXPR. Then strip any more conversions. */
10513 offset
= TREE_OPERAND (offset
, 0);
10514 while (CONVERT_EXPR_P (offset
))
10515 offset
= TREE_OPERAND (offset
, 0);
10517 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10520 offset
= TREE_OPERAND (offset
, 0);
10521 while (CONVERT_EXPR_P (offset
))
10522 offset
= TREE_OPERAND (offset
, 0);
10524 /* This must now be the address of EXP. */
10525 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10528 /* Return the tree node if an ARG corresponds to a string constant or zero
10529 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10530 in bytes within the string that ARG is accessing. The type of the
10531 offset will be `sizetype'. */
10534 string_constant (tree arg
, tree
*ptr_offset
)
10536 tree array
, offset
, lower_bound
;
10539 if (TREE_CODE (arg
) == ADDR_EXPR
)
10541 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10543 *ptr_offset
= size_zero_node
;
10544 return TREE_OPERAND (arg
, 0);
10546 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10548 array
= TREE_OPERAND (arg
, 0);
10549 offset
= size_zero_node
;
10551 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10553 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10554 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10555 if (TREE_CODE (array
) != STRING_CST
10556 && TREE_CODE (array
) != VAR_DECL
)
10559 /* Check if the array has a nonzero lower bound. */
10560 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10561 if (!integer_zerop (lower_bound
))
10563 /* If the offset and base aren't both constants, return 0. */
10564 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10566 if (TREE_CODE (offset
) != INTEGER_CST
)
10568 /* Adjust offset by the lower bound. */
10569 offset
= size_diffop (fold_convert (sizetype
, offset
),
10570 fold_convert (sizetype
, lower_bound
));
10573 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10575 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10576 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10577 if (TREE_CODE (array
) != ADDR_EXPR
)
10579 array
= TREE_OPERAND (array
, 0);
10580 if (TREE_CODE (array
) != STRING_CST
10581 && TREE_CODE (array
) != VAR_DECL
)
10587 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10589 tree arg0
= TREE_OPERAND (arg
, 0);
10590 tree arg1
= TREE_OPERAND (arg
, 1);
10595 if (TREE_CODE (arg0
) == ADDR_EXPR
10596 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10597 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10599 array
= TREE_OPERAND (arg0
, 0);
10602 else if (TREE_CODE (arg1
) == ADDR_EXPR
10603 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10604 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10606 array
= TREE_OPERAND (arg1
, 0);
10615 if (TREE_CODE (array
) == STRING_CST
)
10617 *ptr_offset
= fold_convert (sizetype
, offset
);
10620 else if (TREE_CODE (array
) == VAR_DECL
10621 || TREE_CODE (array
) == CONST_DECL
)
10625 /* Variables initialized to string literals can be handled too. */
10626 if (!const_value_known_p (array
)
10627 || !DECL_INITIAL (array
)
10628 || TREE_CODE (DECL_INITIAL (array
)) != STRING_CST
)
10631 /* Avoid const char foo[4] = "abcde"; */
10632 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10633 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10634 || (length
= TREE_STRING_LENGTH (DECL_INITIAL (array
))) <= 0
10635 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10638 /* If variable is bigger than the string literal, OFFSET must be constant
10639 and inside of the bounds of the string literal. */
10640 offset
= fold_convert (sizetype
, offset
);
10641 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10642 && (! host_integerp (offset
, 1)
10643 || compare_tree_int (offset
, length
) >= 0))
10646 *ptr_offset
= offset
;
10647 return DECL_INITIAL (array
);
10653 /* Generate code to calculate OPS, and exploded expression
10654 using a store-flag instruction and return an rtx for the result.
10655 OPS reflects a comparison.
10657 If TARGET is nonzero, store the result there if convenient.
10659 Return zero if there is no suitable set-flag instruction
10660 available on this machine.
10662 Once expand_expr has been called on the arguments of the comparison,
10663 we are committed to doing the store flag, since it is not safe to
10664 re-evaluate the expression. We emit the store-flag insn by calling
10665 emit_store_flag, but only expand the arguments if we have a reason
10666 to believe that emit_store_flag will be successful. If we think that
10667 it will, but it isn't, we have to simulate the store-flag with a
10668 set/jump/set sequence. */
10671 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10673 enum rtx_code code
;
10674 tree arg0
, arg1
, type
;
10676 enum machine_mode operand_mode
;
10679 rtx subtarget
= target
;
10680 location_t loc
= ops
->location
;
10685 /* Don't crash if the comparison was erroneous. */
10686 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10689 type
= TREE_TYPE (arg0
);
10690 operand_mode
= TYPE_MODE (type
);
10691 unsignedp
= TYPE_UNSIGNED (type
);
10693 /* We won't bother with BLKmode store-flag operations because it would mean
10694 passing a lot of information to emit_store_flag. */
10695 if (operand_mode
== BLKmode
)
10698 /* We won't bother with store-flag operations involving function pointers
10699 when function pointers must be canonicalized before comparisons. */
10700 #ifdef HAVE_canonicalize_funcptr_for_compare
10701 if (HAVE_canonicalize_funcptr_for_compare
10702 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10703 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10705 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10706 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10707 == FUNCTION_TYPE
))))
10714 /* For vector typed comparisons emit code to generate the desired
10715 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10716 expander for this. */
10717 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10719 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10720 tree if_true
= constant_boolean_node (true, ops
->type
);
10721 tree if_false
= constant_boolean_node (false, ops
->type
);
10722 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10725 /* For vector typed comparisons emit code to generate the desired
10726 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10727 expander for this. */
10728 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10730 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10731 tree if_true
= constant_boolean_node (true, ops
->type
);
10732 tree if_false
= constant_boolean_node (false, ops
->type
);
10733 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10736 /* Get the rtx comparison code to use. We know that EXP is a comparison
10737 operation of some type. Some comparisons against 1 and -1 can be
10738 converted to comparisons with zero. Do so here so that the tests
10739 below will be aware that we have a comparison with zero. These
10740 tests will not catch constants in the first operand, but constants
10741 are rarely passed as the first operand. */
10752 if (integer_onep (arg1
))
10753 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10755 code
= unsignedp
? LTU
: LT
;
10758 if (! unsignedp
&& integer_all_onesp (arg1
))
10759 arg1
= integer_zero_node
, code
= LT
;
10761 code
= unsignedp
? LEU
: LE
;
10764 if (! unsignedp
&& integer_all_onesp (arg1
))
10765 arg1
= integer_zero_node
, code
= GE
;
10767 code
= unsignedp
? GTU
: GT
;
10770 if (integer_onep (arg1
))
10771 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10773 code
= unsignedp
? GEU
: GE
;
10776 case UNORDERED_EXPR
:
10802 gcc_unreachable ();
10805 /* Put a constant second. */
10806 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
10807 || TREE_CODE (arg0
) == FIXED_CST
)
10809 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
10810 code
= swap_condition (code
);
10813 /* If this is an equality or inequality test of a single bit, we can
10814 do this by shifting the bit being tested to the low-order bit and
10815 masking the result with the constant 1. If the condition was EQ,
10816 we xor it with 1. This does not require an scc insn and is faster
10817 than an scc insn even if we have it.
10819 The code to make this transformation was moved into fold_single_bit_test,
10820 so we just call into the folder and expand its result. */
10822 if ((code
== NE
|| code
== EQ
)
10823 && integer_zerop (arg1
)
10824 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
10826 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
10828 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
10830 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
10831 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10832 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
10833 gimple_assign_rhs1 (srcstmt
),
10834 gimple_assign_rhs2 (srcstmt
));
10835 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
10837 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
10841 if (! get_subtarget (target
)
10842 || GET_MODE (subtarget
) != operand_mode
)
10845 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10848 target
= gen_reg_rtx (mode
);
10850 /* Try a cstore if possible. */
10851 return emit_store_flag_force (target
, code
, op0
, op1
,
10852 operand_mode
, unsignedp
,
10853 (TYPE_PRECISION (ops
->type
) == 1
10854 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
10858 /* Stubs in case we haven't got a casesi insn. */
10859 #ifndef HAVE_casesi
10860 # define HAVE_casesi 0
10861 # define gen_casesi(a, b, c, d, e) (0)
10862 # define CODE_FOR_casesi CODE_FOR_nothing
10865 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10866 0 otherwise (i.e. if there is no casesi instruction). */
10868 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
10869 rtx table_label ATTRIBUTE_UNUSED
, rtx default_label
,
10870 rtx fallback_label ATTRIBUTE_UNUSED
)
10872 struct expand_operand ops
[5];
10873 enum machine_mode index_mode
= SImode
;
10874 rtx op1
, op2
, index
;
10879 /* Convert the index to SImode. */
10880 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
10882 enum machine_mode omode
= TYPE_MODE (index_type
);
10883 rtx rangertx
= expand_normal (range
);
10885 /* We must handle the endpoints in the original mode. */
10886 index_expr
= build2 (MINUS_EXPR
, index_type
,
10887 index_expr
, minval
);
10888 minval
= integer_zero_node
;
10889 index
= expand_normal (index_expr
);
10891 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
10892 omode
, 1, default_label
);
10893 /* Now we can safely truncate. */
10894 index
= convert_to_mode (index_mode
, index
, 0);
10898 if (TYPE_MODE (index_type
) != index_mode
)
10900 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
10901 index_expr
= fold_convert (index_type
, index_expr
);
10904 index
= expand_normal (index_expr
);
10907 do_pending_stack_adjust ();
10909 op1
= expand_normal (minval
);
10910 op2
= expand_normal (range
);
10912 create_input_operand (&ops
[0], index
, index_mode
);
10913 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
10914 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
10915 create_fixed_operand (&ops
[3], table_label
);
10916 create_fixed_operand (&ops
[4], (default_label
10918 : fallback_label
));
10919 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
10923 /* Attempt to generate a tablejump instruction; same concept. */
10924 #ifndef HAVE_tablejump
10925 #define HAVE_tablejump 0
10926 #define gen_tablejump(x, y) (0)
10929 /* Subroutine of the next function.
10931 INDEX is the value being switched on, with the lowest value
10932 in the table already subtracted.
10933 MODE is its expected mode (needed if INDEX is constant).
10934 RANGE is the length of the jump table.
10935 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10937 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10938 index value is out of range. */
10941 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
10946 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
10947 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
10949 /* Do an unsigned comparison (in the proper mode) between the index
10950 expression and the value which represents the length of the range.
10951 Since we just finished subtracting the lower bound of the range
10952 from the index expression, this comparison allows us to simultaneously
10953 check that the original index expression value is both greater than
10954 or equal to the minimum value of the range and less than or equal to
10955 the maximum value of the range. */
10958 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
10961 /* If index is in range, it must fit in Pmode.
10962 Convert to Pmode so we can index with it. */
10964 index
= convert_to_mode (Pmode
, index
, 1);
10966 /* Don't let a MEM slip through, because then INDEX that comes
10967 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
10968 and break_out_memory_refs will go to work on it and mess it up. */
10969 #ifdef PIC_CASE_VECTOR_ADDRESS
10970 if (flag_pic
&& !REG_P (index
))
10971 index
= copy_to_mode_reg (Pmode
, index
);
10974 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
10975 GET_MODE_SIZE, because this indicates how large insns are. The other
10976 uses should all be Pmode, because they are addresses. This code
10977 could fail if addresses and insns are not the same size. */
10978 index
= gen_rtx_PLUS (Pmode
,
10979 gen_rtx_MULT (Pmode
, index
,
10980 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE
))),
10981 gen_rtx_LABEL_REF (Pmode
, table_label
));
10982 #ifdef PIC_CASE_VECTOR_ADDRESS
10984 index
= PIC_CASE_VECTOR_ADDRESS (index
);
10987 index
= memory_address (CASE_VECTOR_MODE
, index
);
10988 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
10989 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
10990 convert_move (temp
, vector
, 0);
10992 emit_jump_insn (gen_tablejump (temp
, table_label
));
10994 /* If we are generating PIC code or if the table is PC-relative, the
10995 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
10996 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11001 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11002 rtx table_label
, rtx default_label
)
11006 if (! HAVE_tablejump
)
11009 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11010 fold_convert (index_type
, index_expr
),
11011 fold_convert (index_type
, minval
));
11012 index
= expand_normal (index_expr
);
11013 do_pending_stack_adjust ();
11015 do_tablejump (index
, TYPE_MODE (index_type
),
11016 convert_modes (TYPE_MODE (index_type
),
11017 TYPE_MODE (TREE_TYPE (range
)),
11018 expand_normal (range
),
11019 TYPE_UNSIGNED (TREE_TYPE (range
))),
11020 table_label
, default_label
);
11024 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11026 const_vector_from_tree (tree exp
)
11032 enum machine_mode inner
, mode
;
11034 mode
= TYPE_MODE (TREE_TYPE (exp
));
11036 if (initializer_zerop (exp
))
11037 return CONST0_RTX (mode
);
11039 units
= GET_MODE_NUNITS (mode
);
11040 inner
= GET_MODE_INNER (mode
);
11042 v
= rtvec_alloc (units
);
11044 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11046 elt
= VECTOR_CST_ELT (exp
, i
);
11048 if (TREE_CODE (elt
) == REAL_CST
)
11049 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11051 else if (TREE_CODE (elt
) == FIXED_CST
)
11052 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11055 RTVEC_ELT (v
, i
) = immed_double_int_const (tree_to_double_int (elt
),
11059 return gen_rtx_CONST_VECTOR (mode
, v
);
11062 /* Build a decl for a personality function given a language prefix. */
11065 build_personality_function (const char *lang
)
11067 const char *unwind_and_version
;
11071 switch (targetm_common
.except_unwind_info (&global_options
))
11076 unwind_and_version
= "_sj0";
11080 unwind_and_version
= "_v0";
11083 gcc_unreachable ();
11086 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11088 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11089 long_long_unsigned_type_node
,
11090 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11091 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11092 get_identifier (name
), type
);
11093 DECL_ARTIFICIAL (decl
) = 1;
11094 DECL_EXTERNAL (decl
) = 1;
11095 TREE_PUBLIC (decl
) = 1;
11097 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11098 are the flags assigned by targetm.encode_section_info. */
11099 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11104 /* Extracts the personality function of DECL and returns the corresponding
11108 get_personality_function (tree decl
)
11110 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11111 enum eh_personality_kind pk
;
11113 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11114 if (pk
== eh_personality_none
)
11118 && pk
== eh_personality_any
)
11119 personality
= lang_hooks
.eh_personality ();
11121 if (pk
== eh_personality_lang
)
11122 gcc_assert (personality
!= NULL_TREE
);
11124 return XEXP (DECL_RTL (personality
), 0);
11127 #include "gt-expr.h"