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 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2083 of the value stored in X. */
2086 maybe_emit_group_store (rtx x
, tree type
)
2088 enum machine_mode mode
= TYPE_MODE (type
);
2089 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2090 if (GET_CODE (x
) == PARALLEL
)
2092 rtx result
= gen_reg_rtx (mode
);
2093 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2099 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2101 This is used on targets that return BLKmode values in registers. */
2104 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2106 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2107 rtx src
= NULL
, dst
= NULL
;
2108 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2109 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2110 enum machine_mode mode
= GET_MODE (srcreg
);
2111 enum machine_mode tmode
= GET_MODE (target
);
2112 enum machine_mode copy_mode
;
2114 /* BLKmode registers created in the back-end shouldn't have survived. */
2115 gcc_assert (mode
!= BLKmode
);
2117 /* If the structure doesn't take up a whole number of words, see whether
2118 SRCREG is padded on the left or on the right. If it's on the left,
2119 set PADDING_CORRECTION to the number of bits to skip.
2121 In most ABIs, the structure will be returned at the least end of
2122 the register, which translates to right padding on little-endian
2123 targets and left padding on big-endian targets. The opposite
2124 holds if the structure is returned at the most significant
2125 end of the register. */
2126 if (bytes
% UNITS_PER_WORD
!= 0
2127 && (targetm
.calls
.return_in_msb (type
)
2129 : BYTES_BIG_ENDIAN
))
2131 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2133 /* We can use a single move if we have an exact mode for the size. */
2134 else if (MEM_P (target
)
2135 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2136 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2137 && bytes
== GET_MODE_SIZE (mode
))
2139 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2143 /* And if we additionally have the same mode for a register. */
2144 else if (REG_P (target
)
2145 && GET_MODE (target
) == mode
2146 && bytes
== GET_MODE_SIZE (mode
))
2148 emit_move_insn (target
, srcreg
);
2152 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2153 into a new pseudo which is a full word. */
2154 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2156 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2160 /* Copy the structure BITSIZE bits at a time. If the target lives in
2161 memory, take care of not reading/writing past its end by selecting
2162 a copy mode suited to BITSIZE. This should always be possible given
2165 If the target lives in register, make sure not to select a copy mode
2166 larger than the mode of the register.
2168 We could probably emit more efficient code for machines which do not use
2169 strict alignment, but it doesn't seem worth the effort at the current
2172 copy_mode
= word_mode
;
2175 enum machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2176 if (mem_mode
!= BLKmode
)
2177 copy_mode
= mem_mode
;
2179 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2182 for (bitpos
= 0, xbitpos
= padding_correction
;
2183 bitpos
< bytes
* BITS_PER_UNIT
;
2184 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2186 /* We need a new source operand each time xbitpos is on a
2187 word boundary and when xbitpos == padding_correction
2188 (the first time through). */
2189 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2190 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2192 /* We need a new destination operand each time bitpos is on
2194 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2196 else if (bitpos
% BITS_PER_WORD
== 0)
2197 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2199 /* Use xbitpos for the source extraction (right justified) and
2200 bitpos for the destination store (left justified). */
2201 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2202 extract_bit_field (src
, bitsize
,
2203 xbitpos
% BITS_PER_WORD
, 1, false,
2204 NULL_RTX
, copy_mode
, copy_mode
));
2208 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2209 register if it contains any data, otherwise return null.
2211 This is used on targets that return BLKmode values in registers. */
2214 copy_blkmode_to_reg (enum machine_mode mode
, tree src
)
2217 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2218 unsigned int bitsize
;
2219 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2220 enum machine_mode dst_mode
;
2222 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2224 x
= expand_normal (src
);
2226 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2230 /* If the structure doesn't take up a whole number of words, see
2231 whether the register value should be padded on the left or on
2232 the right. Set PADDING_CORRECTION to the number of padding
2233 bits needed on the left side.
2235 In most ABIs, the structure will be returned at the least end of
2236 the register, which translates to right padding on little-endian
2237 targets and left padding on big-endian targets. The opposite
2238 holds if the structure is returned at the most significant
2239 end of the register. */
2240 if (bytes
% UNITS_PER_WORD
!= 0
2241 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2243 : BYTES_BIG_ENDIAN
))
2244 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2247 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2248 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2249 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2251 /* Copy the structure BITSIZE bits at a time. */
2252 for (bitpos
= 0, xbitpos
= padding_correction
;
2253 bitpos
< bytes
* BITS_PER_UNIT
;
2254 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2256 /* We need a new destination pseudo each time xbitpos is
2257 on a word boundary and when xbitpos == padding_correction
2258 (the first time through). */
2259 if (xbitpos
% BITS_PER_WORD
== 0
2260 || xbitpos
== padding_correction
)
2262 /* Generate an appropriate register. */
2263 dst_word
= gen_reg_rtx (word_mode
);
2264 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2266 /* Clear the destination before we move anything into it. */
2267 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2270 /* We need a new source operand each time bitpos is on a word
2272 if (bitpos
% BITS_PER_WORD
== 0)
2273 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2275 /* Use bitpos for the source extraction (left justified) and
2276 xbitpos for the destination store (right justified). */
2277 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2279 extract_bit_field (src_word
, bitsize
,
2280 bitpos
% BITS_PER_WORD
, 1, false,
2281 NULL_RTX
, word_mode
, word_mode
));
2284 if (mode
== BLKmode
)
2286 /* Find the smallest integer mode large enough to hold the
2287 entire structure. */
2288 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2290 mode
= GET_MODE_WIDER_MODE (mode
))
2291 /* Have we found a large enough mode? */
2292 if (GET_MODE_SIZE (mode
) >= bytes
)
2295 /* A suitable mode should have been found. */
2296 gcc_assert (mode
!= VOIDmode
);
2299 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2300 dst_mode
= word_mode
;
2303 dst
= gen_reg_rtx (dst_mode
);
2305 for (i
= 0; i
< n_regs
; i
++)
2306 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2308 if (mode
!= dst_mode
)
2309 dst
= gen_lowpart (mode
, dst
);
2314 /* Add a USE expression for REG to the (possibly empty) list pointed
2315 to by CALL_FUSAGE. REG must denote a hard register. */
2318 use_reg_mode (rtx
*call_fusage
, rtx reg
, enum machine_mode mode
)
2320 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2323 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2326 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2327 starting at REGNO. All of these registers must be hard registers. */
2330 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2334 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2336 for (i
= 0; i
< nregs
; i
++)
2337 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2340 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2341 PARALLEL REGS. This is for calls that pass values in multiple
2342 non-contiguous locations. The Irix 6 ABI has examples of this. */
2345 use_group_regs (rtx
*call_fusage
, rtx regs
)
2349 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2351 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2353 /* A NULL entry means the parameter goes both on the stack and in
2354 registers. This can also be a MEM for targets that pass values
2355 partially on the stack and partially in registers. */
2356 if (reg
!= 0 && REG_P (reg
))
2357 use_reg (call_fusage
, reg
);
2361 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2362 assigment and the code of the expresion on the RHS is CODE. Return
2366 get_def_for_expr (tree name
, enum tree_code code
)
2370 if (TREE_CODE (name
) != SSA_NAME
)
2373 def_stmt
= get_gimple_for_ssa_name (name
);
2375 || gimple_assign_rhs_code (def_stmt
) != code
)
2381 #ifdef HAVE_conditional_move
2382 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2383 assigment and the class of the expresion on the RHS is CLASS. Return
2387 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2391 if (TREE_CODE (name
) != SSA_NAME
)
2394 def_stmt
= get_gimple_for_ssa_name (name
);
2396 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2404 /* Determine whether the LEN bytes generated by CONSTFUN can be
2405 stored to memory using several move instructions. CONSTFUNDATA is
2406 a pointer which will be passed as argument in every CONSTFUN call.
2407 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2408 a memset operation and false if it's a copy of a constant string.
2409 Return nonzero if a call to store_by_pieces should succeed. */
2412 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2413 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2414 void *constfundata
, unsigned int align
, bool memsetp
)
2416 unsigned HOST_WIDE_INT l
;
2417 unsigned int max_size
;
2418 HOST_WIDE_INT offset
= 0;
2419 enum machine_mode mode
;
2420 enum insn_code icode
;
2422 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2423 rtx cst ATTRIBUTE_UNUSED
;
2429 ? SET_BY_PIECES_P (len
, align
)
2430 : STORE_BY_PIECES_P (len
, align
)))
2433 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2435 /* We would first store what we can in the largest integer mode, then go to
2436 successively smaller modes. */
2439 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2443 max_size
= STORE_MAX_PIECES
+ 1;
2444 while (max_size
> 1 && l
> 0)
2446 mode
= widest_int_mode_for_size (max_size
);
2448 if (mode
== VOIDmode
)
2451 icode
= optab_handler (mov_optab
, mode
);
2452 if (icode
!= CODE_FOR_nothing
2453 && align
>= GET_MODE_ALIGNMENT (mode
))
2455 unsigned int size
= GET_MODE_SIZE (mode
);
2462 cst
= (*constfun
) (constfundata
, offset
, mode
);
2463 if (!targetm
.legitimate_constant_p (mode
, cst
))
2473 max_size
= GET_MODE_SIZE (mode
);
2476 /* The code above should have handled everything. */
2483 /* Generate several move instructions to store LEN bytes generated by
2484 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2485 pointer which will be passed as argument in every CONSTFUN call.
2486 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2487 a memset operation and false if it's a copy of a constant string.
2488 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2489 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2493 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2494 rtx (*constfun
) (void *, HOST_WIDE_INT
, enum machine_mode
),
2495 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2497 enum machine_mode to_addr_mode
= get_address_mode (to
);
2498 struct store_by_pieces_d data
;
2502 gcc_assert (endp
!= 2);
2507 ? SET_BY_PIECES_P (len
, align
)
2508 : STORE_BY_PIECES_P (len
, align
));
2509 data
.constfun
= constfun
;
2510 data
.constfundata
= constfundata
;
2513 store_by_pieces_1 (&data
, align
);
2518 gcc_assert (!data
.reverse
);
2523 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2524 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2526 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2527 plus_constant (to_addr_mode
,
2531 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2538 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2546 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2547 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2550 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2552 struct store_by_pieces_d data
;
2557 data
.constfun
= clear_by_pieces_1
;
2558 data
.constfundata
= NULL
;
2561 store_by_pieces_1 (&data
, align
);
2564 /* Callback routine for clear_by_pieces.
2565 Return const0_rtx unconditionally. */
2568 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2569 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2570 enum machine_mode mode ATTRIBUTE_UNUSED
)
2575 /* Subroutine of clear_by_pieces and store_by_pieces.
2576 Generate several move instructions to store LEN bytes of block TO. (A MEM
2577 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2580 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2581 unsigned int align ATTRIBUTE_UNUSED
)
2583 enum machine_mode to_addr_mode
= get_address_mode (data
->to
);
2584 rtx to_addr
= XEXP (data
->to
, 0);
2585 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2586 enum insn_code icode
;
2589 data
->to_addr
= to_addr
;
2591 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2592 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2594 data
->explicit_inc_to
= 0;
2596 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2598 data
->offset
= data
->len
;
2600 /* If storing requires more than two move insns,
2601 copy addresses to registers (to make displacements shorter)
2602 and use post-increment if available. */
2603 if (!data
->autinc_to
2604 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2606 /* Determine the main mode we'll be using.
2607 MODE might not be used depending on the definitions of the
2608 USE_* macros below. */
2609 enum machine_mode mode ATTRIBUTE_UNUSED
2610 = widest_int_mode_for_size (max_size
);
2612 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2614 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2615 plus_constant (to_addr_mode
,
2618 data
->autinc_to
= 1;
2619 data
->explicit_inc_to
= -1;
2622 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2623 && ! data
->autinc_to
)
2625 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2626 data
->autinc_to
= 1;
2627 data
->explicit_inc_to
= 1;
2630 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2631 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2634 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2636 /* First store what we can in the largest integer mode, then go to
2637 successively smaller modes. */
2639 while (max_size
> 1 && data
->len
> 0)
2641 enum machine_mode mode
= widest_int_mode_for_size (max_size
);
2643 if (mode
== VOIDmode
)
2646 icode
= optab_handler (mov_optab
, mode
);
2647 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2648 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2650 max_size
= GET_MODE_SIZE (mode
);
2653 /* The code above should have handled everything. */
2654 gcc_assert (!data
->len
);
2657 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2658 with move instructions for mode MODE. GENFUN is the gen_... function
2659 to make a move insn for that mode. DATA has all the other info. */
2662 store_by_pieces_2 (rtx (*genfun
) (rtx
, ...), enum machine_mode mode
,
2663 struct store_by_pieces_d
*data
)
2665 unsigned int size
= GET_MODE_SIZE (mode
);
2668 while (data
->len
>= size
)
2671 data
->offset
-= size
;
2673 if (data
->autinc_to
)
2674 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2677 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2679 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2680 emit_insn (gen_add2_insn (data
->to_addr
,
2681 GEN_INT (-(HOST_WIDE_INT
) size
)));
2683 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2684 emit_insn ((*genfun
) (to1
, cst
));
2686 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2687 emit_insn (gen_add2_insn (data
->to_addr
, GEN_INT (size
)));
2689 if (! data
->reverse
)
2690 data
->offset
+= size
;
2696 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2697 its length in bytes. */
2700 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2701 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2703 enum machine_mode mode
= GET_MODE (object
);
2706 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2708 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2709 just move a zero. Otherwise, do this a piece at a time. */
2711 && CONST_INT_P (size
)
2712 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2714 rtx zero
= CONST0_RTX (mode
);
2717 emit_move_insn (object
, zero
);
2721 if (COMPLEX_MODE_P (mode
))
2723 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2726 write_complex_part (object
, zero
, 0);
2727 write_complex_part (object
, zero
, 1);
2733 if (size
== const0_rtx
)
2736 align
= MEM_ALIGN (object
);
2738 if (CONST_INT_P (size
)
2739 && CLEAR_BY_PIECES_P (INTVAL (size
), align
))
2740 clear_by_pieces (object
, INTVAL (size
), align
);
2741 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2742 expected_align
, expected_size
))
2744 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2745 return set_storage_via_libcall (object
, size
, const0_rtx
,
2746 method
== BLOCK_OP_TAILCALL
);
2754 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2756 return clear_storage_hints (object
, size
, method
, 0, -1);
2760 /* A subroutine of clear_storage. Expand a call to memset.
2761 Return the return value of memset, 0 otherwise. */
2764 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2766 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2767 enum machine_mode size_mode
;
2770 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2771 place those into new pseudos into a VAR_DECL and use them later. */
2773 object
= copy_addr_to_reg (XEXP (object
, 0));
2775 size_mode
= TYPE_MODE (sizetype
);
2776 size
= convert_to_mode (size_mode
, size
, 1);
2777 size
= copy_to_mode_reg (size_mode
, size
);
2779 /* It is incorrect to use the libcall calling conventions to call
2780 memset in this context. This could be a user call to memset and
2781 the user may wish to examine the return value from memset. For
2782 targets where libcalls and normal calls have different conventions
2783 for returning pointers, we could end up generating incorrect code. */
2785 object_tree
= make_tree (ptr_type_node
, object
);
2786 if (!CONST_INT_P (val
))
2787 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2788 size_tree
= make_tree (sizetype
, size
);
2789 val_tree
= make_tree (integer_type_node
, val
);
2791 fn
= clear_storage_libcall_fn (true);
2792 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2793 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2795 retval
= expand_normal (call_expr
);
2800 /* A subroutine of set_storage_via_libcall. Create the tree node
2801 for the function we use for block clears. */
2803 tree block_clear_fn
;
2806 init_block_clear_fn (const char *asmspec
)
2808 if (!block_clear_fn
)
2812 fn
= get_identifier ("memset");
2813 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2814 integer_type_node
, sizetype
,
2817 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2818 DECL_EXTERNAL (fn
) = 1;
2819 TREE_PUBLIC (fn
) = 1;
2820 DECL_ARTIFICIAL (fn
) = 1;
2821 TREE_NOTHROW (fn
) = 1;
2822 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2823 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2825 block_clear_fn
= fn
;
2829 set_user_assembler_name (block_clear_fn
, asmspec
);
2833 clear_storage_libcall_fn (int for_call
)
2835 static bool emitted_extern
;
2837 if (!block_clear_fn
)
2838 init_block_clear_fn (NULL
);
2840 if (for_call
&& !emitted_extern
)
2842 emitted_extern
= true;
2843 make_decl_rtl (block_clear_fn
);
2846 return block_clear_fn
;
2849 /* Expand a setmem pattern; return true if successful. */
2852 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2853 unsigned int expected_align
, HOST_WIDE_INT expected_size
)
2855 /* Try the most limited insn first, because there's no point
2856 including more than one in the machine description unless
2857 the more limited one has some advantage. */
2859 enum machine_mode mode
;
2861 if (expected_align
< align
)
2862 expected_align
= align
;
2864 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2865 mode
= GET_MODE_WIDER_MODE (mode
))
2867 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2869 if (code
!= CODE_FOR_nothing
2870 /* We don't need MODE to be narrower than
2871 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2872 the mode mask, as it is returned by the macro, it will
2873 definitely be less than the actual mode mask. */
2874 && ((CONST_INT_P (size
)
2875 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2876 <= (GET_MODE_MASK (mode
) >> 1)))
2877 || GET_MODE_BITSIZE (mode
) >= BITS_PER_WORD
))
2879 struct expand_operand ops
[6];
2882 nops
= insn_data
[(int) code
].n_generator_args
;
2883 gcc_assert (nops
== 4 || nops
== 6);
2885 create_fixed_operand (&ops
[0], object
);
2886 /* The check above guarantees that this size conversion is valid. */
2887 create_convert_operand_to (&ops
[1], size
, mode
, true);
2888 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2889 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2892 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2893 create_integer_operand (&ops
[5], expected_size
);
2895 if (maybe_expand_insn (code
, nops
, ops
))
2904 /* Write to one of the components of the complex value CPLX. Write VAL to
2905 the real part if IMAG_P is false, and the imaginary part if its true. */
2908 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2910 enum machine_mode cmode
;
2911 enum machine_mode imode
;
2914 if (GET_CODE (cplx
) == CONCAT
)
2916 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2920 cmode
= GET_MODE (cplx
);
2921 imode
= GET_MODE_INNER (cmode
);
2922 ibitsize
= GET_MODE_BITSIZE (imode
);
2924 /* For MEMs simplify_gen_subreg may generate an invalid new address
2925 because, e.g., the original address is considered mode-dependent
2926 by the target, which restricts simplify_subreg from invoking
2927 adjust_address_nv. Instead of preparing fallback support for an
2928 invalid address, we call adjust_address_nv directly. */
2931 emit_move_insn (adjust_address_nv (cplx
, imode
,
2932 imag_p
? GET_MODE_SIZE (imode
) : 0),
2937 /* If the sub-object is at least word sized, then we know that subregging
2938 will work. This special case is important, since store_bit_field
2939 wants to operate on integer modes, and there's rarely an OImode to
2940 correspond to TCmode. */
2941 if (ibitsize
>= BITS_PER_WORD
2942 /* For hard regs we have exact predicates. Assume we can split
2943 the original object if it spans an even number of hard regs.
2944 This special case is important for SCmode on 64-bit platforms
2945 where the natural size of floating-point regs is 32-bit. */
2947 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2948 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
2950 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
2951 imag_p
? GET_MODE_SIZE (imode
) : 0);
2954 emit_move_insn (part
, val
);
2958 /* simplify_gen_subreg may fail for sub-word MEMs. */
2959 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
2962 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
);
2965 /* Extract one of the components of the complex value CPLX. Extract the
2966 real part if IMAG_P is false, and the imaginary part if it's true. */
2969 read_complex_part (rtx cplx
, bool imag_p
)
2971 enum machine_mode cmode
, imode
;
2974 if (GET_CODE (cplx
) == CONCAT
)
2975 return XEXP (cplx
, imag_p
);
2977 cmode
= GET_MODE (cplx
);
2978 imode
= GET_MODE_INNER (cmode
);
2979 ibitsize
= GET_MODE_BITSIZE (imode
);
2981 /* Special case reads from complex constants that got spilled to memory. */
2982 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
2984 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
2985 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
2987 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
2988 if (CONSTANT_CLASS_P (part
))
2989 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
2993 /* For MEMs simplify_gen_subreg may generate an invalid new address
2994 because, e.g., the original address is considered mode-dependent
2995 by the target, which restricts simplify_subreg from invoking
2996 adjust_address_nv. Instead of preparing fallback support for an
2997 invalid address, we call adjust_address_nv directly. */
2999 return adjust_address_nv (cplx
, imode
,
3000 imag_p
? GET_MODE_SIZE (imode
) : 0);
3002 /* If the sub-object is at least word sized, then we know that subregging
3003 will work. This special case is important, since extract_bit_field
3004 wants to operate on integer modes, and there's rarely an OImode to
3005 correspond to TCmode. */
3006 if (ibitsize
>= BITS_PER_WORD
3007 /* For hard regs we have exact predicates. Assume we can split
3008 the original object if it spans an even number of hard regs.
3009 This special case is important for SCmode on 64-bit platforms
3010 where the natural size of floating-point regs is 32-bit. */
3012 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3013 && hard_regno_nregs
[REGNO (cplx
)][cmode
] % 2 == 0))
3015 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3016 imag_p
? GET_MODE_SIZE (imode
) : 0);
3020 /* simplify_gen_subreg may fail for sub-word MEMs. */
3021 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3024 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3025 true, false, NULL_RTX
, imode
, imode
);
3028 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3029 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3030 represented in NEW_MODE. If FORCE is true, this will never happen, as
3031 we'll force-create a SUBREG if needed. */
3034 emit_move_change_mode (enum machine_mode new_mode
,
3035 enum machine_mode old_mode
, rtx x
, bool force
)
3039 if (push_operand (x
, GET_MODE (x
)))
3041 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3042 MEM_COPY_ATTRIBUTES (ret
, x
);
3046 /* We don't have to worry about changing the address since the
3047 size in bytes is supposed to be the same. */
3048 if (reload_in_progress
)
3050 /* Copy the MEM to change the mode and move any
3051 substitutions from the old MEM to the new one. */
3052 ret
= adjust_address_nv (x
, new_mode
, 0);
3053 copy_replacements (x
, ret
);
3056 ret
= adjust_address (x
, new_mode
, 0);
3060 /* Note that we do want simplify_subreg's behavior of validating
3061 that the new mode is ok for a hard register. If we were to use
3062 simplify_gen_subreg, we would create the subreg, but would
3063 probably run into the target not being able to implement it. */
3064 /* Except, of course, when FORCE is true, when this is exactly what
3065 we want. Which is needed for CCmodes on some targets. */
3067 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3069 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3075 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3076 an integer mode of the same size as MODE. Returns the instruction
3077 emitted, or NULL if such a move could not be generated. */
3080 emit_move_via_integer (enum machine_mode mode
, rtx x
, rtx y
, bool force
)
3082 enum machine_mode imode
;
3083 enum insn_code code
;
3085 /* There must exist a mode of the exact size we require. */
3086 imode
= int_mode_for_mode (mode
);
3087 if (imode
== BLKmode
)
3090 /* The target must support moves in this mode. */
3091 code
= optab_handler (mov_optab
, imode
);
3092 if (code
== CODE_FOR_nothing
)
3095 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3098 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3101 return emit_insn (GEN_FCN (code
) (x
, y
));
3104 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3105 Return an equivalent MEM that does not use an auto-increment. */
3108 emit_move_resolve_push (enum machine_mode mode
, rtx x
)
3110 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3111 HOST_WIDE_INT adjust
;
3114 adjust
= GET_MODE_SIZE (mode
);
3115 #ifdef PUSH_ROUNDING
3116 adjust
= PUSH_ROUNDING (adjust
);
3118 if (code
== PRE_DEC
|| code
== POST_DEC
)
3120 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3122 rtx expr
= XEXP (XEXP (x
, 0), 1);
3125 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3126 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3127 val
= INTVAL (XEXP (expr
, 1));
3128 if (GET_CODE (expr
) == MINUS
)
3130 gcc_assert (adjust
== val
|| adjust
== -val
);
3134 /* Do not use anti_adjust_stack, since we don't want to update
3135 stack_pointer_delta. */
3136 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3137 GEN_INT (adjust
), stack_pointer_rtx
,
3138 0, OPTAB_LIB_WIDEN
);
3139 if (temp
!= stack_pointer_rtx
)
3140 emit_move_insn (stack_pointer_rtx
, temp
);
3147 temp
= stack_pointer_rtx
;
3152 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3158 return replace_equiv_address (x
, temp
);
3161 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3162 X is known to satisfy push_operand, and MODE is known to be complex.
3163 Returns the last instruction emitted. */
3166 emit_move_complex_push (enum machine_mode mode
, rtx x
, rtx y
)
3168 enum machine_mode submode
= GET_MODE_INNER (mode
);
3171 #ifdef PUSH_ROUNDING
3172 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3174 /* In case we output to the stack, but the size is smaller than the
3175 machine can push exactly, we need to use move instructions. */
3176 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3178 x
= emit_move_resolve_push (mode
, x
);
3179 return emit_move_insn (x
, y
);
3183 /* Note that the real part always precedes the imag part in memory
3184 regardless of machine's endianness. */
3185 switch (GET_CODE (XEXP (x
, 0)))
3199 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3200 read_complex_part (y
, imag_first
));
3201 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3202 read_complex_part (y
, !imag_first
));
3205 /* A subroutine of emit_move_complex. Perform the move from Y to X
3206 via two moves of the parts. Returns the last instruction emitted. */
3209 emit_move_complex_parts (rtx x
, rtx y
)
3211 /* Show the output dies here. This is necessary for SUBREGs
3212 of pseudos since we cannot track their lifetimes correctly;
3213 hard regs shouldn't appear here except as return values. */
3214 if (!reload_completed
&& !reload_in_progress
3215 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3218 write_complex_part (x
, read_complex_part (y
, false), false);
3219 write_complex_part (x
, read_complex_part (y
, true), true);
3221 return get_last_insn ();
3224 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3225 MODE is known to be complex. Returns the last instruction emitted. */
3228 emit_move_complex (enum machine_mode mode
, rtx x
, rtx y
)
3232 /* Need to take special care for pushes, to maintain proper ordering
3233 of the data, and possibly extra padding. */
3234 if (push_operand (x
, mode
))
3235 return emit_move_complex_push (mode
, x
, y
);
3237 /* See if we can coerce the target into moving both values at once. */
3239 /* Move floating point as parts. */
3240 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3241 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
)
3243 /* Not possible if the values are inherently not adjacent. */
3244 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3246 /* Is possible if both are registers (or subregs of registers). */
3247 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3249 /* If one of the operands is a memory, and alignment constraints
3250 are friendly enough, we may be able to do combined memory operations.
3251 We do not attempt this if Y is a constant because that combination is
3252 usually better with the by-parts thing below. */
3253 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3254 && (!STRICT_ALIGNMENT
3255 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3264 /* For memory to memory moves, optimal behavior can be had with the
3265 existing block move logic. */
3266 if (MEM_P (x
) && MEM_P (y
))
3268 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3269 BLOCK_OP_NO_LIBCALL
);
3270 return get_last_insn ();
3273 ret
= emit_move_via_integer (mode
, x
, y
, true);
3278 return emit_move_complex_parts (x
, y
);
3281 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3282 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3285 emit_move_ccmode (enum machine_mode mode
, rtx x
, rtx y
)
3289 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3292 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3293 if (code
!= CODE_FOR_nothing
)
3295 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3296 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3297 return emit_insn (GEN_FCN (code
) (x
, y
));
3301 /* Otherwise, find the MODE_INT mode of the same width. */
3302 ret
= emit_move_via_integer (mode
, x
, y
, false);
3303 gcc_assert (ret
!= NULL
);
3307 /* Return true if word I of OP lies entirely in the
3308 undefined bits of a paradoxical subreg. */
3311 undefined_operand_subword_p (const_rtx op
, int i
)
3313 enum machine_mode innermode
, innermostmode
;
3315 if (GET_CODE (op
) != SUBREG
)
3317 innermode
= GET_MODE (op
);
3318 innermostmode
= GET_MODE (SUBREG_REG (op
));
3319 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3320 /* The SUBREG_BYTE represents offset, as if the value were stored in
3321 memory, except for a paradoxical subreg where we define
3322 SUBREG_BYTE to be 0; undo this exception as in
3324 if (SUBREG_BYTE (op
) == 0
3325 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3327 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3328 if (WORDS_BIG_ENDIAN
)
3329 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3330 if (BYTES_BIG_ENDIAN
)
3331 offset
+= difference
% UNITS_PER_WORD
;
3333 if (offset
>= GET_MODE_SIZE (innermostmode
)
3334 || offset
<= -GET_MODE_SIZE (word_mode
))
3339 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3340 MODE is any multi-word or full-word mode that lacks a move_insn
3341 pattern. Note that you will get better code if you define such
3342 patterns, even if they must turn into multiple assembler instructions. */
3345 emit_move_multi_word (enum machine_mode mode
, rtx x
, rtx y
)
3352 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3354 /* If X is a push on the stack, do the push now and replace
3355 X with a reference to the stack pointer. */
3356 if (push_operand (x
, mode
))
3357 x
= emit_move_resolve_push (mode
, x
);
3359 /* If we are in reload, see if either operand is a MEM whose address
3360 is scheduled for replacement. */
3361 if (reload_in_progress
&& MEM_P (x
)
3362 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3363 x
= replace_equiv_address_nv (x
, inner
);
3364 if (reload_in_progress
&& MEM_P (y
)
3365 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3366 y
= replace_equiv_address_nv (y
, inner
);
3370 need_clobber
= false;
3372 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3375 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3378 /* Do not generate code for a move if it would come entirely
3379 from the undefined bits of a paradoxical subreg. */
3380 if (undefined_operand_subword_p (y
, i
))
3383 ypart
= operand_subword (y
, i
, 1, mode
);
3385 /* If we can't get a part of Y, put Y into memory if it is a
3386 constant. Otherwise, force it into a register. Then we must
3387 be able to get a part of Y. */
3388 if (ypart
== 0 && CONSTANT_P (y
))
3390 y
= use_anchored_address (force_const_mem (mode
, y
));
3391 ypart
= operand_subword (y
, i
, 1, mode
);
3393 else if (ypart
== 0)
3394 ypart
= operand_subword_force (y
, i
, mode
);
3396 gcc_assert (xpart
&& ypart
);
3398 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3400 last_insn
= emit_move_insn (xpart
, ypart
);
3406 /* Show the output dies here. This is necessary for SUBREGs
3407 of pseudos since we cannot track their lifetimes correctly;
3408 hard regs shouldn't appear here except as return values.
3409 We never want to emit such a clobber after reload. */
3411 && ! (reload_in_progress
|| reload_completed
)
3412 && need_clobber
!= 0)
3420 /* Low level part of emit_move_insn.
3421 Called just like emit_move_insn, but assumes X and Y
3422 are basically valid. */
3425 emit_move_insn_1 (rtx x
, rtx y
)
3427 enum machine_mode mode
= GET_MODE (x
);
3428 enum insn_code code
;
3430 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3432 code
= optab_handler (mov_optab
, mode
);
3433 if (code
!= CODE_FOR_nothing
)
3434 return emit_insn (GEN_FCN (code
) (x
, y
));
3436 /* Expand complex moves by moving real part and imag part. */
3437 if (COMPLEX_MODE_P (mode
))
3438 return emit_move_complex (mode
, x
, y
);
3440 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3441 || ALL_FIXED_POINT_MODE_P (mode
))
3443 rtx result
= emit_move_via_integer (mode
, x
, y
, true);
3445 /* If we can't find an integer mode, use multi words. */
3449 return emit_move_multi_word (mode
, x
, y
);
3452 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3453 return emit_move_ccmode (mode
, x
, y
);
3455 /* Try using a move pattern for the corresponding integer mode. This is
3456 only safe when simplify_subreg can convert MODE constants into integer
3457 constants. At present, it can only do this reliably if the value
3458 fits within a HOST_WIDE_INT. */
3459 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3461 rtx ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3465 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3470 return emit_move_multi_word (mode
, x
, y
);
3473 /* Generate code to copy Y into X.
3474 Both Y and X must have the same mode, except that
3475 Y can be a constant with VOIDmode.
3476 This mode cannot be BLKmode; use emit_block_move for that.
3478 Return the last instruction emitted. */
3481 emit_move_insn (rtx x
, rtx y
)
3483 enum machine_mode mode
= GET_MODE (x
);
3484 rtx y_cst
= NULL_RTX
;
3487 gcc_assert (mode
!= BLKmode
3488 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3493 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3494 && (last_insn
= compress_float_constant (x
, y
)))
3499 if (!targetm
.legitimate_constant_p (mode
, y
))
3501 y
= force_const_mem (mode
, y
);
3503 /* If the target's cannot_force_const_mem prevented the spill,
3504 assume that the target's move expanders will also take care
3505 of the non-legitimate constant. */
3509 y
= use_anchored_address (y
);
3513 /* If X or Y are memory references, verify that their addresses are valid
3516 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3518 && ! push_operand (x
, GET_MODE (x
))))
3519 x
= validize_mem (x
);
3522 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3523 MEM_ADDR_SPACE (y
)))
3524 y
= validize_mem (y
);
3526 gcc_assert (mode
!= BLKmode
);
3528 last_insn
= emit_move_insn_1 (x
, y
);
3530 if (y_cst
&& REG_P (x
)
3531 && (set
= single_set (last_insn
)) != NULL_RTX
3532 && SET_DEST (set
) == x
3533 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3534 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3539 /* If Y is representable exactly in a narrower mode, and the target can
3540 perform the extension directly from constant or memory, then emit the
3541 move as an extension. */
3544 compress_float_constant (rtx x
, rtx y
)
3546 enum machine_mode dstmode
= GET_MODE (x
);
3547 enum machine_mode orig_srcmode
= GET_MODE (y
);
3548 enum machine_mode srcmode
;
3550 int oldcost
, newcost
;
3551 bool speed
= optimize_insn_for_speed_p ();
3553 REAL_VALUE_FROM_CONST_DOUBLE (r
, y
);
3555 if (targetm
.legitimate_constant_p (dstmode
, y
))
3556 oldcost
= set_src_cost (y
, speed
);
3558 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), speed
);
3560 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3561 srcmode
!= orig_srcmode
;
3562 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3565 rtx trunc_y
, last_insn
;
3567 /* Skip if the target can't extend this way. */
3568 ic
= can_extend_p (dstmode
, srcmode
, 0);
3569 if (ic
== CODE_FOR_nothing
)
3572 /* Skip if the narrowed value isn't exact. */
3573 if (! exact_real_truncate (srcmode
, &r
))
3576 trunc_y
= CONST_DOUBLE_FROM_REAL_VALUE (r
, srcmode
);
3578 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3580 /* Skip if the target needs extra instructions to perform
3582 if (!insn_operand_matches (ic
, 1, trunc_y
))
3584 /* This is valid, but may not be cheaper than the original. */
3585 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3587 if (oldcost
< newcost
)
3590 else if (float_extend_from_mem
[dstmode
][srcmode
])
3592 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3593 /* This is valid, but may not be cheaper than the original. */
3594 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3596 if (oldcost
< newcost
)
3598 trunc_y
= validize_mem (trunc_y
);
3603 /* For CSE's benefit, force the compressed constant pool entry
3604 into a new pseudo. This constant may be used in different modes,
3605 and if not, combine will put things back together for us. */
3606 trunc_y
= force_reg (srcmode
, trunc_y
);
3607 emit_unop_insn (ic
, x
, trunc_y
, UNKNOWN
);
3608 last_insn
= get_last_insn ();
3611 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3619 /* Pushing data onto the stack. */
3621 /* Push a block of length SIZE (perhaps variable)
3622 and return an rtx to address the beginning of the block.
3623 The value may be virtual_outgoing_args_rtx.
3625 EXTRA is the number of bytes of padding to push in addition to SIZE.
3626 BELOW nonzero means this padding comes at low addresses;
3627 otherwise, the padding comes at high addresses. */
3630 push_block (rtx size
, int extra
, int below
)
3634 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3635 if (CONSTANT_P (size
))
3636 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3637 else if (REG_P (size
) && extra
== 0)
3638 anti_adjust_stack (size
);
3641 temp
= copy_to_mode_reg (Pmode
, size
);
3643 temp
= expand_binop (Pmode
, add_optab
, temp
, GEN_INT (extra
),
3644 temp
, 0, OPTAB_LIB_WIDEN
);
3645 anti_adjust_stack (temp
);
3648 #ifndef STACK_GROWS_DOWNWARD
3654 temp
= virtual_outgoing_args_rtx
;
3655 if (extra
!= 0 && below
)
3656 temp
= plus_constant (Pmode
, temp
, extra
);
3660 if (CONST_INT_P (size
))
3661 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3662 -INTVAL (size
) - (below
? 0 : extra
));
3663 else if (extra
!= 0 && !below
)
3664 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3665 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3668 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3669 negate_rtx (Pmode
, size
));
3672 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3675 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3678 mem_autoinc_base (rtx mem
)
3682 rtx addr
= XEXP (mem
, 0);
3683 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3684 return XEXP (addr
, 0);
3689 /* A utility routine used here, in reload, and in try_split. The insns
3690 after PREV up to and including LAST are known to adjust the stack,
3691 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3692 placing notes as appropriate. PREV may be NULL, indicating the
3693 entire insn sequence prior to LAST should be scanned.
3695 The set of allowed stack pointer modifications is small:
3696 (1) One or more auto-inc style memory references (aka pushes),
3697 (2) One or more addition/subtraction with the SP as destination,
3698 (3) A single move insn with the SP as destination,
3699 (4) A call_pop insn,
3700 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3702 Insns in the sequence that do not modify the SP are ignored,
3703 except for noreturn calls.
3705 The return value is the amount of adjustment that can be trivially
3706 verified, via immediate operand or auto-inc. If the adjustment
3707 cannot be trivially extracted, the return value is INT_MIN. */
3710 find_args_size_adjust (rtx insn
)
3715 pat
= PATTERN (insn
);
3718 /* Look for a call_pop pattern. */
3721 /* We have to allow non-call_pop patterns for the case
3722 of emit_single_push_insn of a TLS address. */
3723 if (GET_CODE (pat
) != PARALLEL
)
3726 /* All call_pop have a stack pointer adjust in the parallel.
3727 The call itself is always first, and the stack adjust is
3728 usually last, so search from the end. */
3729 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3731 set
= XVECEXP (pat
, 0, i
);
3732 if (GET_CODE (set
) != SET
)
3734 dest
= SET_DEST (set
);
3735 if (dest
== stack_pointer_rtx
)
3738 /* We'd better have found the stack pointer adjust. */
3741 /* Fall through to process the extracted SET and DEST
3742 as if it was a standalone insn. */
3744 else if (GET_CODE (pat
) == SET
)
3746 else if ((set
= single_set (insn
)) != NULL
)
3748 else if (GET_CODE (pat
) == PARALLEL
)
3750 /* ??? Some older ports use a parallel with a stack adjust
3751 and a store for a PUSH_ROUNDING pattern, rather than a
3752 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3753 /* ??? See h8300 and m68k, pushqi1. */
3754 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3756 set
= XVECEXP (pat
, 0, i
);
3757 if (GET_CODE (set
) != SET
)
3759 dest
= SET_DEST (set
);
3760 if (dest
== stack_pointer_rtx
)
3763 /* We do not expect an auto-inc of the sp in the parallel. */
3764 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3765 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3766 != stack_pointer_rtx
);
3774 dest
= SET_DEST (set
);
3776 /* Look for direct modifications of the stack pointer. */
3777 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3779 /* Look for a trivial adjustment, otherwise assume nothing. */
3780 /* Note that the SPU restore_stack_block pattern refers to
3781 the stack pointer in V4SImode. Consider that non-trivial. */
3782 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3783 && GET_CODE (SET_SRC (set
)) == PLUS
3784 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3785 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3786 return INTVAL (XEXP (SET_SRC (set
), 1));
3787 /* ??? Reload can generate no-op moves, which will be cleaned
3788 up later. Recognize it and continue searching. */
3789 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3792 return HOST_WIDE_INT_MIN
;
3798 /* Otherwise only think about autoinc patterns. */
3799 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3802 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3803 != stack_pointer_rtx
);
3805 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3806 mem
= SET_SRC (set
);
3810 addr
= XEXP (mem
, 0);
3811 switch (GET_CODE (addr
))
3815 return GET_MODE_SIZE (GET_MODE (mem
));
3818 return -GET_MODE_SIZE (GET_MODE (mem
));
3821 addr
= XEXP (addr
, 1);
3822 gcc_assert (GET_CODE (addr
) == PLUS
);
3823 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3824 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3825 return INTVAL (XEXP (addr
, 1));
3833 fixup_args_size_notes (rtx prev
, rtx last
, int end_args_size
)
3835 int args_size
= end_args_size
;
3836 bool saw_unknown
= false;
3839 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3841 HOST_WIDE_INT this_delta
;
3843 if (!NONDEBUG_INSN_P (insn
))
3846 this_delta
= find_args_size_adjust (insn
);
3847 if (this_delta
== 0)
3850 || ACCUMULATE_OUTGOING_ARGS
3851 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3855 gcc_assert (!saw_unknown
);
3856 if (this_delta
== HOST_WIDE_INT_MIN
)
3859 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3860 #ifdef STACK_GROWS_DOWNWARD
3861 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3863 args_size
-= this_delta
;
3866 return saw_unknown
? INT_MIN
: args_size
;
3869 #ifdef PUSH_ROUNDING
3870 /* Emit single push insn. */
3873 emit_single_push_insn_1 (enum machine_mode mode
, rtx x
, tree type
)
3876 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3878 enum insn_code icode
;
3880 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3881 /* If there is push pattern, use it. Otherwise try old way of throwing
3882 MEM representing push operation to move expander. */
3883 icode
= optab_handler (push_optab
, mode
);
3884 if (icode
!= CODE_FOR_nothing
)
3886 struct expand_operand ops
[1];
3888 create_input_operand (&ops
[0], x
, mode
);
3889 if (maybe_expand_insn (icode
, 1, ops
))
3892 if (GET_MODE_SIZE (mode
) == rounded_size
)
3893 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3894 /* If we are to pad downward, adjust the stack pointer first and
3895 then store X into the stack location using an offset. This is
3896 because emit_move_insn does not know how to pad; it does not have
3898 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3900 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3901 HOST_WIDE_INT offset
;
3903 emit_move_insn (stack_pointer_rtx
,
3904 expand_binop (Pmode
,
3905 #ifdef STACK_GROWS_DOWNWARD
3911 GEN_INT (rounded_size
),
3912 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3914 offset
= (HOST_WIDE_INT
) padding_size
;
3915 #ifdef STACK_GROWS_DOWNWARD
3916 if (STACK_PUSH_CODE
== POST_DEC
)
3917 /* We have already decremented the stack pointer, so get the
3919 offset
+= (HOST_WIDE_INT
) rounded_size
;
3921 if (STACK_PUSH_CODE
== POST_INC
)
3922 /* We have already incremented the stack pointer, so get the
3924 offset
-= (HOST_WIDE_INT
) rounded_size
;
3926 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
3930 #ifdef STACK_GROWS_DOWNWARD
3931 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3932 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3933 GEN_INT (-(HOST_WIDE_INT
) rounded_size
));
3935 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3936 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
3937 GEN_INT (rounded_size
));
3939 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
3942 dest
= gen_rtx_MEM (mode
, dest_addr
);
3946 set_mem_attributes (dest
, type
, 1);
3948 if (flag_optimize_sibling_calls
)
3949 /* Function incoming arguments may overlap with sibling call
3950 outgoing arguments and we cannot allow reordering of reads
3951 from function arguments with stores to outgoing arguments
3952 of sibling calls. */
3953 set_mem_alias_set (dest
, 0);
3955 emit_move_insn (dest
, x
);
3958 /* Emit and annotate a single push insn. */
3961 emit_single_push_insn (enum machine_mode mode
, rtx x
, tree type
)
3963 int delta
, old_delta
= stack_pointer_delta
;
3964 rtx prev
= get_last_insn ();
3967 emit_single_push_insn_1 (mode
, x
, type
);
3969 last
= get_last_insn ();
3971 /* Notice the common case where we emitted exactly one insn. */
3972 if (PREV_INSN (last
) == prev
)
3974 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
3978 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
3979 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
3983 /* Generate code to push X onto the stack, assuming it has mode MODE and
3985 MODE is redundant except when X is a CONST_INT (since they don't
3987 SIZE is an rtx for the size of data to be copied (in bytes),
3988 needed only if X is BLKmode.
3990 ALIGN (in bits) is maximum alignment we can assume.
3992 If PARTIAL and REG are both nonzero, then copy that many of the first
3993 bytes of X into registers starting with REG, and push the rest of X.
3994 The amount of space pushed is decreased by PARTIAL bytes.
3995 REG must be a hard register in this case.
3996 If REG is zero but PARTIAL is not, take any all others actions for an
3997 argument partially in registers, but do not actually load any
4000 EXTRA is the amount in bytes of extra space to leave next to this arg.
4001 This is ignored if an argument block has already been allocated.
4003 On a machine that lacks real push insns, ARGS_ADDR is the address of
4004 the bottom of the argument block for this call. We use indexing off there
4005 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4006 argument block has not been preallocated.
4008 ARGS_SO_FAR is the size of args previously pushed for this call.
4010 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4011 for arguments passed in registers. If nonzero, it will be the number
4012 of bytes required. */
4015 emit_push_insn (rtx x
, enum machine_mode mode
, tree type
, rtx size
,
4016 unsigned int align
, int partial
, rtx reg
, int extra
,
4017 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4021 enum direction stack_direction
4022 #ifdef STACK_GROWS_DOWNWARD
4028 /* Decide where to pad the argument: `downward' for below,
4029 `upward' for above, or `none' for don't pad it.
4030 Default is below for small data on big-endian machines; else above. */
4031 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4033 /* Invert direction if stack is post-decrement.
4035 if (STACK_PUSH_CODE
== POST_DEC
)
4036 if (where_pad
!= none
)
4037 where_pad
= (where_pad
== downward
? upward
: downward
);
4042 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4044 /* Copy a block into the stack, entirely or partially. */
4051 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4052 used
= partial
- offset
;
4054 if (mode
!= BLKmode
)
4056 /* A value is to be stored in an insufficiently aligned
4057 stack slot; copy via a suitably aligned slot if
4059 size
= GEN_INT (GET_MODE_SIZE (mode
));
4060 if (!MEM_P (xinner
))
4062 temp
= assign_temp (type
, 1, 1);
4063 emit_move_insn (temp
, xinner
);
4070 /* USED is now the # of bytes we need not copy to the stack
4071 because registers will take care of them. */
4074 xinner
= adjust_address (xinner
, BLKmode
, used
);
4076 /* If the partial register-part of the arg counts in its stack size,
4077 skip the part of stack space corresponding to the registers.
4078 Otherwise, start copying to the beginning of the stack space,
4079 by setting SKIP to 0. */
4080 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4082 #ifdef PUSH_ROUNDING
4083 /* Do it with several push insns if that doesn't take lots of insns
4084 and if there is no difficulty with push insns that skip bytes
4085 on the stack for alignment purposes. */
4088 && CONST_INT_P (size
)
4090 && MEM_ALIGN (xinner
) >= align
4091 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size
) - used
, align
))
4092 /* Here we avoid the case of a structure whose weak alignment
4093 forces many pushes of a small amount of data,
4094 and such small pushes do rounding that causes trouble. */
4095 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4096 || align
>= BIGGEST_ALIGNMENT
4097 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4098 == (align
/ BITS_PER_UNIT
)))
4099 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4101 /* Push padding now if padding above and stack grows down,
4102 or if padding below and stack grows up.
4103 But if space already allocated, this has already been done. */
4104 if (extra
&& args_addr
== 0
4105 && where_pad
!= none
&& where_pad
!= stack_direction
)
4106 anti_adjust_stack (GEN_INT (extra
));
4108 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4111 #endif /* PUSH_ROUNDING */
4115 /* Otherwise make space on the stack and copy the data
4116 to the address of that space. */
4118 /* Deduct words put into registers from the size we must copy. */
4121 if (CONST_INT_P (size
))
4122 size
= GEN_INT (INTVAL (size
) - used
);
4124 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4125 GEN_INT (used
), NULL_RTX
, 0,
4129 /* Get the address of the stack space.
4130 In this case, we do not deal with EXTRA separately.
4131 A single stack adjust will do. */
4134 temp
= push_block (size
, extra
, where_pad
== downward
);
4137 else if (CONST_INT_P (args_so_far
))
4138 temp
= memory_address (BLKmode
,
4139 plus_constant (Pmode
, args_addr
,
4140 skip
+ INTVAL (args_so_far
)));
4142 temp
= memory_address (BLKmode
,
4143 plus_constant (Pmode
,
4144 gen_rtx_PLUS (Pmode
,
4149 if (!ACCUMULATE_OUTGOING_ARGS
)
4151 /* If the source is referenced relative to the stack pointer,
4152 copy it to another register to stabilize it. We do not need
4153 to do this if we know that we won't be changing sp. */
4155 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4156 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4157 temp
= copy_to_reg (temp
);
4160 target
= gen_rtx_MEM (BLKmode
, temp
);
4162 /* We do *not* set_mem_attributes here, because incoming arguments
4163 may overlap with sibling call outgoing arguments and we cannot
4164 allow reordering of reads from function arguments with stores
4165 to outgoing arguments of sibling calls. We do, however, want
4166 to record the alignment of the stack slot. */
4167 /* ALIGN may well be better aligned than TYPE, e.g. due to
4168 PARM_BOUNDARY. Assume the caller isn't lying. */
4169 set_mem_align (target
, align
);
4171 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4174 else if (partial
> 0)
4176 /* Scalar partly in registers. */
4178 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4181 /* # bytes of start of argument
4182 that we must make space for but need not store. */
4183 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4184 int args_offset
= INTVAL (args_so_far
);
4187 /* Push padding now if padding above and stack grows down,
4188 or if padding below and stack grows up.
4189 But if space already allocated, this has already been done. */
4190 if (extra
&& args_addr
== 0
4191 && where_pad
!= none
&& where_pad
!= stack_direction
)
4192 anti_adjust_stack (GEN_INT (extra
));
4194 /* If we make space by pushing it, we might as well push
4195 the real data. Otherwise, we can leave OFFSET nonzero
4196 and leave the space uninitialized. */
4200 /* Now NOT_STACK gets the number of words that we don't need to
4201 allocate on the stack. Convert OFFSET to words too. */
4202 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4203 offset
/= UNITS_PER_WORD
;
4205 /* If the partial register-part of the arg counts in its stack size,
4206 skip the part of stack space corresponding to the registers.
4207 Otherwise, start copying to the beginning of the stack space,
4208 by setting SKIP to 0. */
4209 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4211 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4212 x
= validize_mem (force_const_mem (mode
, x
));
4214 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4215 SUBREGs of such registers are not allowed. */
4216 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4217 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4218 x
= copy_to_reg (x
);
4220 /* Loop over all the words allocated on the stack for this arg. */
4221 /* We can do it by words, because any scalar bigger than a word
4222 has a size a multiple of a word. */
4223 #ifndef PUSH_ARGS_REVERSED
4224 for (i
= not_stack
; i
< size
; i
++)
4226 for (i
= size
- 1; i
>= not_stack
; i
--)
4228 if (i
>= not_stack
+ offset
)
4229 emit_push_insn (operand_subword_force (x
, i
, mode
),
4230 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4232 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4234 reg_parm_stack_space
, alignment_pad
);
4241 /* Push padding now if padding above and stack grows down,
4242 or if padding below and stack grows up.
4243 But if space already allocated, this has already been done. */
4244 if (extra
&& args_addr
== 0
4245 && where_pad
!= none
&& where_pad
!= stack_direction
)
4246 anti_adjust_stack (GEN_INT (extra
));
4248 #ifdef PUSH_ROUNDING
4249 if (args_addr
== 0 && PUSH_ARGS
)
4250 emit_single_push_insn (mode
, x
, type
);
4254 if (CONST_INT_P (args_so_far
))
4256 = memory_address (mode
,
4257 plus_constant (Pmode
, args_addr
,
4258 INTVAL (args_so_far
)));
4260 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4262 dest
= gen_rtx_MEM (mode
, addr
);
4264 /* We do *not* set_mem_attributes here, because incoming arguments
4265 may overlap with sibling call outgoing arguments and we cannot
4266 allow reordering of reads from function arguments with stores
4267 to outgoing arguments of sibling calls. We do, however, want
4268 to record the alignment of the stack slot. */
4269 /* ALIGN may well be better aligned than TYPE, e.g. due to
4270 PARM_BOUNDARY. Assume the caller isn't lying. */
4271 set_mem_align (dest
, align
);
4273 emit_move_insn (dest
, x
);
4277 /* If part should go in registers, copy that part
4278 into the appropriate registers. Do this now, at the end,
4279 since mem-to-mem copies above may do function calls. */
4280 if (partial
> 0 && reg
!= 0)
4282 /* Handle calls that pass values in multiple non-contiguous locations.
4283 The Irix 6 ABI has examples of this. */
4284 if (GET_CODE (reg
) == PARALLEL
)
4285 emit_group_load (reg
, x
, type
, -1);
4288 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4289 move_block_to_reg (REGNO (reg
), x
, partial
/ UNITS_PER_WORD
, mode
);
4293 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4294 anti_adjust_stack (GEN_INT (extra
));
4296 if (alignment_pad
&& args_addr
== 0)
4297 anti_adjust_stack (alignment_pad
);
4300 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4304 get_subtarget (rtx x
)
4308 /* Only registers can be subtargets. */
4310 /* Don't use hard regs to avoid extending their life. */
4311 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4315 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4316 FIELD is a bitfield. Returns true if the optimization was successful,
4317 and there's nothing else to do. */
4320 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4321 unsigned HOST_WIDE_INT bitpos
,
4322 unsigned HOST_WIDE_INT bitregion_start
,
4323 unsigned HOST_WIDE_INT bitregion_end
,
4324 enum machine_mode mode1
, rtx str_rtx
,
4327 enum machine_mode str_mode
= GET_MODE (str_rtx
);
4328 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4333 enum tree_code code
;
4335 if (mode1
!= VOIDmode
4336 || bitsize
>= BITS_PER_WORD
4337 || str_bitsize
> BITS_PER_WORD
4338 || TREE_SIDE_EFFECTS (to
)
4339 || TREE_THIS_VOLATILE (to
))
4343 if (TREE_CODE (src
) != SSA_NAME
)
4345 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4348 srcstmt
= get_gimple_for_ssa_name (src
);
4350 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4353 code
= gimple_assign_rhs_code (srcstmt
);
4355 op0
= gimple_assign_rhs1 (srcstmt
);
4357 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4358 to find its initialization. Hopefully the initialization will
4359 be from a bitfield load. */
4360 if (TREE_CODE (op0
) == SSA_NAME
)
4362 gimple op0stmt
= get_gimple_for_ssa_name (op0
);
4364 /* We want to eventually have OP0 be the same as TO, which
4365 should be a bitfield. */
4367 || !is_gimple_assign (op0stmt
)
4368 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4370 op0
= gimple_assign_rhs1 (op0stmt
);
4373 op1
= gimple_assign_rhs2 (srcstmt
);
4375 if (!operand_equal_p (to
, op0
, 0))
4378 if (MEM_P (str_rtx
))
4380 unsigned HOST_WIDE_INT offset1
;
4382 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4383 str_mode
= word_mode
;
4384 str_mode
= get_best_mode (bitsize
, bitpos
,
4385 bitregion_start
, bitregion_end
,
4386 MEM_ALIGN (str_rtx
), str_mode
, 0);
4387 if (str_mode
== VOIDmode
)
4389 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4392 bitpos
%= str_bitsize
;
4393 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4394 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4396 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4399 /* If the bit field covers the whole REG/MEM, store_field
4400 will likely generate better code. */
4401 if (bitsize
>= str_bitsize
)
4404 /* We can't handle fields split across multiple entities. */
4405 if (bitpos
+ bitsize
> str_bitsize
)
4408 if (BYTES_BIG_ENDIAN
)
4409 bitpos
= str_bitsize
- bitpos
- bitsize
;
4415 /* For now, just optimize the case of the topmost bitfield
4416 where we don't need to do any masking and also
4417 1 bit bitfields where xor can be used.
4418 We might win by one instruction for the other bitfields
4419 too if insv/extv instructions aren't used, so that
4420 can be added later. */
4421 if (bitpos
+ bitsize
!= str_bitsize
4422 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4425 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4426 value
= convert_modes (str_mode
,
4427 TYPE_MODE (TREE_TYPE (op1
)), value
,
4428 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4430 /* We may be accessing data outside the field, which means
4431 we can alias adjacent data. */
4432 if (MEM_P (str_rtx
))
4434 str_rtx
= shallow_copy_rtx (str_rtx
);
4435 set_mem_alias_set (str_rtx
, 0);
4436 set_mem_expr (str_rtx
, 0);
4439 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4440 if (bitsize
== 1 && bitpos
+ bitsize
!= str_bitsize
)
4442 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4445 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4446 result
= expand_binop (str_mode
, binop
, str_rtx
,
4447 value
, str_rtx
, 1, OPTAB_WIDEN
);
4448 if (result
!= str_rtx
)
4449 emit_move_insn (str_rtx
, result
);
4454 if (TREE_CODE (op1
) != INTEGER_CST
)
4456 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4457 value
= convert_modes (str_mode
,
4458 TYPE_MODE (TREE_TYPE (op1
)), value
,
4459 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4461 /* We may be accessing data outside the field, which means
4462 we can alias adjacent data. */
4463 if (MEM_P (str_rtx
))
4465 str_rtx
= shallow_copy_rtx (str_rtx
);
4466 set_mem_alias_set (str_rtx
, 0);
4467 set_mem_expr (str_rtx
, 0);
4470 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4471 if (bitpos
+ bitsize
!= str_bitsize
)
4473 rtx mask
= GEN_INT (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1);
4474 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4476 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4477 result
= expand_binop (str_mode
, binop
, str_rtx
,
4478 value
, str_rtx
, 1, OPTAB_WIDEN
);
4479 if (result
!= str_rtx
)
4480 emit_move_insn (str_rtx
, result
);
4490 /* In the C++ memory model, consecutive bit fields in a structure are
4491 considered one memory location.
4493 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4494 returns the bit range of consecutive bits in which this COMPONENT_REF
4495 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4496 and *OFFSET may be adjusted in the process.
4498 If the access does not need to be restricted, 0 is returned in both
4499 *BITSTART and *BITEND. */
4502 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4503 unsigned HOST_WIDE_INT
*bitend
,
4505 HOST_WIDE_INT
*bitpos
,
4508 HOST_WIDE_INT bitoffset
;
4511 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4513 field
= TREE_OPERAND (exp
, 1);
4514 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4515 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4516 need to limit the range we can access. */
4519 *bitstart
= *bitend
= 0;
4523 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4524 part of a larger bit field, then the representative does not serve any
4525 useful purpose. This can occur in Ada. */
4526 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4528 enum machine_mode rmode
;
4529 HOST_WIDE_INT rbitsize
, rbitpos
;
4533 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4534 &roffset
, &rmode
, &unsignedp
, &volatilep
, false);
4535 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4537 *bitstart
= *bitend
= 0;
4542 /* Compute the adjustment to bitpos from the offset of the field
4543 relative to the representative. DECL_FIELD_OFFSET of field and
4544 repr are the same by construction if they are not constants,
4545 see finish_bitfield_layout. */
4546 if (host_integerp (DECL_FIELD_OFFSET (field
), 1)
4547 && host_integerp (DECL_FIELD_OFFSET (repr
), 1))
4548 bitoffset
= (tree_low_cst (DECL_FIELD_OFFSET (field
), 1)
4549 - tree_low_cst (DECL_FIELD_OFFSET (repr
), 1)) * BITS_PER_UNIT
;
4552 bitoffset
+= (tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 1)
4553 - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr
), 1));
4555 /* If the adjustment is larger than bitpos, we would have a negative bit
4556 position for the lower bound and this may wreak havoc later. This can
4557 occur only if we have a non-null offset, so adjust offset and bitpos
4558 to make the lower bound non-negative. */
4559 if (bitoffset
> *bitpos
)
4561 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4563 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4564 gcc_assert (*offset
!= NULL_TREE
);
4568 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4572 *bitstart
= *bitpos
- bitoffset
;
4574 *bitend
= *bitstart
+ tree_low_cst (DECL_SIZE (repr
), 1) - 1;
4577 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4578 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4579 DECL_RTL was not set yet, return NORTL. */
4582 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4584 if (TREE_CODE (addr
) != ADDR_EXPR
)
4587 tree base
= TREE_OPERAND (addr
, 0);
4590 || TREE_ADDRESSABLE (base
)
4591 || DECL_MODE (base
) == BLKmode
)
4594 if (!DECL_RTL_SET_P (base
))
4597 return (!MEM_P (DECL_RTL (base
)));
4600 /* Returns true if the MEM_REF REF refers to an object that does not
4601 reside in memory and has non-BLKmode. */
4604 mem_ref_refers_to_non_mem_p (tree ref
)
4606 tree base
= TREE_OPERAND (ref
, 0);
4607 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4610 /* Return TRUE iff OP is an ADDR_EXPR of a DECL that's not
4611 addressable. This is very much like mem_ref_refers_to_non_mem_p,
4612 but instead of the MEM_REF, it takes its base, and it doesn't
4613 assume a DECL is in memory just because its RTL is not set yet. */
4616 addr_expr_of_non_mem_decl_p (tree op
)
4618 return addr_expr_of_non_mem_decl_p_1 (op
, true);
4621 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4622 is true, try generating a nontemporal store. */
4625 expand_assignment (tree to
, tree from
, bool nontemporal
)
4629 enum machine_mode mode
;
4631 enum insn_code icode
;
4633 /* Don't crash if the lhs of the assignment was erroneous. */
4634 if (TREE_CODE (to
) == ERROR_MARK
)
4636 expand_normal (from
);
4640 /* Optimize away no-op moves without side-effects. */
4641 if (operand_equal_p (to
, from
, 0))
4644 /* Handle misaligned stores. */
4645 mode
= TYPE_MODE (TREE_TYPE (to
));
4646 if ((TREE_CODE (to
) == MEM_REF
4647 || TREE_CODE (to
) == TARGET_MEM_REF
)
4649 && !mem_ref_refers_to_non_mem_p (to
)
4650 && ((align
= get_object_alignment (to
))
4651 < GET_MODE_ALIGNMENT (mode
))
4652 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4653 != CODE_FOR_nothing
)
4654 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4658 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4659 reg
= force_not_mem (reg
);
4660 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4662 if (icode
!= CODE_FOR_nothing
)
4664 struct expand_operand ops
[2];
4666 create_fixed_operand (&ops
[0], mem
);
4667 create_input_operand (&ops
[1], reg
, mode
);
4668 /* The movmisalign<mode> pattern cannot fail, else the assignment
4669 would silently be omitted. */
4670 expand_insn (icode
, 2, ops
);
4673 store_bit_field (mem
, GET_MODE_BITSIZE (mode
),
4674 0, 0, 0, mode
, reg
);
4678 /* Assignment of a structure component needs special treatment
4679 if the structure component's rtx is not simply a MEM.
4680 Assignment of an array element at a constant index, and assignment of
4681 an array element in an unaligned packed structure field, has the same
4682 problem. Same for (partially) storing into a non-memory object. */
4683 if (handled_component_p (to
)
4684 || (TREE_CODE (to
) == MEM_REF
4685 && mem_ref_refers_to_non_mem_p (to
))
4686 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4688 enum machine_mode mode1
;
4689 HOST_WIDE_INT bitsize
, bitpos
;
4690 unsigned HOST_WIDE_INT bitregion_start
= 0;
4691 unsigned HOST_WIDE_INT bitregion_end
= 0;
4700 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4701 &unsignedp
, &volatilep
, true);
4703 if (TREE_CODE (to
) == COMPONENT_REF
4704 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4705 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4707 /* If we are going to use store_bit_field and extract_bit_field,
4708 make sure to_rtx will be safe for multiple use. */
4709 mode
= TYPE_MODE (TREE_TYPE (tem
));
4710 if (TREE_CODE (tem
) == MEM_REF
4712 && ((align
= get_object_alignment (tem
))
4713 < GET_MODE_ALIGNMENT (mode
))
4714 && ((icode
= optab_handler (movmisalign_optab
, mode
))
4715 != CODE_FOR_nothing
))
4717 struct expand_operand ops
[2];
4720 to_rtx
= gen_reg_rtx (mode
);
4721 mem
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4723 /* If the misaligned store doesn't overwrite all bits, perform
4724 rmw cycle on MEM. */
4725 if (bitsize
!= GET_MODE_BITSIZE (mode
))
4727 create_input_operand (&ops
[0], to_rtx
, mode
);
4728 create_fixed_operand (&ops
[1], mem
);
4729 /* The movmisalign<mode> pattern cannot fail, else the assignment
4730 would silently be omitted. */
4731 expand_insn (icode
, 2, ops
);
4733 mem
= copy_rtx (mem
);
4739 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4742 /* If the bitfield is volatile, we want to access it in the
4743 field's mode, not the computed mode.
4744 If a MEM has VOIDmode (external with incomplete type),
4745 use BLKmode for it instead. */
4748 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
4749 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4750 else if (GET_MODE (to_rtx
) == VOIDmode
)
4751 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4756 enum machine_mode address_mode
;
4759 if (!MEM_P (to_rtx
))
4761 /* We can get constant negative offsets into arrays with broken
4762 user code. Translate this to a trap instead of ICEing. */
4763 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4764 expand_builtin_trap ();
4765 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4768 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4769 address_mode
= get_address_mode (to_rtx
);
4770 if (GET_MODE (offset_rtx
) != address_mode
)
4771 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4773 /* A constant address in TO_RTX can have VOIDmode, we must not try
4774 to call force_reg for that case. Avoid that case. */
4776 && GET_MODE (to_rtx
) == BLKmode
4777 && GET_MODE (XEXP (to_rtx
, 0)) != VOIDmode
4779 && (bitpos
% bitsize
) == 0
4780 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4781 && MEM_ALIGN (to_rtx
) == GET_MODE_ALIGNMENT (mode1
))
4783 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4787 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4788 highest_pow2_factor_for_target (to
,
4792 /* No action is needed if the target is not a memory and the field
4793 lies completely outside that target. This can occur if the source
4794 code contains an out-of-bounds access to a small array. */
4796 && GET_MODE (to_rtx
) != BLKmode
4797 && (unsigned HOST_WIDE_INT
) bitpos
4798 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4800 expand_normal (from
);
4803 /* Handle expand_expr of a complex value returning a CONCAT. */
4804 else if (GET_CODE (to_rtx
) == CONCAT
)
4806 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4807 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4809 && bitsize
== mode_bitsize
)
4810 result
= store_expr (from
, to_rtx
, false, nontemporal
);
4811 else if (bitsize
== mode_bitsize
/ 2
4812 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4813 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4815 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4816 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4817 bitregion_start
, bitregion_end
,
4819 get_alias_set (to
), nontemporal
);
4820 else if (bitpos
>= mode_bitsize
/ 2)
4821 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4822 bitpos
- mode_bitsize
/ 2,
4823 bitregion_start
, bitregion_end
,
4825 get_alias_set (to
), nontemporal
);
4826 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4829 result
= expand_normal (from
);
4830 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4831 TYPE_MODE (TREE_TYPE (from
)), 0);
4832 emit_move_insn (XEXP (to_rtx
, 0),
4833 read_complex_part (from_rtx
, false));
4834 emit_move_insn (XEXP (to_rtx
, 1),
4835 read_complex_part (from_rtx
, true));
4839 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4840 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4841 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4842 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4843 result
= store_field (temp
, bitsize
, bitpos
,
4844 bitregion_start
, bitregion_end
,
4846 get_alias_set (to
), nontemporal
);
4847 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4848 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
4855 /* If the field is at offset zero, we could have been given the
4856 DECL_RTX of the parent struct. Don't munge it. */
4857 to_rtx
= shallow_copy_rtx (to_rtx
);
4859 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
4861 /* Deal with volatile and readonly fields. The former is only
4862 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4864 MEM_VOLATILE_P (to_rtx
) = 1;
4867 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
4868 bitregion_start
, bitregion_end
,
4873 result
= store_field (to_rtx
, bitsize
, bitpos
,
4874 bitregion_start
, bitregion_end
,
4876 get_alias_set (to
), nontemporal
);
4881 struct expand_operand ops
[2];
4883 create_fixed_operand (&ops
[0], mem
);
4884 create_input_operand (&ops
[1], to_rtx
, mode
);
4885 /* The movmisalign<mode> pattern cannot fail, else the assignment
4886 would silently be omitted. */
4887 expand_insn (icode
, 2, ops
);
4891 preserve_temp_slots (result
);
4896 /* If the rhs is a function call and its value is not an aggregate,
4897 call the function before we start to compute the lhs.
4898 This is needed for correct code for cases such as
4899 val = setjmp (buf) on machines where reference to val
4900 requires loading up part of an address in a separate insn.
4902 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4903 since it might be a promoted variable where the zero- or sign- extension
4904 needs to be done. Handling this in the normal way is safe because no
4905 computation is done before the call. The same is true for SSA names. */
4906 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
4907 && COMPLETE_TYPE_P (TREE_TYPE (from
))
4908 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
4909 && ! (((TREE_CODE (to
) == VAR_DECL
4910 || TREE_CODE (to
) == PARM_DECL
4911 || TREE_CODE (to
) == RESULT_DECL
)
4912 && REG_P (DECL_RTL (to
)))
4913 || TREE_CODE (to
) == SSA_NAME
))
4918 value
= expand_normal (from
);
4920 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4922 /* Handle calls that return values in multiple non-contiguous locations.
4923 The Irix 6 ABI has examples of this. */
4924 if (GET_CODE (to_rtx
) == PARALLEL
)
4926 if (GET_CODE (value
) == PARALLEL
)
4927 emit_group_move (to_rtx
, value
);
4929 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
4930 int_size_in_bytes (TREE_TYPE (from
)));
4932 else if (GET_CODE (value
) == PARALLEL
)
4933 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
4934 int_size_in_bytes (TREE_TYPE (from
)));
4935 else if (GET_MODE (to_rtx
) == BLKmode
)
4937 /* Handle calls that return BLKmode values in registers. */
4939 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
4941 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
4945 if (POINTER_TYPE_P (TREE_TYPE (to
)))
4946 value
= convert_memory_address_addr_space
4947 (GET_MODE (to_rtx
), value
,
4948 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
4950 emit_move_insn (to_rtx
, value
);
4952 preserve_temp_slots (to_rtx
);
4957 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
4958 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4960 /* Don't move directly into a return register. */
4961 if (TREE_CODE (to
) == RESULT_DECL
4962 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
4968 /* If the source is itself a return value, it still is in a pseudo at
4969 this point so we can move it back to the return register directly. */
4971 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
4972 && TREE_CODE (from
) != CALL_EXPR
)
4973 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
4975 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
4977 /* Handle calls that return values in multiple non-contiguous locations.
4978 The Irix 6 ABI has examples of this. */
4979 if (GET_CODE (to_rtx
) == PARALLEL
)
4981 if (GET_CODE (temp
) == PARALLEL
)
4982 emit_group_move (to_rtx
, temp
);
4984 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
4985 int_size_in_bytes (TREE_TYPE (from
)));
4988 emit_move_insn (to_rtx
, temp
);
4990 preserve_temp_slots (to_rtx
);
4995 /* In case we are returning the contents of an object which overlaps
4996 the place the value is being stored, use a safe function when copying
4997 a value through a pointer into a structure value return block. */
4998 if (TREE_CODE (to
) == RESULT_DECL
4999 && TREE_CODE (from
) == INDIRECT_REF
5000 && ADDR_SPACE_GENERIC_P
5001 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5002 && refs_may_alias_p (to
, from
)
5003 && cfun
->returns_struct
5004 && !cfun
->returns_pcc_struct
)
5009 size
= expr_size (from
);
5010 from_rtx
= expand_normal (from
);
5012 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5013 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5014 XEXP (from_rtx
, 0), Pmode
,
5015 convert_to_mode (TYPE_MODE (sizetype
),
5016 size
, TYPE_UNSIGNED (sizetype
)),
5017 TYPE_MODE (sizetype
));
5019 preserve_temp_slots (to_rtx
);
5024 /* Compute FROM and store the value in the rtx we got. */
5027 result
= store_expr (from
, to_rtx
, 0, nontemporal
);
5028 preserve_temp_slots (result
);
5033 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5034 succeeded, false otherwise. */
5037 emit_storent_insn (rtx to
, rtx from
)
5039 struct expand_operand ops
[2];
5040 enum machine_mode mode
= GET_MODE (to
);
5041 enum insn_code code
= optab_handler (storent_optab
, mode
);
5043 if (code
== CODE_FOR_nothing
)
5046 create_fixed_operand (&ops
[0], to
);
5047 create_input_operand (&ops
[1], from
, mode
);
5048 return maybe_expand_insn (code
, 2, ops
);
5051 /* Generate code for computing expression EXP,
5052 and storing the value into TARGET.
5054 If the mode is BLKmode then we may return TARGET itself.
5055 It turns out that in BLKmode it doesn't cause a problem.
5056 because C has no operators that could combine two different
5057 assignments into the same BLKmode object with different values
5058 with no sequence point. Will other languages need this to
5061 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5062 stack, and block moves may need to be treated specially.
5064 If NONTEMPORAL is true, try using a nontemporal store instruction. */
5067 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
)
5070 rtx alt_rtl
= NULL_RTX
;
5071 location_t loc
= curr_insn_location ();
5073 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5075 /* C++ can generate ?: expressions with a throw expression in one
5076 branch and an rvalue in the other. Here, we resolve attempts to
5077 store the throw expression's nonexistent result. */
5078 gcc_assert (!call_param_p
);
5079 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5082 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5084 /* Perform first part of compound expression, then assign from second
5086 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5087 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5088 return store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5091 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5093 /* For conditional expression, get safe form of the target. Then
5094 test the condition, doing the appropriate assignment on either
5095 side. This avoids the creation of unnecessary temporaries.
5096 For non-BLKmode, it is more efficient not to do this. */
5098 rtx lab1
= gen_label_rtx (), lab2
= gen_label_rtx ();
5100 do_pending_stack_adjust ();
5102 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5103 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5105 emit_jump_insn (gen_jump (lab2
));
5108 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5115 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5116 /* If this is a scalar in a register that is stored in a wider mode
5117 than the declared mode, compute the result into its declared mode
5118 and then convert to the wider mode. Our value is the computed
5121 rtx inner_target
= 0;
5123 /* We can do the conversion inside EXP, which will often result
5124 in some optimizations. Do the conversion in two steps: first
5125 change the signedness, if needed, then the extend. But don't
5126 do this if the type of EXP is a subtype of something else
5127 since then the conversion might involve more than just
5128 converting modes. */
5129 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5130 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5131 && GET_MODE_PRECISION (GET_MODE (target
))
5132 == TYPE_PRECISION (TREE_TYPE (exp
)))
5134 if (TYPE_UNSIGNED (TREE_TYPE (exp
))
5135 != SUBREG_PROMOTED_UNSIGNED_P (target
))
5137 /* Some types, e.g. Fortran's logical*4, won't have a signed
5138 version, so use the mode instead. */
5140 = (signed_or_unsigned_type_for
5141 (SUBREG_PROMOTED_UNSIGNED_P (target
), TREE_TYPE (exp
)));
5143 ntype
= lang_hooks
.types
.type_for_mode
5144 (TYPE_MODE (TREE_TYPE (exp
)),
5145 SUBREG_PROMOTED_UNSIGNED_P (target
));
5147 exp
= fold_convert_loc (loc
, ntype
, exp
);
5150 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5151 (GET_MODE (SUBREG_REG (target
)),
5152 SUBREG_PROMOTED_UNSIGNED_P (target
)),
5155 inner_target
= SUBREG_REG (target
);
5158 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5159 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5161 /* If TEMP is a VOIDmode constant, use convert_modes to make
5162 sure that we properly convert it. */
5163 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5165 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5166 temp
, SUBREG_PROMOTED_UNSIGNED_P (target
));
5167 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5168 GET_MODE (target
), temp
,
5169 SUBREG_PROMOTED_UNSIGNED_P (target
));
5172 convert_move (SUBREG_REG (target
), temp
,
5173 SUBREG_PROMOTED_UNSIGNED_P (target
));
5177 else if ((TREE_CODE (exp
) == STRING_CST
5178 || (TREE_CODE (exp
) == MEM_REF
5179 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5180 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5182 && integer_zerop (TREE_OPERAND (exp
, 1))))
5183 && !nontemporal
&& !call_param_p
5186 /* Optimize initialization of an array with a STRING_CST. */
5187 HOST_WIDE_INT exp_len
, str_copy_len
;
5189 tree str
= TREE_CODE (exp
) == STRING_CST
5190 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5192 exp_len
= int_expr_size (exp
);
5196 if (TREE_STRING_LENGTH (str
) <= 0)
5199 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5200 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5203 str_copy_len
= TREE_STRING_LENGTH (str
);
5204 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5205 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5207 str_copy_len
+= STORE_MAX_PIECES
- 1;
5208 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5210 str_copy_len
= MIN (str_copy_len
, exp_len
);
5211 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5212 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5213 MEM_ALIGN (target
), false))
5218 dest_mem
= store_by_pieces (dest_mem
,
5219 str_copy_len
, builtin_strncpy_read_str
,
5221 TREE_STRING_POINTER (str
)),
5222 MEM_ALIGN (target
), false,
5223 exp_len
> str_copy_len
? 1 : 0);
5224 if (exp_len
> str_copy_len
)
5225 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5226 GEN_INT (exp_len
- str_copy_len
),
5235 /* If we want to use a nontemporal store, force the value to
5237 tmp_target
= nontemporal
? NULL_RTX
: target
;
5238 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5240 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5244 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5245 the same as that of TARGET, adjust the constant. This is needed, for
5246 example, in case it is a CONST_DOUBLE and we want only a word-sized
5248 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5249 && TREE_CODE (exp
) != ERROR_MARK
5250 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5251 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5252 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5254 /* If value was not generated in the target, store it there.
5255 Convert the value to TARGET's type first if necessary and emit the
5256 pending incrementations that have been queued when expanding EXP.
5257 Note that we cannot emit the whole queue blindly because this will
5258 effectively disable the POST_INC optimization later.
5260 If TEMP and TARGET compare equal according to rtx_equal_p, but
5261 one or both of them are volatile memory refs, we have to distinguish
5263 - expand_expr has used TARGET. In this case, we must not generate
5264 another copy. This can be detected by TARGET being equal according
5266 - expand_expr has not used TARGET - that means that the source just
5267 happens to have the same RTX form. Since temp will have been created
5268 by expand_expr, it will compare unequal according to == .
5269 We must generate a copy in this case, to reach the correct number
5270 of volatile memory references. */
5272 if ((! rtx_equal_p (temp
, target
)
5273 || (temp
!= target
&& (side_effects_p (temp
)
5274 || side_effects_p (target
))))
5275 && TREE_CODE (exp
) != ERROR_MARK
5276 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5277 but TARGET is not valid memory reference, TEMP will differ
5278 from TARGET although it is really the same location. */
5280 && rtx_equal_p (alt_rtl
, target
)
5281 && !side_effects_p (alt_rtl
)
5282 && !side_effects_p (target
))
5283 /* If there's nothing to copy, don't bother. Don't call
5284 expr_size unless necessary, because some front-ends (C++)
5285 expr_size-hook must not be given objects that are not
5286 supposed to be bit-copied or bit-initialized. */
5287 && expr_size (exp
) != const0_rtx
)
5289 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5291 if (GET_MODE (target
) == BLKmode
)
5293 /* Handle calls that return BLKmode values in registers. */
5294 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5295 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5297 store_bit_field (target
,
5298 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5299 0, 0, 0, GET_MODE (temp
), temp
);
5302 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5305 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5307 /* Handle copying a string constant into an array. The string
5308 constant may be shorter than the array. So copy just the string's
5309 actual length, and clear the rest. First get the size of the data
5310 type of the string, which is actually the size of the target. */
5311 rtx size
= expr_size (exp
);
5313 if (CONST_INT_P (size
)
5314 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5315 emit_block_move (target
, temp
, size
,
5317 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5320 enum machine_mode pointer_mode
5321 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5322 enum machine_mode address_mode
= get_address_mode (target
);
5324 /* Compute the size of the data to copy from the string. */
5326 = size_binop_loc (loc
, MIN_EXPR
,
5327 make_tree (sizetype
, size
),
5328 size_int (TREE_STRING_LENGTH (exp
)));
5330 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5332 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5335 /* Copy that much. */
5336 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5337 TYPE_UNSIGNED (sizetype
));
5338 emit_block_move (target
, temp
, copy_size_rtx
,
5340 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5342 /* Figure out how much is left in TARGET that we have to clear.
5343 Do all calculations in pointer_mode. */
5344 if (CONST_INT_P (copy_size_rtx
))
5346 size
= plus_constant (address_mode
, size
,
5347 -INTVAL (copy_size_rtx
));
5348 target
= adjust_address (target
, BLKmode
,
5349 INTVAL (copy_size_rtx
));
5353 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5354 copy_size_rtx
, NULL_RTX
, 0,
5357 if (GET_MODE (copy_size_rtx
) != address_mode
)
5358 copy_size_rtx
= convert_to_mode (address_mode
,
5360 TYPE_UNSIGNED (sizetype
));
5362 target
= offset_address (target
, copy_size_rtx
,
5363 highest_pow2_factor (copy_size
));
5364 label
= gen_label_rtx ();
5365 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5366 GET_MODE (size
), 0, label
);
5369 if (size
!= const0_rtx
)
5370 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5376 /* Handle calls that return values in multiple non-contiguous locations.
5377 The Irix 6 ABI has examples of this. */
5378 else if (GET_CODE (target
) == PARALLEL
)
5380 if (GET_CODE (temp
) == PARALLEL
)
5381 emit_group_move (target
, temp
);
5383 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5384 int_size_in_bytes (TREE_TYPE (exp
)));
5386 else if (GET_CODE (temp
) == PARALLEL
)
5387 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5388 int_size_in_bytes (TREE_TYPE (exp
)));
5389 else if (GET_MODE (temp
) == BLKmode
)
5390 emit_block_move (target
, temp
, expr_size (exp
),
5392 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5393 /* If we emit a nontemporal store, there is nothing else to do. */
5394 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5398 temp
= force_operand (temp
, target
);
5400 emit_move_insn (target
, temp
);
5407 /* Return true if field F of structure TYPE is a flexible array. */
5410 flexible_array_member_p (const_tree f
, const_tree type
)
5415 return (DECL_CHAIN (f
) == NULL
5416 && TREE_CODE (tf
) == ARRAY_TYPE
5418 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5419 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5420 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5421 && int_size_in_bytes (type
) >= 0);
5424 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5425 must have in order for it to completely initialize a value of type TYPE.
5426 Return -1 if the number isn't known.
5428 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5430 static HOST_WIDE_INT
5431 count_type_elements (const_tree type
, bool for_ctor_p
)
5433 switch (TREE_CODE (type
))
5439 nelts
= array_type_nelts (type
);
5440 if (nelts
&& host_integerp (nelts
, 1))
5442 unsigned HOST_WIDE_INT n
;
5444 n
= tree_low_cst (nelts
, 1) + 1;
5445 if (n
== 0 || for_ctor_p
)
5448 return n
* count_type_elements (TREE_TYPE (type
), false);
5450 return for_ctor_p
? -1 : 1;
5455 unsigned HOST_WIDE_INT n
;
5459 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5460 if (TREE_CODE (f
) == FIELD_DECL
)
5463 n
+= count_type_elements (TREE_TYPE (f
), false);
5464 else if (!flexible_array_member_p (f
, type
))
5465 /* Don't count flexible arrays, which are not supposed
5466 to be initialized. */
5474 case QUAL_UNION_TYPE
:
5479 gcc_assert (!for_ctor_p
);
5480 /* Estimate the number of scalars in each field and pick the
5481 maximum. Other estimates would do instead; the idea is simply
5482 to make sure that the estimate is not sensitive to the ordering
5485 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5486 if (TREE_CODE (f
) == FIELD_DECL
)
5488 m
= count_type_elements (TREE_TYPE (f
), false);
5489 /* If the field doesn't span the whole union, add an extra
5490 scalar for the rest. */
5491 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5492 TYPE_SIZE (type
)) != 1)
5504 return TYPE_VECTOR_SUBPARTS (type
);
5508 case FIXED_POINT_TYPE
:
5513 case REFERENCE_TYPE
:
5529 /* Helper for categorize_ctor_elements. Identical interface. */
5532 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5533 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5535 unsigned HOST_WIDE_INT idx
;
5536 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5537 tree value
, purpose
, elt_type
;
5539 /* Whether CTOR is a valid constant initializer, in accordance with what
5540 initializer_constant_valid_p does. If inferred from the constructor
5541 elements, true until proven otherwise. */
5542 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5543 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5548 elt_type
= NULL_TREE
;
5550 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5552 HOST_WIDE_INT mult
= 1;
5554 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5556 tree lo_index
= TREE_OPERAND (purpose
, 0);
5557 tree hi_index
= TREE_OPERAND (purpose
, 1);
5559 if (host_integerp (lo_index
, 1) && host_integerp (hi_index
, 1))
5560 mult
= (tree_low_cst (hi_index
, 1)
5561 - tree_low_cst (lo_index
, 1) + 1);
5564 elt_type
= TREE_TYPE (value
);
5566 switch (TREE_CODE (value
))
5570 HOST_WIDE_INT nz
= 0, ic
= 0;
5572 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5575 nz_elts
+= mult
* nz
;
5576 init_elts
+= mult
* ic
;
5578 if (const_from_elts_p
&& const_p
)
5579 const_p
= const_elt_p
;
5586 if (!initializer_zerop (value
))
5592 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5593 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5597 if (!initializer_zerop (TREE_REALPART (value
)))
5599 if (!initializer_zerop (TREE_IMAGPART (value
)))
5607 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5609 tree v
= VECTOR_CST_ELT (value
, i
);
5610 if (!initializer_zerop (v
))
5619 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5620 nz_elts
+= mult
* tc
;
5621 init_elts
+= mult
* tc
;
5623 if (const_from_elts_p
&& const_p
)
5624 const_p
= initializer_constant_valid_p (value
, elt_type
)
5631 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5632 num_fields
, elt_type
))
5633 *p_complete
= false;
5635 *p_nz_elts
+= nz_elts
;
5636 *p_init_elts
+= init_elts
;
5641 /* Examine CTOR to discover:
5642 * how many scalar fields are set to nonzero values,
5643 and place it in *P_NZ_ELTS;
5644 * how many scalar fields in total are in CTOR,
5645 and place it in *P_ELT_COUNT.
5646 * whether the constructor is complete -- in the sense that every
5647 meaningful byte is explicitly given a value --
5648 and place it in *P_COMPLETE.
5650 Return whether or not CTOR is a valid static constant initializer, the same
5651 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5654 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5655 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5661 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5664 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5665 of which had type LAST_TYPE. Each element was itself a complete
5666 initializer, in the sense that every meaningful byte was explicitly
5667 given a value. Return true if the same is true for the constructor
5671 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5672 const_tree last_type
)
5674 if (TREE_CODE (type
) == UNION_TYPE
5675 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5680 gcc_assert (num_elts
== 1 && last_type
);
5682 /* ??? We could look at each element of the union, and find the
5683 largest element. Which would avoid comparing the size of the
5684 initialized element against any tail padding in the union.
5685 Doesn't seem worth the effort... */
5686 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5689 return count_type_elements (type
, true) == num_elts
;
5692 /* Return 1 if EXP contains mostly (3/4) zeros. */
5695 mostly_zeros_p (const_tree exp
)
5697 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5699 HOST_WIDE_INT nz_elts
, init_elts
;
5702 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5703 return !complete_p
|| nz_elts
< init_elts
/ 4;
5706 return initializer_zerop (exp
);
5709 /* Return 1 if EXP contains all zeros. */
5712 all_zeros_p (const_tree exp
)
5714 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5716 HOST_WIDE_INT nz_elts
, init_elts
;
5719 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5720 return nz_elts
== 0;
5723 return initializer_zerop (exp
);
5726 /* Helper function for store_constructor.
5727 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5728 CLEARED is as for store_constructor.
5729 ALIAS_SET is the alias set to use for any stores.
5731 This provides a recursive shortcut back to store_constructor when it isn't
5732 necessary to go through store_field. This is so that we can pass through
5733 the cleared field to let store_constructor know that we may not have to
5734 clear a substructure if the outer structure has already been cleared. */
5737 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5738 HOST_WIDE_INT bitpos
, enum machine_mode mode
,
5739 tree exp
, int cleared
, alias_set_type alias_set
)
5741 if (TREE_CODE (exp
) == CONSTRUCTOR
5742 /* We can only call store_constructor recursively if the size and
5743 bit position are on a byte boundary. */
5744 && bitpos
% BITS_PER_UNIT
== 0
5745 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5746 /* If we have a nonzero bitpos for a register target, then we just
5747 let store_field do the bitfield handling. This is unlikely to
5748 generate unnecessary clear instructions anyways. */
5749 && (bitpos
== 0 || MEM_P (target
)))
5753 = adjust_address (target
,
5754 GET_MODE (target
) == BLKmode
5756 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5757 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5760 /* Update the alias set, if required. */
5761 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5762 && MEM_ALIAS_SET (target
) != 0)
5764 target
= copy_rtx (target
);
5765 set_mem_alias_set (target
, alias_set
);
5768 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
);
5771 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false);
5774 /* Store the value of constructor EXP into the rtx TARGET.
5775 TARGET is either a REG or a MEM; we know it cannot conflict, since
5776 safe_from_p has been called.
5777 CLEARED is true if TARGET is known to have been zero'd.
5778 SIZE is the number of bytes of TARGET we are allowed to modify: this
5779 may not be the same as the size of EXP if we are assigning to a field
5780 which has been packed to exclude padding bits. */
5783 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
)
5785 tree type
= TREE_TYPE (exp
);
5786 #ifdef WORD_REGISTER_OPERATIONS
5787 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
5790 switch (TREE_CODE (type
))
5794 case QUAL_UNION_TYPE
:
5796 unsigned HOST_WIDE_INT idx
;
5799 /* If size is zero or the target is already cleared, do nothing. */
5800 if (size
== 0 || cleared
)
5802 /* We either clear the aggregate or indicate the value is dead. */
5803 else if ((TREE_CODE (type
) == UNION_TYPE
5804 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5805 && ! CONSTRUCTOR_ELTS (exp
))
5806 /* If the constructor is empty, clear the union. */
5808 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
5812 /* If we are building a static constructor into a register,
5813 set the initial value as zero so we can fold the value into
5814 a constant. But if more than one register is involved,
5815 this probably loses. */
5816 else if (REG_P (target
) && TREE_STATIC (exp
)
5817 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
5819 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
5823 /* If the constructor has fewer fields than the structure or
5824 if we are initializing the structure to mostly zeros, clear
5825 the whole structure first. Don't do this if TARGET is a
5826 register whose mode size isn't equal to SIZE since
5827 clear_storage can't handle this case. */
5829 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
5830 != fields_length (type
))
5831 || mostly_zeros_p (exp
))
5833 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
5836 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
5840 if (REG_P (target
) && !cleared
)
5841 emit_clobber (target
);
5843 /* Store each element of the constructor into the
5844 corresponding field of TARGET. */
5845 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
5847 enum machine_mode mode
;
5848 HOST_WIDE_INT bitsize
;
5849 HOST_WIDE_INT bitpos
= 0;
5851 rtx to_rtx
= target
;
5853 /* Just ignore missing fields. We cleared the whole
5854 structure, above, if any fields are missing. */
5858 if (cleared
&& initializer_zerop (value
))
5861 if (host_integerp (DECL_SIZE (field
), 1))
5862 bitsize
= tree_low_cst (DECL_SIZE (field
), 1);
5866 mode
= DECL_MODE (field
);
5867 if (DECL_BIT_FIELD (field
))
5870 offset
= DECL_FIELD_OFFSET (field
);
5871 if (host_integerp (offset
, 0)
5872 && host_integerp (bit_position (field
), 0))
5874 bitpos
= int_bit_position (field
);
5878 bitpos
= tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 0);
5882 enum machine_mode address_mode
;
5886 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
5887 make_tree (TREE_TYPE (exp
),
5890 offset_rtx
= expand_normal (offset
);
5891 gcc_assert (MEM_P (to_rtx
));
5893 address_mode
= get_address_mode (to_rtx
);
5894 if (GET_MODE (offset_rtx
) != address_mode
)
5895 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
5897 to_rtx
= offset_address (to_rtx
, offset_rtx
,
5898 highest_pow2_factor (offset
));
5901 #ifdef WORD_REGISTER_OPERATIONS
5902 /* If this initializes a field that is smaller than a
5903 word, at the start of a word, try to widen it to a full
5904 word. This special case allows us to output C++ member
5905 function initializations in a form that the optimizers
5908 && bitsize
< BITS_PER_WORD
5909 && bitpos
% BITS_PER_WORD
== 0
5910 && GET_MODE_CLASS (mode
) == MODE_INT
5911 && TREE_CODE (value
) == INTEGER_CST
5913 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
5915 tree type
= TREE_TYPE (value
);
5917 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
5919 type
= lang_hooks
.types
.type_for_mode
5920 (word_mode
, TYPE_UNSIGNED (type
));
5921 value
= fold_convert (type
, value
);
5924 if (BYTES_BIG_ENDIAN
)
5926 = fold_build2 (LSHIFT_EXPR
, type
, value
,
5927 build_int_cst (type
,
5928 BITS_PER_WORD
- bitsize
));
5929 bitsize
= BITS_PER_WORD
;
5934 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
5935 && DECL_NONADDRESSABLE_P (field
))
5937 to_rtx
= copy_rtx (to_rtx
);
5938 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
5941 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
5943 get_alias_set (TREE_TYPE (field
)));
5950 unsigned HOST_WIDE_INT i
;
5953 tree elttype
= TREE_TYPE (type
);
5955 HOST_WIDE_INT minelt
= 0;
5956 HOST_WIDE_INT maxelt
= 0;
5958 domain
= TYPE_DOMAIN (type
);
5959 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
5960 && TYPE_MAX_VALUE (domain
)
5961 && host_integerp (TYPE_MIN_VALUE (domain
), 0)
5962 && host_integerp (TYPE_MAX_VALUE (domain
), 0));
5964 /* If we have constant bounds for the range of the type, get them. */
5967 minelt
= tree_low_cst (TYPE_MIN_VALUE (domain
), 0);
5968 maxelt
= tree_low_cst (TYPE_MAX_VALUE (domain
), 0);
5971 /* If the constructor has fewer elements than the array, clear
5972 the whole array first. Similarly if this is static
5973 constructor of a non-BLKmode object. */
5976 else if (REG_P (target
) && TREE_STATIC (exp
))
5980 unsigned HOST_WIDE_INT idx
;
5982 HOST_WIDE_INT count
= 0, zero_count
= 0;
5983 need_to_clear
= ! const_bounds_p
;
5985 /* This loop is a more accurate version of the loop in
5986 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5987 is also needed to check for missing elements. */
5988 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
5990 HOST_WIDE_INT this_node_count
;
5995 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
5997 tree lo_index
= TREE_OPERAND (index
, 0);
5998 tree hi_index
= TREE_OPERAND (index
, 1);
6000 if (! host_integerp (lo_index
, 1)
6001 || ! host_integerp (hi_index
, 1))
6007 this_node_count
= (tree_low_cst (hi_index
, 1)
6008 - tree_low_cst (lo_index
, 1) + 1);
6011 this_node_count
= 1;
6013 count
+= this_node_count
;
6014 if (mostly_zeros_p (value
))
6015 zero_count
+= this_node_count
;
6018 /* Clear the entire array first if there are any missing
6019 elements, or if the incidence of zero elements is >=
6022 && (count
< maxelt
- minelt
+ 1
6023 || 4 * zero_count
>= 3 * count
))
6027 if (need_to_clear
&& size
> 0)
6030 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6032 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6036 if (!cleared
&& REG_P (target
))
6037 /* Inform later passes that the old value is dead. */
6038 emit_clobber (target
);
6040 /* Store each element of the constructor into the
6041 corresponding element of TARGET, determined by counting the
6043 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6045 enum machine_mode mode
;
6046 HOST_WIDE_INT bitsize
;
6047 HOST_WIDE_INT bitpos
;
6048 rtx xtarget
= target
;
6050 if (cleared
&& initializer_zerop (value
))
6053 mode
= TYPE_MODE (elttype
);
6054 if (mode
== BLKmode
)
6055 bitsize
= (host_integerp (TYPE_SIZE (elttype
), 1)
6056 ? tree_low_cst (TYPE_SIZE (elttype
), 1)
6059 bitsize
= GET_MODE_BITSIZE (mode
);
6061 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6063 tree lo_index
= TREE_OPERAND (index
, 0);
6064 tree hi_index
= TREE_OPERAND (index
, 1);
6065 rtx index_r
, pos_rtx
;
6066 HOST_WIDE_INT lo
, hi
, count
;
6069 /* If the range is constant and "small", unroll the loop. */
6071 && host_integerp (lo_index
, 0)
6072 && host_integerp (hi_index
, 0)
6073 && (lo
= tree_low_cst (lo_index
, 0),
6074 hi
= tree_low_cst (hi_index
, 0),
6075 count
= hi
- lo
+ 1,
6078 || (host_integerp (TYPE_SIZE (elttype
), 1)
6079 && (tree_low_cst (TYPE_SIZE (elttype
), 1) * count
6082 lo
-= minelt
; hi
-= minelt
;
6083 for (; lo
<= hi
; lo
++)
6085 bitpos
= lo
* tree_low_cst (TYPE_SIZE (elttype
), 0);
6088 && !MEM_KEEP_ALIAS_SET_P (target
)
6089 && TREE_CODE (type
) == ARRAY_TYPE
6090 && TYPE_NONALIASED_COMPONENT (type
))
6092 target
= copy_rtx (target
);
6093 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6096 store_constructor_field
6097 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6098 get_alias_set (elttype
));
6103 rtx loop_start
= gen_label_rtx ();
6104 rtx loop_end
= gen_label_rtx ();
6107 expand_normal (hi_index
);
6109 index
= build_decl (EXPR_LOCATION (exp
),
6110 VAR_DECL
, NULL_TREE
, domain
);
6111 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6112 SET_DECL_RTL (index
, index_r
);
6113 store_expr (lo_index
, index_r
, 0, false);
6115 /* Build the head of the loop. */
6116 do_pending_stack_adjust ();
6117 emit_label (loop_start
);
6119 /* Assign value to element index. */
6121 fold_convert (ssizetype
,
6122 fold_build2 (MINUS_EXPR
,
6125 TYPE_MIN_VALUE (domain
)));
6128 size_binop (MULT_EXPR
, position
,
6129 fold_convert (ssizetype
,
6130 TYPE_SIZE_UNIT (elttype
)));
6132 pos_rtx
= expand_normal (position
);
6133 xtarget
= offset_address (target
, pos_rtx
,
6134 highest_pow2_factor (position
));
6135 xtarget
= adjust_address (xtarget
, mode
, 0);
6136 if (TREE_CODE (value
) == CONSTRUCTOR
)
6137 store_constructor (value
, xtarget
, cleared
,
6138 bitsize
/ BITS_PER_UNIT
);
6140 store_expr (value
, xtarget
, 0, false);
6142 /* Generate a conditional jump to exit the loop. */
6143 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6145 jumpif (exit_cond
, loop_end
, -1);
6147 /* Update the loop counter, and jump to the head of
6149 expand_assignment (index
,
6150 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6151 index
, integer_one_node
),
6154 emit_jump (loop_start
);
6156 /* Build the end of the loop. */
6157 emit_label (loop_end
);
6160 else if ((index
!= 0 && ! host_integerp (index
, 0))
6161 || ! host_integerp (TYPE_SIZE (elttype
), 1))
6166 index
= ssize_int (1);
6169 index
= fold_convert (ssizetype
,
6170 fold_build2 (MINUS_EXPR
,
6173 TYPE_MIN_VALUE (domain
)));
6176 size_binop (MULT_EXPR
, index
,
6177 fold_convert (ssizetype
,
6178 TYPE_SIZE_UNIT (elttype
)));
6179 xtarget
= offset_address (target
,
6180 expand_normal (position
),
6181 highest_pow2_factor (position
));
6182 xtarget
= adjust_address (xtarget
, mode
, 0);
6183 store_expr (value
, xtarget
, 0, false);
6188 bitpos
= ((tree_low_cst (index
, 0) - minelt
)
6189 * tree_low_cst (TYPE_SIZE (elttype
), 1));
6191 bitpos
= (i
* tree_low_cst (TYPE_SIZE (elttype
), 1));
6193 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6194 && TREE_CODE (type
) == ARRAY_TYPE
6195 && TYPE_NONALIASED_COMPONENT (type
))
6197 target
= copy_rtx (target
);
6198 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6200 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6201 cleared
, get_alias_set (elttype
));
6209 unsigned HOST_WIDE_INT idx
;
6210 constructor_elt
*ce
;
6213 int icode
= CODE_FOR_nothing
;
6214 tree elttype
= TREE_TYPE (type
);
6215 int elt_size
= tree_low_cst (TYPE_SIZE (elttype
), 1);
6216 enum machine_mode eltmode
= TYPE_MODE (elttype
);
6217 HOST_WIDE_INT bitsize
;
6218 HOST_WIDE_INT bitpos
;
6219 rtvec vector
= NULL
;
6221 alias_set_type alias
;
6223 gcc_assert (eltmode
!= BLKmode
);
6225 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6226 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6228 enum machine_mode mode
= GET_MODE (target
);
6230 icode
= (int) optab_handler (vec_init_optab
, mode
);
6231 if (icode
!= CODE_FOR_nothing
)
6235 vector
= rtvec_alloc (n_elts
);
6236 for (i
= 0; i
< n_elts
; i
++)
6237 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6241 /* If the constructor has fewer elements than the vector,
6242 clear the whole array first. Similarly if this is static
6243 constructor of a non-BLKmode object. */
6246 else if (REG_P (target
) && TREE_STATIC (exp
))
6250 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6253 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6255 int n_elts_here
= tree_low_cst
6256 (int_const_binop (TRUNC_DIV_EXPR
,
6257 TYPE_SIZE (TREE_TYPE (value
)),
6258 TYPE_SIZE (elttype
)), 1);
6260 count
+= n_elts_here
;
6261 if (mostly_zeros_p (value
))
6262 zero_count
+= n_elts_here
;
6265 /* Clear the entire vector first if there are any missing elements,
6266 or if the incidence of zero elements is >= 75%. */
6267 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6270 if (need_to_clear
&& size
> 0 && !vector
)
6273 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6275 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6279 /* Inform later passes that the old value is dead. */
6280 if (!cleared
&& !vector
&& REG_P (target
))
6281 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6284 alias
= MEM_ALIAS_SET (target
);
6286 alias
= get_alias_set (elttype
);
6288 /* Store each element of the constructor into the corresponding
6289 element of TARGET, determined by counting the elements. */
6290 for (idx
= 0, i
= 0;
6291 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6292 idx
++, i
+= bitsize
/ elt_size
)
6294 HOST_WIDE_INT eltpos
;
6295 tree value
= ce
->value
;
6297 bitsize
= tree_low_cst (TYPE_SIZE (TREE_TYPE (value
)), 1);
6298 if (cleared
&& initializer_zerop (value
))
6302 eltpos
= tree_low_cst (ce
->index
, 1);
6308 /* Vector CONSTRUCTORs should only be built from smaller
6309 vectors in the case of BLKmode vectors. */
6310 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6311 RTVEC_ELT (vector
, eltpos
)
6312 = expand_normal (value
);
6316 enum machine_mode value_mode
=
6317 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6318 ? TYPE_MODE (TREE_TYPE (value
))
6320 bitpos
= eltpos
* elt_size
;
6321 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6322 value
, cleared
, alias
);
6327 emit_insn (GEN_FCN (icode
)
6329 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6338 /* Store the value of EXP (an expression tree)
6339 into a subfield of TARGET which has mode MODE and occupies
6340 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6341 If MODE is VOIDmode, it means that we are storing into a bit-field.
6343 BITREGION_START is bitpos of the first bitfield in this region.
6344 BITREGION_END is the bitpos of the ending bitfield in this region.
6345 These two fields are 0, if the C++ memory model does not apply,
6346 or we are not interested in keeping track of bitfield regions.
6348 Always return const0_rtx unless we have something particular to
6351 ALIAS_SET is the alias set for the destination. This value will
6352 (in general) be different from that for TARGET, since TARGET is a
6353 reference to the containing structure.
6355 If NONTEMPORAL is true, try generating a nontemporal store. */
6358 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6359 unsigned HOST_WIDE_INT bitregion_start
,
6360 unsigned HOST_WIDE_INT bitregion_end
,
6361 enum machine_mode mode
, tree exp
,
6362 alias_set_type alias_set
, bool nontemporal
)
6364 if (TREE_CODE (exp
) == ERROR_MARK
)
6367 /* If we have nothing to store, do nothing unless the expression has
6370 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6372 if (GET_CODE (target
) == CONCAT
)
6374 /* We're storing into a struct containing a single __complex. */
6376 gcc_assert (!bitpos
);
6377 return store_expr (exp
, target
, 0, nontemporal
);
6380 /* If the structure is in a register or if the component
6381 is a bit field, we cannot use addressing to access it.
6382 Use bit-field techniques or SUBREG to store in it. */
6384 if (mode
== VOIDmode
6385 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6386 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6387 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6389 || GET_CODE (target
) == SUBREG
6390 /* If the field isn't aligned enough to store as an ordinary memref,
6391 store it as a bit field. */
6393 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6394 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6395 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6396 || (bitpos
% BITS_PER_UNIT
!= 0)))
6397 || (bitsize
>= 0 && mode
!= BLKmode
6398 && GET_MODE_BITSIZE (mode
) > bitsize
)
6399 /* If the RHS and field are a constant size and the size of the
6400 RHS isn't the same size as the bitfield, we must use bitfield
6403 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6404 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0)
6405 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6406 decl we must use bitfield operations. */
6408 && TREE_CODE (exp
) == MEM_REF
6409 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6410 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6411 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6412 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6417 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6418 implies a mask operation. If the precision is the same size as
6419 the field we're storing into, that mask is redundant. This is
6420 particularly common with bit field assignments generated by the
6422 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6425 tree type
= TREE_TYPE (exp
);
6426 if (INTEGRAL_TYPE_P (type
)
6427 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6428 && bitsize
== TYPE_PRECISION (type
))
6430 tree op
= gimple_assign_rhs1 (nop_def
);
6431 type
= TREE_TYPE (op
);
6432 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6437 temp
= expand_normal (exp
);
6439 /* If BITSIZE is narrower than the size of the type of EXP
6440 we will be narrowing TEMP. Normally, what's wanted are the
6441 low-order bits. However, if EXP's type is a record and this is
6442 big-endian machine, we want the upper BITSIZE bits. */
6443 if (BYTES_BIG_ENDIAN
&& GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
6444 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (temp
))
6445 && TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
6446 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6447 GET_MODE_BITSIZE (GET_MODE (temp
)) - bitsize
,
6450 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6451 if (mode
!= VOIDmode
&& mode
!= BLKmode
6452 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6453 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6455 /* If the modes of TEMP and TARGET are both BLKmode, both
6456 must be in memory and BITPOS must be aligned on a byte
6457 boundary. If so, we simply do a block copy. Likewise
6458 for a BLKmode-like TARGET. */
6459 if (GET_MODE (temp
) == BLKmode
6460 && (GET_MODE (target
) == BLKmode
6462 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6463 && (bitpos
% BITS_PER_UNIT
) == 0
6464 && (bitsize
% BITS_PER_UNIT
) == 0)))
6466 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6467 && (bitpos
% BITS_PER_UNIT
) == 0);
6469 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6470 emit_block_move (target
, temp
,
6471 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6478 /* Handle calls that return values in multiple non-contiguous locations.
6479 The Irix 6 ABI has examples of this. */
6480 if (GET_CODE (temp
) == PARALLEL
)
6482 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6484 if (mode
== BLKmode
)
6485 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6486 temp_target
= gen_reg_rtx (mode
);
6487 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6490 else if (mode
== BLKmode
)
6492 /* Handle calls that return BLKmode values in registers. */
6493 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6495 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6496 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6501 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6503 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6504 temp_target
= gen_reg_rtx (mode
);
6506 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6507 false, temp_target
, mode
, mode
);
6512 /* Store the value in the bitfield. */
6513 store_bit_field (target
, bitsize
, bitpos
,
6514 bitregion_start
, bitregion_end
,
6521 /* Now build a reference to just the desired component. */
6522 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6524 if (to_rtx
== target
)
6525 to_rtx
= copy_rtx (to_rtx
);
6527 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6528 set_mem_alias_set (to_rtx
, alias_set
);
6530 return store_expr (exp
, to_rtx
, 0, nontemporal
);
6534 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6535 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6536 codes and find the ultimate containing object, which we return.
6538 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6539 bit position, and *PUNSIGNEDP to the signedness of the field.
6540 If the position of the field is variable, we store a tree
6541 giving the variable offset (in units) in *POFFSET.
6542 This offset is in addition to the bit position.
6543 If the position is not variable, we store 0 in *POFFSET.
6545 If any of the extraction expressions is volatile,
6546 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6548 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6549 Otherwise, it is a mode that can be used to access the field.
6551 If the field describes a variable-sized object, *PMODE is set to
6552 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6553 this case, but the address of the object can be found.
6555 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6556 look through nodes that serve as markers of a greater alignment than
6557 the one that can be deduced from the expression. These nodes make it
6558 possible for front-ends to prevent temporaries from being created by
6559 the middle-end on alignment considerations. For that purpose, the
6560 normal operating mode at high-level is to always pass FALSE so that
6561 the ultimate containing object is really returned; moreover, the
6562 associated predicate handled_component_p will always return TRUE
6563 on these nodes, thus indicating that they are essentially handled
6564 by get_inner_reference. TRUE should only be passed when the caller
6565 is scanning the expression in order to build another representation
6566 and specifically knows how to handle these nodes; as such, this is
6567 the normal operating mode in the RTL expanders. */
6570 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6571 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6572 enum machine_mode
*pmode
, int *punsignedp
,
6573 int *pvolatilep
, bool keep_aligning
)
6576 enum machine_mode mode
= VOIDmode
;
6577 bool blkmode_bitfield
= false;
6578 tree offset
= size_zero_node
;
6579 double_int bit_offset
= double_int_zero
;
6581 /* First get the mode, signedness, and size. We do this from just the
6582 outermost expression. */
6584 if (TREE_CODE (exp
) == COMPONENT_REF
)
6586 tree field
= TREE_OPERAND (exp
, 1);
6587 size_tree
= DECL_SIZE (field
);
6588 if (!DECL_BIT_FIELD (field
))
6589 mode
= DECL_MODE (field
);
6590 else if (DECL_MODE (field
) == BLKmode
)
6591 blkmode_bitfield
= true;
6592 else if (TREE_THIS_VOLATILE (exp
)
6593 && flag_strict_volatile_bitfields
> 0)
6594 /* Volatile bitfields should be accessed in the mode of the
6595 field's type, not the mode computed based on the bit
6597 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6599 *punsignedp
= DECL_UNSIGNED (field
);
6601 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6603 size_tree
= TREE_OPERAND (exp
, 1);
6604 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6605 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6607 /* For vector types, with the correct size of access, use the mode of
6609 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6610 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6611 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6612 mode
= TYPE_MODE (TREE_TYPE (exp
));
6616 mode
= TYPE_MODE (TREE_TYPE (exp
));
6617 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6619 if (mode
== BLKmode
)
6620 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6622 *pbitsize
= GET_MODE_BITSIZE (mode
);
6627 if (! host_integerp (size_tree
, 1))
6628 mode
= BLKmode
, *pbitsize
= -1;
6630 *pbitsize
= tree_low_cst (size_tree
, 1);
6633 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6634 and find the ultimate containing object. */
6637 switch (TREE_CODE (exp
))
6640 bit_offset
+= tree_to_double_int (TREE_OPERAND (exp
, 2));
6645 tree field
= TREE_OPERAND (exp
, 1);
6646 tree this_offset
= component_ref_field_offset (exp
);
6648 /* If this field hasn't been filled in yet, don't go past it.
6649 This should only happen when folding expressions made during
6650 type construction. */
6651 if (this_offset
== 0)
6654 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6655 bit_offset
+= tree_to_double_int (DECL_FIELD_BIT_OFFSET (field
));
6657 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6662 case ARRAY_RANGE_REF
:
6664 tree index
= TREE_OPERAND (exp
, 1);
6665 tree low_bound
= array_ref_low_bound (exp
);
6666 tree unit_size
= array_ref_element_size (exp
);
6668 /* We assume all arrays have sizes that are a multiple of a byte.
6669 First subtract the lower bound, if any, in the type of the
6670 index, then convert to sizetype and multiply by the size of
6671 the array element. */
6672 if (! integer_zerop (low_bound
))
6673 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6676 offset
= size_binop (PLUS_EXPR
, offset
,
6677 size_binop (MULT_EXPR
,
6678 fold_convert (sizetype
, index
),
6687 bit_offset
+= double_int::from_uhwi (*pbitsize
);
6690 case VIEW_CONVERT_EXPR
:
6691 if (keep_aligning
&& STRICT_ALIGNMENT
6692 && (TYPE_ALIGN (TREE_TYPE (exp
))
6693 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6694 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6695 < BIGGEST_ALIGNMENT
)
6696 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6697 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6702 /* Hand back the decl for MEM[&decl, off]. */
6703 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6705 tree off
= TREE_OPERAND (exp
, 1);
6706 if (!integer_zerop (off
))
6708 double_int boff
, coff
= mem_ref_offset (exp
);
6709 boff
= coff
.alshift (BITS_PER_UNIT
== 8
6710 ? 3 : exact_log2 (BITS_PER_UNIT
),
6711 HOST_BITS_PER_DOUBLE_INT
);
6714 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6722 /* If any reference in the chain is volatile, the effect is volatile. */
6723 if (TREE_THIS_VOLATILE (exp
))
6726 exp
= TREE_OPERAND (exp
, 0);
6730 /* If OFFSET is constant, see if we can return the whole thing as a
6731 constant bit position. Make sure to handle overflow during
6733 if (TREE_CODE (offset
) == INTEGER_CST
)
6735 double_int tem
= tree_to_double_int (offset
);
6736 tem
= tem
.sext (TYPE_PRECISION (sizetype
));
6737 tem
= tem
.alshift (BITS_PER_UNIT
== 8 ? 3 : exact_log2 (BITS_PER_UNIT
),
6738 HOST_BITS_PER_DOUBLE_INT
);
6740 if (tem
.fits_shwi ())
6742 *pbitpos
= tem
.to_shwi ();
6743 *poffset
= offset
= NULL_TREE
;
6747 /* Otherwise, split it up. */
6750 /* Avoid returning a negative bitpos as this may wreak havoc later. */
6751 if (bit_offset
.is_negative ())
6754 = double_int::mask (BITS_PER_UNIT
== 8
6755 ? 3 : exact_log2 (BITS_PER_UNIT
));
6756 double_int tem
= bit_offset
.and_not (mask
);
6757 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
6758 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
6760 tem
= tem
.arshift (BITS_PER_UNIT
== 8
6761 ? 3 : exact_log2 (BITS_PER_UNIT
),
6762 HOST_BITS_PER_DOUBLE_INT
);
6763 offset
= size_binop (PLUS_EXPR
, offset
,
6764 double_int_to_tree (sizetype
, tem
));
6767 *pbitpos
= bit_offset
.to_shwi ();
6771 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
6772 if (mode
== VOIDmode
6774 && (*pbitpos
% BITS_PER_UNIT
) == 0
6775 && (*pbitsize
% BITS_PER_UNIT
) == 0)
6783 /* Return a tree of sizetype representing the size, in bytes, of the element
6784 of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6787 array_ref_element_size (tree exp
)
6789 tree aligned_size
= TREE_OPERAND (exp
, 3);
6790 tree elmt_type
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6791 location_t loc
= EXPR_LOCATION (exp
);
6793 /* If a size was specified in the ARRAY_REF, it's the size measured
6794 in alignment units of the element type. So multiply by that value. */
6797 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6798 sizetype from another type of the same width and signedness. */
6799 if (TREE_TYPE (aligned_size
) != sizetype
)
6800 aligned_size
= fold_convert_loc (loc
, sizetype
, aligned_size
);
6801 return size_binop_loc (loc
, MULT_EXPR
, aligned_size
,
6802 size_int (TYPE_ALIGN_UNIT (elmt_type
)));
6805 /* Otherwise, take the size from that of the element type. Substitute
6806 any PLACEHOLDER_EXPR that we have. */
6808 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type
), exp
);
6811 /* Return a tree representing the lower bound of the array mentioned in
6812 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6815 array_ref_low_bound (tree exp
)
6817 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6819 /* If a lower bound is specified in EXP, use it. */
6820 if (TREE_OPERAND (exp
, 2))
6821 return TREE_OPERAND (exp
, 2);
6823 /* Otherwise, if there is a domain type and it has a lower bound, use it,
6824 substituting for a PLACEHOLDER_EXPR as needed. */
6825 if (domain_type
&& TYPE_MIN_VALUE (domain_type
))
6826 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type
), exp
);
6828 /* Otherwise, return a zero of the appropriate type. */
6829 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp
, 1)), 0);
6832 /* Returns true if REF is an array reference to an array at the end of
6833 a structure. If this is the case, the array may be allocated larger
6834 than its upper bound implies. */
6837 array_at_struct_end_p (tree ref
)
6839 if (TREE_CODE (ref
) != ARRAY_REF
6840 && TREE_CODE (ref
) != ARRAY_RANGE_REF
)
6843 while (handled_component_p (ref
))
6845 /* If the reference chain contains a component reference to a
6846 non-union type and there follows another field the reference
6847 is not at the end of a structure. */
6848 if (TREE_CODE (ref
) == COMPONENT_REF
6849 && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref
, 0))) == RECORD_TYPE
)
6851 tree nextf
= DECL_CHAIN (TREE_OPERAND (ref
, 1));
6852 while (nextf
&& TREE_CODE (nextf
) != FIELD_DECL
)
6853 nextf
= DECL_CHAIN (nextf
);
6858 ref
= TREE_OPERAND (ref
, 0);
6861 /* If the reference is based on a declared entity, the size of the array
6862 is constrained by its given domain. */
6869 /* Return a tree representing the upper bound of the array mentioned in
6870 EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
6873 array_ref_up_bound (tree exp
)
6875 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp
, 0)));
6877 /* If there is a domain type and it has an upper bound, use it, substituting
6878 for a PLACEHOLDER_EXPR as needed. */
6879 if (domain_type
&& TYPE_MAX_VALUE (domain_type
))
6880 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type
), exp
);
6882 /* Otherwise fail. */
6886 /* Return a tree representing the offset, in bytes, of the field referenced
6887 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
6890 component_ref_field_offset (tree exp
)
6892 tree aligned_offset
= TREE_OPERAND (exp
, 2);
6893 tree field
= TREE_OPERAND (exp
, 1);
6894 location_t loc
= EXPR_LOCATION (exp
);
6896 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
6897 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
6901 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
6902 sizetype from another type of the same width and signedness. */
6903 if (TREE_TYPE (aligned_offset
) != sizetype
)
6904 aligned_offset
= fold_convert_loc (loc
, sizetype
, aligned_offset
);
6905 return size_binop_loc (loc
, MULT_EXPR
, aligned_offset
,
6906 size_int (DECL_OFFSET_ALIGN (field
)
6910 /* Otherwise, take the offset from that of the field. Substitute
6911 any PLACEHOLDER_EXPR that we have. */
6913 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field
), exp
);
6916 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
6918 static unsigned HOST_WIDE_INT
6919 target_align (const_tree target
)
6921 /* We might have a chain of nested references with intermediate misaligning
6922 bitfields components, so need to recurse to find out. */
6924 unsigned HOST_WIDE_INT this_align
, outer_align
;
6926 switch (TREE_CODE (target
))
6932 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
6933 outer_align
= target_align (TREE_OPERAND (target
, 0));
6934 return MIN (this_align
, outer_align
);
6937 case ARRAY_RANGE_REF
:
6938 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6939 outer_align
= target_align (TREE_OPERAND (target
, 0));
6940 return MIN (this_align
, outer_align
);
6943 case NON_LVALUE_EXPR
:
6944 case VIEW_CONVERT_EXPR
:
6945 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
6946 outer_align
= target_align (TREE_OPERAND (target
, 0));
6947 return MAX (this_align
, outer_align
);
6950 return TYPE_ALIGN (TREE_TYPE (target
));
6955 /* Given an rtx VALUE that may contain additions and multiplications, return
6956 an equivalent value that just refers to a register, memory, or constant.
6957 This is done by generating instructions to perform the arithmetic and
6958 returning a pseudo-register containing the value.
6960 The returned value may be a REG, SUBREG, MEM or constant. */
6963 force_operand (rtx value
, rtx target
)
6966 /* Use subtarget as the target for operand 0 of a binary operation. */
6967 rtx subtarget
= get_subtarget (target
);
6968 enum rtx_code code
= GET_CODE (value
);
6970 /* Check for subreg applied to an expression produced by loop optimizer. */
6972 && !REG_P (SUBREG_REG (value
))
6973 && !MEM_P (SUBREG_REG (value
)))
6976 = simplify_gen_subreg (GET_MODE (value
),
6977 force_reg (GET_MODE (SUBREG_REG (value
)),
6978 force_operand (SUBREG_REG (value
),
6980 GET_MODE (SUBREG_REG (value
)),
6981 SUBREG_BYTE (value
));
6982 code
= GET_CODE (value
);
6985 /* Check for a PIC address load. */
6986 if ((code
== PLUS
|| code
== MINUS
)
6987 && XEXP (value
, 0) == pic_offset_table_rtx
6988 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
6989 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
6990 || GET_CODE (XEXP (value
, 1)) == CONST
))
6993 subtarget
= gen_reg_rtx (GET_MODE (value
));
6994 emit_move_insn (subtarget
, value
);
6998 if (ARITHMETIC_P (value
))
7000 op2
= XEXP (value
, 1);
7001 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7003 if (code
== MINUS
&& CONST_INT_P (op2
))
7006 op2
= negate_rtx (GET_MODE (value
), op2
);
7009 /* Check for an addition with OP2 a constant integer and our first
7010 operand a PLUS of a virtual register and something else. In that
7011 case, we want to emit the sum of the virtual register and the
7012 constant first and then add the other value. This allows virtual
7013 register instantiation to simply modify the constant rather than
7014 creating another one around this addition. */
7015 if (code
== PLUS
&& CONST_INT_P (op2
)
7016 && GET_CODE (XEXP (value
, 0)) == PLUS
7017 && REG_P (XEXP (XEXP (value
, 0), 0))
7018 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7019 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7021 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7022 XEXP (XEXP (value
, 0), 0), op2
,
7023 subtarget
, 0, OPTAB_LIB_WIDEN
);
7024 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7025 force_operand (XEXP (XEXP (value
,
7027 target
, 0, OPTAB_LIB_WIDEN
);
7030 op1
= force_operand (XEXP (value
, 0), subtarget
);
7031 op2
= force_operand (op2
, NULL_RTX
);
7035 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7037 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7038 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7039 target
, 1, OPTAB_LIB_WIDEN
);
7041 return expand_divmod (0,
7042 FLOAT_MODE_P (GET_MODE (value
))
7043 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7044 GET_MODE (value
), op1
, op2
, target
, 0);
7046 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7049 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7052 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7055 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7056 target
, 0, OPTAB_LIB_WIDEN
);
7058 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7059 target
, 1, OPTAB_LIB_WIDEN
);
7062 if (UNARY_P (value
))
7065 target
= gen_reg_rtx (GET_MODE (value
));
7066 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7073 case FLOAT_TRUNCATE
:
7074 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7079 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7083 case UNSIGNED_FLOAT
:
7084 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7088 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7092 #ifdef INSN_SCHEDULING
7093 /* On machines that have insn scheduling, we want all memory reference to be
7094 explicit, so we need to deal with such paradoxical SUBREGs. */
7095 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7097 = simplify_gen_subreg (GET_MODE (value
),
7098 force_reg (GET_MODE (SUBREG_REG (value
)),
7099 force_operand (SUBREG_REG (value
),
7101 GET_MODE (SUBREG_REG (value
)),
7102 SUBREG_BYTE (value
));
7108 /* Subroutine of expand_expr: return nonzero iff there is no way that
7109 EXP can reference X, which is being modified. TOP_P is nonzero if this
7110 call is going to be used to determine whether we need a temporary
7111 for EXP, as opposed to a recursive call to this function.
7113 It is always safe for this routine to return zero since it merely
7114 searches for optimization opportunities. */
7117 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7123 /* If EXP has varying size, we MUST use a target since we currently
7124 have no way of allocating temporaries of variable size
7125 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7126 So we assume here that something at a higher level has prevented a
7127 clash. This is somewhat bogus, but the best we can do. Only
7128 do this when X is BLKmode and when we are at the top level. */
7129 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7130 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7131 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7132 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7133 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7135 && GET_MODE (x
) == BLKmode
)
7136 /* If X is in the outgoing argument area, it is always safe. */
7138 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7139 || (GET_CODE (XEXP (x
, 0)) == PLUS
7140 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7143 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7144 find the underlying pseudo. */
7145 if (GET_CODE (x
) == SUBREG
)
7148 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7152 /* Now look at our tree code and possibly recurse. */
7153 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7155 case tcc_declaration
:
7156 exp_rtl
= DECL_RTL_IF_SET (exp
);
7162 case tcc_exceptional
:
7163 if (TREE_CODE (exp
) == TREE_LIST
)
7167 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7169 exp
= TREE_CHAIN (exp
);
7172 if (TREE_CODE (exp
) != TREE_LIST
)
7173 return safe_from_p (x
, exp
, 0);
7176 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7178 constructor_elt
*ce
;
7179 unsigned HOST_WIDE_INT idx
;
7181 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7182 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7183 || !safe_from_p (x
, ce
->value
, 0))
7187 else if (TREE_CODE (exp
) == ERROR_MARK
)
7188 return 1; /* An already-visited SAVE_EXPR? */
7193 /* The only case we look at here is the DECL_INITIAL inside a
7195 return (TREE_CODE (exp
) != DECL_EXPR
7196 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7197 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7198 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7201 case tcc_comparison
:
7202 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7207 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7209 case tcc_expression
:
7212 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7213 the expression. If it is set, we conflict iff we are that rtx or
7214 both are in memory. Otherwise, we check all operands of the
7215 expression recursively. */
7217 switch (TREE_CODE (exp
))
7220 /* If the operand is static or we are static, we can't conflict.
7221 Likewise if we don't conflict with the operand at all. */
7222 if (staticp (TREE_OPERAND (exp
, 0))
7223 || TREE_STATIC (exp
)
7224 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7227 /* Otherwise, the only way this can conflict is if we are taking
7228 the address of a DECL a that address if part of X, which is
7230 exp
= TREE_OPERAND (exp
, 0);
7233 if (!DECL_RTL_SET_P (exp
)
7234 || !MEM_P (DECL_RTL (exp
)))
7237 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7243 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7244 get_alias_set (exp
)))
7249 /* Assume that the call will clobber all hard registers and
7251 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7256 case WITH_CLEANUP_EXPR
:
7257 case CLEANUP_POINT_EXPR
:
7258 /* Lowered by gimplify.c. */
7262 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7268 /* If we have an rtx, we do not need to scan our operands. */
7272 nops
= TREE_OPERAND_LENGTH (exp
);
7273 for (i
= 0; i
< nops
; i
++)
7274 if (TREE_OPERAND (exp
, i
) != 0
7275 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7281 /* Should never get a type here. */
7285 /* If we have an rtl, find any enclosed object. Then see if we conflict
7289 if (GET_CODE (exp_rtl
) == SUBREG
)
7291 exp_rtl
= SUBREG_REG (exp_rtl
);
7293 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7297 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7298 are memory and they conflict. */
7299 return ! (rtx_equal_p (x
, exp_rtl
)
7300 || (MEM_P (x
) && MEM_P (exp_rtl
)
7301 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7304 /* If we reach here, it is safe. */
7309 /* Return the highest power of two that EXP is known to be a multiple of.
7310 This is used in updating alignment of MEMs in array references. */
7312 unsigned HOST_WIDE_INT
7313 highest_pow2_factor (const_tree exp
)
7315 unsigned HOST_WIDE_INT c0
, c1
;
7317 switch (TREE_CODE (exp
))
7320 /* We can find the lowest bit that's a one. If the low
7321 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
7322 We need to handle this case since we can find it in a COND_EXPR,
7323 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
7324 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
7326 if (TREE_OVERFLOW (exp
))
7327 return BIGGEST_ALIGNMENT
;
7330 /* Note: tree_low_cst is intentionally not used here,
7331 we don't care about the upper bits. */
7332 c0
= TREE_INT_CST_LOW (exp
);
7334 return c0
? c0
: BIGGEST_ALIGNMENT
;
7338 case PLUS_EXPR
: case MINUS_EXPR
: case MIN_EXPR
: case MAX_EXPR
:
7339 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7340 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7341 return MIN (c0
, c1
);
7344 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7345 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7348 case ROUND_DIV_EXPR
: case TRUNC_DIV_EXPR
: case FLOOR_DIV_EXPR
:
7350 if (integer_pow2p (TREE_OPERAND (exp
, 1))
7351 && host_integerp (TREE_OPERAND (exp
, 1), 1))
7353 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 0));
7354 c1
= tree_low_cst (TREE_OPERAND (exp
, 1), 1);
7355 return MAX (1, c0
/ c1
);
7360 /* The highest power of two of a bit-and expression is the maximum of
7361 that of its operands. We typically get here for a complex LHS and
7362 a constant negative power of two on the RHS to force an explicit
7363 alignment, so don't bother looking at the LHS. */
7364 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7368 return highest_pow2_factor (TREE_OPERAND (exp
, 0));
7371 return highest_pow2_factor (TREE_OPERAND (exp
, 1));
7374 c0
= highest_pow2_factor (TREE_OPERAND (exp
, 1));
7375 c1
= highest_pow2_factor (TREE_OPERAND (exp
, 2));
7376 return MIN (c0
, c1
);
7385 /* Similar, except that the alignment requirements of TARGET are
7386 taken into account. Assume it is at least as aligned as its
7387 type, unless it is a COMPONENT_REF in which case the layout of
7388 the structure gives the alignment. */
7390 static unsigned HOST_WIDE_INT
7391 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7393 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7394 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7396 return MAX (factor
, talign
);
7399 #ifdef HAVE_conditional_move
7400 /* Convert the tree comparison code TCODE to the rtl one where the
7401 signedness is UNSIGNEDP. */
7403 static enum rtx_code
7404 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7416 code
= unsignedp
? LTU
: LT
;
7419 code
= unsignedp
? LEU
: LE
;
7422 code
= unsignedp
? GTU
: GT
;
7425 code
= unsignedp
? GEU
: GE
;
7427 case UNORDERED_EXPR
:
7459 /* Subroutine of expand_expr. Expand the two operands of a binary
7460 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7461 The value may be stored in TARGET if TARGET is nonzero. The
7462 MODIFIER argument is as documented by expand_expr. */
7465 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7466 enum expand_modifier modifier
)
7468 if (! safe_from_p (target
, exp1
, 1))
7470 if (operand_equal_p (exp0
, exp1
, 0))
7472 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7473 *op1
= copy_rtx (*op0
);
7477 /* If we need to preserve evaluation order, copy exp0 into its own
7478 temporary variable so that it can't be clobbered by exp1. */
7479 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7480 exp0
= save_expr (exp0
);
7481 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7482 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7487 /* Return a MEM that contains constant EXP. DEFER is as for
7488 output_constant_def and MODIFIER is as for expand_expr. */
7491 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7495 mem
= output_constant_def (exp
, defer
);
7496 if (modifier
!= EXPAND_INITIALIZER
)
7497 mem
= use_anchored_address (mem
);
7501 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7502 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7505 expand_expr_addr_expr_1 (tree exp
, rtx target
, enum machine_mode tmode
,
7506 enum expand_modifier modifier
, addr_space_t as
)
7508 rtx result
, subtarget
;
7510 HOST_WIDE_INT bitsize
, bitpos
;
7511 int volatilep
, unsignedp
;
7512 enum machine_mode mode1
;
7514 /* If we are taking the address of a constant and are at the top level,
7515 we have to use output_constant_def since we can't call force_const_mem
7517 /* ??? This should be considered a front-end bug. We should not be
7518 generating ADDR_EXPR of something that isn't an LVALUE. The only
7519 exception here is STRING_CST. */
7520 if (CONSTANT_CLASS_P (exp
))
7522 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7523 if (modifier
< EXPAND_SUM
)
7524 result
= force_operand (result
, target
);
7528 /* Everything must be something allowed by is_gimple_addressable. */
7529 switch (TREE_CODE (exp
))
7532 /* This case will happen via recursion for &a->b. */
7533 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7537 tree tem
= TREE_OPERAND (exp
, 0);
7538 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7539 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7540 return expand_expr (tem
, target
, tmode
, modifier
);
7544 /* Expand the initializer like constants above. */
7545 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7547 if (modifier
< EXPAND_SUM
)
7548 result
= force_operand (result
, target
);
7552 /* The real part of the complex number is always first, therefore
7553 the address is the same as the address of the parent object. */
7556 inner
= TREE_OPERAND (exp
, 0);
7560 /* The imaginary part of the complex number is always second.
7561 The expression is therefore always offset by the size of the
7564 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7565 inner
= TREE_OPERAND (exp
, 0);
7569 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7570 expand_expr, as that can have various side effects; LABEL_DECLs for
7571 example, may not have their DECL_RTL set yet. Expand the rtl of
7572 CONSTRUCTORs too, which should yield a memory reference for the
7573 constructor's contents. Assume language specific tree nodes can
7574 be expanded in some interesting way. */
7575 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7577 || TREE_CODE (exp
) == CONSTRUCTOR
7578 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7580 result
= expand_expr (exp
, target
, tmode
,
7581 modifier
== EXPAND_INITIALIZER
7582 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7584 /* If the DECL isn't in memory, then the DECL wasn't properly
7585 marked TREE_ADDRESSABLE, which will be either a front-end
7586 or a tree optimizer bug. */
7588 if (TREE_ADDRESSABLE (exp
)
7590 && ! targetm
.calls
.allocate_stack_slots_for_args())
7592 error ("local frame unavailable (naked function?)");
7596 gcc_assert (MEM_P (result
));
7597 result
= XEXP (result
, 0);
7599 /* ??? Is this needed anymore? */
7601 TREE_USED (exp
) = 1;
7603 if (modifier
!= EXPAND_INITIALIZER
7604 && modifier
!= EXPAND_CONST_ADDRESS
7605 && modifier
!= EXPAND_SUM
)
7606 result
= force_operand (result
, target
);
7610 /* Pass FALSE as the last argument to get_inner_reference although
7611 we are expanding to RTL. The rationale is that we know how to
7612 handle "aligning nodes" here: we can just bypass them because
7613 they won't change the final object whose address will be returned
7614 (they actually exist only for that purpose). */
7615 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
7616 &mode1
, &unsignedp
, &volatilep
, false);
7620 /* We must have made progress. */
7621 gcc_assert (inner
!= exp
);
7623 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7624 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7625 inner alignment, force the inner to be sufficiently aligned. */
7626 if (CONSTANT_CLASS_P (inner
)
7627 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7629 inner
= copy_node (inner
);
7630 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7631 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7632 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7634 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7640 if (modifier
!= EXPAND_NORMAL
)
7641 result
= force_operand (result
, NULL
);
7642 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7643 modifier
== EXPAND_INITIALIZER
7644 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7646 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7647 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7649 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7650 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7653 subtarget
= bitpos
? NULL_RTX
: target
;
7654 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7655 1, OPTAB_LIB_WIDEN
);
7661 /* Someone beforehand should have rejected taking the address
7662 of such an object. */
7663 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7665 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7666 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7667 if (modifier
< EXPAND_SUM
)
7668 result
= force_operand (result
, target
);
7674 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7675 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7678 expand_expr_addr_expr (tree exp
, rtx target
, enum machine_mode tmode
,
7679 enum expand_modifier modifier
)
7681 addr_space_t as
= ADDR_SPACE_GENERIC
;
7682 enum machine_mode address_mode
= Pmode
;
7683 enum machine_mode pointer_mode
= ptr_mode
;
7684 enum machine_mode rmode
;
7687 /* Target mode of VOIDmode says "whatever's natural". */
7688 if (tmode
== VOIDmode
)
7689 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7691 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7693 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7694 address_mode
= targetm
.addr_space
.address_mode (as
);
7695 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7698 /* We can get called with some Weird Things if the user does silliness
7699 like "(short) &a". In that case, convert_memory_address won't do
7700 the right thing, so ignore the given target mode. */
7701 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7702 tmode
= address_mode
;
7704 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7705 tmode
, modifier
, as
);
7707 /* Despite expand_expr claims concerning ignoring TMODE when not
7708 strictly convenient, stuff breaks if we don't honor it. Note
7709 that combined with the above, we only do this for pointer modes. */
7710 rmode
= GET_MODE (result
);
7711 if (rmode
== VOIDmode
)
7714 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7719 /* Generate code for computing CONSTRUCTOR EXP.
7720 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7721 is TRUE, instead of creating a temporary variable in memory
7722 NULL is returned and the caller needs to handle it differently. */
7725 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7726 bool avoid_temp_mem
)
7728 tree type
= TREE_TYPE (exp
);
7729 enum machine_mode mode
= TYPE_MODE (type
);
7731 /* Try to avoid creating a temporary at all. This is possible
7732 if all of the initializer is zero.
7733 FIXME: try to handle all [0..255] initializers we can handle
7735 if (TREE_STATIC (exp
)
7736 && !TREE_ADDRESSABLE (exp
)
7737 && target
!= 0 && mode
== BLKmode
7738 && all_zeros_p (exp
))
7740 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7744 /* All elts simple constants => refer to a constant in memory. But
7745 if this is a non-BLKmode mode, let it store a field at a time
7746 since that should make a CONST_INT or CONST_DOUBLE when we
7747 fold. Likewise, if we have a target we can use, it is best to
7748 store directly into the target unless the type is large enough
7749 that memcpy will be used. If we are making an initializer and
7750 all operands are constant, put it in memory as well.
7752 FIXME: Avoid trying to fill vector constructors piece-meal.
7753 Output them with output_constant_def below unless we're sure
7754 they're zeros. This should go away when vector initializers
7755 are treated like VECTOR_CST instead of arrays. */
7756 if ((TREE_STATIC (exp
)
7757 && ((mode
== BLKmode
7758 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7759 || TREE_ADDRESSABLE (exp
)
7760 || (host_integerp (TYPE_SIZE_UNIT (type
), 1)
7761 && (! MOVE_BY_PIECES_P
7762 (tree_low_cst (TYPE_SIZE_UNIT (type
), 1),
7764 && ! mostly_zeros_p (exp
))))
7765 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7766 && TREE_CONSTANT (exp
)))
7773 constructor
= expand_expr_constant (exp
, 1, modifier
);
7775 if (modifier
!= EXPAND_CONST_ADDRESS
7776 && modifier
!= EXPAND_INITIALIZER
7777 && modifier
!= EXPAND_SUM
)
7778 constructor
= validize_mem (constructor
);
7783 /* Handle calls that pass values in multiple non-contiguous
7784 locations. The Irix 6 ABI has examples of this. */
7785 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7786 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7792 = assign_temp (build_qualified_type (type
, (TYPE_QUALS (type
)
7793 | (TREE_READONLY (exp
)
7794 * TYPE_QUAL_CONST
))),
7795 TREE_ADDRESSABLE (exp
), 1);
7798 store_constructor (exp
, target
, 0, int_expr_size (exp
));
7803 /* expand_expr: generate code for computing expression EXP.
7804 An rtx for the computed value is returned. The value is never null.
7805 In the case of a void EXP, const0_rtx is returned.
7807 The value may be stored in TARGET if TARGET is nonzero.
7808 TARGET is just a suggestion; callers must assume that
7809 the rtx returned may not be the same as TARGET.
7811 If TARGET is CONST0_RTX, it means that the value will be ignored.
7813 If TMODE is not VOIDmode, it suggests generating the
7814 result in mode TMODE. But this is done only when convenient.
7815 Otherwise, TMODE is ignored and the value generated in its natural mode.
7816 TMODE is just a suggestion; callers must assume that
7817 the rtx returned may not have mode TMODE.
7819 Note that TARGET may have neither TMODE nor MODE. In that case, it
7820 probably will not be used.
7822 If MODIFIER is EXPAND_SUM then when EXP is an addition
7823 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7824 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7825 products as above, or REG or MEM, or constant.
7826 Ordinarily in such cases we would output mul or add instructions
7827 and then return a pseudo reg containing the sum.
7829 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7830 it also marks a label as absolutely required (it can't be dead).
7831 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7832 This is used for outputting expressions used in initializers.
7834 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7835 with a constant address even if that address is not normally legitimate.
7836 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7838 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7839 a call parameter. Such targets require special care as we haven't yet
7840 marked TARGET so that it's safe from being trashed by libcalls. We
7841 don't want to use TARGET for anything but the final result;
7842 Intermediate values must go elsewhere. Additionally, calls to
7843 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7845 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7846 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7847 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7848 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7852 expand_expr_real (tree exp
, rtx target
, enum machine_mode tmode
,
7853 enum expand_modifier modifier
, rtx
*alt_rtl
)
7857 /* Handle ERROR_MARK before anybody tries to access its type. */
7858 if (TREE_CODE (exp
) == ERROR_MARK
7859 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7861 ret
= CONST0_RTX (tmode
);
7862 return ret
? ret
: const0_rtx
;
7865 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
);
7869 /* Try to expand the conditional expression which is represented by
7870 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
7871 return the rtl reg which repsents the result. Otherwise return
7875 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7876 tree treeop1 ATTRIBUTE_UNUSED
,
7877 tree treeop2 ATTRIBUTE_UNUSED
)
7879 #ifdef HAVE_conditional_move
7881 rtx op00
, op01
, op1
, op2
;
7882 enum rtx_code comparison_code
;
7883 enum machine_mode comparison_mode
;
7886 tree type
= TREE_TYPE (treeop1
);
7887 int unsignedp
= TYPE_UNSIGNED (type
);
7888 enum machine_mode mode
= TYPE_MODE (type
);
7890 /* If we cannot do a conditional move on the mode, try doing it
7891 with the promoted mode. */
7892 if (!can_conditionally_move_p (mode
))
7894 mode
= promote_mode (type
, mode
, &unsignedp
);
7895 if (!can_conditionally_move_p (mode
))
7897 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7900 temp
= assign_temp (type
, 0, 1);
7903 expand_operands (treeop1
, treeop2
,
7904 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7906 if (TREE_CODE (treeop0
) == SSA_NAME
7907 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7909 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7910 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7911 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7912 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7913 comparison_mode
= TYPE_MODE (type
);
7914 unsignedp
= TYPE_UNSIGNED (type
);
7915 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7917 else if (TREE_CODE_CLASS (TREE_CODE (treeop0
)) == tcc_comparison
)
7919 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
7920 enum tree_code cmpcode
= TREE_CODE (treeop0
);
7921 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
7922 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
7923 unsignedp
= TYPE_UNSIGNED (type
);
7924 comparison_mode
= TYPE_MODE (type
);
7925 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7929 op00
= expand_normal (treeop0
);
7931 comparison_code
= NE
;
7932 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
7935 if (GET_MODE (op1
) != mode
)
7936 op1
= gen_lowpart (mode
, op1
);
7938 if (GET_MODE (op2
) != mode
)
7939 op2
= gen_lowpart (mode
, op2
);
7941 /* Try to emit the conditional move. */
7942 insn
= emit_conditional_move (temp
, comparison_code
,
7943 op00
, op01
, comparison_mode
,
7947 /* If we could do the conditional move, emit the sequence,
7951 rtx seq
= get_insns ();
7957 /* Otherwise discard the sequence and fall back to code with
7965 expand_expr_real_2 (sepops ops
, rtx target
, enum machine_mode tmode
,
7966 enum expand_modifier modifier
)
7968 rtx op0
, op1
, op2
, temp
;
7971 enum machine_mode mode
;
7972 enum tree_code code
= ops
->code
;
7974 rtx subtarget
, original_target
;
7976 bool reduce_bit_field
;
7977 location_t loc
= ops
->location
;
7978 tree treeop0
, treeop1
, treeop2
;
7979 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
7980 ? reduce_to_bit_field_precision ((expr), \
7986 mode
= TYPE_MODE (type
);
7987 unsignedp
= TYPE_UNSIGNED (type
);
7993 /* We should be called only on simple (binary or unary) expressions,
7994 exactly those that are valid in gimple expressions that aren't
7995 GIMPLE_SINGLE_RHS (or invalid). */
7996 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
7997 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
7998 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8000 ignore
= (target
== const0_rtx
8001 || ((CONVERT_EXPR_CODE_P (code
)
8002 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8003 && TREE_CODE (type
) == VOID_TYPE
));
8005 /* We should be called only if we need the result. */
8006 gcc_assert (!ignore
);
8008 /* An operation in what may be a bit-field type needs the
8009 result to be reduced to the precision of the bit-field type,
8010 which is narrower than that of the type's mode. */
8011 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8012 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8014 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8017 /* Use subtarget as the target for operand 0 of a binary operation. */
8018 subtarget
= get_subtarget (target
);
8019 original_target
= target
;
8023 case NON_LVALUE_EXPR
:
8026 if (treeop0
== error_mark_node
)
8029 if (TREE_CODE (type
) == UNION_TYPE
)
8031 tree valtype
= TREE_TYPE (treeop0
);
8033 /* If both input and output are BLKmode, this conversion isn't doing
8034 anything except possibly changing memory attribute. */
8035 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8037 rtx result
= expand_expr (treeop0
, target
, tmode
,
8040 result
= copy_rtx (result
);
8041 set_mem_attributes (result
, type
, 0);
8047 if (TYPE_MODE (type
) != BLKmode
)
8048 target
= gen_reg_rtx (TYPE_MODE (type
));
8050 target
= assign_temp (type
, 1, 1);
8054 /* Store data into beginning of memory target. */
8055 store_expr (treeop0
,
8056 adjust_address (target
, TYPE_MODE (valtype
), 0),
8057 modifier
== EXPAND_STACK_PARM
,
8062 gcc_assert (REG_P (target
));
8064 /* Store this field into a union of the proper type. */
8065 store_field (target
,
8066 MIN ((int_size_in_bytes (TREE_TYPE
8069 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8070 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0, false);
8073 /* Return the entire union. */
8077 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8079 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8082 /* If the signedness of the conversion differs and OP0 is
8083 a promoted SUBREG, clear that indication since we now
8084 have to do the proper extension. */
8085 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8086 && GET_CODE (op0
) == SUBREG
)
8087 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8089 return REDUCE_BIT_FIELD (op0
);
8092 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8093 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8094 if (GET_MODE (op0
) == mode
)
8097 /* If OP0 is a constant, just convert it into the proper mode. */
8098 else if (CONSTANT_P (op0
))
8100 tree inner_type
= TREE_TYPE (treeop0
);
8101 enum machine_mode inner_mode
= GET_MODE (op0
);
8103 if (inner_mode
== VOIDmode
)
8104 inner_mode
= TYPE_MODE (inner_type
);
8106 if (modifier
== EXPAND_INITIALIZER
)
8107 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
8108 subreg_lowpart_offset (mode
,
8111 op0
= convert_modes (mode
, inner_mode
, op0
,
8112 TYPE_UNSIGNED (inner_type
));
8115 else if (modifier
== EXPAND_INITIALIZER
)
8116 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8118 else if (target
== 0)
8119 op0
= convert_to_mode (mode
, op0
,
8120 TYPE_UNSIGNED (TREE_TYPE
8124 convert_move (target
, op0
,
8125 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8129 return REDUCE_BIT_FIELD (op0
);
8131 case ADDR_SPACE_CONVERT_EXPR
:
8133 tree treeop0_type
= TREE_TYPE (treeop0
);
8135 addr_space_t as_from
;
8137 gcc_assert (POINTER_TYPE_P (type
));
8138 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8140 as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8141 as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8143 /* Conversions between pointers to the same address space should
8144 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8145 gcc_assert (as_to
!= as_from
);
8147 /* Ask target code to handle conversion between pointers
8148 to overlapping address spaces. */
8149 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8150 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8152 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8153 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8158 /* For disjoint address spaces, converting anything but
8159 a null pointer invokes undefined behaviour. We simply
8160 always return a null pointer here. */
8161 return CONST0_RTX (mode
);
8164 case POINTER_PLUS_EXPR
:
8165 /* Even though the sizetype mode and the pointer's mode can be different
8166 expand is able to handle this correctly and get the correct result out
8167 of the PLUS_EXPR code. */
8168 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8169 if sizetype precision is smaller than pointer precision. */
8170 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8171 treeop1
= fold_convert_loc (loc
, type
,
8172 fold_convert_loc (loc
, ssizetype
,
8174 /* If sizetype precision is larger than pointer precision, truncate the
8175 offset to have matching modes. */
8176 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8177 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8180 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8181 something else, make sure we add the register to the constant and
8182 then to the other thing. This case can occur during strength
8183 reduction and doing it this way will produce better code if the
8184 frame pointer or argument pointer is eliminated.
8186 fold-const.c will ensure that the constant is always in the inner
8187 PLUS_EXPR, so the only case we need to do anything about is if
8188 sp, ap, or fp is our second argument, in which case we must swap
8189 the innermost first argument and our second argument. */
8191 if (TREE_CODE (treeop0
) == PLUS_EXPR
8192 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8193 && TREE_CODE (treeop1
) == VAR_DECL
8194 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8195 || DECL_RTL (treeop1
) == stack_pointer_rtx
8196 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8201 /* If the result is to be ptr_mode and we are adding an integer to
8202 something, we might be forming a constant. So try to use
8203 plus_constant. If it produces a sum and we can't accept it,
8204 use force_operand. This allows P = &ARR[const] to generate
8205 efficient code on machines where a SYMBOL_REF is not a valid
8208 If this is an EXPAND_SUM call, always return the sum. */
8209 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8210 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8212 if (modifier
== EXPAND_STACK_PARM
)
8214 if (TREE_CODE (treeop0
) == INTEGER_CST
8215 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8216 && TREE_CONSTANT (treeop1
))
8220 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8222 /* Use immed_double_const to ensure that the constant is
8223 truncated according to the mode of OP1, then sign extended
8224 to a HOST_WIDE_INT. Using the constant directly can result
8225 in non-canonical RTL in a 64x32 cross compile. */
8227 = immed_double_const (TREE_INT_CST_LOW (treeop0
),
8229 TYPE_MODE (TREE_TYPE (treeop1
)));
8230 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8231 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8232 op1
= force_operand (op1
, target
);
8233 return REDUCE_BIT_FIELD (op1
);
8236 else if (TREE_CODE (treeop1
) == INTEGER_CST
8237 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8238 && TREE_CONSTANT (treeop0
))
8242 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8243 (modifier
== EXPAND_INITIALIZER
8244 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8245 if (! CONSTANT_P (op0
))
8247 op1
= expand_expr (treeop1
, NULL_RTX
,
8248 VOIDmode
, modifier
);
8249 /* Return a PLUS if modifier says it's OK. */
8250 if (modifier
== EXPAND_SUM
8251 || modifier
== EXPAND_INITIALIZER
)
8252 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8255 /* Use immed_double_const to ensure that the constant is
8256 truncated according to the mode of OP1, then sign extended
8257 to a HOST_WIDE_INT. Using the constant directly can result
8258 in non-canonical RTL in a 64x32 cross compile. */
8260 = immed_double_const (TREE_INT_CST_LOW (treeop1
),
8262 TYPE_MODE (TREE_TYPE (treeop0
)));
8263 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8264 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8265 op0
= force_operand (op0
, target
);
8266 return REDUCE_BIT_FIELD (op0
);
8270 /* Use TER to expand pointer addition of a negated value
8271 as pointer subtraction. */
8272 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8273 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8274 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8275 && TREE_CODE (treeop1
) == SSA_NAME
8276 && TYPE_MODE (TREE_TYPE (treeop0
))
8277 == TYPE_MODE (TREE_TYPE (treeop1
)))
8279 gimple def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8282 treeop1
= gimple_assign_rhs1 (def
);
8288 /* No sense saving up arithmetic to be done
8289 if it's all in the wrong mode to form part of an address.
8290 And force_operand won't know whether to sign-extend or
8292 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8293 || mode
!= ptr_mode
)
8295 expand_operands (treeop0
, treeop1
,
8296 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8297 if (op0
== const0_rtx
)
8299 if (op1
== const0_rtx
)
8304 expand_operands (treeop0
, treeop1
,
8305 subtarget
, &op0
, &op1
, modifier
);
8306 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8310 /* For initializers, we are allowed to return a MINUS of two
8311 symbolic constants. Here we handle all cases when both operands
8313 /* Handle difference of two symbolic constants,
8314 for the sake of an initializer. */
8315 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8316 && really_constant_p (treeop0
)
8317 && really_constant_p (treeop1
))
8319 expand_operands (treeop0
, treeop1
,
8320 NULL_RTX
, &op0
, &op1
, modifier
);
8322 /* If the last operand is a CONST_INT, use plus_constant of
8323 the negated constant. Else make the MINUS. */
8324 if (CONST_INT_P (op1
))
8325 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8328 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8331 /* No sense saving up arithmetic to be done
8332 if it's all in the wrong mode to form part of an address.
8333 And force_operand won't know whether to sign-extend or
8335 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8336 || mode
!= ptr_mode
)
8339 expand_operands (treeop0
, treeop1
,
8340 subtarget
, &op0
, &op1
, modifier
);
8342 /* Convert A - const to A + (-const). */
8343 if (CONST_INT_P (op1
))
8345 op1
= negate_rtx (mode
, op1
);
8346 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8351 case WIDEN_MULT_PLUS_EXPR
:
8352 case WIDEN_MULT_MINUS_EXPR
:
8353 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8354 op2
= expand_normal (treeop2
);
8355 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8359 case WIDEN_MULT_EXPR
:
8360 /* If first operand is constant, swap them.
8361 Thus the following special case checks need only
8362 check the second operand. */
8363 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8370 /* First, check if we have a multiplication of one signed and one
8371 unsigned operand. */
8372 if (TREE_CODE (treeop1
) != INTEGER_CST
8373 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8374 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8376 enum machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8377 this_optab
= usmul_widen_optab
;
8378 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8379 != CODE_FOR_nothing
)
8381 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8382 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8385 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8390 /* Check for a multiplication with matching signedness. */
8391 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8392 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8393 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8394 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8396 tree op0type
= TREE_TYPE (treeop0
);
8397 enum machine_mode innermode
= TYPE_MODE (op0type
);
8398 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8399 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8400 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8402 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8404 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8405 != CODE_FOR_nothing
)
8407 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8409 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8410 unsignedp
, this_optab
);
8411 return REDUCE_BIT_FIELD (temp
);
8413 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8415 && innermode
== word_mode
)
8418 op0
= expand_normal (treeop0
);
8419 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8420 op1
= convert_modes (innermode
, mode
,
8421 expand_normal (treeop1
), unsignedp
);
8423 op1
= expand_normal (treeop1
);
8424 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8425 unsignedp
, OPTAB_LIB_WIDEN
);
8426 hipart
= gen_highpart (innermode
, temp
);
8427 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8431 emit_move_insn (hipart
, htem
);
8432 return REDUCE_BIT_FIELD (temp
);
8436 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8437 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8438 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8439 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8443 optab opt
= fma_optab
;
8446 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8448 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8450 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8453 gcc_assert (fn
!= NULL_TREE
);
8454 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8455 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8458 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8459 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8464 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8467 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8468 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8471 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8474 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8477 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8480 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8484 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8486 op2
= expand_normal (treeop2
);
8487 op1
= expand_normal (treeop1
);
8489 return expand_ternary_op (TYPE_MODE (type
), opt
,
8490 op0
, op1
, op2
, target
, 0);
8494 /* If this is a fixed-point operation, then we cannot use the code
8495 below because "expand_mult" doesn't support sat/no-sat fixed-point
8497 if (ALL_FIXED_POINT_MODE_P (mode
))
8500 /* If first operand is constant, swap them.
8501 Thus the following special case checks need only
8502 check the second operand. */
8503 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8510 /* Attempt to return something suitable for generating an
8511 indexed address, for machines that support that. */
8513 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8514 && host_integerp (treeop1
, 0))
8516 tree exp1
= treeop1
;
8518 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8522 op0
= force_operand (op0
, NULL_RTX
);
8524 op0
= copy_to_mode_reg (mode
, op0
);
8526 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8527 gen_int_mode (tree_low_cst (exp1
, 0),
8528 TYPE_MODE (TREE_TYPE (exp1
)))));
8531 if (modifier
== EXPAND_STACK_PARM
)
8534 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8535 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8537 case TRUNC_DIV_EXPR
:
8538 case FLOOR_DIV_EXPR
:
8540 case ROUND_DIV_EXPR
:
8541 case EXACT_DIV_EXPR
:
8542 /* If this is a fixed-point operation, then we cannot use the code
8543 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8545 if (ALL_FIXED_POINT_MODE_P (mode
))
8548 if (modifier
== EXPAND_STACK_PARM
)
8550 /* Possible optimization: compute the dividend with EXPAND_SUM
8551 then if the divisor is constant can optimize the case
8552 where some terms of the dividend have coeffs divisible by it. */
8553 expand_operands (treeop0
, treeop1
,
8554 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8555 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8560 case MULT_HIGHPART_EXPR
:
8561 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8562 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8566 case TRUNC_MOD_EXPR
:
8567 case FLOOR_MOD_EXPR
:
8569 case ROUND_MOD_EXPR
:
8570 if (modifier
== EXPAND_STACK_PARM
)
8572 expand_operands (treeop0
, treeop1
,
8573 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8574 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8576 case FIXED_CONVERT_EXPR
:
8577 op0
= expand_normal (treeop0
);
8578 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8579 target
= gen_reg_rtx (mode
);
8581 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8582 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8583 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8584 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8586 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8589 case FIX_TRUNC_EXPR
:
8590 op0
= expand_normal (treeop0
);
8591 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8592 target
= gen_reg_rtx (mode
);
8593 expand_fix (target
, op0
, unsignedp
);
8597 op0
= expand_normal (treeop0
);
8598 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8599 target
= gen_reg_rtx (mode
);
8600 /* expand_float can't figure out what to do if FROM has VOIDmode.
8601 So give it the correct mode. With -O, cse will optimize this. */
8602 if (GET_MODE (op0
) == VOIDmode
)
8603 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8605 expand_float (target
, op0
,
8606 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8610 op0
= expand_expr (treeop0
, subtarget
,
8611 VOIDmode
, EXPAND_NORMAL
);
8612 if (modifier
== EXPAND_STACK_PARM
)
8614 temp
= expand_unop (mode
,
8615 optab_for_tree_code (NEGATE_EXPR
, type
,
8619 return REDUCE_BIT_FIELD (temp
);
8622 op0
= expand_expr (treeop0
, subtarget
,
8623 VOIDmode
, EXPAND_NORMAL
);
8624 if (modifier
== EXPAND_STACK_PARM
)
8627 /* ABS_EXPR is not valid for complex arguments. */
8628 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8629 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8631 /* Unsigned abs is simply the operand. Testing here means we don't
8632 risk generating incorrect code below. */
8633 if (TYPE_UNSIGNED (type
))
8636 return expand_abs (mode
, op0
, target
, unsignedp
,
8637 safe_from_p (target
, treeop0
, 1));
8641 target
= original_target
;
8643 || modifier
== EXPAND_STACK_PARM
8644 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8645 || GET_MODE (target
) != mode
8647 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8648 target
= gen_reg_rtx (mode
);
8649 expand_operands (treeop0
, treeop1
,
8650 target
, &op0
, &op1
, EXPAND_NORMAL
);
8652 /* First try to do it with a special MIN or MAX instruction.
8653 If that does not win, use a conditional jump to select the proper
8655 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8656 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8661 /* At this point, a MEM target is no longer useful; we will get better
8664 if (! REG_P (target
))
8665 target
= gen_reg_rtx (mode
);
8667 /* If op1 was placed in target, swap op0 and op1. */
8668 if (target
!= op0
&& target
== op1
)
8675 /* We generate better code and avoid problems with op1 mentioning
8676 target by forcing op1 into a pseudo if it isn't a constant. */
8677 if (! CONSTANT_P (op1
))
8678 op1
= force_reg (mode
, op1
);
8681 enum rtx_code comparison_code
;
8684 if (code
== MAX_EXPR
)
8685 comparison_code
= unsignedp
? GEU
: GE
;
8687 comparison_code
= unsignedp
? LEU
: LE
;
8689 /* Canonicalize to comparisons against 0. */
8690 if (op1
== const1_rtx
)
8692 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8693 or (a != 0 ? a : 1) for unsigned.
8694 For MIN we are safe converting (a <= 1 ? a : 1)
8695 into (a <= 0 ? a : 1) */
8696 cmpop1
= const0_rtx
;
8697 if (code
== MAX_EXPR
)
8698 comparison_code
= unsignedp
? NE
: GT
;
8700 if (op1
== constm1_rtx
&& !unsignedp
)
8702 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8703 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8704 cmpop1
= const0_rtx
;
8705 if (code
== MIN_EXPR
)
8706 comparison_code
= LT
;
8708 #ifdef HAVE_conditional_move
8709 /* Use a conditional move if possible. */
8710 if (can_conditionally_move_p (mode
))
8714 /* ??? Same problem as in expmed.c: emit_conditional_move
8715 forces a stack adjustment via compare_from_rtx, and we
8716 lose the stack adjustment if the sequence we are about
8717 to create is discarded. */
8718 do_pending_stack_adjust ();
8722 /* Try to emit the conditional move. */
8723 insn
= emit_conditional_move (target
, comparison_code
,
8728 /* If we could do the conditional move, emit the sequence,
8732 rtx seq
= get_insns ();
8738 /* Otherwise discard the sequence and fall back to code with
8744 emit_move_insn (target
, op0
);
8746 temp
= gen_label_rtx ();
8747 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8748 unsignedp
, mode
, NULL_RTX
, NULL_RTX
, temp
,
8751 emit_move_insn (target
, op1
);
8756 op0
= expand_expr (treeop0
, subtarget
,
8757 VOIDmode
, EXPAND_NORMAL
);
8758 if (modifier
== EXPAND_STACK_PARM
)
8760 /* In case we have to reduce the result to bitfield precision
8761 for unsigned bitfield expand this as XOR with a proper constant
8763 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8764 temp
= expand_binop (mode
, xor_optab
, op0
,
8765 immed_double_int_const
8766 (double_int::mask (TYPE_PRECISION (type
)), mode
),
8767 target
, 1, OPTAB_LIB_WIDEN
);
8769 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8773 /* ??? Can optimize bitwise operations with one arg constant.
8774 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8775 and (a bitwise1 b) bitwise2 b (etc)
8776 but that is probably not worth while. */
8785 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8786 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8787 == TYPE_PRECISION (type
)));
8792 /* If this is a fixed-point operation, then we cannot use the code
8793 below because "expand_shift" doesn't support sat/no-sat fixed-point
8795 if (ALL_FIXED_POINT_MODE_P (mode
))
8798 if (! safe_from_p (subtarget
, treeop1
, 1))
8800 if (modifier
== EXPAND_STACK_PARM
)
8802 op0
= expand_expr (treeop0
, subtarget
,
8803 VOIDmode
, EXPAND_NORMAL
);
8804 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
8806 if (code
== LSHIFT_EXPR
)
8807 temp
= REDUCE_BIT_FIELD (temp
);
8810 /* Could determine the answer when only additive constants differ. Also,
8811 the addition of one can be handled by changing the condition. */
8818 case UNORDERED_EXPR
:
8826 temp
= do_store_flag (ops
,
8827 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
8828 tmode
!= VOIDmode
? tmode
: mode
);
8832 /* Use a compare and a jump for BLKmode comparisons, or for function
8833 type comparisons is HAVE_canonicalize_funcptr_for_compare. */
8836 || modifier
== EXPAND_STACK_PARM
8837 || ! safe_from_p (target
, treeop0
, 1)
8838 || ! safe_from_p (target
, treeop1
, 1)
8839 /* Make sure we don't have a hard reg (such as function's return
8840 value) live across basic blocks, if not optimizing. */
8841 || (!optimize
&& REG_P (target
)
8842 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
8843 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
8845 emit_move_insn (target
, const0_rtx
);
8847 op1
= gen_label_rtx ();
8848 jumpifnot_1 (code
, treeop0
, treeop1
, op1
, -1);
8850 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
8851 emit_move_insn (target
, constm1_rtx
);
8853 emit_move_insn (target
, const1_rtx
);
8859 /* Get the rtx code of the operands. */
8860 op0
= expand_normal (treeop0
);
8861 op1
= expand_normal (treeop1
);
8864 target
= gen_reg_rtx (TYPE_MODE (type
));
8866 /* Move the real (op0) and imaginary (op1) parts to their location. */
8867 write_complex_part (target
, op0
, false);
8868 write_complex_part (target
, op1
, true);
8872 case WIDEN_SUM_EXPR
:
8874 tree oprnd0
= treeop0
;
8875 tree oprnd1
= treeop1
;
8877 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8878 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
8883 case REDUC_MAX_EXPR
:
8884 case REDUC_MIN_EXPR
:
8885 case REDUC_PLUS_EXPR
:
8887 op0
= expand_normal (treeop0
);
8888 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8889 temp
= expand_unop (mode
, this_optab
, op0
, target
, unsignedp
);
8894 case VEC_LSHIFT_EXPR
:
8895 case VEC_RSHIFT_EXPR
:
8897 target
= expand_vec_shift_expr (ops
, target
);
8901 case VEC_UNPACK_HI_EXPR
:
8902 case VEC_UNPACK_LO_EXPR
:
8904 op0
= expand_normal (treeop0
);
8905 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
8911 case VEC_UNPACK_FLOAT_HI_EXPR
:
8912 case VEC_UNPACK_FLOAT_LO_EXPR
:
8914 op0
= expand_normal (treeop0
);
8915 /* The signedness is determined from input operand. */
8916 temp
= expand_widen_pattern_expr
8917 (ops
, op0
, NULL_RTX
, NULL_RTX
,
8918 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8924 case VEC_WIDEN_MULT_HI_EXPR
:
8925 case VEC_WIDEN_MULT_LO_EXPR
:
8926 case VEC_WIDEN_MULT_EVEN_EXPR
:
8927 case VEC_WIDEN_MULT_ODD_EXPR
:
8928 case VEC_WIDEN_LSHIFT_HI_EXPR
:
8929 case VEC_WIDEN_LSHIFT_LO_EXPR
:
8930 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8931 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
8933 gcc_assert (target
);
8936 case VEC_PACK_TRUNC_EXPR
:
8937 case VEC_PACK_SAT_EXPR
:
8938 case VEC_PACK_FIX_TRUNC_EXPR
:
8939 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8943 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
8944 op2
= expand_normal (treeop2
);
8946 /* Careful here: if the target doesn't support integral vector modes,
8947 a constant selection vector could wind up smooshed into a normal
8948 integral constant. */
8949 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
8951 tree sel_type
= TREE_TYPE (treeop2
);
8952 enum machine_mode vmode
8953 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
8954 TYPE_VECTOR_SUBPARTS (sel_type
));
8955 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
8956 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
8957 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
8960 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
8962 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
8968 tree oprnd0
= treeop0
;
8969 tree oprnd1
= treeop1
;
8970 tree oprnd2
= treeop2
;
8973 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8974 op2
= expand_normal (oprnd2
);
8975 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8980 case REALIGN_LOAD_EXPR
:
8982 tree oprnd0
= treeop0
;
8983 tree oprnd1
= treeop1
;
8984 tree oprnd2
= treeop2
;
8987 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8988 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8989 op2
= expand_normal (oprnd2
);
8990 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
8997 /* A COND_EXPR with its type being VOID_TYPE represents a
8998 conditional jump and is handled in
8999 expand_gimple_cond_expr. */
9000 gcc_assert (!VOID_TYPE_P (type
));
9002 /* Note that COND_EXPRs whose type is a structure or union
9003 are required to be constructed to contain assignments of
9004 a temporary variable, so that we can evaluate them here
9005 for side effect only. If type is void, we must do likewise. */
9007 gcc_assert (!TREE_ADDRESSABLE (type
)
9009 && TREE_TYPE (treeop1
) != void_type_node
9010 && TREE_TYPE (treeop2
) != void_type_node
);
9012 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9016 /* If we are not to produce a result, we have no target. Otherwise,
9017 if a target was specified use it; it will not be used as an
9018 intermediate target unless it is safe. If no target, use a
9021 if (modifier
!= EXPAND_STACK_PARM
9023 && safe_from_p (original_target
, treeop0
, 1)
9024 && GET_MODE (original_target
) == mode
9025 && !MEM_P (original_target
))
9026 temp
= original_target
;
9028 temp
= assign_temp (type
, 0, 1);
9030 do_pending_stack_adjust ();
9032 op0
= gen_label_rtx ();
9033 op1
= gen_label_rtx ();
9034 jumpifnot (treeop0
, op0
, -1);
9035 store_expr (treeop1
, temp
,
9036 modifier
== EXPAND_STACK_PARM
,
9039 emit_jump_insn (gen_jump (op1
));
9042 store_expr (treeop2
, temp
,
9043 modifier
== EXPAND_STACK_PARM
,
9051 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9058 /* Here to do an ordinary binary operator. */
9060 expand_operands (treeop0
, treeop1
,
9061 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9063 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9065 if (modifier
== EXPAND_STACK_PARM
)
9067 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9068 unsignedp
, OPTAB_LIB_WIDEN
);
9070 /* Bitwise operations do not need bitfield reduction as we expect their
9071 operands being properly truncated. */
9072 if (code
== BIT_XOR_EXPR
9073 || code
== BIT_AND_EXPR
9074 || code
== BIT_IOR_EXPR
)
9076 return REDUCE_BIT_FIELD (temp
);
9078 #undef REDUCE_BIT_FIELD
9081 expand_expr_real_1 (tree exp
, rtx target
, enum machine_mode tmode
,
9082 enum expand_modifier modifier
, rtx
*alt_rtl
)
9084 rtx op0
, op1
, temp
, decl_rtl
;
9087 enum machine_mode mode
;
9088 enum tree_code code
= TREE_CODE (exp
);
9089 rtx subtarget
, original_target
;
9092 bool reduce_bit_field
;
9093 location_t loc
= EXPR_LOCATION (exp
);
9094 struct separate_ops ops
;
9095 tree treeop0
, treeop1
, treeop2
;
9096 tree ssa_name
= NULL_TREE
;
9099 type
= TREE_TYPE (exp
);
9100 mode
= TYPE_MODE (type
);
9101 unsignedp
= TYPE_UNSIGNED (type
);
9103 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9104 if (!VL_EXP_CLASS_P (exp
))
9105 switch (TREE_CODE_LENGTH (code
))
9108 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9109 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9110 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9120 ignore
= (target
== const0_rtx
9121 || ((CONVERT_EXPR_CODE_P (code
)
9122 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9123 && TREE_CODE (type
) == VOID_TYPE
));
9125 /* An operation in what may be a bit-field type needs the
9126 result to be reduced to the precision of the bit-field type,
9127 which is narrower than that of the type's mode. */
9128 reduce_bit_field
= (!ignore
9129 && INTEGRAL_TYPE_P (type
)
9130 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9132 /* If we are going to ignore this result, we need only do something
9133 if there is a side-effect somewhere in the expression. If there
9134 is, short-circuit the most common cases here. Note that we must
9135 not call expand_expr with anything but const0_rtx in case this
9136 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9140 if (! TREE_SIDE_EFFECTS (exp
))
9143 /* Ensure we reference a volatile object even if value is ignored, but
9144 don't do this if all we are doing is taking its address. */
9145 if (TREE_THIS_VOLATILE (exp
)
9146 && TREE_CODE (exp
) != FUNCTION_DECL
9147 && mode
!= VOIDmode
&& mode
!= BLKmode
9148 && modifier
!= EXPAND_CONST_ADDRESS
)
9150 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9156 if (TREE_CODE_CLASS (code
) == tcc_unary
9157 || code
== BIT_FIELD_REF
9158 || code
== COMPONENT_REF
9159 || code
== INDIRECT_REF
)
9160 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9163 else if (TREE_CODE_CLASS (code
) == tcc_binary
9164 || TREE_CODE_CLASS (code
) == tcc_comparison
9165 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9167 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9168 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9175 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9178 /* Use subtarget as the target for operand 0 of a binary operation. */
9179 subtarget
= get_subtarget (target
);
9180 original_target
= target
;
9186 tree function
= decl_function_context (exp
);
9188 temp
= label_rtx (exp
);
9189 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9191 if (function
!= current_function_decl
9193 LABEL_REF_NONLOCAL_P (temp
) = 1;
9195 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9200 /* ??? ivopts calls expander, without any preparation from
9201 out-of-ssa. So fake instructions as if this was an access to the
9202 base variable. This unnecessarily allocates a pseudo, see how we can
9203 reuse it, if partition base vars have it set already. */
9204 if (!currently_expanding_to_rtl
)
9206 tree var
= SSA_NAME_VAR (exp
);
9207 if (var
&& DECL_RTL_SET_P (var
))
9208 return DECL_RTL (var
);
9209 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9210 LAST_VIRTUAL_REGISTER
+ 1);
9213 g
= get_gimple_for_ssa_name (exp
);
9214 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9216 && modifier
== EXPAND_INITIALIZER
9217 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9218 && (optimize
|| DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9219 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9220 g
= SSA_NAME_DEF_STMT (exp
);
9224 location_t saved_loc
= curr_insn_location ();
9226 set_curr_insn_location (gimple_location (g
));
9227 r
= expand_expr_real (gimple_assign_rhs_to_tree (g
), target
,
9228 tmode
, modifier
, NULL
);
9229 set_curr_insn_location (saved_loc
);
9230 if (REG_P (r
) && !REG_EXPR (r
))
9231 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9236 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9237 exp
= SSA_NAME_VAR (ssa_name
);
9238 goto expand_decl_rtl
;
9242 /* If a static var's type was incomplete when the decl was written,
9243 but the type is complete now, lay out the decl now. */
9244 if (DECL_SIZE (exp
) == 0
9245 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9246 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9247 layout_decl (exp
, 0);
9249 /* ... fall through ... */
9253 decl_rtl
= DECL_RTL (exp
);
9255 gcc_assert (decl_rtl
);
9256 decl_rtl
= copy_rtx (decl_rtl
);
9257 /* Record writes to register variables. */
9258 if (modifier
== EXPAND_WRITE
9260 && HARD_REGISTER_P (decl_rtl
))
9261 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9262 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9264 /* Ensure variable marked as used even if it doesn't go through
9265 a parser. If it hasn't be used yet, write out an external
9267 TREE_USED (exp
) = 1;
9269 /* Show we haven't gotten RTL for this yet. */
9272 /* Variables inherited from containing functions should have
9273 been lowered by this point. */
9274 context
= decl_function_context (exp
);
9275 gcc_assert (!context
9276 || context
== current_function_decl
9277 || TREE_STATIC (exp
)
9278 || DECL_EXTERNAL (exp
)
9279 /* ??? C++ creates functions that are not TREE_STATIC. */
9280 || TREE_CODE (exp
) == FUNCTION_DECL
);
9282 /* This is the case of an array whose size is to be determined
9283 from its initializer, while the initializer is still being parsed.
9284 ??? We aren't parsing while expanding anymore. */
9286 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9287 temp
= validize_mem (decl_rtl
);
9289 /* If DECL_RTL is memory, we are in the normal case and the
9290 address is not valid, get the address into a register. */
9292 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9295 *alt_rtl
= decl_rtl
;
9296 decl_rtl
= use_anchored_address (decl_rtl
);
9297 if (modifier
!= EXPAND_CONST_ADDRESS
9298 && modifier
!= EXPAND_SUM
9299 && !memory_address_addr_space_p (DECL_MODE (exp
),
9301 MEM_ADDR_SPACE (decl_rtl
)))
9302 temp
= replace_equiv_address (decl_rtl
,
9303 copy_rtx (XEXP (decl_rtl
, 0)));
9306 /* If we got something, return it. But first, set the alignment
9307 if the address is a register. */
9310 if (MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9311 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9316 /* If the mode of DECL_RTL does not match that of the decl,
9317 there are two cases: we are dealing with a BLKmode value
9318 that is returned in a register, or we are dealing with
9319 a promoted value. In the latter case, return a SUBREG
9320 of the wanted mode, but mark it so that we know that it
9321 was already extended. */
9322 if (REG_P (decl_rtl
)
9323 && DECL_MODE (exp
) != BLKmode
9324 && GET_MODE (decl_rtl
) != DECL_MODE (exp
))
9326 enum machine_mode pmode
;
9328 /* Get the signedness to be used for this variable. Ensure we get
9329 the same mode we got when the variable was declared. */
9330 if (code
== SSA_NAME
9331 && (g
= SSA_NAME_DEF_STMT (ssa_name
))
9332 && gimple_code (g
) == GIMPLE_CALL
)
9334 gcc_assert (!gimple_call_internal_p (g
));
9335 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9336 gimple_call_fntype (g
),
9340 pmode
= promote_decl_mode (exp
, &unsignedp
);
9341 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9343 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9344 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9345 SUBREG_PROMOTED_UNSIGNED_SET (temp
, unsignedp
);
9352 temp
= immed_double_const (TREE_INT_CST_LOW (exp
),
9353 TREE_INT_CST_HIGH (exp
), mode
);
9359 tree tmp
= NULL_TREE
;
9360 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9361 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9362 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9363 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9364 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9365 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9366 return const_vector_from_tree (exp
);
9367 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9369 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9371 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9375 vec
<constructor_elt
, va_gc
> *v
;
9377 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9378 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9379 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9380 tmp
= build_constructor (type
, v
);
9382 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9387 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9390 /* If optimized, generate immediate CONST_DOUBLE
9391 which will be turned into memory by reload if necessary.
9393 We used to force a register so that loop.c could see it. But
9394 this does not allow gen_* patterns to perform optimizations with
9395 the constants. It also produces two insns in cases like "x = 1.0;".
9396 On most machines, floating-point constants are not permitted in
9397 many insns, so we'd end up copying it to a register in any case.
9399 Now, we do the copying in expand_binop, if appropriate. */
9400 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp
),
9401 TYPE_MODE (TREE_TYPE (exp
)));
9404 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9405 TYPE_MODE (TREE_TYPE (exp
)));
9408 /* Handle evaluating a complex constant in a CONCAT target. */
9409 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9411 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9414 rtarg
= XEXP (original_target
, 0);
9415 itarg
= XEXP (original_target
, 1);
9417 /* Move the real and imaginary parts separately. */
9418 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9419 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9422 emit_move_insn (rtarg
, op0
);
9424 emit_move_insn (itarg
, op1
);
9426 return original_target
;
9429 /* ... fall through ... */
9432 temp
= expand_expr_constant (exp
, 1, modifier
);
9434 /* temp contains a constant address.
9435 On RISC machines where a constant address isn't valid,
9436 make some insns to get that address into a register. */
9437 if (modifier
!= EXPAND_CONST_ADDRESS
9438 && modifier
!= EXPAND_INITIALIZER
9439 && modifier
!= EXPAND_SUM
9440 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9441 MEM_ADDR_SPACE (temp
)))
9442 return replace_equiv_address (temp
,
9443 copy_rtx (XEXP (temp
, 0)));
9449 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
);
9451 if (!SAVE_EXPR_RESOLVED_P (exp
))
9453 /* We can indeed still hit this case, typically via builtin
9454 expanders calling save_expr immediately before expanding
9455 something. Assume this means that we only have to deal
9456 with non-BLKmode values. */
9457 gcc_assert (GET_MODE (ret
) != BLKmode
);
9459 val
= build_decl (curr_insn_location (),
9460 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9461 DECL_ARTIFICIAL (val
) = 1;
9462 DECL_IGNORED_P (val
) = 1;
9464 TREE_OPERAND (exp
, 0) = treeop0
;
9465 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9467 if (!CONSTANT_P (ret
))
9468 ret
= copy_to_reg (ret
);
9469 SET_DECL_RTL (val
, ret
);
9477 /* If we don't need the result, just ensure we evaluate any
9481 unsigned HOST_WIDE_INT idx
;
9484 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9485 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9490 return expand_constructor (exp
, target
, modifier
, false);
9492 case TARGET_MEM_REF
:
9495 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9496 struct mem_address addr
;
9497 enum insn_code icode
;
9500 get_address_description (exp
, &addr
);
9501 op0
= addr_for_mem_ref (&addr
, as
, true);
9502 op0
= memory_address_addr_space (mode
, op0
, as
);
9503 temp
= gen_rtx_MEM (mode
, op0
);
9504 set_mem_attributes (temp
, exp
, 0);
9505 set_mem_addr_space (temp
, as
);
9506 align
= get_object_alignment (exp
);
9507 if (modifier
!= EXPAND_WRITE
9509 && align
< GET_MODE_ALIGNMENT (mode
)
9510 /* If the target does not have special handling for unaligned
9511 loads of mode then it can use regular moves for them. */
9512 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9513 != CODE_FOR_nothing
))
9515 struct expand_operand ops
[2];
9517 /* We've already validated the memory, and we're creating a
9518 new pseudo destination. The predicates really can't fail,
9519 nor can the generator. */
9520 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9521 create_fixed_operand (&ops
[1], temp
);
9522 expand_insn (icode
, 2, ops
);
9523 return ops
[0].value
;
9531 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9532 enum machine_mode address_mode
;
9533 tree base
= TREE_OPERAND (exp
, 0);
9535 enum insn_code icode
;
9537 /* Handle expansion of non-aliased memory with non-BLKmode. That
9538 might end up in a register. */
9539 if (mem_ref_refers_to_non_mem_p (exp
))
9541 HOST_WIDE_INT offset
= mem_ref_offset (exp
).low
;
9544 base
= TREE_OPERAND (base
, 0);
9546 && host_integerp (TYPE_SIZE (TREE_TYPE (exp
)), 1)
9547 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9548 == TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (exp
)))))
9549 return expand_expr (build1 (VIEW_CONVERT_EXPR
,
9550 TREE_TYPE (exp
), base
),
9551 target
, tmode
, modifier
);
9552 bit_offset
= bitsize_int (offset
* BITS_PER_UNIT
);
9553 bftype
= TREE_TYPE (base
);
9554 if (TYPE_MODE (TREE_TYPE (exp
)) != BLKmode
)
9555 bftype
= TREE_TYPE (exp
);
9558 temp
= assign_stack_temp (DECL_MODE (base
),
9559 GET_MODE_SIZE (DECL_MODE (base
)));
9560 store_expr (base
, temp
, 0, false);
9561 temp
= adjust_address (temp
, BLKmode
, offset
);
9562 set_mem_size (temp
, int_size_in_bytes (TREE_TYPE (exp
)));
9565 return expand_expr (build3 (BIT_FIELD_REF
, bftype
,
9567 TYPE_SIZE (TREE_TYPE (exp
)),
9569 target
, tmode
, modifier
);
9571 address_mode
= targetm
.addr_space
.address_mode (as
);
9572 base
= TREE_OPERAND (exp
, 0);
9573 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9575 tree mask
= gimple_assign_rhs2 (def_stmt
);
9576 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9577 gimple_assign_rhs1 (def_stmt
), mask
);
9578 TREE_OPERAND (exp
, 0) = base
;
9580 align
= get_object_alignment (exp
);
9581 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9582 op0
= memory_address_addr_space (address_mode
, op0
, as
);
9583 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9586 = immed_double_int_const (mem_ref_offset (exp
), address_mode
);
9587 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9589 op0
= memory_address_addr_space (mode
, op0
, as
);
9590 temp
= gen_rtx_MEM (mode
, op0
);
9591 set_mem_attributes (temp
, exp
, 0);
9592 set_mem_addr_space (temp
, as
);
9593 if (TREE_THIS_VOLATILE (exp
))
9594 MEM_VOLATILE_P (temp
) = 1;
9595 if (modifier
!= EXPAND_WRITE
9597 && align
< GET_MODE_ALIGNMENT (mode
))
9599 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9600 != CODE_FOR_nothing
)
9602 struct expand_operand ops
[2];
9604 /* We've already validated the memory, and we're creating a
9605 new pseudo destination. The predicates really can't fail,
9606 nor can the generator. */
9607 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9608 create_fixed_operand (&ops
[1], temp
);
9609 expand_insn (icode
, 2, ops
);
9610 return ops
[0].value
;
9612 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9613 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9614 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9615 true, (modifier
== EXPAND_STACK_PARM
9616 ? NULL_RTX
: target
),
9625 tree array
= treeop0
;
9626 tree index
= treeop1
;
9628 /* Fold an expression like: "foo"[2].
9629 This is not done in fold so it won't happen inside &.
9630 Don't fold if this is for wide characters since it's too
9631 difficult to do correctly and this is a very rare case. */
9633 if (modifier
!= EXPAND_CONST_ADDRESS
9634 && modifier
!= EXPAND_INITIALIZER
9635 && modifier
!= EXPAND_MEMORY
)
9637 tree t
= fold_read_from_constant_string (exp
);
9640 return expand_expr (t
, target
, tmode
, modifier
);
9643 /* If this is a constant index into a constant array,
9644 just get the value from the array. Handle both the cases when
9645 we have an explicit constructor and when our operand is a variable
9646 that was declared const. */
9648 if (modifier
!= EXPAND_CONST_ADDRESS
9649 && modifier
!= EXPAND_INITIALIZER
9650 && modifier
!= EXPAND_MEMORY
9651 && TREE_CODE (array
) == CONSTRUCTOR
9652 && ! TREE_SIDE_EFFECTS (array
)
9653 && TREE_CODE (index
) == INTEGER_CST
)
9655 unsigned HOST_WIDE_INT ix
;
9658 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
9660 if (tree_int_cst_equal (field
, index
))
9662 if (!TREE_SIDE_EFFECTS (value
))
9663 return expand_expr (fold (value
), target
, tmode
, modifier
);
9668 else if (optimize
>= 1
9669 && modifier
!= EXPAND_CONST_ADDRESS
9670 && modifier
!= EXPAND_INITIALIZER
9671 && modifier
!= EXPAND_MEMORY
9672 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
9673 && TREE_CODE (array
) == VAR_DECL
&& DECL_INITIAL (array
)
9674 && TREE_CODE (DECL_INITIAL (array
)) != ERROR_MARK
9675 && const_value_known_p (array
))
9677 if (TREE_CODE (index
) == INTEGER_CST
)
9679 tree init
= DECL_INITIAL (array
);
9681 if (TREE_CODE (init
) == CONSTRUCTOR
)
9683 unsigned HOST_WIDE_INT ix
;
9686 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
9688 if (tree_int_cst_equal (field
, index
))
9690 if (TREE_SIDE_EFFECTS (value
))
9693 if (TREE_CODE (value
) == CONSTRUCTOR
)
9695 /* If VALUE is a CONSTRUCTOR, this
9696 optimization is only useful if
9697 this doesn't store the CONSTRUCTOR
9698 into memory. If it does, it is more
9699 efficient to just load the data from
9700 the array directly. */
9701 rtx ret
= expand_constructor (value
, target
,
9703 if (ret
== NULL_RTX
)
9707 return expand_expr (fold (value
), target
, tmode
,
9711 else if(TREE_CODE (init
) == STRING_CST
)
9713 tree index1
= index
;
9714 tree low_bound
= array_ref_low_bound (exp
);
9715 index1
= fold_convert_loc (loc
, sizetype
,
9718 /* Optimize the special-case of a zero lower bound.
9720 We convert the low_bound to sizetype to avoid some problems
9721 with constant folding. (E.g. suppose the lower bound is 1,
9722 and its mode is QI. Without the conversion,l (ARRAY
9723 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
9724 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
9726 if (! integer_zerop (low_bound
))
9727 index1
= size_diffop_loc (loc
, index1
,
9728 fold_convert_loc (loc
, sizetype
,
9731 if (0 > compare_tree_int (index1
,
9732 TREE_STRING_LENGTH (init
)))
9734 tree type
= TREE_TYPE (TREE_TYPE (init
));
9735 enum machine_mode mode
= TYPE_MODE (type
);
9737 if (GET_MODE_CLASS (mode
) == MODE_INT
9738 && GET_MODE_SIZE (mode
) == 1)
9739 return gen_int_mode (TREE_STRING_POINTER (init
)
9740 [TREE_INT_CST_LOW (index1
)],
9747 goto normal_inner_ref
;
9750 /* If the operand is a CONSTRUCTOR, we can just extract the
9751 appropriate field if it is present. */
9752 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
9754 unsigned HOST_WIDE_INT idx
;
9757 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
9759 if (field
== treeop1
9760 /* We can normally use the value of the field in the
9761 CONSTRUCTOR. However, if this is a bitfield in
9762 an integral mode that we can fit in a HOST_WIDE_INT,
9763 we must mask only the number of bits in the bitfield,
9764 since this is done implicitly by the constructor. If
9765 the bitfield does not meet either of those conditions,
9766 we can't do this optimization. */
9767 && (! DECL_BIT_FIELD (field
)
9768 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
9769 && (GET_MODE_PRECISION (DECL_MODE (field
))
9770 <= HOST_BITS_PER_WIDE_INT
))))
9772 if (DECL_BIT_FIELD (field
)
9773 && modifier
== EXPAND_STACK_PARM
)
9775 op0
= expand_expr (value
, target
, tmode
, modifier
);
9776 if (DECL_BIT_FIELD (field
))
9778 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
9779 enum machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
9781 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
9783 op1
= GEN_INT (((HOST_WIDE_INT
) 1 << bitsize
) - 1);
9784 op0
= expand_and (imode
, op0
, op1
, target
);
9788 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
9790 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
9792 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
9800 goto normal_inner_ref
;
9803 case ARRAY_RANGE_REF
:
9806 enum machine_mode mode1
, mode2
;
9807 HOST_WIDE_INT bitsize
, bitpos
;
9809 int volatilep
= 0, must_force_mem
;
9810 bool packedp
= false;
9811 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
9812 &mode1
, &unsignedp
, &volatilep
, true);
9813 rtx orig_op0
, memloc
;
9814 bool mem_attrs_from_type
= false;
9816 /* If we got back the original object, something is wrong. Perhaps
9817 we are evaluating an expression too early. In any event, don't
9818 infinitely recurse. */
9819 gcc_assert (tem
!= exp
);
9821 if (TYPE_PACKED (TREE_TYPE (TREE_OPERAND (exp
, 0)))
9822 || (TREE_CODE (TREE_OPERAND (exp
, 1)) == FIELD_DECL
9823 && DECL_PACKED (TREE_OPERAND (exp
, 1))))
9826 /* If TEM's type is a union of variable size, pass TARGET to the inner
9827 computation, since it will need a temporary and TARGET is known
9828 to have to do. This occurs in unchecked conversion in Ada. */
9831 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
9832 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
9833 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
9835 && modifier
!= EXPAND_STACK_PARM
9836 ? target
: NULL_RTX
),
9838 (modifier
== EXPAND_INITIALIZER
9839 || modifier
== EXPAND_CONST_ADDRESS
9840 || modifier
== EXPAND_STACK_PARM
)
9841 ? modifier
: EXPAND_NORMAL
);
9844 /* If the bitfield is volatile, we want to access it in the
9845 field's mode, not the computed mode.
9846 If a MEM has VOIDmode (external with incomplete type),
9847 use BLKmode for it instead. */
9850 if (volatilep
&& flag_strict_volatile_bitfields
> 0)
9851 op0
= adjust_address (op0
, mode1
, 0);
9852 else if (GET_MODE (op0
) == VOIDmode
)
9853 op0
= adjust_address (op0
, BLKmode
, 0);
9857 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
9859 /* If we have either an offset, a BLKmode result, or a reference
9860 outside the underlying object, we must force it to memory.
9861 Such a case can occur in Ada if we have unchecked conversion
9862 of an expression from a scalar type to an aggregate type or
9863 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
9864 passed a partially uninitialized object or a view-conversion
9865 to a larger size. */
9866 must_force_mem
= (offset
9868 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
9870 /* Handle CONCAT first. */
9871 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
9874 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
9877 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9880 op0
= XEXP (op0
, 0);
9881 mode2
= GET_MODE (op0
);
9883 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
9884 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
9888 op0
= XEXP (op0
, 1);
9890 mode2
= GET_MODE (op0
);
9893 /* Otherwise force into memory. */
9897 /* If this is a constant, put it in a register if it is a legitimate
9898 constant and we don't need a memory reference. */
9899 if (CONSTANT_P (op0
)
9901 && targetm
.legitimate_constant_p (mode2
, op0
)
9903 op0
= force_reg (mode2
, op0
);
9905 /* Otherwise, if this is a constant, try to force it to the constant
9906 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
9907 is a legitimate constant. */
9908 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
9909 op0
= validize_mem (memloc
);
9911 /* Otherwise, if this is a constant or the object is not in memory
9912 and need be, put it there. */
9913 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
9915 tree nt
= build_qualified_type (TREE_TYPE (tem
),
9916 (TYPE_QUALS (TREE_TYPE (tem
))
9917 | TYPE_QUAL_CONST
));
9918 memloc
= assign_temp (nt
, 1, 1);
9919 emit_move_insn (memloc
, op0
);
9921 mem_attrs_from_type
= true;
9926 enum machine_mode address_mode
;
9927 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
9930 gcc_assert (MEM_P (op0
));
9932 address_mode
= get_address_mode (op0
);
9933 if (GET_MODE (offset_rtx
) != address_mode
)
9934 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
9936 if (GET_MODE (op0
) == BLKmode
9937 /* A constant address in OP0 can have VOIDmode, we must
9938 not try to call force_reg in that case. */
9939 && GET_MODE (XEXP (op0
, 0)) != VOIDmode
9941 && (bitpos
% bitsize
) == 0
9942 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
9943 && MEM_ALIGN (op0
) == GET_MODE_ALIGNMENT (mode1
))
9945 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
9949 op0
= offset_address (op0
, offset_rtx
,
9950 highest_pow2_factor (offset
));
9953 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
9954 record its alignment as BIGGEST_ALIGNMENT. */
9955 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
9956 && is_aligning_offset (offset
, tem
))
9957 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
9959 /* Don't forget about volatility even if this is a bitfield. */
9960 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
9962 if (op0
== orig_op0
)
9963 op0
= copy_rtx (op0
);
9965 MEM_VOLATILE_P (op0
) = 1;
9968 /* In cases where an aligned union has an unaligned object
9969 as a field, we might be extracting a BLKmode value from
9970 an integer-mode (e.g., SImode) object. Handle this case
9971 by doing the extract into an object as wide as the field
9972 (which we know to be the width of a basic mode), then
9973 storing into memory, and changing the mode to BLKmode. */
9974 if (mode1
== VOIDmode
9975 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
9976 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
9977 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
9978 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
9979 && modifier
!= EXPAND_CONST_ADDRESS
9980 && modifier
!= EXPAND_INITIALIZER
9981 && modifier
!= EXPAND_MEMORY
)
9982 /* If the field is volatile, we always want an aligned
9983 access. Do this in following two situations:
9984 1. the access is not already naturally
9985 aligned, otherwise "normal" (non-bitfield) volatile fields
9986 become non-addressable.
9987 2. the bitsize is narrower than the access size. Need
9988 to extract bitfields from the access. */
9989 || (volatilep
&& flag_strict_volatile_bitfields
> 0
9990 && (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0
9991 || (mode1
!= BLKmode
9992 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)))
9993 /* If the field isn't aligned enough to fetch as a memref,
9994 fetch it as a bit field. */
9995 || (mode1
!= BLKmode
9996 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
9997 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
9999 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10000 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10001 && ((modifier
== EXPAND_CONST_ADDRESS
10002 || modifier
== EXPAND_INITIALIZER
)
10004 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10005 || (bitpos
% BITS_PER_UNIT
!= 0)))
10006 /* If the type and the field are a constant size and the
10007 size of the type isn't the same size as the bitfield,
10008 we must use bitfield operations. */
10010 && TYPE_SIZE (TREE_TYPE (exp
))
10011 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10012 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10015 enum machine_mode ext_mode
= mode
;
10017 if (ext_mode
== BLKmode
10018 && ! (target
!= 0 && MEM_P (op0
)
10020 && bitpos
% BITS_PER_UNIT
== 0))
10021 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10023 if (ext_mode
== BLKmode
)
10026 target
= assign_temp (type
, 1, 1);
10031 /* In this case, BITPOS must start at a byte boundary and
10032 TARGET, if specified, must be a MEM. */
10033 gcc_assert (MEM_P (op0
)
10034 && (!target
|| MEM_P (target
))
10035 && !(bitpos
% BITS_PER_UNIT
));
10037 emit_block_move (target
,
10038 adjust_address (op0
, VOIDmode
,
10039 bitpos
/ BITS_PER_UNIT
),
10040 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10042 (modifier
== EXPAND_STACK_PARM
10043 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10048 op0
= validize_mem (op0
);
10050 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10051 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10053 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
, packedp
,
10054 (modifier
== EXPAND_STACK_PARM
10055 ? NULL_RTX
: target
),
10056 ext_mode
, ext_mode
);
10058 /* If the result is a record type and BITSIZE is narrower than
10059 the mode of OP0, an integral mode, and this is a big endian
10060 machine, we must put the field into the high-order bits. */
10061 if (TREE_CODE (type
) == RECORD_TYPE
&& BYTES_BIG_ENDIAN
10062 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
10063 && bitsize
< (HOST_WIDE_INT
) GET_MODE_BITSIZE (GET_MODE (op0
)))
10064 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10065 GET_MODE_BITSIZE (GET_MODE (op0
))
10066 - bitsize
, op0
, 1);
10068 /* If the result type is BLKmode, store the data into a temporary
10069 of the appropriate type, but with the mode corresponding to the
10070 mode for the data we have (op0's mode). It's tempting to make
10071 this a constant type, since we know it's only being stored once,
10072 but that can cause problems if we are taking the address of this
10073 COMPONENT_REF because the MEM of any reference via that address
10074 will have flags corresponding to the type, which will not
10075 necessarily be constant. */
10076 if (mode
== BLKmode
)
10080 new_rtx
= assign_stack_temp_for_type (ext_mode
,
10081 GET_MODE_BITSIZE (ext_mode
),
10083 emit_move_insn (new_rtx
, op0
);
10084 op0
= copy_rtx (new_rtx
);
10085 PUT_MODE (op0
, BLKmode
);
10091 /* If the result is BLKmode, use that to access the object
10093 if (mode
== BLKmode
)
10096 /* Get a reference to just this component. */
10097 if (modifier
== EXPAND_CONST_ADDRESS
10098 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10099 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10101 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10103 if (op0
== orig_op0
)
10104 op0
= copy_rtx (op0
);
10106 /* If op0 is a temporary because of forcing to memory, pass only the
10107 type to set_mem_attributes so that the original expression is never
10108 marked as ADDRESSABLE through MEM_EXPR of the temporary. */
10109 if (mem_attrs_from_type
)
10110 set_mem_attributes (op0
, type
, 0);
10112 set_mem_attributes (op0
, exp
, 0);
10114 if (REG_P (XEXP (op0
, 0)))
10115 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10117 MEM_VOLATILE_P (op0
) |= volatilep
;
10118 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10119 || modifier
== EXPAND_CONST_ADDRESS
10120 || modifier
== EXPAND_INITIALIZER
)
10122 else if (target
== 0)
10123 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10125 convert_move (target
, op0
, unsignedp
);
10130 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10133 /* All valid uses of __builtin_va_arg_pack () are removed during
10135 if (CALL_EXPR_VA_ARG_PACK (exp
))
10136 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10138 tree fndecl
= get_callee_fndecl (exp
), attr
;
10141 && (attr
= lookup_attribute ("error",
10142 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10143 error ("%Kcall to %qs declared with attribute error: %s",
10144 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10145 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10147 && (attr
= lookup_attribute ("warning",
10148 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10149 warning_at (tree_nonartificial_location (exp
),
10150 0, "%Kcall to %qs declared with attribute warning: %s",
10151 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10152 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10154 /* Check for a built-in function. */
10155 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10157 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10158 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10161 return expand_call (exp
, target
, ignore
);
10163 case VIEW_CONVERT_EXPR
:
10166 /* If we are converting to BLKmode, try to avoid an intermediate
10167 temporary by fetching an inner memory reference. */
10168 if (mode
== BLKmode
10169 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10170 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10171 && handled_component_p (treeop0
))
10173 enum machine_mode mode1
;
10174 HOST_WIDE_INT bitsize
, bitpos
;
10179 = get_inner_reference (treeop0
, &bitsize
, &bitpos
,
10180 &offset
, &mode1
, &unsignedp
, &volatilep
,
10184 /* ??? We should work harder and deal with non-zero offsets. */
10186 && (bitpos
% BITS_PER_UNIT
) == 0
10188 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) == 0)
10190 /* See the normal_inner_ref case for the rationale. */
10192 = expand_expr (tem
,
10193 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10194 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10196 && modifier
!= EXPAND_STACK_PARM
10197 ? target
: NULL_RTX
),
10199 (modifier
== EXPAND_INITIALIZER
10200 || modifier
== EXPAND_CONST_ADDRESS
10201 || modifier
== EXPAND_STACK_PARM
)
10202 ? modifier
: EXPAND_NORMAL
);
10204 if (MEM_P (orig_op0
))
10208 /* Get a reference to just this component. */
10209 if (modifier
== EXPAND_CONST_ADDRESS
10210 || modifier
== EXPAND_SUM
10211 || modifier
== EXPAND_INITIALIZER
)
10212 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10214 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10216 if (op0
== orig_op0
)
10217 op0
= copy_rtx (op0
);
10219 set_mem_attributes (op0
, treeop0
, 0);
10220 if (REG_P (XEXP (op0
, 0)))
10221 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10223 MEM_VOLATILE_P (op0
) |= volatilep
;
10229 op0
= expand_expr (treeop0
,
10230 NULL_RTX
, VOIDmode
, modifier
);
10232 /* If the input and output modes are both the same, we are done. */
10233 if (mode
== GET_MODE (op0
))
10235 /* If neither mode is BLKmode, and both modes are the same size
10236 then we can use gen_lowpart. */
10237 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10238 && (GET_MODE_PRECISION (mode
)
10239 == GET_MODE_PRECISION (GET_MODE (op0
)))
10240 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10242 if (GET_CODE (op0
) == SUBREG
)
10243 op0
= force_reg (GET_MODE (op0
), op0
);
10244 temp
= gen_lowpart_common (mode
, op0
);
10249 if (!REG_P (op0
) && !MEM_P (op0
))
10250 op0
= force_reg (GET_MODE (op0
), op0
);
10251 op0
= gen_lowpart (mode
, op0
);
10254 /* If both types are integral, convert from one mode to the other. */
10255 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10256 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10257 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10258 /* As a last resort, spill op0 to memory, and reload it in a
10260 else if (!MEM_P (op0
))
10262 /* If the operand is not a MEM, force it into memory. Since we
10263 are going to be changing the mode of the MEM, don't call
10264 force_const_mem for constants because we don't allow pool
10265 constants to change mode. */
10266 tree inner_type
= TREE_TYPE (treeop0
);
10268 gcc_assert (!TREE_ADDRESSABLE (exp
));
10270 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10272 = assign_stack_temp_for_type
10273 (TYPE_MODE (inner_type
),
10274 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10276 emit_move_insn (target
, op0
);
10280 /* At this point, OP0 is in the correct mode. If the output type is
10281 such that the operand is known to be aligned, indicate that it is.
10282 Otherwise, we need only be concerned about alignment for non-BLKmode
10286 enum insn_code icode
;
10288 if (TYPE_ALIGN_OK (type
))
10290 /* ??? Copying the MEM without substantially changing it might
10291 run afoul of the code handling volatile memory references in
10292 store_expr, which assumes that TARGET is returned unmodified
10293 if it has been used. */
10294 op0
= copy_rtx (op0
);
10295 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10297 else if (mode
!= BLKmode
10298 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
)
10299 /* If the target does have special handling for unaligned
10300 loads of mode then use them. */
10301 && ((icode
= optab_handler (movmisalign_optab
, mode
))
10302 != CODE_FOR_nothing
))
10306 op0
= adjust_address (op0
, mode
, 0);
10307 /* We've already validated the memory, and we're creating a
10308 new pseudo destination. The predicates really can't
10310 reg
= gen_reg_rtx (mode
);
10312 /* Nor can the insn generator. */
10313 insn
= GEN_FCN (icode
) (reg
, op0
);
10317 else if (STRICT_ALIGNMENT
10319 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10321 tree inner_type
= TREE_TYPE (treeop0
);
10322 HOST_WIDE_INT temp_size
10323 = MAX (int_size_in_bytes (inner_type
),
10324 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10326 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10327 rtx new_with_op0_mode
10328 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10330 gcc_assert (!TREE_ADDRESSABLE (exp
));
10332 if (GET_MODE (op0
) == BLKmode
)
10333 emit_block_move (new_with_op0_mode
, op0
,
10334 GEN_INT (GET_MODE_SIZE (mode
)),
10335 (modifier
== EXPAND_STACK_PARM
10336 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10338 emit_move_insn (new_with_op0_mode
, op0
);
10343 op0
= adjust_address (op0
, mode
, 0);
10350 tree lhs
= treeop0
;
10351 tree rhs
= treeop1
;
10352 gcc_assert (ignore
);
10354 /* Check for |= or &= of a bitfield of size one into another bitfield
10355 of size 1. In this case, (unless we need the result of the
10356 assignment) we can do this more efficiently with a
10357 test followed by an assignment, if necessary.
10359 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10360 things change so we do, this code should be enhanced to
10362 if (TREE_CODE (lhs
) == COMPONENT_REF
10363 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10364 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10365 && TREE_OPERAND (rhs
, 0) == lhs
10366 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10367 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10368 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10370 rtx label
= gen_label_rtx ();
10371 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10372 do_jump (TREE_OPERAND (rhs
, 1),
10374 value
? 0 : label
, -1);
10375 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10377 do_pending_stack_adjust ();
10378 emit_label (label
);
10382 expand_assignment (lhs
, rhs
, false);
10387 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10389 case REALPART_EXPR
:
10390 op0
= expand_normal (treeop0
);
10391 return read_complex_part (op0
, false);
10393 case IMAGPART_EXPR
:
10394 op0
= expand_normal (treeop0
);
10395 return read_complex_part (op0
, true);
10402 /* Expanded in cfgexpand.c. */
10403 gcc_unreachable ();
10405 case TRY_CATCH_EXPR
:
10407 case EH_FILTER_EXPR
:
10408 case TRY_FINALLY_EXPR
:
10409 /* Lowered by tree-eh.c. */
10410 gcc_unreachable ();
10412 case WITH_CLEANUP_EXPR
:
10413 case CLEANUP_POINT_EXPR
:
10415 case CASE_LABEL_EXPR
:
10420 case COMPOUND_EXPR
:
10421 case PREINCREMENT_EXPR
:
10422 case PREDECREMENT_EXPR
:
10423 case POSTINCREMENT_EXPR
:
10424 case POSTDECREMENT_EXPR
:
10427 case COMPOUND_LITERAL_EXPR
:
10428 /* Lowered by gimplify.c. */
10429 gcc_unreachable ();
10432 /* Function descriptors are not valid except for as
10433 initialization constants, and should not be expanded. */
10434 gcc_unreachable ();
10436 case WITH_SIZE_EXPR
:
10437 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10438 have pulled out the size to use in whatever context it needed. */
10439 return expand_expr_real (treeop0
, original_target
, tmode
,
10440 modifier
, alt_rtl
);
10443 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10447 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10448 signedness of TYPE), possibly returning the result in TARGET. */
10450 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10452 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10453 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10455 /* For constant values, reduce using build_int_cst_type. */
10456 if (CONST_INT_P (exp
))
10458 HOST_WIDE_INT value
= INTVAL (exp
);
10459 tree t
= build_int_cst_type (type
, value
);
10460 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10462 else if (TYPE_UNSIGNED (type
))
10464 rtx mask
= immed_double_int_const (double_int::mask (prec
),
10466 return expand_and (GET_MODE (exp
), exp
, mask
, target
);
10470 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10471 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10472 exp
, count
, target
, 0);
10473 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10474 exp
, count
, target
, 0);
10478 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10479 when applied to the address of EXP produces an address known to be
10480 aligned more than BIGGEST_ALIGNMENT. */
10483 is_aligning_offset (const_tree offset
, const_tree exp
)
10485 /* Strip off any conversions. */
10486 while (CONVERT_EXPR_P (offset
))
10487 offset
= TREE_OPERAND (offset
, 0);
10489 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10490 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10491 if (TREE_CODE (offset
) != BIT_AND_EXPR
10492 || !host_integerp (TREE_OPERAND (offset
, 1), 1)
10493 || compare_tree_int (TREE_OPERAND (offset
, 1),
10494 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10495 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset
, 1), 1) + 1) < 0)
10498 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10499 It must be NEGATE_EXPR. Then strip any more conversions. */
10500 offset
= TREE_OPERAND (offset
, 0);
10501 while (CONVERT_EXPR_P (offset
))
10502 offset
= TREE_OPERAND (offset
, 0);
10504 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10507 offset
= TREE_OPERAND (offset
, 0);
10508 while (CONVERT_EXPR_P (offset
))
10509 offset
= TREE_OPERAND (offset
, 0);
10511 /* This must now be the address of EXP. */
10512 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10515 /* Return the tree node if an ARG corresponds to a string constant or zero
10516 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10517 in bytes within the string that ARG is accessing. The type of the
10518 offset will be `sizetype'. */
10521 string_constant (tree arg
, tree
*ptr_offset
)
10523 tree array
, offset
, lower_bound
;
10526 if (TREE_CODE (arg
) == ADDR_EXPR
)
10528 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10530 *ptr_offset
= size_zero_node
;
10531 return TREE_OPERAND (arg
, 0);
10533 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10535 array
= TREE_OPERAND (arg
, 0);
10536 offset
= size_zero_node
;
10538 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10540 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10541 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10542 if (TREE_CODE (array
) != STRING_CST
10543 && TREE_CODE (array
) != VAR_DECL
)
10546 /* Check if the array has a nonzero lower bound. */
10547 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10548 if (!integer_zerop (lower_bound
))
10550 /* If the offset and base aren't both constants, return 0. */
10551 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10553 if (TREE_CODE (offset
) != INTEGER_CST
)
10555 /* Adjust offset by the lower bound. */
10556 offset
= size_diffop (fold_convert (sizetype
, offset
),
10557 fold_convert (sizetype
, lower_bound
));
10560 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10562 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10563 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10564 if (TREE_CODE (array
) != ADDR_EXPR
)
10566 array
= TREE_OPERAND (array
, 0);
10567 if (TREE_CODE (array
) != STRING_CST
10568 && TREE_CODE (array
) != VAR_DECL
)
10574 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10576 tree arg0
= TREE_OPERAND (arg
, 0);
10577 tree arg1
= TREE_OPERAND (arg
, 1);
10582 if (TREE_CODE (arg0
) == ADDR_EXPR
10583 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
10584 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
10586 array
= TREE_OPERAND (arg0
, 0);
10589 else if (TREE_CODE (arg1
) == ADDR_EXPR
10590 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
10591 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
10593 array
= TREE_OPERAND (arg1
, 0);
10602 if (TREE_CODE (array
) == STRING_CST
)
10604 *ptr_offset
= fold_convert (sizetype
, offset
);
10607 else if (TREE_CODE (array
) == VAR_DECL
10608 || TREE_CODE (array
) == CONST_DECL
)
10612 /* Variables initialized to string literals can be handled too. */
10613 if (!const_value_known_p (array
)
10614 || !DECL_INITIAL (array
)
10615 || TREE_CODE (DECL_INITIAL (array
)) != STRING_CST
)
10618 /* Avoid const char foo[4] = "abcde"; */
10619 if (DECL_SIZE_UNIT (array
) == NULL_TREE
10620 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
10621 || (length
= TREE_STRING_LENGTH (DECL_INITIAL (array
))) <= 0
10622 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
10625 /* If variable is bigger than the string literal, OFFSET must be constant
10626 and inside of the bounds of the string literal. */
10627 offset
= fold_convert (sizetype
, offset
);
10628 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
10629 && (! host_integerp (offset
, 1)
10630 || compare_tree_int (offset
, length
) >= 0))
10633 *ptr_offset
= offset
;
10634 return DECL_INITIAL (array
);
10640 /* Generate code to calculate OPS, and exploded expression
10641 using a store-flag instruction and return an rtx for the result.
10642 OPS reflects a comparison.
10644 If TARGET is nonzero, store the result there if convenient.
10646 Return zero if there is no suitable set-flag instruction
10647 available on this machine.
10649 Once expand_expr has been called on the arguments of the comparison,
10650 we are committed to doing the store flag, since it is not safe to
10651 re-evaluate the expression. We emit the store-flag insn by calling
10652 emit_store_flag, but only expand the arguments if we have a reason
10653 to believe that emit_store_flag will be successful. If we think that
10654 it will, but it isn't, we have to simulate the store-flag with a
10655 set/jump/set sequence. */
10658 do_store_flag (sepops ops
, rtx target
, enum machine_mode mode
)
10660 enum rtx_code code
;
10661 tree arg0
, arg1
, type
;
10663 enum machine_mode operand_mode
;
10666 rtx subtarget
= target
;
10667 location_t loc
= ops
->location
;
10672 /* Don't crash if the comparison was erroneous. */
10673 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
10676 type
= TREE_TYPE (arg0
);
10677 operand_mode
= TYPE_MODE (type
);
10678 unsignedp
= TYPE_UNSIGNED (type
);
10680 /* We won't bother with BLKmode store-flag operations because it would mean
10681 passing a lot of information to emit_store_flag. */
10682 if (operand_mode
== BLKmode
)
10685 /* We won't bother with store-flag operations involving function pointers
10686 when function pointers must be canonicalized before comparisons. */
10687 #ifdef HAVE_canonicalize_funcptr_for_compare
10688 if (HAVE_canonicalize_funcptr_for_compare
10689 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
10690 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
10692 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
10693 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
10694 == FUNCTION_TYPE
))))
10701 /* For vector typed comparisons emit code to generate the desired
10702 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
10703 expander for this. */
10704 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
10706 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
10707 tree if_true
= constant_boolean_node (true, ops
->type
);
10708 tree if_false
= constant_boolean_node (false, ops
->type
);
10709 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
, if_false
, target
);
10712 /* Get the rtx comparison code to use. We know that EXP is a comparison
10713 operation of some type. Some comparisons against 1 and -1 can be
10714 converted to comparisons with zero. Do so here so that the tests
10715 below will be aware that we have a comparison with zero. These
10716 tests will not catch constants in the first operand, but constants
10717 are rarely passed as the first operand. */
10728 if (integer_onep (arg1
))
10729 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
10731 code
= unsignedp
? LTU
: LT
;
10734 if (! unsignedp
&& integer_all_onesp (arg1
))
10735 arg1
= integer_zero_node
, code
= LT
;
10737 code
= unsignedp
? LEU
: LE
;
10740 if (! unsignedp
&& integer_all_onesp (arg1
))
10741 arg1
= integer_zero_node
, code
= GE
;
10743 code
= unsignedp
? GTU
: GT
;
10746 if (integer_onep (arg1
))
10747 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
10749 code
= unsignedp
? GEU
: GE
;
10752 case UNORDERED_EXPR
:
10778 gcc_unreachable ();
10781 /* Put a constant second. */
10782 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
10783 || TREE_CODE (arg0
) == FIXED_CST
)
10785 tem
= arg0
; arg0
= arg1
; arg1
= tem
;
10786 code
= swap_condition (code
);
10789 /* If this is an equality or inequality test of a single bit, we can
10790 do this by shifting the bit being tested to the low-order bit and
10791 masking the result with the constant 1. If the condition was EQ,
10792 we xor it with 1. This does not require an scc insn and is faster
10793 than an scc insn even if we have it.
10795 The code to make this transformation was moved into fold_single_bit_test,
10796 so we just call into the folder and expand its result. */
10798 if ((code
== NE
|| code
== EQ
)
10799 && integer_zerop (arg1
)
10800 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
10802 gimple srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
10804 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
10806 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
10807 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
10808 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
10809 gimple_assign_rhs1 (srcstmt
),
10810 gimple_assign_rhs2 (srcstmt
));
10811 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
10813 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
10817 if (! get_subtarget (target
)
10818 || GET_MODE (subtarget
) != operand_mode
)
10821 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10824 target
= gen_reg_rtx (mode
);
10826 /* Try a cstore if possible. */
10827 return emit_store_flag_force (target
, code
, op0
, op1
,
10828 operand_mode
, unsignedp
,
10829 (TYPE_PRECISION (ops
->type
) == 1
10830 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
10834 /* Stubs in case we haven't got a casesi insn. */
10835 #ifndef HAVE_casesi
10836 # define HAVE_casesi 0
10837 # define gen_casesi(a, b, c, d, e) (0)
10838 # define CODE_FOR_casesi CODE_FOR_nothing
10841 /* Attempt to generate a casesi instruction. Returns 1 if successful,
10842 0 otherwise (i.e. if there is no casesi instruction).
10844 DEFAULT_PROBABILITY is the probability of jumping to the default
10847 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
10848 rtx table_label
, rtx default_label
, rtx fallback_label
,
10849 int default_probability
)
10851 struct expand_operand ops
[5];
10852 enum machine_mode index_mode
= SImode
;
10853 rtx op1
, op2
, index
;
10858 /* Convert the index to SImode. */
10859 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
10861 enum machine_mode omode
= TYPE_MODE (index_type
);
10862 rtx rangertx
= expand_normal (range
);
10864 /* We must handle the endpoints in the original mode. */
10865 index_expr
= build2 (MINUS_EXPR
, index_type
,
10866 index_expr
, minval
);
10867 minval
= integer_zero_node
;
10868 index
= expand_normal (index_expr
);
10870 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
10871 omode
, 1, default_label
,
10872 default_probability
);
10873 /* Now we can safely truncate. */
10874 index
= convert_to_mode (index_mode
, index
, 0);
10878 if (TYPE_MODE (index_type
) != index_mode
)
10880 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
10881 index_expr
= fold_convert (index_type
, index_expr
);
10884 index
= expand_normal (index_expr
);
10887 do_pending_stack_adjust ();
10889 op1
= expand_normal (minval
);
10890 op2
= expand_normal (range
);
10892 create_input_operand (&ops
[0], index
, index_mode
);
10893 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
10894 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
10895 create_fixed_operand (&ops
[3], table_label
);
10896 create_fixed_operand (&ops
[4], (default_label
10898 : fallback_label
));
10899 expand_jump_insn (CODE_FOR_casesi
, 5, ops
);
10903 /* Attempt to generate a tablejump instruction; same concept. */
10904 #ifndef HAVE_tablejump
10905 #define HAVE_tablejump 0
10906 #define gen_tablejump(x, y) (0)
10909 /* Subroutine of the next function.
10911 INDEX is the value being switched on, with the lowest value
10912 in the table already subtracted.
10913 MODE is its expected mode (needed if INDEX is constant).
10914 RANGE is the length of the jump table.
10915 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
10917 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
10918 index value is out of range.
10919 DEFAULT_PROBABILITY is the probability of jumping to
10920 the default label. */
10923 do_tablejump (rtx index
, enum machine_mode mode
, rtx range
, rtx table_label
,
10924 rtx default_label
, int default_probability
)
10928 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
10929 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
10931 /* Do an unsigned comparison (in the proper mode) between the index
10932 expression and the value which represents the length of the range.
10933 Since we just finished subtracting the lower bound of the range
10934 from the index expression, this comparison allows us to simultaneously
10935 check that the original index expression value is both greater than
10936 or equal to the minimum value of the range and less than or equal to
10937 the maximum value of the range. */
10940 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
10941 default_label
, default_probability
);
10944 /* If index is in range, it must fit in Pmode.
10945 Convert to Pmode so we can index with it. */
10947 index
= convert_to_mode (Pmode
, index
, 1);
10949 /* Don't let a MEM slip through, because then INDEX that comes
10950 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
10951 and break_out_memory_refs will go to work on it and mess it up. */
10952 #ifdef PIC_CASE_VECTOR_ADDRESS
10953 if (flag_pic
&& !REG_P (index
))
10954 index
= copy_to_mode_reg (Pmode
, index
);
10957 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
10958 GET_MODE_SIZE, because this indicates how large insns are. The other
10959 uses should all be Pmode, because they are addresses. This code
10960 could fail if addresses and insns are not the same size. */
10961 index
= gen_rtx_PLUS (Pmode
,
10962 gen_rtx_MULT (Pmode
, index
,
10963 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE
))),
10964 gen_rtx_LABEL_REF (Pmode
, table_label
));
10965 #ifdef PIC_CASE_VECTOR_ADDRESS
10967 index
= PIC_CASE_VECTOR_ADDRESS (index
);
10970 index
= memory_address (CASE_VECTOR_MODE
, index
);
10971 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
10972 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
10973 convert_move (temp
, vector
, 0);
10975 emit_jump_insn (gen_tablejump (temp
, table_label
));
10977 /* If we are generating PIC code or if the table is PC-relative, the
10978 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
10979 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
10984 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
10985 rtx table_label
, rtx default_label
, int default_probability
)
10989 if (! HAVE_tablejump
)
10992 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
10993 fold_convert (index_type
, index_expr
),
10994 fold_convert (index_type
, minval
));
10995 index
= expand_normal (index_expr
);
10996 do_pending_stack_adjust ();
10998 do_tablejump (index
, TYPE_MODE (index_type
),
10999 convert_modes (TYPE_MODE (index_type
),
11000 TYPE_MODE (TREE_TYPE (range
)),
11001 expand_normal (range
),
11002 TYPE_UNSIGNED (TREE_TYPE (range
))),
11003 table_label
, default_label
, default_probability
);
11007 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11009 const_vector_from_tree (tree exp
)
11015 enum machine_mode inner
, mode
;
11017 mode
= TYPE_MODE (TREE_TYPE (exp
));
11019 if (initializer_zerop (exp
))
11020 return CONST0_RTX (mode
);
11022 units
= GET_MODE_NUNITS (mode
);
11023 inner
= GET_MODE_INNER (mode
);
11025 v
= rtvec_alloc (units
);
11027 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11029 elt
= VECTOR_CST_ELT (exp
, i
);
11031 if (TREE_CODE (elt
) == REAL_CST
)
11032 RTVEC_ELT (v
, i
) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt
),
11034 else if (TREE_CODE (elt
) == FIXED_CST
)
11035 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11038 RTVEC_ELT (v
, i
) = immed_double_int_const (tree_to_double_int (elt
),
11042 return gen_rtx_CONST_VECTOR (mode
, v
);
11045 /* Build a decl for a personality function given a language prefix. */
11048 build_personality_function (const char *lang
)
11050 const char *unwind_and_version
;
11054 switch (targetm_common
.except_unwind_info (&global_options
))
11059 unwind_and_version
= "_sj0";
11063 unwind_and_version
= "_v0";
11066 unwind_and_version
= "_seh0";
11069 gcc_unreachable ();
11072 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11074 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11075 long_long_unsigned_type_node
,
11076 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11077 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11078 get_identifier (name
), type
);
11079 DECL_ARTIFICIAL (decl
) = 1;
11080 DECL_EXTERNAL (decl
) = 1;
11081 TREE_PUBLIC (decl
) = 1;
11083 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11084 are the flags assigned by targetm.encode_section_info. */
11085 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11090 /* Extracts the personality function of DECL and returns the corresponding
11094 get_personality_function (tree decl
)
11096 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11097 enum eh_personality_kind pk
;
11099 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11100 if (pk
== eh_personality_none
)
11104 && pk
== eh_personality_any
)
11105 personality
= lang_hooks
.eh_personality ();
11107 if (pk
== eh_personality_lang
)
11108 gcc_assert (personality
!= NULL_TREE
);
11110 return XEXP (DECL_RTL (personality
), 0);
11113 #include "gt-expr.h"