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
, 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
,
144 enum machine_mode
, tree
, alias_set_type
, bool);
146 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
148 static int is_aligning_offset (const_tree
, const_tree
);
149 static void expand_operands (tree
, tree
, rtx
, rtx
*, rtx
*,
150 enum expand_modifier
);
151 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
152 static rtx
do_store_flag (sepops
, rtx
, enum machine_mode
);
154 static void emit_single_push_insn (enum machine_mode
, rtx
, tree
);
156 static void do_tablejump (rtx
, enum machine_mode
, rtx
, rtx
, rtx
, int);
157 static rtx
const_vector_from_tree (tree
);
158 static void write_complex_part (rtx
, rtx
, bool);
160 /* This macro is used to determine whether move_by_pieces should be called
161 to perform a structure copy. */
162 #ifndef MOVE_BY_PIECES_P
163 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
164 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
165 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
168 /* This macro is used to determine whether clear_by_pieces should be
169 called to clear storage. */
170 #ifndef CLEAR_BY_PIECES_P
171 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
172 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
173 < (unsigned int) CLEAR_RATIO (optimize_insn_for_speed_p ()))
176 /* This macro is used to determine whether store_by_pieces should be
177 called to "memset" storage with byte values other than zero. */
178 #ifndef SET_BY_PIECES_P
179 #define SET_BY_PIECES_P(SIZE, ALIGN) \
180 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
181 < (unsigned int) SET_RATIO (optimize_insn_for_speed_p ()))
184 /* This macro is used to determine whether store_by_pieces should be
185 called to "memcpy" storage when the source is a constant string. */
186 #ifndef STORE_BY_PIECES_P
187 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
188 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
189 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()))
192 /* This is run to set up which modes can be used
193 directly in memory and to initialize the block move optab. It is run
194 at the beginning of compilation and when the target is reinitialized. */
197 init_expr_target (void)
200 enum machine_mode mode
;
205 /* Try indexing by frame ptr and try by stack ptr.
206 It is known that on the Convex the stack ptr isn't a valid index.
207 With luck, one or the other is valid on any machine. */
208 mem
= gen_rtx_MEM (VOIDmode
, stack_pointer_rtx
);
209 mem1
= gen_rtx_MEM (VOIDmode
, frame_pointer_rtx
);
211 /* A scratch register we can modify in-place below to avoid
212 useless RTL allocations. */
213 reg
= gen_rtx_REG (VOIDmode
, -1);
215 insn
= rtx_alloc (INSN
);
216 pat
= gen_rtx_SET (VOIDmode
, NULL_RTX
, NULL_RTX
);
217 PATTERN (insn
) = pat
;
219 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
220 mode
= (enum machine_mode
) ((int) mode
+ 1))
224 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
225 PUT_MODE (mem
, mode
);
226 PUT_MODE (mem1
, mode
);
227 PUT_MODE (reg
, mode
);
229 /* See if there is some register that can be used in this mode and
230 directly loaded or stored from memory. */
232 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
233 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
234 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
237 if (! HARD_REGNO_MODE_OK (regno
, mode
))
240 SET_REGNO (reg
, regno
);
243 SET_DEST (pat
) = reg
;
244 if (recog (pat
, insn
, &num_clobbers
) >= 0)
245 direct_load
[(int) mode
] = 1;
247 SET_SRC (pat
) = mem1
;
248 SET_DEST (pat
) = reg
;
249 if (recog (pat
, insn
, &num_clobbers
) >= 0)
250 direct_load
[(int) mode
] = 1;
253 SET_DEST (pat
) = mem
;
254 if (recog (pat
, insn
, &num_clobbers
) >= 0)
255 direct_store
[(int) mode
] = 1;
258 SET_DEST (pat
) = mem1
;
259 if (recog (pat
, insn
, &num_clobbers
) >= 0)
260 direct_store
[(int) mode
] = 1;
264 mem
= gen_rtx_MEM (VOIDmode
, gen_rtx_raw_REG (Pmode
, 10000));
266 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
267 mode
= GET_MODE_WIDER_MODE (mode
))
269 enum machine_mode srcmode
;
270 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
271 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
275 ic
= can_extend_p (mode
, srcmode
, 0);
276 if (ic
== CODE_FOR_nothing
)
279 PUT_MODE (mem
, srcmode
);
281 if (insn_operand_matches (ic
, 1, mem
))
282 float_extend_from_mem
[mode
][srcmode
] = true;
287 /* This is run at the start of compiling a function. */
292 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
295 /* Copy data from FROM to TO, where the machine modes are not the same.
296 Both modes may be integer, or both may be floating, or both may be
298 UNSIGNEDP should be nonzero if FROM is an unsigned type.
299 This causes zero-extension instead of sign-extension. */
302 convert_move (rtx to
, rtx from
, int unsignedp
)
304 enum machine_mode to_mode
= GET_MODE (to
);
305 enum machine_mode from_mode
= GET_MODE (from
);
306 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
307 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
311 /* rtx code for making an equivalent value. */
312 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
313 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
316 gcc_assert (to_real
== from_real
);
317 gcc_assert (to_mode
!= BLKmode
);
318 gcc_assert (from_mode
!= BLKmode
);
320 /* If the source and destination are already the same, then there's
325 /* If FROM is a SUBREG that indicates that we have already done at least
326 the required extension, strip it. We don't handle such SUBREGs as
329 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
330 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
331 >= GET_MODE_PRECISION (to_mode
))
332 && SUBREG_PROMOTED_UNSIGNED_P (from
) == unsignedp
)
333 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
335 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
337 if (to_mode
== from_mode
338 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
340 emit_move_insn (to
, from
);
344 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
346 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
348 if (VECTOR_MODE_P (to_mode
))
349 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
351 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
353 emit_move_insn (to
, from
);
357 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
359 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
360 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
369 gcc_assert ((GET_MODE_PRECISION (from_mode
)
370 != GET_MODE_PRECISION (to_mode
))
371 || (DECIMAL_FLOAT_MODE_P (from_mode
)
372 != DECIMAL_FLOAT_MODE_P (to_mode
)));
374 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
375 /* Conversion between decimal float and binary float, same size. */
376 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
377 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
382 /* Try converting directly if the insn is supported. */
384 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
385 if (code
!= CODE_FOR_nothing
)
387 emit_unop_insn (code
, to
, from
,
388 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
392 /* Otherwise use a libcall. */
393 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
395 /* Is this conversion implemented yet? */
396 gcc_assert (libcall
);
399 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
401 insns
= get_insns ();
403 emit_libcall_block (insns
, to
, value
,
404 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
406 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
410 /* Handle pointer conversion. */ /* SPEE 900220. */
411 /* Targets are expected to provide conversion insns between PxImode and
412 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
413 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
415 enum machine_mode full_mode
416 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
418 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
419 != CODE_FOR_nothing
);
421 if (full_mode
!= from_mode
)
422 from
= convert_to_mode (full_mode
, from
, unsignedp
);
423 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
427 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
430 enum machine_mode full_mode
431 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
432 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
433 enum insn_code icode
;
435 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
436 gcc_assert (icode
!= CODE_FOR_nothing
);
438 if (to_mode
== full_mode
)
440 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
444 new_from
= gen_reg_rtx (full_mode
);
445 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
447 /* else proceed to integer conversions below. */
448 from_mode
= full_mode
;
452 /* Make sure both are fixed-point modes or both are not. */
453 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
454 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
455 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
457 /* If we widen from_mode to to_mode and they are in the same class,
458 we won't saturate the result.
459 Otherwise, always saturate the result to play safe. */
460 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
461 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
462 expand_fixed_convert (to
, from
, 0, 0);
464 expand_fixed_convert (to
, from
, 0, 1);
468 /* Now both modes are integers. */
470 /* Handle expanding beyond a word. */
471 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
472 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
479 enum machine_mode lowpart_mode
;
480 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
482 /* Try converting directly if the insn is supported. */
483 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
486 /* If FROM is a SUBREG, put it into a register. Do this
487 so that we always generate the same set of insns for
488 better cse'ing; if an intermediate assignment occurred,
489 we won't be doing the operation directly on the SUBREG. */
490 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
491 from
= force_reg (from_mode
, from
);
492 emit_unop_insn (code
, to
, from
, equiv_code
);
495 /* Next, try converting via full word. */
496 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
497 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
498 != CODE_FOR_nothing
))
500 rtx word_to
= gen_reg_rtx (word_mode
);
503 if (reg_overlap_mentioned_p (to
, from
))
504 from
= force_reg (from_mode
, from
);
507 convert_move (word_to
, from
, unsignedp
);
508 emit_unop_insn (code
, to
, word_to
, equiv_code
);
512 /* No special multiword conversion insn; do it by hand. */
515 /* Since we will turn this into a no conflict block, we must ensure the
516 the source does not overlap the target so force it into an isolated
517 register when maybe so. Likewise for any MEM input, since the
518 conversion sequence might require several references to it and we
519 must ensure we're getting the same value every time. */
521 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
522 from
= force_reg (from_mode
, from
);
524 /* Get a copy of FROM widened to a word, if necessary. */
525 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
526 lowpart_mode
= word_mode
;
528 lowpart_mode
= from_mode
;
530 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
532 lowpart
= gen_lowpart (lowpart_mode
, to
);
533 emit_move_insn (lowpart
, lowfrom
);
535 /* Compute the value to put in each remaining word. */
537 fill_value
= const0_rtx
;
539 fill_value
= emit_store_flag (gen_reg_rtx (word_mode
),
540 LT
, lowfrom
, const0_rtx
,
543 /* Fill the remaining words. */
544 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
546 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
547 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
549 gcc_assert (subword
);
551 if (fill_value
!= subword
)
552 emit_move_insn (subword
, fill_value
);
555 insns
= get_insns ();
562 /* Truncating multi-word to a word or less. */
563 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
564 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
567 && ! MEM_VOLATILE_P (from
)
568 && direct_load
[(int) to_mode
]
569 && ! mode_dependent_address_p (XEXP (from
, 0),
570 MEM_ADDR_SPACE (from
)))
572 || GET_CODE (from
) == SUBREG
))
573 from
= force_reg (from_mode
, from
);
574 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
578 /* Now follow all the conversions between integers
579 no more than a word long. */
581 /* For truncation, usually we can just refer to FROM in a narrower mode. */
582 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
583 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
586 && ! MEM_VOLATILE_P (from
)
587 && direct_load
[(int) to_mode
]
588 && ! mode_dependent_address_p (XEXP (from
, 0),
589 MEM_ADDR_SPACE (from
)))
591 || GET_CODE (from
) == SUBREG
))
592 from
= force_reg (from_mode
, from
);
593 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
594 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
595 from
= copy_to_reg (from
);
596 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
600 /* Handle extension. */
601 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
603 /* Convert directly if that works. */
604 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
607 emit_unop_insn (code
, to
, from
, equiv_code
);
612 enum machine_mode intermediate
;
616 /* Search for a mode to convert via. */
617 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
618 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
619 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
621 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
622 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
623 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
624 != CODE_FOR_nothing
))
626 convert_move (to
, convert_to_mode (intermediate
, from
,
627 unsignedp
), unsignedp
);
631 /* No suitable intermediate mode.
632 Generate what we need with shifts. */
633 shift_amount
= (GET_MODE_PRECISION (to_mode
)
634 - GET_MODE_PRECISION (from_mode
));
635 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
636 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
638 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
641 emit_move_insn (to
, tmp
);
646 /* Support special truncate insns for certain modes. */
647 if (convert_optab_handler (trunc_optab
, to_mode
,
648 from_mode
) != CODE_FOR_nothing
)
650 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
655 /* Handle truncation of volatile memrefs, and so on;
656 the things that couldn't be truncated directly,
657 and for which there was no special instruction.
659 ??? Code above formerly short-circuited this, for most integer
660 mode pairs, with a force_reg in from_mode followed by a recursive
661 call to this routine. Appears always to have been wrong. */
662 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
664 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
665 emit_move_insn (to
, temp
);
669 /* Mode combination is not recognized. */
673 /* Return an rtx for a value that would result
674 from converting X to mode MODE.
675 Both X and MODE may be floating, or both integer.
676 UNSIGNEDP is nonzero if X is an unsigned value.
677 This can be done by referring to a part of X in place
678 or by copying to a new temporary with conversion. */
681 convert_to_mode (enum machine_mode mode
, rtx x
, int unsignedp
)
683 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
686 /* Return an rtx for a value that would result
687 from converting X from mode OLDMODE to mode MODE.
688 Both modes may be floating, or both integer.
689 UNSIGNEDP is nonzero if X is an unsigned value.
691 This can be done by referring to a part of X in place
692 or by copying to a new temporary with conversion.
694 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
697 convert_modes (enum machine_mode mode
, enum machine_mode oldmode
, rtx x
, int unsignedp
)
701 /* If FROM is a SUBREG that indicates that we have already done at least
702 the required extension, strip it. */
704 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
705 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
706 && SUBREG_PROMOTED_UNSIGNED_P (x
) == unsignedp
)
707 x
= gen_lowpart (mode
, x
);
709 if (GET_MODE (x
) != VOIDmode
)
710 oldmode
= GET_MODE (x
);
715 /* There is one case that we must handle specially: If we are converting
716 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
717 we are to interpret the constant as unsigned, gen_lowpart will do
718 the wrong if the constant appears negative. What we want to do is
719 make the high-order word of the constant zero, not all ones. */
721 if (unsignedp
&& GET_MODE_CLASS (mode
) == MODE_INT
722 && GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
723 && CONST_INT_P (x
) && INTVAL (x
) < 0)
725 double_int val
= double_int::from_uhwi (INTVAL (x
));
727 /* We need to zero extend VAL. */
728 if (oldmode
!= VOIDmode
)
729 val
= val
.zext (GET_MODE_BITSIZE (oldmode
));
731 return immed_double_int_const (val
, mode
);
734 /* We can do this with a gen_lowpart if both desired and current modes
735 are integer, and this is either a constant integer, a register, or a
736 non-volatile MEM. Except for the constant case where MODE is no
737 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
740 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
)
741 || (GET_MODE_CLASS (mode
) == MODE_INT
742 && GET_MODE_CLASS (oldmode
) == MODE_INT
743 && (CONST_DOUBLE_AS_INT_P (x
)
744 || (GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
745 && ((MEM_P (x
) && ! MEM_VOLATILE_P (x
)
746 && direct_load
[(int) mode
])
748 && (! HARD_REGISTER_P (x
)
749 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
750 && TRULY_NOOP_TRUNCATION_MODES_P (mode
,
753 /* ?? If we don't know OLDMODE, we have to assume here that
754 X does not need sign- or zero-extension. This may not be
755 the case, but it's the best we can do. */
756 if (CONST_INT_P (x
) && oldmode
!= VOIDmode
757 && GET_MODE_PRECISION (mode
) > GET_MODE_PRECISION (oldmode
))
759 HOST_WIDE_INT val
= INTVAL (x
);
761 /* We must sign or zero-extend in this case. Start by
762 zero-extending, then sign extend if we need to. */
763 val
&= GET_MODE_MASK (oldmode
);
765 && val_signbit_known_set_p (oldmode
, val
))
766 val
|= ~GET_MODE_MASK (oldmode
);
768 return gen_int_mode (val
, mode
);
771 return gen_lowpart (mode
, x
);
774 /* Converting from integer constant into mode is always equivalent to an
776 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
778 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
779 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
782 temp
= gen_reg_rtx (mode
);
783 convert_move (temp
, x
, unsignedp
);
787 /* Return the largest alignment we can use for doing a move (or store)
788 of MAX_PIECES. ALIGN is the largest alignment we could use. */
791 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
793 enum machine_mode tmode
;
795 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
796 if (align
>= GET_MODE_ALIGNMENT (tmode
))
797 align
= GET_MODE_ALIGNMENT (tmode
);
800 enum machine_mode tmode
, xmode
;
802 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
804 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
805 if (GET_MODE_SIZE (tmode
) > max_pieces
806 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
809 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
815 /* Return the widest integer mode no wider than SIZE. If no such mode
816 can be found, return VOIDmode. */
818 static enum machine_mode
819 widest_int_mode_for_size (unsigned int size
)
821 enum machine_mode tmode
, mode
= VOIDmode
;
823 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
824 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
825 if (GET_MODE_SIZE (tmode
) < size
)
831 /* STORE_MAX_PIECES is the number of bytes at a time that we can
832 store efficiently. Due to internal GCC limitations, this is
833 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
834 for an immediate constant. */
836 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
838 /* Determine whether the LEN bytes can be moved by using several move
839 instructions. Return nonzero if a call to move_by_pieces should
843 can_move_by_pieces (unsigned HOST_WIDE_INT len ATTRIBUTE_UNUSED
,
844 unsigned int align ATTRIBUTE_UNUSED
)
846 return MOVE_BY_PIECES_P (len
, align
);
849 /* Generate several move instructions to copy LEN bytes from block FROM to
850 block TO. (These are MEM rtx's with BLKmode).
852 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
853 used to push FROM to the stack.
855 ALIGN is maximum stack alignment we can assume.
857 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
858 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
862 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
863 unsigned int align
, int endp
)
865 struct move_by_pieces_d data
;
866 enum machine_mode to_addr_mode
;
867 enum machine_mode from_addr_mode
= get_address_mode (from
);
868 rtx to_addr
, from_addr
= XEXP (from
, 0);
869 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
870 enum insn_code icode
;
872 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
875 data
.from_addr
= from_addr
;
878 to_addr_mode
= get_address_mode (to
);
879 to_addr
= XEXP (to
, 0);
882 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
883 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
885 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
889 to_addr_mode
= VOIDmode
;
893 #ifdef STACK_GROWS_DOWNWARD
899 data
.to_addr
= to_addr
;
902 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
903 || GET_CODE (from_addr
) == POST_INC
904 || GET_CODE (from_addr
) == POST_DEC
);
906 data
.explicit_inc_from
= 0;
907 data
.explicit_inc_to
= 0;
908 if (data
.reverse
) data
.offset
= len
;
911 /* If copying requires more than two move insns,
912 copy addresses to registers (to make displacements shorter)
913 and use post-increment if available. */
914 if (!(data
.autinc_from
&& data
.autinc_to
)
915 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
917 /* Find the mode of the largest move...
918 MODE might not be used depending on the definitions of the
919 USE_* macros below. */
920 enum machine_mode mode ATTRIBUTE_UNUSED
921 = widest_int_mode_for_size (max_size
);
923 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
925 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
926 plus_constant (from_addr_mode
,
928 data
.autinc_from
= 1;
929 data
.explicit_inc_from
= -1;
931 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
933 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
934 data
.autinc_from
= 1;
935 data
.explicit_inc_from
= 1;
937 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
938 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
939 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
941 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
942 plus_constant (to_addr_mode
,
945 data
.explicit_inc_to
= -1;
947 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
949 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
951 data
.explicit_inc_to
= 1;
953 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
954 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
957 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
959 /* First move what we can in the largest integer mode, then go to
960 successively smaller modes. */
962 while (max_size
> 1 && data
.len
> 0)
964 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
966 if (mode
== VOIDmode
)
969 icode
= optab_handler (mov_optab
, mode
);
970 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
971 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
973 max_size
= GET_MODE_SIZE (mode
);
976 /* The code above should have handled everything. */
977 gcc_assert (!data
.len
);
983 gcc_assert (!data
.reverse
);
988 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
989 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
991 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
992 plus_constant (to_addr_mode
,
996 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
1003 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
1011 /* Return number of insns required to move L bytes by pieces.
1012 ALIGN (in bits) is maximum alignment we can assume. */
1014 unsigned HOST_WIDE_INT
1015 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1016 unsigned int max_size
)
1018 unsigned HOST_WIDE_INT n_insns
= 0;
1020 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1022 while (max_size
> 1 && l
> 0)
1024 enum machine_mode mode
;
1025 enum insn_code icode
;
1027 mode
= widest_int_mode_for_size (max_size
);
1029 if (mode
== VOIDmode
)
1032 icode
= optab_handler (mov_optab
, mode
);
1033 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
1034 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
1036 max_size
= GET_MODE_SIZE (mode
);
1043 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1044 with move instructions for mode MODE. GENFUN is the gen_... function
1045 to make a move insn for that mode. DATA has all the other info. */
1048 move_by_pieces_1 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
1049 struct move_by_pieces_d
*data
)
1051 unsigned int size
= GET_MODE_SIZE (mode
);
1052 rtx to1
= NULL_RTX
, from1
;
1054 while (data
->len
>= size
)
1057 data
->offset
-= size
;
1061 if (data
->autinc_to
)
1062 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
1065 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1068 if (data
->autinc_from
)
1069 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1072 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1074 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1075 emit_insn (gen_add2_insn (data
->to_addr
,
1076 GEN_INT (-(HOST_WIDE_INT
)size
)));
1077 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1078 emit_insn (gen_add2_insn (data
->from_addr
,
1079 GEN_INT (-(HOST_WIDE_INT
)size
)));
1082 emit_insn ((*genfun
) (to1
, from1
));
1085 #ifdef PUSH_ROUNDING
1086 emit_single_push_insn (mode
, from1
, NULL
);
1092 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1093 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
1094 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1095 emit_insn (gen_add2_insn (data
->from_addr
, GEN_INT (size
)));
1097 if (! data
->reverse
)
1098 data
->offset
+= size
;
1104 /* Emit code to move a block Y to a block X. This may be done with
1105 string-move instructions, with multiple scalar move instructions,
1106 or with a library call.
1108 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1109 SIZE is an rtx that says how long they are.
1110 ALIGN is the maximum alignment we can assume they have.
1111 METHOD describes what kind of copy this is, and what mechanisms may be used.
1113 Return the address of the new block, if memcpy is called and returns it,
1117 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1118 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
1125 if (CONST_INT_P (size
)
1126 && INTVAL (size
) == 0)
1131 case BLOCK_OP_NORMAL
:
1132 case BLOCK_OP_TAILCALL
:
1133 may_use_call
= true;
1136 case BLOCK_OP_CALL_PARM
:
1137 may_use_call
= block_move_libcall_safe_for_call_parm ();
1139 /* Make inhibit_defer_pop nonzero around the library call
1140 to force it to pop the arguments right away. */
1144 case BLOCK_OP_NO_LIBCALL
:
1145 may_use_call
= false;
1152 gcc_assert (MEM_P (x
) && MEM_P (y
));
1153 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1154 gcc_assert (align
>= BITS_PER_UNIT
);
1156 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1157 block copy is more efficient for other large modes, e.g. DCmode. */
1158 x
= adjust_address (x
, BLKmode
, 0);
1159 y
= adjust_address (y
, BLKmode
, 0);
1161 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1162 can be incorrect is coming from __builtin_memcpy. */
1163 if (CONST_INT_P (size
))
1165 x
= shallow_copy_rtx (x
);
1166 y
= shallow_copy_rtx (y
);
1167 set_mem_size (x
, INTVAL (size
));
1168 set_mem_size (y
, INTVAL (size
));
1171 if (CONST_INT_P (size
) && MOVE_BY_PIECES_P (INTVAL (size
), align
))
1172 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1173 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1174 expected_align
, expected_size
))
1176 else if (may_use_call
1177 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1178 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1180 /* Since x and y are passed to a libcall, mark the corresponding
1181 tree EXPR as addressable. */
1182 tree y_expr
= MEM_EXPR (y
);
1183 tree x_expr
= MEM_EXPR (x
);
1185 mark_addressable (y_expr
);
1187 mark_addressable (x_expr
);
1188 retval
= emit_block_move_via_libcall (x
, y
, size
,
1189 method
== BLOCK_OP_TAILCALL
);
1193 emit_block_move_via_loop (x
, y
, size
, align
);
1195 if (method
== BLOCK_OP_CALL_PARM
)
1202 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1204 return emit_block_move_hints (x
, y
, size
, method
, 0, -1);
1207 /* A subroutine of emit_block_move. Returns true if calling the
1208 block move libcall will not clobber any parameters which may have
1209 already been placed on the stack. */
1212 block_move_libcall_safe_for_call_parm (void)
1214 #if defined (REG_PARM_STACK_SPACE)
1218 /* If arguments are pushed on the stack, then they're safe. */
1222 /* If registers go on the stack anyway, any argument is sure to clobber
1223 an outgoing argument. */
1224 #if defined (REG_PARM_STACK_SPACE)
1225 fn
= emit_block_move_libcall_fn (false);
1226 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1227 depend on its argument. */
1229 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1230 && REG_PARM_STACK_SPACE (fn
) != 0)
1234 /* If any argument goes in memory, then it might clobber an outgoing
1237 CUMULATIVE_ARGS args_so_far_v
;
1238 cumulative_args_t args_so_far
;
1241 fn
= emit_block_move_libcall_fn (false);
1242 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1243 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1245 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1246 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1248 enum machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1249 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1251 if (!tmp
|| !REG_P (tmp
))
1253 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1255 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1262 /* A subroutine of emit_block_move. Expand a movmem pattern;
1263 return true if successful. */
1266 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1267 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
1269 int save_volatile_ok
= volatile_ok
;
1270 enum machine_mode mode
;
1272 if (expected_align
< align
)
1273 expected_align
= align
;
1275 /* Since this is a move insn, we don't care about volatility. */
1278 /* Try the most limited insn first, because there's no point
1279 including more than one in the machine description unless
1280 the more limited one has some advantage. */
1282 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1283 mode
= GET_MODE_WIDER_MODE (mode
))
1285 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1287 if (code
!= CODE_FOR_nothing
1288 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1289 here because if SIZE is less than the mode mask, as it is
1290 returned by the macro, it will definitely be less than the
1291 actual mode mask. */
1292 && ((CONST_INT_P (size
)
1293 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1294 <= (GET_MODE_MASK (mode
) >> 1)))
1295 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
1297 struct expand_operand ops
[6];
1300 /* ??? When called via emit_block_move_for_call, it'd be
1301 nice if there were some way to inform the backend, so
1302 that it doesn't fail the expansion because it thinks
1303 emitting the libcall would be more efficient. */
1304 nops
= insn_data
[(int) code
].n_generator_args
;
1305 gcc_assert (nops
== 4 || nops
== 6);
1307 create_fixed_operand (&ops
[0], x
);
1308 create_fixed_operand (&ops
[1], y
);
1309 /* The check above guarantees that this size conversion is valid. */
1310 create_convert_operand_to (&ops
[2], size
, mode
, true);
1311 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1314 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1315 create_integer_operand (&ops
[5], expected_size
);
1317 if (maybe_expand_insn (code
, nops
, ops
))
1319 volatile_ok
= save_volatile_ok
;
1325 volatile_ok
= save_volatile_ok
;
1329 /* A subroutine of emit_block_move. Expand a call to memcpy.
1330 Return the return value from memcpy, 0 otherwise. */
1333 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1335 rtx dst_addr
, src_addr
;
1336 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1337 enum machine_mode size_mode
;
1340 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1341 pseudos. We can then place those new pseudos into a VAR_DECL and
1344 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1345 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1347 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1348 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1350 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1351 src_tree
= make_tree (ptr_type_node
, src_addr
);
1353 size_mode
= TYPE_MODE (sizetype
);
1355 size
= convert_to_mode (size_mode
, size
, 1);
1356 size
= copy_to_mode_reg (size_mode
, size
);
1358 /* It is incorrect to use the libcall calling conventions to call
1359 memcpy in this context. This could be a user call to memcpy and
1360 the user may wish to examine the return value from memcpy. For
1361 targets where libcalls and normal calls have different conventions
1362 for returning pointers, we could end up generating incorrect code. */
1364 size_tree
= make_tree (sizetype
, size
);
1366 fn
= emit_block_move_libcall_fn (true);
1367 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1368 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1370 retval
= expand_normal (call_expr
);
1375 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1376 for the function we use for block copies. */
1378 static GTY(()) tree block_move_fn
;
1381 init_block_move_fn (const char *asmspec
)
1385 tree args
, fn
, attrs
, attr_args
;
1387 fn
= get_identifier ("memcpy");
1388 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1389 const_ptr_type_node
, sizetype
,
1392 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1393 DECL_EXTERNAL (fn
) = 1;
1394 TREE_PUBLIC (fn
) = 1;
1395 DECL_ARTIFICIAL (fn
) = 1;
1396 TREE_NOTHROW (fn
) = 1;
1397 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1398 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1400 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1401 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1403 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1409 set_user_assembler_name (block_move_fn
, asmspec
);
1413 emit_block_move_libcall_fn (int for_call
)
1415 static bool emitted_extern
;
1418 init_block_move_fn (NULL
);
1420 if (for_call
&& !emitted_extern
)
1422 emitted_extern
= true;
1423 make_decl_rtl (block_move_fn
);
1426 return block_move_fn
;
1429 /* A subroutine of emit_block_move. Copy the data via an explicit
1430 loop. This is used only when libcalls are forbidden. */
1431 /* ??? It'd be nice to copy in hunks larger than QImode. */
1434 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1435 unsigned int align ATTRIBUTE_UNUSED
)
1437 rtx cmp_label
, top_label
, iter
, x_addr
, y_addr
, tmp
;
1438 enum machine_mode x_addr_mode
= get_address_mode (x
);
1439 enum machine_mode y_addr_mode
= get_address_mode (y
);
1440 enum machine_mode iter_mode
;
1442 iter_mode
= GET_MODE (size
);
1443 if (iter_mode
== VOIDmode
)
1444 iter_mode
= word_mode
;
1446 top_label
= gen_label_rtx ();
1447 cmp_label
= gen_label_rtx ();
1448 iter
= gen_reg_rtx (iter_mode
);
1450 emit_move_insn (iter
, const0_rtx
);
1452 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1453 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1454 do_pending_stack_adjust ();
1456 emit_jump (cmp_label
);
1457 emit_label (top_label
);
1459 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1460 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1462 if (x_addr_mode
!= y_addr_mode
)
1463 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1464 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1466 x
= change_address (x
, QImode
, x_addr
);
1467 y
= change_address (y
, QImode
, y_addr
);
1469 emit_move_insn (x
, y
);
1471 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1472 true, OPTAB_LIB_WIDEN
);
1474 emit_move_insn (iter
, tmp
);
1476 emit_label (cmp_label
);
1478 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1479 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1482 /* Copy all or part of a value X into registers starting at REGNO.
1483 The number of registers to be filled is NREGS. */
1486 move_block_to_reg (int regno
, rtx x
, int nregs
, enum machine_mode mode
)
1489 #ifdef HAVE_load_multiple
1497 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1498 x
= validize_mem (force_const_mem (mode
, x
));
1500 /* See if the machine can do this with a load multiple insn. */
1501 #ifdef HAVE_load_multiple
1502 if (HAVE_load_multiple
)
1504 last
= get_last_insn ();
1505 pat
= gen_load_multiple (gen_rtx_REG (word_mode
, regno
), x
,
1513 delete_insns_since (last
);
1517 for (i
= 0; i
< nregs
; i
++)
1518 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1519 operand_subword_force (x
, i
, mode
));
1522 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1523 The number of registers to be filled is NREGS. */
1526 move_block_from_reg (int regno
, rtx x
, int nregs
)
1533 /* See if the machine can do this with a store multiple insn. */
1534 #ifdef HAVE_store_multiple
1535 if (HAVE_store_multiple
)
1537 rtx last
= get_last_insn ();
1538 rtx pat
= gen_store_multiple (x
, gen_rtx_REG (word_mode
, regno
),
1546 delete_insns_since (last
);
1550 for (i
= 0; i
< nregs
; i
++)
1552 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1556 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1560 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1561 ORIG, where ORIG is a non-consecutive group of registers represented by
1562 a PARALLEL. The clone is identical to the original except in that the
1563 original set of registers is replaced by a new set of pseudo registers.
1564 The new set has the same modes as the original set. */
1567 gen_group_rtx (rtx orig
)
1572 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1574 length
= XVECLEN (orig
, 0);
1575 tmps
= XALLOCAVEC (rtx
, length
);
1577 /* Skip a NULL entry in first slot. */
1578 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1583 for (; i
< length
; i
++)
1585 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1586 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1588 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1591 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1594 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1595 except that values are placed in TMPS[i], and must later be moved
1596 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1599 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1603 enum machine_mode m
= GET_MODE (orig_src
);
1605 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1608 && !SCALAR_INT_MODE_P (m
)
1609 && !MEM_P (orig_src
)
1610 && GET_CODE (orig_src
) != CONCAT
)
1612 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1613 if (imode
== BLKmode
)
1614 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1616 src
= gen_reg_rtx (imode
);
1617 if (imode
!= BLKmode
)
1618 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1619 emit_move_insn (src
, orig_src
);
1620 /* ...and back again. */
1621 if (imode
!= BLKmode
)
1622 src
= gen_lowpart (imode
, src
);
1623 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1627 /* Check for a NULL entry, used to indicate that the parameter goes
1628 both on the stack and in registers. */
1629 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1634 /* Process the pieces. */
1635 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1637 enum machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1638 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1639 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1642 /* Handle trailing fragments that run over the size of the struct. */
1643 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1645 /* Arrange to shift the fragment to where it belongs.
1646 extract_bit_field loads to the lsb of the reg. */
1648 #ifdef BLOCK_REG_PADDING
1649 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1650 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1655 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1656 bytelen
= ssize
- bytepos
;
1657 gcc_assert (bytelen
> 0);
1660 /* If we won't be loading directly from memory, protect the real source
1661 from strange tricks we might play; but make sure that the source can
1662 be loaded directly into the destination. */
1664 if (!MEM_P (orig_src
)
1665 && (!CONSTANT_P (orig_src
)
1666 || (GET_MODE (orig_src
) != mode
1667 && GET_MODE (orig_src
) != VOIDmode
)))
1669 if (GET_MODE (orig_src
) == VOIDmode
)
1670 src
= gen_reg_rtx (mode
);
1672 src
= gen_reg_rtx (GET_MODE (orig_src
));
1674 emit_move_insn (src
, orig_src
);
1677 /* Optimize the access just a bit. */
1679 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1680 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1681 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1682 && bytelen
== GET_MODE_SIZE (mode
))
1684 tmps
[i
] = gen_reg_rtx (mode
);
1685 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1687 else if (COMPLEX_MODE_P (mode
)
1688 && GET_MODE (src
) == mode
1689 && bytelen
== GET_MODE_SIZE (mode
))
1690 /* Let emit_move_complex do the bulk of the work. */
1692 else if (GET_CODE (src
) == CONCAT
)
1694 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1695 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1697 if ((bytepos
== 0 && bytelen
== slen0
)
1698 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1700 /* The following assumes that the concatenated objects all
1701 have the same size. In this case, a simple calculation
1702 can be used to determine the object and the bit field
1704 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1705 if (! CONSTANT_P (tmps
[i
])
1706 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1707 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1708 (bytepos
% slen0
) * BITS_PER_UNIT
,
1709 1, false, NULL_RTX
, mode
, mode
);
1715 gcc_assert (!bytepos
);
1716 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1717 emit_move_insn (mem
, src
);
1718 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1719 0, 1, false, NULL_RTX
, mode
, mode
);
1722 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1723 SIMD register, which is currently broken. While we get GCC
1724 to emit proper RTL for these cases, let's dump to memory. */
1725 else if (VECTOR_MODE_P (GET_MODE (dst
))
1728 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1731 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1732 emit_move_insn (mem
, src
);
1733 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1735 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1736 && XVECLEN (dst
, 0) > 1)
1737 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE(dst
), bytepos
);
1738 else if (CONSTANT_P (src
))
1740 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1748 gcc_assert (2 * len
== ssize
);
1749 split_double (src
, &first
, &second
);
1756 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1759 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1760 bytepos
* BITS_PER_UNIT
, 1, false, NULL_RTX
,
1764 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1769 /* Emit code to move a block SRC of type TYPE to a block DST,
1770 where DST is non-consecutive registers represented by a PARALLEL.
1771 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1775 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1780 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1781 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1783 /* Copy the extracted pieces into the proper (probable) hard regs. */
1784 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1786 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1789 emit_move_insn (d
, tmps
[i
]);
1793 /* Similar, but load SRC into new pseudos in a format that looks like
1794 PARALLEL. This can later be fed to emit_group_move to get things
1795 in the right place. */
1798 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1803 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1804 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1806 /* Convert the vector to look just like the original PARALLEL, except
1807 with the computed values. */
1808 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1810 rtx e
= XVECEXP (parallel
, 0, i
);
1811 rtx d
= XEXP (e
, 0);
1815 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1816 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1818 RTVEC_ELT (vec
, i
) = e
;
1821 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1824 /* Emit code to move a block SRC to block DST, where SRC and DST are
1825 non-consecutive groups of registers, each represented by a PARALLEL. */
1828 emit_group_move (rtx dst
, rtx src
)
1832 gcc_assert (GET_CODE (src
) == PARALLEL
1833 && GET_CODE (dst
) == PARALLEL
1834 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1836 /* Skip first entry if NULL. */
1837 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1838 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1839 XEXP (XVECEXP (src
, 0, i
), 0));
1842 /* Move a group of registers represented by a PARALLEL into pseudos. */
1845 emit_group_move_into_temps (rtx src
)
1847 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1850 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1852 rtx e
= XVECEXP (src
, 0, i
);
1853 rtx d
= XEXP (e
, 0);
1856 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1857 RTVEC_ELT (vec
, i
) = e
;
1860 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1863 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1864 where SRC is non-consecutive registers represented by a PARALLEL.
1865 SSIZE represents the total size of block ORIG_DST, or -1 if not
1869 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1872 int start
, finish
, i
;
1873 enum machine_mode m
= GET_MODE (orig_dst
);
1875 gcc_assert (GET_CODE (src
) == PARALLEL
);
1877 if (!SCALAR_INT_MODE_P (m
)
1878 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1880 enum machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1881 if (imode
== BLKmode
)
1882 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1884 dst
= gen_reg_rtx (imode
);
1885 emit_group_store (dst
, src
, type
, ssize
);
1886 if (imode
!= BLKmode
)
1887 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1888 emit_move_insn (orig_dst
, dst
);
1892 /* Check for a NULL entry, used to indicate that the parameter goes
1893 both on the stack and in registers. */
1894 if (XEXP (XVECEXP (src
, 0, 0), 0))
1898 finish
= XVECLEN (src
, 0);
1900 tmps
= XALLOCAVEC (rtx
, finish
);
1902 /* Copy the (probable) hard regs into pseudos. */
1903 for (i
= start
; i
< finish
; i
++)
1905 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1906 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1908 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1909 emit_move_insn (tmps
[i
], reg
);
1915 /* If we won't be storing directly into memory, protect the real destination
1916 from strange tricks we might play. */
1918 if (GET_CODE (dst
) == PARALLEL
)
1922 /* We can get a PARALLEL dst if there is a conditional expression in
1923 a return statement. In that case, the dst and src are the same,
1924 so no action is necessary. */
1925 if (rtx_equal_p (dst
, src
))
1928 /* It is unclear if we can ever reach here, but we may as well handle
1929 it. Allocate a temporary, and split this into a store/load to/from
1932 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1933 emit_group_store (temp
, src
, type
, ssize
);
1934 emit_group_load (dst
, temp
, type
, ssize
);
1937 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1939 enum machine_mode outer
= GET_MODE (dst
);
1940 enum machine_mode inner
;
1941 HOST_WIDE_INT bytepos
;
1945 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1946 dst
= gen_reg_rtx (outer
);
1948 /* Make life a bit easier for combine. */
1949 /* If the first element of the vector is the low part
1950 of the destination mode, use a paradoxical subreg to
1951 initialize the destination. */
1954 inner
= GET_MODE (tmps
[start
]);
1955 bytepos
= subreg_lowpart_offset (inner
, outer
);
1956 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1958 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1962 emit_move_insn (dst
, temp
);
1969 /* If the first element wasn't the low part, try the last. */
1971 && start
< finish
- 1)
1973 inner
= GET_MODE (tmps
[finish
- 1]);
1974 bytepos
= subreg_lowpart_offset (inner
, outer
);
1975 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1977 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1981 emit_move_insn (dst
, temp
);
1988 /* Otherwise, simply initialize the result to zero. */
1990 emit_move_insn (dst
, CONST0_RTX (outer
));
1993 /* Process the pieces. */
1994 for (i
= start
; i
< finish
; i
++)
1996 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
1997 enum machine_mode mode
= GET_MODE (tmps
[i
]);
1998 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1999 unsigned int adj_bytelen
= bytelen
;
2002 /* Handle trailing fragments that run over the size of the struct. */
2003 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2004 adj_bytelen
= ssize
- bytepos
;
2006 if (GET_CODE (dst
) == CONCAT
)
2008 if (bytepos
+ adj_bytelen
2009 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2010 dest
= XEXP (dst
, 0);
2011 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
2013 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
2014 dest
= XEXP (dst
, 1);
2018 enum machine_mode dest_mode
= GET_MODE (dest
);
2019 enum machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
2021 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
2023 if (GET_MODE_ALIGNMENT (dest_mode
)
2024 >= GET_MODE_ALIGNMENT (tmp_mode
))
2026 dest
= assign_stack_temp (dest_mode
,
2027 GET_MODE_SIZE (dest_mode
));
2028 emit_move_insn (adjust_address (dest
,
2036 dest
= assign_stack_temp (tmp_mode
,
2037 GET_MODE_SIZE (tmp_mode
));
2038 emit_move_insn (dest
, tmps
[i
]);
2039 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2045 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2047 /* store_bit_field always takes its value from the lsb.
2048 Move the fragment to the lsb if it's not already there. */
2050 #ifdef BLOCK_REG_PADDING
2051 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2052 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2058 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2059 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2062 bytelen
= adj_bytelen
;
2065 /* Optimize the access just a bit. */
2067 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2068 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2069 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2070 && bytelen
== GET_MODE_SIZE (mode
))
2071 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2073 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2074 0, 0, mode
, tmps
[i
]);
2077 /* Copy from the pseudo into the (probable) hard reg. */
2078 if (orig_dst
!= dst
)
2079 emit_move_insn (orig_dst
, dst
);
2082 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2084 This is used on targets that return BLKmode values in registers. */
2087 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2089 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2090 rtx src
= NULL
, dst
= NULL
;
2091 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2092 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2093 enum machine_mode mode
= GET_MODE (srcreg
);
2094 enum machine_mode tmode
= GET_MODE (target
);
2095 enum machine_mode copy_mode
;
2097 /* BLKmode registers created in the back-end shouldn't have survived. */
2098 gcc_assert (mode
!= BLKmode
);
2100 /* If the structure doesn't take up a whole number of words, see whether
2101 SRCREG is padded on the left or on the right. If it's on the left,
2102 set PADDING_CORRECTION to the number of bits to skip.
2104 In most ABIs, the structure will be returned at the least end of
2105 the register, which translates to right padding on little-endian
2106 targets and left padding on big-endian targets. The opposite
2107 holds if the structure is returned at the most significant
2108 end of the register. */
2109 if (bytes
% UNITS_PER_WORD
!= 0
2110 && (targetm
.calls
.return_in_msb (type
)
2112 : BYTES_BIG_ENDIAN
))
2114 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2116 /* We can use a single move if we have an exact mode for the size. */
2117 else if (MEM_P (target
)
2118 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2119 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2120 && bytes
== GET_MODE_SIZE (mode
))
2122 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2126 /* And if we additionally have the same mode for a register. */
2127 else if (REG_P (target
)
2128 && GET_MODE (target
) == mode
2129 && bytes
== GET_MODE_SIZE (mode
))
2131 emit_move_insn (target
, srcreg
);
2135 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2136 into a new pseudo which is a full word. */
2137 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2139 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2143 /* Copy the structure BITSIZE bits at a time. If the target lives in
2144 memory, take care of not reading/writing past its end by selecting
2145 a copy mode suited to BITSIZE. This should always be possible given
2148 If the target lives in register, make sure not to select a copy mode
2149 larger than the mode of the register.
2151 We could probably emit more efficient code for machines which do not use
2152 strict alignment, but it doesn't seem worth the effort at the current
2155 copy_mode
= word_mode
;
2158 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2159 if (mem_mode
!= BLKmode
)
2160 copy_mode
= mem_mode
;
2162 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2165 for (bitpos
= 0, xbitpos
= padding_correction
;
2166 bitpos
< bytes
* BITS_PER_UNIT
;
2167 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2169 /* We need a new source operand each time xbitpos is on a
2170 word boundary and when xbitpos == padding_correction
2171 (the first time through). */
2172 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2173 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2175 /* We need a new destination operand each time bitpos is on
2177 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2179 else if (bitpos
% BITS_PER_WORD
== 0)
2180 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2182 /* Use xbitpos for the source extraction (right justified) and
2183 bitpos for the destination store (left justified). */
2184 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2185 extract_bit_field (src
, bitsize
,
2186 xbitpos
% BITS_PER_WORD
, 1, false,
2187 NULL_RTX
, copy_mode
, copy_mode
));
2191 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2192 register if it contains any data, otherwise return null.
2194 This is used on targets that return BLKmode values in registers. */
2197 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2200 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2201 unsigned int bitsize
;
2202 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2203 enum machine_mode dst_mode
;
2205 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2207 x
= expand_normal (src
);
2209 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2213 /* If the structure doesn't take up a whole number of words, see
2214 whether the register value should be padded on the left or on
2215 the right. Set PADDING_CORRECTION to the number of padding
2216 bits needed on the left side.
2218 In most ABIs, the structure will be returned at the least end of
2219 the register, which translates to right padding on little-endian
2220 targets and left padding on big-endian targets. The opposite
2221 holds if the structure is returned at the most significant
2222 end of the register. */
2223 if (bytes
% UNITS_PER_WORD
!= 0
2224 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2226 : BYTES_BIG_ENDIAN
))
2227 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2230 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2231 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2232 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2234 /* Copy the structure BITSIZE bits at a time. */
2235 for (bitpos
= 0, xbitpos
= padding_correction
;
2236 bitpos
< bytes
* BITS_PER_UNIT
;
2237 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2239 /* We need a new destination pseudo each time xbitpos is
2240 on a word boundary and when xbitpos == padding_correction
2241 (the first time through). */
2242 if (xbitpos
% BITS_PER_WORD
== 0
2243 || xbitpos
== padding_correction
)
2245 /* Generate an appropriate register. */
2246 dst_word
= gen_reg_rtx (word_mode
);
2247 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2249 /* Clear the destination before we move anything into it. */
2250 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2253 /* We need a new source operand each time bitpos is on a word
2255 if (bitpos
% BITS_PER_WORD
== 0)
2256 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2258 /* Use bitpos for the source extraction (left justified) and
2259 xbitpos for the destination store (right justified). */
2260 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2262 extract_bit_field (src_word
, bitsize
,
2263 bitpos
% BITS_PER_WORD
, 1, false,
2264 NULL_RTX
, word_mode
, word_mode
));
2267 if (mode
== BLKmode
)
2269 /* Find the smallest integer mode large enough to hold the
2270 entire structure. */
2271 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2273 mode
= GET_MODE_WIDER_MODE (mode
))
2274 /* Have we found a large enough mode? */
2275 if (GET_MODE_SIZE (mode
) >= bytes
)
2278 /* A suitable mode should have been found. */
2279 gcc_assert (mode
!= VOIDmode
);
2282 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2283 dst_mode
= word_mode
;
2286 dst
= gen_reg_rtx (dst_mode
);
2288 for (i
= 0; i
< n_regs
; i
++)
2289 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2291 if (mode
!= dst_mode
)
2292 dst
= gen_lowpart (mode
, dst
);
2297 /* Add a USE expression for REG to the (possibly empty) list pointed
2298 to by CALL_FUSAGE. REG must denote a hard register. */
2301 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2303 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2306 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2309 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2310 starting at REGNO. All of these registers must be hard registers. */
2313 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2317 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2319 for (i
= 0; i
< nregs
; i
++)
2320 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2323 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2324 PARALLEL REGS. This is for calls that pass values in multiple
2325 non-contiguous locations. The Irix 6 ABI has examples of this. */
2328 use_group_regs (rtx
*call_fusage
, rtx regs
)
2332 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2334 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2336 /* A NULL entry means the parameter goes both on the stack and in
2337 registers. This can also be a MEM for targets that pass values
2338 partially on the stack and partially in registers. */
2339 if (reg
!= 0 && REG_P (reg
))
2340 use_reg (call_fusage
, reg
);
2344 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2345 assigment and the code of the expresion on the RHS is CODE. Return
2349 get_def_for_expr (tree name
, enum tree_code code
)
2353 if (TREE_CODE (name
) != SSA_NAME
)
2356 def_stmt
= get_gimple_for_ssa_name (name
);
2358 || gimple_assign_rhs_code (def_stmt
) != code
)
2364 #ifdef HAVE_conditional_move
2365 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2366 assigment and the class of the expresion on the RHS is CLASS. Return
2370 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2374 if (TREE_CODE (name
) != SSA_NAME
)
2377 def_stmt
= get_gimple_for_ssa_name (name
);
2379 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2387 /* Determine whether the LEN bytes generated by CONSTFUN can be
2388 stored to memory using several move instructions. CONSTFUNDATA is
2389 a pointer which will be passed as argument in every CONSTFUN call.
2390 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2391 a memset operation and false if it's a copy of a constant string.
2392 Return nonzero if a call to store_by_pieces should succeed. */
2395 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2396 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2397 void *constfundata
, unsigned int align
, bool memsetp
)
2399 unsigned HOST_WIDE_INT l
;
2400 unsigned int max_size
;
2401 HOST_WIDE_INT offset
= 0;
2402 enum machine_mode mode
;
2403 enum insn_code icode
;
2405 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2406 rtx cst ATTRIBUTE_UNUSED
;
2412 ? SET_BY_PIECES_P (len
, align
)
2413 : STORE_BY_PIECES_P (len
, align
)))
2416 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2418 /* We would first store what we can in the largest integer mode, then go to
2419 successively smaller modes. */
2422 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2426 max_size
= STORE_MAX_PIECES
+ 1;
2427 while (max_size
> 1 && l
> 0)
2429 mode
= widest_int_mode_for_size (max_size
);
2431 if (mode
== VOIDmode
)
2434 icode
= optab_handler (mov_optab
, mode
);
2435 if (icode
!= CODE_FOR_nothing
2436 && align
>= GET_MODE_ALIGNMENT (mode
))
2438 unsigned int size
= GET_MODE_SIZE (mode
);
2445 cst
= (*constfun
) (constfundata
, offset
, mode
);
2446 if (!targetm
.legitimate_constant_p (mode
, cst
))
2456 max_size
= GET_MODE_SIZE (mode
);
2459 /* The code above should have handled everything. */
2466 /* Generate several move instructions to store LEN bytes generated by
2467 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2468 pointer which will be passed as argument in every CONSTFUN call.
2469 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2470 a memset operation and false if it's a copy of a constant string.
2471 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2472 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2476 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2477 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2478 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2480 enum machine_mode to_addr_mode
= get_address_mode (to
);
2481 struct store_by_pieces_d data
;
2485 gcc_assert (endp
!= 2);
2490 ? SET_BY_PIECES_P (len
, align
)
2491 : STORE_BY_PIECES_P (len
, align
));
2492 data
.constfun
= constfun
;
2493 data
.constfundata
= constfundata
;
2496 store_by_pieces_1 (&data
, align
);
2501 gcc_assert (!data
.reverse
);
2506 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2507 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2509 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2510 plus_constant (to_addr_mode
,
2514 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2521 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2529 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2530 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2533 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2535 struct store_by_pieces_d data
;
2540 data
.constfun
= clear_by_pieces_1
;
2541 data
.constfundata
= NULL
;
2544 store_by_pieces_1 (&data
, align
);
2547 /* Callback routine for clear_by_pieces.
2548 Return const0_rtx unconditionally. */
2551 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2552 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2553 enum machine_mode mode ATTRIBUTE_UNUSED
)
2558 /* Subroutine of clear_by_pieces and store_by_pieces.
2559 Generate several move instructions to store LEN bytes of block TO. (A MEM
2560 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2563 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2564 unsigned int align ATTRIBUTE_UNUSED
)
2566 enum machine_mode to_addr_mode
= get_address_mode (data
->to
);
2567 rtx to_addr
= XEXP (data
->to
, 0);
2568 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2569 enum insn_code icode
;
2572 data
->to_addr
= to_addr
;
2574 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2575 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2577 data
->explicit_inc_to
= 0;
2579 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2581 data
->offset
= data
->len
;
2583 /* If storing requires more than two move insns,
2584 copy addresses to registers (to make displacements shorter)
2585 and use post-increment if available. */
2586 if (!data
->autinc_to
2587 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2589 /* Determine the main mode we'll be using.
2590 MODE might not be used depending on the definitions of the
2591 USE_* macros below. */
2592 enum machine_mode mode ATTRIBUTE_UNUSED
2593 = widest_int_mode_for_size (max_size
);
2595 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2597 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2598 plus_constant (to_addr_mode
,
2601 data
->autinc_to
= 1;
2602 data
->explicit_inc_to
= -1;
2605 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2606 && ! data
->autinc_to
)
2608 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2609 data
->autinc_to
= 1;
2610 data
->explicit_inc_to
= 1;
2613 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2614 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2617 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2619 /* First store what we can in the largest integer mode, then go to
2620 successively smaller modes. */
2622 while (max_size
> 1 && data
->len
> 0)
2624 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2626 if (mode
== VOIDmode
)
2629 icode
= optab_handler (mov_optab
, mode
);
2630 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2631 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2633 max_size
= GET_MODE_SIZE (mode
);
2636 /* The code above should have handled everything. */
2637 gcc_assert (!data
->len
);
2640 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2641 with move instructions for mode MODE. GENFUN is the gen_... function
2642 to make a move insn for that mode. DATA has all the other info. */
2645 store_by_pieces_2 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
2646 struct store_by_pieces_d
*data
)
2648 unsigned int size
= GET_MODE_SIZE (mode
);
2651 while (data
->len
>= size
)
2654 data
->offset
-= size
;
2656 if (data
->autinc_to
)
2657 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2660 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2662 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2663 emit_insn (gen_add2_insn (data
->to_addr
,
2664 GEN_INT (-(HOST_WIDE_INT
) size
)));
2666 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2667 emit_insn ((*genfun
) (to1
, cst
));
2669 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2670 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
2672 if (! data
->reverse
)
2673 data
->offset
+= size
;
2679 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2680 its length in bytes. */
2683 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2684 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2686 enum machine_mode mode
= GET_MODE (object
);
2689 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2691 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2692 just move a zero. Otherwise, do this a piece at a time. */
2694 && CONST_INT_P (size
)
2695 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2697 rtx zero
= CONST0_RTX (mode
);
2700 emit_move_insn (object
, zero
);
2704 if (COMPLEX_MODE_P (mode
))
2706 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2709 write_complex_part (object
, zero
, 0);
2710 write_complex_part (object
, zero
, 1);
2716 if (size
== const0_rtx
)
2719 align
= MEM_ALIGN (object
);
2721 if (CONST_INT_P (size
)
2722 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2723 clear_by_pieces (object
, INTVAL (size
), align
);
2724 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2725 expected_align
, expected_size
))
2727 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2728 return set_storage_via_libcall (object
, size
, const0_rtx
,
2729 method
== BLOCK_OP_TAILCALL
);
2737 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2739 return clear_storage_hints (object
, size
, method
, 0, -1);
2743 /* A subroutine of clear_storage. Expand a call to memset.
2744 Return the return value of memset, 0 otherwise. */
2747 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2749 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2750 enum machine_mode size_mode
;
2753 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2754 place those into new pseudos into a VAR_DECL and use them later. */
2756 object
= copy_addr_to_reg (XEXP (object
, 0));
2758 size_mode
= TYPE_MODE (sizetype
);
2759 size
= convert_to_mode (size_mode
, size
, 1);
2760 size
= copy_to_mode_reg (size_mode
, size
);
2762 /* It is incorrect to use the libcall calling conventions to call
2763 memset in this context. This could be a user call to memset and
2764 the user may wish to examine the return value from memset. For
2765 targets where libcalls and normal calls have different conventions
2766 for returning pointers, we could end up generating incorrect code. */
2768 object_tree
= make_tree (ptr_type_node
, object
);
2769 if (!CONST_INT_P (val
))
2770 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2771 size_tree
= make_tree (sizetype
, size
);
2772 val_tree
= make_tree (integer_type_node
, val
);
2774 fn
= clear_storage_libcall_fn (true);
2775 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2776 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2778 retval
= expand_normal (call_expr
);
2783 /* A subroutine of set_storage_via_libcall. Create the tree node
2784 for the function we use for block clears. */
2786 tree block_clear_fn
;
2789 init_block_clear_fn (const char *asmspec
)
2791 if (!block_clear_fn
)
2795 fn
= get_identifier ("memset");
2796 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2797 integer_type_node
, sizetype
,
2800 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2801 DECL_EXTERNAL (fn
) = 1;
2802 TREE_PUBLIC (fn
) = 1;
2803 DECL_ARTIFICIAL (fn
) = 1;
2804 TREE_NOTHROW (fn
) = 1;
2805 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2806 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2808 block_clear_fn
= fn
;
2812 set_user_assembler_name (block_clear_fn
, asmspec
);
2816 clear_storage_libcall_fn (int for_call
)
2818 static bool emitted_extern
;
2820 if (!block_clear_fn
)
2821 init_block_clear_fn (NULL
);
2823 if (for_call
&& !emitted_extern
)
2825 emitted_extern
= true;
2826 make_decl_rtl (block_clear_fn
);
2829 return block_clear_fn
;
2832 /* Expand a setmem pattern; return true if successful. */
2835 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2836 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2838 /* Try the most limited insn first, because there's no point
2839 including more than one in the machine description unless
2840 the more limited one has some advantage. */
2842 enum machine_mode mode
;
2844 if (expected_align
< align
)
2845 expected_align
= align
;
2847 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2848 mode
= GET_MODE_WIDER_MODE (mode
))
2850 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2852 if (code
!= CODE_FOR_nothing
2853 /* We don't need MODE to be narrower than
2854 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2855 the mode mask, as it is returned by the macro, it will
2856 definitely be less than the actual mode mask. */
2857 && ((CONST_INT_P (size
)
2858 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2859 <= (GET_MODE_MASK (mode
) >> 1)))
2860 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
2862 struct expand_operand ops
[6];
2865 nops
= insn_data
[(int) code
].n_generator_args
;
2866 gcc_assert (nops
== 4 || nops
== 6);
2868 create_fixed_operand (&ops
[0], object
);
2869 /* The check above guarantees that this size conversion is valid. */
2870 create_convert_operand_to (&ops
[1], size
, mode
, true);
2871 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2872 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2875 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2876 create_integer_operand (&ops
[5], expected_size
);
2878 if (maybe_expand_insn (code
, nops
, ops
))
2887 /* Write to one of the components of the complex value CPLX. Write VAL to
2888 the real part if IMAG_P is false, and the imaginary part if its true. */
2891 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2893 enum machine_mode cmode
;
2894 enum machine_mode imode
;
2897 if (GET_CODE (cplx
) == CONCAT
)
2899 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2903 cmode
= GET_MODE (cplx
);
2904 imode
= GET_MODE_INNER (cmode
);
2905 ibitsize
= GET_MODE_BITSIZE (imode
);
2907 /* For MEMs simplify_gen_subreg may generate an invalid new address
2908 because, e.g., the original address is considered mode-dependent
2909 by the target, which restricts simplify_subreg from invoking
2910 adjust_address_nv. Instead of preparing fallback support for an
2911 invalid address, we call adjust_address_nv directly. */
2914 emit_move_insn (adjust_address_nv (cplx
, imode
,
2915 imag_p
? GET_MODE_SIZE (imode
) : 0),
2920 /* If the sub-object is at least word sized, then we know that subregging
2921 will work. This special case is important, since store_bit_field
2922 wants to operate on integer modes, and there's rarely an OImode to
2923 correspond to TCmode. */
2924 if (ibitsize
>= BITS_PER_WORD
2925 /* For hard regs we have exact predicates. Assume we can split
2926 the original object if it spans an even number of hard regs.
2927 This special case is important for SCmode on 64-bit platforms
2928 where the natural size of floating-point regs is 32-bit. */
2930 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2931 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2933 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
2934 imag_p
? GET_MODE_SIZE (imode
) : 0);
2937 emit_move_insn (part
, val
);
2941 /* simplify_gen_subreg may fail for sub-word MEMs. */
2942 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2945 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
2948 /* Extract one of the components of the complex value CPLX. Extract the
2949 real part if IMAG_P is false, and the imaginary part if it's true. */
2952 read_complex_part (rtx cplx
, bool imag_p
)
2954 enum machine_mode cmode
, imode
;
2957 if (GET_CODE (cplx
) == CONCAT
)
2958 return XEXP (cplx
, imag_p
);
2960 cmode
= GET_MODE (cplx
);
2961 imode
= GET_MODE_INNER (cmode
);
2962 ibitsize
= GET_MODE_BITSIZE (imode
);
2964 /* Special case reads from complex constants that got spilled to memory. */
2965 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
2967 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
2968 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
2970 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
2971 if (CONSTANT_CLASS_P (part
))
2972 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
2976 /* For MEMs simplify_gen_subreg may generate an invalid new address
2977 because, e.g., the original address is considered mode-dependent
2978 by the target, which restricts simplify_subreg from invoking
2979 adjust_address_nv. Instead of preparing fallback support for an
2980 invalid address, we call adjust_address_nv directly. */
2982 return adjust_address_nv (cplx
, imode
,
2983 imag_p
? GET_MODE_SIZE (imode
) : 0);
2985 /* If the sub-object is at least word sized, then we know that subregging
2986 will work. This special case is important, since extract_bit_field
2987 wants to operate on integer modes, and there's rarely an OImode to
2988 correspond to TCmode. */
2989 if (ibitsize
>= BITS_PER_WORD
2990 /* For hard regs we have exact predicates. Assume we can split
2991 the original object if it spans an even number of hard regs.
2992 This special case is important for SCmode on 64-bit platforms
2993 where the natural size of floating-point regs is 32-bit. */
2995 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2996 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2998 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
2999 imag_p
? GET_MODE_SIZE (imode
) : 0);
3003 /* simplify_gen_subreg may fail for sub-word MEMs. */
3004 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3007 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3008 true, false, NULL_RTX
, imode
, imode
);
3011 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3012 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3013 represented in NEW_MODE. If FORCE is true, this will never happen, as
3014 we'll force-create a SUBREG if needed. */
3017 emit_move_change_mode (enum machine_mode new_mode
,
3018 enum machine_mode old_mode
, rtx x
, bool force
)
3022 if (push_operand (x
, GET_MODE (x
)))
3024 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3025 MEM_COPY_ATTRIBUTES (ret
, x
);
3029 /* We don't have to worry about changing the address since the
3030 size in bytes is supposed to be the same. */
3031 if (reload_in_progress
)
3033 /* Copy the MEM to change the mode and move any
3034 substitutions from the old MEM to the new one. */
3035 ret
= adjust_address_nv (x
, new_mode
, 0);
3036 copy_replacements (x
, ret
);
3039 ret
= adjust_address (x
, new_mode
, 0);
3043 /* Note that we do want simplify_subreg's behavior of validating
3044 that the new mode is ok for a hard register. If we were to use
3045 simplify_gen_subreg, we would create the subreg, but would
3046 probably run into the target not being able to implement it. */
3047 /* Except, of course, when FORCE is true, when this is exactly what
3048 we want. Which is needed for CCmodes on some targets. */
3050 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3052 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3058 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3059 an integer mode of the same size as MODE. Returns the instruction
3060 emitted, or NULL if such a move could not be generated. */
3063 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3065 enum machine_mode imode
;
3066 enum insn_code code
;
3068 /* There must exist a mode of the exact size we require. */
3069 imode
= int_mode_for_mode (mode
);
3070 if (imode
== BLKmode
)
3073 /* The target must support moves in this mode. */
3074 code
= optab_handler (mov_optab
, imode
);
3075 if (code
== CODE_FOR_nothing
)
3078 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3081 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3084 return emit_insn (GEN_FCN (code
) (x
, y
));
3087 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3088 Return an equivalent MEM that does not use an auto-increment. */
3091 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3093 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3094 HOST_WIDE_INT adjust
;
3097 adjust
= GET_MODE_SIZE (mode
);
3098 #ifdef PUSH_ROUNDING
3099 adjust
= PUSH_ROUNDING (adjust
);
3101 if (code
== PRE_DEC
|| code
== POST_DEC
)
3103 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3105 rtx expr
= XEXP (XEXP (x
, 0), 1);
3108 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3109 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3110 val
= INTVAL (XEXP (expr
, 1));
3111 if (GET_CODE (expr
) == MINUS
)
3113 gcc_assert (adjust
== val
|| adjust
== -val
);
3117 /* Do not use anti_adjust_stack, since we don't want to update
3118 stack_pointer_delta. */
3119 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3120 GEN_INT (adjust
), stack_pointer_rtx
,
3121 0, OPTAB_LIB_WIDEN
);
3122 if (temp
!= stack_pointer_rtx
)
3123 emit_move_insn (stack_pointer_rtx
, temp
);
3130 temp
= stack_pointer_rtx
;
3135 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3141 return replace_equiv_address (x
, temp
);
3144 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3145 X is known to satisfy push_operand, and MODE is known to be complex.
3146 Returns the last instruction emitted. */
3149 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3151 enum machine_mode submode
= GET_MODE_INNER (mode
);
3154 #ifdef PUSH_ROUNDING
3155 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3157 /* In case we output to the stack, but the size is smaller than the
3158 machine can push exactly, we need to use move instructions. */
3159 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3161 x
= emit_move_resolve_push (mode
, x
);
3162 return emit_move_insn (x
, y
);
3166 /* Note that the real part always precedes the imag part in memory
3167 regardless of machine's endianness. */
3168 switch (GET_CODE (XEXP (x
, 0)))
3182 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3183 read_complex_part (y
, imag_first
));
3184 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3185 read_complex_part (y
, !imag_first
));
3188 /* A subroutine of emit_move_complex. Perform the move from Y to X
3189 via two moves of the parts. Returns the last instruction emitted. */
3192 emit_move_complex_parts (rtx x
, rtx y
)
3194 /* Show the output dies here. This is necessary for SUBREGs
3195 of pseudos since we cannot track their lifetimes correctly;
3196 hard regs shouldn't appear here except as return values. */
3197 if (!reload_completed
&& !reload_in_progress
3198 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3201 write_complex_part (x
, read_complex_part (y
, false), false);
3202 write_complex_part (x
, read_complex_part (y
, true), true);
3204 return get_last_insn ();
3207 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3208 MODE is known to be complex. Returns the last instruction emitted. */
3211 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3215 /* Need to take special care for pushes, to maintain proper ordering
3216 of the data, and possibly extra padding. */
3217 if (push_operand (x
, mode
))
3218 return emit_move_complex_push (mode
, x
, y
);
3220 /* See if we can coerce the target into moving both values at once. */
3222 /* Move floating point as parts. */
3223 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3224 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
)
3226 /* Not possible if the values are inherently not adjacent. */
3227 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3229 /* Is possible if both are registers (or subregs of registers). */
3230 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3232 /* If one of the operands is a memory, and alignment constraints
3233 are friendly enough, we may be able to do combined memory operations.
3234 We do not attempt this if Y is a constant because that combination is
3235 usually better with the by-parts thing below. */
3236 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3237 && (!STRICT_ALIGNMENT
3238 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3247 /* For memory to memory moves, optimal behavior can be had with the
3248 existing block move logic. */
3249 if (MEM_P (x
) && MEM_P (y
))
3251 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3252 BLOCK_OP_NO_LIBCALL
);
3253 return get_last_insn ();
3256 ret
= emit_move_via_integer (mode
, x
, y
, true);
3261 return emit_move_complex_parts (x
, y
);
3264 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3265 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3268 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3272 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3275 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3276 if (code
!= CODE_FOR_nothing
)
3278 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3279 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3280 return emit_insn (GEN_FCN (code
) (x
, y
));
3284 /* Otherwise, find the MODE_INT mode of the same width. */
3285 ret
= emit_move_via_integer (mode
, x
, y
, false);
3286 gcc_assert (ret
!= NULL
);
3290 /* Return true if word I of OP lies entirely in the
3291 undefined bits of a paradoxical subreg. */
3294 undefined_operand_subword_p (const_rtx op
, int i
)
3296 enum machine_mode innermode
, innermostmode
;
3298 if (GET_CODE (op
) != SUBREG
)
3300 innermode
= GET_MODE (op
);
3301 innermostmode
= GET_MODE (SUBREG_REG (op
));
3302 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3303 /* The SUBREG_BYTE represents offset, as if the value were stored in
3304 memory, except for a paradoxical subreg where we define
3305 SUBREG_BYTE to be 0; undo this exception as in
3307 if (SUBREG_BYTE (op
) == 0
3308 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3310 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3311 if (WORDS_BIG_ENDIAN
)
3312 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3313 if (BYTES_BIG_ENDIAN
)
3314 offset
+= difference
% UNITS_PER_WORD
;
3316 if (offset
>= GET_MODE_SIZE (innermostmode
)
3317 || offset
<= -GET_MODE_SIZE (word_mode
))
3322 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3323 MODE is any multi-word or full-word mode that lacks a move_insn
3324 pattern. Note that you will get better code if you define such
3325 patterns, even if they must turn into multiple assembler instructions. */
3328 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3335 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3337 /* If X is a push on the stack, do the push now and replace
3338 X with a reference to the stack pointer. */
3339 if (push_operand (x
, mode
))
3340 x
= emit_move_resolve_push (mode
, x
);
3342 /* If we are in reload, see if either operand is a MEM whose address
3343 is scheduled for replacement. */
3344 if (reload_in_progress
&& MEM_P (x
)
3345 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3346 x
= replace_equiv_address_nv (x
, inner
);
3347 if (reload_in_progress
&& MEM_P (y
)
3348 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3349 y
= replace_equiv_address_nv (y
, inner
);
3353 need_clobber
= false;
3355 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3358 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3361 /* Do not generate code for a move if it would come entirely
3362 from the undefined bits of a paradoxical subreg. */
3363 if (undefined_operand_subword_p (y
, i
))
3366 ypart
= operand_subword (y
, i
, 1, mode
);
3368 /* If we can't get a part of Y, put Y into memory if it is a
3369 constant. Otherwise, force it into a register. Then we must
3370 be able to get a part of Y. */
3371 if (ypart
== 0 && CONSTANT_P (y
))
3373 y
= use_anchored_address (force_const_mem (mode
, y
));
3374 ypart
= operand_subword (y
, i
, 1, mode
);
3376 else if (ypart
== 0)
3377 ypart
= operand_subword_force (y
, i
, mode
);
3379 gcc_assert (xpart
&& ypart
);
3381 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3383 last_insn
= emit_move_insn (xpart
, ypart
);
3389 /* Show the output dies here. This is necessary for SUBREGs
3390 of pseudos since we cannot track their lifetimes correctly;
3391 hard regs shouldn't appear here except as return values.
3392 We never want to emit such a clobber after reload. */
3394 && ! (reload_in_progress
|| reload_completed
)
3395 && need_clobber
!= 0)
3403 /* Low level part of emit_move_insn.
3404 Called just like emit_move_insn, but assumes X and Y
3405 are basically valid. */
3408 emit_move_insn_1 (rtx x
, rtx y
)
3410 enum machine_mode mode
= GET_MODE (x
);
3411 enum insn_code code
;
3413 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3415 code
= optab_handler (mov_optab
, mode
);
3416 if (code
!= CODE_FOR_nothing
)
3417 return emit_insn (GEN_FCN (code
) (x
, y
));
3419 /* Expand complex moves by moving real part and imag part. */
3420 if (COMPLEX_MODE_P (mode
))
3421 return emit_move_complex (mode
, x
, y
);
3423 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3424 || ALL_FIXED_POINT_MODE_P (mode
))
3426 rtx result
= emit_move_via_integer (mode
, x
, y
, true);
3428 /* If we can't find an integer mode, use multi words. */
3432 return emit_move_multi_word (mode
, x
, y
);
3435 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3436 return emit_move_ccmode (mode
, x
, y
);
3438 /* Try using a move pattern for the corresponding integer mode. This is
3439 only safe when simplify_subreg can convert MODE constants into integer
3440 constants. At present, it can only do this reliably if the value
3441 fits within a HOST_WIDE_INT. */
3442 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3444 rtx ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3448 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3453 return emit_move_multi_word (mode
, x
, y
);
3456 /* Generate code to copy Y into X.
3457 Both Y and X must have the same mode, except that
3458 Y can be a constant with VOIDmode.
3459 This mode cannot be BLKmode; use emit_block_move for that.
3461 Return the last instruction emitted. */
3464 emit_move_insn (rtx x
, rtx y
)
3466 enum machine_mode mode
= GET_MODE (x
);
3467 rtx y_cst
= NULL_RTX
;
3470 gcc_assert (mode
!= BLKmode
3471 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3476 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3477 && (last_insn
= compress_float_constant (x
, y
)))
3482 if (!targetm
.legitimate_constant_p (mode
, y
))
3484 y
= force_const_mem (mode
, y
);
3486 /* If the target's cannot_force_const_mem prevented the spill,
3487 assume that the target's move expanders will also take care
3488 of the non-legitimate constant. */
3492 y
= use_anchored_address (y
);
3496 /* If X or Y are memory references, verify that their addresses are valid
3499 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3501 && ! push_operand (x
, GET_MODE (x
))))
3502 x
= validize_mem (x
);
3505 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3506 MEM_ADDR_SPACE (y
)))
3507 y
= validize_mem (y
);
3509 gcc_assert (mode
!= BLKmode
);
3511 last_insn
= emit_move_insn_1 (x
, y
);
3513 if (y_cst
&& REG_P (x
)
3514 && (set
= single_set (last_insn
)) != NULL_RTX
3515 && SET_DEST (set
) == x
3516 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3517 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3522 /* If Y is representable exactly in a narrower mode, and the target can
3523 perform the extension directly from constant or memory, then emit the
3524 move as an extension. */
3527 compress_float_constant (rtx x
, rtx y
)
3529 enum machine_mode dstmode
= GET_MODE (x
);
3530 enum machine_mode orig_srcmode
= GET_MODE (y
);
3531 enum machine_mode srcmode
;
3533 int oldcost
, newcost
;
3534 bool speed
= optimize_insn_for_speed_p ();
3536 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3538 if (targetm
.legitimate_constant_p (dstmode
, y
))
3539 oldcost
= set_src_cost (y
, speed
);
3541 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3543 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3544 srcmode
!= orig_srcmode
;
3545 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3548 rtx trunc_y
, last_insn
;
3550 /* Skip if the target can't extend this way. */
3551 ic
= can_extend_p (dstmode
, srcmode
, 0);
3552 if (ic
== CODE_FOR_nothing
)
3555 /* Skip if the narrowed value isn't exact. */
3556 if (! exact_real_truncate (srcmode
, &r
))
3559 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3561 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3563 /* Skip if the target needs extra instructions to perform
3565 if (!insn_operand_matches (ic
, 1, trunc_y
))
3567 /* This is valid, but may not be cheaper than the original. */
3568 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3570 if (oldcost
< newcost
)
3573 else if (float_extend_from_mem
[dstmode
][srcmode
])
3575 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3576 /* This is valid, but may not be cheaper than the original. */
3577 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3579 if (oldcost
< newcost
)
3581 trunc_y
= validize_mem (trunc_y
);
3586 /* For CSE's benefit, force the compressed constant pool entry
3587 into a new pseudo. This constant may be used in different modes,
3588 and if not, combine will put things back together for us. */
3589 trunc_y
= force_reg (srcmode
, trunc_y
);
3590 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3591 last_insn
= get_last_insn ();
3594 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3602 /* Pushing data onto the stack. */
3604 /* Push a block of length SIZE (perhaps variable)
3605 and return an rtx to address the beginning of the block.
3606 The value may be virtual_outgoing_args_rtx.
3608 EXTRA is the number of bytes of padding to push in addition to SIZE.
3609 BELOW nonzero means this padding comes at low addresses;
3610 otherwise, the padding comes at high addresses. */
3613 push_block (rtx size
, int extra
, int below
)
3617 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3618 if (CONSTANT_P (size
))
3619 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3620 else if (REG_P (size
) && extra
== 0)
3621 anti_adjust_stack (size
);
3624 temp
= copy_to_mode_reg (Pmode
, size
);
3626 temp
= expand_binop (Pmode
, add_optab
, temp
, GEN_INT (extra
),
3627 temp
, 0, OPTAB_LIB_WIDEN
);
3628 anti_adjust_stack (temp
);
3631 #ifndef STACK_GROWS_DOWNWARD
3637 temp
= virtual_outgoing_args_rtx
;
3638 if (extra
!= 0 && below
)
3639 temp
= plus_constant (Pmode
, temp
, extra
);
3643 if (CONST_INT_P (size
))
3644 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3645 -INTVAL (size
) - (below
? 0 : extra
));
3646 else if (extra
!= 0 && !below
)
3647 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3648 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3651 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3652 negate_rtx (Pmode
, size
));
3655 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3658 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3661 mem_autoinc_base (rtx mem
)
3665 rtx addr
= XEXP (mem
, 0);
3666 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3667 return XEXP (addr
, 0);
3672 /* A utility routine used here, in reload, and in try_split. The insns
3673 after PREV up to and including LAST are known to adjust the stack,
3674 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3675 placing notes as appropriate. PREV may be NULL, indicating the
3676 entire insn sequence prior to LAST should be scanned.
3678 The set of allowed stack pointer modifications is small:
3679 (1) One or more auto-inc style memory references (aka pushes),
3680 (2) One or more addition/subtraction with the SP as destination,
3681 (3) A single move insn with the SP as destination,
3682 (4) A call_pop insn,
3683 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3685 Insns in the sequence that do not modify the SP are ignored,
3686 except for noreturn calls.
3688 The return value is the amount of adjustment that can be trivially
3689 verified, via immediate operand or auto-inc. If the adjustment
3690 cannot be trivially extracted, the return value is INT_MIN. */
3693 find_args_size_adjust (rtx insn
)
3698 pat
= PATTERN (insn
);
3701 /* Look for a call_pop pattern. */
3704 /* We have to allow non-call_pop patterns for the case
3705 of emit_single_push_insn of a TLS address. */
3706 if (GET_CODE (pat
) != PARALLEL
)
3709 /* All call_pop have a stack pointer adjust in the parallel.
3710 The call itself is always first, and the stack adjust is
3711 usually last, so search from the end. */
3712 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3714 set
= XVECEXP (pat
, 0, i
);
3715 if (GET_CODE (set
) != SET
)
3717 dest
= SET_DEST (set
);
3718 if (dest
== stack_pointer_rtx
)
3721 /* We'd better have found the stack pointer adjust. */
3724 /* Fall through to process the extracted SET and DEST
3725 as if it was a standalone insn. */
3727 else if (GET_CODE (pat
) == SET
)
3729 else if ((set
= single_set (insn
)) != NULL
)
3731 else if (GET_CODE (pat
) == PARALLEL
)
3733 /* ??? Some older ports use a parallel with a stack adjust
3734 and a store for a PUSH_ROUNDING pattern, rather than a
3735 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3736 /* ??? See h8300 and m68k, pushqi1. */
3737 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3739 set
= XVECEXP (pat
, 0, i
);
3740 if (GET_CODE (set
) != SET
)
3742 dest
= SET_DEST (set
);
3743 if (dest
== stack_pointer_rtx
)
3746 /* We do not expect an auto-inc of the sp in the parallel. */
3747 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3748 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3749 != stack_pointer_rtx
);
3757 dest
= SET_DEST (set
);
3759 /* Look for direct modifications of the stack pointer. */
3760 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3762 /* Look for a trivial adjustment, otherwise assume nothing. */
3763 /* Note that the SPU restore_stack_block pattern refers to
3764 the stack pointer in V4SImode. Consider that non-trivial. */
3765 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3766 && GET_CODE (SET_SRC (set
)) == PLUS
3767 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3768 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3769 return INTVAL (XEXP (SET_SRC (set
), 1));
3770 /* ??? Reload can generate no-op moves, which will be cleaned
3771 up later. Recognize it and continue searching. */
3772 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3775 return HOST_WIDE_INT_MIN
;
3781 /* Otherwise only think about autoinc patterns. */
3782 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3785 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3786 != stack_pointer_rtx
);
3788 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3789 mem
= SET_SRC (set
);
3793 addr
= XEXP (mem
, 0);
3794 switch (GET_CODE (addr
))
3798 return GET_MODE_SIZE (GET_MODE (mem
));
3801 return -GET_MODE_SIZE (GET_MODE (mem
));
3804 addr
= XEXP (addr
, 1);
3805 gcc_assert (GET_CODE (addr
) == PLUS
);
3806 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3807 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3808 return INTVAL (XEXP (addr
, 1));
3816 fixup_args_size_notes (rtx prev
, rtx last
, int end_args_size
)
3818 int args_size
= end_args_size
;
3819 bool saw_unknown
= false;
3822 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3824 HOST_WIDE_INT this_delta
;
3826 if (!NONDEBUG_INSN_P (insn
))
3829 this_delta
= find_args_size_adjust (insn
);
3830 if (this_delta
== 0)
3833 || ACCUMULATE_OUTGOING_ARGS
3834 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3838 gcc_assert (!saw_unknown
);
3839 if (this_delta
== HOST_WIDE_INT_MIN
)
3842 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3843 #ifdef STACK_GROWS_DOWNWARD
3844 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3846 args_size
-= this_delta
;
3849 return saw_unknown
? INT_MIN
: args_size
;
3852 #ifdef PUSH_ROUNDING
3853 /* Emit single push insn. */
3856 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3859 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3861 enum insn_code icode
;
3863 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3864 /* If there is push pattern, use it. Otherwise try old way of throwing
3865 MEM representing push operation to move expander. */
3866 icode
= optab_handler (push_optab
, mode
);
3867 if (icode
!= CODE_FOR_nothing
)
3869 struct expand_operand ops
[1];
3871 create_input_operand (&ops
[0], x
, mode
);
3872 if (maybe_expand_insn (icode
, 1, ops
))
3875 if (GET_MODE_SIZE (mode
) == rounded_size
)
3876 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3877 /* If we are to pad downward, adjust the stack pointer first and
3878 then store X into the stack location using an offset. This is
3879 because emit_move_insn does not know how to pad; it does not have
3881 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3883 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3884 HOST_WIDE_INT offset
;
3886 emit_move_insn (stack_pointer_rtx
,
3887 expand_binop (Pmode
,
3888 #ifdef STACK_GROWS_DOWNWARD
3894 GEN_INT (rounded_size
),
3895 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3897 offset
= (HOST_WIDE_INT
) padding_size
;
3898 #ifdef STACK_GROWS_DOWNWARD
3899 if (STACK_PUSH_CODE
== POST_DEC
)
3900 /* We have already decremented the stack pointer, so get the
3902 offset
+= (HOST_WIDE_INT
) rounded_size
;
3904 if (STACK_PUSH_CODE
== POST_INC
)
3905 /* We have already incremented the stack pointer, so get the
3907 offset
-= (HOST_WIDE_INT
) rounded_size
;
3909 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
3913 #ifdef STACK_GROWS_DOWNWARD
3914 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3915 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3916 GEN_INT (-(HOST_WIDE_INT
) rounded_size
));
3918 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3919 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3920 GEN_INT (rounded_size
));
3922 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
3925 dest
= gen_rtx_MEM (mode
, dest_addr
);
3929 set_mem_attributes (dest
, type
, 1);
3931 if (flag_optimize_sibling_calls
)
3932 /* Function incoming arguments may overlap with sibling call
3933 outgoing arguments and we cannot allow reordering of reads
3934 from function arguments with stores to outgoing arguments
3935 of sibling calls. */
3936 set_mem_alias_set (dest
, 0);
3938 emit_move_insn (dest
, x
);
3941 /* Emit and annotate a single push insn. */
3944 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
3946 int delta
, old_delta
= stack_pointer_delta
;
3947 rtx prev
= get_last_insn ();
3950 emit_single_push_insn_1 (mode
, x
, type
);
3952 last
= get_last_insn ();
3954 /* Notice the common case where we emitted exactly one insn. */
3955 if (PREV_INSN (last
) == prev
)
3957 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
3961 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
3962 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
3966 /* Generate code to push X onto the stack, assuming it has mode MODE and
3968 MODE is redundant except when X is a CONST_INT (since they don't
3970 SIZE is an rtx for the size of data to be copied (in bytes),
3971 needed only if X is BLKmode.
3973 ALIGN (in bits) is maximum alignment we can assume.
3975 If PARTIAL and REG are both nonzero, then copy that many of the first
3976 bytes of X into registers starting with REG, and push the rest of X.
3977 The amount of space pushed is decreased by PARTIAL bytes.
3978 REG must be a hard register in this case.
3979 If REG is zero but PARTIAL is not, take any all others actions for an
3980 argument partially in registers, but do not actually load any
3983 EXTRA is the amount in bytes of extra space to leave next to this arg.
3984 This is ignored if an argument block has already been allocated.
3986 On a machine that lacks real push insns, ARGS_ADDR is the address of
3987 the bottom of the argument block for this call. We use indexing off there
3988 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3989 argument block has not been preallocated.
3991 ARGS_SO_FAR is the size of args previously pushed for this call.
3993 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3994 for arguments passed in registers. If nonzero, it will be the number
3995 of bytes required. */
3998 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
3999 unsigned int align
, int partial
, rtx reg
, int extra
,
4000 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4004 enum direction stack_direction
4005 #ifdef STACK_GROWS_DOWNWARD
4011 /* Decide where to pad the argument: `downward' for below,
4012 `upward' for above, or `none' for don't pad it.
4013 Default is below for small data on big-endian machines; else above. */
4014 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4016 /* Invert direction if stack is post-decrement.
4018 if (STACK_PUSH_CODE
== POST_DEC
)
4019 if (where_pad
!= none
)
4020 where_pad
= (where_pad
== downward
? upward
: downward
);
4025 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4027 /* Copy a block into the stack, entirely or partially. */
4034 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4035 used
= partial
- offset
;
4037 if (mode
!= BLKmode
)
4039 /* A value is to be stored in an insufficiently aligned
4040 stack slot; copy via a suitably aligned slot if
4042 size
= GEN_INT (GET_MODE_SIZE (mode
));
4043 if (!MEM_P (xinner
))
4045 temp
= assign_temp (type
, 1, 1);
4046 emit_move_insn (temp
, xinner
);
4053 /* USED is now the # of bytes we need not copy to the stack
4054 because registers will take care of them. */
4057 xinner
= adjust_address (xinner
, BLKmode
, used
);
4059 /* If the partial register-part of the arg counts in its stack size,
4060 skip the part of stack space corresponding to the registers.
4061 Otherwise, start copying to the beginning of the stack space,
4062 by setting SKIP to 0. */
4063 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4065 #ifdef PUSH_ROUNDING
4066 /* Do it with several push insns if that doesn't take lots of insns
4067 and if there is no difficulty with push insns that skip bytes
4068 on the stack for alignment purposes. */
4071 && CONST_INT_P (size
)
4073 && MEM_ALIGN (xinner
) >= align
4074 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4075 /* Here we avoid the case of a structure whose weak alignment
4076 forces many pushes of a small amount of data,
4077 and such small pushes do rounding that causes trouble. */
4078 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4079 || align
>= BIGGEST_ALIGNMENT
4080 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4081 == (align
/ BITS_PER_UNIT
)))
4082 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4084 /* Push padding now if padding above and stack grows down,
4085 or if padding below and stack grows up.
4086 But if space already allocated, this has already been done. */
4087 if (extra
&& args_addr
== 0
4088 && where_pad
!= none
&& where_pad
!= stack_direction
)
4089 anti_adjust_stack (GEN_INT (extra
));
4091 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4094 #endif /* PUSH_ROUNDING */
4098 /* Otherwise make space on the stack and copy the data
4099 to the address of that space. */
4101 /* Deduct words put into registers from the size we must copy. */
4104 if (CONST_INT_P (size
))
4105 size
= GEN_INT (INTVAL (size
) - used
);
4107 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4108 GEN_INT (used
), NULL_RTX
, 0,
4112 /* Get the address of the stack space.
4113 In this case, we do not deal with EXTRA separately.
4114 A single stack adjust will do. */
4117 temp
= push_block (size
, extra
, where_pad
== downward
);
4120 else if (CONST_INT_P (args_so_far
))
4121 temp
= memory_address (BLKmode
,
4122 plus_constant (Pmode
, args_addr
,
4123 skip
+ INTVAL (args_so_far
)));
4125 temp
= memory_address (BLKmode
,
4126 plus_constant (Pmode
,
4127 gen_rtx_PLUS (Pmode
,
4132 if (!ACCUMULATE_OUTGOING_ARGS
)
4134 /* If the source is referenced relative to the stack pointer,
4135 copy it to another register to stabilize it. We do not need
4136 to do this if we know that we won't be changing sp. */
4138 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4139 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4140 temp
= copy_to_reg (temp
);
4143 target
= gen_rtx_MEM (BLKmode
, temp
);
4145 /* We do *not* set_mem_attributes here, because incoming arguments
4146 may overlap with sibling call outgoing arguments and we cannot
4147 allow reordering of reads from function arguments with stores
4148 to outgoing arguments of sibling calls. We do, however, want
4149 to record the alignment of the stack slot. */
4150 /* ALIGN may well be better aligned than TYPE, e.g. due to
4151 PARM_BOUNDARY. Assume the caller isn't lying. */
4152 set_mem_align (target
, align
);
4154 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4157 else if (partial
> 0)
4159 /* Scalar partly in registers. */
4161 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4164 /* # bytes of start of argument
4165 that we must make space for but need not store. */
4166 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4167 int args_offset
= INTVAL (args_so_far
);
4170 /* Push padding now if padding above and stack grows down,
4171 or if padding below and stack grows up.
4172 But if space already allocated, this has already been done. */
4173 if (extra
&& args_addr
== 0
4174 && where_pad
!= none
&& where_pad
!= stack_direction
)
4175 anti_adjust_stack (GEN_INT (extra
));
4177 /* If we make space by pushing it, we might as well push
4178 the real data. Otherwise, we can leave OFFSET nonzero
4179 and leave the space uninitialized. */
4183 /* Now NOT_STACK gets the number of words that we don't need to
4184 allocate on the stack. Convert OFFSET to words too. */
4185 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4186 offset
/= UNITS_PER_WORD
;
4188 /* If the partial register-part of the arg counts in its stack size,
4189 skip the part of stack space corresponding to the registers.
4190 Otherwise, start copying to the beginning of the stack space,
4191 by setting SKIP to 0. */
4192 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4194 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4195 x
= validize_mem (force_const_mem (mode
, x
));
4197 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4198 SUBREGs of such registers are not allowed. */
4199 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4200 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4201 x
= copy_to_reg (x
);
4203 /* Loop over all the words allocated on the stack for this arg. */
4204 /* We can do it by words, because any scalar bigger than a word
4205 has a size a multiple of a word. */
4206 #ifndef PUSH_ARGS_REVERSED
4207 for (i
= not_stack
; i
< size
; i
++)
4209 for (i
= size
- 1; i
>= not_stack
; i
--)
4211 if (i
>= not_stack
+ offset
)
4212 emit_push_insn (operand_subword_force (x
, i
, mode
),
4213 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4215 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4217 reg_parm_stack_space
, alignment_pad
);
4224 /* Push padding now if padding above and stack grows down,
4225 or if padding below and stack grows up.
4226 But if space already allocated, this has already been done. */
4227 if (extra
&& args_addr
== 0
4228 && where_pad
!= none
&& where_pad
!= stack_direction
)
4229 anti_adjust_stack (GEN_INT (extra
));
4231 #ifdef PUSH_ROUNDING
4232 if (args_addr
== 0 && PUSH_ARGS
)
4233 emit_single_push_insn (mode
, x
, type
);
4237 if (CONST_INT_P (args_so_far
))
4239 = memory_address (mode
,
4240 plus_constant (Pmode
, args_addr
,
4241 INTVAL (args_so_far
)));
4243 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4245 dest
= gen_rtx_MEM (mode
, addr
);
4247 /* We do *not* set_mem_attributes here, because incoming arguments
4248 may overlap with sibling call outgoing arguments and we cannot
4249 allow reordering of reads from function arguments with stores
4250 to outgoing arguments of sibling calls. We do, however, want
4251 to record the alignment of the stack slot. */
4252 /* ALIGN may well be better aligned than TYPE, e.g. due to
4253 PARM_BOUNDARY. Assume the caller isn't lying. */
4254 set_mem_align (dest
, align
);
4256 emit_move_insn (dest
, x
);
4260 /* If part should go in registers, copy that part
4261 into the appropriate registers. Do this now, at the end,
4262 since mem-to-mem copies above may do function calls. */
4263 if (partial
> 0 && reg
!= 0)
4265 /* Handle calls that pass values in multiple non-contiguous locations.
4266 The Irix 6 ABI has examples of this. */
4267 if (GET_CODE (reg
) == PARALLEL
)
4268 emit_group_load (reg
, x
, type
, -1);
4271 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4272 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4276 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4277 anti_adjust_stack (GEN_INT (extra
));
4279 if (alignment_pad
&& args_addr
== 0)
4280 anti_adjust_stack (alignment_pad
);
4283 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4287 get_subtarget (rtx x
)
4291 /* Only registers can be subtargets. */
4293 /* Don't use hard regs to avoid extending their life. */
4294 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4298 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4299 FIELD is a bitfield. Returns true if the optimization was successful,
4300 and there's nothing else to do. */
4303 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4304 unsigned HOST_WIDE_INT bitpos
,
4305 unsigned HOST_WIDE_INT bitregion_start
,
4306 unsigned HOST_WIDE_INT bitregion_end
,
4307 enum machine_mode mode1
, rtx str_rtx
,
4310 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4311 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4316 enum tree_code code
;
4318 if (mode1
!= VOIDmode
4319 || bitsize
>= BITS_PER_WORD
4320 || str_bitsize
> BITS_PER_WORD
4321 || TREE_SIDE_EFFECTS (to
)
4322 || TREE_THIS_VOLATILE (to
))
4326 if (TREE_CODE (src
) != SSA_NAME
)
4328 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4331 srcstmt
= get_gimple_for_ssa_name (src
);
4333 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4336 code
= gimple_assign_rhs_code (srcstmt
);
4338 op0
= gimple_assign_rhs1 (srcstmt
);
4340 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4341 to find its initialization. Hopefully the initialization will
4342 be from a bitfield load. */
4343 if (TREE_CODE (op0
) == SSA_NAME
)
4345 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4347 /* We want to eventually have OP0 be the same as TO, which
4348 should be a bitfield. */
4350 || !is_gimple_assign (op0stmt
)
4351 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4353 op0
= gimple_assign_rhs1 (op0stmt
);
4356 op1
= gimple_assign_rhs2 (srcstmt
);
4358 if (!operand_equal_p (to
, op0
, 0))
4361 if (MEM_P (str_rtx
))
4363 unsigned HOST_WIDE_INT offset1
;
4365 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4366 str_mode
= word_mode
;
4367 str_mode
= get_best_mode (bitsize
, bitpos
,
4368 bitregion_start
, bitregion_end
,
4369 MEM_ALIGN (str_rtx
), str_mode
, 0);
4370 if (str_mode
== VOIDmode
)
4372 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4375 bitpos
%= str_bitsize
;
4376 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4377 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4379 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4382 /* If the bit field covers the whole REG/MEM, store_field
4383 will likely generate better code. */
4384 if (bitsize
>= str_bitsize
)
4387 /* We can't handle fields split across multiple entities. */
4388 if (bitpos
+ bitsize
> str_bitsize
)
4391 if (BYTES_BIG_ENDIAN
)
4392 bitpos
= str_bitsize
- bitpos
- bitsize
;
4398 /* For now, just optimize the case of the topmost bitfield
4399 where we don't need to do any masking and also
4400 1 bit bitfields where xor can be used.
4401 We might win by one instruction for the other bitfields
4402 too if insv/extv instructions aren't used, so that
4403 can be added later. */
4404 if (bitpos
+ bitsize
!= str_bitsize
4405 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4408 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4409 value
= convert_modes (str_mode
,
4410 TYPE_MODE (TREE_TYPE (op1
)), value
,
4411 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4413 /* We may be accessing data outside the field, which means
4414 we can alias adjacent data. */
4415 if (MEM_P (str_rtx
))
4417 str_rtx
= shallow_copy_rtx (str_rtx
);
4418 set_mem_alias_set (str_rtx
, 0);
4419 set_mem_expr (str_rtx
, 0);
4422 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4423 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4425 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4428 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4429 result
= expand_binop (str_mode
, binop
, str_rtx
,
4430 value
, str_rtx
, 1, OPTAB_WIDEN
);
4431 if (result
!= str_rtx
)
4432 emit_move_insn (str_rtx
, result
);
4437 if (TREE_CODE (op1
) != INTEGER_CST
)
4439 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4440 value
= convert_modes (str_mode
,
4441 TYPE_MODE (TREE_TYPE (op1
)), value
,
4442 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4444 /* We may be accessing data outside the field, which means
4445 we can alias adjacent data. */
4446 if (MEM_P (str_rtx
))
4448 str_rtx
= shallow_copy_rtx (str_rtx
);
4449 set_mem_alias_set (str_rtx
, 0);
4450 set_mem_expr (str_rtx
, 0);
4453 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4454 if (bitpos
+ bitsize
!= str_bitsize
)
4456 rtx mask
= GEN_INT (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1);
4457 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4459 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4460 result
= expand_binop (str_mode
, binop
, str_rtx
,
4461 value
, str_rtx
, 1, OPTAB_WIDEN
);
4462 if (result
!= str_rtx
)
4463 emit_move_insn (str_rtx
, result
);
4473 /* In the C++ memory model, consecutive bit fields in a structure are
4474 considered one memory location.
4476 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4477 returns the bit range of consecutive bits in which this COMPONENT_REF
4478 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4479 and *OFFSET may be adjusted in the process.
4481 If the access does not need to be restricted, 0 is returned in both
4482 *BITSTART and *BITEND. */
4485 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4486 unsigned HOST_WIDE_INT
*bitend
,
4488 HOST_WIDE_INT
*bitpos
,
4491 HOST_WIDE_INT bitoffset
;
4494 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4496 field
= TREE_OPERAND (exp
, 1);
4497 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4498 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4499 need to limit the range we can access. */
4502 *bitstart
= *bitend
= 0;
4506 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4507 part of a larger bit field, then the representative does not serve any
4508 useful purpose. This can occur in Ada. */
4509 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4511 enum machine_mode rmode
;
4512 HOST_WIDE_INT rbitsize
, rbitpos
;
4516 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4517 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4518 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4520 *bitstart
= *bitend
= 0;
4525 /* Compute the adjustment to bitpos from the offset of the field
4526 relative to the representative. DECL_FIELD_OFFSET of field and
4527 repr are the same by construction if they are not constants,
4528 see finish_bitfield_layout. */
4529 if (host_integerp (DECL_FIELD_OFFSET (field
), 1)
4530 && host_integerp (DECL_FIELD_OFFSET (repr
), 1))
4531 bitoffset
= (tree_low_cst (DECL_FIELD_OFFSET (field
), 1)
4532 - tree_low_cst (DECL_FIELD_OFFSET (repr
), 1)) * BITS_PER_UNIT
;
4535 bitoffset
+= (tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 1)
4536 - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr
), 1));
4538 /* If the adjustment is larger than bitpos, we would have a negative bit
4539 position for the lower bound and this may wreak havoc later. This can
4540 occur only if we have a non-null offset, so adjust offset and bitpos
4541 to make the lower bound non-negative. */
4542 if (bitoffset
> *bitpos
)
4544 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4546 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4547 gcc_assert (*offset
!= NULL_TREE
);
4551 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4555 *bitstart
= *bitpos
- bitoffset
;
4557 *bitend
= *bitstart
+ tree_low_cst (DECL_SIZE (repr
), 1) - 1;
4560 /* Returns true if the MEM_REF REF refers to an object that does not
4561 reside in memory and has non-BLKmode. */
4564 mem_ref_refers_to_non_mem_p (tree ref
)
4566 tree base
= TREE_OPERAND (ref
, 0);
4567 if (TREE_CODE (base
) != ADDR_EXPR
)
4569 base
= TREE_OPERAND (base
, 0);
4570 return (DECL_P (base
)
4571 && !TREE_ADDRESSABLE (base
)
4572 && DECL_MODE (base
) != BLKmode
4573 && DECL_RTL_SET_P (base
)
4574 && !MEM_P (DECL_RTL (base
)));
4577 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4578 is true, try generating a nontemporal store. */
4581 expand_assignment (tree to
, tree from
, bool nontemporal
)
4585 enum machine_mode mode
;
4587 enum insn_code icode
;
4589 /* Don't crash if the lhs of the assignment was erroneous. */
4590 if (TREE_CODE (to
) == ERROR_MARK
)
4592 expand_normal (from
);
4596 /* Optimize away no-op moves without side-effects. */
4597 if (operand_equal_p (to
, from
, 0))
4600 /* Handle misaligned stores. */
4601 mode
= TYPE_MODE (TREE_TYPE (to
));
4602 if ((TREE_CODE (to
) == MEM_REF
4603 || TREE_CODE (to
) == TARGET_MEM_REF
)
4605 && !mem_ref_refers_to_non_mem_p (to
)
4606 && ((align
= get_object_alignment (to
))
4607 < GET_MODE_ALIGNMENT (mode
))
4608 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4609 != CODE_FOR_nothing
)
4610 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4614 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4615 reg
= force_not_mem (reg
);
4616 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4618 if (icode
!= CODE_FOR_nothing
)
4620 struct expand_operand ops
[2];
4622 create_fixed_operand (&ops
[0], mem
);
4623 create_input_operand (&ops
[1], reg
, mode
);
4624 /* The movmisalign<mode> pattern cannot fail, else the assignment
4625 would silently be omitted. */
4626 expand_insn (icode
, 2, ops
);
4629 store_bit_field (mem
, GET_MODE_BITSIZE (mode
),
4630 0, 0, 0, mode
, reg
);
4634 /* Assignment of a structure component needs special treatment
4635 if the structure component's rtx is not simply a MEM.
4636 Assignment of an array element at a constant index, and assignment of
4637 an array element in an unaligned packed structure field, has the same
4638 problem. Same for (partially) storing into a non-memory object. */
4639 if (handled_component_p (to
)
4640 || (TREE_CODE (to
) == MEM_REF
4641 && mem_ref_refers_to_non_mem_p (to
))
4642 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4644 enum machine_mode mode1
;
4645 HOST_WIDE_INT bitsize
, bitpos
;
4646 unsigned HOST_WIDE_INT bitregion_start
= 0;
4647 unsigned HOST_WIDE_INT bitregion_end
= 0;
4656 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4657 &unsignedp
, &volatilep
, true);
4659 if (TREE_CODE (to
) == COMPONENT_REF
4660 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4661 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4663 /* If we are going to use store_bit_field and extract_bit_field,
4664 make sure to_rtx will be safe for multiple use. */
4665 mode
= TYPE_MODE (TREE_TYPE (tem
));
4666 if (TREE_CODE (tem
) == MEM_REF
4668 && ((align
= get_object_alignment (tem
))
4669 < GET_MODE_ALIGNMENT (mode
))
4670 && ((icode
= optab_handler (movmisalign_optab
, mode
))
4671 != CODE_FOR_nothing
))
4673 struct expand_operand ops
[2];
4676 to_rtx
= gen_reg_rtx (mode
);
4677 mem
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4679 /* If the misaligned store doesn't overwrite all bits, perform
4680 rmw cycle on MEM. */
4681 if (bitsize
!= GET_MODE_BITSIZE (mode
))
4683 create_input_operand (&ops
[0], to_rtx
, mode
);
4684 create_fixed_operand (&ops
[1], mem
);
4685 /* The movmisalign<mode> pattern cannot fail, else the assignment
4686 would silently be omitted. */
4687 expand_insn (icode
, 2, ops
);
4689 mem
= copy_rtx (mem
);
4695 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4698 /* If the bitfield is volatile, we want to access it in the
4699 field's mode, not the computed mode.
4700 If a MEM has VOIDmode (external with incomplete type),
4701 use BLKmode for it instead. */
4704 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
4705 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4706 else if (GET_MODE (to_rtx
) == VOIDmode
)
4707 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4712 enum machine_mode address_mode
;
4715 if (!MEM_P (to_rtx
))
4717 /* We can get constant negative offsets into arrays with broken
4718 user code. Translate this to a trap instead of ICEing. */
4719 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4720 expand_builtin_trap ();
4721 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4724 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4725 address_mode
= get_address_mode (to_rtx
);
4726 if (GET_MODE (offset_rtx
) != address_mode
)
4727 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4729 /* A constant address in TO_RTX can have VOIDmode, we must not try
4730 to call force_reg for that case. Avoid that case. */
4732 && GET_MODE (to_rtx
) == BLKmode
4733 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
4735 && (bitpos
% bitsize
) == 0
4736 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4737 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
4739 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4743 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4744 highest_pow2_factor_for_target (to
,
4748 /* No action is needed if the target is not a memory and the field
4749 lies completely outside that target. This can occur if the source
4750 code contains an out-of-bounds access to a small array. */
4752 && GET_MODE (to_rtx
) != BLKmode
4753 && (unsigned HOST_WIDE_INT
) bitpos
4754 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4756 expand_normal (from
);
4759 /* Handle expand_expr of a complex value returning a CONCAT. */
4760 else if (GET_CODE (to_rtx
) == CONCAT
)
4762 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4763 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4765 && bitsize
== mode_bitsize
)
4766 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4767 else if (bitsize
== mode_bitsize
/ 2
4768 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4769 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4771 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4772 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4773 bitregion_start
, bitregion_end
,
4775 get_alias_set (to
), nontemporal
);
4776 else if (bitpos
>= mode_bitsize
/ 2)
4777 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4778 bitpos
- mode_bitsize
/ 2,
4779 bitregion_start
, bitregion_end
,
4781 get_alias_set (to
), nontemporal
);
4782 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4785 result
= expand_normal (from
);
4786 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4787 TYPE_MODE (TREE_TYPE (from
)), 0);
4788 emit_move_insn (XEXP (to_rtx
, 0),
4789 read_complex_part (from_rtx
, false));
4790 emit_move_insn (XEXP (to_rtx
, 1),
4791 read_complex_part (from_rtx
, true));
4795 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4796 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4797 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4798 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4799 result
= store_field (temp
, bitsize
, bitpos
,
4800 bitregion_start
, bitregion_end
,
4802 get_alias_set (to
), nontemporal
);
4803 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4804 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4811 /* If the field is at offset zero, we could have been given the
4812 DECL_RTX of the parent struct. Don't munge it. */
4813 to_rtx
= shallow_copy_rtx (to_rtx
);
4815 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4817 /* Deal with volatile and readonly fields. The former is only
4818 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4820 MEM_VOLATILE_P (to_rtx
) = 1;
4821 if (component_uses_parent_alias_set (to
))
4822 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
4825 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4826 bitregion_start
, bitregion_end
,
4831 result
= store_field (to_rtx
, bitsize
, bitpos
,
4832 bitregion_start
, bitregion_end
,
4834 get_alias_set (to
), nontemporal
);
4839 struct expand_operand ops
[2];
4841 create_fixed_operand (&ops
[0], mem
);
4842 create_input_operand (&ops
[1], to_rtx
, mode
);
4843 /* The movmisalign<mode> pattern cannot fail, else the assignment
4844 would silently be omitted. */
4845 expand_insn (icode
, 2, ops
);
4849 preserve_temp_slots (result
);
4854 /* If the rhs is a function call and its value is not an aggregate,
4855 call the function before we start to compute the lhs.
4856 This is needed for correct code for cases such as
4857 val = setjmp (buf) on machines where reference to val
4858 requires loading up part of an address in a separate insn.
4860 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4861 since it might be a promoted variable where the zero- or sign- extension
4862 needs to be done. Handling this in the normal way is safe because no
4863 computation is done before the call. The same is true for SSA names. */
4864 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4865 && COMPLETE_TYPE_P (TREE_TYPE (from
))
4866 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4867 && ! (((TREE_CODE (to
) == VAR_DECL
4868 || TREE_CODE (to
) == PARM_DECL
4869 || TREE_CODE (to
) == RESULT_DECL
)
4870 && REG_P (DECL_RTL (to
)))
4871 || TREE_CODE (to
) == SSA_NAME
))
4876 value
= expand_normal (from
);
4878 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4880 /* Handle calls that return values in multiple non-contiguous locations.
4881 The Irix 6 ABI has examples of this. */
4882 if (GET_CODE (to_rtx
) == PARALLEL
)
4884 if (GET_CODE (value
) == PARALLEL
)
4885 emit_group_move (to_rtx
, value
);
4887 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
4888 int_size_in_bytes (TREE_TYPE (from
)));
4890 else if (GET_CODE (value
) == PARALLEL
)
4891 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
4892 int_size_in_bytes (TREE_TYPE (from
)));
4893 else if (GET_MODE (to_rtx
) == BLKmode
)
4895 /* Handle calls that return BLKmode values in registers. */
4897 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
4899 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
4903 if (POINTER_TYPE_P (TREE_TYPE (to
)))
4904 value
= convert_memory_address_addr_space
4905 (GET_MODE (to_rtx
), value
,
4906 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
4908 emit_move_insn (to_rtx
, value
);
4910 preserve_temp_slots (to_rtx
);
4915 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4916 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4918 /* Don't move directly into a return register. */
4919 if (TREE_CODE (to
) == RESULT_DECL
4920 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
4925 if (REG_P (to_rtx
) && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
)
4926 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
4928 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
4930 /* Handle calls that return values in multiple non-contiguous locations.
4931 The Irix 6 ABI has examples of this. */
4932 if (GET_CODE (to_rtx
) == PARALLEL
)
4934 if (GET_CODE (temp
) == PARALLEL
)
4935 emit_group_move (to_rtx
, temp
);
4937 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
4938 int_size_in_bytes (TREE_TYPE (from
)));
4941 emit_move_insn (to_rtx
, temp
);
4943 preserve_temp_slots (to_rtx
);
4948 /* In case we are returning the contents of an object which overlaps
4949 the place the value is being stored, use a safe function when copying
4950 a value through a pointer into a structure value return block. */
4951 if (TREE_CODE (to
) == RESULT_DECL
4952 && TREE_CODE (from
) == INDIRECT_REF
4953 && ADDR_SPACE_GENERIC_P
4954 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
4955 && refs_may_alias_p (to
, from
)
4956 && cfun
->returns_struct
4957 && !cfun
->returns_pcc_struct
)
4962 size
= expr_size (from
);
4963 from_rtx
= expand_normal (from
);
4965 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
4966 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
4967 XEXP (from_rtx
, 0), Pmode
,
4968 convert_to_mode (TYPE_MODE (sizetype
),
4969 size
, TYPE_UNSIGNED (sizetype
)),
4970 TYPE_MODE (sizetype
));
4972 preserve_temp_slots (to_rtx
);
4977 /* Compute FROM and store the value in the rtx we got. */
4980 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
4981 preserve_temp_slots (result
);
4986 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
4987 succeeded, false otherwise. */
4990 emit_storent_insn (rtx to
, rtx from
)
4992 struct expand_operand ops
[2];
4993 enum machine_mode mode
= GET_MODE (to
);
4994 enum insn_code code
= optab_handler (storent_optab
, mode
);
4996 if (code
== CODE_FOR_nothing
)
4999 create_fixed_operand (&ops
[0], to
);
5000 create_input_operand (&ops
[1], from
, mode
);
5001 return maybe_expand_insn (code
, 2, ops
);
5004 /* Generate code for computing expression EXP,
5005 and storing the value into TARGET.
5007 If the mode is BLKmode then we may return TARGET itself.
5008 It turns out that in BLKmode it doesn't cause a problem.
5009 because C has no operators that could combine two different
5010 assignments into the same BLKmode object with different values
5011 with no sequence point. Will other languages need this to
5014 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5015 stack, and block moves may need to be treated specially.
5017 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5020 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5023 rtx alt_rtl
= NULL_RTX
;
5024 location_t loc
= curr_insn_location ();
5026 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5028 /* C++ can generate ?: expressions with a throw expression in one
5029 branch and an rvalue in the other. Here, we resolve attempts to
5030 store the throw expression's nonexistent result. */
5031 gcc_assert (!call_param_p
);
5032 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5035 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5037 /* Perform first part of compound expression, then assign from second
5039 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5040 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5041 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5044 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5046 /* For conditional expression, get safe form of the target. Then
5047 test the condition, doing the appropriate assignment on either
5048 side. This avoids the creation of unnecessary temporaries.
5049 For non-BLKmode, it is more efficient not to do this. */
5051 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
5053 do_pending_stack_adjust ();
5055 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5056 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5058 emit_jump_insn (gen_jump (lab2
));
5061 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5068 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5069 /* If this is a scalar in a register that is stored in a wider mode
5070 than the declared mode, compute the result into its declared mode
5071 and then convert to the wider mode. Our value is the computed
5074 rtx inner_target
= 0;
5076 /* We can do the conversion inside EXP, which will often result
5077 in some optimizations. Do the conversion in two steps: first
5078 change the signedness, if needed, then the extend. But don't
5079 do this if the type of EXP is a subtype of something else
5080 since then the conversion might involve more than just
5081 converting modes. */
5082 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5083 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5084 && GET_MODE_PRECISION (GET_MODE (target
))
5085 == TYPE_PRECISION (TREE_TYPE (exp
)))
5087 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
5088 != SUBREG_PROMOTED_UNSIGNED_P (target
))
5090 /* Some types, e.g. Fortran's logical*4, won't have a signed
5091 version, so use the mode instead. */
5093 = (signed_or_unsigned_type_for
5094 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)));
5096 ntype
= lang_hooks
.types
.type_for_mode
5097 (TYPE_MODE (TREE_TYPE (exp
)),
5098 SUBREG_PROMOTED_UNSIGNED_P (target
));
5100 exp
= fold_convert_loc (loc
, ntype
, exp
);
5103 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5104 (GET_MODE (SUBREG_REG (target
)),
5105 SUBREG_PROMOTED_UNSIGNED_P (target
)),
5108 inner_target
= SUBREG_REG (target
);
5111 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5112 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5114 /* If TEMP is a VOIDmode constant, use convert_modes to make
5115 sure that we properly convert it. */
5116 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5118 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5119 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
5120 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5121 GET_MODE (target
), temp
,
5122 SUBREG_PROMOTED_UNSIGNED_P (target
));
5125 convert_move (SUBREG_REG (target
), temp
,
5126 SUBREG_PROMOTED_UNSIGNED_P (target
));
5130 else if ((TREE_CODE (exp
) == STRING_CST
5131 || (TREE_CODE (exp
) == MEM_REF
5132 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5133 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5135 && integer_zerop (TREE_OPERAND (exp
, 1))))
5136 && !nontemporal
&& !call_param_p
5139 /* Optimize initialization of an array with a STRING_CST. */
5140 HOST_WIDE_INT exp_len
, str_copy_len
;
5142 tree str
= TREE_CODE (exp
) == STRING_CST
5143 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5145 exp_len
= int_expr_size (exp
);
5149 if (TREE_STRING_LENGTH (str
) <= 0)
5152 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5153 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5156 str_copy_len
= TREE_STRING_LENGTH (str
);
5157 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5158 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5160 str_copy_len
+= STORE_MAX_PIECES
- 1;
5161 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5163 str_copy_len
= MIN (str_copy_len
, exp_len
);
5164 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5165 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5166 MEM_ALIGN (target
), false))
5171 dest_mem
= store_by_pieces (dest_mem
,
5172 str_copy_len
, builtin_strncpy_read_str
,
5174 TREE_STRING_POINTER (str
)),
5175 MEM_ALIGN (target
), false,
5176 exp_len
> str_copy_len
? 1 : 0);
5177 if (exp_len
> str_copy_len
)
5178 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5179 GEN_INT (exp_len
- str_copy_len
),
5188 /* If we want to use a nontemporal store, force the value to
5190 tmp_target
= nontemporal
? NULL_RTX
: target
;
5191 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5193 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5197 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5198 the same as that of TARGET, adjust the constant. This is needed, for
5199 example, in case it is a CONST_DOUBLE and we want only a word-sized
5201 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5202 && TREE_CODE (exp
) != ERROR_MARK
5203 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5204 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5205 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5207 /* If value was not generated in the target, store it there.
5208 Convert the value to TARGET's type first if necessary and emit the
5209 pending incrementations that have been queued when expanding EXP.
5210 Note that we cannot emit the whole queue blindly because this will
5211 effectively disable the POST_INC optimization later.
5213 If TEMP and TARGET compare equal according to rtx_equal_p, but
5214 one or both of them are volatile memory refs, we have to distinguish
5216 - expand_expr has used TARGET. In this case, we must not generate
5217 another copy. This can be detected by TARGET being equal according
5219 - expand_expr has not used TARGET - that means that the source just
5220 happens to have the same RTX form. Since temp will have been created
5221 by expand_expr, it will compare unequal according to == .
5222 We must generate a copy in this case, to reach the correct number
5223 of volatile memory references. */
5225 if ((! rtx_equal_p (temp
, target
)
5226 || (temp
!= target
&& (side_effects_p (temp
)
5227 || side_effects_p (target
))))
5228 && TREE_CODE (exp
) != ERROR_MARK
5229 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5230 but TARGET is not valid memory reference, TEMP will differ
5231 from TARGET although it is really the same location. */
5233 && rtx_equal_p (alt_rtl
, target
)
5234 && !side_effects_p (alt_rtl
)
5235 && !side_effects_p (target
))
5236 /* If there's nothing to copy, don't bother. Don't call
5237 expr_size unless necessary, because some front-ends (C++)
5238 expr_size-hook must not be given objects that are not
5239 supposed to be bit-copied or bit-initialized. */
5240 && expr_size (exp
) != const0_rtx
)
5242 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5244 if (GET_MODE (target
) == BLKmode
)
5246 /* Handle calls that return BLKmode values in registers. */
5247 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5248 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5250 store_bit_field (target
,
5251 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5252 0, 0, 0, GET_MODE (temp
), temp
);
5255 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5258 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5260 /* Handle copying a string constant into an array. The string
5261 constant may be shorter than the array. So copy just the string's
5262 actual length, and clear the rest. First get the size of the data
5263 type of the string, which is actually the size of the target. */
5264 rtx size
= expr_size (exp
);
5266 if (CONST_INT_P (size
)
5267 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5268 emit_block_move (target
, temp
, size
,
5270 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5273 enum machine_mode pointer_mode
5274 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5275 enum machine_mode address_mode
= get_address_mode (target
);
5277 /* Compute the size of the data to copy from the string. */
5279 = size_binop_loc (loc
, MIN_EXPR
,
5280 make_tree (sizetype
, size
),
5281 size_int (TREE_STRING_LENGTH (exp
)));
5283 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5285 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5288 /* Copy that much. */
5289 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5290 TYPE_UNSIGNED (sizetype
));
5291 emit_block_move (target
, temp
, copy_size_rtx
,
5293 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5295 /* Figure out how much is left in TARGET that we have to clear.
5296 Do all calculations in pointer_mode. */
5297 if (CONST_INT_P (copy_size_rtx
))
5299 size
= plus_constant (address_mode
, size
,
5300 -INTVAL (copy_size_rtx
));
5301 target
= adjust_address (target
, BLKmode
,
5302 INTVAL (copy_size_rtx
));
5306 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5307 copy_size_rtx
, NULL_RTX
, 0,
5310 if (GET_MODE (copy_size_rtx
) != address_mode
)
5311 copy_size_rtx
= convert_to_mode (address_mode
,
5313 TYPE_UNSIGNED (sizetype
));
5315 target
= offset_address (target
, copy_size_rtx
,
5316 highest_pow2_factor (copy_size
));
5317 label
= gen_label_rtx ();
5318 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5319 GET_MODE (size
), 0, label
);
5322 if (size
!= const0_rtx
)
5323 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5329 /* Handle calls that return values in multiple non-contiguous locations.
5330 The Irix 6 ABI has examples of this. */
5331 else if (GET_CODE (target
) == PARALLEL
)
5333 if (GET_CODE (temp
) == PARALLEL
)
5334 emit_group_move (target
, temp
);
5336 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5337 int_size_in_bytes (TREE_TYPE (exp
)));
5339 else if (GET_CODE (temp
) == PARALLEL
)
5340 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5341 int_size_in_bytes (TREE_TYPE (exp
)));
5342 else if (GET_MODE (temp
) == BLKmode
)
5343 emit_block_move (target
, temp
, expr_size (exp
),
5345 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5346 /* If we emit a nontemporal store, there is nothing else to do. */
5347 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5351 temp
= force_operand (temp
, target
);
5353 emit_move_insn (target
, temp
);
5360 /* Return true if field F of structure TYPE is a flexible array. */
5363 flexible_array_member_p (const_tree f
, const_tree type
)
5368 return (DECL_CHAIN (f
) == NULL
5369 && TREE_CODE (tf
) == ARRAY_TYPE
5371 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5372 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5373 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5374 && int_size_in_bytes (type
) >= 0);
5377 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5378 must have in order for it to completely initialize a value of type TYPE.
5379 Return -1 if the number isn't known.
5381 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5383 static HOST_WIDE_INT
5384 count_type_elements (const_tree type
, bool for_ctor_p
)
5386 switch (TREE_CODE (type
))
5392 nelts
= array_type_nelts (type
);
5393 if (nelts
&& host_integerp (nelts
, 1))
5395 unsigned HOST_WIDE_INT n
;
5397 n
= tree_low_cst (nelts
, 1) + 1;
5398 if (n
== 0 || for_ctor_p
)
5401 return n
* count_type_elements (TREE_TYPE (type
), false);
5403 return for_ctor_p
? -1 : 1;
5408 unsigned HOST_WIDE_INT n
;
5412 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5413 if (TREE_CODE (f
) == FIELD_DECL
)
5416 n
+= count_type_elements (TREE_TYPE (f
), false);
5417 else if (!flexible_array_member_p (f
, type
))
5418 /* Don't count flexible arrays, which are not supposed
5419 to be initialized. */
5427 case QUAL_UNION_TYPE
:
5432 gcc_assert (!for_ctor_p
);
5433 /* Estimate the number of scalars in each field and pick the
5434 maximum. Other estimates would do instead; the idea is simply
5435 to make sure that the estimate is not sensitive to the ordering
5438 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5439 if (TREE_CODE (f
) == FIELD_DECL
)
5441 m
= count_type_elements (TREE_TYPE (f
), false);
5442 /* If the field doesn't span the whole union, add an extra
5443 scalar for the rest. */
5444 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5445 TYPE_SIZE (type
)) != 1)
5457 return TYPE_VECTOR_SUBPARTS (type
);
5461 case FIXED_POINT_TYPE
:
5466 case REFERENCE_TYPE
:
5482 /* Helper for categorize_ctor_elements. Identical interface. */
5485 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5486 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5488 unsigned HOST_WIDE_INT idx
;
5489 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5490 tree value
, purpose
, elt_type
;
5492 /* Whether CTOR is a valid constant initializer, in accordance with what
5493 initializer_constant_valid_p does. If inferred from the constructor
5494 elements, true until proven otherwise. */
5495 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5496 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5501 elt_type
= NULL_TREE
;
5503 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5505 HOST_WIDE_INT mult
= 1;
5507 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5509 tree lo_index
= TREE_OPERAND (purpose
, 0);
5510 tree hi_index
= TREE_OPERAND (purpose
, 1);
5512 if (host_integerp (lo_index
, 1) && host_integerp (hi_index
, 1))
5513 mult
= (tree_low_cst (hi_index
, 1)
5514 - tree_low_cst (lo_index
, 1) + 1);
5517 elt_type
= TREE_TYPE (value
);
5519 switch (TREE_CODE (value
))
5523 HOST_WIDE_INT nz
= 0, ic
= 0;
5525 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5528 nz_elts
+= mult
* nz
;
5529 init_elts
+= mult
* ic
;
5531 if (const_from_elts_p
&& const_p
)
5532 const_p
= const_elt_p
;
5539 if (!initializer_zerop (value
))
5545 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5546 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5550 if (!initializer_zerop (TREE_REALPART (value
)))
5552 if (!initializer_zerop (TREE_IMAGPART (value
)))
5560 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5562 tree v
= VECTOR_CST_ELT (value
, i
);
5563 if (!initializer_zerop (v
))
5572 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5573 nz_elts
+= mult
* tc
;
5574 init_elts
+= mult
* tc
;
5576 if (const_from_elts_p
&& const_p
)
5577 const_p
= initializer_constant_valid_p (value
, elt_type
)
5584 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5585 num_fields
, elt_type
))
5586 *p_complete
= false;
5588 *p_nz_elts
+= nz_elts
;
5589 *p_init_elts
+= init_elts
;
5594 /* Examine CTOR to discover:
5595 * how many scalar fields are set to nonzero values,
5596 and place it in *P_NZ_ELTS;
5597 * how many scalar fields in total are in CTOR,
5598 and place it in *P_ELT_COUNT.
5599 * whether the constructor is complete -- in the sense that every
5600 meaningful byte is explicitly given a value --
5601 and place it in *P_COMPLETE.
5603 Return whether or not CTOR is a valid static constant initializer, the same
5604 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5607 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5608 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5614 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5617 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5618 of which had type LAST_TYPE. Each element was itself a complete
5619 initializer, in the sense that every meaningful byte was explicitly
5620 given a value. Return true if the same is true for the constructor
5624 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5625 const_tree last_type
)
5627 if (TREE_CODE (type
) == UNION_TYPE
5628 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5633 gcc_assert (num_elts
== 1 && last_type
);
5635 /* ??? We could look at each element of the union, and find the
5636 largest element. Which would avoid comparing the size of the
5637 initialized element against any tail padding in the union.
5638 Doesn't seem worth the effort... */
5639 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5642 return count_type_elements (type
, true) == num_elts
;
5645 /* Return 1 if EXP contains mostly (3/4) zeros. */
5648 mostly_zeros_p (const_tree exp
)
5650 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5652 HOST_WIDE_INT nz_elts
, init_elts
;
5655 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5656 return !complete_p
|| nz_elts
< init_elts
/ 4;
5659 return initializer_zerop (exp
);
5662 /* Return 1 if EXP contains all zeros. */
5665 all_zeros_p (const_tree exp
)
5667 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5669 HOST_WIDE_INT nz_elts
, init_elts
;
5672 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5673 return nz_elts
== 0;
5676 return initializer_zerop (exp
);
5679 /* Helper function for store_constructor.
5680 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5681 CLEARED is as for store_constructor.
5682 ALIAS_SET is the alias set to use for any stores.
5684 This provides a recursive shortcut back to store_constructor when it isn't
5685 necessary to go through store_field. This is so that we can pass through
5686 the cleared field to let store_constructor know that we may not have to
5687 clear a substructure if the outer structure has already been cleared. */
5690 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5691 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5692 tree exp
, int cleared
, alias_set_type alias_set
)
5694 if (TREE_CODE (exp
) == CONSTRUCTOR
5695 /* We can only call store_constructor recursively if the size and
5696 bit position are on a byte boundary. */
5697 && bitpos
% BITS_PER_UNIT
== 0
5698 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5699 /* If we have a nonzero bitpos for a register target, then we just
5700 let store_field do the bitfield handling. This is unlikely to
5701 generate unnecessary clear instructions anyways. */
5702 && (bitpos
== 0 || MEM_P (target
)))
5706 = adjust_address (target
,
5707 GET_MODE (target
) == BLKmode
5709 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5710 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5713 /* Update the alias set, if required. */
5714 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5715 && MEM_ALIAS_SET (target
) != 0)
5717 target
= copy_rtx (target
);
5718 set_mem_alias_set (target
, alias_set
);
5721 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5724 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5727 /* Store the value of constructor EXP into the rtx TARGET.
5728 TARGET is either a REG or a MEM; we know it cannot conflict, since
5729 safe_from_p has been called.
5730 CLEARED is true if TARGET is known to have been zero'd.
5731 SIZE is the number of bytes of TARGET we are allowed to modify: this
5732 may not be the same as the size of EXP if we are assigning to a field
5733 which has been packed to exclude padding bits. */
5736 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5738 tree type
= TREE_TYPE (exp
);
5739 #ifdef WORD_REGISTER_OPERATIONS
5740 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5743 switch (TREE_CODE (type
))
5747 case QUAL_UNION_TYPE
:
5749 unsigned HOST_WIDE_INT idx
;
5752 /* If size is zero or the target is already cleared, do nothing. */
5753 if (size
== 0 || cleared
)
5755 /* We either clear the aggregate or indicate the value is dead. */
5756 else if ((TREE_CODE (type
) == UNION_TYPE
5757 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5758 && ! CONSTRUCTOR_ELTS (exp
))
5759 /* If the constructor is empty, clear the union. */
5761 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5765 /* If we are building a static constructor into a register,
5766 set the initial value as zero so we can fold the value into
5767 a constant. But if more than one register is involved,
5768 this probably loses. */
5769 else if (REG_P (target
) && TREE_STATIC (exp
)
5770 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5772 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5776 /* If the constructor has fewer fields than the structure or
5777 if we are initializing the structure to mostly zeros, clear
5778 the whole structure first. Don't do this if TARGET is a
5779 register whose mode size isn't equal to SIZE since
5780 clear_storage can't handle this case. */
5782 && (((int)VEC_length (constructor_elt
, CONSTRUCTOR_ELTS (exp
))
5783 != fields_length (type
))
5784 || mostly_zeros_p (exp
))
5786 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5789 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5793 if (REG_P (target
) && !cleared
)
5794 emit_clobber (target
);
5796 /* Store each element of the constructor into the
5797 corresponding field of TARGET. */
5798 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5800 enum machine_mode mode
;
5801 HOST_WIDE_INT bitsize
;
5802 HOST_WIDE_INT bitpos
= 0;
5804 rtx to_rtx
= target
;
5806 /* Just ignore missing fields. We cleared the whole
5807 structure, above, if any fields are missing. */
5811 if (cleared
&& initializer_zerop (value
))
5814 if (host_integerp (DECL_SIZE (field
), 1))
5815 bitsize
= tree_low_cst (DECL_SIZE (field
), 1);
5819 mode
= DECL_MODE (field
);
5820 if (DECL_BIT_FIELD (field
))
5823 offset
= DECL_FIELD_OFFSET (field
);
5824 if (host_integerp (offset
, 0)
5825 && host_integerp (bit_position (field
), 0))
5827 bitpos
= int_bit_position (field
);
5831 bitpos
= tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 0);
5835 enum machine_mode address_mode
;
5839 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5840 make_tree (TREE_TYPE (exp
),
5843 offset_rtx
= expand_normal (offset
);
5844 gcc_assert (MEM_P (to_rtx
));
5846 address_mode
= get_address_mode (to_rtx
);
5847 if (GET_MODE (offset_rtx
) != address_mode
)
5848 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5850 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5851 highest_pow2_factor (offset
));
5854 #ifdef WORD_REGISTER_OPERATIONS
5855 /* If this initializes a field that is smaller than a
5856 word, at the start of a word, try to widen it to a full
5857 word. This special case allows us to output C++ member
5858 function initializations in a form that the optimizers
5861 && bitsize
< BITS_PER_WORD
5862 && bitpos
% BITS_PER_WORD
== 0
5863 && GET_MODE_CLASS (mode
) == MODE_INT
5864 && TREE_CODE (value
) == INTEGER_CST
5866 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
5868 tree type
= TREE_TYPE (value
);
5870 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
5872 type
= lang_hooks
.types
.type_for_mode
5873 (word_mode
, TYPE_UNSIGNED (type
));
5874 value
= fold_convert (type
, value
);
5877 if (BYTES_BIG_ENDIAN
)
5879 = fold_build2 (LSHIFT_EXPR
, type
, value
,
5880 build_int_cst (type
,
5881 BITS_PER_WORD
- bitsize
));
5882 bitsize
= BITS_PER_WORD
;
5887 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
5888 && DECL_NONADDRESSABLE_P (field
))
5890 to_rtx
= copy_rtx (to_rtx
);
5891 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
5894 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
5896 get_alias_set (TREE_TYPE (field
)));
5903 unsigned HOST_WIDE_INT i
;
5906 tree elttype
= TREE_TYPE (type
);
5908 HOST_WIDE_INT minelt
= 0;
5909 HOST_WIDE_INT maxelt
= 0;
5911 domain
= TYPE_DOMAIN (type
);
5912 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
5913 && TYPE_MAX_VALUE (domain
)
5914 && host_integerp (TYPE_MIN_VALUE (domain
), 0)
5915 && host_integerp (TYPE_MAX_VALUE (domain
), 0));
5917 /* If we have constant bounds for the range of the type, get them. */
5920 minelt
= tree_low_cst (TYPE_MIN_VALUE (domain
), 0);
5921 maxelt
= tree_low_cst (TYPE_MAX_VALUE (domain
), 0);
5924 /* If the constructor has fewer elements than the array, clear
5925 the whole array first. Similarly if this is static
5926 constructor of a non-BLKmode object. */
5929 else if (REG_P (target
) && TREE_STATIC (exp
))
5933 unsigned HOST_WIDE_INT idx
;
5935 HOST_WIDE_INT count
= 0, zero_count
= 0;
5936 need_to_clear
= ! const_bounds_p
;
5938 /* This loop is a more accurate version of the loop in
5939 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5940 is also needed to check for missing elements. */
5941 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
5943 HOST_WIDE_INT this_node_count
;
5948 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
5950 tree lo_index
= TREE_OPERAND (index
, 0);
5951 tree hi_index
= TREE_OPERAND (index
, 1);
5953 if (! host_integerp (lo_index
, 1)
5954 || ! host_integerp (hi_index
, 1))
5960 this_node_count
= (tree_low_cst (hi_index
, 1)
5961 - tree_low_cst (lo_index
, 1) + 1);
5964 this_node_count
= 1;
5966 count
+= this_node_count
;
5967 if (mostly_zeros_p (value
))
5968 zero_count
+= this_node_count
;
5971 /* Clear the entire array first if there are any missing
5972 elements, or if the incidence of zero elements is >=
5975 && (count
< maxelt
- minelt
+ 1
5976 || 4 * zero_count
>= 3 * count
))
5980 if (need_to_clear
&& size
> 0)
5983 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5985 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5989 if (!cleared
&& REG_P (target
))
5990 /* Inform later passes that the old value is dead. */
5991 emit_clobber (target
);
5993 /* Store each element of the constructor into the
5994 corresponding element of TARGET, determined by counting the
5996 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
5998 enum machine_mode mode
;
5999 HOST_WIDE_INT bitsize
;
6000 HOST_WIDE_INT bitpos
;
6001 rtx xtarget
= target
;
6003 if (cleared
&& initializer_zerop (value
))
6006 mode
= TYPE_MODE (elttype
);
6007 if (mode
== BLKmode
)
6008 bitsize
= (host_integerp (TYPE_SIZE (elttype
), 1)
6009 ? tree_low_cst (TYPE_SIZE (elttype
), 1)
6012 bitsize
= GET_MODE_BITSIZE (mode
);
6014 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6016 tree lo_index
= TREE_OPERAND (index
, 0);
6017 tree hi_index
= TREE_OPERAND (index
, 1);
6018 rtx index_r
, pos_rtx
;
6019 HOST_WIDE_INT lo
, hi
, count
;
6022 /* If the range is constant and "small", unroll the loop. */
6024 && host_integerp (lo_index
, 0)
6025 && host_integerp (hi_index
, 0)
6026 && (lo
= tree_low_cst (lo_index
, 0),
6027 hi
= tree_low_cst (hi_index
, 0),
6028 count
= hi
- lo
+ 1,
6031 || (host_integerp (TYPE_SIZE (elttype
), 1)
6032 && (tree_low_cst (TYPE_SIZE (elttype
), 1) * count
6035 lo
-= minelt
; hi
-= minelt
;
6036 for (; lo
<= hi
; lo
++)
6038 bitpos
= lo
* tree_low_cst (TYPE_SIZE (elttype
), 0);
6041 && !MEM_KEEP_ALIAS_SET_P (target
)
6042 && TREE_CODE (type
) == ARRAY_TYPE
6043 && TYPE_NONALIASED_COMPONENT (type
))
6045 target
= copy_rtx (target
);
6046 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6049 store_constructor_field
6050 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6051 get_alias_set (elttype
));
6056 rtx loop_start
= gen_label_rtx ();
6057 rtx loop_end
= gen_label_rtx ();
6060 expand_normal (hi_index
);
6062 index
= build_decl (EXPR_LOCATION (exp
),
6063 VAR_DECL
, NULL_TREE
, domain
);
6064 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6065 SET_DECL_RTL (index
, index_r
);
6066 store_expr (lo_index
, index_r
, 0, false);
6068 /* Build the head of the loop. */
6069 do_pending_stack_adjust ();
6070 emit_label (loop_start
);
6072 /* Assign value to element index. */
6074 fold_convert (ssizetype
,
6075 fold_build2 (MINUS_EXPR
,
6078 TYPE_MIN_VALUE (domain
)));
6081 size_binop (MULT_EXPR
, position
,
6082 fold_convert (ssizetype
,
6083 TYPE_SIZE_UNIT (elttype
)));
6085 pos_rtx
= expand_normal (position
);
6086 xtarget
= offset_address (target
, pos_rtx
,
6087 highest_pow2_factor (position
));
6088 xtarget
= adjust_address (xtarget
, mode
, 0);
6089 if (TREE_CODE (value
) == CONSTRUCTOR
)
6090 store_constructor (value
, xtarget
, cleared
,
6091 bitsize
/ BITS_PER_UNIT
);
6093 store_expr (value
, xtarget
, 0, false);
6095 /* Generate a conditional jump to exit the loop. */
6096 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6098 jumpif (exit_cond
, loop_end
, -1);
6100 /* Update the loop counter, and jump to the head of
6102 expand_assignment (index
,
6103 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6104 index
, integer_one_node
),
6107 emit_jump (loop_start
);
6109 /* Build the end of the loop. */
6110 emit_label (loop_end
);
6113 else if ((index
!= 0 && ! host_integerp (index
, 0))
6114 || ! host_integerp (TYPE_SIZE (elttype
), 1))
6119 index
= ssize_int (1);
6122 index
= fold_convert (ssizetype
,
6123 fold_build2 (MINUS_EXPR
,
6126 TYPE_MIN_VALUE (domain
)));
6129 size_binop (MULT_EXPR
, index
,
6130 fold_convert (ssizetype
,
6131 TYPE_SIZE_UNIT (elttype
)));
6132 xtarget
= offset_address (target
,
6133 expand_normal (position
),
6134 highest_pow2_factor (position
));
6135 xtarget
= adjust_address (xtarget
, mode
, 0);
6136 store_expr (value
, xtarget
, 0, false);
6141 bitpos
= ((tree_low_cst (index
, 0) - minelt
)
6142 * tree_low_cst (TYPE_SIZE (elttype
), 1));
6144 bitpos
= (i
* tree_low_cst (TYPE_SIZE (elttype
), 1));
6146 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6147 && TREE_CODE (type
) == ARRAY_TYPE
6148 && TYPE_NONALIASED_COMPONENT (type
))
6150 target
= copy_rtx (target
);
6151 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6153 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6154 cleared
, get_alias_set (elttype
));
6162 unsigned HOST_WIDE_INT idx
;
6163 constructor_elt
*ce
;
6166 int icode
= CODE_FOR_nothing
;
6167 tree elttype
= TREE_TYPE (type
);
6168 int elt_size
= tree_low_cst (TYPE_SIZE (elttype
), 1);
6169 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6170 HOST_WIDE_INT bitsize
;
6171 HOST_WIDE_INT bitpos
;
6172 rtvec vector
= NULL
;
6174 alias_set_type alias
;
6176 gcc_assert (eltmode
!= BLKmode
);
6178 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6179 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6181 enum machine_mode mode
= GET_MODE (target
);
6183 icode
= (int) optab_handler (vec_init_optab
, mode
);
6184 if (icode
!= CODE_FOR_nothing
)
6188 vector
= rtvec_alloc (n_elts
);
6189 for (i
= 0; i
< n_elts
; i
++)
6190 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6194 /* If the constructor has fewer elements than the vector,
6195 clear the whole array first. Similarly if this is static
6196 constructor of a non-BLKmode object. */
6199 else if (REG_P (target
) && TREE_STATIC (exp
))
6203 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6206 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6208 int n_elts_here
= tree_low_cst
6209 (int_const_binop (TRUNC_DIV_EXPR
,
6210 TYPE_SIZE (TREE_TYPE (value
)),
6211 TYPE_SIZE (elttype
)), 1);
6213 count
+= n_elts_here
;
6214 if (mostly_zeros_p (value
))
6215 zero_count
+= n_elts_here
;
6218 /* Clear the entire vector first if there are any missing elements,
6219 or if the incidence of zero elements is >= 75%. */
6220 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6223 if (need_to_clear
&& size
> 0 && !vector
)
6226 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6228 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6232 /* Inform later passes that the old value is dead. */
6233 if (!cleared
&& !vector
&& REG_P (target
))
6234 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6237 alias
= MEM_ALIAS_SET (target
);
6239 alias
= get_alias_set (elttype
);
6241 /* Store each element of the constructor into the corresponding
6242 element of TARGET, determined by counting the elements. */
6243 for (idx
= 0, i
= 0;
6244 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
);
6245 idx
++, i
+= bitsize
/ elt_size
)
6247 HOST_WIDE_INT eltpos
;
6248 tree value
= ce
->value
;
6250 bitsize
= tree_low_cst (TYPE_SIZE (TREE_TYPE (value
)), 1);
6251 if (cleared
&& initializer_zerop (value
))
6255 eltpos
= tree_low_cst (ce
->index
, 1);
6261 /* Vector CONSTRUCTORs should only be built from smaller
6262 vectors in the case of BLKmode vectors. */
6263 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6264 RTVEC_ELT (vector
, eltpos
)
6265 = expand_normal (value
);
6269 enum machine_mode value_mode
=
6270 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6271 ? TYPE_MODE (TREE_TYPE (value
))
6273 bitpos
= eltpos
* elt_size
;
6274 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6275 value
, cleared
, alias
);
6280 emit_insn (GEN_FCN (icode
)
6282 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6291 /* Store the value of EXP (an expression tree)
6292 into a subfield of TARGET which has mode MODE and occupies
6293 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6294 If MODE is VOIDmode, it means that we are storing into a bit-field.
6296 BITREGION_START is bitpos of the first bitfield in this region.
6297 BITREGION_END is the bitpos of the ending bitfield in this region.
6298 These two fields are 0, if the C++ memory model does not apply,
6299 or we are not interested in keeping track of bitfield regions.
6301 Always return const0_rtx unless we have something particular to
6304 ALIAS_SET is the alias set for the destination. This value will
6305 (in general) be different from that for TARGET, since TARGET is a
6306 reference to the containing structure.
6308 If NONTEMPORAL is true, try generating a nontemporal store. */
6311 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6312 unsigned HOST_WIDE_INT bitregion_start
,
6313 unsigned HOST_WIDE_INT bitregion_end
,
6314 enum machine_mode mode
, tree exp
,
6315 alias_set_type alias_set
, bool nontemporal
)
6317 if (TREE_CODE (exp
) == ERROR_MARK
)
6320 /* If we have nothing to store, do nothing unless the expression has
6323 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6325 if (GET_CODE (target
) == CONCAT
)
6327 /* We're storing into a struct containing a single __complex. */
6329 gcc_assert (!bitpos
);
6330 return store_expr (exp
, target
, 0, nontemporal
);
6333 /* If the structure is in a register or if the component
6334 is a bit field, we cannot use addressing to access it.
6335 Use bit-field techniques or SUBREG to store in it. */
6337 if (mode
== VOIDmode
6338 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6339 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6340 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6342 || GET_CODE (target
) == SUBREG
6343 /* If the field isn't aligned enough to store as an ordinary memref,
6344 store it as a bit field. */
6346 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6347 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6348 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6349 || (bitpos
% BITS_PER_UNIT
!= 0)))
6350 || (bitsize
>= 0 && mode
!= BLKmode
6351 && GET_MODE_BITSIZE (mode
) > bitsize
)
6352 /* If the RHS and field are a constant size and the size of the
6353 RHS isn't the same size as the bitfield, we must use bitfield
6356 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6357 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6358 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6359 decl we must use bitfield operations. */
6361 && TREE_CODE (exp
) == MEM_REF
6362 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6363 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6364 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6365 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6370 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6371 implies a mask operation. If the precision is the same size as
6372 the field we're storing into, that mask is redundant. This is
6373 particularly common with bit field assignments generated by the
6375 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6378 tree type
= TREE_TYPE (exp
);
6379 if (INTEGRAL_TYPE_P (type
)
6380 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6381 && bitsize
== TYPE_PRECISION (type
))
6383 tree op
= gimple_assign_rhs1 (nop_def
);
6384 type
= TREE_TYPE (op
);
6385 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6390 temp
= expand_normal (exp
);
6392 /* If BITSIZE is narrower than the size of the type of EXP
6393 we will be narrowing TEMP. Normally, what's wanted are the
6394 low-order bits. However, if EXP's type is a record and this is
6395 big-endian machine, we want the upper BITSIZE bits. */
6396 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6397 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6398 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6399 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6400 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6403 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6404 if (mode
!= VOIDmode
&& mode
!= BLKmode
6405 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6406 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6408 /* If the modes of TEMP and TARGET are both BLKmode, both
6409 must be in memory and BITPOS must be aligned on a byte
6410 boundary. If so, we simply do a block copy. Likewise
6411 for a BLKmode-like TARGET. */
6412 if (GET_MODE (temp
) == BLKmode
6413 && (GET_MODE (target
) == BLKmode
6415 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6416 && (bitpos
% BITS_PER_UNIT
) == 0
6417 && (bitsize
% BITS_PER_UNIT
) == 0)))
6419 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6420 && (bitpos
% BITS_PER_UNIT
) == 0);
6422 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6423 emit_block_move (target
, temp
,
6424 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6431 /* Handle calls that return values in multiple non-contiguous locations.
6432 The Irix 6 ABI has examples of this. */
6433 if (GET_CODE (temp
) == PARALLEL
)
6435 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6437 if (mode
== BLKmode
)
6438 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6439 temp_target
= gen_reg_rtx (mode
);
6440 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6443 else if (mode
== BLKmode
)
6445 /* Handle calls that return BLKmode values in registers. */
6446 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6448 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6449 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6454 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6456 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6457 temp_target
= gen_reg_rtx (mode
);
6459 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6460 false, temp_target
, mode
, mode
);
6465 /* Store the value in the bitfield. */
6466 store_bit_field (target
, bitsize
, bitpos
,
6467 bitregion_start
, bitregion_end
,
6474 /* Now build a reference to just the desired component. */
6475 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6477 if (to_rtx
== target
)
6478 to_rtx
= copy_rtx (to_rtx
);
6480 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6481 set_mem_alias_set (to_rtx
, alias_set
);
6483 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6487 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6488 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6489 codes and find the ultimate containing object, which we return.
6491 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6492 bit position, and *PUNSIGNEDP to the signedness of the field.
6493 If the position of the field is variable, we store a tree
6494 giving the variable offset (in units) in *POFFSET.
6495 This offset is in addition to the bit position.
6496 If the position is not variable, we store 0 in *POFFSET.
6498 If any of the extraction expressions is volatile,
6499 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6501 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6502 Otherwise, it is a mode that can be used to access the field.
6504 If the field describes a variable-sized object, *PMODE is set to
6505 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6506 this case, but the address of the object can be found.
6508 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6509 look through nodes that serve as markers of a greater alignment than
6510 the one that can be deduced from the expression. These nodes make it
6511 possible for front-ends to prevent temporaries from being created by
6512 the middle-end on alignment considerations. For that purpose, the
6513 normal operating mode at high-level is to always pass FALSE so that
6514 the ultimate containing object is really returned; moreover, the
6515 associated predicate handled_component_p will always return TRUE
6516 on these nodes, thus indicating that they are essentially handled
6517 by get_inner_reference. TRUE should only be passed when the caller
6518 is scanning the expression in order to build another representation
6519 and specifically knows how to handle these nodes; as such, this is
6520 the normal operating mode in the RTL expanders. */
6523 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6524 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6525 enum machine_mode
*pmode
, int *punsignedp
,
6526 int *pvolatilep
, bool keep_aligning
)
6529 enum machine_mode mode
= VOIDmode
;
6530 bool blkmode_bitfield
= false;
6531 tree offset
= size_zero_node
;
6532 double_int bit_offset
= double_int_zero
;
6534 /* First get the mode, signedness, and size. We do this from just the
6535 outermost expression. */
6537 if (TREE_CODE (exp
) == COMPONENT_REF
)
6539 tree field
= TREE_OPERAND (exp
, 1);
6540 size_tree
= DECL_SIZE (field
);
6541 if (!DECL_BIT_FIELD (field
))
6542 mode
= DECL_MODE (field
);
6543 else if (DECL_MODE (field
) == BLKmode
)
6544 blkmode_bitfield
= true;
6545 else if (TREE_THIS_VOLATILE (exp
)
6546 && flag_strict_volatile_bitfields
> 0)
6547 /* Volatile bitfields should be accessed in the mode of the
6548 field's type, not the mode computed based on the bit
6550 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6552 *punsignedp
= DECL_UNSIGNED (field
);
6554 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6556 size_tree
= TREE_OPERAND (exp
, 1);
6557 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6558 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6560 /* For vector types, with the correct size of access, use the mode of
6562 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6563 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6564 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6565 mode
= TYPE_MODE (TREE_TYPE (exp
));
6569 mode
= TYPE_MODE (TREE_TYPE (exp
));
6570 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6572 if (mode
== BLKmode
)
6573 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6575 *pbitsize
= GET_MODE_BITSIZE (mode
);
6580 if (! host_integerp (size_tree
, 1))
6581 mode
= BLKmode
, *pbitsize
= -1;
6583 *pbitsize
= tree_low_cst (size_tree
, 1);
6586 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6587 and find the ultimate containing object. */
6590 switch (TREE_CODE (exp
))
6593 bit_offset
+= tree_to_double_int (TREE_OPERAND (exp
, 2));
6598 tree field
= TREE_OPERAND (exp
, 1);
6599 tree this_offset
= component_ref_field_offset (exp
);
6601 /* If this field hasn't been filled in yet, don't go past it.
6602 This should only happen when folding expressions made during
6603 type construction. */
6604 if (this_offset
== 0)
6607 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6608 bit_offset
+= tree_to_double_int (DECL_FIELD_BIT_OFFSET (field
));
6610 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6615 case ARRAY_RANGE_REF
:
6617 tree index
= TREE_OPERAND (exp
, 1);
6618 tree low_bound
= array_ref_low_bound (exp
);
6619 tree unit_size
= array_ref_element_size (exp
);
6621 /* We assume all arrays have sizes that are a multiple of a byte.
6622 First subtract the lower bound, if any, in the type of the
6623 index, then convert to sizetype and multiply by the size of
6624 the array element. */
6625 if (! integer_zerop (low_bound
))
6626 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6629 offset
= size_binop (PLUS_EXPR
, offset
,
6630 size_binop (MULT_EXPR
,
6631 fold_convert (sizetype
, index
),
6640 bit_offset
+= double_int::from_uhwi (*pbitsize
);
6643 case VIEW_CONVERT_EXPR
:
6644 if (keep_aligning
&& STRICT_ALIGNMENT
6645 && (TYPE_ALIGN (TREE_TYPE (exp
))
6646 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6647 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6648 < BIGGEST_ALIGNMENT
)
6649 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6650 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6655 /* Hand back the decl for MEM[&decl, off]. */
6656 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6658 tree off
= TREE_OPERAND (exp
, 1);
6659 if (!integer_zerop (off
))
6661 double_int boff
, coff
= mem_ref_offset (exp
);
6662 boff
= coff
.alshift (BITS_PER_UNIT
== 8
6663 ? 3 : exact_log2 (BITS_PER_UNIT
),
6664 HOST_BITS_PER_DOUBLE_INT
);
6667 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6675 /* If any reference in the chain is volatile, the effect is volatile. */
6676 if (TREE_THIS_VOLATILE (exp
))
6679 exp
= TREE_OPERAND (exp
, 0);
6683 /* If OFFSET is constant, see if we can return the whole thing as a
6684 constant bit position. Make sure to handle overflow during
6686 if (TREE_CODE (offset
) == INTEGER_CST
)
6688 double_int tem
= tree_to_double_int (offset
);
6689 tem
= tem
.sext (TYPE_PRECISION (sizetype
));
6690 tem
= tem
.alshift (BITS_PER_UNIT
== 8 ? 3 : exact_log2 (BITS_PER_UNIT
),
6691 HOST_BITS_PER_DOUBLE_INT
);
6693 if (tem
.fits_shwi ())
6695 *pbitpos
= tem
.to_shwi ();
6696 *poffset
= offset
= NULL_TREE
;
6700 /* Otherwise, split it up. */
6703 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6704 if (bit_offset
.is_negative ())
6707 = double_int::mask (BITS_PER_UNIT
== 8
6708 ? 3 : exact_log2 (BITS_PER_UNIT
));
6709 double_int tem
= bit_offset
.and_not (mask
);
6710 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6711 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6713 tem
= tem
.arshift (BITS_PER_UNIT
== 8
6714 ? 3 : exact_log2 (BITS_PER_UNIT
),
6715 HOST_BITS_PER_DOUBLE_INT
);
6716 offset
= size_binop (PLUS_EXPR
, offset
,
6717 double_int_to_tree (sizetype
, tem
));
6720 *pbitpos
= bit_offset
.to_shwi ();
6724 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6725 if (mode
== VOIDmode
6727 && (*pbitpos
% BITS_PER_UNIT
) == 0
6728 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6736 /* Return a tree of sizetype representing the size, in bytes, of the element
6737 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6740 array_ref_element_size (tree exp
)
6742 tree aligned_size
= TREE_OPERAND (exp
, 3);
6743 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6744 location_t loc
= EXPR_LOCATION (exp
);
6746 /* If a size was specified in the ARRAY_REF, it's the size measured
6747 in alignment units of the element type. So multiply by that value. */
6750 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6751 sizetype from another type of the same width and signedness. */
6752 if (TREE_TYPE (aligned_size
) != sizetype
)
6753 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6754 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6755 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6758 /* Otherwise, take the size from that of the element type. Substitute
6759 any PLACEHOLDER_EXPR that we have. */
6761 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6764 /* Return a tree representing the lower bound of the array mentioned in
6765 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6768 array_ref_low_bound (tree exp
)
6770 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6772 /* If a lower bound is specified in EXP, use it. */
6773 if (TREE_OPERAND (exp
, 2))
6774 return TREE_OPERAND (exp
, 2);
6776 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6777 substituting for a PLACEHOLDER_EXPR as needed. */
6778 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6779 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6781 /* Otherwise, return a zero of the appropriate type. */
6782 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6785 /* Returns true if REF is an array reference to an array at the end of
6786 a structure. If this is the case, the array may be allocated larger
6787 than its upper bound implies. */
6790 array_at_struct_end_p (tree ref
)
6792 if (TREE_CODE (ref
) != ARRAY_REF
6793 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6796 while (handled_component_p (ref
))
6798 /* If the reference chain contains a component reference to a
6799 non-union type and there follows another field the reference
6800 is not at the end of a structure. */
6801 if (TREE_CODE (ref
) == COMPONENT_REF
6802 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6804 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6805 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6806 nextf
= DECL_CHAIN (nextf
);
6811 ref
= TREE_OPERAND (ref
, 0);
6814 /* If the reference is based on a declared entity, the size of the array
6815 is constrained by its given domain. */
6822 /* Return a tree representing the upper bound of the array mentioned in
6823 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6826 array_ref_up_bound (tree exp
)
6828 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6830 /* If there is a domain type and it has an upper bound, use it, substituting
6831 for a PLACEHOLDER_EXPR as needed. */
6832 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6833 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6835 /* Otherwise fail. */
6839 /* Return a tree representing the offset, in bytes, of the field referenced
6840 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6843 component_ref_field_offset (tree exp
)
6845 tree aligned_offset
= TREE_OPERAND (exp
, 2);
6846 tree field
= TREE_OPERAND (exp
, 1);
6847 location_t loc
= EXPR_LOCATION (exp
);
6849 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6850 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6854 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6855 sizetype from another type of the same width and signedness. */
6856 if (TREE_TYPE (aligned_offset
) != sizetype
)
6857 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
6858 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
6859 size_int (DECL_OFFSET_ALIGN (field
)
6863 /* Otherwise, take the offset from that of the field. Substitute
6864 any PLACEHOLDER_EXPR that we have. */
6866 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
6869 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6871 static unsigned HOST_WIDE_INT
6872 target_align (const_tree target
)
6874 /* We might have a chain of nested references with intermediate misaligning
6875 bitfields components, so need to recurse to find out. */
6877 unsigned HOST_WIDE_INT this_align
, outer_align
;
6879 switch (TREE_CODE (target
))
6885 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
6886 outer_align
= target_align (TREE_OPERAND (target
, 0));
6887 return MIN (this_align
, outer_align
);
6890 case ARRAY_RANGE_REF
:
6891 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6892 outer_align
= target_align (TREE_OPERAND (target
, 0));
6893 return MIN (this_align
, outer_align
);
6896 case NON_LVALUE_EXPR
:
6897 case VIEW_CONVERT_EXPR
:
6898 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6899 outer_align
= target_align (TREE_OPERAND (target
, 0));
6900 return MAX (this_align
, outer_align
);
6903 return TYPE_ALIGN (TREE_TYPE (target
));
6908 /* Given an rtx VALUE that may contain additions and multiplications, return
6909 an equivalent value that just refers to a register, memory, or constant.
6910 This is done by generating instructions to perform the arithmetic and
6911 returning a pseudo-register containing the value.
6913 The returned value may be a REG, SUBREG, MEM or constant. */
6916 force_operand (rtx value
, rtx target
)
6919 /* Use subtarget as the target for operand 0 of a binary operation. */
6920 rtx subtarget
= get_subtarget (target
);
6921 enum rtx_code code
= GET_CODE (value
);
6923 /* Check for subreg applied to an expression produced by loop optimizer. */
6925 && !REG_P (SUBREG_REG (value
))
6926 && !MEM_P (SUBREG_REG (value
)))
6929 = simplify_gen_subreg (GET_MODE (value
),
6930 force_reg (GET_MODE (SUBREG_REG (value
)),
6931 force_operand (SUBREG_REG (value
),
6933 GET_MODE (SUBREG_REG (value
)),
6934 SUBREG_BYTE (value
));
6935 code
= GET_CODE (value
);
6938 /* Check for a PIC address load. */
6939 if ((code
== PLUS
|| code
== MINUS
)
6940 && XEXP (value
, 0) == pic_offset_table_rtx
6941 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
6942 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
6943 || GET_CODE (XEXP (value
, 1)) == CONST
))
6946 subtarget
= gen_reg_rtx (GET_MODE (value
));
6947 emit_move_insn (subtarget
, value
);
6951 if (ARITHMETIC_P (value
))
6953 op2
= XEXP (value
, 1);
6954 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
6956 if (code
== MINUS
&& CONST_INT_P (op2
))
6959 op2
= negate_rtx (GET_MODE (value
), op2
);
6962 /* Check for an addition with OP2 a constant integer and our first
6963 operand a PLUS of a virtual register and something else. In that
6964 case, we want to emit the sum of the virtual register and the
6965 constant first and then add the other value. This allows virtual
6966 register instantiation to simply modify the constant rather than
6967 creating another one around this addition. */
6968 if (code
== PLUS
&& CONST_INT_P (op2
)
6969 && GET_CODE (XEXP (value
, 0)) == PLUS
6970 && REG_P (XEXP (XEXP (value
, 0), 0))
6971 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
6972 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
6974 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
6975 XEXP (XEXP (value
, 0), 0), op2
,
6976 subtarget
, 0, OPTAB_LIB_WIDEN
);
6977 return expand_simple_binop (GET_MODE (value
), code
, temp
,
6978 force_operand (XEXP (XEXP (value
,
6980 target
, 0, OPTAB_LIB_WIDEN
);
6983 op1
= force_operand (XEXP (value
, 0), subtarget
);
6984 op2
= force_operand (op2
, NULL_RTX
);
6988 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
6990 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
6991 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
6992 target
, 1, OPTAB_LIB_WIDEN
);
6994 return expand_divmod (0,
6995 FLOAT_MODE_P (GET_MODE (value
))
6996 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
6997 GET_MODE (value
), op1
, op2
, target
, 0);
6999 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7002 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7005 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7008 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7009 target
, 0, OPTAB_LIB_WIDEN
);
7011 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7012 target
, 1, OPTAB_LIB_WIDEN
);
7015 if (UNARY_P (value
))
7018 target
= gen_reg_rtx (GET_MODE (value
));
7019 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7026 case FLOAT_TRUNCATE
:
7027 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7032 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7036 case UNSIGNED_FLOAT
:
7037 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7041 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7045 #ifdef INSN_SCHEDULING
7046 /* On machines that have insn scheduling, we want all memory reference to be
7047 explicit, so we need to deal with such paradoxical SUBREGs. */
7048 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7050 = simplify_gen_subreg (GET_MODE (value
),
7051 force_reg (GET_MODE (SUBREG_REG (value
)),
7052 force_operand (SUBREG_REG (value
),
7054 GET_MODE (SUBREG_REG (value
)),
7055 SUBREG_BYTE (value
));
7061 /* Subroutine of expand_expr: return nonzero iff there is no way that
7062 EXP can reference X, which is being modified. TOP_P is nonzero if this
7063 call is going to be used to determine whether we need a temporary
7064 for EXP, as opposed to a recursive call to this function.
7066 It is always safe for this routine to return zero since it merely
7067 searches for optimization opportunities. */
7070 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7076 /* If EXP has varying size, we MUST use a target since we currently
7077 have no way of allocating temporaries of variable size
7078 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7079 So we assume here that something at a higher level has prevented a
7080 clash. This is somewhat bogus, but the best we can do. Only
7081 do this when X is BLKmode and when we are at the top level. */
7082 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7083 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7084 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7085 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7086 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7088 && GET_MODE (x
) == BLKmode
)
7089 /* If X is in the outgoing argument area, it is always safe. */
7091 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7092 || (GET_CODE (XEXP (x
, 0)) == PLUS
7093 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7096 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7097 find the underlying pseudo. */
7098 if (GET_CODE (x
) == SUBREG
)
7101 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7105 /* Now look at our tree code and possibly recurse. */
7106 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7108 case tcc_declaration
:
7109 exp_rtl
= DECL_RTL_IF_SET (exp
);
7115 case tcc_exceptional
:
7116 if (TREE_CODE (exp
) == TREE_LIST
)
7120 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7122 exp
= TREE_CHAIN (exp
);
7125 if (TREE_CODE (exp
) != TREE_LIST
)
7126 return safe_from_p (x
, exp
, 0);
7129 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7131 constructor_elt
*ce
;
7132 unsigned HOST_WIDE_INT idx
;
7134 FOR_EACH_VEC_ELT (constructor_elt
, CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7135 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7136 || !safe_from_p (x
, ce
->value
, 0))
7140 else if (TREE_CODE (exp
) == ERROR_MARK
)
7141 return 1; /* An already-visited SAVE_EXPR? */
7146 /* The only case we look at here is the DECL_INITIAL inside a
7148 return (TREE_CODE (exp
) != DECL_EXPR
7149 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7150 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7151 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7154 case tcc_comparison
:
7155 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7160 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7162 case tcc_expression
:
7165 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7166 the expression. If it is set, we conflict iff we are that rtx or
7167 both are in memory. Otherwise, we check all operands of the
7168 expression recursively. */
7170 switch (TREE_CODE (exp
))
7173 /* If the operand is static or we are static, we can't conflict.
7174 Likewise if we don't conflict with the operand at all. */
7175 if (staticp (TREE_OPERAND (exp
, 0))
7176 || TREE_STATIC (exp
)
7177 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7180 /* Otherwise, the only way this can conflict is if we are taking
7181 the address of a DECL a that address if part of X, which is
7183 exp
= TREE_OPERAND (exp
, 0);
7186 if (!DECL_RTL_SET_P (exp
)
7187 || !MEM_P (DECL_RTL (exp
)))
7190 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7196 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7197 get_alias_set (exp
)))
7202 /* Assume that the call will clobber all hard registers and
7204 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7209 case WITH_CLEANUP_EXPR
:
7210 case CLEANUP_POINT_EXPR
:
7211 /* Lowered by gimplify.c. */
7215 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7221 /* If we have an rtx, we do not need to scan our operands. */
7225 nops
= TREE_OPERAND_LENGTH (exp
);
7226 for (i
= 0; i
< nops
; i
++)
7227 if (TREE_OPERAND (exp
, i
) != 0
7228 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7234 /* Should never get a type here. */
7238 /* If we have an rtl, find any enclosed object. Then see if we conflict
7242 if (GET_CODE (exp_rtl
) == SUBREG
)
7244 exp_rtl
= SUBREG_REG (exp_rtl
);
7246 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7250 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7251 are memory and they conflict. */
7252 return ! (rtx_equal_p (x
, exp_rtl
)
7253 || (MEM_P (x
) && MEM_P (exp_rtl
)
7254 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7257 /* If we reach here, it is safe. */
7262 /* Return the highest power of two that EXP is known to be a multiple of.
7263 This is used in updating alignment of MEMs in array references. */
7265 unsigned HOST_WIDE_INT
7266 highest_pow2_factor (const_tree exp
)
7268 unsigned HOST_WIDE_INT c0
, c1
;
7270 switch (TREE_CODE (exp
))
7273 /* We can find the lowest bit that's a one. If the low
7274 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
7275 We need to handle this case since we can find it in a COND_EXPR,
7276 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
7277 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
7279 if (TREE_OVERFLOW (exp
))
7280 return BIGGEST_ALIGNMENT
;
7283 /* Note: tree_low_cst is intentionally not used here,
7284 we don't care about the upper bits. */
7285 c0
= TREE_INT_CST_LOW (exp
);
7287 return c0
? c0
: BIGGEST_ALIGNMENT
;
7291 case PLUS_EXPR
: case MINUS_EXPR
: case MIN_EXPR
: case MAX_EXPR
:
7292 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7293 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7294 return MIN (c0
, c1
);
7297 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7298 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7301 case ROUND_DIV_EXPR
: case TRUNC_DIV_EXPR
: case FLOOR_DIV_EXPR
:
7303 if (integer_pow2p (TREE_OPERAND (exp
, 1))
7304 && host_integerp (TREE_OPERAND (exp
, 1), 1))
7306 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7307 c1
= tree_low_cst (TREE_OPERAND (exp
, 1), 1);
7308 return MAX (1, c0
/ c1
);
7313 /* The highest power of two of a bit-and expression is the maximum of
7314 that of its operands. We typically get here for a complex LHS and
7315 a constant negative power of two on the RHS to force an explicit
7316 alignment, so don't bother looking at the LHS. */
7317 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7321 return highest_pow2_factor (TREE_OPERAND (exp
, 0));
7324 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7327 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7328 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 2));
7329 return MIN (c0
, c1
);
7338 /* Similar, except that the alignment requirements of TARGET are
7339 taken into account. Assume it is at least as aligned as its
7340 type, unless it is a COMPONENT_REF in which case the layout of
7341 the structure gives the alignment. */
7343 static unsigned HOST_WIDE_INT
7344 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7346 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7347 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7349 return MAX (factor
, talign
);
7352 #ifdef HAVE_conditional_move
7353 /* Convert the tree comparison code TCODE to the rtl one where the
7354 signedness is UNSIGNEDP. */
7356 static enum rtx_code
7357 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7369 code
= unsignedp
? LTU
: LT
;
7372 code
= unsignedp
? LEU
: LE
;
7375 code
= unsignedp
? GTU
: GT
;
7378 code
= unsignedp
? GEU
: GE
;
7380 case UNORDERED_EXPR
:
7412 /* Subroutine of expand_expr. Expand the two operands of a binary
7413 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7414 The value may be stored in TARGET if TARGET is nonzero. The
7415 MODIFIER argument is as documented by expand_expr. */
7418 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7419 enum expand_modifier modifier
)
7421 if (! safe_from_p (target
, exp1
, 1))
7423 if (operand_equal_p (exp0
, exp1
, 0))
7425 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7426 *op1
= copy_rtx (*op0
);
7430 /* If we need to preserve evaluation order, copy exp0 into its own
7431 temporary variable so that it can't be clobbered by exp1. */
7432 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7433 exp0
= save_expr (exp0
);
7434 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7435 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7440 /* Return a MEM that contains constant EXP. DEFER is as for
7441 output_constant_def and MODIFIER is as for expand_expr. */
7444 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7448 mem
= output_constant_def (exp
, defer
);
7449 if (modifier
!= EXPAND_INITIALIZER
)
7450 mem
= use_anchored_address (mem
);
7454 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7455 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7458 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7459 enum expand_modifier modifier
, addr_space_t as
)
7461 rtx result
, subtarget
;
7463 HOST_WIDE_INT bitsize
, bitpos
;
7464 int volatilep
, unsignedp
;
7465 enum machine_mode mode1
;
7467 /* If we are taking the address of a constant and are at the top level,
7468 we have to use output_constant_def since we can't call force_const_mem
7470 /* ??? This should be considered a front-end bug. We should not be
7471 generating ADDR_EXPR of something that isn't an LVALUE. The only
7472 exception here is STRING_CST. */
7473 if (CONSTANT_CLASS_P (exp
))
7475 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7476 if (modifier
< EXPAND_SUM
)
7477 result
= force_operand (result
, target
);
7481 /* Everything must be something allowed by is_gimple_addressable. */
7482 switch (TREE_CODE (exp
))
7485 /* This case will happen via recursion for &a->b. */
7486 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7490 tree tem
= TREE_OPERAND (exp
, 0);
7491 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7492 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7493 return expand_expr (tem
, target
, tmode
, modifier
);
7497 /* Expand the initializer like constants above. */
7498 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7500 if (modifier
< EXPAND_SUM
)
7501 result
= force_operand (result
, target
);
7505 /* The real part of the complex number is always first, therefore
7506 the address is the same as the address of the parent object. */
7509 inner
= TREE_OPERAND (exp
, 0);
7513 /* The imaginary part of the complex number is always second.
7514 The expression is therefore always offset by the size of the
7517 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7518 inner
= TREE_OPERAND (exp
, 0);
7522 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7523 expand_expr, as that can have various side effects; LABEL_DECLs for
7524 example, may not have their DECL_RTL set yet. Expand the rtl of
7525 CONSTRUCTORs too, which should yield a memory reference for the
7526 constructor's contents. Assume language specific tree nodes can
7527 be expanded in some interesting way. */
7528 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7530 || TREE_CODE (exp
) == CONSTRUCTOR
7531 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7533 result
= expand_expr (exp
, target
, tmode
,
7534 modifier
== EXPAND_INITIALIZER
7535 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7537 /* If the DECL isn't in memory, then the DECL wasn't properly
7538 marked TREE_ADDRESSABLE, which will be either a front-end
7539 or a tree optimizer bug. */
7541 if (TREE_ADDRESSABLE (exp
)
7543 && ! targetm
.calls
.allocate_stack_slots_for_args())
7545 error ("local frame unavailable (naked function?)");
7549 gcc_assert (MEM_P (result
));
7550 result
= XEXP (result
, 0);
7552 /* ??? Is this needed anymore? */
7554 TREE_USED (exp
) = 1;
7556 if (modifier
!= EXPAND_INITIALIZER
7557 && modifier
!= EXPAND_CONST_ADDRESS
7558 && modifier
!= EXPAND_SUM
)
7559 result
= force_operand (result
, target
);
7563 /* Pass FALSE as the last argument to get_inner_reference although
7564 we are expanding to RTL. The rationale is that we know how to
7565 handle "aligning nodes" here: we can just bypass them because
7566 they won't change the final object whose address will be returned
7567 (they actually exist only for that purpose). */
7568 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7569 &mode1
, &unsignedp
, &volatilep
, false);
7573 /* We must have made progress. */
7574 gcc_assert (inner
!= exp
);
7576 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7577 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7578 inner alignment, force the inner to be sufficiently aligned. */
7579 if (CONSTANT_CLASS_P (inner
)
7580 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7582 inner
= copy_node (inner
);
7583 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7584 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7585 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7587 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7593 if (modifier
!= EXPAND_NORMAL
)
7594 result
= force_operand (result
, NULL
);
7595 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7596 modifier
== EXPAND_INITIALIZER
7597 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7599 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7600 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7602 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7603 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7606 subtarget
= bitpos
? NULL_RTX
: target
;
7607 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7608 1, OPTAB_LIB_WIDEN
);
7614 /* Someone beforehand should have rejected taking the address
7615 of such an object. */
7616 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7618 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7619 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7620 if (modifier
< EXPAND_SUM
)
7621 result
= force_operand (result
, target
);
7627 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7628 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7631 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7632 enum expand_modifier modifier
)
7634 addr_space_t as
= ADDR_SPACE_GENERIC
;
7635 enum machine_mode address_mode
= Pmode
;
7636 enum machine_mode pointer_mode
= ptr_mode
;
7637 enum machine_mode rmode
;
7640 /* Target mode of VOIDmode says "whatever's natural". */
7641 if (tmode
== VOIDmode
)
7642 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7644 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7646 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7647 address_mode
= targetm
.addr_space
.address_mode (as
);
7648 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7651 /* We can get called with some Weird Things if the user does silliness
7652 like "(short) &a". In that case, convert_memory_address won't do
7653 the right thing, so ignore the given target mode. */
7654 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7655 tmode
= address_mode
;
7657 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7658 tmode
, modifier
, as
);
7660 /* Despite expand_expr claims concerning ignoring TMODE when not
7661 strictly convenient, stuff breaks if we don't honor it. Note
7662 that combined with the above, we only do this for pointer modes. */
7663 rmode
= GET_MODE (result
);
7664 if (rmode
== VOIDmode
)
7667 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7672 /* Generate code for computing CONSTRUCTOR EXP.
7673 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7674 is TRUE, instead of creating a temporary variable in memory
7675 NULL is returned and the caller needs to handle it differently. */
7678 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7679 bool avoid_temp_mem
)
7681 tree type
= TREE_TYPE (exp
);
7682 enum machine_mode mode
= TYPE_MODE (type
);
7684 /* Try to avoid creating a temporary at all. This is possible
7685 if all of the initializer is zero.
7686 FIXME: try to handle all [0..255] initializers we can handle
7688 if (TREE_STATIC (exp
)
7689 && !TREE_ADDRESSABLE (exp
)
7690 && target
!= 0 && mode
== BLKmode
7691 && all_zeros_p (exp
))
7693 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7697 /* All elts simple constants => refer to a constant in memory. But
7698 if this is a non-BLKmode mode, let it store a field at a time
7699 since that should make a CONST_INT or CONST_DOUBLE when we
7700 fold. Likewise, if we have a target we can use, it is best to
7701 store directly into the target unless the type is large enough
7702 that memcpy will be used. If we are making an initializer and
7703 all operands are constant, put it in memory as well.
7705 FIXME: Avoid trying to fill vector constructors piece-meal.
7706 Output them with output_constant_def below unless we're sure
7707 they're zeros. This should go away when vector initializers
7708 are treated like VECTOR_CST instead of arrays. */
7709 if ((TREE_STATIC (exp
)
7710 && ((mode
== BLKmode
7711 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7712 || TREE_ADDRESSABLE (exp
)
7713 || (host_integerp (TYPE_SIZE_UNIT (type
), 1)
7714 && (! MOVE_BY_PIECES_P
7715 (tree_low_cst (TYPE_SIZE_UNIT (type
), 1),
7717 && ! mostly_zeros_p (exp
))))
7718 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7719 && TREE_CONSTANT (exp
)))
7726 constructor
= expand_expr_constant (exp
, 1, modifier
);
7728 if (modifier
!= EXPAND_CONST_ADDRESS
7729 && modifier
!= EXPAND_INITIALIZER
7730 && modifier
!= EXPAND_SUM
)
7731 constructor
= validize_mem (constructor
);
7736 /* Handle calls that pass values in multiple non-contiguous
7737 locations. The Irix 6 ABI has examples of this. */
7738 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7739 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7745 = assign_temp (build_qualified_type (type
, (TYPE_QUALS (type
)
7746 | (TREE_READONLY (exp
)
7747 * TYPE_QUAL_CONST
))),
7748 TREE_ADDRESSABLE (exp
), 1);
7751 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7756 /* expand_expr: generate code for computing expression EXP.
7757 An rtx for the computed value is returned. The value is never null.
7758 In the case of a void EXP, const0_rtx is returned.
7760 The value may be stored in TARGET if TARGET is nonzero.
7761 TARGET is just a suggestion; callers must assume that
7762 the rtx returned may not be the same as TARGET.
7764 If TARGET is CONST0_RTX, it means that the value will be ignored.
7766 If TMODE is not VOIDmode, it suggests generating the
7767 result in mode TMODE. But this is done only when convenient.
7768 Otherwise, TMODE is ignored and the value generated in its natural mode.
7769 TMODE is just a suggestion; callers must assume that
7770 the rtx returned may not have mode TMODE.
7772 Note that TARGET may have neither TMODE nor MODE. In that case, it
7773 probably will not be used.
7775 If MODIFIER is EXPAND_SUM then when EXP is an addition
7776 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7777 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7778 products as above, or REG or MEM, or constant.
7779 Ordinarily in such cases we would output mul or add instructions
7780 and then return a pseudo reg containing the sum.
7782 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7783 it also marks a label as absolutely required (it can't be dead).
7784 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7785 This is used for outputting expressions used in initializers.
7787 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7788 with a constant address even if that address is not normally legitimate.
7789 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7791 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7792 a call parameter. Such targets require special care as we haven't yet
7793 marked TARGET so that it's safe from being trashed by libcalls. We
7794 don't want to use TARGET for anything but the final result;
7795 Intermediate values must go elsewhere. Additionally, calls to
7796 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7798 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7799 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7800 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7801 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7805 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7806 enum expand_modifier modifier
, rtx
*alt_rtl
)
7810 /* Handle ERROR_MARK before anybody tries to access its type. */
7811 if (TREE_CODE (exp
) == ERROR_MARK
7812 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7814 ret
= CONST0_RTX (tmode
);
7815 return ret
? ret
: const0_rtx
;
7818 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7822 /* Try to expand the conditional expression which is represented by
7823 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7824 return the rtl reg which repsents the result. Otherwise return
7828 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7829 tree treeop1 ATTRIBUTE_UNUSED
,
7830 tree treeop2 ATTRIBUTE_UNUSED
)
7832 #ifdef HAVE_conditional_move
7834 rtx op00
, op01
, op1
, op2
;
7835 enum rtx_code comparison_code
;
7836 enum machine_mode comparison_mode
;
7839 tree type
= TREE_TYPE (treeop1
);
7840 int unsignedp
= TYPE_UNSIGNED (type
);
7841 enum machine_mode mode
= TYPE_MODE (type
);
7843 /* If we cannot do a conditional move on the mode, try doing it
7844 with the promoted mode. */
7845 if (!can_conditionally_move_p (mode
))
7847 mode
= promote_mode (type
, mode
, &unsignedp
);
7848 if (!can_conditionally_move_p (mode
))
7850 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7853 temp
= assign_temp (type
, 0, 1);
7856 expand_operands (treeop1
, treeop2
,
7857 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7859 if (TREE_CODE (treeop0
) == SSA_NAME
7860 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7862 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7863 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7864 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7865 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7866 comparison_mode
= TYPE_MODE (type
);
7867 unsignedp
= TYPE_UNSIGNED (type
);
7868 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7870 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7872 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7873 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7874 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7875 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7876 unsignedp
= TYPE_UNSIGNED (type
);
7877 comparison_mode
= TYPE_MODE (type
);
7878 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7882 op00
= expand_normal (treeop0
);
7884 comparison_code
= NE
;
7885 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7888 if (GET_MODE (op1
) != mode
)
7889 op1
= gen_lowpart (mode
, op1
);
7891 if (GET_MODE (op2
) != mode
)
7892 op2
= gen_lowpart (mode
, op2
);
7894 /* Try to emit the conditional move. */
7895 insn
= emit_conditional_move (temp
, comparison_code
,
7896 op00
, op01
, comparison_mode
,
7900 /* If we could do the conditional move, emit the sequence,
7904 rtx seq
= get_insns ();
7910 /* Otherwise discard the sequence and fall back to code with
7918 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
7919 enum expand_modifier modifier
)
7921 rtx op0
, op1
, op2
, temp
;
7924 enum machine_mode mode
;
7925 enum tree_code code
= ops
->code
;
7927 rtx subtarget
, original_target
;
7929 bool reduce_bit_field
;
7930 location_t loc
= ops
->location
;
7931 tree treeop0
, treeop1
, treeop2
;
7932 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
7933 ? reduce_to_bit_field_precision ((expr), \
7939 mode
= TYPE_MODE (type
);
7940 unsignedp
= TYPE_UNSIGNED (type
);
7946 /* We should be called only on simple (binary or unary) expressions,
7947 exactly those that are valid in gimple expressions that aren't
7948 GIMPLE_SINGLE_RHS (or invalid). */
7949 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
7950 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
7951 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
7953 ignore
= (target
== const0_rtx
7954 || ((CONVERT_EXPR_CODE_P (code
)
7955 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
7956 && TREE_CODE (type
) == VOID_TYPE
));
7958 /* We should be called only if we need the result. */
7959 gcc_assert (!ignore
);
7961 /* An operation in what may be a bit-field type needs the
7962 result to be reduced to the precision of the bit-field type,
7963 which is narrower than that of the type's mode. */
7964 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
7965 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
7967 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
7970 /* Use subtarget as the target for operand 0 of a binary operation. */
7971 subtarget
= get_subtarget (target
);
7972 original_target
= target
;
7976 case NON_LVALUE_EXPR
:
7979 if (treeop0
== error_mark_node
)
7982 if (TREE_CODE (type
) == UNION_TYPE
)
7984 tree valtype
= TREE_TYPE (treeop0
);
7986 /* If both input and output are BLKmode, this conversion isn't doing
7987 anything except possibly changing memory attribute. */
7988 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
7990 rtx result
= expand_expr (treeop0
, target
, tmode
,
7993 result
= copy_rtx (result
);
7994 set_mem_attributes (result
, type
, 0);
8000 if (TYPE_MODE (type
) != BLKmode
)
8001 target
= gen_reg_rtx (TYPE_MODE (type
));
8003 target
= assign_temp (type
, 1, 1);
8007 /* Store data into beginning of memory target. */
8008 store_expr (treeop0
,
8009 adjust_address (target
, TYPE_MODE (valtype
), 0),
8010 modifier
== EXPAND_STACK_PARM
,
8015 gcc_assert (REG_P (target
));
8017 /* Store this field into a union of the proper type. */
8018 store_field (target
,
8019 MIN ((int_size_in_bytes (TREE_TYPE
8022 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8023 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8026 /* Return the entire union. */
8030 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8032 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8035 /* If the signedness of the conversion differs and OP0 is
8036 a promoted SUBREG, clear that indication since we now
8037 have to do the proper extension. */
8038 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8039 && GET_CODE (op0
) == SUBREG
)
8040 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8042 return REDUCE_BIT_FIELD (op0
);
8045 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8046 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8047 if (GET_MODE (op0
) == mode
)
8050 /* If OP0 is a constant, just convert it into the proper mode. */
8051 else if (CONSTANT_P (op0
))
8053 tree inner_type
= TREE_TYPE (treeop0
);
8054 enum machine_mode inner_mode
= GET_MODE (op0
);
8056 if (inner_mode
== VOIDmode
)
8057 inner_mode
= TYPE_MODE (inner_type
);
8059 if (modifier
== EXPAND_INITIALIZER
)
8060 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8061 subreg_lowpart_offset (mode
,
8064 op0
= convert_modes (mode
, inner_mode
, op0
,
8065 TYPE_UNSIGNED (inner_type
));
8068 else if (modifier
== EXPAND_INITIALIZER
)
8069 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8071 else if (target
== 0)
8072 op0
= convert_to_mode (mode
, op0
,
8073 TYPE_UNSIGNED (TREE_TYPE
8077 convert_move (target
, op0
,
8078 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8082 return REDUCE_BIT_FIELD (op0
);
8084 case ADDR_SPACE_CONVERT_EXPR
:
8086 tree treeop0_type
= TREE_TYPE (treeop0
);
8088 addr_space_t as_from
;
8090 gcc_assert (POINTER_TYPE_P (type
));
8091 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8093 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8094 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8096 /* Conversions between pointers to the same address space should
8097 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8098 gcc_assert (as_to
!= as_from
);
8100 /* Ask target code to handle conversion between pointers
8101 to overlapping address spaces. */
8102 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8103 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8105 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8106 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8111 /* For disjoint address spaces, converting anything but
8112 a null pointer invokes undefined behaviour. We simply
8113 always return a null pointer here. */
8114 return CONST0_RTX (mode
);
8117 case POINTER_PLUS_EXPR
:
8118 /* Even though the sizetype mode and the pointer's mode can be different
8119 expand is able to handle this correctly and get the correct result out
8120 of the PLUS_EXPR code. */
8121 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8122 if sizetype precision is smaller than pointer precision. */
8123 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8124 treeop1
= fold_convert_loc (loc
, type
,
8125 fold_convert_loc (loc
, ssizetype
,
8127 /* If sizetype precision is larger than pointer precision, truncate the
8128 offset to have matching modes. */
8129 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8130 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8133 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8134 something else, make sure we add the register to the constant and
8135 then to the other thing. This case can occur during strength
8136 reduction and doing it this way will produce better code if the
8137 frame pointer or argument pointer is eliminated.
8139 fold-const.c will ensure that the constant is always in the inner
8140 PLUS_EXPR, so the only case we need to do anything about is if
8141 sp, ap, or fp is our second argument, in which case we must swap
8142 the innermost first argument and our second argument. */
8144 if (TREE_CODE (treeop0
) == PLUS_EXPR
8145 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8146 && TREE_CODE (treeop1
) == VAR_DECL
8147 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8148 || DECL_RTL (treeop1
) == stack_pointer_rtx
8149 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8154 /* If the result is to be ptr_mode and we are adding an integer to
8155 something, we might be forming a constant. So try to use
8156 plus_constant. If it produces a sum and we can't accept it,
8157 use force_operand. This allows P = &ARR[const] to generate
8158 efficient code on machines where a SYMBOL_REF is not a valid
8161 If this is an EXPAND_SUM call, always return the sum. */
8162 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8163 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8165 if (modifier
== EXPAND_STACK_PARM
)
8167 if (TREE_CODE (treeop0
) == INTEGER_CST
8168 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8169 && TREE_CONSTANT (treeop1
))
8173 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8175 /* Use immed_double_const to ensure that the constant is
8176 truncated according to the mode of OP1, then sign extended
8177 to a HOST_WIDE_INT. Using the constant directly can result
8178 in non-canonical RTL in a 64x32 cross compile. */
8180 = immed_double_const (TREE_INT_CST_LOW (treeop0
),
8182 TYPE_MODE (TREE_TYPE (treeop1
)));
8183 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8184 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8185 op1
= force_operand (op1
, target
);
8186 return REDUCE_BIT_FIELD (op1
);
8189 else if (TREE_CODE (treeop1
) == INTEGER_CST
8190 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8191 && TREE_CONSTANT (treeop0
))
8195 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8196 (modifier
== EXPAND_INITIALIZER
8197 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8198 if (! CONSTANT_P (op0
))
8200 op1
= expand_expr (treeop1
, NULL_RTX
,
8201 VOIDmode
, modifier
);
8202 /* Return a PLUS if modifier says it's OK. */
8203 if (modifier
== EXPAND_SUM
8204 || modifier
== EXPAND_INITIALIZER
)
8205 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8208 /* Use immed_double_const to ensure that the constant is
8209 truncated according to the mode of OP1, then sign extended
8210 to a HOST_WIDE_INT. Using the constant directly can result
8211 in non-canonical RTL in a 64x32 cross compile. */
8213 = immed_double_const (TREE_INT_CST_LOW (treeop1
),
8215 TYPE_MODE (TREE_TYPE (treeop0
)));
8216 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8217 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8218 op0
= force_operand (op0
, target
);
8219 return REDUCE_BIT_FIELD (op0
);
8223 /* Use TER to expand pointer addition of a negated value
8224 as pointer subtraction. */
8225 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8226 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8227 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8228 && TREE_CODE (treeop1
) == SSA_NAME
8229 && TYPE_MODE (TREE_TYPE (treeop0
))
8230 == TYPE_MODE (TREE_TYPE (treeop1
)))
8232 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8235 treeop1
= gimple_assign_rhs1 (def
);
8241 /* No sense saving up arithmetic to be done
8242 if it's all in the wrong mode to form part of an address.
8243 And force_operand won't know whether to sign-extend or
8245 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8246 || mode
!= ptr_mode
)
8248 expand_operands (treeop0
, treeop1
,
8249 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8250 if (op0
== const0_rtx
)
8252 if (op1
== const0_rtx
)
8257 expand_operands (treeop0
, treeop1
,
8258 subtarget
, &op0
, &op1
, modifier
);
8259 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8263 /* For initializers, we are allowed to return a MINUS of two
8264 symbolic constants. Here we handle all cases when both operands
8266 /* Handle difference of two symbolic constants,
8267 for the sake of an initializer. */
8268 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8269 && really_constant_p (treeop0
)
8270 && really_constant_p (treeop1
))
8272 expand_operands (treeop0
, treeop1
,
8273 NULL_RTX
, &op0
, &op1
, modifier
);
8275 /* If the last operand is a CONST_INT, use plus_constant of
8276 the negated constant. Else make the MINUS. */
8277 if (CONST_INT_P (op1
))
8278 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8281 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8284 /* No sense saving up arithmetic to be done
8285 if it's all in the wrong mode to form part of an address.
8286 And force_operand won't know whether to sign-extend or
8288 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8289 || mode
!= ptr_mode
)
8292 expand_operands (treeop0
, treeop1
,
8293 subtarget
, &op0
, &op1
, modifier
);
8295 /* Convert A - const to A + (-const). */
8296 if (CONST_INT_P (op1
))
8298 op1
= negate_rtx (mode
, op1
);
8299 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8304 case WIDEN_MULT_PLUS_EXPR
:
8305 case WIDEN_MULT_MINUS_EXPR
:
8306 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8307 op2
= expand_normal (treeop2
);
8308 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8312 case WIDEN_MULT_EXPR
:
8313 /* If first operand is constant, swap them.
8314 Thus the following special case checks need only
8315 check the second operand. */
8316 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8323 /* First, check if we have a multiplication of one signed and one
8324 unsigned operand. */
8325 if (TREE_CODE (treeop1
) != INTEGER_CST
8326 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8327 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8329 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8330 this_optab
= usmul_widen_optab
;
8331 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8332 != CODE_FOR_nothing
)
8334 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8335 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8338 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8343 /* Check for a multiplication with matching signedness. */
8344 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8345 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8346 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8347 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8349 tree op0type
= TREE_TYPE (treeop0
);
8350 enum machine_mode innermode
= TYPE_MODE (op0type
);
8351 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8352 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8353 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8355 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8357 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8358 != CODE_FOR_nothing
)
8360 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8362 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8363 unsignedp
, this_optab
);
8364 return REDUCE_BIT_FIELD (temp
);
8366 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8368 && innermode
== word_mode
)
8371 op0
= expand_normal (treeop0
);
8372 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8373 op1
= convert_modes (innermode
, mode
,
8374 expand_normal (treeop1
), unsignedp
);
8376 op1
= expand_normal (treeop1
);
8377 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8378 unsignedp
, OPTAB_LIB_WIDEN
);
8379 hipart
= gen_highpart (innermode
, temp
);
8380 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8384 emit_move_insn (hipart
, htem
);
8385 return REDUCE_BIT_FIELD (temp
);
8389 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8390 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8391 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8392 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8396 optab opt
= fma_optab
;
8399 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8401 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8403 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8406 gcc_assert (fn
!= NULL_TREE
);
8407 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8408 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8411 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8412 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8417 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8420 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8421 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8424 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8427 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8430 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8433 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8437 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8439 op2
= expand_normal (treeop2
);
8440 op1
= expand_normal (treeop1
);
8442 return expand_ternary_op (TYPE_MODE (type
), opt
,
8443 op0
, op1
, op2
, target
, 0);
8447 /* If this is a fixed-point operation, then we cannot use the code
8448 below because "expand_mult" doesn't support sat/no-sat fixed-point
8450 if (ALL_FIXED_POINT_MODE_P (mode
))
8453 /* If first operand is constant, swap them.
8454 Thus the following special case checks need only
8455 check the second operand. */
8456 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8463 /* Attempt to return something suitable for generating an
8464 indexed address, for machines that support that. */
8466 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8467 && host_integerp (treeop1
, 0))
8469 tree exp1
= treeop1
;
8471 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8475 op0
= force_operand (op0
, NULL_RTX
);
8477 op0
= copy_to_mode_reg (mode
, op0
);
8479 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8480 gen_int_mode (tree_low_cst (exp1
, 0),
8481 TYPE_MODE (TREE_TYPE (exp1
)))));
8484 if (modifier
== EXPAND_STACK_PARM
)
8487 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8488 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8490 case TRUNC_DIV_EXPR
:
8491 case FLOOR_DIV_EXPR
:
8493 case ROUND_DIV_EXPR
:
8494 case EXACT_DIV_EXPR
:
8495 /* If this is a fixed-point operation, then we cannot use the code
8496 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8498 if (ALL_FIXED_POINT_MODE_P (mode
))
8501 if (modifier
== EXPAND_STACK_PARM
)
8503 /* Possible optimization: compute the dividend with EXPAND_SUM
8504 then if the divisor is constant can optimize the case
8505 where some terms of the dividend have coeffs divisible by it. */
8506 expand_operands (treeop0
, treeop1
,
8507 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8508 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8513 case MULT_HIGHPART_EXPR
:
8514 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8515 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8519 case TRUNC_MOD_EXPR
:
8520 case FLOOR_MOD_EXPR
:
8522 case ROUND_MOD_EXPR
:
8523 if (modifier
== EXPAND_STACK_PARM
)
8525 expand_operands (treeop0
, treeop1
,
8526 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8527 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8529 case FIXED_CONVERT_EXPR
:
8530 op0
= expand_normal (treeop0
);
8531 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8532 target
= gen_reg_rtx (mode
);
8534 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8535 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8536 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8537 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8539 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8542 case FIX_TRUNC_EXPR
:
8543 op0
= expand_normal (treeop0
);
8544 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8545 target
= gen_reg_rtx (mode
);
8546 expand_fix (target
, op0
, unsignedp
);
8550 op0
= expand_normal (treeop0
);
8551 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8552 target
= gen_reg_rtx (mode
);
8553 /* expand_float can't figure out what to do if FROM has VOIDmode.
8554 So give it the correct mode. With -O, cse will optimize this. */
8555 if (GET_MODE (op0
) == VOIDmode
)
8556 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8558 expand_float (target
, op0
,
8559 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8563 op0
= expand_expr (treeop0
, subtarget
,
8564 VOIDmode
, EXPAND_NORMAL
);
8565 if (modifier
== EXPAND_STACK_PARM
)
8567 temp
= expand_unop (mode
,
8568 optab_for_tree_code (NEGATE_EXPR
, type
,
8572 return REDUCE_BIT_FIELD (temp
);
8575 op0
= expand_expr (treeop0
, subtarget
,
8576 VOIDmode
, EXPAND_NORMAL
);
8577 if (modifier
== EXPAND_STACK_PARM
)
8580 /* ABS_EXPR is not valid for complex arguments. */
8581 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8582 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8584 /* Unsigned abs is simply the operand. Testing here means we don't
8585 risk generating incorrect code below. */
8586 if (TYPE_UNSIGNED (type
))
8589 return expand_abs (mode
, op0
, target
, unsignedp
,
8590 safe_from_p (target
, treeop0
, 1));
8594 target
= original_target
;
8596 || modifier
== EXPAND_STACK_PARM
8597 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8598 || GET_MODE (target
) != mode
8600 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8601 target
= gen_reg_rtx (mode
);
8602 expand_operands (treeop0
, treeop1
,
8603 target
, &op0
, &op1
, EXPAND_NORMAL
);
8605 /* First try to do it with a special MIN or MAX instruction.
8606 If that does not win, use a conditional jump to select the proper
8608 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8609 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8614 /* At this point, a MEM target is no longer useful; we will get better
8617 if (! REG_P (target
))
8618 target
= gen_reg_rtx (mode
);
8620 /* If op1 was placed in target, swap op0 and op1. */
8621 if (target
!= op0
&& target
== op1
)
8628 /* We generate better code and avoid problems with op1 mentioning
8629 target by forcing op1 into a pseudo if it isn't a constant. */
8630 if (! CONSTANT_P (op1
))
8631 op1
= force_reg (mode
, op1
);
8634 enum rtx_code comparison_code
;
8637 if (code
== MAX_EXPR
)
8638 comparison_code
= unsignedp
? GEU
: GE
;
8640 comparison_code
= unsignedp
? LEU
: LE
;
8642 /* Canonicalize to comparisons against 0. */
8643 if (op1
== const1_rtx
)
8645 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8646 or (a != 0 ? a : 1) for unsigned.
8647 For MIN we are safe converting (a <= 1 ? a : 1)
8648 into (a <= 0 ? a : 1) */
8649 cmpop1
= const0_rtx
;
8650 if (code
== MAX_EXPR
)
8651 comparison_code
= unsignedp
? NE
: GT
;
8653 if (op1
== constm1_rtx
&& !unsignedp
)
8655 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8656 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8657 cmpop1
= const0_rtx
;
8658 if (code
== MIN_EXPR
)
8659 comparison_code
= LT
;
8661 #ifdef HAVE_conditional_move
8662 /* Use a conditional move if possible. */
8663 if (can_conditionally_move_p (mode
))
8667 /* ??? Same problem as in expmed.c: emit_conditional_move
8668 forces a stack adjustment via compare_from_rtx, and we
8669 lose the stack adjustment if the sequence we are about
8670 to create is discarded. */
8671 do_pending_stack_adjust ();
8675 /* Try to emit the conditional move. */
8676 insn
= emit_conditional_move (target
, comparison_code
,
8681 /* If we could do the conditional move, emit the sequence,
8685 rtx seq
= get_insns ();
8691 /* Otherwise discard the sequence and fall back to code with
8697 emit_move_insn (target
, op0
);
8699 temp
= gen_label_rtx ();
8700 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8701 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8704 emit_move_insn (target
, op1
);
8709 op0
= expand_expr (treeop0
, subtarget
,
8710 VOIDmode
, EXPAND_NORMAL
);
8711 if (modifier
== EXPAND_STACK_PARM
)
8713 /* In case we have to reduce the result to bitfield precision
8714 for unsigned bitfield expand this as XOR with a proper constant
8716 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8717 temp
= expand_binop (mode
, xor_optab
, op0
,
8718 immed_double_int_const
8719 (double_int::mask (TYPE_PRECISION (type
)), mode
),
8720 target
, 1, OPTAB_LIB_WIDEN
);
8722 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8726 /* ??? Can optimize bitwise operations with one arg constant.
8727 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8728 and (a bitwise1 b) bitwise2 b (etc)
8729 but that is probably not worth while. */
8738 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8739 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8740 == TYPE_PRECISION (type
)));
8745 /* If this is a fixed-point operation, then we cannot use the code
8746 below because "expand_shift" doesn't support sat/no-sat fixed-point
8748 if (ALL_FIXED_POINT_MODE_P (mode
))
8751 if (! safe_from_p (subtarget
, treeop1
, 1))
8753 if (modifier
== EXPAND_STACK_PARM
)
8755 op0
= expand_expr (treeop0
, subtarget
,
8756 VOIDmode
, EXPAND_NORMAL
);
8757 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8759 if (code
== LSHIFT_EXPR
)
8760 temp
= REDUCE_BIT_FIELD (temp
);
8763 /* Could determine the answer when only additive constants differ. Also,
8764 the addition of one can be handled by changing the condition. */
8771 case UNORDERED_EXPR
:
8779 temp
= do_store_flag (ops
,
8780 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8781 tmode
!= VOIDmode
? tmode
: mode
);
8785 /* Use a compare and a jump for BLKmode comparisons, or for function
8786 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8789 || modifier
== EXPAND_STACK_PARM
8790 || ! safe_from_p (target
, treeop0
, 1)
8791 || ! safe_from_p (target
, treeop1
, 1)
8792 /* Make sure we don't have a hard reg (such as function's return
8793 value) live across basic blocks, if not optimizing. */
8794 || (!optimize
&& REG_P (target
)
8795 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8796 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8798 emit_move_insn (target
, const0_rtx
);
8800 op1
= gen_label_rtx ();
8801 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8803 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8804 emit_move_insn (target
, constm1_rtx
);
8806 emit_move_insn (target
, const1_rtx
);
8812 /* Get the rtx code of the operands. */
8813 op0
= expand_normal (treeop0
);
8814 op1
= expand_normal (treeop1
);
8817 target
= gen_reg_rtx (TYPE_MODE (type
));
8819 /* Move the real (op0) and imaginary (op1) parts to their location. */
8820 write_complex_part (target
, op0
, false);
8821 write_complex_part (target
, op1
, true);
8825 case WIDEN_SUM_EXPR
:
8827 tree oprnd0
= treeop0
;
8828 tree oprnd1
= treeop1
;
8830 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8831 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
8836 case REDUC_MAX_EXPR
:
8837 case REDUC_MIN_EXPR
:
8838 case REDUC_PLUS_EXPR
:
8840 op0
= expand_normal (treeop0
);
8841 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8842 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
8847 case VEC_LSHIFT_EXPR
:
8848 case VEC_RSHIFT_EXPR
:
8850 target
= expand_vec_shift_expr (ops
, target
);
8854 case VEC_UNPACK_HI_EXPR
:
8855 case VEC_UNPACK_LO_EXPR
:
8857 op0
= expand_normal (treeop0
);
8858 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
8864 case VEC_UNPACK_FLOAT_HI_EXPR
:
8865 case VEC_UNPACK_FLOAT_LO_EXPR
:
8867 op0
= expand_normal (treeop0
);
8868 /* The signedness is determined from input operand. */
8869 temp
= expand_widen_pattern_expr
8870 (ops
, op0
, NULL_RTX
, NULL_RTX
,
8871 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8877 case VEC_WIDEN_MULT_HI_EXPR
:
8878 case VEC_WIDEN_MULT_LO_EXPR
:
8879 case VEC_WIDEN_MULT_EVEN_EXPR
:
8880 case VEC_WIDEN_MULT_ODD_EXPR
:
8881 case VEC_WIDEN_LSHIFT_HI_EXPR
:
8882 case VEC_WIDEN_LSHIFT_LO_EXPR
:
8883 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8884 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
8886 gcc_assert (target
);
8889 case VEC_PACK_TRUNC_EXPR
:
8890 case VEC_PACK_SAT_EXPR
:
8891 case VEC_PACK_FIX_TRUNC_EXPR
:
8892 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8896 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
8897 op2
= expand_normal (treeop2
);
8899 /* Careful here: if the target doesn't support integral vector modes,
8900 a constant selection vector could wind up smooshed into a normal
8901 integral constant. */
8902 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
8904 tree sel_type
= TREE_TYPE (treeop2
);
8905 enum machine_mode vmode
8906 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
8907 TYPE_VECTOR_SUBPARTS (sel_type
));
8908 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
8909 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
8910 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
8913 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
8915 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
8921 tree oprnd0
= treeop0
;
8922 tree oprnd1
= treeop1
;
8923 tree oprnd2
= treeop2
;
8926 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8927 op2
= expand_normal (oprnd2
);
8928 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8933 case REALIGN_LOAD_EXPR
:
8935 tree oprnd0
= treeop0
;
8936 tree oprnd1
= treeop1
;
8937 tree oprnd2
= treeop2
;
8940 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8941 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8942 op2
= expand_normal (oprnd2
);
8943 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
8950 /* A COND_EXPR with its type being VOID_TYPE represents a
8951 conditional jump and is handled in
8952 expand_gimple_cond_expr. */
8953 gcc_assert (!VOID_TYPE_P (type
));
8955 /* Note that COND_EXPRs whose type is a structure or union
8956 are required to be constructed to contain assignments of
8957 a temporary variable, so that we can evaluate them here
8958 for side effect only. If type is void, we must do likewise. */
8960 gcc_assert (!TREE_ADDRESSABLE (type
)
8962 && TREE_TYPE (treeop1
) != void_type_node
8963 && TREE_TYPE (treeop2
) != void_type_node
);
8965 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
8969 /* If we are not to produce a result, we have no target. Otherwise,
8970 if a target was specified use it; it will not be used as an
8971 intermediate target unless it is safe. If no target, use a
8974 if (modifier
!= EXPAND_STACK_PARM
8976 && safe_from_p (original_target
, treeop0
, 1)
8977 && GET_MODE (original_target
) == mode
8978 && !MEM_P (original_target
))
8979 temp
= original_target
;
8981 temp
= assign_temp (type
, 0, 1);
8983 do_pending_stack_adjust ();
8985 op0
= gen_label_rtx ();
8986 op1
= gen_label_rtx ();
8987 jumpifnot (treeop0
, op0
, -1);
8988 store_expr (treeop1
, temp
,
8989 modifier
== EXPAND_STACK_PARM
,
8992 emit_jump_insn (gen_jump (op1
));
8995 store_expr (treeop2
, temp
,
8996 modifier
== EXPAND_STACK_PARM
,
9004 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9011 /* Here to do an ordinary binary operator. */
9013 expand_operands (treeop0
, treeop1
,
9014 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9016 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9018 if (modifier
== EXPAND_STACK_PARM
)
9020 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9021 unsignedp
, OPTAB_LIB_WIDEN
);
9023 /* Bitwise operations do not need bitfield reduction as we expect their
9024 operands being properly truncated. */
9025 if (code
== BIT_XOR_EXPR
9026 || code
== BIT_AND_EXPR
9027 || code
== BIT_IOR_EXPR
)
9029 return REDUCE_BIT_FIELD (temp
);
9031 #undef REDUCE_BIT_FIELD
9034 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9035 enum expand_modifier modifier
, rtx
*alt_rtl
)
9037 rtx op0
, op1
, temp
, decl_rtl
;
9040 enum machine_mode mode
;
9041 enum tree_code code
= TREE_CODE (exp
);
9042 rtx subtarget
, original_target
;
9045 bool reduce_bit_field
;
9046 location_t loc
= EXPR_LOCATION (exp
);
9047 struct separate_ops ops
;
9048 tree treeop0
, treeop1
, treeop2
;
9049 tree ssa_name
= NULL_TREE
;
9052 type
= TREE_TYPE (exp
);
9053 mode
= TYPE_MODE (type
);
9054 unsignedp
= TYPE_UNSIGNED (type
);
9056 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9057 if (!VL_EXP_CLASS_P (exp
))
9058 switch (TREE_CODE_LENGTH (code
))
9061 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9062 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9063 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9073 ignore
= (target
== const0_rtx
9074 || ((CONVERT_EXPR_CODE_P (code
)
9075 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9076 && TREE_CODE (type
) == VOID_TYPE
));
9078 /* An operation in what may be a bit-field type needs the
9079 result to be reduced to the precision of the bit-field type,
9080 which is narrower than that of the type's mode. */
9081 reduce_bit_field
= (!ignore
9082 && INTEGRAL_TYPE_P (type
)
9083 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9085 /* If we are going to ignore this result, we need only do something
9086 if there is a side-effect somewhere in the expression. If there
9087 is, short-circuit the most common cases here. Note that we must
9088 not call expand_expr with anything but const0_rtx in case this
9089 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9093 if (! TREE_SIDE_EFFECTS (exp
))
9096 /* Ensure we reference a volatile object even if value is ignored, but
9097 don't do this if all we are doing is taking its address. */
9098 if (TREE_THIS_VOLATILE (exp
)
9099 && TREE_CODE (exp
) != FUNCTION_DECL
9100 && mode
!= VOIDmode
&& mode
!= BLKmode
9101 && modifier
!= EXPAND_CONST_ADDRESS
)
9103 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9109 if (TREE_CODE_CLASS (code
) == tcc_unary
9110 || code
== BIT_FIELD_REF
9111 || code
== COMPONENT_REF
9112 || code
== INDIRECT_REF
)
9113 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9116 else if (TREE_CODE_CLASS (code
) == tcc_binary
9117 || TREE_CODE_CLASS (code
) == tcc_comparison
9118 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9120 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9121 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9128 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9131 /* Use subtarget as the target for operand 0 of a binary operation. */
9132 subtarget
= get_subtarget (target
);
9133 original_target
= target
;
9139 tree function
= decl_function_context (exp
);
9141 temp
= label_rtx (exp
);
9142 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9144 if (function
!= current_function_decl
9146 LABEL_REF_NONLOCAL_P (temp
) = 1;
9148 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9153 /* ??? ivopts calls expander, without any preparation from
9154 out-of-ssa. So fake instructions as if this was an access to the
9155 base variable. This unnecessarily allocates a pseudo, see how we can
9156 reuse it, if partition base vars have it set already. */
9157 if (!currently_expanding_to_rtl
)
9159 tree var
= SSA_NAME_VAR (exp
);
9160 if (var
&& DECL_RTL_SET_P (var
))
9161 return DECL_RTL (var
);
9162 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9163 LAST_VIRTUAL_REGISTER
+ 1);
9166 g
= get_gimple_for_ssa_name (exp
);
9167 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9169 && modifier
== EXPAND_INITIALIZER
9170 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9171 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9172 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9173 g
= SSA_NAME_DEF_STMT (exp
);
9177 location_t saved_loc
= curr_insn_location ();
9179 set_curr_insn_location (gimple_location (g
));
9180 r
= expand_expr_real (gimple_assign_rhs_to_tree (g
), target
,
9181 tmode
, modifier
, NULL
);
9182 set_curr_insn_location (saved_loc
);
9183 if (REG_P (r
) && !REG_EXPR (r
))
9184 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9189 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9190 exp
= SSA_NAME_VAR (ssa_name
);
9191 goto expand_decl_rtl
;
9195 /* If a static var's type was incomplete when the decl was written,
9196 but the type is complete now, lay out the decl now. */
9197 if (DECL_SIZE (exp
) == 0
9198 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9199 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9200 layout_decl (exp
, 0);
9202 /* ... fall through ... */
9206 decl_rtl
= DECL_RTL (exp
);
9208 gcc_assert (decl_rtl
);
9209 decl_rtl
= copy_rtx (decl_rtl
);
9210 /* Record writes to register variables. */
9211 if (modifier
== EXPAND_WRITE
9213 && HARD_REGISTER_P (decl_rtl
))
9214 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9215 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9217 /* Ensure variable marked as used even if it doesn't go through
9218 a parser. If it hasn't be used yet, write out an external
9220 TREE_USED (exp
) = 1;
9222 /* Show we haven't gotten RTL for this yet. */
9225 /* Variables inherited from containing functions should have
9226 been lowered by this point. */
9227 context
= decl_function_context (exp
);
9228 gcc_assert (!context
9229 || context
== current_function_decl
9230 || TREE_STATIC (exp
)
9231 || DECL_EXTERNAL (exp
)
9232 /* ??? C++ creates functions that are not TREE_STATIC. */
9233 || TREE_CODE (exp
) == FUNCTION_DECL
);
9235 /* This is the case of an array whose size is to be determined
9236 from its initializer, while the initializer is still being parsed.
9237 ??? We aren't parsing while expanding anymore. */
9239 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9240 temp
= validize_mem (decl_rtl
);
9242 /* If DECL_RTL is memory, we are in the normal case and the
9243 address is not valid, get the address into a register. */
9245 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9248 *alt_rtl
= decl_rtl
;
9249 decl_rtl
= use_anchored_address (decl_rtl
);
9250 if (modifier
!= EXPAND_CONST_ADDRESS
9251 && modifier
!= EXPAND_SUM
9252 && !memory_address_addr_space_p (DECL_MODE (exp
),
9254 MEM_ADDR_SPACE (decl_rtl
)))
9255 temp
= replace_equiv_address (decl_rtl
,
9256 copy_rtx (XEXP (decl_rtl
, 0)));
9259 /* If we got something, return it. But first, set the alignment
9260 if the address is a register. */
9263 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9264 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9269 /* If the mode of DECL_RTL does not match that of the decl,
9270 there are two cases: we are dealing with a BLKmode value
9271 that is returned in a register, or we are dealing with
9272 a promoted value. In the latter case, return a SUBREG
9273 of the wanted mode, but mark it so that we know that it
9274 was already extended. */
9275 if (REG_P (decl_rtl
)
9276 && DECL_MODE (exp
) != BLKmode
9277 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9279 enum machine_mode pmode
;
9281 /* Get the signedness to be used for this variable. Ensure we get
9282 the same mode we got when the variable was declared. */
9283 if (code
== SSA_NAME
9284 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9285 && gimple_code (g
) == GIMPLE_CALL
)
9287 gcc_assert (!gimple_call_internal_p (g
));
9288 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9289 gimple_call_fntype (g
),
9293 pmode
= promote_decl_mode (exp
, &unsignedp
);
9294 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9296 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9297 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9298 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
9305 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
9306 TREE_INT_CST_HIGH (exp
), mode
);
9312 tree tmp
= NULL_TREE
;
9313 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9314 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9315 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9316 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9317 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9318 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9319 return const_vector_from_tree (exp
);
9320 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9322 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9324 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9328 VEC(constructor_elt
,gc
) *v
;
9330 v
= VEC_alloc (constructor_elt
, gc
, VECTOR_CST_NELTS (exp
));
9331 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9332 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9333 tmp
= build_constructor (type
, v
);
9335 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9340 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9343 /* If optimized, generate immediate CONST_DOUBLE
9344 which will be turned into memory by reload if necessary.
9346 We used to force a register so that loop.c could see it. But
9347 this does not allow gen_* patterns to perform optimizations with
9348 the constants. It also produces two insns in cases like "x = 1.0;".
9349 On most machines, floating-point constants are not permitted in
9350 many insns, so we'd end up copying it to a register in any case.
9352 Now, we do the copying in expand_binop, if appropriate. */
9353 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9354 TYPE_MODE (TREE_TYPE (exp
)));
9357 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9358 TYPE_MODE (TREE_TYPE (exp
)));
9361 /* Handle evaluating a complex constant in a CONCAT target. */
9362 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9364 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9367 rtarg
= XEXP (original_target
, 0);
9368 itarg
= XEXP (original_target
, 1);
9370 /* Move the real and imaginary parts separately. */
9371 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9372 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9375 emit_move_insn (rtarg
, op0
);
9377 emit_move_insn (itarg
, op1
);
9379 return original_target
;
9382 /* ... fall through ... */
9385 temp
= expand_expr_constant (exp
, 1, modifier
);
9387 /* temp contains a constant address.
9388 On RISC machines where a constant address isn't valid,
9389 make some insns to get that address into a register. */
9390 if (modifier
!= EXPAND_CONST_ADDRESS
9391 && modifier
!= EXPAND_INITIALIZER
9392 && modifier
!= EXPAND_SUM
9393 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9394 MEM_ADDR_SPACE (temp
)))
9395 return replace_equiv_address (temp
,
9396 copy_rtx (XEXP (temp
, 0)));
9402 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
9404 if (!SAVE_EXPR_RESOLVED_P (exp
))
9406 /* We can indeed still hit this case, typically via builtin
9407 expanders calling save_expr immediately before expanding
9408 something. Assume this means that we only have to deal
9409 with non-BLKmode values. */
9410 gcc_assert (GET_MODE (ret
) != BLKmode
);
9412 val
= build_decl (curr_insn_location (),
9413 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9414 DECL_ARTIFICIAL (val
) = 1;
9415 DECL_IGNORED_P (val
) = 1;
9417 TREE_OPERAND (exp
, 0) = treeop0
;
9418 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9420 if (!CONSTANT_P (ret
))
9421 ret
= copy_to_reg (ret
);
9422 SET_DECL_RTL (val
, ret
);
9430 /* If we don't need the result, just ensure we evaluate any
9434 unsigned HOST_WIDE_INT idx
;
9437 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9438 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9443 return expand_constructor (exp
, target
, modifier
, false);
9445 case TARGET_MEM_REF
:
9448 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9449 struct mem_address addr
;
9450 enum insn_code icode
;
9453 get_address_description (exp
, &addr
);
9454 op0
= addr_for_mem_ref (&addr
, as
, true);
9455 op0
= memory_address_addr_space (mode
, op0
, as
);
9456 temp
= gen_rtx_MEM (mode
, op0
);
9457 set_mem_attributes (temp
, exp
, 0);
9458 set_mem_addr_space (temp
, as
);
9459 align
= get_object_alignment (exp
);
9460 if (modifier
!= EXPAND_WRITE
9462 && align
< GET_MODE_ALIGNMENT (mode
)
9463 /* If the target does not have special handling for unaligned
9464 loads of mode then it can use regular moves for them. */
9465 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9466 != CODE_FOR_nothing
))
9468 struct expand_operand ops
[2];
9470 /* We've already validated the memory, and we're creating a
9471 new pseudo destination. The predicates really can't fail,
9472 nor can the generator. */
9473 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9474 create_fixed_operand (&ops
[1], temp
);
9475 expand_insn (icode
, 2, ops
);
9476 return ops
[0].value
;
9484 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9485 enum machine_mode address_mode
;
9486 tree base
= TREE_OPERAND (exp
, 0);
9488 enum insn_code icode
;
9490 /* Handle expansion of non-aliased memory with non-BLKmode. That
9491 might end up in a register. */
9492 if (mem_ref_refers_to_non_mem_p (exp
))
9494 HOST_WIDE_INT offset
= mem_ref_offset (exp
).low
;
9497 base
= TREE_OPERAND (base
, 0);
9499 && host_integerp (TYPE_SIZE (TREE_TYPE (exp
)), 1)
9500 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9501 == TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp
)))))
9502 return expand_expr (build1 (VIEW_CONVERT_EXPR
,
9503 TREE_TYPE (exp
), base
),
9504 target
, tmode
, modifier
);
9505 bit_offset
= bitsize_int (offset
* BITS_PER_UNIT
);
9506 bftype
= TREE_TYPE (base
);
9507 if (TYPE_MODE (TREE_TYPE (exp
)) != BLKmode
)
9508 bftype
= TREE_TYPE (exp
);
9511 temp
= assign_stack_temp (DECL_MODE (base
),
9512 GET_MODE_SIZE (DECL_MODE (base
)));
9513 store_expr (base
, temp
, 0, false);
9514 temp
= adjust_address (temp
, BLKmode
, offset
);
9515 set_mem_size (temp
, int_size_in_bytes (TREE_TYPE (exp
)));
9518 return expand_expr (build3 (BIT_FIELD_REF
, bftype
,
9520 TYPE_SIZE (TREE_TYPE (exp
)),
9522 target
, tmode
, modifier
);
9524 address_mode
= targetm
.addr_space
.address_mode (as
);
9525 base
= TREE_OPERAND (exp
, 0);
9526 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9528 tree mask
= gimple_assign_rhs2 (def_stmt
);
9529 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9530 gimple_assign_rhs1 (def_stmt
), mask
);
9531 TREE_OPERAND (exp
, 0) = base
;
9533 align
= get_object_alignment (exp
);
9534 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9535 op0
= memory_address_addr_space (address_mode
, op0
, as
);
9536 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9539 = immed_double_int_const (mem_ref_offset (exp
), address_mode
);
9540 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9542 op0
= memory_address_addr_space (mode
, op0
, as
);
9543 temp
= gen_rtx_MEM (mode
, op0
);
9544 set_mem_attributes (temp
, exp
, 0);
9545 set_mem_addr_space (temp
, as
);
9546 if (TREE_THIS_VOLATILE (exp
))
9547 MEM_VOLATILE_P (temp
) = 1;
9548 if (modifier
!= EXPAND_WRITE
9550 && align
< GET_MODE_ALIGNMENT (mode
))
9552 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9553 != CODE_FOR_nothing
)
9555 struct expand_operand ops
[2];
9557 /* We've already validated the memory, and we're creating a
9558 new pseudo destination. The predicates really can't fail,
9559 nor can the generator. */
9560 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9561 create_fixed_operand (&ops
[1], temp
);
9562 expand_insn (icode
, 2, ops
);
9563 return ops
[0].value
;
9565 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9566 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9567 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9568 true, (modifier
== EXPAND_STACK_PARM
9569 ? NULL_RTX
: target
),
9578 tree array
= treeop0
;
9579 tree index
= treeop1
;
9581 /* Fold an expression like: "foo"[2].
9582 This is not done in fold so it won't happen inside &.
9583 Don't fold if this is for wide characters since it's too
9584 difficult to do correctly and this is a very rare case. */
9586 if (modifier
!= EXPAND_CONST_ADDRESS
9587 && modifier
!= EXPAND_INITIALIZER
9588 && modifier
!= EXPAND_MEMORY
)
9590 tree t
= fold_read_from_constant_string (exp
);
9593 return expand_expr (t
, target
, tmode
, modifier
);
9596 /* If this is a constant index into a constant array,
9597 just get the value from the array. Handle both the cases when
9598 we have an explicit constructor and when our operand is a variable
9599 that was declared const. */
9601 if (modifier
!= EXPAND_CONST_ADDRESS
9602 && modifier
!= EXPAND_INITIALIZER
9603 && modifier
!= EXPAND_MEMORY
9604 && TREE_CODE (array
) == CONSTRUCTOR
9605 && ! TREE_SIDE_EFFECTS (array
)
9606 && TREE_CODE (index
) == INTEGER_CST
)
9608 unsigned HOST_WIDE_INT ix
;
9611 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9613 if (tree_int_cst_equal (field
, index
))
9615 if (!TREE_SIDE_EFFECTS (value
))
9616 return expand_expr (fold (value
), target
, tmode
, modifier
);
9621 else if (optimize
>= 1
9622 && modifier
!= EXPAND_CONST_ADDRESS
9623 && modifier
!= EXPAND_INITIALIZER
9624 && modifier
!= EXPAND_MEMORY
9625 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9626 && TREE_CODE (array
) == VAR_DECL
&& DECL_INITIAL (array
)
9627 && TREE_CODE (DECL_INITIAL (array
)) != ERROR_MARK
9628 && const_value_known_p (array
))
9630 if (TREE_CODE (index
) == INTEGER_CST
)
9632 tree init
= DECL_INITIAL (array
);
9634 if (TREE_CODE (init
) == CONSTRUCTOR
)
9636 unsigned HOST_WIDE_INT ix
;
9639 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9641 if (tree_int_cst_equal (field
, index
))
9643 if (TREE_SIDE_EFFECTS (value
))
9646 if (TREE_CODE (value
) == CONSTRUCTOR
)
9648 /* If VALUE is a CONSTRUCTOR, this
9649 optimization is only useful if
9650 this doesn't store the CONSTRUCTOR
9651 into memory. If it does, it is more
9652 efficient to just load the data from
9653 the array directly. */
9654 rtx ret
= expand_constructor (value
, target
,
9656 if (ret
== NULL_RTX
)
9660 return expand_expr (fold (value
), target
, tmode
,
9664 else if(TREE_CODE (init
) == STRING_CST
)
9666 tree index1
= index
;
9667 tree low_bound
= array_ref_low_bound (exp
);
9668 index1
= fold_convert_loc (loc
, sizetype
,
9671 /* Optimize the special-case of a zero lower bound.
9673 We convert the low_bound to sizetype to avoid some problems
9674 with constant folding. (E.g. suppose the lower bound is 1,
9675 and its mode is QI. Without the conversion,l (ARRAY
9676 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
9677 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
9679 if (! integer_zerop (low_bound
))
9680 index1
= size_diffop_loc (loc
, index1
,
9681 fold_convert_loc (loc
, sizetype
,
9684 if (0 > compare_tree_int (index1
,
9685 TREE_STRING_LENGTH (init
)))
9687 tree type
= TREE_TYPE (TREE_TYPE (init
));
9688 enum machine_mode mode
= TYPE_MODE (type
);
9690 if (GET_MODE_CLASS (mode
) == MODE_INT
9691 && GET_MODE_SIZE (mode
) == 1)
9692 return gen_int_mode (TREE_STRING_POINTER (init
)
9693 [TREE_INT_CST_LOW (index1
)],
9700 goto normal_inner_ref
;
9703 /* If the operand is a CONSTRUCTOR, we can just extract the
9704 appropriate field if it is present. */
9705 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9707 unsigned HOST_WIDE_INT idx
;
9710 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9712 if (field
== treeop1
9713 /* We can normally use the value of the field in the
9714 CONSTRUCTOR. However, if this is a bitfield in
9715 an integral mode that we can fit in a HOST_WIDE_INT,
9716 we must mask only the number of bits in the bitfield,
9717 since this is done implicitly by the constructor. If
9718 the bitfield does not meet either of those conditions,
9719 we can't do this optimization. */
9720 && (! DECL_BIT_FIELD (field
)
9721 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9722 && (GET_MODE_PRECISION (DECL_MODE (field
))
9723 <= HOST_BITS_PER_WIDE_INT
))))
9725 if (DECL_BIT_FIELD (field
)
9726 && modifier
== EXPAND_STACK_PARM
)
9728 op0
= expand_expr (value
, target
, tmode
, modifier
);
9729 if (DECL_BIT_FIELD (field
))
9731 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9732 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9734 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9736 op1
= GEN_INT (((HOST_WIDE_INT
) 1 << bitsize
) - 1);
9737 op0
= expand_and (imode
, op0
, op1
, target
);
9741 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
9743 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
9745 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
9753 goto normal_inner_ref
;
9756 case ARRAY_RANGE_REF
:
9759 enum machine_mode mode1
, mode2
;
9760 HOST_WIDE_INT bitsize
, bitpos
;
9762 int volatilep
= 0, must_force_mem
;
9763 bool packedp
= false;
9764 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
9765 &mode1
, &unsignedp
, &volatilep
, true);
9766 rtx orig_op0
, memloc
;
9767 bool mem_attrs_from_type
= false;
9769 /* If we got back the original object, something is wrong. Perhaps
9770 we are evaluating an expression too early. In any event, don't
9771 infinitely recurse. */
9772 gcc_assert (tem
!= exp
);
9774 if (TYPE_PACKED (TREE_TYPE (TREE_OPERAND (exp
, 0)))
9775 || (TREE_CODE (TREE_OPERAND (exp
, 1)) == FIELD_DECL
9776 && DECL_PACKED (TREE_OPERAND (exp
, 1))))
9779 /* If TEM's type is a union of variable size, pass TARGET to the inner
9780 computation, since it will need a temporary and TARGET is known
9781 to have to do. This occurs in unchecked conversion in Ada. */
9784 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
9785 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
9786 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
9788 && modifier
!= EXPAND_STACK_PARM
9789 ? target
: NULL_RTX
),
9791 (modifier
== EXPAND_INITIALIZER
9792 || modifier
== EXPAND_CONST_ADDRESS
9793 || modifier
== EXPAND_STACK_PARM
)
9794 ? modifier
: EXPAND_NORMAL
);
9797 /* If the bitfield is volatile, we want to access it in the
9798 field's mode, not the computed mode.
9799 If a MEM has VOIDmode (external with incomplete type),
9800 use BLKmode for it instead. */
9803 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
9804 op0
= adjust_address (op0
, mode1
, 0);
9805 else if (GET_MODE (op0
) == VOIDmode
)
9806 op0
= adjust_address (op0
, BLKmode
, 0);
9810 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
9812 /* If we have either an offset, a BLKmode result, or a reference
9813 outside the underlying object, we must force it to memory.
9814 Such a case can occur in Ada if we have unchecked conversion
9815 of an expression from a scalar type to an aggregate type or
9816 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9817 passed a partially uninitialized object or a view-conversion
9818 to a larger size. */
9819 must_force_mem
= (offset
9821 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
9823 /* Handle CONCAT first. */
9824 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
9827 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
9830 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9833 op0
= XEXP (op0
, 0);
9834 mode2
= GET_MODE (op0
);
9836 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9837 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
9841 op0
= XEXP (op0
, 1);
9843 mode2
= GET_MODE (op0
);
9846 /* Otherwise force into memory. */
9850 /* If this is a constant, put it in a register if it is a legitimate
9851 constant and we don't need a memory reference. */
9852 if (CONSTANT_P (op0
)
9854 && targetm
.legitimate_constant_p (mode2
, op0
)
9856 op0
= force_reg (mode2
, op0
);
9858 /* Otherwise, if this is a constant, try to force it to the constant
9859 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9860 is a legitimate constant. */
9861 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
9862 op0
= validize_mem (memloc
);
9864 /* Otherwise, if this is a constant or the object is not in memory
9865 and need be, put it there. */
9866 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
9868 tree nt
= build_qualified_type (TREE_TYPE (tem
),
9869 (TYPE_QUALS (TREE_TYPE (tem
))
9870 | TYPE_QUAL_CONST
));
9871 memloc
= assign_temp (nt
, 1, 1);
9872 emit_move_insn (memloc
, op0
);
9874 mem_attrs_from_type
= true;
9879 enum machine_mode address_mode
;
9880 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
9883 gcc_assert (MEM_P (op0
));
9885 address_mode
= get_address_mode (op0
);
9886 if (GET_MODE (offset_rtx
) != address_mode
)
9887 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
9889 if (GET_MODE (op0
) == BLKmode
9890 /* A constant address in OP0 can have VOIDmode, we must
9891 not try to call force_reg in that case. */
9892 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
9894 && (bitpos
% bitsize
) == 0
9895 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
9896 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
9898 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
9902 op0
= offset_address (op0
, offset_rtx
,
9903 highest_pow2_factor (offset
));
9906 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
9907 record its alignment as BIGGEST_ALIGNMENT. */
9908 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
9909 && is_aligning_offset (offset
, tem
))
9910 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
9912 /* Don't forget about volatility even if this is a bitfield. */
9913 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
9915 if (op0
== orig_op0
)
9916 op0
= copy_rtx (op0
);
9918 MEM_VOLATILE_P (op0
) = 1;
9921 /* In cases where an aligned union has an unaligned object
9922 as a field, we might be extracting a BLKmode value from
9923 an integer-mode (e.g., SImode) object. Handle this case
9924 by doing the extract into an object as wide as the field
9925 (which we know to be the width of a basic mode), then
9926 storing into memory, and changing the mode to BLKmode. */
9927 if (mode1
== VOIDmode
9928 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
9929 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
9930 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
9931 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
9932 && modifier
!= EXPAND_CONST_ADDRESS
9933 && modifier
!= EXPAND_INITIALIZER
)
9934 /* If the field is volatile, we always want an aligned
9935 access. Do this in following two situations:
9936 1. the access is not already naturally
9937 aligned, otherwise "normal" (non-bitfield) volatile fields
9938 become non-addressable.
9939 2. the bitsize is narrower than the access size. Need
9940 to extract bitfields from the access. */
9941 || (volatilep
&& flag_strict_volatile_bitfields
> 0
9942 && (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0
9943 || (mode1
!= BLKmode
9944 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)))
9945 /* If the field isn't aligned enough to fetch as a memref,
9946 fetch it as a bit field. */
9947 || (mode1
!= BLKmode
9948 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
9949 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
9951 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
9952 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
9953 && ((modifier
== EXPAND_CONST_ADDRESS
9954 || modifier
== EXPAND_INITIALIZER
)
9956 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
9957 || (bitpos
% BITS_PER_UNIT
!= 0)))
9958 /* If the type and the field are a constant size and the
9959 size of the type isn't the same size as the bitfield,
9960 we must use bitfield operations. */
9962 && TYPE_SIZE (TREE_TYPE (exp
))
9963 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
9964 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
9967 enum machine_mode ext_mode
= mode
;
9969 if (ext_mode
== BLKmode
9970 && ! (target
!= 0 && MEM_P (op0
)
9972 && bitpos
% BITS_PER_UNIT
== 0))
9973 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
9975 if (ext_mode
== BLKmode
)
9978 target
= assign_temp (type
, 1, 1);
9983 /* In this case, BITPOS must start at a byte boundary and
9984 TARGET, if specified, must be a MEM. */
9985 gcc_assert (MEM_P (op0
)
9986 && (!target
|| MEM_P (target
))
9987 && !(bitpos
% BITS_PER_UNIT
));
9989 emit_block_move (target
,
9990 adjust_address (op0
, VOIDmode
,
9991 bitpos
/ BITS_PER_UNIT
),
9992 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
9994 (modifier
== EXPAND_STACK_PARM
9995 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10000 op0
= validize_mem (op0
);
10002 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10003 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10005 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
, packedp
,
10006 (modifier
== EXPAND_STACK_PARM
10007 ? NULL_RTX
: target
),
10008 ext_mode
, ext_mode
);
10010 /* If the result is a record type and BITSIZE is narrower than
10011 the mode of OP0, an integral mode, and this is a big endian
10012 machine, we must put the field into the high-order bits. */
10013 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10014 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10015 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10016 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10017 GET_MODE_BITSIZE (GET_MODE (op0
))
10018 - bitsize
, op0
, 1);
10020 /* If the result type is BLKmode, store the data into a temporary
10021 of the appropriate type, but with the mode corresponding to the
10022 mode for the data we have (op0's mode). It's tempting to make
10023 this a constant type, since we know it's only being stored once,
10024 but that can cause problems if we are taking the address of this
10025 COMPONENT_REF because the MEM of any reference via that address
10026 will have flags corresponding to the type, which will not
10027 necessarily be constant. */
10028 if (mode
== BLKmode
)
10032 new_rtx
= assign_stack_temp_for_type (ext_mode
,
10033 GET_MODE_BITSIZE (ext_mode
),
10035 emit_move_insn (new_rtx
, op0
);
10036 op0
= copy_rtx (new_rtx
);
10037 PUT_MODE (op0
, BLKmode
);
10043 /* If the result is BLKmode, use that to access the object
10045 if (mode
== BLKmode
)
10048 /* Get a reference to just this component. */
10049 if (modifier
== EXPAND_CONST_ADDRESS
10050 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10051 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10053 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10055 if (op0
== orig_op0
)
10056 op0
= copy_rtx (op0
);
10058 /* If op0 is a temporary because of forcing to memory, pass only the
10059 type to set_mem_attributes so that the original expression is never
10060 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10061 if (mem_attrs_from_type
)
10062 set_mem_attributes (op0
, type
, 0);
10064 set_mem_attributes (op0
, exp
, 0);
10066 if (REG_P (XEXP (op0
, 0)))
10067 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10069 MEM_VOLATILE_P (op0
) |= volatilep
;
10070 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10071 || modifier
== EXPAND_CONST_ADDRESS
10072 || modifier
== EXPAND_INITIALIZER
)
10074 else if (target
== 0)
10075 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10077 convert_move (target
, op0
, unsignedp
);
10082 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10085 /* All valid uses of __builtin_va_arg_pack () are removed during
10087 if (CALL_EXPR_VA_ARG_PACK (exp
))
10088 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10090 tree fndecl
= get_callee_fndecl (exp
), attr
;
10093 && (attr
= lookup_attribute ("error",
10094 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10095 error ("%Kcall to %qs declared with attribute error: %s",
10096 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10097 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10099 && (attr
= lookup_attribute ("warning",
10100 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10101 warning_at (tree_nonartificial_location (exp
),
10102 0, "%Kcall to %qs declared with attribute warning: %s",
10103 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10104 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10106 /* Check for a built-in function. */
10107 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10109 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10110 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10113 return expand_call (exp
, target
, ignore
);
10115 case VIEW_CONVERT_EXPR
:
10118 /* If we are converting to BLKmode, try to avoid an intermediate
10119 temporary by fetching an inner memory reference. */
10120 if (mode
== BLKmode
10121 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10122 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10123 && handled_component_p (treeop0
))
10125 enum machine_mode mode1
;
10126 HOST_WIDE_INT bitsize
, bitpos
;
10131 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10132 &offset
, &mode1
, &unsignedp
, &volatilep
,
10136 /* ??? We should work harder and deal with non-zero offsets. */
10138 && (bitpos
% BITS_PER_UNIT
) == 0
10140 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) == 0)
10142 /* See the normal_inner_ref case for the rationale. */
10144 = expand_expr (tem
,
10145 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10146 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10148 && modifier
!= EXPAND_STACK_PARM
10149 ? target
: NULL_RTX
),
10151 (modifier
== EXPAND_INITIALIZER
10152 || modifier
== EXPAND_CONST_ADDRESS
10153 || modifier
== EXPAND_STACK_PARM
)
10154 ? modifier
: EXPAND_NORMAL
);
10156 if (MEM_P (orig_op0
))
10160 /* Get a reference to just this component. */
10161 if (modifier
== EXPAND_CONST_ADDRESS
10162 || modifier
== EXPAND_SUM
10163 || modifier
== EXPAND_INITIALIZER
)
10164 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10166 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10168 if (op0
== orig_op0
)
10169 op0
= copy_rtx (op0
);
10171 set_mem_attributes (op0
, treeop0
, 0);
10172 if (REG_P (XEXP (op0
, 0)))
10173 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10175 MEM_VOLATILE_P (op0
) |= volatilep
;
10181 op0
= expand_expr (treeop0
,
10182 NULL_RTX
, VOIDmode
, modifier
);
10184 /* If the input and output modes are both the same, we are done. */
10185 if (mode
== GET_MODE (op0
))
10187 /* If neither mode is BLKmode, and both modes are the same size
10188 then we can use gen_lowpart. */
10189 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10190 && (GET_MODE_PRECISION (mode
)
10191 == GET_MODE_PRECISION (GET_MODE (op0
)))
10192 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10194 if (GET_CODE (op0
) == SUBREG
)
10195 op0
= force_reg (GET_MODE (op0
), op0
);
10196 temp
= gen_lowpart_common (mode
, op0
);
10201 if (!REG_P (op0
) && !MEM_P (op0
))
10202 op0
= force_reg (GET_MODE (op0
), op0
);
10203 op0
= gen_lowpart (mode
, op0
);
10206 /* If both types are integral, convert from one mode to the other. */
10207 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10208 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10209 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10210 /* As a last resort, spill op0 to memory, and reload it in a
10212 else if (!MEM_P (op0
))
10214 /* If the operand is not a MEM, force it into memory. Since we
10215 are going to be changing the mode of the MEM, don't call
10216 force_const_mem for constants because we don't allow pool
10217 constants to change mode. */
10218 tree inner_type
= TREE_TYPE (treeop0
);
10220 gcc_assert (!TREE_ADDRESSABLE (exp
));
10222 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10224 = assign_stack_temp_for_type
10225 (TYPE_MODE (inner_type
),
10226 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10228 emit_move_insn (target
, op0
);
10232 /* At this point, OP0 is in the correct mode. If the output type is
10233 such that the operand is known to be aligned, indicate that it is.
10234 Otherwise, we need only be concerned about alignment for non-BLKmode
10238 enum insn_code icode
;
10240 if (TYPE_ALIGN_OK (type
))
10242 /* ??? Copying the MEM without substantially changing it might
10243 run afoul of the code handling volatile memory references in
10244 store_expr, which assumes that TARGET is returned unmodified
10245 if it has been used. */
10246 op0
= copy_rtx (op0
);
10247 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10249 else if (mode
!= BLKmode
10250 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
)
10251 /* If the target does have special handling for unaligned
10252 loads of mode then use them. */
10253 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10254 != CODE_FOR_nothing
))
10258 op0
= adjust_address (op0
, mode
, 0);
10259 /* We've already validated the memory, and we're creating a
10260 new pseudo destination. The predicates really can't
10262 reg
= gen_reg_rtx (mode
);
10264 /* Nor can the insn generator. */
10265 insn
= GEN_FCN (icode
) (reg
, op0
);
10269 else if (STRICT_ALIGNMENT
10271 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10273 tree inner_type
= TREE_TYPE (treeop0
);
10274 HOST_WIDE_INT temp_size
10275 = MAX (int_size_in_bytes (inner_type
),
10276 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10278 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10279 rtx new_with_op0_mode
10280 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10282 gcc_assert (!TREE_ADDRESSABLE (exp
));
10284 if (GET_MODE (op0
) == BLKmode
)
10285 emit_block_move (new_with_op0_mode
, op0
,
10286 GEN_INT (GET_MODE_SIZE (mode
)),
10287 (modifier
== EXPAND_STACK_PARM
10288 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10290 emit_move_insn (new_with_op0_mode
, op0
);
10295 op0
= adjust_address (op0
, mode
, 0);
10302 tree lhs
= treeop0
;
10303 tree rhs
= treeop1
;
10304 gcc_assert (ignore
);
10306 /* Check for |= or &= of a bitfield of size one into another bitfield
10307 of size 1. In this case, (unless we need the result of the
10308 assignment) we can do this more efficiently with a
10309 test followed by an assignment, if necessary.
10311 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10312 things change so we do, this code should be enhanced to
10314 if (TREE_CODE (lhs
) == COMPONENT_REF
10315 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10316 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10317 && TREE_OPERAND (rhs
, 0) == lhs
10318 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10319 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10320 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10322 rtx label
= gen_label_rtx ();
10323 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10324 do_jump (TREE_OPERAND (rhs
, 1),
10326 value
? 0 : label
, -1);
10327 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10329 do_pending_stack_adjust ();
10330 emit_label (label
);
10334 expand_assignment (lhs
, rhs
, false);
10339 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10341 case REALPART_EXPR
:
10342 op0
= expand_normal (treeop0
);
10343 return read_complex_part (op0
, false);
10345 case IMAGPART_EXPR
:
10346 op0
= expand_normal (treeop0
);
10347 return read_complex_part (op0
, true);
10354 /* Expanded in cfgexpand.c. */
10355 gcc_unreachable ();
10357 case TRY_CATCH_EXPR
:
10359 case EH_FILTER_EXPR
:
10360 case TRY_FINALLY_EXPR
:
10361 /* Lowered by tree-eh.c. */
10362 gcc_unreachable ();
10364 case WITH_CLEANUP_EXPR
:
10365 case CLEANUP_POINT_EXPR
:
10367 case CASE_LABEL_EXPR
:
10372 case COMPOUND_EXPR
:
10373 case PREINCREMENT_EXPR
:
10374 case PREDECREMENT_EXPR
:
10375 case POSTINCREMENT_EXPR
:
10376 case POSTDECREMENT_EXPR
:
10379 case COMPOUND_LITERAL_EXPR
:
10380 /* Lowered by gimplify.c. */
10381 gcc_unreachable ();
10384 /* Function descriptors are not valid except for as
10385 initialization constants, and should not be expanded. */
10386 gcc_unreachable ();
10388 case WITH_SIZE_EXPR
:
10389 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10390 have pulled out the size to use in whatever context it needed. */
10391 return expand_expr_real (treeop0
, original_target
, tmode
,
10392 modifier
, alt_rtl
);
10395 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10399 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10400 signedness of TYPE), possibly returning the result in TARGET. */
10402 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10404 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10405 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10407 /* For constant values, reduce using build_int_cst_type. */
10408 if (CONST_INT_P (exp
))
10410 HOST_WIDE_INT value
= INTVAL (exp
);
10411 tree t
= build_int_cst_type (type
, value
);
10412 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10414 else if (TYPE_UNSIGNED (type
))
10416 rtx mask
= immed_double_int_const (double_int::mask (prec
),
10418 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
10422 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10423 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10424 exp
, count
, target
, 0);
10425 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10426 exp
, count
, target
, 0);
10430 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10431 when applied to the address of EXP produces an address known to be
10432 aligned more than BIGGEST_ALIGNMENT. */
10435 is_aligning_offset (const_tree offset
, const_tree exp
)
10437 /* Strip off any conversions. */
10438 while (CONVERT_EXPR_P (offset
))
10439 offset
= TREE_OPERAND (offset
, 0);
10441 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10442 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10443 if (TREE_CODE (offset
) != BIT_AND_EXPR
10444 || !host_integerp (TREE_OPERAND (offset
, 1), 1)
10445 || compare_tree_int (TREE_OPERAND (offset
, 1),
10446 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10447 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset
, 1), 1) + 1) < 0)
10450 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10451 It must be NEGATE_EXPR. Then strip any more conversions. */
10452 offset
= TREE_OPERAND (offset
, 0);
10453 while (CONVERT_EXPR_P (offset
))
10454 offset
= TREE_OPERAND (offset
, 0);
10456 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10459 offset
= TREE_OPERAND (offset
, 0);
10460 while (CONVERT_EXPR_P (offset
))
10461 offset
= TREE_OPERAND (offset
, 0);
10463 /* This must now be the address of EXP. */
10464 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10467 /* Return the tree node if an ARG corresponds to a string constant or zero
10468 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10469 in bytes within the string that ARG is accessing. The type of the
10470 offset will be `sizetype'. */
10473 string_constant (tree arg
, tree
*ptr_offset
)
10475 tree array
, offset
, lower_bound
;
10478 if (TREE_CODE (arg
) == ADDR_EXPR
)
10480 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10482 *ptr_offset
= size_zero_node
;
10483 return TREE_OPERAND (arg
, 0);
10485 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10487 array
= TREE_OPERAND (arg
, 0);
10488 offset
= size_zero_node
;
10490 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10492 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10493 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10494 if (TREE_CODE (array
) != STRING_CST
10495 && TREE_CODE (array
) != VAR_DECL
)
10498 /* Check if the array has a nonzero lower bound. */
10499 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10500 if (!integer_zerop (lower_bound
))
10502 /* If the offset and base aren't both constants, return 0. */
10503 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10505 if (TREE_CODE (offset
) != INTEGER_CST
)
10507 /* Adjust offset by the lower bound. */
10508 offset
= size_diffop (fold_convert (sizetype
, offset
),
10509 fold_convert (sizetype
, lower_bound
));
10512 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10514 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10515 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10516 if (TREE_CODE (array
) != ADDR_EXPR
)
10518 array
= TREE_OPERAND (array
, 0);
10519 if (TREE_CODE (array
) != STRING_CST
10520 && TREE_CODE (array
) != VAR_DECL
)
10526 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10528 tree arg0
= TREE_OPERAND (arg
, 0);
10529 tree arg1
= TREE_OPERAND (arg
, 1);
10534 if (TREE_CODE (arg0
) == ADDR_EXPR
10535 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10536 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10538 array
= TREE_OPERAND (arg0
, 0);
10541 else if (TREE_CODE (arg1
) == ADDR_EXPR
10542 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10543 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10545 array
= TREE_OPERAND (arg1
, 0);
10554 if (TREE_CODE (array
) == STRING_CST
)
10556 *ptr_offset
= fold_convert (sizetype
, offset
);
10559 else if (TREE_CODE (array
) == VAR_DECL
10560 || TREE_CODE (array
) == CONST_DECL
)
10564 /* Variables initialized to string literals can be handled too. */
10565 if (!const_value_known_p (array
)
10566 || !DECL_INITIAL (array
)
10567 || TREE_CODE (DECL_INITIAL (array
)) != STRING_CST
)
10570 /* Avoid const char foo[4] = "abcde"; */
10571 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10572 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10573 || (length
= TREE_STRING_LENGTH (DECL_INITIAL (array
))) <= 0
10574 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10577 /* If variable is bigger than the string literal, OFFSET must be constant
10578 and inside of the bounds of the string literal. */
10579 offset
= fold_convert (sizetype
, offset
);
10580 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10581 && (! host_integerp (offset
, 1)
10582 || compare_tree_int (offset
, length
) >= 0))
10585 *ptr_offset
= offset
;
10586 return DECL_INITIAL (array
);
10592 /* Generate code to calculate OPS, and exploded expression
10593 using a store-flag instruction and return an rtx for the result.
10594 OPS reflects a comparison.
10596 If TARGET is nonzero, store the result there if convenient.
10598 Return zero if there is no suitable set-flag instruction
10599 available on this machine.
10601 Once expand_expr has been called on the arguments of the comparison,
10602 we are committed to doing the store flag, since it is not safe to
10603 re-evaluate the expression. We emit the store-flag insn by calling
10604 emit_store_flag, but only expand the arguments if we have a reason
10605 to believe that emit_store_flag will be successful. If we think that
10606 it will, but it isn't, we have to simulate the store-flag with a
10607 set/jump/set sequence. */
10610 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10612 enum rtx_code code
;
10613 tree arg0
, arg1
, type
;
10615 enum machine_mode operand_mode
;
10618 rtx subtarget
= target
;
10619 location_t loc
= ops
->location
;
10624 /* Don't crash if the comparison was erroneous. */
10625 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10628 type
= TREE_TYPE (arg0
);
10629 operand_mode
= TYPE_MODE (type
);
10630 unsignedp
= TYPE_UNSIGNED (type
);
10632 /* We won't bother with BLKmode store-flag operations because it would mean
10633 passing a lot of information to emit_store_flag. */
10634 if (operand_mode
== BLKmode
)
10637 /* We won't bother with store-flag operations involving function pointers
10638 when function pointers must be canonicalized before comparisons. */
10639 #ifdef HAVE_canonicalize_funcptr_for_compare
10640 if (HAVE_canonicalize_funcptr_for_compare
10641 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10642 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10644 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10645 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10646 == FUNCTION_TYPE
))))
10653 /* For vector typed comparisons emit code to generate the desired
10654 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10655 expander for this. */
10656 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10658 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10659 tree if_true
= constant_boolean_node (true, ops
->type
);
10660 tree if_false
= constant_boolean_node (false, ops
->type
);
10661 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10664 /* Get the rtx comparison code to use. We know that EXP is a comparison
10665 operation of some type. Some comparisons against 1 and -1 can be
10666 converted to comparisons with zero. Do so here so that the tests
10667 below will be aware that we have a comparison with zero. These
10668 tests will not catch constants in the first operand, but constants
10669 are rarely passed as the first operand. */
10680 if (integer_onep (arg1
))
10681 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10683 code
= unsignedp
? LTU
: LT
;
10686 if (! unsignedp
&& integer_all_onesp (arg1
))
10687 arg1
= integer_zero_node
, code
= LT
;
10689 code
= unsignedp
? LEU
: LE
;
10692 if (! unsignedp
&& integer_all_onesp (arg1
))
10693 arg1
= integer_zero_node
, code
= GE
;
10695 code
= unsignedp
? GTU
: GT
;
10698 if (integer_onep (arg1
))
10699 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10701 code
= unsignedp
? GEU
: GE
;
10704 case UNORDERED_EXPR
:
10730 gcc_unreachable ();
10733 /* Put a constant second. */
10734 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
10735 || TREE_CODE (arg0
) == FIXED_CST
)
10737 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
10738 code
= swap_condition (code
);
10741 /* If this is an equality or inequality test of a single bit, we can
10742 do this by shifting the bit being tested to the low-order bit and
10743 masking the result with the constant 1. If the condition was EQ,
10744 we xor it with 1. This does not require an scc insn and is faster
10745 than an scc insn even if we have it.
10747 The code to make this transformation was moved into fold_single_bit_test,
10748 so we just call into the folder and expand its result. */
10750 if ((code
== NE
|| code
== EQ
)
10751 && integer_zerop (arg1
)
10752 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
10754 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
10756 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
10758 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
10759 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10760 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
10761 gimple_assign_rhs1 (srcstmt
),
10762 gimple_assign_rhs2 (srcstmt
));
10763 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
10765 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
10769 if (! get_subtarget (target
)
10770 || GET_MODE (subtarget
) != operand_mode
)
10773 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10776 target
= gen_reg_rtx (mode
);
10778 /* Try a cstore if possible. */
10779 return emit_store_flag_force (target
, code
, op0
, op1
,
10780 operand_mode
, unsignedp
,
10781 (TYPE_PRECISION (ops
->type
) == 1
10782 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
10786 /* Stubs in case we haven't got a casesi insn. */
10787 #ifndef HAVE_casesi
10788 # define HAVE_casesi 0
10789 # define gen_casesi(a, b, c, d, e) (0)
10790 # define CODE_FOR_casesi CODE_FOR_nothing
10793 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10794 0 otherwise (i.e. if there is no casesi instruction).
10796 DEFAULT_PROBABILITY is the probability of jumping to the default
10799 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
10800 rtx table_label
, rtx default_label
, rtx fallback_label
,
10801 int default_probability
)
10803 struct expand_operand ops
[5];
10804 enum machine_mode index_mode
= SImode
;
10805 rtx op1
, op2
, index
;
10810 /* Convert the index to SImode. */
10811 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
10813 enum machine_mode omode
= TYPE_MODE (index_type
);
10814 rtx rangertx
= expand_normal (range
);
10816 /* We must handle the endpoints in the original mode. */
10817 index_expr
= build2 (MINUS_EXPR
, index_type
,
10818 index_expr
, minval
);
10819 minval
= integer_zero_node
;
10820 index
= expand_normal (index_expr
);
10822 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
10823 omode
, 1, default_label
,
10824 default_probability
);
10825 /* Now we can safely truncate. */
10826 index
= convert_to_mode (index_mode
, index
, 0);
10830 if (TYPE_MODE (index_type
) != index_mode
)
10832 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
10833 index_expr
= fold_convert (index_type
, index_expr
);
10836 index
= expand_normal (index_expr
);
10839 do_pending_stack_adjust ();
10841 op1
= expand_normal (minval
);
10842 op2
= expand_normal (range
);
10844 create_input_operand (&ops
[0], index
, index_mode
);
10845 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
10846 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
10847 create_fixed_operand (&ops
[3], table_label
);
10848 create_fixed_operand (&ops
[4], (default_label
10850 : fallback_label
));
10851 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
10855 /* Attempt to generate a tablejump instruction; same concept. */
10856 #ifndef HAVE_tablejump
10857 #define HAVE_tablejump 0
10858 #define gen_tablejump(x, y) (0)
10861 /* Subroutine of the next function.
10863 INDEX is the value being switched on, with the lowest value
10864 in the table already subtracted.
10865 MODE is its expected mode (needed if INDEX is constant).
10866 RANGE is the length of the jump table.
10867 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10869 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10870 index value is out of range.
10871 DEFAULT_PROBABILITY is the probability of jumping to
10872 the default label. */
10875 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
10876 rtx default_label
, int default_probability
)
10880 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
10881 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
10883 /* Do an unsigned comparison (in the proper mode) between the index
10884 expression and the value which represents the length of the range.
10885 Since we just finished subtracting the lower bound of the range
10886 from the index expression, this comparison allows us to simultaneously
10887 check that the original index expression value is both greater than
10888 or equal to the minimum value of the range and less than or equal to
10889 the maximum value of the range. */
10892 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
10893 default_label
, default_probability
);
10896 /* If index is in range, it must fit in Pmode.
10897 Convert to Pmode so we can index with it. */
10899 index
= convert_to_mode (Pmode
, index
, 1);
10901 /* Don't let a MEM slip through, because then INDEX that comes
10902 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
10903 and break_out_memory_refs will go to work on it and mess it up. */
10904 #ifdef PIC_CASE_VECTOR_ADDRESS
10905 if (flag_pic
&& !REG_P (index
))
10906 index
= copy_to_mode_reg (Pmode
, index
);
10909 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
10910 GET_MODE_SIZE, because this indicates how large insns are. The other
10911 uses should all be Pmode, because they are addresses. This code
10912 could fail if addresses and insns are not the same size. */
10913 index
= gen_rtx_PLUS (Pmode
,
10914 gen_rtx_MULT (Pmode
, index
,
10915 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE
))),
10916 gen_rtx_LABEL_REF (Pmode
, table_label
));
10917 #ifdef PIC_CASE_VECTOR_ADDRESS
10919 index
= PIC_CASE_VECTOR_ADDRESS (index
);
10922 index
= memory_address (CASE_VECTOR_MODE
, index
);
10923 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
10924 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
10925 convert_move (temp
, vector
, 0);
10927 emit_jump_insn (gen_tablejump (temp
, table_label
));
10929 /* If we are generating PIC code or if the table is PC-relative, the
10930 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
10931 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
10936 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
10937 rtx table_label
, rtx default_label
, int default_probability
)
10941 if (! HAVE_tablejump
)
10944 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
10945 fold_convert (index_type
, index_expr
),
10946 fold_convert (index_type
, minval
));
10947 index
= expand_normal (index_expr
);
10948 do_pending_stack_adjust ();
10950 do_tablejump (index
, TYPE_MODE (index_type
),
10951 convert_modes (TYPE_MODE (index_type
),
10952 TYPE_MODE (TREE_TYPE (range
)),
10953 expand_normal (range
),
10954 TYPE_UNSIGNED (TREE_TYPE (range
))),
10955 table_label
, default_label
, default_probability
);
10959 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
10961 const_vector_from_tree (tree exp
)
10967 enum machine_mode inner
, mode
;
10969 mode
= TYPE_MODE (TREE_TYPE (exp
));
10971 if (initializer_zerop (exp
))
10972 return CONST0_RTX (mode
);
10974 units
= GET_MODE_NUNITS (mode
);
10975 inner
= GET_MODE_INNER (mode
);
10977 v
= rtvec_alloc (units
);
10979 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
10981 elt
= VECTOR_CST_ELT (exp
, i
);
10983 if (TREE_CODE (elt
) == REAL_CST
)
10984 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
10986 else if (TREE_CODE (elt
) == FIXED_CST
)
10987 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
10990 RTVEC_ELT (v
, i
) = immed_double_int_const (tree_to_double_int (elt
),
10994 return gen_rtx_CONST_VECTOR (mode
, v
);
10997 /* Build a decl for a personality function given a language prefix. */
11000 build_personality_function (const char *lang
)
11002 const char *unwind_and_version
;
11006 switch (targetm_common
.except_unwind_info (&global_options
))
11011 unwind_and_version
= "_sj0";
11015 unwind_and_version
= "_v0";
11018 unwind_and_version
= "_seh0";
11021 gcc_unreachable ();
11024 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11026 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11027 long_long_unsigned_type_node
,
11028 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11029 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11030 get_identifier (name
), type
);
11031 DECL_ARTIFICIAL (decl
) = 1;
11032 DECL_EXTERNAL (decl
) = 1;
11033 TREE_PUBLIC (decl
) = 1;
11035 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11036 are the flags assigned by targetm.encode_section_info. */
11037 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11042 /* Extracts the personality function of DECL and returns the corresponding
11046 get_personality_function (tree decl
)
11048 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11049 enum eh_personality_kind pk
;
11051 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11052 if (pk
== eh_personality_none
)
11056 && pk
== eh_personality_any
)
11057 personality
= lang_hooks
.eh_personality ();
11059 if (pk
== eh_personality_lang
)
11060 gcc_assert (personality
!= NULL_TREE
);
11062 return XEXP (DECL_RTL (personality
), 0);
11065 #include "gt-expr.h"