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. */
42 #include "typeclass.h"
44 #include "langhooks.h"
47 #include "tree-iterator.h"
48 #include "tree-flow.h"
50 #include "common/common-target.h"
53 #include "diagnostic.h"
54 #include "ssaexpand.h"
55 #include "target-globals.h"
58 /* Decide whether a function's arguments should be processed
59 from first to last or from last to first.
61 They should if the stack and args grow in opposite directions, but
62 only if we have push insns. */
66 #ifndef PUSH_ARGS_REVERSED
67 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
68 #define PUSH_ARGS_REVERSED /* If it's last to first. */
74 #ifndef STACK_PUSH_CODE
75 #ifdef STACK_GROWS_DOWNWARD
76 #define STACK_PUSH_CODE PRE_DEC
78 #define STACK_PUSH_CODE PRE_INC
83 /* If this is nonzero, we do not bother generating VOLATILE
84 around volatile memory references, and we are willing to
85 output indirect addresses. If cse is to follow, we reject
86 indirect addresses so a useful potential cse is generated;
87 if it is used only once, instruction combination will produce
88 the same indirect address eventually. */
91 /* This structure is used by move_by_pieces to describe the move to
93 struct move_by_pieces_d
102 int explicit_inc_from
;
103 unsigned HOST_WIDE_INT len
;
104 HOST_WIDE_INT offset
;
108 /* This structure is used by store_by_pieces to describe the clear to
111 struct store_by_pieces_d
117 unsigned HOST_WIDE_INT len
;
118 HOST_WIDE_INT offset
;
119 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
);
124 static void move_by_pieces_1 (rtx (*) (rtx
, ...), enum machine_mode
,
125 struct move_by_pieces_d
*);
126 static bool block_move_libcall_safe_for_call_parm (void);
127 static bool emit_block_move_via_movmem (rtx
, rtx
, rtx
, unsigned, unsigned, HOST_WIDE_INT
);
128 static tree
emit_block_move_libcall_fn (int);
129 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned);
130 static rtx
clear_by_pieces_1 (void *, HOST_WIDE_INT
, enum machine_mode
);
131 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
132 static void store_by_pieces_1 (struct store_by_pieces_d
*, unsigned int);
133 static void store_by_pieces_2 (rtx (*) (rtx
, ...), enum machine_mode
,
134 struct store_by_pieces_d
*);
135 static tree
clear_storage_libcall_fn (int);
136 static rtx
compress_float_constant (rtx
, rtx
);
137 static rtx
get_subtarget (rtx
);
138 static void store_constructor_field (rtx
, unsigned HOST_WIDE_INT
,
139 HOST_WIDE_INT
, enum machine_mode
,
140 tree
, tree
, int, alias_set_type
);
141 static void store_constructor (tree
, rtx
, int, HOST_WIDE_INT
);
142 static rtx
store_field (rtx
, HOST_WIDE_INT
, HOST_WIDE_INT
,
143 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
145 tree
, tree
, alias_set_type
, bool);
147 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
149 static int is_aligning_offset (const_tree
, const_tree
);
150 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
151 enum expand_modifier
);
152 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
153 static rtx
do_store_flag (sepops
, rtx
, enum machine_mode
);
155 static void emit_single_push_insn (enum machine_mode
, rtx
, tree
);
157 static void do_tablejump (rtx
, enum machine_mode
, rtx
, rtx
, rtx
, int);
158 static rtx
const_vector_from_tree (tree
);
159 static void write_complex_part (rtx
, rtx
, bool);
161 /* This macro is used to determine whether move_by_pieces should be called
162 to perform a structure copy. */
163 #ifndef MOVE_BY_PIECES_P
164 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
165 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
166 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
169 /* This macro is used to determine whether clear_by_pieces should be
170 called to clear storage. */
171 #ifndef CLEAR_BY_PIECES_P
172 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
173 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
174 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
177 /* This macro is used to determine whether store_by_pieces should be
178 called to "memset" storage with byte values other than zero. */
179 #ifndef SET_BY_PIECES_P
180 #define SET_BY_PIECES_P(SIZE, ALIGN) \
181 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
182 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
185 /* This macro is used to determine whether store_by_pieces should be
186 called to "memcpy" storage when the source is a constant string. */
187 #ifndef STORE_BY_PIECES_P
188 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
189 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
190 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
193 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
195 #ifndef SLOW_UNALIGNED_ACCESS
196 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
199 /* This is run to set up which modes can be used
200 directly in memory and to initialize the block move optab. It is run
201 at the beginning of compilation and when the target is reinitialized. */
204 init_expr_target (void)
207 enum machine_mode mode
;
212 /* Try indexing by frame ptr and try by stack ptr.
213 It is known that on the Convex the stack ptr isn't a valid index.
214 With luck, one or the other is valid on any machine. */
215 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
216 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
218 /* A scratch register we can modify in-place below to avoid
219 useless RTL allocations. */
220 reg
= gen_rtx_REG (VOIDmode
, -1);
222 insn
= rtx_alloc (INSN
);
223 pat
= gen_rtx_SET (VOIDmode
, NULL_RTX
, NULL_RTX
);
224 PATTERN (insn
) = pat
;
226 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
227 mode
= (enum machine_mode
) ((int) mode
+ 1))
231 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
232 PUT_MODE (mem
, mode
);
233 PUT_MODE (mem1
, mode
);
234 PUT_MODE (reg
, mode
);
236 /* See if there is some register that can be used in this mode and
237 directly loaded or stored from memory. */
239 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
240 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
241 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
244 if (! HARD_REGNO_MODE_OK (regno
, mode
))
247 SET_REGNO (reg
, regno
);
250 SET_DEST (pat
) = reg
;
251 if (recog (pat
, insn
, &num_clobbers
) >= 0)
252 direct_load
[(int) mode
] = 1;
254 SET_SRC (pat
) = mem1
;
255 SET_DEST (pat
) = reg
;
256 if (recog (pat
, insn
, &num_clobbers
) >= 0)
257 direct_load
[(int) mode
] = 1;
260 SET_DEST (pat
) = mem
;
261 if (recog (pat
, insn
, &num_clobbers
) >= 0)
262 direct_store
[(int) mode
] = 1;
265 SET_DEST (pat
) = mem1
;
266 if (recog (pat
, insn
, &num_clobbers
) >= 0)
267 direct_store
[(int) mode
] = 1;
271 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
273 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
274 mode
= GET_MODE_WIDER_MODE (mode
))
276 enum machine_mode srcmode
;
277 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
278 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
282 ic
= can_extend_p (mode
, srcmode
, 0);
283 if (ic
== CODE_FOR_nothing
)
286 PUT_MODE (mem
, srcmode
);
288 if (insn_operand_matches (ic
, 1, mem
))
289 float_extend_from_mem
[mode
][srcmode
] = true;
294 /* This is run at the start of compiling a function. */
299 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
302 /* Copy data from FROM to TO, where the machine modes are not the same.
303 Both modes may be integer, or both may be floating, or both may be
305 UNSIGNEDP should be nonzero if FROM is an unsigned type.
306 This causes zero-extension instead of sign-extension. */
309 convert_move (rtx to
, rtx from
, int unsignedp
)
311 enum machine_mode to_mode
= GET_MODE (to
);
312 enum machine_mode from_mode
= GET_MODE (from
);
313 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
314 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
318 /* rtx code for making an equivalent value. */
319 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
320 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
323 gcc_assert (to_real
== from_real
);
324 gcc_assert (to_mode
!= BLKmode
);
325 gcc_assert (from_mode
!= BLKmode
);
327 /* If the source and destination are already the same, then there's
332 /* If FROM is a SUBREG that indicates that we have already done at least
333 the required extension, strip it. We don't handle such SUBREGs as
336 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
337 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
338 >= GET_MODE_PRECISION (to_mode
))
339 && SUBREG_PROMOTED_UNSIGNED_P (from
) == unsignedp
)
340 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
342 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
344 if (to_mode
== from_mode
345 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
347 emit_move_insn (to
, from
);
351 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
353 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
355 if (VECTOR_MODE_P (to_mode
))
356 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
358 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
360 emit_move_insn (to
, from
);
364 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
366 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
367 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
376 gcc_assert ((GET_MODE_PRECISION (from_mode
)
377 != GET_MODE_PRECISION (to_mode
))
378 || (DECIMAL_FLOAT_MODE_P (from_mode
)
379 != DECIMAL_FLOAT_MODE_P (to_mode
)));
381 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
382 /* Conversion between decimal float and binary float, same size. */
383 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
384 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
389 /* Try converting directly if the insn is supported. */
391 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
392 if (code
!= CODE_FOR_nothing
)
394 emit_unop_insn (code
, to
, from
,
395 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
399 /* Otherwise use a libcall. */
400 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
402 /* Is this conversion implemented yet? */
403 gcc_assert (libcall
);
406 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
408 insns
= get_insns ();
410 emit_libcall_block (insns
, to
, value
,
411 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
413 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
417 /* Handle pointer conversion. */ /* SPEE 900220. */
418 /* Targets are expected to provide conversion insns between PxImode and
419 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
420 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
422 enum machine_mode full_mode
423 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
425 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
426 != CODE_FOR_nothing
);
428 if (full_mode
!= from_mode
)
429 from
= convert_to_mode (full_mode
, from
, unsignedp
);
430 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
434 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
437 enum machine_mode full_mode
438 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
439 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
440 enum insn_code icode
;
442 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
443 gcc_assert (icode
!= CODE_FOR_nothing
);
445 if (to_mode
== full_mode
)
447 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
451 new_from
= gen_reg_rtx (full_mode
);
452 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
454 /* else proceed to integer conversions below. */
455 from_mode
= full_mode
;
459 /* Make sure both are fixed-point modes or both are not. */
460 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
461 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
462 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
464 /* If we widen from_mode to to_mode and they are in the same class,
465 we won't saturate the result.
466 Otherwise, always saturate the result to play safe. */
467 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
468 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
469 expand_fixed_convert (to
, from
, 0, 0);
471 expand_fixed_convert (to
, from
, 0, 1);
475 /* Now both modes are integers. */
477 /* Handle expanding beyond a word. */
478 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
479 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
486 enum machine_mode lowpart_mode
;
487 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
489 /* Try converting directly if the insn is supported. */
490 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
493 /* If FROM is a SUBREG, put it into a register. Do this
494 so that we always generate the same set of insns for
495 better cse'ing; if an intermediate assignment occurred,
496 we won't be doing the operation directly on the SUBREG. */
497 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
498 from
= force_reg (from_mode
, from
);
499 emit_unop_insn (code
, to
, from
, equiv_code
);
502 /* Next, try converting via full word. */
503 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
504 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
505 != CODE_FOR_nothing
))
507 rtx word_to
= gen_reg_rtx (word_mode
);
510 if (reg_overlap_mentioned_p (to
, from
))
511 from
= force_reg (from_mode
, from
);
514 convert_move (word_to
, from
, unsignedp
);
515 emit_unop_insn (code
, to
, word_to
, equiv_code
);
519 /* No special multiword conversion insn; do it by hand. */
522 /* Since we will turn this into a no conflict block, we must ensure the
523 the source does not overlap the target so force it into an isolated
524 register when maybe so. Likewise for any MEM input, since the
525 conversion sequence might require several references to it and we
526 must ensure we're getting the same value every time. */
528 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
529 from
= force_reg (from_mode
, from
);
531 /* Get a copy of FROM widened to a word, if necessary. */
532 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
533 lowpart_mode
= word_mode
;
535 lowpart_mode
= from_mode
;
537 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
539 lowpart
= gen_lowpart (lowpart_mode
, to
);
540 emit_move_insn (lowpart
, lowfrom
);
542 /* Compute the value to put in each remaining word. */
544 fill_value
= const0_rtx
;
546 fill_value
= emit_store_flag (gen_reg_rtx (word_mode
),
547 LT
, lowfrom
, const0_rtx
,
550 /* Fill the remaining words. */
551 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
553 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
554 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
556 gcc_assert (subword
);
558 if (fill_value
!= subword
)
559 emit_move_insn (subword
, fill_value
);
562 insns
= get_insns ();
569 /* Truncating multi-word to a word or less. */
570 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
571 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
574 && ! MEM_VOLATILE_P (from
)
575 && direct_load
[(int) to_mode
]
576 && ! mode_dependent_address_p (XEXP (from
, 0),
577 MEM_ADDR_SPACE (from
)))
579 || GET_CODE (from
) == SUBREG
))
580 from
= force_reg (from_mode
, from
);
581 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
585 /* Now follow all the conversions between integers
586 no more than a word long. */
588 /* For truncation, usually we can just refer to FROM in a narrower mode. */
589 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
590 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
593 && ! MEM_VOLATILE_P (from
)
594 && direct_load
[(int) to_mode
]
595 && ! mode_dependent_address_p (XEXP (from
, 0),
596 MEM_ADDR_SPACE (from
)))
598 || GET_CODE (from
) == SUBREG
))
599 from
= force_reg (from_mode
, from
);
600 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
601 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
602 from
= copy_to_reg (from
);
603 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
607 /* Handle extension. */
608 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
610 /* Convert directly if that works. */
611 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
614 emit_unop_insn (code
, to
, from
, equiv_code
);
619 enum machine_mode intermediate
;
623 /* Search for a mode to convert via. */
624 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
625 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
626 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
628 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
629 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
630 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
631 != CODE_FOR_nothing
))
633 convert_move (to
, convert_to_mode (intermediate
, from
,
634 unsignedp
), unsignedp
);
638 /* No suitable intermediate mode.
639 Generate what we need with shifts. */
640 shift_amount
= (GET_MODE_PRECISION (to_mode
)
641 - GET_MODE_PRECISION (from_mode
));
642 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
643 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
645 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
648 emit_move_insn (to
, tmp
);
653 /* Support special truncate insns for certain modes. */
654 if (convert_optab_handler (trunc_optab
, to_mode
,
655 from_mode
) != CODE_FOR_nothing
)
657 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
662 /* Handle truncation of volatile memrefs, and so on;
663 the things that couldn't be truncated directly,
664 and for which there was no special instruction.
666 ??? Code above formerly short-circuited this, for most integer
667 mode pairs, with a force_reg in from_mode followed by a recursive
668 call to this routine. Appears always to have been wrong. */
669 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
671 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
672 emit_move_insn (to
, temp
);
676 /* Mode combination is not recognized. */
680 /* Return an rtx for a value that would result
681 from converting X to mode MODE.
682 Both X and MODE may be floating, or both integer.
683 UNSIGNEDP is nonzero if X is an unsigned value.
684 This can be done by referring to a part of X in place
685 or by copying to a new temporary with conversion. */
688 convert_to_mode (enum machine_mode mode
, rtx x
, int unsignedp
)
690 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
693 /* Return an rtx for a value that would result
694 from converting X from mode OLDMODE to mode MODE.
695 Both modes may be floating, or both integer.
696 UNSIGNEDP is nonzero if X is an unsigned value.
698 This can be done by referring to a part of X in place
699 or by copying to a new temporary with conversion.
701 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
704 convert_modes (enum machine_mode mode
, enum machine_mode oldmode
, rtx x
, int unsignedp
)
708 /* If FROM is a SUBREG that indicates that we have already done at least
709 the required extension, strip it. */
711 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
712 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
713 && SUBREG_PROMOTED_UNSIGNED_P (x
) == unsignedp
)
714 x
= gen_lowpart (mode
, x
);
716 if (GET_MODE (x
) != VOIDmode
)
717 oldmode
= GET_MODE (x
);
722 /* There is one case that we must handle specially: If we are converting
723 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
724 we are to interpret the constant as unsigned, gen_lowpart will do
725 the wrong if the constant appears negative. What we want to do is
726 make the high-order word of the constant zero, not all ones. */
728 if (unsignedp
&& GET_MODE_CLASS (mode
) == MODE_INT
729 && GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
730 && CONST_INT_P (x
) && INTVAL (x
) < 0)
732 double_int val
= double_int::from_uhwi (INTVAL (x
));
734 /* We need to zero extend VAL. */
735 if (oldmode
!= VOIDmode
)
736 val
= val
.zext (GET_MODE_BITSIZE (oldmode
));
738 return immed_double_int_const (val
, mode
);
741 /* We can do this with a gen_lowpart if both desired and current modes
742 are integer, and this is either a constant integer, a register, or a
743 non-volatile MEM. Except for the constant case where MODE is no
744 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
747 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
)
748 || (GET_MODE_CLASS (mode
) == MODE_INT
749 && GET_MODE_CLASS (oldmode
) == MODE_INT
750 && (CONST_DOUBLE_AS_INT_P (x
)
751 || (GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
752 && ((MEM_P (x
) && ! MEM_VOLATILE_P (x
)
753 && direct_load
[(int) mode
])
755 && (! HARD_REGISTER_P (x
)
756 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
757 && TRULY_NOOP_TRUNCATION_MODES_P (mode
,
760 /* ?? If we don't know OLDMODE, we have to assume here that
761 X does not need sign- or zero-extension. This may not be
762 the case, but it's the best we can do. */
763 if (CONST_INT_P (x
) && oldmode
!= VOIDmode
764 && GET_MODE_PRECISION (mode
) > GET_MODE_PRECISION (oldmode
))
766 HOST_WIDE_INT val
= INTVAL (x
);
768 /* We must sign or zero-extend in this case. Start by
769 zero-extending, then sign extend if we need to. */
770 val
&= GET_MODE_MASK (oldmode
);
772 && val_signbit_known_set_p (oldmode
, val
))
773 val
|= ~GET_MODE_MASK (oldmode
);
775 return gen_int_mode (val
, mode
);
778 return gen_lowpart (mode
, x
);
781 /* Converting from integer constant into mode is always equivalent to an
783 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
785 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
786 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
789 temp
= gen_reg_rtx (mode
);
790 convert_move (temp
, x
, unsignedp
);
794 /* Return the largest alignment we can use for doing a move (or store)
795 of MAX_PIECES. ALIGN is the largest alignment we could use. */
798 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
800 enum machine_mode tmode
;
802 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
803 if (align
>= GET_MODE_ALIGNMENT (tmode
))
804 align
= GET_MODE_ALIGNMENT (tmode
);
807 enum machine_mode tmode
, xmode
;
809 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
811 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
812 if (GET_MODE_SIZE (tmode
) > max_pieces
813 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
816 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
822 /* Return the widest integer mode no wider than SIZE. If no such mode
823 can be found, return VOIDmode. */
825 static enum machine_mode
826 widest_int_mode_for_size (unsigned int size
)
828 enum machine_mode tmode
, mode
= VOIDmode
;
830 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
831 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
832 if (GET_MODE_SIZE (tmode
) < size
)
838 /* STORE_MAX_PIECES is the number of bytes at a time that we can
839 store efficiently. Due to internal GCC limitations, this is
840 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
841 for an immediate constant. */
843 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
845 /* Determine whether the LEN bytes can be moved by using several move
846 instructions. Return nonzero if a call to move_by_pieces should
850 can_move_by_pieces (unsigned HOST_WIDE_INT len
,
851 unsigned int align ATTRIBUTE_UNUSED
)
853 return MOVE_BY_PIECES_P (len
, align
);
856 /* Generate several move instructions to copy LEN bytes from block FROM to
857 block TO. (These are MEM rtx's with BLKmode).
859 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
860 used to push FROM to the stack.
862 ALIGN is maximum stack alignment we can assume.
864 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
865 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
869 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
870 unsigned int align
, int endp
)
872 struct move_by_pieces_d data
;
873 enum machine_mode to_addr_mode
;
874 enum machine_mode from_addr_mode
= get_address_mode (from
);
875 rtx to_addr
, from_addr
= XEXP (from
, 0);
876 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
877 enum insn_code icode
;
879 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
882 data
.from_addr
= from_addr
;
885 to_addr_mode
= get_address_mode (to
);
886 to_addr
= XEXP (to
, 0);
889 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
890 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
892 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
896 to_addr_mode
= VOIDmode
;
900 #ifdef STACK_GROWS_DOWNWARD
906 data
.to_addr
= to_addr
;
909 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
910 || GET_CODE (from_addr
) == POST_INC
911 || GET_CODE (from_addr
) == POST_DEC
);
913 data
.explicit_inc_from
= 0;
914 data
.explicit_inc_to
= 0;
915 if (data
.reverse
) data
.offset
= len
;
918 /* If copying requires more than two move insns,
919 copy addresses to registers (to make displacements shorter)
920 and use post-increment if available. */
921 if (!(data
.autinc_from
&& data
.autinc_to
)
922 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
924 /* Find the mode of the largest move...
925 MODE might not be used depending on the definitions of the
926 USE_* macros below. */
927 enum machine_mode mode ATTRIBUTE_UNUSED
928 = widest_int_mode_for_size (max_size
);
930 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
932 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
933 plus_constant (from_addr_mode
,
935 data
.autinc_from
= 1;
936 data
.explicit_inc_from
= -1;
938 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
940 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
941 data
.autinc_from
= 1;
942 data
.explicit_inc_from
= 1;
944 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
945 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
946 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
948 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
949 plus_constant (to_addr_mode
,
952 data
.explicit_inc_to
= -1;
954 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
956 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
958 data
.explicit_inc_to
= 1;
960 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
961 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
964 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
966 /* First move what we can in the largest integer mode, then go to
967 successively smaller modes. */
969 while (max_size
> 1 && data
.len
> 0)
971 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
973 if (mode
== VOIDmode
)
976 icode
= optab_handler (mov_optab
, mode
);
977 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
978 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
980 max_size
= GET_MODE_SIZE (mode
);
983 /* The code above should have handled everything. */
984 gcc_assert (!data
.len
);
990 gcc_assert (!data
.reverse
);
995 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
996 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
998 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
999 plus_constant (to_addr_mode
,
1003 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
1010 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1018 /* Return number of insns required to move L bytes by pieces.
1019 ALIGN (in bits) is maximum alignment we can assume. */
1021 unsigned HOST_WIDE_INT
1022 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1023 unsigned int max_size
)
1025 unsigned HOST_WIDE_INT n_insns
= 0;
1027 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1029 while (max_size
> 1 && l
> 0)
1031 enum machine_mode mode
;
1032 enum insn_code icode
;
1034 mode
= widest_int_mode_for_size (max_size
);
1036 if (mode
== VOIDmode
)
1039 icode
= optab_handler (mov_optab
, mode
);
1040 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1041 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1043 max_size
= GET_MODE_SIZE (mode
);
1050 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1051 with move instructions for mode MODE. GENFUN is the gen_... function
1052 to make a move insn for that mode. DATA has all the other info. */
1055 move_by_pieces_1 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
1056 struct move_by_pieces_d
*data
)
1058 unsigned int size
= GET_MODE_SIZE (mode
);
1059 rtx to1
= NULL_RTX
, from1
;
1061 while (data
->len
>= size
)
1064 data
->offset
-= size
;
1068 if (data
->autinc_to
)
1069 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1072 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1075 if (data
->autinc_from
)
1076 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1079 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1081 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1082 emit_insn (gen_add2_insn (data
->to_addr
,
1083 GEN_INT (-(HOST_WIDE_INT
)size
)));
1084 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1085 emit_insn (gen_add2_insn (data
->from_addr
,
1086 GEN_INT (-(HOST_WIDE_INT
)size
)));
1089 emit_insn ((*genfun
) (to1
, from1
));
1092 #ifdef PUSH_ROUNDING
1093 emit_single_push_insn (mode
, from1
, NULL
);
1099 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1100 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
1101 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1102 emit_insn (gen_add2_insn (data
->from_addr
, GEN_INT (size
)));
1104 if (! data
->reverse
)
1105 data
->offset
+= size
;
1111 /* Emit code to move a block Y to a block X. This may be done with
1112 string-move instructions, with multiple scalar move instructions,
1113 or with a library call.
1115 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1116 SIZE is an rtx that says how long they are.
1117 ALIGN is the maximum alignment we can assume they have.
1118 METHOD describes what kind of copy this is, and what mechanisms may be used.
1120 Return the address of the new block, if memcpy is called and returns it,
1124 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1125 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
1132 if (CONST_INT_P (size
)
1133 && INTVAL (size
) == 0)
1138 case BLOCK_OP_NORMAL
:
1139 case BLOCK_OP_TAILCALL
:
1140 may_use_call
= true;
1143 case BLOCK_OP_CALL_PARM
:
1144 may_use_call
= block_move_libcall_safe_for_call_parm ();
1146 /* Make inhibit_defer_pop nonzero around the library call
1147 to force it to pop the arguments right away. */
1151 case BLOCK_OP_NO_LIBCALL
:
1152 may_use_call
= false;
1159 gcc_assert (MEM_P (x
) && MEM_P (y
));
1160 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1161 gcc_assert (align
>= BITS_PER_UNIT
);
1163 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1164 block copy is more efficient for other large modes, e.g. DCmode. */
1165 x
= adjust_address (x
, BLKmode
, 0);
1166 y
= adjust_address (y
, BLKmode
, 0);
1168 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1169 can be incorrect is coming from __builtin_memcpy. */
1170 if (CONST_INT_P (size
))
1172 x
= shallow_copy_rtx (x
);
1173 y
= shallow_copy_rtx (y
);
1174 set_mem_size (x
, INTVAL (size
));
1175 set_mem_size (y
, INTVAL (size
));
1178 if (CONST_INT_P (size
) && MOVE_BY_PIECES_P (INTVAL (size
), align
))
1179 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1180 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1181 expected_align
, expected_size
))
1183 else if (may_use_call
1184 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1185 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1187 /* Since x and y are passed to a libcall, mark the corresponding
1188 tree EXPR as addressable. */
1189 tree y_expr
= MEM_EXPR (y
);
1190 tree x_expr
= MEM_EXPR (x
);
1192 mark_addressable (y_expr
);
1194 mark_addressable (x_expr
);
1195 retval
= emit_block_move_via_libcall (x
, y
, size
,
1196 method
== BLOCK_OP_TAILCALL
);
1200 emit_block_move_via_loop (x
, y
, size
, align
);
1202 if (method
== BLOCK_OP_CALL_PARM
)
1209 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1211 return emit_block_move_hints (x
, y
, size
, method
, 0, -1);
1214 /* A subroutine of emit_block_move. Returns true if calling the
1215 block move libcall will not clobber any parameters which may have
1216 already been placed on the stack. */
1219 block_move_libcall_safe_for_call_parm (void)
1221 #if defined (REG_PARM_STACK_SPACE)
1225 /* If arguments are pushed on the stack, then they're safe. */
1229 /* If registers go on the stack anyway, any argument is sure to clobber
1230 an outgoing argument. */
1231 #if defined (REG_PARM_STACK_SPACE)
1232 fn
= emit_block_move_libcall_fn (false);
1233 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1234 depend on its argument. */
1236 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1237 && REG_PARM_STACK_SPACE (fn
) != 0)
1241 /* If any argument goes in memory, then it might clobber an outgoing
1244 CUMULATIVE_ARGS args_so_far_v
;
1245 cumulative_args_t args_so_far
;
1248 fn
= emit_block_move_libcall_fn (false);
1249 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1250 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1252 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1253 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1255 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1256 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1258 if (!tmp
|| !REG_P (tmp
))
1260 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1262 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1269 /* A subroutine of emit_block_move. Expand a movmem pattern;
1270 return true if successful. */
1273 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1274 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
1276 int save_volatile_ok
= volatile_ok
;
1277 enum machine_mode mode
;
1279 if (expected_align
< align
)
1280 expected_align
= align
;
1282 /* Since this is a move insn, we don't care about volatility. */
1285 /* Try the most limited insn first, because there's no point
1286 including more than one in the machine description unless
1287 the more limited one has some advantage. */
1289 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1290 mode
= GET_MODE_WIDER_MODE (mode
))
1292 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1294 if (code
!= CODE_FOR_nothing
1295 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1296 here because if SIZE is less than the mode mask, as it is
1297 returned by the macro, it will definitely be less than the
1298 actual mode mask. */
1299 && ((CONST_INT_P (size
)
1300 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1301 <= (GET_MODE_MASK (mode
) >> 1)))
1302 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
1304 struct expand_operand ops
[6];
1307 /* ??? When called via emit_block_move_for_call, it'd be
1308 nice if there were some way to inform the backend, so
1309 that it doesn't fail the expansion because it thinks
1310 emitting the libcall would be more efficient. */
1311 nops
= insn_data
[(int) code
].n_generator_args
;
1312 gcc_assert (nops
== 4 || nops
== 6);
1314 create_fixed_operand (&ops
[0], x
);
1315 create_fixed_operand (&ops
[1], y
);
1316 /* The check above guarantees that this size conversion is valid. */
1317 create_convert_operand_to (&ops
[2], size
, mode
, true);
1318 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1321 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1322 create_integer_operand (&ops
[5], expected_size
);
1324 if (maybe_expand_insn (code
, nops
, ops
))
1326 volatile_ok
= save_volatile_ok
;
1332 volatile_ok
= save_volatile_ok
;
1336 /* A subroutine of emit_block_move. Expand a call to memcpy.
1337 Return the return value from memcpy, 0 otherwise. */
1340 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1342 rtx dst_addr
, src_addr
;
1343 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1344 enum machine_mode size_mode
;
1347 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1348 pseudos. We can then place those new pseudos into a VAR_DECL and
1351 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1352 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1354 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1355 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1357 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1358 src_tree
= make_tree (ptr_type_node
, src_addr
);
1360 size_mode
= TYPE_MODE (sizetype
);
1362 size
= convert_to_mode (size_mode
, size
, 1);
1363 size
= copy_to_mode_reg (size_mode
, size
);
1365 /* It is incorrect to use the libcall calling conventions to call
1366 memcpy in this context. This could be a user call to memcpy and
1367 the user may wish to examine the return value from memcpy. For
1368 targets where libcalls and normal calls have different conventions
1369 for returning pointers, we could end up generating incorrect code. */
1371 size_tree
= make_tree (sizetype
, size
);
1373 fn
= emit_block_move_libcall_fn (true);
1374 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1375 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1377 retval
= expand_normal (call_expr
);
1382 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1383 for the function we use for block copies. */
1385 static GTY(()) tree block_move_fn
;
1388 init_block_move_fn (const char *asmspec
)
1392 tree args
, fn
, attrs
, attr_args
;
1394 fn
= get_identifier ("memcpy");
1395 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1396 const_ptr_type_node
, sizetype
,
1399 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1400 DECL_EXTERNAL (fn
) = 1;
1401 TREE_PUBLIC (fn
) = 1;
1402 DECL_ARTIFICIAL (fn
) = 1;
1403 TREE_NOTHROW (fn
) = 1;
1404 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1405 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1407 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1408 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1410 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1416 set_user_assembler_name (block_move_fn
, asmspec
);
1420 emit_block_move_libcall_fn (int for_call
)
1422 static bool emitted_extern
;
1425 init_block_move_fn (NULL
);
1427 if (for_call
&& !emitted_extern
)
1429 emitted_extern
= true;
1430 make_decl_rtl (block_move_fn
);
1433 return block_move_fn
;
1436 /* A subroutine of emit_block_move. Copy the data via an explicit
1437 loop. This is used only when libcalls are forbidden. */
1438 /* ??? It'd be nice to copy in hunks larger than QImode. */
1441 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1442 unsigned int align ATTRIBUTE_UNUSED
)
1444 rtx cmp_label
, top_label
, iter
, x_addr
, y_addr
, tmp
;
1445 enum machine_mode x_addr_mode
= get_address_mode (x
);
1446 enum machine_mode y_addr_mode
= get_address_mode (y
);
1447 enum machine_mode iter_mode
;
1449 iter_mode
= GET_MODE (size
);
1450 if (iter_mode
== VOIDmode
)
1451 iter_mode
= word_mode
;
1453 top_label
= gen_label_rtx ();
1454 cmp_label
= gen_label_rtx ();
1455 iter
= gen_reg_rtx (iter_mode
);
1457 emit_move_insn (iter
, const0_rtx
);
1459 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1460 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1461 do_pending_stack_adjust ();
1463 emit_jump (cmp_label
);
1464 emit_label (top_label
);
1466 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1467 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1469 if (x_addr_mode
!= y_addr_mode
)
1470 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1471 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1473 x
= change_address (x
, QImode
, x_addr
);
1474 y
= change_address (y
, QImode
, y_addr
);
1476 emit_move_insn (x
, y
);
1478 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1479 true, OPTAB_LIB_WIDEN
);
1481 emit_move_insn (iter
, tmp
);
1483 emit_label (cmp_label
);
1485 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1486 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1489 /* Copy all or part of a value X into registers starting at REGNO.
1490 The number of registers to be filled is NREGS. */
1493 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1496 #ifdef HAVE_load_multiple
1504 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1505 x
= validize_mem (force_const_mem (mode
, x
));
1507 /* See if the machine can do this with a load multiple insn. */
1508 #ifdef HAVE_load_multiple
1509 if (HAVE_load_multiple
)
1511 last
= get_last_insn ();
1512 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1520 delete_insns_since (last
);
1524 for (i
= 0; i
< nregs
; i
++)
1525 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1526 operand_subword_force (x
, i
, mode
));
1529 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1530 The number of registers to be filled is NREGS. */
1533 move_block_from_reg (int regno
, rtx x
, int nregs
)
1540 /* See if the machine can do this with a store multiple insn. */
1541 #ifdef HAVE_store_multiple
1542 if (HAVE_store_multiple
)
1544 rtx last
= get_last_insn ();
1545 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1553 delete_insns_since (last
);
1557 for (i
= 0; i
< nregs
; i
++)
1559 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1563 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1567 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1568 ORIG, where ORIG is a non-consecutive group of registers represented by
1569 a PARALLEL. The clone is identical to the original except in that the
1570 original set of registers is replaced by a new set of pseudo registers.
1571 The new set has the same modes as the original set. */
1574 gen_group_rtx (rtx orig
)
1579 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1581 length
= XVECLEN (orig
, 0);
1582 tmps
= XALLOCAVEC (rtx
, length
);
1584 /* Skip a NULL entry in first slot. */
1585 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1590 for (; i
< length
; i
++)
1592 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1593 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1595 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1598 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1601 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1602 except that values are placed in TMPS[i], and must later be moved
1603 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1606 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1610 enum machine_mode m
= GET_MODE (orig_src
);
1612 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1615 && !SCALAR_INT_MODE_P (m
)
1616 && !MEM_P (orig_src
)
1617 && GET_CODE (orig_src
) != CONCAT
)
1619 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1620 if (imode
== BLKmode
)
1621 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1623 src
= gen_reg_rtx (imode
);
1624 if (imode
!= BLKmode
)
1625 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1626 emit_move_insn (src
, orig_src
);
1627 /* ...and back again. */
1628 if (imode
!= BLKmode
)
1629 src
= gen_lowpart (imode
, src
);
1630 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1634 /* Check for a NULL entry, used to indicate that the parameter goes
1635 both on the stack and in registers. */
1636 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1641 /* Process the pieces. */
1642 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1644 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1645 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1646 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1649 /* Handle trailing fragments that run over the size of the struct. */
1650 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1652 /* Arrange to shift the fragment to where it belongs.
1653 extract_bit_field loads to the lsb of the reg. */
1655 #ifdef BLOCK_REG_PADDING
1656 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1657 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1662 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1663 bytelen
= ssize
- bytepos
;
1664 gcc_assert (bytelen
> 0);
1667 /* If we won't be loading directly from memory, protect the real source
1668 from strange tricks we might play; but make sure that the source can
1669 be loaded directly into the destination. */
1671 if (!MEM_P (orig_src
)
1672 && (!CONSTANT_P (orig_src
)
1673 || (GET_MODE (orig_src
) != mode
1674 && GET_MODE (orig_src
) != VOIDmode
)))
1676 if (GET_MODE (orig_src
) == VOIDmode
)
1677 src
= gen_reg_rtx (mode
);
1679 src
= gen_reg_rtx (GET_MODE (orig_src
));
1681 emit_move_insn (src
, orig_src
);
1684 /* Optimize the access just a bit. */
1686 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1687 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1688 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1689 && bytelen
== GET_MODE_SIZE (mode
))
1691 tmps
[i
] = gen_reg_rtx (mode
);
1692 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1694 else if (COMPLEX_MODE_P (mode
)
1695 && GET_MODE (src
) == mode
1696 && bytelen
== GET_MODE_SIZE (mode
))
1697 /* Let emit_move_complex do the bulk of the work. */
1699 else if (GET_CODE (src
) == CONCAT
)
1701 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1702 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1704 if ((bytepos
== 0 && bytelen
== slen0
)
1705 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1707 /* The following assumes that the concatenated objects all
1708 have the same size. In this case, a simple calculation
1709 can be used to determine the object and the bit field
1711 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1712 if (! CONSTANT_P (tmps
[i
])
1713 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1714 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1715 (bytepos
% slen0
) * BITS_PER_UNIT
,
1716 1, false, NULL_RTX
, mode
, mode
);
1722 gcc_assert (!bytepos
);
1723 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1724 emit_move_insn (mem
, src
);
1725 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1726 0, 1, false, NULL_RTX
, mode
, mode
);
1729 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1730 SIMD register, which is currently broken. While we get GCC
1731 to emit proper RTL for these cases, let's dump to memory. */
1732 else if (VECTOR_MODE_P (GET_MODE (dst
))
1735 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1738 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1739 emit_move_insn (mem
, src
);
1740 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1742 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1743 && XVECLEN (dst
, 0) > 1)
1744 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE(dst
), bytepos
);
1745 else if (CONSTANT_P (src
))
1747 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1755 gcc_assert (2 * len
== ssize
);
1756 split_double (src
, &first
, &second
);
1763 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1766 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1767 bytepos
* BITS_PER_UNIT
, 1, false, NULL_RTX
,
1771 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1776 /* Emit code to move a block SRC of type TYPE to a block DST,
1777 where DST is non-consecutive registers represented by a PARALLEL.
1778 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1782 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1787 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1788 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1790 /* Copy the extracted pieces into the proper (probable) hard regs. */
1791 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1793 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1796 emit_move_insn (d
, tmps
[i
]);
1800 /* Similar, but load SRC into new pseudos in a format that looks like
1801 PARALLEL. This can later be fed to emit_group_move to get things
1802 in the right place. */
1805 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1810 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1811 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1813 /* Convert the vector to look just like the original PARALLEL, except
1814 with the computed values. */
1815 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1817 rtx e
= XVECEXP (parallel
, 0, i
);
1818 rtx d
= XEXP (e
, 0);
1822 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1823 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1825 RTVEC_ELT (vec
, i
) = e
;
1828 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1831 /* Emit code to move a block SRC to block DST, where SRC and DST are
1832 non-consecutive groups of registers, each represented by a PARALLEL. */
1835 emit_group_move (rtx dst
, rtx src
)
1839 gcc_assert (GET_CODE (src
) == PARALLEL
1840 && GET_CODE (dst
) == PARALLEL
1841 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1843 /* Skip first entry if NULL. */
1844 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1845 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1846 XEXP (XVECEXP (src
, 0, i
), 0));
1849 /* Move a group of registers represented by a PARALLEL into pseudos. */
1852 emit_group_move_into_temps (rtx src
)
1854 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1857 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1859 rtx e
= XVECEXP (src
, 0, i
);
1860 rtx d
= XEXP (e
, 0);
1863 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1864 RTVEC_ELT (vec
, i
) = e
;
1867 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1870 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1871 where SRC is non-consecutive registers represented by a PARALLEL.
1872 SSIZE represents the total size of block ORIG_DST, or -1 if not
1876 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1879 int start
, finish
, i
;
1880 enum machine_mode m
= GET_MODE (orig_dst
);
1882 gcc_assert (GET_CODE (src
) == PARALLEL
);
1884 if (!SCALAR_INT_MODE_P (m
)
1885 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1887 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1888 if (imode
== BLKmode
)
1889 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1891 dst
= gen_reg_rtx (imode
);
1892 emit_group_store (dst
, src
, type
, ssize
);
1893 if (imode
!= BLKmode
)
1894 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1895 emit_move_insn (orig_dst
, dst
);
1899 /* Check for a NULL entry, used to indicate that the parameter goes
1900 both on the stack and in registers. */
1901 if (XEXP (XVECEXP (src
, 0, 0), 0))
1905 finish
= XVECLEN (src
, 0);
1907 tmps
= XALLOCAVEC (rtx
, finish
);
1909 /* Copy the (probable) hard regs into pseudos. */
1910 for (i
= start
; i
< finish
; i
++)
1912 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1913 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1915 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1916 emit_move_insn (tmps
[i
], reg
);
1922 /* If we won't be storing directly into memory, protect the real destination
1923 from strange tricks we might play. */
1925 if (GET_CODE (dst
) == PARALLEL
)
1929 /* We can get a PARALLEL dst if there is a conditional expression in
1930 a return statement. In that case, the dst and src are the same,
1931 so no action is necessary. */
1932 if (rtx_equal_p (dst
, src
))
1935 /* It is unclear if we can ever reach here, but we may as well handle
1936 it. Allocate a temporary, and split this into a store/load to/from
1939 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1940 emit_group_store (temp
, src
, type
, ssize
);
1941 emit_group_load (dst
, temp
, type
, ssize
);
1944 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1946 enum machine_mode outer
= GET_MODE (dst
);
1947 enum machine_mode inner
;
1948 HOST_WIDE_INT bytepos
;
1952 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1953 dst
= gen_reg_rtx (outer
);
1955 /* Make life a bit easier for combine. */
1956 /* If the first element of the vector is the low part
1957 of the destination mode, use a paradoxical subreg to
1958 initialize the destination. */
1961 inner
= GET_MODE (tmps
[start
]);
1962 bytepos
= subreg_lowpart_offset (inner
, outer
);
1963 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1965 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1969 emit_move_insn (dst
, temp
);
1976 /* If the first element wasn't the low part, try the last. */
1978 && start
< finish
- 1)
1980 inner
= GET_MODE (tmps
[finish
- 1]);
1981 bytepos
= subreg_lowpart_offset (inner
, outer
);
1982 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1984 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1988 emit_move_insn (dst
, temp
);
1995 /* Otherwise, simply initialize the result to zero. */
1997 emit_move_insn (dst
, CONST0_RTX (outer
));
2000 /* Process the pieces. */
2001 for (i
= start
; i
< finish
; i
++)
2003 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
2004 enum machine_mode mode
= GET_MODE (tmps
[i
]);
2005 unsigned int bytelen
= GET_MODE_SIZE (mode
);
2006 unsigned int adj_bytelen
= bytelen
;
2009 /* Handle trailing fragments that run over the size of the struct. */
2010 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2011 adj_bytelen
= ssize
- bytepos
;
2013 if (GET_CODE (dst
) == CONCAT
)
2015 if (bytepos
+ adj_bytelen
2016 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2017 dest
= XEXP (dst
, 0);
2018 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2020 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2021 dest
= XEXP (dst
, 1);
2025 enum machine_mode dest_mode
= GET_MODE (dest
);
2026 enum machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2028 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2030 if (GET_MODE_ALIGNMENT (dest_mode
)
2031 >= GET_MODE_ALIGNMENT (tmp_mode
))
2033 dest
= assign_stack_temp (dest_mode
,
2034 GET_MODE_SIZE (dest_mode
));
2035 emit_move_insn (adjust_address (dest
,
2043 dest
= assign_stack_temp (tmp_mode
,
2044 GET_MODE_SIZE (tmp_mode
));
2045 emit_move_insn (dest
, tmps
[i
]);
2046 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2052 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2054 /* store_bit_field always takes its value from the lsb.
2055 Move the fragment to the lsb if it's not already there. */
2057 #ifdef BLOCK_REG_PADDING
2058 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2059 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2065 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2066 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2069 bytelen
= adj_bytelen
;
2072 /* Optimize the access just a bit. */
2074 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2075 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2076 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2077 && bytelen
== GET_MODE_SIZE (mode
))
2078 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2080 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2081 0, 0, mode
, tmps
[i
]);
2084 /* Copy from the pseudo into the (probable) hard reg. */
2085 if (orig_dst
!= dst
)
2086 emit_move_insn (orig_dst
, dst
);
2089 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2091 This is used on targets that return BLKmode values in registers. */
2094 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2096 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2097 rtx src
= NULL
, dst
= NULL
;
2098 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2099 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2100 enum machine_mode mode
= GET_MODE (srcreg
);
2101 enum machine_mode tmode
= GET_MODE (target
);
2102 enum machine_mode copy_mode
;
2104 /* BLKmode registers created in the back-end shouldn't have survived. */
2105 gcc_assert (mode
!= BLKmode
);
2107 /* If the structure doesn't take up a whole number of words, see whether
2108 SRCREG is padded on the left or on the right. If it's on the left,
2109 set PADDING_CORRECTION to the number of bits to skip.
2111 In most ABIs, the structure will be returned at the least end of
2112 the register, which translates to right padding on little-endian
2113 targets and left padding on big-endian targets. The opposite
2114 holds if the structure is returned at the most significant
2115 end of the register. */
2116 if (bytes
% UNITS_PER_WORD
!= 0
2117 && (targetm
.calls
.return_in_msb (type
)
2119 : BYTES_BIG_ENDIAN
))
2121 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2123 /* We can use a single move if we have an exact mode for the size. */
2124 else if (MEM_P (target
)
2125 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2126 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2127 && bytes
== GET_MODE_SIZE (mode
))
2129 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2133 /* And if we additionally have the same mode for a register. */
2134 else if (REG_P (target
)
2135 && GET_MODE (target
) == mode
2136 && bytes
== GET_MODE_SIZE (mode
))
2138 emit_move_insn (target
, srcreg
);
2142 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2143 into a new pseudo which is a full word. */
2144 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2146 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2150 /* Copy the structure BITSIZE bits at a time. If the target lives in
2151 memory, take care of not reading/writing past its end by selecting
2152 a copy mode suited to BITSIZE. This should always be possible given
2155 If the target lives in register, make sure not to select a copy mode
2156 larger than the mode of the register.
2158 We could probably emit more efficient code for machines which do not use
2159 strict alignment, but it doesn't seem worth the effort at the current
2162 copy_mode
= word_mode
;
2165 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2166 if (mem_mode
!= BLKmode
)
2167 copy_mode
= mem_mode
;
2169 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2172 for (bitpos
= 0, xbitpos
= padding_correction
;
2173 bitpos
< bytes
* BITS_PER_UNIT
;
2174 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2176 /* We need a new source operand each time xbitpos is on a
2177 word boundary and when xbitpos == padding_correction
2178 (the first time through). */
2179 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2180 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2182 /* We need a new destination operand each time bitpos is on
2184 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2186 else if (bitpos
% BITS_PER_WORD
== 0)
2187 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2189 /* Use xbitpos for the source extraction (right justified) and
2190 bitpos for the destination store (left justified). */
2191 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2192 extract_bit_field (src
, bitsize
,
2193 xbitpos
% BITS_PER_WORD
, 1, false,
2194 NULL_RTX
, copy_mode
, copy_mode
));
2198 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2199 register if it contains any data, otherwise return null.
2201 This is used on targets that return BLKmode values in registers. */
2204 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2207 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2208 unsigned int bitsize
;
2209 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2210 enum machine_mode dst_mode
;
2212 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2214 x
= expand_normal (src
);
2216 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2220 /* If the structure doesn't take up a whole number of words, see
2221 whether the register value should be padded on the left or on
2222 the right. Set PADDING_CORRECTION to the number of padding
2223 bits needed on the left side.
2225 In most ABIs, the structure will be returned at the least end of
2226 the register, which translates to right padding on little-endian
2227 targets and left padding on big-endian targets. The opposite
2228 holds if the structure is returned at the most significant
2229 end of the register. */
2230 if (bytes
% UNITS_PER_WORD
!= 0
2231 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2233 : BYTES_BIG_ENDIAN
))
2234 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2237 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2238 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2239 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2241 /* Copy the structure BITSIZE bits at a time. */
2242 for (bitpos
= 0, xbitpos
= padding_correction
;
2243 bitpos
< bytes
* BITS_PER_UNIT
;
2244 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2246 /* We need a new destination pseudo each time xbitpos is
2247 on a word boundary and when xbitpos == padding_correction
2248 (the first time through). */
2249 if (xbitpos
% BITS_PER_WORD
== 0
2250 || xbitpos
== padding_correction
)
2252 /* Generate an appropriate register. */
2253 dst_word
= gen_reg_rtx (word_mode
);
2254 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2256 /* Clear the destination before we move anything into it. */
2257 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2260 /* We need a new source operand each time bitpos is on a word
2262 if (bitpos
% BITS_PER_WORD
== 0)
2263 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2265 /* Use bitpos for the source extraction (left justified) and
2266 xbitpos for the destination store (right justified). */
2267 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2269 extract_bit_field (src_word
, bitsize
,
2270 bitpos
% BITS_PER_WORD
, 1, false,
2271 NULL_RTX
, word_mode
, word_mode
));
2274 if (mode
== BLKmode
)
2276 /* Find the smallest integer mode large enough to hold the
2277 entire structure. */
2278 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2280 mode
= GET_MODE_WIDER_MODE (mode
))
2281 /* Have we found a large enough mode? */
2282 if (GET_MODE_SIZE (mode
) >= bytes
)
2285 /* A suitable mode should have been found. */
2286 gcc_assert (mode
!= VOIDmode
);
2289 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2290 dst_mode
= word_mode
;
2293 dst
= gen_reg_rtx (dst_mode
);
2295 for (i
= 0; i
< n_regs
; i
++)
2296 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2298 if (mode
!= dst_mode
)
2299 dst
= gen_lowpart (mode
, dst
);
2304 /* Add a USE expression for REG to the (possibly empty) list pointed
2305 to by CALL_FUSAGE. REG must denote a hard register. */
2308 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2310 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2313 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2316 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2317 starting at REGNO. All of these registers must be hard registers. */
2320 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2324 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2326 for (i
= 0; i
< nregs
; i
++)
2327 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2330 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2331 PARALLEL REGS. This is for calls that pass values in multiple
2332 non-contiguous locations. The Irix 6 ABI has examples of this. */
2335 use_group_regs (rtx
*call_fusage
, rtx regs
)
2339 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2341 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2343 /* A NULL entry means the parameter goes both on the stack and in
2344 registers. This can also be a MEM for targets that pass values
2345 partially on the stack and partially in registers. */
2346 if (reg
!= 0 && REG_P (reg
))
2347 use_reg (call_fusage
, reg
);
2351 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2352 assigment and the code of the expresion on the RHS is CODE. Return
2356 get_def_for_expr (tree name
, enum tree_code code
)
2360 if (TREE_CODE (name
) != SSA_NAME
)
2363 def_stmt
= get_gimple_for_ssa_name (name
);
2365 || gimple_assign_rhs_code (def_stmt
) != code
)
2371 #ifdef HAVE_conditional_move
2372 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2373 assigment and the class of the expresion on the RHS is CLASS. Return
2377 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2381 if (TREE_CODE (name
) != SSA_NAME
)
2384 def_stmt
= get_gimple_for_ssa_name (name
);
2386 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2394 /* Determine whether the LEN bytes generated by CONSTFUN can be
2395 stored to memory using several move instructions. CONSTFUNDATA is
2396 a pointer which will be passed as argument in every CONSTFUN call.
2397 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2398 a memset operation and false if it's a copy of a constant string.
2399 Return nonzero if a call to store_by_pieces should succeed. */
2402 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2403 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2404 void *constfundata
, unsigned int align
, bool memsetp
)
2406 unsigned HOST_WIDE_INT l
;
2407 unsigned int max_size
;
2408 HOST_WIDE_INT offset
= 0;
2409 enum machine_mode mode
;
2410 enum insn_code icode
;
2412 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2413 rtx cst ATTRIBUTE_UNUSED
;
2419 ? SET_BY_PIECES_P (len
, align
)
2420 : STORE_BY_PIECES_P (len
, align
)))
2423 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2425 /* We would first store what we can in the largest integer mode, then go to
2426 successively smaller modes. */
2429 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2433 max_size
= STORE_MAX_PIECES
+ 1;
2434 while (max_size
> 1 && l
> 0)
2436 mode
= widest_int_mode_for_size (max_size
);
2438 if (mode
== VOIDmode
)
2441 icode
= optab_handler (mov_optab
, mode
);
2442 if (icode
!= CODE_FOR_nothing
2443 && align
>= GET_MODE_ALIGNMENT (mode
))
2445 unsigned int size
= GET_MODE_SIZE (mode
);
2452 cst
= (*constfun
) (constfundata
, offset
, mode
);
2453 if (!targetm
.legitimate_constant_p (mode
, cst
))
2463 max_size
= GET_MODE_SIZE (mode
);
2466 /* The code above should have handled everything. */
2473 /* Generate several move instructions to store LEN bytes generated by
2474 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2475 pointer which will be passed as argument in every CONSTFUN call.
2476 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2477 a memset operation and false if it's a copy of a constant string.
2478 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2479 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2483 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2484 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2485 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2487 enum machine_mode to_addr_mode
= get_address_mode (to
);
2488 struct store_by_pieces_d data
;
2492 gcc_assert (endp
!= 2);
2497 ? SET_BY_PIECES_P (len
, align
)
2498 : STORE_BY_PIECES_P (len
, align
));
2499 data
.constfun
= constfun
;
2500 data
.constfundata
= constfundata
;
2503 store_by_pieces_1 (&data
, align
);
2508 gcc_assert (!data
.reverse
);
2513 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2514 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2516 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2517 plus_constant (to_addr_mode
,
2521 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2528 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2536 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2537 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2540 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2542 struct store_by_pieces_d data
;
2547 data
.constfun
= clear_by_pieces_1
;
2548 data
.constfundata
= NULL
;
2551 store_by_pieces_1 (&data
, align
);
2554 /* Callback routine for clear_by_pieces.
2555 Return const0_rtx unconditionally. */
2558 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2559 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2560 enum machine_mode mode ATTRIBUTE_UNUSED
)
2565 /* Subroutine of clear_by_pieces and store_by_pieces.
2566 Generate several move instructions to store LEN bytes of block TO. (A MEM
2567 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2570 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2571 unsigned int align ATTRIBUTE_UNUSED
)
2573 enum machine_mode to_addr_mode
= get_address_mode (data
->to
);
2574 rtx to_addr
= XEXP (data
->to
, 0);
2575 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2576 enum insn_code icode
;
2579 data
->to_addr
= to_addr
;
2581 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2582 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2584 data
->explicit_inc_to
= 0;
2586 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2588 data
->offset
= data
->len
;
2590 /* If storing requires more than two move insns,
2591 copy addresses to registers (to make displacements shorter)
2592 and use post-increment if available. */
2593 if (!data
->autinc_to
2594 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2596 /* Determine the main mode we'll be using.
2597 MODE might not be used depending on the definitions of the
2598 USE_* macros below. */
2599 enum machine_mode mode ATTRIBUTE_UNUSED
2600 = widest_int_mode_for_size (max_size
);
2602 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2604 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2605 plus_constant (to_addr_mode
,
2608 data
->autinc_to
= 1;
2609 data
->explicit_inc_to
= -1;
2612 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2613 && ! data
->autinc_to
)
2615 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2616 data
->autinc_to
= 1;
2617 data
->explicit_inc_to
= 1;
2620 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2621 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2624 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2626 /* First store what we can in the largest integer mode, then go to
2627 successively smaller modes. */
2629 while (max_size
> 1 && data
->len
> 0)
2631 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2633 if (mode
== VOIDmode
)
2636 icode
= optab_handler (mov_optab
, mode
);
2637 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2638 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2640 max_size
= GET_MODE_SIZE (mode
);
2643 /* The code above should have handled everything. */
2644 gcc_assert (!data
->len
);
2647 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2648 with move instructions for mode MODE. GENFUN is the gen_... function
2649 to make a move insn for that mode. DATA has all the other info. */
2652 store_by_pieces_2 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
2653 struct store_by_pieces_d
*data
)
2655 unsigned int size
= GET_MODE_SIZE (mode
);
2658 while (data
->len
>= size
)
2661 data
->offset
-= size
;
2663 if (data
->autinc_to
)
2664 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2667 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2669 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2670 emit_insn (gen_add2_insn (data
->to_addr
,
2671 GEN_INT (-(HOST_WIDE_INT
) size
)));
2673 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2674 emit_insn ((*genfun
) (to1
, cst
));
2676 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2677 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
2679 if (! data
->reverse
)
2680 data
->offset
+= size
;
2686 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2687 its length in bytes. */
2690 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2691 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2693 enum machine_mode mode
= GET_MODE (object
);
2696 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2698 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2699 just move a zero. Otherwise, do this a piece at a time. */
2701 && CONST_INT_P (size
)
2702 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2704 rtx zero
= CONST0_RTX (mode
);
2707 emit_move_insn (object
, zero
);
2711 if (COMPLEX_MODE_P (mode
))
2713 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2716 write_complex_part (object
, zero
, 0);
2717 write_complex_part (object
, zero
, 1);
2723 if (size
== const0_rtx
)
2726 align
= MEM_ALIGN (object
);
2728 if (CONST_INT_P (size
)
2729 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2730 clear_by_pieces (object
, INTVAL (size
), align
);
2731 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2732 expected_align
, expected_size
))
2734 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2735 return set_storage_via_libcall (object
, size
, const0_rtx
,
2736 method
== BLOCK_OP_TAILCALL
);
2744 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2746 return clear_storage_hints (object
, size
, method
, 0, -1);
2750 /* A subroutine of clear_storage. Expand a call to memset.
2751 Return the return value of memset, 0 otherwise. */
2754 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2756 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2757 enum machine_mode size_mode
;
2760 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2761 place those into new pseudos into a VAR_DECL and use them later. */
2763 object
= copy_addr_to_reg (XEXP (object
, 0));
2765 size_mode
= TYPE_MODE (sizetype
);
2766 size
= convert_to_mode (size_mode
, size
, 1);
2767 size
= copy_to_mode_reg (size_mode
, size
);
2769 /* It is incorrect to use the libcall calling conventions to call
2770 memset in this context. This could be a user call to memset and
2771 the user may wish to examine the return value from memset. For
2772 targets where libcalls and normal calls have different conventions
2773 for returning pointers, we could end up generating incorrect code. */
2775 object_tree
= make_tree (ptr_type_node
, object
);
2776 if (!CONST_INT_P (val
))
2777 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2778 size_tree
= make_tree (sizetype
, size
);
2779 val_tree
= make_tree (integer_type_node
, val
);
2781 fn
= clear_storage_libcall_fn (true);
2782 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2783 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2785 retval
= expand_normal (call_expr
);
2790 /* A subroutine of set_storage_via_libcall. Create the tree node
2791 for the function we use for block clears. */
2793 tree block_clear_fn
;
2796 init_block_clear_fn (const char *asmspec
)
2798 if (!block_clear_fn
)
2802 fn
= get_identifier ("memset");
2803 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2804 integer_type_node
, sizetype
,
2807 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2808 DECL_EXTERNAL (fn
) = 1;
2809 TREE_PUBLIC (fn
) = 1;
2810 DECL_ARTIFICIAL (fn
) = 1;
2811 TREE_NOTHROW (fn
) = 1;
2812 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2813 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2815 block_clear_fn
= fn
;
2819 set_user_assembler_name (block_clear_fn
, asmspec
);
2823 clear_storage_libcall_fn (int for_call
)
2825 static bool emitted_extern
;
2827 if (!block_clear_fn
)
2828 init_block_clear_fn (NULL
);
2830 if (for_call
&& !emitted_extern
)
2832 emitted_extern
= true;
2833 make_decl_rtl (block_clear_fn
);
2836 return block_clear_fn
;
2839 /* Expand a setmem pattern; return true if successful. */
2842 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2843 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2845 /* Try the most limited insn first, because there's no point
2846 including more than one in the machine description unless
2847 the more limited one has some advantage. */
2849 enum machine_mode mode
;
2851 if (expected_align
< align
)
2852 expected_align
= align
;
2854 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2855 mode
= GET_MODE_WIDER_MODE (mode
))
2857 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2859 if (code
!= CODE_FOR_nothing
2860 /* We don't need MODE to be narrower than
2861 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2862 the mode mask, as it is returned by the macro, it will
2863 definitely be less than the actual mode mask. */
2864 && ((CONST_INT_P (size
)
2865 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2866 <= (GET_MODE_MASK (mode
) >> 1)))
2867 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
2869 struct expand_operand ops
[6];
2872 nops
= insn_data
[(int) code
].n_generator_args
;
2873 gcc_assert (nops
== 4 || nops
== 6);
2875 create_fixed_operand (&ops
[0], object
);
2876 /* The check above guarantees that this size conversion is valid. */
2877 create_convert_operand_to (&ops
[1], size
, mode
, true);
2878 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2879 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2882 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2883 create_integer_operand (&ops
[5], expected_size
);
2885 if (maybe_expand_insn (code
, nops
, ops
))
2894 /* Write to one of the components of the complex value CPLX. Write VAL to
2895 the real part if IMAG_P is false, and the imaginary part if its true. */
2898 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2900 enum machine_mode cmode
;
2901 enum machine_mode imode
;
2904 if (GET_CODE (cplx
) == CONCAT
)
2906 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2910 cmode
= GET_MODE (cplx
);
2911 imode
= GET_MODE_INNER (cmode
);
2912 ibitsize
= GET_MODE_BITSIZE (imode
);
2914 /* For MEMs simplify_gen_subreg may generate an invalid new address
2915 because, e.g., the original address is considered mode-dependent
2916 by the target, which restricts simplify_subreg from invoking
2917 adjust_address_nv. Instead of preparing fallback support for an
2918 invalid address, we call adjust_address_nv directly. */
2921 emit_move_insn (adjust_address_nv (cplx
, imode
,
2922 imag_p
? GET_MODE_SIZE (imode
) : 0),
2927 /* If the sub-object is at least word sized, then we know that subregging
2928 will work. This special case is important, since store_bit_field
2929 wants to operate on integer modes, and there's rarely an OImode to
2930 correspond to TCmode. */
2931 if (ibitsize
>= BITS_PER_WORD
2932 /* For hard regs we have exact predicates. Assume we can split
2933 the original object if it spans an even number of hard regs.
2934 This special case is important for SCmode on 64-bit platforms
2935 where the natural size of floating-point regs is 32-bit. */
2937 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2938 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2940 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
2941 imag_p
? GET_MODE_SIZE (imode
) : 0);
2944 emit_move_insn (part
, val
);
2948 /* simplify_gen_subreg may fail for sub-word MEMs. */
2949 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2952 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
2955 /* Extract one of the components of the complex value CPLX. Extract the
2956 real part if IMAG_P is false, and the imaginary part if it's true. */
2959 read_complex_part (rtx cplx
, bool imag_p
)
2961 enum machine_mode cmode
, imode
;
2964 if (GET_CODE (cplx
) == CONCAT
)
2965 return XEXP (cplx
, imag_p
);
2967 cmode
= GET_MODE (cplx
);
2968 imode
= GET_MODE_INNER (cmode
);
2969 ibitsize
= GET_MODE_BITSIZE (imode
);
2971 /* Special case reads from complex constants that got spilled to memory. */
2972 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
2974 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
2975 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
2977 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
2978 if (CONSTANT_CLASS_P (part
))
2979 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
2983 /* For MEMs simplify_gen_subreg may generate an invalid new address
2984 because, e.g., the original address is considered mode-dependent
2985 by the target, which restricts simplify_subreg from invoking
2986 adjust_address_nv. Instead of preparing fallback support for an
2987 invalid address, we call adjust_address_nv directly. */
2989 return adjust_address_nv (cplx
, imode
,
2990 imag_p
? GET_MODE_SIZE (imode
) : 0);
2992 /* If the sub-object is at least word sized, then we know that subregging
2993 will work. This special case is important, since extract_bit_field
2994 wants to operate on integer modes, and there's rarely an OImode to
2995 correspond to TCmode. */
2996 if (ibitsize
>= BITS_PER_WORD
2997 /* For hard regs we have exact predicates. Assume we can split
2998 the original object if it spans an even number of hard regs.
2999 This special case is important for SCmode on 64-bit platforms
3000 where the natural size of floating-point regs is 32-bit. */
3002 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3003 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3005 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3006 imag_p
? GET_MODE_SIZE (imode
) : 0);
3010 /* simplify_gen_subreg may fail for sub-word MEMs. */
3011 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3014 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3015 true, false, NULL_RTX
, imode
, imode
);
3018 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3019 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3020 represented in NEW_MODE. If FORCE is true, this will never happen, as
3021 we'll force-create a SUBREG if needed. */
3024 emit_move_change_mode (enum machine_mode new_mode
,
3025 enum machine_mode old_mode
, rtx x
, bool force
)
3029 if (push_operand (x
, GET_MODE (x
)))
3031 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3032 MEM_COPY_ATTRIBUTES (ret
, x
);
3036 /* We don't have to worry about changing the address since the
3037 size in bytes is supposed to be the same. */
3038 if (reload_in_progress
)
3040 /* Copy the MEM to change the mode and move any
3041 substitutions from the old MEM to the new one. */
3042 ret
= adjust_address_nv (x
, new_mode
, 0);
3043 copy_replacements (x
, ret
);
3046 ret
= adjust_address (x
, new_mode
, 0);
3050 /* Note that we do want simplify_subreg's behavior of validating
3051 that the new mode is ok for a hard register. If we were to use
3052 simplify_gen_subreg, we would create the subreg, but would
3053 probably run into the target not being able to implement it. */
3054 /* Except, of course, when FORCE is true, when this is exactly what
3055 we want. Which is needed for CCmodes on some targets. */
3057 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3059 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3065 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3066 an integer mode of the same size as MODE. Returns the instruction
3067 emitted, or NULL if such a move could not be generated. */
3070 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3072 enum machine_mode imode
;
3073 enum insn_code code
;
3075 /* There must exist a mode of the exact size we require. */
3076 imode
= int_mode_for_mode (mode
);
3077 if (imode
== BLKmode
)
3080 /* The target must support moves in this mode. */
3081 code
= optab_handler (mov_optab
, imode
);
3082 if (code
== CODE_FOR_nothing
)
3085 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3088 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3091 return emit_insn (GEN_FCN (code
) (x
, y
));
3094 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3095 Return an equivalent MEM that does not use an auto-increment. */
3098 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3100 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3101 HOST_WIDE_INT adjust
;
3104 adjust
= GET_MODE_SIZE (mode
);
3105 #ifdef PUSH_ROUNDING
3106 adjust
= PUSH_ROUNDING (adjust
);
3108 if (code
== PRE_DEC
|| code
== POST_DEC
)
3110 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3112 rtx expr
= XEXP (XEXP (x
, 0), 1);
3115 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3116 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3117 val
= INTVAL (XEXP (expr
, 1));
3118 if (GET_CODE (expr
) == MINUS
)
3120 gcc_assert (adjust
== val
|| adjust
== -val
);
3124 /* Do not use anti_adjust_stack, since we don't want to update
3125 stack_pointer_delta. */
3126 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3127 GEN_INT (adjust
), stack_pointer_rtx
,
3128 0, OPTAB_LIB_WIDEN
);
3129 if (temp
!= stack_pointer_rtx
)
3130 emit_move_insn (stack_pointer_rtx
, temp
);
3137 temp
= stack_pointer_rtx
;
3142 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3148 return replace_equiv_address (x
, temp
);
3151 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3152 X is known to satisfy push_operand, and MODE is known to be complex.
3153 Returns the last instruction emitted. */
3156 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3158 enum machine_mode submode
= GET_MODE_INNER (mode
);
3161 #ifdef PUSH_ROUNDING
3162 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3164 /* In case we output to the stack, but the size is smaller than the
3165 machine can push exactly, we need to use move instructions. */
3166 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3168 x
= emit_move_resolve_push (mode
, x
);
3169 return emit_move_insn (x
, y
);
3173 /* Note that the real part always precedes the imag part in memory
3174 regardless of machine's endianness. */
3175 switch (GET_CODE (XEXP (x
, 0)))
3189 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3190 read_complex_part (y
, imag_first
));
3191 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3192 read_complex_part (y
, !imag_first
));
3195 /* A subroutine of emit_move_complex. Perform the move from Y to X
3196 via two moves of the parts. Returns the last instruction emitted. */
3199 emit_move_complex_parts (rtx x
, rtx y
)
3201 /* Show the output dies here. This is necessary for SUBREGs
3202 of pseudos since we cannot track their lifetimes correctly;
3203 hard regs shouldn't appear here except as return values. */
3204 if (!reload_completed
&& !reload_in_progress
3205 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3208 write_complex_part (x
, read_complex_part (y
, false), false);
3209 write_complex_part (x
, read_complex_part (y
, true), true);
3211 return get_last_insn ();
3214 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3215 MODE is known to be complex. Returns the last instruction emitted. */
3218 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3222 /* Need to take special care for pushes, to maintain proper ordering
3223 of the data, and possibly extra padding. */
3224 if (push_operand (x
, mode
))
3225 return emit_move_complex_push (mode
, x
, y
);
3227 /* See if we can coerce the target into moving both values at once. */
3229 /* Move floating point as parts. */
3230 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3231 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
)
3233 /* Not possible if the values are inherently not adjacent. */
3234 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3236 /* Is possible if both are registers (or subregs of registers). */
3237 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3239 /* If one of the operands is a memory, and alignment constraints
3240 are friendly enough, we may be able to do combined memory operations.
3241 We do not attempt this if Y is a constant because that combination is
3242 usually better with the by-parts thing below. */
3243 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3244 && (!STRICT_ALIGNMENT
3245 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3254 /* For memory to memory moves, optimal behavior can be had with the
3255 existing block move logic. */
3256 if (MEM_P (x
) && MEM_P (y
))
3258 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3259 BLOCK_OP_NO_LIBCALL
);
3260 return get_last_insn ();
3263 ret
= emit_move_via_integer (mode
, x
, y
, true);
3268 return emit_move_complex_parts (x
, y
);
3271 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3272 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3275 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3279 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3282 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3283 if (code
!= CODE_FOR_nothing
)
3285 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3286 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3287 return emit_insn (GEN_FCN (code
) (x
, y
));
3291 /* Otherwise, find the MODE_INT mode of the same width. */
3292 ret
= emit_move_via_integer (mode
, x
, y
, false);
3293 gcc_assert (ret
!= NULL
);
3297 /* Return true if word I of OP lies entirely in the
3298 undefined bits of a paradoxical subreg. */
3301 undefined_operand_subword_p (const_rtx op
, int i
)
3303 enum machine_mode innermode
, innermostmode
;
3305 if (GET_CODE (op
) != SUBREG
)
3307 innermode
= GET_MODE (op
);
3308 innermostmode
= GET_MODE (SUBREG_REG (op
));
3309 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3310 /* The SUBREG_BYTE represents offset, as if the value were stored in
3311 memory, except for a paradoxical subreg where we define
3312 SUBREG_BYTE to be 0; undo this exception as in
3314 if (SUBREG_BYTE (op
) == 0
3315 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3317 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3318 if (WORDS_BIG_ENDIAN
)
3319 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3320 if (BYTES_BIG_ENDIAN
)
3321 offset
+= difference
% UNITS_PER_WORD
;
3323 if (offset
>= GET_MODE_SIZE (innermostmode
)
3324 || offset
<= -GET_MODE_SIZE (word_mode
))
3329 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3330 MODE is any multi-word or full-word mode that lacks a move_insn
3331 pattern. Note that you will get better code if you define such
3332 patterns, even if they must turn into multiple assembler instructions. */
3335 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3342 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3344 /* If X is a push on the stack, do the push now and replace
3345 X with a reference to the stack pointer. */
3346 if (push_operand (x
, mode
))
3347 x
= emit_move_resolve_push (mode
, x
);
3349 /* If we are in reload, see if either operand is a MEM whose address
3350 is scheduled for replacement. */
3351 if (reload_in_progress
&& MEM_P (x
)
3352 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3353 x
= replace_equiv_address_nv (x
, inner
);
3354 if (reload_in_progress
&& MEM_P (y
)
3355 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3356 y
= replace_equiv_address_nv (y
, inner
);
3360 need_clobber
= false;
3362 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3365 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3368 /* Do not generate code for a move if it would come entirely
3369 from the undefined bits of a paradoxical subreg. */
3370 if (undefined_operand_subword_p (y
, i
))
3373 ypart
= operand_subword (y
, i
, 1, mode
);
3375 /* If we can't get a part of Y, put Y into memory if it is a
3376 constant. Otherwise, force it into a register. Then we must
3377 be able to get a part of Y. */
3378 if (ypart
== 0 && CONSTANT_P (y
))
3380 y
= use_anchored_address (force_const_mem (mode
, y
));
3381 ypart
= operand_subword (y
, i
, 1, mode
);
3383 else if (ypart
== 0)
3384 ypart
= operand_subword_force (y
, i
, mode
);
3386 gcc_assert (xpart
&& ypart
);
3388 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3390 last_insn
= emit_move_insn (xpart
, ypart
);
3396 /* Show the output dies here. This is necessary for SUBREGs
3397 of pseudos since we cannot track their lifetimes correctly;
3398 hard regs shouldn't appear here except as return values.
3399 We never want to emit such a clobber after reload. */
3401 && ! (reload_in_progress
|| reload_completed
)
3402 && need_clobber
!= 0)
3410 /* Low level part of emit_move_insn.
3411 Called just like emit_move_insn, but assumes X and Y
3412 are basically valid. */
3415 emit_move_insn_1 (rtx x
, rtx y
)
3417 enum machine_mode mode
= GET_MODE (x
);
3418 enum insn_code code
;
3420 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3422 code
= optab_handler (mov_optab
, mode
);
3423 if (code
!= CODE_FOR_nothing
)
3424 return emit_insn (GEN_FCN (code
) (x
, y
));
3426 /* Expand complex moves by moving real part and imag part. */
3427 if (COMPLEX_MODE_P (mode
))
3428 return emit_move_complex (mode
, x
, y
);
3430 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3431 || ALL_FIXED_POINT_MODE_P (mode
))
3433 rtx result
= emit_move_via_integer (mode
, x
, y
, true);
3435 /* If we can't find an integer mode, use multi words. */
3439 return emit_move_multi_word (mode
, x
, y
);
3442 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3443 return emit_move_ccmode (mode
, x
, y
);
3445 /* Try using a move pattern for the corresponding integer mode. This is
3446 only safe when simplify_subreg can convert MODE constants into integer
3447 constants. At present, it can only do this reliably if the value
3448 fits within a HOST_WIDE_INT. */
3449 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3451 rtx ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3455 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3460 return emit_move_multi_word (mode
, x
, y
);
3463 /* Generate code to copy Y into X.
3464 Both Y and X must have the same mode, except that
3465 Y can be a constant with VOIDmode.
3466 This mode cannot be BLKmode; use emit_block_move for that.
3468 Return the last instruction emitted. */
3471 emit_move_insn (rtx x
, rtx y
)
3473 enum machine_mode mode
= GET_MODE (x
);
3474 rtx y_cst
= NULL_RTX
;
3477 gcc_assert (mode
!= BLKmode
3478 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3483 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3484 && (last_insn
= compress_float_constant (x
, y
)))
3489 if (!targetm
.legitimate_constant_p (mode
, y
))
3491 y
= force_const_mem (mode
, y
);
3493 /* If the target's cannot_force_const_mem prevented the spill,
3494 assume that the target's move expanders will also take care
3495 of the non-legitimate constant. */
3499 y
= use_anchored_address (y
);
3503 /* If X or Y are memory references, verify that their addresses are valid
3506 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3508 && ! push_operand (x
, GET_MODE (x
))))
3509 x
= validize_mem (x
);
3512 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3513 MEM_ADDR_SPACE (y
)))
3514 y
= validize_mem (y
);
3516 gcc_assert (mode
!= BLKmode
);
3518 last_insn
= emit_move_insn_1 (x
, y
);
3520 if (y_cst
&& REG_P (x
)
3521 && (set
= single_set (last_insn
)) != NULL_RTX
3522 && SET_DEST (set
) == x
3523 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3524 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3529 /* If Y is representable exactly in a narrower mode, and the target can
3530 perform the extension directly from constant or memory, then emit the
3531 move as an extension. */
3534 compress_float_constant (rtx x
, rtx y
)
3536 enum machine_mode dstmode
= GET_MODE (x
);
3537 enum machine_mode orig_srcmode
= GET_MODE (y
);
3538 enum machine_mode srcmode
;
3540 int oldcost
, newcost
;
3541 bool speed
= optimize_insn_for_speed_p ();
3543 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3545 if (targetm
.legitimate_constant_p (dstmode
, y
))
3546 oldcost
= set_src_cost (y
, speed
);
3548 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3550 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3551 srcmode
!= orig_srcmode
;
3552 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3555 rtx trunc_y
, last_insn
;
3557 /* Skip if the target can't extend this way. */
3558 ic
= can_extend_p (dstmode
, srcmode
, 0);
3559 if (ic
== CODE_FOR_nothing
)
3562 /* Skip if the narrowed value isn't exact. */
3563 if (! exact_real_truncate (srcmode
, &r
))
3566 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3568 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3570 /* Skip if the target needs extra instructions to perform
3572 if (!insn_operand_matches (ic
, 1, trunc_y
))
3574 /* This is valid, but may not be cheaper than the original. */
3575 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3577 if (oldcost
< newcost
)
3580 else if (float_extend_from_mem
[dstmode
][srcmode
])
3582 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3583 /* This is valid, but may not be cheaper than the original. */
3584 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3586 if (oldcost
< newcost
)
3588 trunc_y
= validize_mem (trunc_y
);
3593 /* For CSE's benefit, force the compressed constant pool entry
3594 into a new pseudo. This constant may be used in different modes,
3595 and if not, combine will put things back together for us. */
3596 trunc_y
= force_reg (srcmode
, trunc_y
);
3597 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3598 last_insn
= get_last_insn ();
3601 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3609 /* Pushing data onto the stack. */
3611 /* Push a block of length SIZE (perhaps variable)
3612 and return an rtx to address the beginning of the block.
3613 The value may be virtual_outgoing_args_rtx.
3615 EXTRA is the number of bytes of padding to push in addition to SIZE.
3616 BELOW nonzero means this padding comes at low addresses;
3617 otherwise, the padding comes at high addresses. */
3620 push_block (rtx size
, int extra
, int below
)
3624 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3625 if (CONSTANT_P (size
))
3626 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3627 else if (REG_P (size
) && extra
== 0)
3628 anti_adjust_stack (size
);
3631 temp
= copy_to_mode_reg (Pmode
, size
);
3633 temp
= expand_binop (Pmode
, add_optab
, temp
, GEN_INT (extra
),
3634 temp
, 0, OPTAB_LIB_WIDEN
);
3635 anti_adjust_stack (temp
);
3638 #ifndef STACK_GROWS_DOWNWARD
3644 temp
= virtual_outgoing_args_rtx
;
3645 if (extra
!= 0 && below
)
3646 temp
= plus_constant (Pmode
, temp
, extra
);
3650 if (CONST_INT_P (size
))
3651 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3652 -INTVAL (size
) - (below
? 0 : extra
));
3653 else if (extra
!= 0 && !below
)
3654 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3655 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3658 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3659 negate_rtx (Pmode
, size
));
3662 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3665 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3668 mem_autoinc_base (rtx mem
)
3672 rtx addr
= XEXP (mem
, 0);
3673 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3674 return XEXP (addr
, 0);
3679 /* A utility routine used here, in reload, and in try_split. The insns
3680 after PREV up to and including LAST are known to adjust the stack,
3681 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3682 placing notes as appropriate. PREV may be NULL, indicating the
3683 entire insn sequence prior to LAST should be scanned.
3685 The set of allowed stack pointer modifications is small:
3686 (1) One or more auto-inc style memory references (aka pushes),
3687 (2) One or more addition/subtraction with the SP as destination,
3688 (3) A single move insn with the SP as destination,
3689 (4) A call_pop insn,
3690 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3692 Insns in the sequence that do not modify the SP are ignored,
3693 except for noreturn calls.
3695 The return value is the amount of adjustment that can be trivially
3696 verified, via immediate operand or auto-inc. If the adjustment
3697 cannot be trivially extracted, the return value is INT_MIN. */
3700 find_args_size_adjust (rtx insn
)
3705 pat
= PATTERN (insn
);
3708 /* Look for a call_pop pattern. */
3711 /* We have to allow non-call_pop patterns for the case
3712 of emit_single_push_insn of a TLS address. */
3713 if (GET_CODE (pat
) != PARALLEL
)
3716 /* All call_pop have a stack pointer adjust in the parallel.
3717 The call itself is always first, and the stack adjust is
3718 usually last, so search from the end. */
3719 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3721 set
= XVECEXP (pat
, 0, i
);
3722 if (GET_CODE (set
) != SET
)
3724 dest
= SET_DEST (set
);
3725 if (dest
== stack_pointer_rtx
)
3728 /* We'd better have found the stack pointer adjust. */
3731 /* Fall through to process the extracted SET and DEST
3732 as if it was a standalone insn. */
3734 else if (GET_CODE (pat
) == SET
)
3736 else if ((set
= single_set (insn
)) != NULL
)
3738 else if (GET_CODE (pat
) == PARALLEL
)
3740 /* ??? Some older ports use a parallel with a stack adjust
3741 and a store for a PUSH_ROUNDING pattern, rather than a
3742 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3743 /* ??? See h8300 and m68k, pushqi1. */
3744 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3746 set
= XVECEXP (pat
, 0, i
);
3747 if (GET_CODE (set
) != SET
)
3749 dest
= SET_DEST (set
);
3750 if (dest
== stack_pointer_rtx
)
3753 /* We do not expect an auto-inc of the sp in the parallel. */
3754 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3755 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3756 != stack_pointer_rtx
);
3764 dest
= SET_DEST (set
);
3766 /* Look for direct modifications of the stack pointer. */
3767 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3769 /* Look for a trivial adjustment, otherwise assume nothing. */
3770 /* Note that the SPU restore_stack_block pattern refers to
3771 the stack pointer in V4SImode. Consider that non-trivial. */
3772 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3773 && GET_CODE (SET_SRC (set
)) == PLUS
3774 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3775 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3776 return INTVAL (XEXP (SET_SRC (set
), 1));
3777 /* ??? Reload can generate no-op moves, which will be cleaned
3778 up later. Recognize it and continue searching. */
3779 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3782 return HOST_WIDE_INT_MIN
;
3788 /* Otherwise only think about autoinc patterns. */
3789 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3792 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3793 != stack_pointer_rtx
);
3795 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3796 mem
= SET_SRC (set
);
3800 addr
= XEXP (mem
, 0);
3801 switch (GET_CODE (addr
))
3805 return GET_MODE_SIZE (GET_MODE (mem
));
3808 return -GET_MODE_SIZE (GET_MODE (mem
));
3811 addr
= XEXP (addr
, 1);
3812 gcc_assert (GET_CODE (addr
) == PLUS
);
3813 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3814 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3815 return INTVAL (XEXP (addr
, 1));
3823 fixup_args_size_notes (rtx prev
, rtx last
, int end_args_size
)
3825 int args_size
= end_args_size
;
3826 bool saw_unknown
= false;
3829 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3831 HOST_WIDE_INT this_delta
;
3833 if (!NONDEBUG_INSN_P (insn
))
3836 this_delta
= find_args_size_adjust (insn
);
3837 if (this_delta
== 0)
3840 || ACCUMULATE_OUTGOING_ARGS
3841 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3845 gcc_assert (!saw_unknown
);
3846 if (this_delta
== HOST_WIDE_INT_MIN
)
3849 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3850 #ifdef STACK_GROWS_DOWNWARD
3851 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3853 args_size
-= this_delta
;
3856 return saw_unknown
? INT_MIN
: args_size
;
3859 #ifdef PUSH_ROUNDING
3860 /* Emit single push insn. */
3863 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3866 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3868 enum insn_code icode
;
3870 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3871 /* If there is push pattern, use it. Otherwise try old way of throwing
3872 MEM representing push operation to move expander. */
3873 icode
= optab_handler (push_optab
, mode
);
3874 if (icode
!= CODE_FOR_nothing
)
3876 struct expand_operand ops
[1];
3878 create_input_operand (&ops
[0], x
, mode
);
3879 if (maybe_expand_insn (icode
, 1, ops
))
3882 if (GET_MODE_SIZE (mode
) == rounded_size
)
3883 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3884 /* If we are to pad downward, adjust the stack pointer first and
3885 then store X into the stack location using an offset. This is
3886 because emit_move_insn does not know how to pad; it does not have
3888 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3890 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3891 HOST_WIDE_INT offset
;
3893 emit_move_insn (stack_pointer_rtx
,
3894 expand_binop (Pmode
,
3895 #ifdef STACK_GROWS_DOWNWARD
3901 GEN_INT (rounded_size
),
3902 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3904 offset
= (HOST_WIDE_INT
) padding_size
;
3905 #ifdef STACK_GROWS_DOWNWARD
3906 if (STACK_PUSH_CODE
== POST_DEC
)
3907 /* We have already decremented the stack pointer, so get the
3909 offset
+= (HOST_WIDE_INT
) rounded_size
;
3911 if (STACK_PUSH_CODE
== POST_INC
)
3912 /* We have already incremented the stack pointer, so get the
3914 offset
-= (HOST_WIDE_INT
) rounded_size
;
3916 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
3920 #ifdef STACK_GROWS_DOWNWARD
3921 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3922 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3923 GEN_INT (-(HOST_WIDE_INT
) rounded_size
));
3925 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3926 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3927 GEN_INT (rounded_size
));
3929 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
3932 dest
= gen_rtx_MEM (mode
, dest_addr
);
3936 set_mem_attributes (dest
, type
, 1);
3938 if (flag_optimize_sibling_calls
)
3939 /* Function incoming arguments may overlap with sibling call
3940 outgoing arguments and we cannot allow reordering of reads
3941 from function arguments with stores to outgoing arguments
3942 of sibling calls. */
3943 set_mem_alias_set (dest
, 0);
3945 emit_move_insn (dest
, x
);
3948 /* Emit and annotate a single push insn. */
3951 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
3953 int delta
, old_delta
= stack_pointer_delta
;
3954 rtx prev
= get_last_insn ();
3957 emit_single_push_insn_1 (mode
, x
, type
);
3959 last
= get_last_insn ();
3961 /* Notice the common case where we emitted exactly one insn. */
3962 if (PREV_INSN (last
) == prev
)
3964 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
3968 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
3969 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
3973 /* Generate code to push X onto the stack, assuming it has mode MODE and
3975 MODE is redundant except when X is a CONST_INT (since they don't
3977 SIZE is an rtx for the size of data to be copied (in bytes),
3978 needed only if X is BLKmode.
3980 ALIGN (in bits) is maximum alignment we can assume.
3982 If PARTIAL and REG are both nonzero, then copy that many of the first
3983 bytes of X into registers starting with REG, and push the rest of X.
3984 The amount of space pushed is decreased by PARTIAL bytes.
3985 REG must be a hard register in this case.
3986 If REG is zero but PARTIAL is not, take any all others actions for an
3987 argument partially in registers, but do not actually load any
3990 EXTRA is the amount in bytes of extra space to leave next to this arg.
3991 This is ignored if an argument block has already been allocated.
3993 On a machine that lacks real push insns, ARGS_ADDR is the address of
3994 the bottom of the argument block for this call. We use indexing off there
3995 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3996 argument block has not been preallocated.
3998 ARGS_SO_FAR is the size of args previously pushed for this call.
4000 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4001 for arguments passed in registers. If nonzero, it will be the number
4002 of bytes required. */
4005 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
4006 unsigned int align
, int partial
, rtx reg
, int extra
,
4007 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4011 enum direction stack_direction
4012 #ifdef STACK_GROWS_DOWNWARD
4018 /* Decide where to pad the argument: `downward' for below,
4019 `upward' for above, or `none' for don't pad it.
4020 Default is below for small data on big-endian machines; else above. */
4021 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4023 /* Invert direction if stack is post-decrement.
4025 if (STACK_PUSH_CODE
== POST_DEC
)
4026 if (where_pad
!= none
)
4027 where_pad
= (where_pad
== downward
? upward
: downward
);
4032 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4034 /* Copy a block into the stack, entirely or partially. */
4041 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4042 used
= partial
- offset
;
4044 if (mode
!= BLKmode
)
4046 /* A value is to be stored in an insufficiently aligned
4047 stack slot; copy via a suitably aligned slot if
4049 size
= GEN_INT (GET_MODE_SIZE (mode
));
4050 if (!MEM_P (xinner
))
4052 temp
= assign_temp (type
, 1, 1);
4053 emit_move_insn (temp
, xinner
);
4060 /* USED is now the # of bytes we need not copy to the stack
4061 because registers will take care of them. */
4064 xinner
= adjust_address (xinner
, BLKmode
, used
);
4066 /* If the partial register-part of the arg counts in its stack size,
4067 skip the part of stack space corresponding to the registers.
4068 Otherwise, start copying to the beginning of the stack space,
4069 by setting SKIP to 0. */
4070 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4072 #ifdef PUSH_ROUNDING
4073 /* Do it with several push insns if that doesn't take lots of insns
4074 and if there is no difficulty with push insns that skip bytes
4075 on the stack for alignment purposes. */
4078 && CONST_INT_P (size
)
4080 && MEM_ALIGN (xinner
) >= align
4081 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4082 /* Here we avoid the case of a structure whose weak alignment
4083 forces many pushes of a small amount of data,
4084 and such small pushes do rounding that causes trouble. */
4085 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4086 || align
>= BIGGEST_ALIGNMENT
4087 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4088 == (align
/ BITS_PER_UNIT
)))
4089 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4091 /* Push padding now if padding above and stack grows down,
4092 or if padding below and stack grows up.
4093 But if space already allocated, this has already been done. */
4094 if (extra
&& args_addr
== 0
4095 && where_pad
!= none
&& where_pad
!= stack_direction
)
4096 anti_adjust_stack (GEN_INT (extra
));
4098 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4101 #endif /* PUSH_ROUNDING */
4105 /* Otherwise make space on the stack and copy the data
4106 to the address of that space. */
4108 /* Deduct words put into registers from the size we must copy. */
4111 if (CONST_INT_P (size
))
4112 size
= GEN_INT (INTVAL (size
) - used
);
4114 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4115 GEN_INT (used
), NULL_RTX
, 0,
4119 /* Get the address of the stack space.
4120 In this case, we do not deal with EXTRA separately.
4121 A single stack adjust will do. */
4124 temp
= push_block (size
, extra
, where_pad
== downward
);
4127 else if (CONST_INT_P (args_so_far
))
4128 temp
= memory_address (BLKmode
,
4129 plus_constant (Pmode
, args_addr
,
4130 skip
+ INTVAL (args_so_far
)));
4132 temp
= memory_address (BLKmode
,
4133 plus_constant (Pmode
,
4134 gen_rtx_PLUS (Pmode
,
4139 if (!ACCUMULATE_OUTGOING_ARGS
)
4141 /* If the source is referenced relative to the stack pointer,
4142 copy it to another register to stabilize it. We do not need
4143 to do this if we know that we won't be changing sp. */
4145 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4146 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4147 temp
= copy_to_reg (temp
);
4150 target
= gen_rtx_MEM (BLKmode
, temp
);
4152 /* We do *not* set_mem_attributes here, because incoming arguments
4153 may overlap with sibling call outgoing arguments and we cannot
4154 allow reordering of reads from function arguments with stores
4155 to outgoing arguments of sibling calls. We do, however, want
4156 to record the alignment of the stack slot. */
4157 /* ALIGN may well be better aligned than TYPE, e.g. due to
4158 PARM_BOUNDARY. Assume the caller isn't lying. */
4159 set_mem_align (target
, align
);
4161 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4164 else if (partial
> 0)
4166 /* Scalar partly in registers. */
4168 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4171 /* # bytes of start of argument
4172 that we must make space for but need not store. */
4173 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4174 int args_offset
= INTVAL (args_so_far
);
4177 /* Push padding now if padding above and stack grows down,
4178 or if padding below and stack grows up.
4179 But if space already allocated, this has already been done. */
4180 if (extra
&& args_addr
== 0
4181 && where_pad
!= none
&& where_pad
!= stack_direction
)
4182 anti_adjust_stack (GEN_INT (extra
));
4184 /* If we make space by pushing it, we might as well push
4185 the real data. Otherwise, we can leave OFFSET nonzero
4186 and leave the space uninitialized. */
4190 /* Now NOT_STACK gets the number of words that we don't need to
4191 allocate on the stack. Convert OFFSET to words too. */
4192 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4193 offset
/= UNITS_PER_WORD
;
4195 /* If the partial register-part of the arg counts in its stack size,
4196 skip the part of stack space corresponding to the registers.
4197 Otherwise, start copying to the beginning of the stack space,
4198 by setting SKIP to 0. */
4199 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4201 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4202 x
= validize_mem (force_const_mem (mode
, x
));
4204 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4205 SUBREGs of such registers are not allowed. */
4206 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4207 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4208 x
= copy_to_reg (x
);
4210 /* Loop over all the words allocated on the stack for this arg. */
4211 /* We can do it by words, because any scalar bigger than a word
4212 has a size a multiple of a word. */
4213 #ifndef PUSH_ARGS_REVERSED
4214 for (i
= not_stack
; i
< size
; i
++)
4216 for (i
= size
- 1; i
>= not_stack
; i
--)
4218 if (i
>= not_stack
+ offset
)
4219 emit_push_insn (operand_subword_force (x
, i
, mode
),
4220 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4222 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4224 reg_parm_stack_space
, alignment_pad
);
4231 /* Push padding now if padding above and stack grows down,
4232 or if padding below and stack grows up.
4233 But if space already allocated, this has already been done. */
4234 if (extra
&& args_addr
== 0
4235 && where_pad
!= none
&& where_pad
!= stack_direction
)
4236 anti_adjust_stack (GEN_INT (extra
));
4238 #ifdef PUSH_ROUNDING
4239 if (args_addr
== 0 && PUSH_ARGS
)
4240 emit_single_push_insn (mode
, x
, type
);
4244 if (CONST_INT_P (args_so_far
))
4246 = memory_address (mode
,
4247 plus_constant (Pmode
, args_addr
,
4248 INTVAL (args_so_far
)));
4250 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4252 dest
= gen_rtx_MEM (mode
, addr
);
4254 /* We do *not* set_mem_attributes here, because incoming arguments
4255 may overlap with sibling call outgoing arguments and we cannot
4256 allow reordering of reads from function arguments with stores
4257 to outgoing arguments of sibling calls. We do, however, want
4258 to record the alignment of the stack slot. */
4259 /* ALIGN may well be better aligned than TYPE, e.g. due to
4260 PARM_BOUNDARY. Assume the caller isn't lying. */
4261 set_mem_align (dest
, align
);
4263 emit_move_insn (dest
, x
);
4267 /* If part should go in registers, copy that part
4268 into the appropriate registers. Do this now, at the end,
4269 since mem-to-mem copies above may do function calls. */
4270 if (partial
> 0 && reg
!= 0)
4272 /* Handle calls that pass values in multiple non-contiguous locations.
4273 The Irix 6 ABI has examples of this. */
4274 if (GET_CODE (reg
) == PARALLEL
)
4275 emit_group_load (reg
, x
, type
, -1);
4278 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4279 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4283 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4284 anti_adjust_stack (GEN_INT (extra
));
4286 if (alignment_pad
&& args_addr
== 0)
4287 anti_adjust_stack (alignment_pad
);
4290 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4294 get_subtarget (rtx x
)
4298 /* Only registers can be subtargets. */
4300 /* Don't use hard regs to avoid extending their life. */
4301 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4305 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4306 FIELD is a bitfield. Returns true if the optimization was successful,
4307 and there's nothing else to do. */
4310 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4311 unsigned HOST_WIDE_INT bitpos
,
4312 unsigned HOST_WIDE_INT bitregion_start
,
4313 unsigned HOST_WIDE_INT bitregion_end
,
4314 enum machine_mode mode1
, rtx str_rtx
,
4317 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4318 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4323 enum tree_code code
;
4325 if (mode1
!= VOIDmode
4326 || bitsize
>= BITS_PER_WORD
4327 || str_bitsize
> BITS_PER_WORD
4328 || TREE_SIDE_EFFECTS (to
)
4329 || TREE_THIS_VOLATILE (to
))
4333 if (TREE_CODE (src
) != SSA_NAME
)
4335 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4338 srcstmt
= get_gimple_for_ssa_name (src
);
4340 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4343 code
= gimple_assign_rhs_code (srcstmt
);
4345 op0
= gimple_assign_rhs1 (srcstmt
);
4347 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4348 to find its initialization. Hopefully the initialization will
4349 be from a bitfield load. */
4350 if (TREE_CODE (op0
) == SSA_NAME
)
4352 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4354 /* We want to eventually have OP0 be the same as TO, which
4355 should be a bitfield. */
4357 || !is_gimple_assign (op0stmt
)
4358 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4360 op0
= gimple_assign_rhs1 (op0stmt
);
4363 op1
= gimple_assign_rhs2 (srcstmt
);
4365 if (!operand_equal_p (to
, op0
, 0))
4368 if (MEM_P (str_rtx
))
4370 unsigned HOST_WIDE_INT offset1
;
4372 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4373 str_mode
= word_mode
;
4374 str_mode
= get_best_mode (bitsize
, bitpos
,
4375 bitregion_start
, bitregion_end
,
4376 MEM_ALIGN (str_rtx
), str_mode
, 0);
4377 if (str_mode
== VOIDmode
)
4379 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4382 bitpos
%= str_bitsize
;
4383 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4384 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4386 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4389 /* If the bit field covers the whole REG/MEM, store_field
4390 will likely generate better code. */
4391 if (bitsize
>= str_bitsize
)
4394 /* We can't handle fields split across multiple entities. */
4395 if (bitpos
+ bitsize
> str_bitsize
)
4398 if (BYTES_BIG_ENDIAN
)
4399 bitpos
= str_bitsize
- bitpos
- bitsize
;
4405 /* For now, just optimize the case of the topmost bitfield
4406 where we don't need to do any masking and also
4407 1 bit bitfields where xor can be used.
4408 We might win by one instruction for the other bitfields
4409 too if insv/extv instructions aren't used, so that
4410 can be added later. */
4411 if (bitpos
+ bitsize
!= str_bitsize
4412 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4415 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4416 value
= convert_modes (str_mode
,
4417 TYPE_MODE (TREE_TYPE (op1
)), value
,
4418 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4420 /* We may be accessing data outside the field, which means
4421 we can alias adjacent data. */
4422 if (MEM_P (str_rtx
))
4424 str_rtx
= shallow_copy_rtx (str_rtx
);
4425 set_mem_alias_set (str_rtx
, 0);
4426 set_mem_expr (str_rtx
, 0);
4429 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4430 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4432 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4435 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4436 result
= expand_binop (str_mode
, binop
, str_rtx
,
4437 value
, str_rtx
, 1, OPTAB_WIDEN
);
4438 if (result
!= str_rtx
)
4439 emit_move_insn (str_rtx
, result
);
4444 if (TREE_CODE (op1
) != INTEGER_CST
)
4446 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4447 value
= convert_modes (str_mode
,
4448 TYPE_MODE (TREE_TYPE (op1
)), value
,
4449 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4451 /* We may be accessing data outside the field, which means
4452 we can alias adjacent data. */
4453 if (MEM_P (str_rtx
))
4455 str_rtx
= shallow_copy_rtx (str_rtx
);
4456 set_mem_alias_set (str_rtx
, 0);
4457 set_mem_expr (str_rtx
, 0);
4460 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4461 if (bitpos
+ bitsize
!= str_bitsize
)
4463 rtx mask
= GEN_INT (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1);
4464 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4466 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4467 result
= expand_binop (str_mode
, binop
, str_rtx
,
4468 value
, str_rtx
, 1, OPTAB_WIDEN
);
4469 if (result
!= str_rtx
)
4470 emit_move_insn (str_rtx
, result
);
4480 /* In the C++ memory model, consecutive bit fields in a structure are
4481 considered one memory location.
4483 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4484 returns the bit range of consecutive bits in which this COMPONENT_REF
4485 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4486 and *OFFSET may be adjusted in the process.
4488 If the access does not need to be restricted, 0 is returned in both
4489 *BITSTART and *BITEND. */
4492 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4493 unsigned HOST_WIDE_INT
*bitend
,
4495 HOST_WIDE_INT
*bitpos
,
4498 HOST_WIDE_INT bitoffset
;
4501 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4503 field
= TREE_OPERAND (exp
, 1);
4504 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4505 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4506 need to limit the range we can access. */
4509 *bitstart
= *bitend
= 0;
4513 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4514 part of a larger bit field, then the representative does not serve any
4515 useful purpose. This can occur in Ada. */
4516 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4518 enum machine_mode rmode
;
4519 HOST_WIDE_INT rbitsize
, rbitpos
;
4523 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4524 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4525 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4527 *bitstart
= *bitend
= 0;
4532 /* Compute the adjustment to bitpos from the offset of the field
4533 relative to the representative. DECL_FIELD_OFFSET of field and
4534 repr are the same by construction if they are not constants,
4535 see finish_bitfield_layout. */
4536 if (host_integerp (DECL_FIELD_OFFSET (field
), 1)
4537 && host_integerp (DECL_FIELD_OFFSET (repr
), 1))
4538 bitoffset
= (tree_low_cst (DECL_FIELD_OFFSET (field
), 1)
4539 - tree_low_cst (DECL_FIELD_OFFSET (repr
), 1)) * BITS_PER_UNIT
;
4542 bitoffset
+= (tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 1)
4543 - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr
), 1));
4545 /* If the adjustment is larger than bitpos, we would have a negative bit
4546 position for the lower bound and this may wreak havoc later. This can
4547 occur only if we have a non-null offset, so adjust offset and bitpos
4548 to make the lower bound non-negative. */
4549 if (bitoffset
> *bitpos
)
4551 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4553 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4554 gcc_assert (*offset
!= NULL_TREE
);
4558 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4562 *bitstart
= *bitpos
- bitoffset
;
4564 *bitend
= *bitstart
+ tree_low_cst (DECL_SIZE (repr
), 1) - 1;
4567 /* Returns true if the MEM_REF REF refers to an object that does not
4568 reside in memory and has non-BLKmode. */
4571 mem_ref_refers_to_non_mem_p (tree ref
)
4573 tree base
= TREE_OPERAND (ref
, 0);
4574 if (TREE_CODE (base
) != ADDR_EXPR
)
4576 base
= TREE_OPERAND (base
, 0);
4577 return (DECL_P (base
)
4578 && !TREE_ADDRESSABLE (base
)
4579 && DECL_MODE (base
) != BLKmode
4580 && DECL_RTL_SET_P (base
)
4581 && !MEM_P (DECL_RTL (base
)));
4584 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4585 is true, try generating a nontemporal store. */
4588 expand_assignment (tree to
, tree from
, bool nontemporal
)
4592 enum machine_mode mode
;
4594 enum insn_code icode
;
4596 /* Don't crash if the lhs of the assignment was erroneous. */
4597 if (TREE_CODE (to
) == ERROR_MARK
)
4599 expand_normal (from
);
4603 /* Optimize away no-op moves without side-effects. */
4604 if (operand_equal_p (to
, from
, 0))
4607 /* Handle misaligned stores. */
4608 mode
= TYPE_MODE (TREE_TYPE (to
));
4609 if ((TREE_CODE (to
) == MEM_REF
4610 || TREE_CODE (to
) == TARGET_MEM_REF
)
4612 && !mem_ref_refers_to_non_mem_p (to
)
4613 && ((align
= get_object_alignment (to
))
4614 < GET_MODE_ALIGNMENT (mode
))
4615 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4616 != CODE_FOR_nothing
)
4617 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4621 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4622 reg
= force_not_mem (reg
);
4623 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4625 if (icode
!= CODE_FOR_nothing
)
4627 struct expand_operand ops
[2];
4629 create_fixed_operand (&ops
[0], mem
);
4630 create_input_operand (&ops
[1], reg
, mode
);
4631 /* The movmisalign<mode> pattern cannot fail, else the assignment
4632 would silently be omitted. */
4633 expand_insn (icode
, 2, ops
);
4636 store_bit_field (mem
, GET_MODE_BITSIZE (mode
),
4637 0, 0, 0, mode
, reg
);
4641 /* Assignment of a structure component needs special treatment
4642 if the structure component's rtx is not simply a MEM.
4643 Assignment of an array element at a constant index, and assignment of
4644 an array element in an unaligned packed structure field, has the same
4645 problem. Same for (partially) storing into a non-memory object. */
4646 if (handled_component_p (to
)
4647 || (TREE_CODE (to
) == MEM_REF
4648 && mem_ref_refers_to_non_mem_p (to
))
4649 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4651 enum machine_mode mode1
;
4652 HOST_WIDE_INT bitsize
, bitpos
;
4653 unsigned HOST_WIDE_INT bitregion_start
= 0;
4654 unsigned HOST_WIDE_INT bitregion_end
= 0;
4663 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4664 &unsignedp
, &volatilep
, true);
4666 if (TREE_CODE (to
) == COMPONENT_REF
4667 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4668 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4670 /* If we are going to use store_bit_field and extract_bit_field,
4671 make sure to_rtx will be safe for multiple use. */
4672 mode
= TYPE_MODE (TREE_TYPE (tem
));
4673 if (TREE_CODE (tem
) == MEM_REF
4675 && ((align
= get_object_alignment (tem
))
4676 < GET_MODE_ALIGNMENT (mode
))
4677 && ((icode
= optab_handler (movmisalign_optab
, mode
))
4678 != CODE_FOR_nothing
))
4680 struct expand_operand ops
[2];
4683 to_rtx
= gen_reg_rtx (mode
);
4684 mem
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4686 /* If the misaligned store doesn't overwrite all bits, perform
4687 rmw cycle on MEM. */
4688 if (bitsize
!= GET_MODE_BITSIZE (mode
))
4690 create_input_operand (&ops
[0], to_rtx
, mode
);
4691 create_fixed_operand (&ops
[1], mem
);
4692 /* The movmisalign<mode> pattern cannot fail, else the assignment
4693 would silently be omitted. */
4694 expand_insn (icode
, 2, ops
);
4696 mem
= copy_rtx (mem
);
4702 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4705 /* If the bitfield is volatile, we want to access it in the
4706 field's mode, not the computed mode.
4707 If a MEM has VOIDmode (external with incomplete type),
4708 use BLKmode for it instead. */
4711 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
4712 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4713 else if (GET_MODE (to_rtx
) == VOIDmode
)
4714 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4719 enum machine_mode address_mode
;
4722 if (!MEM_P (to_rtx
))
4724 /* We can get constant negative offsets into arrays with broken
4725 user code. Translate this to a trap instead of ICEing. */
4726 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4727 expand_builtin_trap ();
4728 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4731 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4732 address_mode
= get_address_mode (to_rtx
);
4733 if (GET_MODE (offset_rtx
) != address_mode
)
4734 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4736 /* A constant address in TO_RTX can have VOIDmode, we must not try
4737 to call force_reg for that case. Avoid that case. */
4739 && GET_MODE (to_rtx
) == BLKmode
4740 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
4742 && (bitpos
% bitsize
) == 0
4743 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4744 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
4746 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4750 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4751 highest_pow2_factor_for_target (to
,
4755 /* No action is needed if the target is not a memory and the field
4756 lies completely outside that target. This can occur if the source
4757 code contains an out-of-bounds access to a small array. */
4759 && GET_MODE (to_rtx
) != BLKmode
4760 && (unsigned HOST_WIDE_INT
) bitpos
4761 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4763 expand_normal (from
);
4766 /* Handle expand_expr of a complex value returning a CONCAT. */
4767 else if (GET_CODE (to_rtx
) == CONCAT
)
4769 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4770 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4772 && bitsize
== mode_bitsize
)
4773 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4774 else if (bitsize
== mode_bitsize
/ 2
4775 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4776 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4778 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4779 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4780 bitregion_start
, bitregion_end
,
4781 mode1
, from
, TREE_TYPE (tem
),
4782 get_alias_set (to
), nontemporal
);
4783 else if (bitpos
>= mode_bitsize
/ 2)
4784 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4785 bitpos
- mode_bitsize
/ 2,
4786 bitregion_start
, bitregion_end
,
4788 TREE_TYPE (tem
), get_alias_set (to
),
4790 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4793 result
= expand_normal (from
);
4794 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4795 TYPE_MODE (TREE_TYPE (from
)), 0);
4796 emit_move_insn (XEXP (to_rtx
, 0),
4797 read_complex_part (from_rtx
, false));
4798 emit_move_insn (XEXP (to_rtx
, 1),
4799 read_complex_part (from_rtx
, true));
4803 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4804 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4805 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4806 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4807 result
= store_field (temp
, bitsize
, bitpos
,
4808 bitregion_start
, bitregion_end
,
4810 TREE_TYPE (tem
), get_alias_set (to
),
4812 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4813 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4820 /* If the field is at offset zero, we could have been given the
4821 DECL_RTX of the parent struct. Don't munge it. */
4822 to_rtx
= shallow_copy_rtx (to_rtx
);
4824 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4826 /* Deal with volatile and readonly fields. The former is only
4827 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4829 MEM_VOLATILE_P (to_rtx
) = 1;
4830 if (component_uses_parent_alias_set (to
))
4831 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
4834 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4835 bitregion_start
, bitregion_end
,
4840 result
= store_field (to_rtx
, bitsize
, bitpos
,
4841 bitregion_start
, bitregion_end
,
4843 TREE_TYPE (tem
), get_alias_set (to
),
4849 struct expand_operand ops
[2];
4851 create_fixed_operand (&ops
[0], mem
);
4852 create_input_operand (&ops
[1], to_rtx
, mode
);
4853 /* The movmisalign<mode> pattern cannot fail, else the assignment
4854 would silently be omitted. */
4855 expand_insn (icode
, 2, ops
);
4859 preserve_temp_slots (result
);
4864 /* If the rhs is a function call and its value is not an aggregate,
4865 call the function before we start to compute the lhs.
4866 This is needed for correct code for cases such as
4867 val = setjmp (buf) on machines where reference to val
4868 requires loading up part of an address in a separate insn.
4870 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4871 since it might be a promoted variable where the zero- or sign- extension
4872 needs to be done. Handling this in the normal way is safe because no
4873 computation is done before the call. The same is true for SSA names. */
4874 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4875 && COMPLETE_TYPE_P (TREE_TYPE (from
))
4876 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4877 && ! (((TREE_CODE (to
) == VAR_DECL
4878 || TREE_CODE (to
) == PARM_DECL
4879 || TREE_CODE (to
) == RESULT_DECL
)
4880 && REG_P (DECL_RTL (to
)))
4881 || TREE_CODE (to
) == SSA_NAME
))
4886 value
= expand_normal (from
);
4888 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4890 /* Handle calls that return values in multiple non-contiguous locations.
4891 The Irix 6 ABI has examples of this. */
4892 if (GET_CODE (to_rtx
) == PARALLEL
)
4894 if (GET_CODE (value
) == PARALLEL
)
4895 emit_group_move (to_rtx
, value
);
4897 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
4898 int_size_in_bytes (TREE_TYPE (from
)));
4900 else if (GET_CODE (value
) == PARALLEL
)
4901 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
4902 int_size_in_bytes (TREE_TYPE (from
)));
4903 else if (GET_MODE (to_rtx
) == BLKmode
)
4906 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
4908 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
4912 if (POINTER_TYPE_P (TREE_TYPE (to
)))
4913 value
= convert_memory_address_addr_space
4914 (GET_MODE (to_rtx
), value
,
4915 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
4917 emit_move_insn (to_rtx
, value
);
4919 preserve_temp_slots (to_rtx
);
4924 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4925 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4927 /* Don't move directly into a return register. */
4928 if (TREE_CODE (to
) == RESULT_DECL
4929 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
4934 if (REG_P (to_rtx
) && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
)
4935 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
4937 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
4939 /* Handle calls that return values in multiple non-contiguous locations.
4940 The Irix 6 ABI has examples of this. */
4941 if (GET_CODE (to_rtx
) == PARALLEL
)
4943 if (GET_CODE (temp
) == PARALLEL
)
4944 emit_group_move (to_rtx
, temp
);
4946 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
4947 int_size_in_bytes (TREE_TYPE (from
)));
4950 emit_move_insn (to_rtx
, temp
);
4952 preserve_temp_slots (to_rtx
);
4957 /* In case we are returning the contents of an object which overlaps
4958 the place the value is being stored, use a safe function when copying
4959 a value through a pointer into a structure value return block. */
4960 if (TREE_CODE (to
) == RESULT_DECL
4961 && TREE_CODE (from
) == INDIRECT_REF
4962 && ADDR_SPACE_GENERIC_P
4963 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
4964 && refs_may_alias_p (to
, from
)
4965 && cfun
->returns_struct
4966 && !cfun
->returns_pcc_struct
)
4971 size
= expr_size (from
);
4972 from_rtx
= expand_normal (from
);
4974 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
4975 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
4976 XEXP (from_rtx
, 0), Pmode
,
4977 convert_to_mode (TYPE_MODE (sizetype
),
4978 size
, TYPE_UNSIGNED (sizetype
)),
4979 TYPE_MODE (sizetype
));
4981 preserve_temp_slots (to_rtx
);
4986 /* Compute FROM and store the value in the rtx we got. */
4989 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
4990 preserve_temp_slots (result
);
4995 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
4996 succeeded, false otherwise. */
4999 emit_storent_insn (rtx to
, rtx from
)
5001 struct expand_operand ops
[2];
5002 enum machine_mode mode
= GET_MODE (to
);
5003 enum insn_code code
= optab_handler (storent_optab
, mode
);
5005 if (code
== CODE_FOR_nothing
)
5008 create_fixed_operand (&ops
[0], to
);
5009 create_input_operand (&ops
[1], from
, mode
);
5010 return maybe_expand_insn (code
, 2, ops
);
5013 /* Generate code for computing expression EXP,
5014 and storing the value into TARGET.
5016 If the mode is BLKmode then we may return TARGET itself.
5017 It turns out that in BLKmode it doesn't cause a problem.
5018 because C has no operators that could combine two different
5019 assignments into the same BLKmode object with different values
5020 with no sequence point. Will other languages need this to
5023 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5024 stack, and block moves may need to be treated specially.
5026 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5029 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5032 rtx alt_rtl
= NULL_RTX
;
5033 location_t loc
= EXPR_LOCATION (exp
);
5035 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5037 /* C++ can generate ?: expressions with a throw expression in one
5038 branch and an rvalue in the other. Here, we resolve attempts to
5039 store the throw expression's nonexistent result. */
5040 gcc_assert (!call_param_p
);
5041 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5044 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5046 /* Perform first part of compound expression, then assign from second
5048 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5049 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5050 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5053 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5055 /* For conditional expression, get safe form of the target. Then
5056 test the condition, doing the appropriate assignment on either
5057 side. This avoids the creation of unnecessary temporaries.
5058 For non-BLKmode, it is more efficient not to do this. */
5060 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
5062 do_pending_stack_adjust ();
5064 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5065 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5067 emit_jump_insn (gen_jump (lab2
));
5070 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5077 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5078 /* If this is a scalar in a register that is stored in a wider mode
5079 than the declared mode, compute the result into its declared mode
5080 and then convert to the wider mode. Our value is the computed
5083 rtx inner_target
= 0;
5085 /* We can do the conversion inside EXP, which will often result
5086 in some optimizations. Do the conversion in two steps: first
5087 change the signedness, if needed, then the extend. But don't
5088 do this if the type of EXP is a subtype of something else
5089 since then the conversion might involve more than just
5090 converting modes. */
5091 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5092 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5093 && GET_MODE_PRECISION (GET_MODE (target
))
5094 == TYPE_PRECISION (TREE_TYPE (exp
)))
5096 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
5097 != SUBREG_PROMOTED_UNSIGNED_P (target
))
5099 /* Some types, e.g. Fortran's logical*4, won't have a signed
5100 version, so use the mode instead. */
5102 = (signed_or_unsigned_type_for
5103 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)));
5105 ntype
= lang_hooks
.types
.type_for_mode
5106 (TYPE_MODE (TREE_TYPE (exp
)),
5107 SUBREG_PROMOTED_UNSIGNED_P (target
));
5109 exp
= fold_convert_loc (loc
, ntype
, exp
);
5112 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5113 (GET_MODE (SUBREG_REG (target
)),
5114 SUBREG_PROMOTED_UNSIGNED_P (target
)),
5117 inner_target
= SUBREG_REG (target
);
5120 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5121 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5123 /* If TEMP is a VOIDmode constant, use convert_modes to make
5124 sure that we properly convert it. */
5125 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5127 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5128 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
5129 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5130 GET_MODE (target
), temp
,
5131 SUBREG_PROMOTED_UNSIGNED_P (target
));
5134 convert_move (SUBREG_REG (target
), temp
,
5135 SUBREG_PROMOTED_UNSIGNED_P (target
));
5139 else if ((TREE_CODE (exp
) == STRING_CST
5140 || (TREE_CODE (exp
) == MEM_REF
5141 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5142 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5144 && integer_zerop (TREE_OPERAND (exp
, 1))))
5145 && !nontemporal
&& !call_param_p
5148 /* Optimize initialization of an array with a STRING_CST. */
5149 HOST_WIDE_INT exp_len
, str_copy_len
;
5151 tree str
= TREE_CODE (exp
) == STRING_CST
5152 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5154 exp_len
= int_expr_size (exp
);
5158 if (TREE_STRING_LENGTH (str
) <= 0)
5161 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5162 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5165 str_copy_len
= TREE_STRING_LENGTH (str
);
5166 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5167 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5169 str_copy_len
+= STORE_MAX_PIECES
- 1;
5170 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5172 str_copy_len
= MIN (str_copy_len
, exp_len
);
5173 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5174 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5175 MEM_ALIGN (target
), false))
5180 dest_mem
= store_by_pieces (dest_mem
,
5181 str_copy_len
, builtin_strncpy_read_str
,
5183 TREE_STRING_POINTER (str
)),
5184 MEM_ALIGN (target
), false,
5185 exp_len
> str_copy_len
? 1 : 0);
5186 if (exp_len
> str_copy_len
)
5187 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5188 GEN_INT (exp_len
- str_copy_len
),
5197 /* If we want to use a nontemporal store, force the value to
5199 tmp_target
= nontemporal
? NULL_RTX
: target
;
5200 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5202 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5206 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5207 the same as that of TARGET, adjust the constant. This is needed, for
5208 example, in case it is a CONST_DOUBLE and we want only a word-sized
5210 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5211 && TREE_CODE (exp
) != ERROR_MARK
5212 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5213 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5214 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5216 /* If value was not generated in the target, store it there.
5217 Convert the value to TARGET's type first if necessary and emit the
5218 pending incrementations that have been queued when expanding EXP.
5219 Note that we cannot emit the whole queue blindly because this will
5220 effectively disable the POST_INC optimization later.
5222 If TEMP and TARGET compare equal according to rtx_equal_p, but
5223 one or both of them are volatile memory refs, we have to distinguish
5225 - expand_expr has used TARGET. In this case, we must not generate
5226 another copy. This can be detected by TARGET being equal according
5228 - expand_expr has not used TARGET - that means that the source just
5229 happens to have the same RTX form. Since temp will have been created
5230 by expand_expr, it will compare unequal according to == .
5231 We must generate a copy in this case, to reach the correct number
5232 of volatile memory references. */
5234 if ((! rtx_equal_p (temp
, target
)
5235 || (temp
!= target
&& (side_effects_p (temp
)
5236 || side_effects_p (target
))))
5237 && TREE_CODE (exp
) != ERROR_MARK
5238 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5239 but TARGET is not valid memory reference, TEMP will differ
5240 from TARGET although it is really the same location. */
5242 && rtx_equal_p (alt_rtl
, target
)
5243 && !side_effects_p (alt_rtl
)
5244 && !side_effects_p (target
))
5245 /* If there's nothing to copy, don't bother. Don't call
5246 expr_size unless necessary, because some front-ends (C++)
5247 expr_size-hook must not be given objects that are not
5248 supposed to be bit-copied or bit-initialized. */
5249 && expr_size (exp
) != const0_rtx
)
5251 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5253 if (GET_MODE (target
) == BLKmode
)
5257 if (TREE_CODE (exp
) == CALL_EXPR
)
5258 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5260 store_bit_field (target
,
5261 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5262 0, 0, 0, GET_MODE (temp
), temp
);
5265 emit_block_move (target
, temp
, expr_size (exp
),
5267 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5270 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5273 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5275 /* Handle copying a string constant into an array. The string
5276 constant may be shorter than the array. So copy just the string's
5277 actual length, and clear the rest. First get the size of the data
5278 type of the string, which is actually the size of the target. */
5279 rtx size
= expr_size (exp
);
5281 if (CONST_INT_P (size
)
5282 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5283 emit_block_move (target
, temp
, size
,
5285 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5288 enum machine_mode pointer_mode
5289 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5290 enum machine_mode address_mode
= get_address_mode (target
);
5292 /* Compute the size of the data to copy from the string. */
5294 = size_binop_loc (loc
, MIN_EXPR
,
5295 make_tree (sizetype
, size
),
5296 size_int (TREE_STRING_LENGTH (exp
)));
5298 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5300 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5303 /* Copy that much. */
5304 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5305 TYPE_UNSIGNED (sizetype
));
5306 emit_block_move (target
, temp
, copy_size_rtx
,
5308 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5310 /* Figure out how much is left in TARGET that we have to clear.
5311 Do all calculations in pointer_mode. */
5312 if (CONST_INT_P (copy_size_rtx
))
5314 size
= plus_constant (address_mode
, size
,
5315 -INTVAL (copy_size_rtx
));
5316 target
= adjust_address (target
, BLKmode
,
5317 INTVAL (copy_size_rtx
));
5321 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5322 copy_size_rtx
, NULL_RTX
, 0,
5325 if (GET_MODE (copy_size_rtx
) != address_mode
)
5326 copy_size_rtx
= convert_to_mode (address_mode
,
5328 TYPE_UNSIGNED (sizetype
));
5330 target
= offset_address (target
, copy_size_rtx
,
5331 highest_pow2_factor (copy_size
));
5332 label
= gen_label_rtx ();
5333 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5334 GET_MODE (size
), 0, label
);
5337 if (size
!= const0_rtx
)
5338 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5344 /* Handle calls that return values in multiple non-contiguous locations.
5345 The Irix 6 ABI has examples of this. */
5346 else if (GET_CODE (target
) == PARALLEL
)
5348 if (GET_CODE (temp
) == PARALLEL
)
5349 emit_group_move (target
, temp
);
5351 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5352 int_size_in_bytes (TREE_TYPE (exp
)));
5354 else if (GET_CODE (temp
) == PARALLEL
)
5355 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5356 int_size_in_bytes (TREE_TYPE (exp
)));
5357 else if (GET_MODE (temp
) == BLKmode
)
5358 emit_block_move (target
, temp
, expr_size (exp
),
5360 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5361 /* If we emit a nontemporal store, there is nothing else to do. */
5362 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5366 temp
= force_operand (temp
, target
);
5368 emit_move_insn (target
, temp
);
5375 /* Return true if field F of structure TYPE is a flexible array. */
5378 flexible_array_member_p (const_tree f
, const_tree type
)
5383 return (DECL_CHAIN (f
) == NULL
5384 && TREE_CODE (tf
) == ARRAY_TYPE
5386 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5387 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5388 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5389 && int_size_in_bytes (type
) >= 0);
5392 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5393 must have in order for it to completely initialize a value of type TYPE.
5394 Return -1 if the number isn't known.
5396 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5398 static HOST_WIDE_INT
5399 count_type_elements (const_tree type
, bool for_ctor_p
)
5401 switch (TREE_CODE (type
))
5407 nelts
= array_type_nelts (type
);
5408 if (nelts
&& host_integerp (nelts
, 1))
5410 unsigned HOST_WIDE_INT n
;
5412 n
= tree_low_cst (nelts
, 1) + 1;
5413 if (n
== 0 || for_ctor_p
)
5416 return n
* count_type_elements (TREE_TYPE (type
), false);
5418 return for_ctor_p
? -1 : 1;
5423 unsigned HOST_WIDE_INT n
;
5427 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5428 if (TREE_CODE (f
) == FIELD_DECL
)
5431 n
+= count_type_elements (TREE_TYPE (f
), false);
5432 else if (!flexible_array_member_p (f
, type
))
5433 /* Don't count flexible arrays, which are not supposed
5434 to be initialized. */
5442 case QUAL_UNION_TYPE
:
5447 gcc_assert (!for_ctor_p
);
5448 /* Estimate the number of scalars in each field and pick the
5449 maximum. Other estimates would do instead; the idea is simply
5450 to make sure that the estimate is not sensitive to the ordering
5453 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5454 if (TREE_CODE (f
) == FIELD_DECL
)
5456 m
= count_type_elements (TREE_TYPE (f
), false);
5457 /* If the field doesn't span the whole union, add an extra
5458 scalar for the rest. */
5459 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5460 TYPE_SIZE (type
)) != 1)
5472 return TYPE_VECTOR_SUBPARTS (type
);
5476 case FIXED_POINT_TYPE
:
5481 case REFERENCE_TYPE
:
5497 /* Helper for categorize_ctor_elements. Identical interface. */
5500 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5501 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5503 unsigned HOST_WIDE_INT idx
;
5504 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5505 tree value
, purpose
, elt_type
;
5507 /* Whether CTOR is a valid constant initializer, in accordance with what
5508 initializer_constant_valid_p does. If inferred from the constructor
5509 elements, true until proven otherwise. */
5510 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5511 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5516 elt_type
= NULL_TREE
;
5518 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5520 HOST_WIDE_INT mult
= 1;
5522 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5524 tree lo_index
= TREE_OPERAND (purpose
, 0);
5525 tree hi_index
= TREE_OPERAND (purpose
, 1);
5527 if (host_integerp (lo_index
, 1) && host_integerp (hi_index
, 1))
5528 mult
= (tree_low_cst (hi_index
, 1)
5529 - tree_low_cst (lo_index
, 1) + 1);
5532 elt_type
= TREE_TYPE (value
);
5534 switch (TREE_CODE (value
))
5538 HOST_WIDE_INT nz
= 0, ic
= 0;
5540 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5543 nz_elts
+= mult
* nz
;
5544 init_elts
+= mult
* ic
;
5546 if (const_from_elts_p
&& const_p
)
5547 const_p
= const_elt_p
;
5554 if (!initializer_zerop (value
))
5560 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5561 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5565 if (!initializer_zerop (TREE_REALPART (value
)))
5567 if (!initializer_zerop (TREE_IMAGPART (value
)))
5575 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5577 tree v
= VECTOR_CST_ELT (value
, i
);
5578 if (!initializer_zerop (v
))
5587 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5588 nz_elts
+= mult
* tc
;
5589 init_elts
+= mult
* tc
;
5591 if (const_from_elts_p
&& const_p
)
5592 const_p
= initializer_constant_valid_p (value
, elt_type
)
5599 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5600 num_fields
, elt_type
))
5601 *p_complete
= false;
5603 *p_nz_elts
+= nz_elts
;
5604 *p_init_elts
+= init_elts
;
5609 /* Examine CTOR to discover:
5610 * how many scalar fields are set to nonzero values,
5611 and place it in *P_NZ_ELTS;
5612 * how many scalar fields in total are in CTOR,
5613 and place it in *P_ELT_COUNT.
5614 * whether the constructor is complete -- in the sense that every
5615 meaningful byte is explicitly given a value --
5616 and place it in *P_COMPLETE.
5618 Return whether or not CTOR is a valid static constant initializer, the same
5619 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5622 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5623 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5629 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5632 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5633 of which had type LAST_TYPE. Each element was itself a complete
5634 initializer, in the sense that every meaningful byte was explicitly
5635 given a value. Return true if the same is true for the constructor
5639 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5640 const_tree last_type
)
5642 if (TREE_CODE (type
) == UNION_TYPE
5643 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5648 gcc_assert (num_elts
== 1 && last_type
);
5650 /* ??? We could look at each element of the union, and find the
5651 largest element. Which would avoid comparing the size of the
5652 initialized element against any tail padding in the union.
5653 Doesn't seem worth the effort... */
5654 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5657 return count_type_elements (type
, true) == num_elts
;
5660 /* Return 1 if EXP contains mostly (3/4) zeros. */
5663 mostly_zeros_p (const_tree exp
)
5665 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5667 HOST_WIDE_INT nz_elts
, init_elts
;
5670 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5671 return !complete_p
|| nz_elts
< init_elts
/ 4;
5674 return initializer_zerop (exp
);
5677 /* Return 1 if EXP contains all zeros. */
5680 all_zeros_p (const_tree exp
)
5682 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5684 HOST_WIDE_INT nz_elts
, init_elts
;
5687 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5688 return nz_elts
== 0;
5691 return initializer_zerop (exp
);
5694 /* Helper function for store_constructor.
5695 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5696 TYPE is the type of the CONSTRUCTOR, not the element type.
5697 CLEARED is as for store_constructor.
5698 ALIAS_SET is the alias set to use for any stores.
5700 This provides a recursive shortcut back to store_constructor when it isn't
5701 necessary to go through store_field. This is so that we can pass through
5702 the cleared field to let store_constructor know that we may not have to
5703 clear a substructure if the outer structure has already been cleared. */
5706 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5707 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5708 tree exp
, tree type
, int cleared
,
5709 alias_set_type alias_set
)
5711 if (TREE_CODE (exp
) == CONSTRUCTOR
5712 /* We can only call store_constructor recursively if the size and
5713 bit position are on a byte boundary. */
5714 && bitpos
% BITS_PER_UNIT
== 0
5715 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5716 /* If we have a nonzero bitpos for a register target, then we just
5717 let store_field do the bitfield handling. This is unlikely to
5718 generate unnecessary clear instructions anyways. */
5719 && (bitpos
== 0 || MEM_P (target
)))
5723 = adjust_address (target
,
5724 GET_MODE (target
) == BLKmode
5726 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5727 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5730 /* Update the alias set, if required. */
5731 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5732 && MEM_ALIAS_SET (target
) != 0)
5734 target
= copy_rtx (target
);
5735 set_mem_alias_set (target
, alias_set
);
5738 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5741 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, type
, alias_set
,
5745 /* Store the value of constructor EXP into the rtx TARGET.
5746 TARGET is either a REG or a MEM; we know it cannot conflict, since
5747 safe_from_p has been called.
5748 CLEARED is true if TARGET is known to have been zero'd.
5749 SIZE is the number of bytes of TARGET we are allowed to modify: this
5750 may not be the same as the size of EXP if we are assigning to a field
5751 which has been packed to exclude padding bits. */
5754 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5756 tree type
= TREE_TYPE (exp
);
5757 #ifdef WORD_REGISTER_OPERATIONS
5758 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5761 switch (TREE_CODE (type
))
5765 case QUAL_UNION_TYPE
:
5767 unsigned HOST_WIDE_INT idx
;
5770 /* If size is zero or the target is already cleared, do nothing. */
5771 if (size
== 0 || cleared
)
5773 /* We either clear the aggregate or indicate the value is dead. */
5774 else if ((TREE_CODE (type
) == UNION_TYPE
5775 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5776 && ! CONSTRUCTOR_ELTS (exp
))
5777 /* If the constructor is empty, clear the union. */
5779 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5783 /* If we are building a static constructor into a register,
5784 set the initial value as zero so we can fold the value into
5785 a constant. But if more than one register is involved,
5786 this probably loses. */
5787 else if (REG_P (target
) && TREE_STATIC (exp
)
5788 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5790 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5794 /* If the constructor has fewer fields than the structure or
5795 if we are initializing the structure to mostly zeros, clear
5796 the whole structure first. Don't do this if TARGET is a
5797 register whose mode size isn't equal to SIZE since
5798 clear_storage can't handle this case. */
5800 && (((int)VEC_length (constructor_elt
, CONSTRUCTOR_ELTS (exp
))
5801 != fields_length (type
))
5802 || mostly_zeros_p (exp
))
5804 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5807 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5811 if (REG_P (target
) && !cleared
)
5812 emit_clobber (target
);
5814 /* Store each element of the constructor into the
5815 corresponding field of TARGET. */
5816 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5818 enum machine_mode mode
;
5819 HOST_WIDE_INT bitsize
;
5820 HOST_WIDE_INT bitpos
= 0;
5822 rtx to_rtx
= target
;
5824 /* Just ignore missing fields. We cleared the whole
5825 structure, above, if any fields are missing. */
5829 if (cleared
&& initializer_zerop (value
))
5832 if (host_integerp (DECL_SIZE (field
), 1))
5833 bitsize
= tree_low_cst (DECL_SIZE (field
), 1);
5837 mode
= DECL_MODE (field
);
5838 if (DECL_BIT_FIELD (field
))
5841 offset
= DECL_FIELD_OFFSET (field
);
5842 if (host_integerp (offset
, 0)
5843 && host_integerp (bit_position (field
), 0))
5845 bitpos
= int_bit_position (field
);
5849 bitpos
= tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 0);
5853 enum machine_mode address_mode
;
5857 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5858 make_tree (TREE_TYPE (exp
),
5861 offset_rtx
= expand_normal (offset
);
5862 gcc_assert (MEM_P (to_rtx
));
5864 address_mode
= get_address_mode (to_rtx
);
5865 if (GET_MODE (offset_rtx
) != address_mode
)
5866 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5868 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5869 highest_pow2_factor (offset
));
5872 #ifdef WORD_REGISTER_OPERATIONS
5873 /* If this initializes a field that is smaller than a
5874 word, at the start of a word, try to widen it to a full
5875 word. This special case allows us to output C++ member
5876 function initializations in a form that the optimizers
5879 && bitsize
< BITS_PER_WORD
5880 && bitpos
% BITS_PER_WORD
== 0
5881 && GET_MODE_CLASS (mode
) == MODE_INT
5882 && TREE_CODE (value
) == INTEGER_CST
5884 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
5886 tree type
= TREE_TYPE (value
);
5888 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
5890 type
= lang_hooks
.types
.type_for_mode
5891 (word_mode
, TYPE_UNSIGNED (type
));
5892 value
= fold_convert (type
, value
);
5895 if (BYTES_BIG_ENDIAN
)
5897 = fold_build2 (LSHIFT_EXPR
, type
, value
,
5898 build_int_cst (type
,
5899 BITS_PER_WORD
- bitsize
));
5900 bitsize
= BITS_PER_WORD
;
5905 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
5906 && DECL_NONADDRESSABLE_P (field
))
5908 to_rtx
= copy_rtx (to_rtx
);
5909 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
5912 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
5913 value
, type
, cleared
,
5914 get_alias_set (TREE_TYPE (field
)));
5921 unsigned HOST_WIDE_INT i
;
5924 tree elttype
= TREE_TYPE (type
);
5926 HOST_WIDE_INT minelt
= 0;
5927 HOST_WIDE_INT maxelt
= 0;
5929 domain
= TYPE_DOMAIN (type
);
5930 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
5931 && TYPE_MAX_VALUE (domain
)
5932 && host_integerp (TYPE_MIN_VALUE (domain
), 0)
5933 && host_integerp (TYPE_MAX_VALUE (domain
), 0));
5935 /* If we have constant bounds for the range of the type, get them. */
5938 minelt
= tree_low_cst (TYPE_MIN_VALUE (domain
), 0);
5939 maxelt
= tree_low_cst (TYPE_MAX_VALUE (domain
), 0);
5942 /* If the constructor has fewer elements than the array, clear
5943 the whole array first. Similarly if this is static
5944 constructor of a non-BLKmode object. */
5947 else if (REG_P (target
) && TREE_STATIC (exp
))
5951 unsigned HOST_WIDE_INT idx
;
5953 HOST_WIDE_INT count
= 0, zero_count
= 0;
5954 need_to_clear
= ! const_bounds_p
;
5956 /* This loop is a more accurate version of the loop in
5957 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5958 is also needed to check for missing elements. */
5959 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
5961 HOST_WIDE_INT this_node_count
;
5966 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
5968 tree lo_index
= TREE_OPERAND (index
, 0);
5969 tree hi_index
= TREE_OPERAND (index
, 1);
5971 if (! host_integerp (lo_index
, 1)
5972 || ! host_integerp (hi_index
, 1))
5978 this_node_count
= (tree_low_cst (hi_index
, 1)
5979 - tree_low_cst (lo_index
, 1) + 1);
5982 this_node_count
= 1;
5984 count
+= this_node_count
;
5985 if (mostly_zeros_p (value
))
5986 zero_count
+= this_node_count
;
5989 /* Clear the entire array first if there are any missing
5990 elements, or if the incidence of zero elements is >=
5993 && (count
< maxelt
- minelt
+ 1
5994 || 4 * zero_count
>= 3 * count
))
5998 if (need_to_clear
&& size
> 0)
6001 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6003 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6007 if (!cleared
&& REG_P (target
))
6008 /* Inform later passes that the old value is dead. */
6009 emit_clobber (target
);
6011 /* Store each element of the constructor into the
6012 corresponding element of TARGET, determined by counting the
6014 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6016 enum machine_mode mode
;
6017 HOST_WIDE_INT bitsize
;
6018 HOST_WIDE_INT bitpos
;
6019 rtx xtarget
= target
;
6021 if (cleared
&& initializer_zerop (value
))
6024 mode
= TYPE_MODE (elttype
);
6025 if (mode
== BLKmode
)
6026 bitsize
= (host_integerp (TYPE_SIZE (elttype
), 1)
6027 ? tree_low_cst (TYPE_SIZE (elttype
), 1)
6030 bitsize
= GET_MODE_BITSIZE (mode
);
6032 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6034 tree lo_index
= TREE_OPERAND (index
, 0);
6035 tree hi_index
= TREE_OPERAND (index
, 1);
6036 rtx index_r
, pos_rtx
;
6037 HOST_WIDE_INT lo
, hi
, count
;
6040 /* If the range is constant and "small", unroll the loop. */
6042 && host_integerp (lo_index
, 0)
6043 && host_integerp (hi_index
, 0)
6044 && (lo
= tree_low_cst (lo_index
, 0),
6045 hi
= tree_low_cst (hi_index
, 0),
6046 count
= hi
- lo
+ 1,
6049 || (host_integerp (TYPE_SIZE (elttype
), 1)
6050 && (tree_low_cst (TYPE_SIZE (elttype
), 1) * count
6053 lo
-= minelt
; hi
-= minelt
;
6054 for (; lo
<= hi
; lo
++)
6056 bitpos
= lo
* tree_low_cst (TYPE_SIZE (elttype
), 0);
6059 && !MEM_KEEP_ALIAS_SET_P (target
)
6060 && TREE_CODE (type
) == ARRAY_TYPE
6061 && TYPE_NONALIASED_COMPONENT (type
))
6063 target
= copy_rtx (target
);
6064 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6067 store_constructor_field
6068 (target
, bitsize
, bitpos
, mode
, value
, type
, cleared
,
6069 get_alias_set (elttype
));
6074 rtx loop_start
= gen_label_rtx ();
6075 rtx loop_end
= gen_label_rtx ();
6078 expand_normal (hi_index
);
6080 index
= build_decl (EXPR_LOCATION (exp
),
6081 VAR_DECL
, NULL_TREE
, domain
);
6082 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6083 SET_DECL_RTL (index
, index_r
);
6084 store_expr (lo_index
, index_r
, 0, false);
6086 /* Build the head of the loop. */
6087 do_pending_stack_adjust ();
6088 emit_label (loop_start
);
6090 /* Assign value to element index. */
6092 fold_convert (ssizetype
,
6093 fold_build2 (MINUS_EXPR
,
6096 TYPE_MIN_VALUE (domain
)));
6099 size_binop (MULT_EXPR
, position
,
6100 fold_convert (ssizetype
,
6101 TYPE_SIZE_UNIT (elttype
)));
6103 pos_rtx
= expand_normal (position
);
6104 xtarget
= offset_address (target
, pos_rtx
,
6105 highest_pow2_factor (position
));
6106 xtarget
= adjust_address (xtarget
, mode
, 0);
6107 if (TREE_CODE (value
) == CONSTRUCTOR
)
6108 store_constructor (value
, xtarget
, cleared
,
6109 bitsize
/ BITS_PER_UNIT
);
6111 store_expr (value
, xtarget
, 0, false);
6113 /* Generate a conditional jump to exit the loop. */
6114 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6116 jumpif (exit_cond
, loop_end
, -1);
6118 /* Update the loop counter, and jump to the head of
6120 expand_assignment (index
,
6121 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6122 index
, integer_one_node
),
6125 emit_jump (loop_start
);
6127 /* Build the end of the loop. */
6128 emit_label (loop_end
);
6131 else if ((index
!= 0 && ! host_integerp (index
, 0))
6132 || ! host_integerp (TYPE_SIZE (elttype
), 1))
6137 index
= ssize_int (1);
6140 index
= fold_convert (ssizetype
,
6141 fold_build2 (MINUS_EXPR
,
6144 TYPE_MIN_VALUE (domain
)));
6147 size_binop (MULT_EXPR
, index
,
6148 fold_convert (ssizetype
,
6149 TYPE_SIZE_UNIT (elttype
)));
6150 xtarget
= offset_address (target
,
6151 expand_normal (position
),
6152 highest_pow2_factor (position
));
6153 xtarget
= adjust_address (xtarget
, mode
, 0);
6154 store_expr (value
, xtarget
, 0, false);
6159 bitpos
= ((tree_low_cst (index
, 0) - minelt
)
6160 * tree_low_cst (TYPE_SIZE (elttype
), 1));
6162 bitpos
= (i
* tree_low_cst (TYPE_SIZE (elttype
), 1));
6164 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6165 && TREE_CODE (type
) == ARRAY_TYPE
6166 && TYPE_NONALIASED_COMPONENT (type
))
6168 target
= copy_rtx (target
);
6169 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6171 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6172 type
, cleared
, get_alias_set (elttype
));
6180 unsigned HOST_WIDE_INT idx
;
6181 constructor_elt
*ce
;
6184 int icode
= CODE_FOR_nothing
;
6185 tree elttype
= TREE_TYPE (type
);
6186 int elt_size
= tree_low_cst (TYPE_SIZE (elttype
), 1);
6187 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6188 HOST_WIDE_INT bitsize
;
6189 HOST_WIDE_INT bitpos
;
6190 rtvec vector
= NULL
;
6192 alias_set_type alias
;
6194 gcc_assert (eltmode
!= BLKmode
);
6196 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6197 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6199 enum machine_mode mode
= GET_MODE (target
);
6201 icode
= (int) optab_handler (vec_init_optab
, mode
);
6202 if (icode
!= CODE_FOR_nothing
)
6206 vector
= rtvec_alloc (n_elts
);
6207 for (i
= 0; i
< n_elts
; i
++)
6208 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6212 /* If the constructor has fewer elements than the vector,
6213 clear the whole array first. Similarly if this is static
6214 constructor of a non-BLKmode object. */
6217 else if (REG_P (target
) && TREE_STATIC (exp
))
6221 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6224 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6226 int n_elts_here
= tree_low_cst
6227 (int_const_binop (TRUNC_DIV_EXPR
,
6228 TYPE_SIZE (TREE_TYPE (value
)),
6229 TYPE_SIZE (elttype
)), 1);
6231 count
+= n_elts_here
;
6232 if (mostly_zeros_p (value
))
6233 zero_count
+= n_elts_here
;
6236 /* Clear the entire vector first if there are any missing elements,
6237 or if the incidence of zero elements is >= 75%. */
6238 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6241 if (need_to_clear
&& size
> 0 && !vector
)
6244 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6246 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6250 /* Inform later passes that the old value is dead. */
6251 if (!cleared
&& !vector
&& REG_P (target
))
6252 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6255 alias
= MEM_ALIAS_SET (target
);
6257 alias
= get_alias_set (elttype
);
6259 /* Store each element of the constructor into the corresponding
6260 element of TARGET, determined by counting the elements. */
6261 for (idx
= 0, i
= 0;
6262 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
);
6263 idx
++, i
+= bitsize
/ elt_size
)
6265 HOST_WIDE_INT eltpos
;
6266 tree value
= ce
->value
;
6268 bitsize
= tree_low_cst (TYPE_SIZE (TREE_TYPE (value
)), 1);
6269 if (cleared
&& initializer_zerop (value
))
6273 eltpos
= tree_low_cst (ce
->index
, 1);
6279 /* Vector CONSTRUCTORs should only be built from smaller
6280 vectors in the case of BLKmode vectors. */
6281 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6282 RTVEC_ELT (vector
, eltpos
)
6283 = expand_normal (value
);
6287 enum machine_mode value_mode
=
6288 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6289 ? TYPE_MODE (TREE_TYPE (value
))
6291 bitpos
= eltpos
* elt_size
;
6292 store_constructor_field (target
, bitsize
, bitpos
,
6293 value_mode
, value
, type
,
6299 emit_insn (GEN_FCN (icode
)
6301 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6310 /* Store the value of EXP (an expression tree)
6311 into a subfield of TARGET which has mode MODE and occupies
6312 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6313 If MODE is VOIDmode, it means that we are storing into a bit-field.
6315 BITREGION_START is bitpos of the first bitfield in this region.
6316 BITREGION_END is the bitpos of the ending bitfield in this region.
6317 These two fields are 0, if the C++ memory model does not apply,
6318 or we are not interested in keeping track of bitfield regions.
6320 Always return const0_rtx unless we have something particular to
6323 TYPE is the type of the underlying object,
6325 ALIAS_SET is the alias set for the destination. This value will
6326 (in general) be different from that for TARGET, since TARGET is a
6327 reference to the containing structure.
6329 If NONTEMPORAL is true, try generating a nontemporal store. */
6332 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6333 unsigned HOST_WIDE_INT bitregion_start
,
6334 unsigned HOST_WIDE_INT bitregion_end
,
6335 enum machine_mode mode
, tree exp
, tree type
,
6336 alias_set_type alias_set
, bool nontemporal
)
6338 if (TREE_CODE (exp
) == ERROR_MARK
)
6341 /* If we have nothing to store, do nothing unless the expression has
6344 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6346 /* If we are storing into an unaligned field of an aligned union that is
6347 in a register, we may have the mode of TARGET being an integer mode but
6348 MODE == BLKmode. In that case, get an aligned object whose size and
6349 alignment are the same as TARGET and store TARGET into it (we can avoid
6350 the store if the field being stored is the entire width of TARGET). Then
6351 call ourselves recursively to store the field into a BLKmode version of
6352 that object. Finally, load from the object into TARGET. This is not
6353 very efficient in general, but should only be slightly more expensive
6354 than the otherwise-required unaligned accesses. Perhaps this can be
6355 cleaned up later. It's tempting to make OBJECT readonly, but it's set
6356 twice, once with emit_move_insn and once via store_field. */
6359 && (REG_P (target
) || GET_CODE (target
) == SUBREG
)
6360 && TREE_CODE (exp
) != CALL_EXPR
)
6362 rtx object
= assign_temp (type
, 1, 1);
6363 rtx blk_object
= adjust_address (object
, BLKmode
, 0);
6365 if (bitsize
!= (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (target
)))
6366 emit_move_insn (object
, target
);
6368 store_field (blk_object
, bitsize
, bitpos
,
6369 bitregion_start
, bitregion_end
,
6370 mode
, exp
, type
, MEM_ALIAS_SET (blk_object
), nontemporal
);
6372 emit_move_insn (target
, object
);
6374 /* We want to return the BLKmode version of the data. */
6378 if (GET_CODE (target
) == CONCAT
)
6380 /* We're storing into a struct containing a single __complex. */
6382 gcc_assert (!bitpos
);
6383 return store_expr (exp
, target
, 0, nontemporal
);
6386 /* If the structure is in a register or if the component
6387 is a bit field, we cannot use addressing to access it.
6388 Use bit-field techniques or SUBREG to store in it. */
6390 if (mode
== VOIDmode
6391 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6392 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6393 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6395 || GET_CODE (target
) == SUBREG
6396 /* If the field isn't aligned enough to store as an ordinary memref,
6397 store it as a bit field. */
6399 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6400 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6401 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6402 || (bitpos
% BITS_PER_UNIT
!= 0)))
6403 || (bitsize
>= 0 && mode
!= BLKmode
6404 && GET_MODE_BITSIZE (mode
) > bitsize
)
6405 /* If the RHS and field are a constant size and the size of the
6406 RHS isn't the same size as the bitfield, we must use bitfield
6409 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6410 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6411 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6412 decl we must use bitfield operations. */
6414 && TREE_CODE (exp
) == MEM_REF
6415 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6416 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6417 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6418 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6423 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6424 implies a mask operation. If the precision is the same size as
6425 the field we're storing into, that mask is redundant. This is
6426 particularly common with bit field assignments generated by the
6428 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6431 tree type
= TREE_TYPE (exp
);
6432 if (INTEGRAL_TYPE_P (type
)
6433 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6434 && bitsize
== TYPE_PRECISION (type
))
6436 tree op
= gimple_assign_rhs1 (nop_def
);
6437 type
= TREE_TYPE (op
);
6438 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6443 temp
= expand_normal (exp
);
6445 /* If BITSIZE is narrower than the size of the type of EXP
6446 we will be narrowing TEMP. Normally, what's wanted are the
6447 low-order bits. However, if EXP's type is a record and this is
6448 big-endian machine, we want the upper BITSIZE bits. */
6449 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6450 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6451 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6452 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6453 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6456 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6457 if (mode
!= VOIDmode
&& mode
!= BLKmode
6458 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6459 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6461 /* If the modes of TEMP and TARGET are both BLKmode, both
6462 must be in memory and BITPOS must be aligned on a byte
6463 boundary. If so, we simply do a block copy. Likewise
6464 for a BLKmode-like TARGET. */
6465 if (GET_MODE (temp
) == BLKmode
6466 && (GET_MODE (target
) == BLKmode
6468 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6469 && (bitpos
% BITS_PER_UNIT
) == 0
6470 && (bitsize
% BITS_PER_UNIT
) == 0)))
6472 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6473 && (bitpos
% BITS_PER_UNIT
) == 0);
6475 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6476 emit_block_move (target
, temp
,
6477 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6484 /* Handle calls that return values in multiple non-contiguous locations.
6485 The Irix 6 ABI has examples of this. */
6486 if (GET_CODE (temp
) == PARALLEL
)
6490 /* We are not supposed to have a true bitfield in this case. */
6491 gcc_assert (bitsize
== GET_MODE_BITSIZE (mode
));
6493 /* If we don't store at bit 0, we need an intermediate pseudo
6494 since emit_group_store only stores at bit 0. */
6496 temp_target
= gen_reg_rtx (mode
);
6498 temp_target
= target
;
6500 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
),
6501 int_size_in_bytes (TREE_TYPE (exp
)));
6503 if (temp_target
== target
)
6509 /* Handle calls that return BLKmode values in registers. */
6510 else if (mode
== BLKmode
6512 && TREE_CODE (exp
) == CALL_EXPR
)
6514 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6515 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6519 /* Store the value in the bitfield. */
6520 store_bit_field (target
, bitsize
, bitpos
,
6521 bitregion_start
, bitregion_end
,
6528 /* Now build a reference to just the desired component. */
6529 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6531 if (to_rtx
== target
)
6532 to_rtx
= copy_rtx (to_rtx
);
6534 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6535 set_mem_alias_set (to_rtx
, alias_set
);
6537 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6541 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6542 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6543 codes and find the ultimate containing object, which we return.
6545 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6546 bit position, and *PUNSIGNEDP to the signedness of the field.
6547 If the position of the field is variable, we store a tree
6548 giving the variable offset (in units) in *POFFSET.
6549 This offset is in addition to the bit position.
6550 If the position is not variable, we store 0 in *POFFSET.
6552 If any of the extraction expressions is volatile,
6553 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6555 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6556 Otherwise, it is a mode that can be used to access the field.
6558 If the field describes a variable-sized object, *PMODE is set to
6559 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6560 this case, but the address of the object can be found.
6562 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6563 look through nodes that serve as markers of a greater alignment than
6564 the one that can be deduced from the expression. These nodes make it
6565 possible for front-ends to prevent temporaries from being created by
6566 the middle-end on alignment considerations. For that purpose, the
6567 normal operating mode at high-level is to always pass FALSE so that
6568 the ultimate containing object is really returned; moreover, the
6569 associated predicate handled_component_p will always return TRUE
6570 on these nodes, thus indicating that they are essentially handled
6571 by get_inner_reference. TRUE should only be passed when the caller
6572 is scanning the expression in order to build another representation
6573 and specifically knows how to handle these nodes; as such, this is
6574 the normal operating mode in the RTL expanders. */
6577 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6578 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6579 enum machine_mode
*pmode
, int *punsignedp
,
6580 int *pvolatilep
, bool keep_aligning
)
6583 enum machine_mode mode
= VOIDmode
;
6584 bool blkmode_bitfield
= false;
6585 tree offset
= size_zero_node
;
6586 double_int bit_offset
= double_int_zero
;
6588 /* First get the mode, signedness, and size. We do this from just the
6589 outermost expression. */
6591 if (TREE_CODE (exp
) == COMPONENT_REF
)
6593 tree field
= TREE_OPERAND (exp
, 1);
6594 size_tree
= DECL_SIZE (field
);
6595 if (!DECL_BIT_FIELD (field
))
6596 mode
= DECL_MODE (field
);
6597 else if (DECL_MODE (field
) == BLKmode
)
6598 blkmode_bitfield
= true;
6599 else if (TREE_THIS_VOLATILE (exp
)
6600 && flag_strict_volatile_bitfields
> 0)
6601 /* Volatile bitfields should be accessed in the mode of the
6602 field's type, not the mode computed based on the bit
6604 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6606 *punsignedp
= DECL_UNSIGNED (field
);
6608 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6610 size_tree
= TREE_OPERAND (exp
, 1);
6611 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6612 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6614 /* For vector types, with the correct size of access, use the mode of
6616 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6617 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6618 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6619 mode
= TYPE_MODE (TREE_TYPE (exp
));
6623 mode
= TYPE_MODE (TREE_TYPE (exp
));
6624 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6626 if (mode
== BLKmode
)
6627 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6629 *pbitsize
= GET_MODE_BITSIZE (mode
);
6634 if (! host_integerp (size_tree
, 1))
6635 mode
= BLKmode
, *pbitsize
= -1;
6637 *pbitsize
= tree_low_cst (size_tree
, 1);
6640 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6641 and find the ultimate containing object. */
6644 switch (TREE_CODE (exp
))
6647 bit_offset
+= tree_to_double_int (TREE_OPERAND (exp
, 2));
6652 tree field
= TREE_OPERAND (exp
, 1);
6653 tree this_offset
= component_ref_field_offset (exp
);
6655 /* If this field hasn't been filled in yet, don't go past it.
6656 This should only happen when folding expressions made during
6657 type construction. */
6658 if (this_offset
== 0)
6661 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6662 bit_offset
+= tree_to_double_int (DECL_FIELD_BIT_OFFSET (field
));
6664 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6669 case ARRAY_RANGE_REF
:
6671 tree index
= TREE_OPERAND (exp
, 1);
6672 tree low_bound
= array_ref_low_bound (exp
);
6673 tree unit_size
= array_ref_element_size (exp
);
6675 /* We assume all arrays have sizes that are a multiple of a byte.
6676 First subtract the lower bound, if any, in the type of the
6677 index, then convert to sizetype and multiply by the size of
6678 the array element. */
6679 if (! integer_zerop (low_bound
))
6680 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6683 offset
= size_binop (PLUS_EXPR
, offset
,
6684 size_binop (MULT_EXPR
,
6685 fold_convert (sizetype
, index
),
6694 bit_offset
+= double_int::from_uhwi (*pbitsize
);
6697 case VIEW_CONVERT_EXPR
:
6698 if (keep_aligning
&& STRICT_ALIGNMENT
6699 && (TYPE_ALIGN (TREE_TYPE (exp
))
6700 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6701 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6702 < BIGGEST_ALIGNMENT
)
6703 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6704 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6709 /* Hand back the decl for MEM[&decl, off]. */
6710 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6712 tree off
= TREE_OPERAND (exp
, 1);
6713 if (!integer_zerop (off
))
6715 double_int boff
, coff
= mem_ref_offset (exp
);
6716 boff
= coff
.alshift (BITS_PER_UNIT
== 8
6717 ? 3 : exact_log2 (BITS_PER_UNIT
),
6718 HOST_BITS_PER_DOUBLE_INT
);
6721 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6729 /* If any reference in the chain is volatile, the effect is volatile. */
6730 if (TREE_THIS_VOLATILE (exp
))
6733 exp
= TREE_OPERAND (exp
, 0);
6737 /* If OFFSET is constant, see if we can return the whole thing as a
6738 constant bit position. Make sure to handle overflow during
6740 if (TREE_CODE (offset
) == INTEGER_CST
)
6742 double_int tem
= tree_to_double_int (offset
);
6743 tem
= tem
.sext (TYPE_PRECISION (sizetype
));
6744 tem
= tem
.alshift (BITS_PER_UNIT
== 8 ? 3 : exact_log2 (BITS_PER_UNIT
),
6745 HOST_BITS_PER_DOUBLE_INT
);
6747 if (tem
.fits_shwi ())
6749 *pbitpos
= tem
.to_shwi ();
6750 *poffset
= offset
= NULL_TREE
;
6754 /* Otherwise, split it up. */
6757 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6758 if (bit_offset
.is_negative ())
6761 = double_int::mask (BITS_PER_UNIT
== 8
6762 ? 3 : exact_log2 (BITS_PER_UNIT
));
6763 double_int tem
= bit_offset
.and_not (mask
);
6764 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6765 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6767 tem
= tem
.arshift (BITS_PER_UNIT
== 8
6768 ? 3 : exact_log2 (BITS_PER_UNIT
),
6769 HOST_BITS_PER_DOUBLE_INT
);
6770 offset
= size_binop (PLUS_EXPR
, offset
,
6771 double_int_to_tree (sizetype
, tem
));
6774 *pbitpos
= bit_offset
.to_shwi ();
6778 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6779 if (mode
== VOIDmode
6781 && (*pbitpos
% BITS_PER_UNIT
) == 0
6782 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6790 /* Return a tree of sizetype representing the size, in bytes, of the element
6791 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6794 array_ref_element_size (tree exp
)
6796 tree aligned_size
= TREE_OPERAND (exp
, 3);
6797 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6798 location_t loc
= EXPR_LOCATION (exp
);
6800 /* If a size was specified in the ARRAY_REF, it's the size measured
6801 in alignment units of the element type. So multiply by that value. */
6804 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6805 sizetype from another type of the same width and signedness. */
6806 if (TREE_TYPE (aligned_size
) != sizetype
)
6807 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6808 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6809 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6812 /* Otherwise, take the size from that of the element type. Substitute
6813 any PLACEHOLDER_EXPR that we have. */
6815 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6818 /* Return a tree representing the lower bound of the array mentioned in
6819 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6822 array_ref_low_bound (tree exp
)
6824 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6826 /* If a lower bound is specified in EXP, use it. */
6827 if (TREE_OPERAND (exp
, 2))
6828 return TREE_OPERAND (exp
, 2);
6830 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6831 substituting for a PLACEHOLDER_EXPR as needed. */
6832 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6833 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6835 /* Otherwise, return a zero of the appropriate type. */
6836 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6839 /* Returns true if REF is an array reference to an array at the end of
6840 a structure. If this is the case, the array may be allocated larger
6841 than its upper bound implies. */
6844 array_at_struct_end_p (tree ref
)
6846 if (TREE_CODE (ref
) != ARRAY_REF
6847 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6850 while (handled_component_p (ref
))
6852 /* If the reference chain contains a component reference to a
6853 non-union type and there follows another field the reference
6854 is not at the end of a structure. */
6855 if (TREE_CODE (ref
) == COMPONENT_REF
6856 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6858 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6859 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6860 nextf
= DECL_CHAIN (nextf
);
6865 ref
= TREE_OPERAND (ref
, 0);
6868 /* If the reference is based on a declared entity, the size of the array
6869 is constrained by its given domain. */
6876 /* Return a tree representing the upper bound of the array mentioned in
6877 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6880 array_ref_up_bound (tree exp
)
6882 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6884 /* If there is a domain type and it has an upper bound, use it, substituting
6885 for a PLACEHOLDER_EXPR as needed. */
6886 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6887 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6889 /* Otherwise fail. */
6893 /* Return a tree representing the offset, in bytes, of the field referenced
6894 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6897 component_ref_field_offset (tree exp
)
6899 tree aligned_offset
= TREE_OPERAND (exp
, 2);
6900 tree field
= TREE_OPERAND (exp
, 1);
6901 location_t loc
= EXPR_LOCATION (exp
);
6903 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6904 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6908 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6909 sizetype from another type of the same width and signedness. */
6910 if (TREE_TYPE (aligned_offset
) != sizetype
)
6911 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
6912 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
6913 size_int (DECL_OFFSET_ALIGN (field
)
6917 /* Otherwise, take the offset from that of the field. Substitute
6918 any PLACEHOLDER_EXPR that we have. */
6920 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
6923 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6925 static unsigned HOST_WIDE_INT
6926 target_align (const_tree target
)
6928 /* We might have a chain of nested references with intermediate misaligning
6929 bitfields components, so need to recurse to find out. */
6931 unsigned HOST_WIDE_INT this_align
, outer_align
;
6933 switch (TREE_CODE (target
))
6939 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
6940 outer_align
= target_align (TREE_OPERAND (target
, 0));
6941 return MIN (this_align
, outer_align
);
6944 case ARRAY_RANGE_REF
:
6945 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6946 outer_align
= target_align (TREE_OPERAND (target
, 0));
6947 return MIN (this_align
, outer_align
);
6950 case NON_LVALUE_EXPR
:
6951 case VIEW_CONVERT_EXPR
:
6952 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6953 outer_align
= target_align (TREE_OPERAND (target
, 0));
6954 return MAX (this_align
, outer_align
);
6957 return TYPE_ALIGN (TREE_TYPE (target
));
6962 /* Given an rtx VALUE that may contain additions and multiplications, return
6963 an equivalent value that just refers to a register, memory, or constant.
6964 This is done by generating instructions to perform the arithmetic and
6965 returning a pseudo-register containing the value.
6967 The returned value may be a REG, SUBREG, MEM or constant. */
6970 force_operand (rtx value
, rtx target
)
6973 /* Use subtarget as the target for operand 0 of a binary operation. */
6974 rtx subtarget
= get_subtarget (target
);
6975 enum rtx_code code
= GET_CODE (value
);
6977 /* Check for subreg applied to an expression produced by loop optimizer. */
6979 && !REG_P (SUBREG_REG (value
))
6980 && !MEM_P (SUBREG_REG (value
)))
6983 = simplify_gen_subreg (GET_MODE (value
),
6984 force_reg (GET_MODE (SUBREG_REG (value
)),
6985 force_operand (SUBREG_REG (value
),
6987 GET_MODE (SUBREG_REG (value
)),
6988 SUBREG_BYTE (value
));
6989 code
= GET_CODE (value
);
6992 /* Check for a PIC address load. */
6993 if ((code
== PLUS
|| code
== MINUS
)
6994 && XEXP (value
, 0) == pic_offset_table_rtx
6995 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
6996 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
6997 || GET_CODE (XEXP (value
, 1)) == CONST
))
7000 subtarget
= gen_reg_rtx (GET_MODE (value
));
7001 emit_move_insn (subtarget
, value
);
7005 if (ARITHMETIC_P (value
))
7007 op2
= XEXP (value
, 1);
7008 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7010 if (code
== MINUS
&& CONST_INT_P (op2
))
7013 op2
= negate_rtx (GET_MODE (value
), op2
);
7016 /* Check for an addition with OP2 a constant integer and our first
7017 operand a PLUS of a virtual register and something else. In that
7018 case, we want to emit the sum of the virtual register and the
7019 constant first and then add the other value. This allows virtual
7020 register instantiation to simply modify the constant rather than
7021 creating another one around this addition. */
7022 if (code
== PLUS
&& CONST_INT_P (op2
)
7023 && GET_CODE (XEXP (value
, 0)) == PLUS
7024 && REG_P (XEXP (XEXP (value
, 0), 0))
7025 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7026 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7028 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7029 XEXP (XEXP (value
, 0), 0), op2
,
7030 subtarget
, 0, OPTAB_LIB_WIDEN
);
7031 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7032 force_operand (XEXP (XEXP (value
,
7034 target
, 0, OPTAB_LIB_WIDEN
);
7037 op1
= force_operand (XEXP (value
, 0), subtarget
);
7038 op2
= force_operand (op2
, NULL_RTX
);
7042 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7044 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7045 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7046 target
, 1, OPTAB_LIB_WIDEN
);
7048 return expand_divmod (0,
7049 FLOAT_MODE_P (GET_MODE (value
))
7050 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7051 GET_MODE (value
), op1
, op2
, target
, 0);
7053 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7056 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7059 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7062 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7063 target
, 0, OPTAB_LIB_WIDEN
);
7065 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7066 target
, 1, OPTAB_LIB_WIDEN
);
7069 if (UNARY_P (value
))
7072 target
= gen_reg_rtx (GET_MODE (value
));
7073 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7080 case FLOAT_TRUNCATE
:
7081 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7086 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7090 case UNSIGNED_FLOAT
:
7091 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7095 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7099 #ifdef INSN_SCHEDULING
7100 /* On machines that have insn scheduling, we want all memory reference to be
7101 explicit, so we need to deal with such paradoxical SUBREGs. */
7102 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7104 = simplify_gen_subreg (GET_MODE (value
),
7105 force_reg (GET_MODE (SUBREG_REG (value
)),
7106 force_operand (SUBREG_REG (value
),
7108 GET_MODE (SUBREG_REG (value
)),
7109 SUBREG_BYTE (value
));
7115 /* Subroutine of expand_expr: return nonzero iff there is no way that
7116 EXP can reference X, which is being modified. TOP_P is nonzero if this
7117 call is going to be used to determine whether we need a temporary
7118 for EXP, as opposed to a recursive call to this function.
7120 It is always safe for this routine to return zero since it merely
7121 searches for optimization opportunities. */
7124 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7130 /* If EXP has varying size, we MUST use a target since we currently
7131 have no way of allocating temporaries of variable size
7132 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7133 So we assume here that something at a higher level has prevented a
7134 clash. This is somewhat bogus, but the best we can do. Only
7135 do this when X is BLKmode and when we are at the top level. */
7136 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7137 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7138 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7139 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7140 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7142 && GET_MODE (x
) == BLKmode
)
7143 /* If X is in the outgoing argument area, it is always safe. */
7145 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7146 || (GET_CODE (XEXP (x
, 0)) == PLUS
7147 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7150 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7151 find the underlying pseudo. */
7152 if (GET_CODE (x
) == SUBREG
)
7155 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7159 /* Now look at our tree code and possibly recurse. */
7160 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7162 case tcc_declaration
:
7163 exp_rtl
= DECL_RTL_IF_SET (exp
);
7169 case tcc_exceptional
:
7170 if (TREE_CODE (exp
) == TREE_LIST
)
7174 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7176 exp
= TREE_CHAIN (exp
);
7179 if (TREE_CODE (exp
) != TREE_LIST
)
7180 return safe_from_p (x
, exp
, 0);
7183 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7185 constructor_elt
*ce
;
7186 unsigned HOST_WIDE_INT idx
;
7188 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7189 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7190 || !safe_from_p (x
, ce
->value
, 0))
7194 else if (TREE_CODE (exp
) == ERROR_MARK
)
7195 return 1; /* An already-visited SAVE_EXPR? */
7200 /* The only case we look at here is the DECL_INITIAL inside a
7202 return (TREE_CODE (exp
) != DECL_EXPR
7203 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7204 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7205 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7208 case tcc_comparison
:
7209 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7214 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7216 case tcc_expression
:
7219 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7220 the expression. If it is set, we conflict iff we are that rtx or
7221 both are in memory. Otherwise, we check all operands of the
7222 expression recursively. */
7224 switch (TREE_CODE (exp
))
7227 /* If the operand is static or we are static, we can't conflict.
7228 Likewise if we don't conflict with the operand at all. */
7229 if (staticp (TREE_OPERAND (exp
, 0))
7230 || TREE_STATIC (exp
)
7231 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7234 /* Otherwise, the only way this can conflict is if we are taking
7235 the address of a DECL a that address if part of X, which is
7237 exp
= TREE_OPERAND (exp
, 0);
7240 if (!DECL_RTL_SET_P (exp
)
7241 || !MEM_P (DECL_RTL (exp
)))
7244 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7250 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7251 get_alias_set (exp
)))
7256 /* Assume that the call will clobber all hard registers and
7258 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7263 case WITH_CLEANUP_EXPR
:
7264 case CLEANUP_POINT_EXPR
:
7265 /* Lowered by gimplify.c. */
7269 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7275 /* If we have an rtx, we do not need to scan our operands. */
7279 nops
= TREE_OPERAND_LENGTH (exp
);
7280 for (i
= 0; i
< nops
; i
++)
7281 if (TREE_OPERAND (exp
, i
) != 0
7282 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7288 /* Should never get a type here. */
7292 /* If we have an rtl, find any enclosed object. Then see if we conflict
7296 if (GET_CODE (exp_rtl
) == SUBREG
)
7298 exp_rtl
= SUBREG_REG (exp_rtl
);
7300 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7304 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7305 are memory and they conflict. */
7306 return ! (rtx_equal_p (x
, exp_rtl
)
7307 || (MEM_P (x
) && MEM_P (exp_rtl
)
7308 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7311 /* If we reach here, it is safe. */
7316 /* Return the highest power of two that EXP is known to be a multiple of.
7317 This is used in updating alignment of MEMs in array references. */
7319 unsigned HOST_WIDE_INT
7320 highest_pow2_factor (const_tree exp
)
7322 unsigned HOST_WIDE_INT c0
, c1
;
7324 switch (TREE_CODE (exp
))
7327 /* We can find the lowest bit that's a one. If the low
7328 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
7329 We need to handle this case since we can find it in a COND_EXPR,
7330 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
7331 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
7333 if (TREE_OVERFLOW (exp
))
7334 return BIGGEST_ALIGNMENT
;
7337 /* Note: tree_low_cst is intentionally not used here,
7338 we don't care about the upper bits. */
7339 c0
= TREE_INT_CST_LOW (exp
);
7341 return c0
? c0
: BIGGEST_ALIGNMENT
;
7345 case PLUS_EXPR
: case MINUS_EXPR
: case MIN_EXPR
: case MAX_EXPR
:
7346 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7347 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7348 return MIN (c0
, c1
);
7351 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7352 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7355 case ROUND_DIV_EXPR
: case TRUNC_DIV_EXPR
: case FLOOR_DIV_EXPR
:
7357 if (integer_pow2p (TREE_OPERAND (exp
, 1))
7358 && host_integerp (TREE_OPERAND (exp
, 1), 1))
7360 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7361 c1
= tree_low_cst (TREE_OPERAND (exp
, 1), 1);
7362 return MAX (1, c0
/ c1
);
7367 /* The highest power of two of a bit-and expression is the maximum of
7368 that of its operands. We typically get here for a complex LHS and
7369 a constant negative power of two on the RHS to force an explicit
7370 alignment, so don't bother looking at the LHS. */
7371 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7375 return highest_pow2_factor (TREE_OPERAND (exp
, 0));
7378 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7381 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7382 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 2));
7383 return MIN (c0
, c1
);
7392 /* Similar, except that the alignment requirements of TARGET are
7393 taken into account. Assume it is at least as aligned as its
7394 type, unless it is a COMPONENT_REF in which case the layout of
7395 the structure gives the alignment. */
7397 static unsigned HOST_WIDE_INT
7398 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7400 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7401 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7403 return MAX (factor
, talign
);
7406 #ifdef HAVE_conditional_move
7407 /* Convert the tree comparison code TCODE to the rtl one where the
7408 signedness is UNSIGNEDP. */
7410 static enum rtx_code
7411 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7423 code
= unsignedp
? LTU
: LT
;
7426 code
= unsignedp
? LEU
: LE
;
7429 code
= unsignedp
? GTU
: GT
;
7432 code
= unsignedp
? GEU
: GE
;
7434 case UNORDERED_EXPR
:
7466 /* Subroutine of expand_expr. Expand the two operands of a binary
7467 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7468 The value may be stored in TARGET if TARGET is nonzero. The
7469 MODIFIER argument is as documented by expand_expr. */
7472 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7473 enum expand_modifier modifier
)
7475 if (! safe_from_p (target
, exp1
, 1))
7477 if (operand_equal_p (exp0
, exp1
, 0))
7479 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7480 *op1
= copy_rtx (*op0
);
7484 /* If we need to preserve evaluation order, copy exp0 into its own
7485 temporary variable so that it can't be clobbered by exp1. */
7486 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7487 exp0
= save_expr (exp0
);
7488 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7489 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7494 /* Return a MEM that contains constant EXP. DEFER is as for
7495 output_constant_def and MODIFIER is as for expand_expr. */
7498 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7502 mem
= output_constant_def (exp
, defer
);
7503 if (modifier
!= EXPAND_INITIALIZER
)
7504 mem
= use_anchored_address (mem
);
7508 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7509 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7512 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7513 enum expand_modifier modifier
, addr_space_t as
)
7515 rtx result
, subtarget
;
7517 HOST_WIDE_INT bitsize
, bitpos
;
7518 int volatilep
, unsignedp
;
7519 enum machine_mode mode1
;
7521 /* If we are taking the address of a constant and are at the top level,
7522 we have to use output_constant_def since we can't call force_const_mem
7524 /* ??? This should be considered a front-end bug. We should not be
7525 generating ADDR_EXPR of something that isn't an LVALUE. The only
7526 exception here is STRING_CST. */
7527 if (CONSTANT_CLASS_P (exp
))
7529 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7530 if (modifier
< EXPAND_SUM
)
7531 result
= force_operand (result
, target
);
7535 /* Everything must be something allowed by is_gimple_addressable. */
7536 switch (TREE_CODE (exp
))
7539 /* This case will happen via recursion for &a->b. */
7540 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7544 tree tem
= TREE_OPERAND (exp
, 0);
7545 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7546 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7547 return expand_expr (tem
, target
, tmode
, modifier
);
7551 /* Expand the initializer like constants above. */
7552 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7554 if (modifier
< EXPAND_SUM
)
7555 result
= force_operand (result
, target
);
7559 /* The real part of the complex number is always first, therefore
7560 the address is the same as the address of the parent object. */
7563 inner
= TREE_OPERAND (exp
, 0);
7567 /* The imaginary part of the complex number is always second.
7568 The expression is therefore always offset by the size of the
7571 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7572 inner
= TREE_OPERAND (exp
, 0);
7576 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7577 expand_expr, as that can have various side effects; LABEL_DECLs for
7578 example, may not have their DECL_RTL set yet. Expand the rtl of
7579 CONSTRUCTORs too, which should yield a memory reference for the
7580 constructor's contents. Assume language specific tree nodes can
7581 be expanded in some interesting way. */
7582 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7584 || TREE_CODE (exp
) == CONSTRUCTOR
7585 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7587 result
= expand_expr (exp
, target
, tmode
,
7588 modifier
== EXPAND_INITIALIZER
7589 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7591 /* If the DECL isn't in memory, then the DECL wasn't properly
7592 marked TREE_ADDRESSABLE, which will be either a front-end
7593 or a tree optimizer bug. */
7595 if (TREE_ADDRESSABLE (exp
)
7597 && ! targetm
.calls
.allocate_stack_slots_for_args())
7599 error ("local frame unavailable (naked function?)");
7603 gcc_assert (MEM_P (result
));
7604 result
= XEXP (result
, 0);
7606 /* ??? Is this needed anymore? */
7608 TREE_USED (exp
) = 1;
7610 if (modifier
!= EXPAND_INITIALIZER
7611 && modifier
!= EXPAND_CONST_ADDRESS
7612 && modifier
!= EXPAND_SUM
)
7613 result
= force_operand (result
, target
);
7617 /* Pass FALSE as the last argument to get_inner_reference although
7618 we are expanding to RTL. The rationale is that we know how to
7619 handle "aligning nodes" here: we can just bypass them because
7620 they won't change the final object whose address will be returned
7621 (they actually exist only for that purpose). */
7622 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7623 &mode1
, &unsignedp
, &volatilep
, false);
7627 /* We must have made progress. */
7628 gcc_assert (inner
!= exp
);
7630 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7631 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7632 inner alignment, force the inner to be sufficiently aligned. */
7633 if (CONSTANT_CLASS_P (inner
)
7634 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7636 inner
= copy_node (inner
);
7637 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7638 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7639 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7641 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7647 if (modifier
!= EXPAND_NORMAL
)
7648 result
= force_operand (result
, NULL
);
7649 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7650 modifier
== EXPAND_INITIALIZER
7651 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7653 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7654 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7656 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7657 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7660 subtarget
= bitpos
? NULL_RTX
: target
;
7661 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7662 1, OPTAB_LIB_WIDEN
);
7668 /* Someone beforehand should have rejected taking the address
7669 of such an object. */
7670 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7672 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7673 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7674 if (modifier
< EXPAND_SUM
)
7675 result
= force_operand (result
, target
);
7681 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7682 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7685 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7686 enum expand_modifier modifier
)
7688 addr_space_t as
= ADDR_SPACE_GENERIC
;
7689 enum machine_mode address_mode
= Pmode
;
7690 enum machine_mode pointer_mode
= ptr_mode
;
7691 enum machine_mode rmode
;
7694 /* Target mode of VOIDmode says "whatever's natural". */
7695 if (tmode
== VOIDmode
)
7696 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7698 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7700 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7701 address_mode
= targetm
.addr_space
.address_mode (as
);
7702 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7705 /* We can get called with some Weird Things if the user does silliness
7706 like "(short) &a". In that case, convert_memory_address won't do
7707 the right thing, so ignore the given target mode. */
7708 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7709 tmode
= address_mode
;
7711 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7712 tmode
, modifier
, as
);
7714 /* Despite expand_expr claims concerning ignoring TMODE when not
7715 strictly convenient, stuff breaks if we don't honor it. Note
7716 that combined with the above, we only do this for pointer modes. */
7717 rmode
= GET_MODE (result
);
7718 if (rmode
== VOIDmode
)
7721 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7726 /* Generate code for computing CONSTRUCTOR EXP.
7727 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7728 is TRUE, instead of creating a temporary variable in memory
7729 NULL is returned and the caller needs to handle it differently. */
7732 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7733 bool avoid_temp_mem
)
7735 tree type
= TREE_TYPE (exp
);
7736 enum machine_mode mode
= TYPE_MODE (type
);
7738 /* Try to avoid creating a temporary at all. This is possible
7739 if all of the initializer is zero.
7740 FIXME: try to handle all [0..255] initializers we can handle
7742 if (TREE_STATIC (exp
)
7743 && !TREE_ADDRESSABLE (exp
)
7744 && target
!= 0 && mode
== BLKmode
7745 && all_zeros_p (exp
))
7747 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7751 /* All elts simple constants => refer to a constant in memory. But
7752 if this is a non-BLKmode mode, let it store a field at a time
7753 since that should make a CONST_INT or CONST_DOUBLE when we
7754 fold. Likewise, if we have a target we can use, it is best to
7755 store directly into the target unless the type is large enough
7756 that memcpy will be used. If we are making an initializer and
7757 all operands are constant, put it in memory as well.
7759 FIXME: Avoid trying to fill vector constructors piece-meal.
7760 Output them with output_constant_def below unless we're sure
7761 they're zeros. This should go away when vector initializers
7762 are treated like VECTOR_CST instead of arrays. */
7763 if ((TREE_STATIC (exp
)
7764 && ((mode
== BLKmode
7765 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7766 || TREE_ADDRESSABLE (exp
)
7767 || (host_integerp (TYPE_SIZE_UNIT (type
), 1)
7768 && (! MOVE_BY_PIECES_P
7769 (tree_low_cst (TYPE_SIZE_UNIT (type
), 1),
7771 && ! mostly_zeros_p (exp
))))
7772 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7773 && TREE_CONSTANT (exp
)))
7780 constructor
= expand_expr_constant (exp
, 1, modifier
);
7782 if (modifier
!= EXPAND_CONST_ADDRESS
7783 && modifier
!= EXPAND_INITIALIZER
7784 && modifier
!= EXPAND_SUM
)
7785 constructor
= validize_mem (constructor
);
7790 /* Handle calls that pass values in multiple non-contiguous
7791 locations. The Irix 6 ABI has examples of this. */
7792 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7793 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7799 = assign_temp (build_qualified_type (type
, (TYPE_QUALS (type
)
7800 | (TREE_READONLY (exp
)
7801 * TYPE_QUAL_CONST
))),
7802 TREE_ADDRESSABLE (exp
), 1);
7805 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7810 /* expand_expr: generate code for computing expression EXP.
7811 An rtx for the computed value is returned. The value is never null.
7812 In the case of a void EXP, const0_rtx is returned.
7814 The value may be stored in TARGET if TARGET is nonzero.
7815 TARGET is just a suggestion; callers must assume that
7816 the rtx returned may not be the same as TARGET.
7818 If TARGET is CONST0_RTX, it means that the value will be ignored.
7820 If TMODE is not VOIDmode, it suggests generating the
7821 result in mode TMODE. But this is done only when convenient.
7822 Otherwise, TMODE is ignored and the value generated in its natural mode.
7823 TMODE is just a suggestion; callers must assume that
7824 the rtx returned may not have mode TMODE.
7826 Note that TARGET may have neither TMODE nor MODE. In that case, it
7827 probably will not be used.
7829 If MODIFIER is EXPAND_SUM then when EXP is an addition
7830 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7831 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7832 products as above, or REG or MEM, or constant.
7833 Ordinarily in such cases we would output mul or add instructions
7834 and then return a pseudo reg containing the sum.
7836 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7837 it also marks a label as absolutely required (it can't be dead).
7838 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7839 This is used for outputting expressions used in initializers.
7841 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7842 with a constant address even if that address is not normally legitimate.
7843 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7845 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7846 a call parameter. Such targets require special care as we haven't yet
7847 marked TARGET so that it's safe from being trashed by libcalls. We
7848 don't want to use TARGET for anything but the final result;
7849 Intermediate values must go elsewhere. Additionally, calls to
7850 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7852 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7853 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7854 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7855 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7859 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7860 enum expand_modifier modifier
, rtx
*alt_rtl
)
7864 /* Handle ERROR_MARK before anybody tries to access its type. */
7865 if (TREE_CODE (exp
) == ERROR_MARK
7866 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7868 ret
= CONST0_RTX (tmode
);
7869 return ret
? ret
: const0_rtx
;
7872 /* If this is an expression of some kind and it has an associated line
7873 number, then emit the line number before expanding the expression.
7875 We need to save and restore the file and line information so that
7876 errors discovered during expansion are emitted with the right
7877 information. It would be better of the diagnostic routines
7878 used the file/line information embedded in the tree nodes rather
7880 if (cfun
&& EXPR_HAS_LOCATION (exp
))
7882 location_t saved_location
= input_location
;
7883 location_t saved_curr_loc
= curr_insn_location ();
7884 input_location
= EXPR_LOCATION (exp
);
7885 set_curr_insn_location (input_location
);
7887 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7889 input_location
= saved_location
;
7890 set_curr_insn_location (saved_curr_loc
);
7894 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7900 /* Try to expand the conditional expression which is represented by
7901 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7902 return the rtl reg which repsents the result. Otherwise return
7906 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7907 tree treeop1 ATTRIBUTE_UNUSED
,
7908 tree treeop2 ATTRIBUTE_UNUSED
)
7910 #ifdef HAVE_conditional_move
7912 rtx op00
, op01
, op1
, op2
;
7913 enum rtx_code comparison_code
;
7914 enum machine_mode comparison_mode
;
7917 tree type
= TREE_TYPE (treeop1
);
7918 int unsignedp
= TYPE_UNSIGNED (type
);
7919 enum machine_mode mode
= TYPE_MODE (type
);
7921 temp
= assign_temp (type
, 0, 1);
7923 /* If we cannot do a conditional move on the mode, try doing it
7924 with the promoted mode. */
7925 if (!can_conditionally_move_p (mode
))
7926 mode
= promote_mode (type
, mode
, &unsignedp
);
7928 if (!can_conditionally_move_p (mode
))
7932 expand_operands (treeop1
, treeop2
,
7933 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7935 if (TREE_CODE (treeop0
) == SSA_NAME
7936 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7938 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7939 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7940 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7941 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7942 comparison_mode
= TYPE_MODE (type
);
7943 unsignedp
= TYPE_UNSIGNED (type
);
7944 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7946 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7948 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7949 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7950 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7951 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7952 unsignedp
= TYPE_UNSIGNED (type
);
7953 comparison_mode
= TYPE_MODE (type
);
7954 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7958 op00
= expand_normal (treeop0
);
7960 comparison_code
= NE
;
7961 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7964 if (GET_MODE (op1
) != mode
)
7965 op1
= gen_lowpart (mode
, op1
);
7967 if (GET_MODE (op2
) != mode
)
7968 op2
= gen_lowpart (mode
, op2
);
7970 /* Try to emit the conditional move. */
7971 insn
= emit_conditional_move (temp
, comparison_code
,
7972 op00
, op01
, comparison_mode
,
7976 /* If we could do the conditional move, emit the sequence,
7980 rtx seq
= get_insns ();
7986 /* Otherwise discard the sequence and fall back to code with
7994 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
7995 enum expand_modifier modifier
)
7997 rtx op0
, op1
, op2
, temp
;
8000 enum machine_mode mode
;
8001 enum tree_code code
= ops
->code
;
8003 rtx subtarget
, original_target
;
8005 bool reduce_bit_field
;
8006 location_t loc
= ops
->location
;
8007 tree treeop0
, treeop1
, treeop2
;
8008 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8009 ? reduce_to_bit_field_precision ((expr), \
8015 mode
= TYPE_MODE (type
);
8016 unsignedp
= TYPE_UNSIGNED (type
);
8022 /* We should be called only on simple (binary or unary) expressions,
8023 exactly those that are valid in gimple expressions that aren't
8024 GIMPLE_SINGLE_RHS (or invalid). */
8025 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8026 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8027 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8029 ignore
= (target
== const0_rtx
8030 || ((CONVERT_EXPR_CODE_P (code
)
8031 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8032 && TREE_CODE (type
) == VOID_TYPE
));
8034 /* We should be called only if we need the result. */
8035 gcc_assert (!ignore
);
8037 /* An operation in what may be a bit-field type needs the
8038 result to be reduced to the precision of the bit-field type,
8039 which is narrower than that of the type's mode. */
8040 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8041 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8043 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8046 /* Use subtarget as the target for operand 0 of a binary operation. */
8047 subtarget
= get_subtarget (target
);
8048 original_target
= target
;
8052 case NON_LVALUE_EXPR
:
8055 if (treeop0
== error_mark_node
)
8058 if (TREE_CODE (type
) == UNION_TYPE
)
8060 tree valtype
= TREE_TYPE (treeop0
);
8062 /* If both input and output are BLKmode, this conversion isn't doing
8063 anything except possibly changing memory attribute. */
8064 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8066 rtx result
= expand_expr (treeop0
, target
, tmode
,
8069 result
= copy_rtx (result
);
8070 set_mem_attributes (result
, type
, 0);
8076 if (TYPE_MODE (type
) != BLKmode
)
8077 target
= gen_reg_rtx (TYPE_MODE (type
));
8079 target
= assign_temp (type
, 1, 1);
8083 /* Store data into beginning of memory target. */
8084 store_expr (treeop0
,
8085 adjust_address (target
, TYPE_MODE (valtype
), 0),
8086 modifier
== EXPAND_STACK_PARM
,
8091 gcc_assert (REG_P (target
));
8093 /* Store this field into a union of the proper type. */
8094 store_field (target
,
8095 MIN ((int_size_in_bytes (TREE_TYPE
8098 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8099 0, 0, 0, TYPE_MODE (valtype
), treeop0
,
8103 /* Return the entire union. */
8107 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8109 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8112 /* If the signedness of the conversion differs and OP0 is
8113 a promoted SUBREG, clear that indication since we now
8114 have to do the proper extension. */
8115 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8116 && GET_CODE (op0
) == SUBREG
)
8117 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8119 return REDUCE_BIT_FIELD (op0
);
8122 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8123 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8124 if (GET_MODE (op0
) == mode
)
8127 /* If OP0 is a constant, just convert it into the proper mode. */
8128 else if (CONSTANT_P (op0
))
8130 tree inner_type
= TREE_TYPE (treeop0
);
8131 enum machine_mode inner_mode
= GET_MODE (op0
);
8133 if (inner_mode
== VOIDmode
)
8134 inner_mode
= TYPE_MODE (inner_type
);
8136 if (modifier
== EXPAND_INITIALIZER
)
8137 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8138 subreg_lowpart_offset (mode
,
8141 op0
= convert_modes (mode
, inner_mode
, op0
,
8142 TYPE_UNSIGNED (inner_type
));
8145 else if (modifier
== EXPAND_INITIALIZER
)
8146 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8148 else if (target
== 0)
8149 op0
= convert_to_mode (mode
, op0
,
8150 TYPE_UNSIGNED (TREE_TYPE
8154 convert_move (target
, op0
,
8155 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8159 return REDUCE_BIT_FIELD (op0
);
8161 case ADDR_SPACE_CONVERT_EXPR
:
8163 tree treeop0_type
= TREE_TYPE (treeop0
);
8165 addr_space_t as_from
;
8167 gcc_assert (POINTER_TYPE_P (type
));
8168 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8170 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8171 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8173 /* Conversions between pointers to the same address space should
8174 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8175 gcc_assert (as_to
!= as_from
);
8177 /* Ask target code to handle conversion between pointers
8178 to overlapping address spaces. */
8179 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8180 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8182 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8183 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8188 /* For disjoint address spaces, converting anything but
8189 a null pointer invokes undefined behaviour. We simply
8190 always return a null pointer here. */
8191 return CONST0_RTX (mode
);
8194 case POINTER_PLUS_EXPR
:
8195 /* Even though the sizetype mode and the pointer's mode can be different
8196 expand is able to handle this correctly and get the correct result out
8197 of the PLUS_EXPR code. */
8198 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8199 if sizetype precision is smaller than pointer precision. */
8200 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8201 treeop1
= fold_convert_loc (loc
, type
,
8202 fold_convert_loc (loc
, ssizetype
,
8204 /* If sizetype precision is larger than pointer precision, truncate the
8205 offset to have matching modes. */
8206 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8207 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8210 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8211 something else, make sure we add the register to the constant and
8212 then to the other thing. This case can occur during strength
8213 reduction and doing it this way will produce better code if the
8214 frame pointer or argument pointer is eliminated.
8216 fold-const.c will ensure that the constant is always in the inner
8217 PLUS_EXPR, so the only case we need to do anything about is if
8218 sp, ap, or fp is our second argument, in which case we must swap
8219 the innermost first argument and our second argument. */
8221 if (TREE_CODE (treeop0
) == PLUS_EXPR
8222 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8223 && TREE_CODE (treeop1
) == VAR_DECL
8224 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8225 || DECL_RTL (treeop1
) == stack_pointer_rtx
8226 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8231 /* If the result is to be ptr_mode and we are adding an integer to
8232 something, we might be forming a constant. So try to use
8233 plus_constant. If it produces a sum and we can't accept it,
8234 use force_operand. This allows P = &ARR[const] to generate
8235 efficient code on machines where a SYMBOL_REF is not a valid
8238 If this is an EXPAND_SUM call, always return the sum. */
8239 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8240 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8242 if (modifier
== EXPAND_STACK_PARM
)
8244 if (TREE_CODE (treeop0
) == INTEGER_CST
8245 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8246 && TREE_CONSTANT (treeop1
))
8250 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8252 /* Use immed_double_const to ensure that the constant is
8253 truncated according to the mode of OP1, then sign extended
8254 to a HOST_WIDE_INT. Using the constant directly can result
8255 in non-canonical RTL in a 64x32 cross compile. */
8257 = immed_double_const (TREE_INT_CST_LOW (treeop0
),
8259 TYPE_MODE (TREE_TYPE (treeop1
)));
8260 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8261 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8262 op1
= force_operand (op1
, target
);
8263 return REDUCE_BIT_FIELD (op1
);
8266 else if (TREE_CODE (treeop1
) == INTEGER_CST
8267 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8268 && TREE_CONSTANT (treeop0
))
8272 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8273 (modifier
== EXPAND_INITIALIZER
8274 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8275 if (! CONSTANT_P (op0
))
8277 op1
= expand_expr (treeop1
, NULL_RTX
,
8278 VOIDmode
, modifier
);
8279 /* Return a PLUS if modifier says it's OK. */
8280 if (modifier
== EXPAND_SUM
8281 || modifier
== EXPAND_INITIALIZER
)
8282 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8285 /* Use immed_double_const to ensure that the constant is
8286 truncated according to the mode of OP1, then sign extended
8287 to a HOST_WIDE_INT. Using the constant directly can result
8288 in non-canonical RTL in a 64x32 cross compile. */
8290 = immed_double_const (TREE_INT_CST_LOW (treeop1
),
8292 TYPE_MODE (TREE_TYPE (treeop0
)));
8293 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8294 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8295 op0
= force_operand (op0
, target
);
8296 return REDUCE_BIT_FIELD (op0
);
8300 /* Use TER to expand pointer addition of a negated value
8301 as pointer subtraction. */
8302 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8303 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8304 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8305 && TREE_CODE (treeop1
) == SSA_NAME
8306 && TYPE_MODE (TREE_TYPE (treeop0
))
8307 == TYPE_MODE (TREE_TYPE (treeop1
)))
8309 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8312 treeop1
= gimple_assign_rhs1 (def
);
8318 /* No sense saving up arithmetic to be done
8319 if it's all in the wrong mode to form part of an address.
8320 And force_operand won't know whether to sign-extend or
8322 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8323 || mode
!= ptr_mode
)
8325 expand_operands (treeop0
, treeop1
,
8326 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8327 if (op0
== const0_rtx
)
8329 if (op1
== const0_rtx
)
8334 expand_operands (treeop0
, treeop1
,
8335 subtarget
, &op0
, &op1
, modifier
);
8336 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8340 /* For initializers, we are allowed to return a MINUS of two
8341 symbolic constants. Here we handle all cases when both operands
8343 /* Handle difference of two symbolic constants,
8344 for the sake of an initializer. */
8345 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8346 && really_constant_p (treeop0
)
8347 && really_constant_p (treeop1
))
8349 expand_operands (treeop0
, treeop1
,
8350 NULL_RTX
, &op0
, &op1
, modifier
);
8352 /* If the last operand is a CONST_INT, use plus_constant of
8353 the negated constant. Else make the MINUS. */
8354 if (CONST_INT_P (op1
))
8355 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8358 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8361 /* No sense saving up arithmetic to be done
8362 if it's all in the wrong mode to form part of an address.
8363 And force_operand won't know whether to sign-extend or
8365 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8366 || mode
!= ptr_mode
)
8369 expand_operands (treeop0
, treeop1
,
8370 subtarget
, &op0
, &op1
, modifier
);
8372 /* Convert A - const to A + (-const). */
8373 if (CONST_INT_P (op1
))
8375 op1
= negate_rtx (mode
, op1
);
8376 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8381 case WIDEN_MULT_PLUS_EXPR
:
8382 case WIDEN_MULT_MINUS_EXPR
:
8383 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8384 op2
= expand_normal (treeop2
);
8385 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8389 case WIDEN_MULT_EXPR
:
8390 /* If first operand is constant, swap them.
8391 Thus the following special case checks need only
8392 check the second operand. */
8393 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8400 /* First, check if we have a multiplication of one signed and one
8401 unsigned operand. */
8402 if (TREE_CODE (treeop1
) != INTEGER_CST
8403 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8404 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8406 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8407 this_optab
= usmul_widen_optab
;
8408 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8409 != CODE_FOR_nothing
)
8411 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8412 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8415 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8420 /* Check for a multiplication with matching signedness. */
8421 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8422 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8423 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8424 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8426 tree op0type
= TREE_TYPE (treeop0
);
8427 enum machine_mode innermode
= TYPE_MODE (op0type
);
8428 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8429 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8430 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8432 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8434 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8435 != CODE_FOR_nothing
)
8437 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8439 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8440 unsignedp
, this_optab
);
8441 return REDUCE_BIT_FIELD (temp
);
8443 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8445 && innermode
== word_mode
)
8448 op0
= expand_normal (treeop0
);
8449 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8450 op1
= convert_modes (innermode
, mode
,
8451 expand_normal (treeop1
), unsignedp
);
8453 op1
= expand_normal (treeop1
);
8454 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8455 unsignedp
, OPTAB_LIB_WIDEN
);
8456 hipart
= gen_highpart (innermode
, temp
);
8457 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8461 emit_move_insn (hipart
, htem
);
8462 return REDUCE_BIT_FIELD (temp
);
8466 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8467 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8468 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8469 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8473 optab opt
= fma_optab
;
8476 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8478 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8480 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8483 gcc_assert (fn
!= NULL_TREE
);
8484 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8485 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8488 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8489 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8494 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8497 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8498 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8501 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8504 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8507 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8510 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8514 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8516 op2
= expand_normal (treeop2
);
8517 op1
= expand_normal (treeop1
);
8519 return expand_ternary_op (TYPE_MODE (type
), opt
,
8520 op0
, op1
, op2
, target
, 0);
8524 /* If this is a fixed-point operation, then we cannot use the code
8525 below because "expand_mult" doesn't support sat/no-sat fixed-point
8527 if (ALL_FIXED_POINT_MODE_P (mode
))
8530 /* If first operand is constant, swap them.
8531 Thus the following special case checks need only
8532 check the second operand. */
8533 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8540 /* Attempt to return something suitable for generating an
8541 indexed address, for machines that support that. */
8543 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8544 && host_integerp (treeop1
, 0))
8546 tree exp1
= treeop1
;
8548 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8552 op0
= force_operand (op0
, NULL_RTX
);
8554 op0
= copy_to_mode_reg (mode
, op0
);
8556 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8557 gen_int_mode (tree_low_cst (exp1
, 0),
8558 TYPE_MODE (TREE_TYPE (exp1
)))));
8561 if (modifier
== EXPAND_STACK_PARM
)
8564 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8565 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8567 case TRUNC_DIV_EXPR
:
8568 case FLOOR_DIV_EXPR
:
8570 case ROUND_DIV_EXPR
:
8571 case EXACT_DIV_EXPR
:
8572 /* If this is a fixed-point operation, then we cannot use the code
8573 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8575 if (ALL_FIXED_POINT_MODE_P (mode
))
8578 if (modifier
== EXPAND_STACK_PARM
)
8580 /* Possible optimization: compute the dividend with EXPAND_SUM
8581 then if the divisor is constant can optimize the case
8582 where some terms of the dividend have coeffs divisible by it. */
8583 expand_operands (treeop0
, treeop1
,
8584 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8585 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8590 case MULT_HIGHPART_EXPR
:
8591 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8592 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8596 case TRUNC_MOD_EXPR
:
8597 case FLOOR_MOD_EXPR
:
8599 case ROUND_MOD_EXPR
:
8600 if (modifier
== EXPAND_STACK_PARM
)
8602 expand_operands (treeop0
, treeop1
,
8603 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8604 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8606 case FIXED_CONVERT_EXPR
:
8607 op0
= expand_normal (treeop0
);
8608 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8609 target
= gen_reg_rtx (mode
);
8611 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8612 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8613 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8614 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8616 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8619 case FIX_TRUNC_EXPR
:
8620 op0
= expand_normal (treeop0
);
8621 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8622 target
= gen_reg_rtx (mode
);
8623 expand_fix (target
, op0
, unsignedp
);
8627 op0
= expand_normal (treeop0
);
8628 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8629 target
= gen_reg_rtx (mode
);
8630 /* expand_float can't figure out what to do if FROM has VOIDmode.
8631 So give it the correct mode. With -O, cse will optimize this. */
8632 if (GET_MODE (op0
) == VOIDmode
)
8633 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8635 expand_float (target
, op0
,
8636 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8640 op0
= expand_expr (treeop0
, subtarget
,
8641 VOIDmode
, EXPAND_NORMAL
);
8642 if (modifier
== EXPAND_STACK_PARM
)
8644 temp
= expand_unop (mode
,
8645 optab_for_tree_code (NEGATE_EXPR
, type
,
8649 return REDUCE_BIT_FIELD (temp
);
8652 op0
= expand_expr (treeop0
, subtarget
,
8653 VOIDmode
, EXPAND_NORMAL
);
8654 if (modifier
== EXPAND_STACK_PARM
)
8657 /* ABS_EXPR is not valid for complex arguments. */
8658 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8659 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8661 /* Unsigned abs is simply the operand. Testing here means we don't
8662 risk generating incorrect code below. */
8663 if (TYPE_UNSIGNED (type
))
8666 return expand_abs (mode
, op0
, target
, unsignedp
,
8667 safe_from_p (target
, treeop0
, 1));
8671 target
= original_target
;
8673 || modifier
== EXPAND_STACK_PARM
8674 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8675 || GET_MODE (target
) != mode
8677 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8678 target
= gen_reg_rtx (mode
);
8679 expand_operands (treeop0
, treeop1
,
8680 target
, &op0
, &op1
, EXPAND_NORMAL
);
8682 /* First try to do it with a special MIN or MAX instruction.
8683 If that does not win, use a conditional jump to select the proper
8685 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8686 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8691 /* At this point, a MEM target is no longer useful; we will get better
8694 if (! REG_P (target
))
8695 target
= gen_reg_rtx (mode
);
8697 /* If op1 was placed in target, swap op0 and op1. */
8698 if (target
!= op0
&& target
== op1
)
8705 /* We generate better code and avoid problems with op1 mentioning
8706 target by forcing op1 into a pseudo if it isn't a constant. */
8707 if (! CONSTANT_P (op1
))
8708 op1
= force_reg (mode
, op1
);
8711 enum rtx_code comparison_code
;
8714 if (code
== MAX_EXPR
)
8715 comparison_code
= unsignedp
? GEU
: GE
;
8717 comparison_code
= unsignedp
? LEU
: LE
;
8719 /* Canonicalize to comparisons against 0. */
8720 if (op1
== const1_rtx
)
8722 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8723 or (a != 0 ? a : 1) for unsigned.
8724 For MIN we are safe converting (a <= 1 ? a : 1)
8725 into (a <= 0 ? a : 1) */
8726 cmpop1
= const0_rtx
;
8727 if (code
== MAX_EXPR
)
8728 comparison_code
= unsignedp
? NE
: GT
;
8730 if (op1
== constm1_rtx
&& !unsignedp
)
8732 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8733 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8734 cmpop1
= const0_rtx
;
8735 if (code
== MIN_EXPR
)
8736 comparison_code
= LT
;
8738 #ifdef HAVE_conditional_move
8739 /* Use a conditional move if possible. */
8740 if (can_conditionally_move_p (mode
))
8744 /* ??? Same problem as in expmed.c: emit_conditional_move
8745 forces a stack adjustment via compare_from_rtx, and we
8746 lose the stack adjustment if the sequence we are about
8747 to create is discarded. */
8748 do_pending_stack_adjust ();
8752 /* Try to emit the conditional move. */
8753 insn
= emit_conditional_move (target
, comparison_code
,
8758 /* If we could do the conditional move, emit the sequence,
8762 rtx seq
= get_insns ();
8768 /* Otherwise discard the sequence and fall back to code with
8774 emit_move_insn (target
, op0
);
8776 temp
= gen_label_rtx ();
8777 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8778 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8781 emit_move_insn (target
, op1
);
8786 op0
= expand_expr (treeop0
, subtarget
,
8787 VOIDmode
, EXPAND_NORMAL
);
8788 if (modifier
== EXPAND_STACK_PARM
)
8790 /* In case we have to reduce the result to bitfield precision
8791 for unsigned bitfield expand this as XOR with a proper constant
8793 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8794 temp
= expand_binop (mode
, xor_optab
, op0
,
8795 immed_double_int_const
8796 (double_int::mask (TYPE_PRECISION (type
)), mode
),
8797 target
, 1, OPTAB_LIB_WIDEN
);
8799 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8803 /* ??? Can optimize bitwise operations with one arg constant.
8804 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8805 and (a bitwise1 b) bitwise2 b (etc)
8806 but that is probably not worth while. */
8815 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8816 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8817 == TYPE_PRECISION (type
)));
8822 /* If this is a fixed-point operation, then we cannot use the code
8823 below because "expand_shift" doesn't support sat/no-sat fixed-point
8825 if (ALL_FIXED_POINT_MODE_P (mode
))
8828 if (! safe_from_p (subtarget
, treeop1
, 1))
8830 if (modifier
== EXPAND_STACK_PARM
)
8832 op0
= expand_expr (treeop0
, subtarget
,
8833 VOIDmode
, EXPAND_NORMAL
);
8834 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8836 if (code
== LSHIFT_EXPR
)
8837 temp
= REDUCE_BIT_FIELD (temp
);
8840 /* Could determine the answer when only additive constants differ. Also,
8841 the addition of one can be handled by changing the condition. */
8848 case UNORDERED_EXPR
:
8856 temp
= do_store_flag (ops
,
8857 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8858 tmode
!= VOIDmode
? tmode
: mode
);
8862 /* Use a compare and a jump for BLKmode comparisons, or for function
8863 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8866 || modifier
== EXPAND_STACK_PARM
8867 || ! safe_from_p (target
, treeop0
, 1)
8868 || ! safe_from_p (target
, treeop1
, 1)
8869 /* Make sure we don't have a hard reg (such as function's return
8870 value) live across basic blocks, if not optimizing. */
8871 || (!optimize
&& REG_P (target
)
8872 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8873 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8875 emit_move_insn (target
, const0_rtx
);
8877 op1
= gen_label_rtx ();
8878 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8880 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8881 emit_move_insn (target
, constm1_rtx
);
8883 emit_move_insn (target
, const1_rtx
);
8889 /* Get the rtx code of the operands. */
8890 op0
= expand_normal (treeop0
);
8891 op1
= expand_normal (treeop1
);
8894 target
= gen_reg_rtx (TYPE_MODE (type
));
8896 /* Move the real (op0) and imaginary (op1) parts to their location. */
8897 write_complex_part (target
, op0
, false);
8898 write_complex_part (target
, op1
, true);
8902 case WIDEN_SUM_EXPR
:
8904 tree oprnd0
= treeop0
;
8905 tree oprnd1
= treeop1
;
8907 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8908 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
8913 case REDUC_MAX_EXPR
:
8914 case REDUC_MIN_EXPR
:
8915 case REDUC_PLUS_EXPR
:
8917 op0
= expand_normal (treeop0
);
8918 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8919 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
8924 case VEC_LSHIFT_EXPR
:
8925 case VEC_RSHIFT_EXPR
:
8927 target
= expand_vec_shift_expr (ops
, target
);
8931 case VEC_UNPACK_HI_EXPR
:
8932 case VEC_UNPACK_LO_EXPR
:
8934 op0
= expand_normal (treeop0
);
8935 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
8941 case VEC_UNPACK_FLOAT_HI_EXPR
:
8942 case VEC_UNPACK_FLOAT_LO_EXPR
:
8944 op0
= expand_normal (treeop0
);
8945 /* The signedness is determined from input operand. */
8946 temp
= expand_widen_pattern_expr
8947 (ops
, op0
, NULL_RTX
, NULL_RTX
,
8948 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8954 case VEC_WIDEN_MULT_HI_EXPR
:
8955 case VEC_WIDEN_MULT_LO_EXPR
:
8956 case VEC_WIDEN_MULT_EVEN_EXPR
:
8957 case VEC_WIDEN_MULT_ODD_EXPR
:
8958 case VEC_WIDEN_LSHIFT_HI_EXPR
:
8959 case VEC_WIDEN_LSHIFT_LO_EXPR
:
8960 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8961 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
8963 gcc_assert (target
);
8966 case VEC_PACK_TRUNC_EXPR
:
8967 case VEC_PACK_SAT_EXPR
:
8968 case VEC_PACK_FIX_TRUNC_EXPR
:
8969 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8973 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
8974 op2
= expand_normal (treeop2
);
8976 /* Careful here: if the target doesn't support integral vector modes,
8977 a constant selection vector could wind up smooshed into a normal
8978 integral constant. */
8979 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
8981 tree sel_type
= TREE_TYPE (treeop2
);
8982 enum machine_mode vmode
8983 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
8984 TYPE_VECTOR_SUBPARTS (sel_type
));
8985 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
8986 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
8987 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
8990 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
8992 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
8998 tree oprnd0
= treeop0
;
8999 tree oprnd1
= treeop1
;
9000 tree oprnd2
= treeop2
;
9003 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9004 op2
= expand_normal (oprnd2
);
9005 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9010 case REALIGN_LOAD_EXPR
:
9012 tree oprnd0
= treeop0
;
9013 tree oprnd1
= treeop1
;
9014 tree oprnd2
= treeop2
;
9017 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9018 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9019 op2
= expand_normal (oprnd2
);
9020 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9027 /* A COND_EXPR with its type being VOID_TYPE represents a
9028 conditional jump and is handled in
9029 expand_gimple_cond_expr. */
9030 gcc_assert (!VOID_TYPE_P (type
));
9032 /* Note that COND_EXPRs whose type is a structure or union
9033 are required to be constructed to contain assignments of
9034 a temporary variable, so that we can evaluate them here
9035 for side effect only. If type is void, we must do likewise. */
9037 gcc_assert (!TREE_ADDRESSABLE (type
)
9039 && TREE_TYPE (treeop1
) != void_type_node
9040 && TREE_TYPE (treeop2
) != void_type_node
);
9042 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9046 /* If we are not to produce a result, we have no target. Otherwise,
9047 if a target was specified use it; it will not be used as an
9048 intermediate target unless it is safe. If no target, use a
9051 if (modifier
!= EXPAND_STACK_PARM
9053 && safe_from_p (original_target
, treeop0
, 1)
9054 && GET_MODE (original_target
) == mode
9055 && !MEM_P (original_target
))
9056 temp
= original_target
;
9058 temp
= assign_temp (type
, 0, 1);
9060 do_pending_stack_adjust ();
9062 op0
= gen_label_rtx ();
9063 op1
= gen_label_rtx ();
9064 jumpifnot (treeop0
, op0
, -1);
9065 store_expr (treeop1
, temp
,
9066 modifier
== EXPAND_STACK_PARM
,
9069 emit_jump_insn (gen_jump (op1
));
9072 store_expr (treeop2
, temp
,
9073 modifier
== EXPAND_STACK_PARM
,
9081 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9088 /* Here to do an ordinary binary operator. */
9090 expand_operands (treeop0
, treeop1
,
9091 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9093 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9095 if (modifier
== EXPAND_STACK_PARM
)
9097 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9098 unsignedp
, OPTAB_LIB_WIDEN
);
9100 /* Bitwise operations do not need bitfield reduction as we expect their
9101 operands being properly truncated. */
9102 if (code
== BIT_XOR_EXPR
9103 || code
== BIT_AND_EXPR
9104 || code
== BIT_IOR_EXPR
)
9106 return REDUCE_BIT_FIELD (temp
);
9108 #undef REDUCE_BIT_FIELD
9111 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9112 enum expand_modifier modifier
, rtx
*alt_rtl
)
9114 rtx op0
, op1
, temp
, decl_rtl
;
9117 enum machine_mode mode
;
9118 enum tree_code code
= TREE_CODE (exp
);
9119 rtx subtarget
, original_target
;
9122 bool reduce_bit_field
;
9123 location_t loc
= EXPR_LOCATION (exp
);
9124 struct separate_ops ops
;
9125 tree treeop0
, treeop1
, treeop2
;
9126 tree ssa_name
= NULL_TREE
;
9129 type
= TREE_TYPE (exp
);
9130 mode
= TYPE_MODE (type
);
9131 unsignedp
= TYPE_UNSIGNED (type
);
9133 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9134 if (!VL_EXP_CLASS_P (exp
))
9135 switch (TREE_CODE_LENGTH (code
))
9138 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9139 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9140 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9150 ignore
= (target
== const0_rtx
9151 || ((CONVERT_EXPR_CODE_P (code
)
9152 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9153 && TREE_CODE (type
) == VOID_TYPE
));
9155 /* An operation in what may be a bit-field type needs the
9156 result to be reduced to the precision of the bit-field type,
9157 which is narrower than that of the type's mode. */
9158 reduce_bit_field
= (!ignore
9159 && INTEGRAL_TYPE_P (type
)
9160 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9162 /* If we are going to ignore this result, we need only do something
9163 if there is a side-effect somewhere in the expression. If there
9164 is, short-circuit the most common cases here. Note that we must
9165 not call expand_expr with anything but const0_rtx in case this
9166 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9170 if (! TREE_SIDE_EFFECTS (exp
))
9173 /* Ensure we reference a volatile object even if value is ignored, but
9174 don't do this if all we are doing is taking its address. */
9175 if (TREE_THIS_VOLATILE (exp
)
9176 && TREE_CODE (exp
) != FUNCTION_DECL
9177 && mode
!= VOIDmode
&& mode
!= BLKmode
9178 && modifier
!= EXPAND_CONST_ADDRESS
)
9180 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9186 if (TREE_CODE_CLASS (code
) == tcc_unary
9187 || code
== BIT_FIELD_REF
9188 || code
== COMPONENT_REF
9189 || code
== INDIRECT_REF
)
9190 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9193 else if (TREE_CODE_CLASS (code
) == tcc_binary
9194 || TREE_CODE_CLASS (code
) == tcc_comparison
9195 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9197 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9198 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9205 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9208 /* Use subtarget as the target for operand 0 of a binary operation. */
9209 subtarget
= get_subtarget (target
);
9210 original_target
= target
;
9216 tree function
= decl_function_context (exp
);
9218 temp
= label_rtx (exp
);
9219 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9221 if (function
!= current_function_decl
9223 LABEL_REF_NONLOCAL_P (temp
) = 1;
9225 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9230 /* ??? ivopts calls expander, without any preparation from
9231 out-of-ssa. So fake instructions as if this was an access to the
9232 base variable. This unnecessarily allocates a pseudo, see how we can
9233 reuse it, if partition base vars have it set already. */
9234 if (!currently_expanding_to_rtl
)
9236 tree var
= SSA_NAME_VAR (exp
);
9237 if (var
&& DECL_RTL_SET_P (var
))
9238 return DECL_RTL (var
);
9239 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9240 LAST_VIRTUAL_REGISTER
+ 1);
9243 g
= get_gimple_for_ssa_name (exp
);
9244 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9246 && modifier
== EXPAND_INITIALIZER
9247 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9248 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9249 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9250 g
= SSA_NAME_DEF_STMT (exp
);
9253 rtx r
= expand_expr_real (gimple_assign_rhs_to_tree (g
), target
,
9254 tmode
, modifier
, NULL
);
9255 if (REG_P (r
) && !REG_EXPR (r
))
9256 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9261 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9262 exp
= SSA_NAME_VAR (ssa_name
);
9263 goto expand_decl_rtl
;
9267 /* If a static var's type was incomplete when the decl was written,
9268 but the type is complete now, lay out the decl now. */
9269 if (DECL_SIZE (exp
) == 0
9270 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9271 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9272 layout_decl (exp
, 0);
9274 /* ... fall through ... */
9278 decl_rtl
= DECL_RTL (exp
);
9280 gcc_assert (decl_rtl
);
9281 decl_rtl
= copy_rtx (decl_rtl
);
9282 /* Record writes to register variables. */
9283 if (modifier
== EXPAND_WRITE
9285 && HARD_REGISTER_P (decl_rtl
))
9286 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9287 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9289 /* Ensure variable marked as used even if it doesn't go through
9290 a parser. If it hasn't be used yet, write out an external
9292 TREE_USED (exp
) = 1;
9294 /* Show we haven't gotten RTL for this yet. */
9297 /* Variables inherited from containing functions should have
9298 been lowered by this point. */
9299 context
= decl_function_context (exp
);
9300 gcc_assert (!context
9301 || context
== current_function_decl
9302 || TREE_STATIC (exp
)
9303 || DECL_EXTERNAL (exp
)
9304 /* ??? C++ creates functions that are not TREE_STATIC. */
9305 || TREE_CODE (exp
) == FUNCTION_DECL
);
9307 /* This is the case of an array whose size is to be determined
9308 from its initializer, while the initializer is still being parsed.
9309 ??? We aren't parsing while expanding anymore. */
9311 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9312 temp
= validize_mem (decl_rtl
);
9314 /* If DECL_RTL is memory, we are in the normal case and the
9315 address is not valid, get the address into a register. */
9317 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9320 *alt_rtl
= decl_rtl
;
9321 decl_rtl
= use_anchored_address (decl_rtl
);
9322 if (modifier
!= EXPAND_CONST_ADDRESS
9323 && modifier
!= EXPAND_SUM
9324 && !memory_address_addr_space_p (DECL_MODE (exp
),
9326 MEM_ADDR_SPACE (decl_rtl
)))
9327 temp
= replace_equiv_address (decl_rtl
,
9328 copy_rtx (XEXP (decl_rtl
, 0)));
9331 /* If we got something, return it. But first, set the alignment
9332 if the address is a register. */
9335 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9336 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9341 /* If the mode of DECL_RTL does not match that of the decl,
9342 there are two cases: we are dealing with a BLKmode value
9343 that is returned in a register, or we are dealing with
9344 a promoted value. In the latter case, return a SUBREG
9345 of the wanted mode, but mark it so that we know that it
9346 was already extended. */
9347 if (REG_P (decl_rtl
)
9348 && DECL_MODE (exp
) != BLKmode
9349 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9351 enum machine_mode pmode
;
9353 /* Get the signedness to be used for this variable. Ensure we get
9354 the same mode we got when the variable was declared. */
9355 if (code
== SSA_NAME
9356 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9357 && gimple_code (g
) == GIMPLE_CALL
)
9359 gcc_assert (!gimple_call_internal_p (g
));
9360 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9361 gimple_call_fntype (g
),
9365 pmode
= promote_decl_mode (exp
, &unsignedp
);
9366 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9368 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9369 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9370 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
9377 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
9378 TREE_INT_CST_HIGH (exp
), mode
);
9384 tree tmp
= NULL_TREE
;
9385 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9386 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9387 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9388 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9389 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9390 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9391 return const_vector_from_tree (exp
);
9392 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9394 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9396 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9400 VEC(constructor_elt
,gc
) *v
;
9402 v
= VEC_alloc (constructor_elt
, gc
, VECTOR_CST_NELTS (exp
));
9403 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9404 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9405 tmp
= build_constructor (type
, v
);
9407 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9412 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9415 /* If optimized, generate immediate CONST_DOUBLE
9416 which will be turned into memory by reload if necessary.
9418 We used to force a register so that loop.c could see it. But
9419 this does not allow gen_* patterns to perform optimizations with
9420 the constants. It also produces two insns in cases like "x = 1.0;".
9421 On most machines, floating-point constants are not permitted in
9422 many insns, so we'd end up copying it to a register in any case.
9424 Now, we do the copying in expand_binop, if appropriate. */
9425 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9426 TYPE_MODE (TREE_TYPE (exp
)));
9429 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9430 TYPE_MODE (TREE_TYPE (exp
)));
9433 /* Handle evaluating a complex constant in a CONCAT target. */
9434 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9436 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9439 rtarg
= XEXP (original_target
, 0);
9440 itarg
= XEXP (original_target
, 1);
9442 /* Move the real and imaginary parts separately. */
9443 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9444 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9447 emit_move_insn (rtarg
, op0
);
9449 emit_move_insn (itarg
, op1
);
9451 return original_target
;
9454 /* ... fall through ... */
9457 temp
= expand_expr_constant (exp
, 1, modifier
);
9459 /* temp contains a constant address.
9460 On RISC machines where a constant address isn't valid,
9461 make some insns to get that address into a register. */
9462 if (modifier
!= EXPAND_CONST_ADDRESS
9463 && modifier
!= EXPAND_INITIALIZER
9464 && modifier
!= EXPAND_SUM
9465 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9466 MEM_ADDR_SPACE (temp
)))
9467 return replace_equiv_address (temp
,
9468 copy_rtx (XEXP (temp
, 0)));
9474 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
9476 if (!SAVE_EXPR_RESOLVED_P (exp
))
9478 /* We can indeed still hit this case, typically via builtin
9479 expanders calling save_expr immediately before expanding
9480 something. Assume this means that we only have to deal
9481 with non-BLKmode values. */
9482 gcc_assert (GET_MODE (ret
) != BLKmode
);
9484 val
= build_decl (EXPR_LOCATION (exp
),
9485 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9486 DECL_ARTIFICIAL (val
) = 1;
9487 DECL_IGNORED_P (val
) = 1;
9489 TREE_OPERAND (exp
, 0) = treeop0
;
9490 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9492 if (!CONSTANT_P (ret
))
9493 ret
= copy_to_reg (ret
);
9494 SET_DECL_RTL (val
, ret
);
9502 /* If we don't need the result, just ensure we evaluate any
9506 unsigned HOST_WIDE_INT idx
;
9509 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9510 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9515 return expand_constructor (exp
, target
, modifier
, false);
9517 case TARGET_MEM_REF
:
9520 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9521 struct mem_address addr
;
9522 enum insn_code icode
;
9525 get_address_description (exp
, &addr
);
9526 op0
= addr_for_mem_ref (&addr
, as
, true);
9527 op0
= memory_address_addr_space (mode
, op0
, as
);
9528 temp
= gen_rtx_MEM (mode
, op0
);
9529 set_mem_attributes (temp
, exp
, 0);
9530 set_mem_addr_space (temp
, as
);
9531 align
= get_object_alignment (exp
);
9532 if (modifier
!= EXPAND_WRITE
9534 && align
< GET_MODE_ALIGNMENT (mode
)
9535 /* If the target does not have special handling for unaligned
9536 loads of mode then it can use regular moves for them. */
9537 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9538 != CODE_FOR_nothing
))
9540 struct expand_operand ops
[2];
9542 /* We've already validated the memory, and we're creating a
9543 new pseudo destination. The predicates really can't fail,
9544 nor can the generator. */
9545 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9546 create_fixed_operand (&ops
[1], temp
);
9547 expand_insn (icode
, 2, ops
);
9548 return ops
[0].value
;
9556 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9557 enum machine_mode address_mode
;
9558 tree base
= TREE_OPERAND (exp
, 0);
9560 enum insn_code icode
;
9562 /* Handle expansion of non-aliased memory with non-BLKmode. That
9563 might end up in a register. */
9564 if (mem_ref_refers_to_non_mem_p (exp
))
9566 HOST_WIDE_INT offset
= mem_ref_offset (exp
).low
;
9569 base
= TREE_OPERAND (base
, 0);
9571 && host_integerp (TYPE_SIZE (TREE_TYPE (exp
)), 1)
9572 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9573 == TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp
)))))
9574 return expand_expr (build1 (VIEW_CONVERT_EXPR
,
9575 TREE_TYPE (exp
), base
),
9576 target
, tmode
, modifier
);
9577 bit_offset
= bitsize_int (offset
* BITS_PER_UNIT
);
9578 bftype
= TREE_TYPE (base
);
9579 if (TYPE_MODE (TREE_TYPE (exp
)) != BLKmode
)
9580 bftype
= TREE_TYPE (exp
);
9583 temp
= assign_stack_temp (DECL_MODE (base
),
9584 GET_MODE_SIZE (DECL_MODE (base
)));
9585 store_expr (base
, temp
, 0, false);
9586 temp
= adjust_address (temp
, BLKmode
, offset
);
9587 set_mem_size (temp
, int_size_in_bytes (TREE_TYPE (exp
)));
9590 return expand_expr (build3 (BIT_FIELD_REF
, bftype
,
9592 TYPE_SIZE (TREE_TYPE (exp
)),
9594 target
, tmode
, modifier
);
9596 address_mode
= targetm
.addr_space
.address_mode (as
);
9597 base
= TREE_OPERAND (exp
, 0);
9598 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9600 tree mask
= gimple_assign_rhs2 (def_stmt
);
9601 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9602 gimple_assign_rhs1 (def_stmt
), mask
);
9603 TREE_OPERAND (exp
, 0) = base
;
9605 align
= get_object_alignment (exp
);
9606 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9607 op0
= memory_address_addr_space (address_mode
, op0
, as
);
9608 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9611 = immed_double_int_const (mem_ref_offset (exp
), address_mode
);
9612 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9614 op0
= memory_address_addr_space (mode
, op0
, as
);
9615 temp
= gen_rtx_MEM (mode
, op0
);
9616 set_mem_attributes (temp
, exp
, 0);
9617 set_mem_addr_space (temp
, as
);
9618 if (TREE_THIS_VOLATILE (exp
))
9619 MEM_VOLATILE_P (temp
) = 1;
9620 if (modifier
!= EXPAND_WRITE
9622 && align
< GET_MODE_ALIGNMENT (mode
))
9624 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9625 != CODE_FOR_nothing
)
9627 struct expand_operand ops
[2];
9629 /* We've already validated the memory, and we're creating a
9630 new pseudo destination. The predicates really can't fail,
9631 nor can the generator. */
9632 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9633 create_fixed_operand (&ops
[1], temp
);
9634 expand_insn (icode
, 2, ops
);
9635 return ops
[0].value
;
9637 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9638 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9639 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9640 true, (modifier
== EXPAND_STACK_PARM
9641 ? NULL_RTX
: target
),
9650 tree array
= treeop0
;
9651 tree index
= treeop1
;
9653 /* Fold an expression like: "foo"[2].
9654 This is not done in fold so it won't happen inside &.
9655 Don't fold if this is for wide characters since it's too
9656 difficult to do correctly and this is a very rare case. */
9658 if (modifier
!= EXPAND_CONST_ADDRESS
9659 && modifier
!= EXPAND_INITIALIZER
9660 && modifier
!= EXPAND_MEMORY
)
9662 tree t
= fold_read_from_constant_string (exp
);
9665 return expand_expr (t
, target
, tmode
, modifier
);
9668 /* If this is a constant index into a constant array,
9669 just get the value from the array. Handle both the cases when
9670 we have an explicit constructor and when our operand is a variable
9671 that was declared const. */
9673 if (modifier
!= EXPAND_CONST_ADDRESS
9674 && modifier
!= EXPAND_INITIALIZER
9675 && modifier
!= EXPAND_MEMORY
9676 && TREE_CODE (array
) == CONSTRUCTOR
9677 && ! TREE_SIDE_EFFECTS (array
)
9678 && TREE_CODE (index
) == INTEGER_CST
)
9680 unsigned HOST_WIDE_INT ix
;
9683 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9685 if (tree_int_cst_equal (field
, index
))
9687 if (!TREE_SIDE_EFFECTS (value
))
9688 return expand_expr (fold (value
), target
, tmode
, modifier
);
9693 else if (optimize
>= 1
9694 && modifier
!= EXPAND_CONST_ADDRESS
9695 && modifier
!= EXPAND_INITIALIZER
9696 && modifier
!= EXPAND_MEMORY
9697 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9698 && TREE_CODE (array
) == VAR_DECL
&& DECL_INITIAL (array
)
9699 && TREE_CODE (DECL_INITIAL (array
)) != ERROR_MARK
9700 && const_value_known_p (array
))
9702 if (TREE_CODE (index
) == INTEGER_CST
)
9704 tree init
= DECL_INITIAL (array
);
9706 if (TREE_CODE (init
) == CONSTRUCTOR
)
9708 unsigned HOST_WIDE_INT ix
;
9711 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9713 if (tree_int_cst_equal (field
, index
))
9715 if (TREE_SIDE_EFFECTS (value
))
9718 if (TREE_CODE (value
) == CONSTRUCTOR
)
9720 /* If VALUE is a CONSTRUCTOR, this
9721 optimization is only useful if
9722 this doesn't store the CONSTRUCTOR
9723 into memory. If it does, it is more
9724 efficient to just load the data from
9725 the array directly. */
9726 rtx ret
= expand_constructor (value
, target
,
9728 if (ret
== NULL_RTX
)
9732 return expand_expr (fold (value
), target
, tmode
,
9736 else if(TREE_CODE (init
) == STRING_CST
)
9738 tree index1
= index
;
9739 tree low_bound
= array_ref_low_bound (exp
);
9740 index1
= fold_convert_loc (loc
, sizetype
,
9743 /* Optimize the special-case of a zero lower bound.
9745 We convert the low_bound to sizetype to avoid some problems
9746 with constant folding. (E.g. suppose the lower bound is 1,
9747 and its mode is QI. Without the conversion,l (ARRAY
9748 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
9749 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
9751 if (! integer_zerop (low_bound
))
9752 index1
= size_diffop_loc (loc
, index1
,
9753 fold_convert_loc (loc
, sizetype
,
9756 if (0 > compare_tree_int (index1
,
9757 TREE_STRING_LENGTH (init
)))
9759 tree type
= TREE_TYPE (TREE_TYPE (init
));
9760 enum machine_mode mode
= TYPE_MODE (type
);
9762 if (GET_MODE_CLASS (mode
) == MODE_INT
9763 && GET_MODE_SIZE (mode
) == 1)
9764 return gen_int_mode (TREE_STRING_POINTER (init
)
9765 [TREE_INT_CST_LOW (index1
)],
9772 goto normal_inner_ref
;
9775 /* If the operand is a CONSTRUCTOR, we can just extract the
9776 appropriate field if it is present. */
9777 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9779 unsigned HOST_WIDE_INT idx
;
9782 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9784 if (field
== treeop1
9785 /* We can normally use the value of the field in the
9786 CONSTRUCTOR. However, if this is a bitfield in
9787 an integral mode that we can fit in a HOST_WIDE_INT,
9788 we must mask only the number of bits in the bitfield,
9789 since this is done implicitly by the constructor. If
9790 the bitfield does not meet either of those conditions,
9791 we can't do this optimization. */
9792 && (! DECL_BIT_FIELD (field
)
9793 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9794 && (GET_MODE_PRECISION (DECL_MODE (field
))
9795 <= HOST_BITS_PER_WIDE_INT
))))
9797 if (DECL_BIT_FIELD (field
)
9798 && modifier
== EXPAND_STACK_PARM
)
9800 op0
= expand_expr (value
, target
, tmode
, modifier
);
9801 if (DECL_BIT_FIELD (field
))
9803 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9804 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9806 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9808 op1
= GEN_INT (((HOST_WIDE_INT
) 1 << bitsize
) - 1);
9809 op0
= expand_and (imode
, op0
, op1
, target
);
9813 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
9815 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
9817 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
9825 goto normal_inner_ref
;
9828 case ARRAY_RANGE_REF
:
9831 enum machine_mode mode1
, mode2
;
9832 HOST_WIDE_INT bitsize
, bitpos
;
9834 int volatilep
= 0, must_force_mem
;
9835 bool packedp
= false;
9836 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
9837 &mode1
, &unsignedp
, &volatilep
, true);
9838 rtx orig_op0
, memloc
;
9839 bool mem_attrs_from_type
= false;
9841 /* If we got back the original object, something is wrong. Perhaps
9842 we are evaluating an expression too early. In any event, don't
9843 infinitely recurse. */
9844 gcc_assert (tem
!= exp
);
9846 if (TYPE_PACKED (TREE_TYPE (TREE_OPERAND (exp
, 0)))
9847 || (TREE_CODE (TREE_OPERAND (exp
, 1)) == FIELD_DECL
9848 && DECL_PACKED (TREE_OPERAND (exp
, 1))))
9851 /* If TEM's type is a union of variable size, pass TARGET to the inner
9852 computation, since it will need a temporary and TARGET is known
9853 to have to do. This occurs in unchecked conversion in Ada. */
9856 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
9857 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
9858 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
9860 && modifier
!= EXPAND_STACK_PARM
9861 ? target
: NULL_RTX
),
9863 (modifier
== EXPAND_INITIALIZER
9864 || modifier
== EXPAND_CONST_ADDRESS
9865 || modifier
== EXPAND_STACK_PARM
)
9866 ? modifier
: EXPAND_NORMAL
);
9869 /* If the bitfield is volatile, we want to access it in the
9870 field's mode, not the computed mode.
9871 If a MEM has VOIDmode (external with incomplete type),
9872 use BLKmode for it instead. */
9875 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
9876 op0
= adjust_address (op0
, mode1
, 0);
9877 else if (GET_MODE (op0
) == VOIDmode
)
9878 op0
= adjust_address (op0
, BLKmode
, 0);
9882 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
9884 /* If we have either an offset, a BLKmode result, or a reference
9885 outside the underlying object, we must force it to memory.
9886 Such a case can occur in Ada if we have unchecked conversion
9887 of an expression from a scalar type to an aggregate type or
9888 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9889 passed a partially uninitialized object or a view-conversion
9890 to a larger size. */
9891 must_force_mem
= (offset
9893 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
9895 /* Handle CONCAT first. */
9896 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
9899 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
9902 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9905 op0
= XEXP (op0
, 0);
9906 mode2
= GET_MODE (op0
);
9908 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9909 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
9913 op0
= XEXP (op0
, 1);
9915 mode2
= GET_MODE (op0
);
9918 /* Otherwise force into memory. */
9922 /* If this is a constant, put it in a register if it is a legitimate
9923 constant and we don't need a memory reference. */
9924 if (CONSTANT_P (op0
)
9926 && targetm
.legitimate_constant_p (mode2
, op0
)
9928 op0
= force_reg (mode2
, op0
);
9930 /* Otherwise, if this is a constant, try to force it to the constant
9931 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9932 is a legitimate constant. */
9933 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
9934 op0
= validize_mem (memloc
);
9936 /* Otherwise, if this is a constant or the object is not in memory
9937 and need be, put it there. */
9938 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
9940 tree nt
= build_qualified_type (TREE_TYPE (tem
),
9941 (TYPE_QUALS (TREE_TYPE (tem
))
9942 | TYPE_QUAL_CONST
));
9943 memloc
= assign_temp (nt
, 1, 1);
9944 emit_move_insn (memloc
, op0
);
9946 mem_attrs_from_type
= true;
9951 enum machine_mode address_mode
;
9952 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
9955 gcc_assert (MEM_P (op0
));
9957 address_mode
= get_address_mode (op0
);
9958 if (GET_MODE (offset_rtx
) != address_mode
)
9959 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
9961 if (GET_MODE (op0
) == BLKmode
9962 /* A constant address in OP0 can have VOIDmode, we must
9963 not try to call force_reg in that case. */
9964 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
9966 && (bitpos
% bitsize
) == 0
9967 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
9968 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
9970 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
9974 op0
= offset_address (op0
, offset_rtx
,
9975 highest_pow2_factor (offset
));
9978 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
9979 record its alignment as BIGGEST_ALIGNMENT. */
9980 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
9981 && is_aligning_offset (offset
, tem
))
9982 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
9984 /* Don't forget about volatility even if this is a bitfield. */
9985 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
9987 if (op0
== orig_op0
)
9988 op0
= copy_rtx (op0
);
9990 MEM_VOLATILE_P (op0
) = 1;
9993 /* In cases where an aligned union has an unaligned object
9994 as a field, we might be extracting a BLKmode value from
9995 an integer-mode (e.g., SImode) object. Handle this case
9996 by doing the extract into an object as wide as the field
9997 (which we know to be the width of a basic mode), then
9998 storing into memory, and changing the mode to BLKmode. */
9999 if (mode1
== VOIDmode
10000 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10001 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10002 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10003 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10004 && modifier
!= EXPAND_CONST_ADDRESS
10005 && modifier
!= EXPAND_INITIALIZER
)
10006 /* If the field is volatile, we always want an aligned
10007 access. Do this in following two situations:
10008 1. the access is not already naturally
10009 aligned, otherwise "normal" (non-bitfield) volatile fields
10010 become non-addressable.
10011 2. the bitsize is narrower than the access size. Need
10012 to extract bitfields from the access. */
10013 || (volatilep
&& flag_strict_volatile_bitfields
> 0
10014 && (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0
10015 || (mode1
!= BLKmode
10016 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)))
10017 /* If the field isn't aligned enough to fetch as a memref,
10018 fetch it as a bit field. */
10019 || (mode1
!= BLKmode
10020 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10021 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10023 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10024 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10025 && ((modifier
== EXPAND_CONST_ADDRESS
10026 || modifier
== EXPAND_INITIALIZER
)
10028 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10029 || (bitpos
% BITS_PER_UNIT
!= 0)))
10030 /* If the type and the field are a constant size and the
10031 size of the type isn't the same size as the bitfield,
10032 we must use bitfield operations. */
10034 && TYPE_SIZE (TREE_TYPE (exp
))
10035 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10036 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10039 enum machine_mode ext_mode
= mode
;
10041 if (ext_mode
== BLKmode
10042 && ! (target
!= 0 && MEM_P (op0
)
10044 && bitpos
% BITS_PER_UNIT
== 0))
10045 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10047 if (ext_mode
== BLKmode
)
10050 target
= assign_temp (type
, 1, 1);
10055 /* In this case, BITPOS must start at a byte boundary and
10056 TARGET, if specified, must be a MEM. */
10057 gcc_assert (MEM_P (op0
)
10058 && (!target
|| MEM_P (target
))
10059 && !(bitpos
% BITS_PER_UNIT
));
10061 emit_block_move (target
,
10062 adjust_address (op0
, VOIDmode
,
10063 bitpos
/ BITS_PER_UNIT
),
10064 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10066 (modifier
== EXPAND_STACK_PARM
10067 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10072 op0
= validize_mem (op0
);
10074 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10075 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10077 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
, packedp
,
10078 (modifier
== EXPAND_STACK_PARM
10079 ? NULL_RTX
: target
),
10080 ext_mode
, ext_mode
);
10082 /* If the result is a record type and BITSIZE is narrower than
10083 the mode of OP0, an integral mode, and this is a big endian
10084 machine, we must put the field into the high-order bits. */
10085 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10086 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10087 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10088 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10089 GET_MODE_BITSIZE (GET_MODE (op0
))
10090 - bitsize
, op0
, 1);
10092 /* If the result type is BLKmode, store the data into a temporary
10093 of the appropriate type, but with the mode corresponding to the
10094 mode for the data we have (op0's mode). It's tempting to make
10095 this a constant type, since we know it's only being stored once,
10096 but that can cause problems if we are taking the address of this
10097 COMPONENT_REF because the MEM of any reference via that address
10098 will have flags corresponding to the type, which will not
10099 necessarily be constant. */
10100 if (mode
== BLKmode
)
10104 new_rtx
= assign_stack_temp_for_type (ext_mode
,
10105 GET_MODE_BITSIZE (ext_mode
),
10107 emit_move_insn (new_rtx
, op0
);
10108 op0
= copy_rtx (new_rtx
);
10109 PUT_MODE (op0
, BLKmode
);
10115 /* If the result is BLKmode, use that to access the object
10117 if (mode
== BLKmode
)
10120 /* Get a reference to just this component. */
10121 if (modifier
== EXPAND_CONST_ADDRESS
10122 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10123 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10125 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10127 if (op0
== orig_op0
)
10128 op0
= copy_rtx (op0
);
10130 /* If op0 is a temporary because of forcing to memory, pass only the
10131 type to set_mem_attributes so that the original expression is never
10132 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10133 if (mem_attrs_from_type
)
10134 set_mem_attributes (op0
, type
, 0);
10136 set_mem_attributes (op0
, exp
, 0);
10138 if (REG_P (XEXP (op0
, 0)))
10139 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10141 MEM_VOLATILE_P (op0
) |= volatilep
;
10142 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10143 || modifier
== EXPAND_CONST_ADDRESS
10144 || modifier
== EXPAND_INITIALIZER
)
10146 else if (target
== 0)
10147 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10149 convert_move (target
, op0
, unsignedp
);
10154 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10157 /* All valid uses of __builtin_va_arg_pack () are removed during
10159 if (CALL_EXPR_VA_ARG_PACK (exp
))
10160 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10162 tree fndecl
= get_callee_fndecl (exp
), attr
;
10165 && (attr
= lookup_attribute ("error",
10166 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10167 error ("%Kcall to %qs declared with attribute error: %s",
10168 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10169 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10171 && (attr
= lookup_attribute ("warning",
10172 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10173 warning_at (tree_nonartificial_location (exp
),
10174 0, "%Kcall to %qs declared with attribute warning: %s",
10175 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10176 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10178 /* Check for a built-in function. */
10179 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10181 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10182 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10185 return expand_call (exp
, target
, ignore
);
10187 case VIEW_CONVERT_EXPR
:
10190 /* If we are converting to BLKmode, try to avoid an intermediate
10191 temporary by fetching an inner memory reference. */
10192 if (mode
== BLKmode
10193 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10194 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10195 && handled_component_p (treeop0
))
10197 enum machine_mode mode1
;
10198 HOST_WIDE_INT bitsize
, bitpos
;
10203 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10204 &offset
, &mode1
, &unsignedp
, &volatilep
,
10208 /* ??? We should work harder and deal with non-zero offsets. */
10210 && (bitpos
% BITS_PER_UNIT
) == 0
10212 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) == 0)
10214 /* See the normal_inner_ref case for the rationale. */
10216 = expand_expr (tem
,
10217 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10218 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10220 && modifier
!= EXPAND_STACK_PARM
10221 ? target
: NULL_RTX
),
10223 (modifier
== EXPAND_INITIALIZER
10224 || modifier
== EXPAND_CONST_ADDRESS
10225 || modifier
== EXPAND_STACK_PARM
)
10226 ? modifier
: EXPAND_NORMAL
);
10228 if (MEM_P (orig_op0
))
10232 /* Get a reference to just this component. */
10233 if (modifier
== EXPAND_CONST_ADDRESS
10234 || modifier
== EXPAND_SUM
10235 || modifier
== EXPAND_INITIALIZER
)
10236 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10238 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10240 if (op0
== orig_op0
)
10241 op0
= copy_rtx (op0
);
10243 set_mem_attributes (op0
, treeop0
, 0);
10244 if (REG_P (XEXP (op0
, 0)))
10245 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10247 MEM_VOLATILE_P (op0
) |= volatilep
;
10253 op0
= expand_expr (treeop0
,
10254 NULL_RTX
, VOIDmode
, modifier
);
10256 /* If the input and output modes are both the same, we are done. */
10257 if (mode
== GET_MODE (op0
))
10259 /* If neither mode is BLKmode, and both modes are the same size
10260 then we can use gen_lowpart. */
10261 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10262 && (GET_MODE_PRECISION (mode
)
10263 == GET_MODE_PRECISION (GET_MODE (op0
)))
10264 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10266 if (GET_CODE (op0
) == SUBREG
)
10267 op0
= force_reg (GET_MODE (op0
), op0
);
10268 temp
= gen_lowpart_common (mode
, op0
);
10273 if (!REG_P (op0
) && !MEM_P (op0
))
10274 op0
= force_reg (GET_MODE (op0
), op0
);
10275 op0
= gen_lowpart (mode
, op0
);
10278 /* If both types are integral, convert from one mode to the other. */
10279 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10280 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10281 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10282 /* As a last resort, spill op0 to memory, and reload it in a
10284 else if (!MEM_P (op0
))
10286 /* If the operand is not a MEM, force it into memory. Since we
10287 are going to be changing the mode of the MEM, don't call
10288 force_const_mem for constants because we don't allow pool
10289 constants to change mode. */
10290 tree inner_type
= TREE_TYPE (treeop0
);
10292 gcc_assert (!TREE_ADDRESSABLE (exp
));
10294 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10296 = assign_stack_temp_for_type
10297 (TYPE_MODE (inner_type
),
10298 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10300 emit_move_insn (target
, op0
);
10304 /* At this point, OP0 is in the correct mode. If the output type is
10305 such that the operand is known to be aligned, indicate that it is.
10306 Otherwise, we need only be concerned about alignment for non-BLKmode
10310 enum insn_code icode
;
10312 if (TYPE_ALIGN_OK (type
))
10314 /* ??? Copying the MEM without substantially changing it might
10315 run afoul of the code handling volatile memory references in
10316 store_expr, which assumes that TARGET is returned unmodified
10317 if it has been used. */
10318 op0
= copy_rtx (op0
);
10319 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10321 else if (mode
!= BLKmode
10322 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
)
10323 /* If the target does have special handling for unaligned
10324 loads of mode then use them. */
10325 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10326 != CODE_FOR_nothing
))
10330 op0
= adjust_address (op0
, mode
, 0);
10331 /* We've already validated the memory, and we're creating a
10332 new pseudo destination. The predicates really can't
10334 reg
= gen_reg_rtx (mode
);
10336 /* Nor can the insn generator. */
10337 insn
= GEN_FCN (icode
) (reg
, op0
);
10341 else if (STRICT_ALIGNMENT
10343 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10345 tree inner_type
= TREE_TYPE (treeop0
);
10346 HOST_WIDE_INT temp_size
10347 = MAX (int_size_in_bytes (inner_type
),
10348 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10350 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10351 rtx new_with_op0_mode
10352 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10354 gcc_assert (!TREE_ADDRESSABLE (exp
));
10356 if (GET_MODE (op0
) == BLKmode
)
10357 emit_block_move (new_with_op0_mode
, op0
,
10358 GEN_INT (GET_MODE_SIZE (mode
)),
10359 (modifier
== EXPAND_STACK_PARM
10360 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10362 emit_move_insn (new_with_op0_mode
, op0
);
10367 op0
= adjust_address (op0
, mode
, 0);
10374 tree lhs
= treeop0
;
10375 tree rhs
= treeop1
;
10376 gcc_assert (ignore
);
10378 /* Check for |= or &= of a bitfield of size one into another bitfield
10379 of size 1. In this case, (unless we need the result of the
10380 assignment) we can do this more efficiently with a
10381 test followed by an assignment, if necessary.
10383 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10384 things change so we do, this code should be enhanced to
10386 if (TREE_CODE (lhs
) == COMPONENT_REF
10387 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10388 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10389 && TREE_OPERAND (rhs
, 0) == lhs
10390 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10391 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10392 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10394 rtx label
= gen_label_rtx ();
10395 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10396 do_jump (TREE_OPERAND (rhs
, 1),
10398 value
? 0 : label
, -1);
10399 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10401 do_pending_stack_adjust ();
10402 emit_label (label
);
10406 expand_assignment (lhs
, rhs
, false);
10411 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10413 case REALPART_EXPR
:
10414 op0
= expand_normal (treeop0
);
10415 return read_complex_part (op0
, false);
10417 case IMAGPART_EXPR
:
10418 op0
= expand_normal (treeop0
);
10419 return read_complex_part (op0
, true);
10426 /* Expanded in cfgexpand.c. */
10427 gcc_unreachable ();
10429 case TRY_CATCH_EXPR
:
10431 case EH_FILTER_EXPR
:
10432 case TRY_FINALLY_EXPR
:
10433 /* Lowered by tree-eh.c. */
10434 gcc_unreachable ();
10436 case WITH_CLEANUP_EXPR
:
10437 case CLEANUP_POINT_EXPR
:
10439 case CASE_LABEL_EXPR
:
10444 case COMPOUND_EXPR
:
10445 case PREINCREMENT_EXPR
:
10446 case PREDECREMENT_EXPR
:
10447 case POSTINCREMENT_EXPR
:
10448 case POSTDECREMENT_EXPR
:
10451 case COMPOUND_LITERAL_EXPR
:
10452 /* Lowered by gimplify.c. */
10453 gcc_unreachable ();
10456 /* Function descriptors are not valid except for as
10457 initialization constants, and should not be expanded. */
10458 gcc_unreachable ();
10460 case WITH_SIZE_EXPR
:
10461 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10462 have pulled out the size to use in whatever context it needed. */
10463 return expand_expr_real (treeop0
, original_target
, tmode
,
10464 modifier
, alt_rtl
);
10467 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10471 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10472 signedness of TYPE), possibly returning the result in TARGET. */
10474 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10476 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10477 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10479 /* For constant values, reduce using build_int_cst_type. */
10480 if (CONST_INT_P (exp
))
10482 HOST_WIDE_INT value
= INTVAL (exp
);
10483 tree t
= build_int_cst_type (type
, value
);
10484 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10486 else if (TYPE_UNSIGNED (type
))
10488 rtx mask
= immed_double_int_const (double_int::mask (prec
),
10490 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
10494 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10495 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10496 exp
, count
, target
, 0);
10497 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10498 exp
, count
, target
, 0);
10502 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10503 when applied to the address of EXP produces an address known to be
10504 aligned more than BIGGEST_ALIGNMENT. */
10507 is_aligning_offset (const_tree offset
, const_tree exp
)
10509 /* Strip off any conversions. */
10510 while (CONVERT_EXPR_P (offset
))
10511 offset
= TREE_OPERAND (offset
, 0);
10513 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10514 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10515 if (TREE_CODE (offset
) != BIT_AND_EXPR
10516 || !host_integerp (TREE_OPERAND (offset
, 1), 1)
10517 || compare_tree_int (TREE_OPERAND (offset
, 1),
10518 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10519 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset
, 1), 1) + 1) < 0)
10522 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10523 It must be NEGATE_EXPR. Then strip any more conversions. */
10524 offset
= TREE_OPERAND (offset
, 0);
10525 while (CONVERT_EXPR_P (offset
))
10526 offset
= TREE_OPERAND (offset
, 0);
10528 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10531 offset
= TREE_OPERAND (offset
, 0);
10532 while (CONVERT_EXPR_P (offset
))
10533 offset
= TREE_OPERAND (offset
, 0);
10535 /* This must now be the address of EXP. */
10536 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10539 /* Return the tree node if an ARG corresponds to a string constant or zero
10540 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10541 in bytes within the string that ARG is accessing. The type of the
10542 offset will be `sizetype'. */
10545 string_constant (tree arg
, tree
*ptr_offset
)
10547 tree array
, offset
, lower_bound
;
10550 if (TREE_CODE (arg
) == ADDR_EXPR
)
10552 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10554 *ptr_offset
= size_zero_node
;
10555 return TREE_OPERAND (arg
, 0);
10557 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10559 array
= TREE_OPERAND (arg
, 0);
10560 offset
= size_zero_node
;
10562 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10564 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10565 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10566 if (TREE_CODE (array
) != STRING_CST
10567 && TREE_CODE (array
) != VAR_DECL
)
10570 /* Check if the array has a nonzero lower bound. */
10571 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10572 if (!integer_zerop (lower_bound
))
10574 /* If the offset and base aren't both constants, return 0. */
10575 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10577 if (TREE_CODE (offset
) != INTEGER_CST
)
10579 /* Adjust offset by the lower bound. */
10580 offset
= size_diffop (fold_convert (sizetype
, offset
),
10581 fold_convert (sizetype
, lower_bound
));
10584 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10586 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10587 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10588 if (TREE_CODE (array
) != ADDR_EXPR
)
10590 array
= TREE_OPERAND (array
, 0);
10591 if (TREE_CODE (array
) != STRING_CST
10592 && TREE_CODE (array
) != VAR_DECL
)
10598 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10600 tree arg0
= TREE_OPERAND (arg
, 0);
10601 tree arg1
= TREE_OPERAND (arg
, 1);
10606 if (TREE_CODE (arg0
) == ADDR_EXPR
10607 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10608 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10610 array
= TREE_OPERAND (arg0
, 0);
10613 else if (TREE_CODE (arg1
) == ADDR_EXPR
10614 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10615 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10617 array
= TREE_OPERAND (arg1
, 0);
10626 if (TREE_CODE (array
) == STRING_CST
)
10628 *ptr_offset
= fold_convert (sizetype
, offset
);
10631 else if (TREE_CODE (array
) == VAR_DECL
10632 || TREE_CODE (array
) == CONST_DECL
)
10636 /* Variables initialized to string literals can be handled too. */
10637 if (!const_value_known_p (array
)
10638 || !DECL_INITIAL (array
)
10639 || TREE_CODE (DECL_INITIAL (array
)) != STRING_CST
)
10642 /* Avoid const char foo[4] = "abcde"; */
10643 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10644 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10645 || (length
= TREE_STRING_LENGTH (DECL_INITIAL (array
))) <= 0
10646 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10649 /* If variable is bigger than the string literal, OFFSET must be constant
10650 and inside of the bounds of the string literal. */
10651 offset
= fold_convert (sizetype
, offset
);
10652 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10653 && (! host_integerp (offset
, 1)
10654 || compare_tree_int (offset
, length
) >= 0))
10657 *ptr_offset
= offset
;
10658 return DECL_INITIAL (array
);
10664 /* Generate code to calculate OPS, and exploded expression
10665 using a store-flag instruction and return an rtx for the result.
10666 OPS reflects a comparison.
10668 If TARGET is nonzero, store the result there if convenient.
10670 Return zero if there is no suitable set-flag instruction
10671 available on this machine.
10673 Once expand_expr has been called on the arguments of the comparison,
10674 we are committed to doing the store flag, since it is not safe to
10675 re-evaluate the expression. We emit the store-flag insn by calling
10676 emit_store_flag, but only expand the arguments if we have a reason
10677 to believe that emit_store_flag will be successful. If we think that
10678 it will, but it isn't, we have to simulate the store-flag with a
10679 set/jump/set sequence. */
10682 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10684 enum rtx_code code
;
10685 tree arg0
, arg1
, type
;
10687 enum machine_mode operand_mode
;
10690 rtx subtarget
= target
;
10691 location_t loc
= ops
->location
;
10696 /* Don't crash if the comparison was erroneous. */
10697 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10700 type
= TREE_TYPE (arg0
);
10701 operand_mode
= TYPE_MODE (type
);
10702 unsignedp
= TYPE_UNSIGNED (type
);
10704 /* We won't bother with BLKmode store-flag operations because it would mean
10705 passing a lot of information to emit_store_flag. */
10706 if (operand_mode
== BLKmode
)
10709 /* We won't bother with store-flag operations involving function pointers
10710 when function pointers must be canonicalized before comparisons. */
10711 #ifdef HAVE_canonicalize_funcptr_for_compare
10712 if (HAVE_canonicalize_funcptr_for_compare
10713 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10714 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10716 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10717 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10718 == FUNCTION_TYPE
))))
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 DEFAULT_PROBABILITY is the probability of jumping to the default
10871 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
10872 rtx table_label
, rtx default_label
, rtx fallback_label
,
10873 int default_probability
)
10875 struct expand_operand ops
[5];
10876 enum machine_mode index_mode
= SImode
;
10877 rtx op1
, op2
, index
;
10882 /* Convert the index to SImode. */
10883 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
10885 enum machine_mode omode
= TYPE_MODE (index_type
);
10886 rtx rangertx
= expand_normal (range
);
10888 /* We must handle the endpoints in the original mode. */
10889 index_expr
= build2 (MINUS_EXPR
, index_type
,
10890 index_expr
, minval
);
10891 minval
= integer_zero_node
;
10892 index
= expand_normal (index_expr
);
10894 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
10895 omode
, 1, default_label
,
10896 default_probability
);
10897 /* Now we can safely truncate. */
10898 index
= convert_to_mode (index_mode
, index
, 0);
10902 if (TYPE_MODE (index_type
) != index_mode
)
10904 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
10905 index_expr
= fold_convert (index_type
, index_expr
);
10908 index
= expand_normal (index_expr
);
10911 do_pending_stack_adjust ();
10913 op1
= expand_normal (minval
);
10914 op2
= expand_normal (range
);
10916 create_input_operand (&ops
[0], index
, index_mode
);
10917 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
10918 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
10919 create_fixed_operand (&ops
[3], table_label
);
10920 create_fixed_operand (&ops
[4], (default_label
10922 : fallback_label
));
10923 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
10927 /* Attempt to generate a tablejump instruction; same concept. */
10928 #ifndef HAVE_tablejump
10929 #define HAVE_tablejump 0
10930 #define gen_tablejump(x, y) (0)
10933 /* Subroutine of the next function.
10935 INDEX is the value being switched on, with the lowest value
10936 in the table already subtracted.
10937 MODE is its expected mode (needed if INDEX is constant).
10938 RANGE is the length of the jump table.
10939 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10941 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10942 index value is out of range.
10943 DEFAULT_PROBABILITY is the probability of jumping to
10944 the default label. */
10947 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
10948 rtx default_label
, int default_probability
)
10952 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
10953 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
10955 /* Do an unsigned comparison (in the proper mode) between the index
10956 expression and the value which represents the length of the range.
10957 Since we just finished subtracting the lower bound of the range
10958 from the index expression, this comparison allows us to simultaneously
10959 check that the original index expression value is both greater than
10960 or equal to the minimum value of the range and less than or equal to
10961 the maximum value of the range. */
10964 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
10965 default_label
, default_probability
);
10968 /* If index is in range, it must fit in Pmode.
10969 Convert to Pmode so we can index with it. */
10971 index
= convert_to_mode (Pmode
, index
, 1);
10973 /* Don't let a MEM slip through, because then INDEX that comes
10974 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
10975 and break_out_memory_refs will go to work on it and mess it up. */
10976 #ifdef PIC_CASE_VECTOR_ADDRESS
10977 if (flag_pic
&& !REG_P (index
))
10978 index
= copy_to_mode_reg (Pmode
, index
);
10981 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
10982 GET_MODE_SIZE, because this indicates how large insns are. The other
10983 uses should all be Pmode, because they are addresses. This code
10984 could fail if addresses and insns are not the same size. */
10985 index
= gen_rtx_PLUS (Pmode
,
10986 gen_rtx_MULT (Pmode
, index
,
10987 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE
))),
10988 gen_rtx_LABEL_REF (Pmode
, table_label
));
10989 #ifdef PIC_CASE_VECTOR_ADDRESS
10991 index
= PIC_CASE_VECTOR_ADDRESS (index
);
10994 index
= memory_address (CASE_VECTOR_MODE
, index
);
10995 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
10996 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
10997 convert_move (temp
, vector
, 0);
10999 emit_jump_insn (gen_tablejump (temp
, table_label
));
11001 /* If we are generating PIC code or if the table is PC-relative, the
11002 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11003 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11008 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11009 rtx table_label
, rtx default_label
, int default_probability
)
11013 if (! HAVE_tablejump
)
11016 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11017 fold_convert (index_type
, index_expr
),
11018 fold_convert (index_type
, minval
));
11019 index
= expand_normal (index_expr
);
11020 do_pending_stack_adjust ();
11022 do_tablejump (index
, TYPE_MODE (index_type
),
11023 convert_modes (TYPE_MODE (index_type
),
11024 TYPE_MODE (TREE_TYPE (range
)),
11025 expand_normal (range
),
11026 TYPE_UNSIGNED (TREE_TYPE (range
))),
11027 table_label
, default_label
, default_probability
);
11031 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11033 const_vector_from_tree (tree exp
)
11039 enum machine_mode inner
, mode
;
11041 mode
= TYPE_MODE (TREE_TYPE (exp
));
11043 if (initializer_zerop (exp
))
11044 return CONST0_RTX (mode
);
11046 units
= GET_MODE_NUNITS (mode
);
11047 inner
= GET_MODE_INNER (mode
);
11049 v
= rtvec_alloc (units
);
11051 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11053 elt
= VECTOR_CST_ELT (exp
, i
);
11055 if (TREE_CODE (elt
) == REAL_CST
)
11056 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11058 else if (TREE_CODE (elt
) == FIXED_CST
)
11059 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11062 RTVEC_ELT (v
, i
) = immed_double_int_const (tree_to_double_int (elt
),
11066 return gen_rtx_CONST_VECTOR (mode
, v
);
11069 /* Build a decl for a personality function given a language prefix. */
11072 build_personality_function (const char *lang
)
11074 const char *unwind_and_version
;
11078 switch (targetm_common
.except_unwind_info (&global_options
))
11083 unwind_and_version
= "_sj0";
11087 unwind_and_version
= "_v0";
11090 unwind_and_version
= "_seh0";
11093 gcc_unreachable ();
11096 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11098 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11099 long_long_unsigned_type_node
,
11100 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11101 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11102 get_identifier (name
), type
);
11103 DECL_ARTIFICIAL (decl
) = 1;
11104 DECL_EXTERNAL (decl
) = 1;
11105 TREE_PUBLIC (decl
) = 1;
11107 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11108 are the flags assigned by targetm.encode_section_info. */
11109 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11114 /* Extracts the personality function of DECL and returns the corresponding
11118 get_personality_function (tree decl
)
11120 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11121 enum eh_personality_kind pk
;
11123 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11124 if (pk
== eh_personality_none
)
11128 && pk
== eh_personality_any
)
11129 personality
= lang_hooks
.eh_personality ();
11131 if (pk
== eh_personality_lang
)
11132 gcc_assert (personality
!= NULL_TREE
);
11134 return XEXP (DECL_RTL (personality
), 0);
11137 #include "gt-expr.h"